Skip to content

Commit

Permalink
Merge pull request #8 from PixelOutlaw/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
UltraFaceguy committed Aug 26, 2020
2 parents 08b1e7a + f4d8b8b commit ab32677
Show file tree
Hide file tree
Showing 14 changed files with 624 additions and 484 deletions.
32 changes: 23 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
<parent>
<groupId>io.pixeloutlaw</groupId>
<artifactId>spigot-plugin-parent</artifactId>
<version>1.16.1.0</version>
<version>1.16.2.0</version>
</parent>

<artifactId>loot</artifactId>
<version>1.3.8</version>
<version>1.3.10</version>
<packaging>jar</packaging>

<name>loot</name>
Expand Down Expand Up @@ -67,23 +67,37 @@
<dependency>
<groupId>io.pixeloutlaw</groupId>
<artifactId>facecore</artifactId>
<version>1.16.1.8</version>
<version>1.16.2.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.pixeloutlaw</groupId>
<artifactId>strife</artifactId>
<version>3.1.1</version>
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
<exclusion>
<artifactId>bukkit</artifactId>
<groupId>org.bukkit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.UltraFaceguy</groupId>
Expand Down
44 changes: 22 additions & 22 deletions src/main/java/info/faceland/loot/items/prefabs/ShardOfFailure.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
/**
* The MIT License Copyright (c) 2015 Teal Cube Games
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package info.faceland.loot.items.prefabs;

import com.tealcube.minecraft.bukkit.TextUtils;
import info.faceland.loot.utils.MaterialUtil;
import io.pixeloutlaw.minecraft.spigot.garbage.ListExtensionsKt;
import io.pixeloutlaw.minecraft.spigot.hilt.ItemStackExtensionsKt;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -48,19 +47,20 @@ public static void rebuild() {
String name = ChatColor.RED + "Shard of Failure";
FAILURE_NAME = name;
ItemStackExtensionsKt.setDisplayName(stack, name);
ItemStackExtensionsKt.setLore(stack, TextUtils.color(Arrays.asList(
"&7Use this item on an Upgrade Scroll",
"&7to slightly increase the chance of",
"&7upgrade success!",
"&8&oThis failure is special because it",
"&8&owas created by {name} :)"
ItemStackExtensionsKt.setLore(stack, ListExtensionsKt.chatColorize(Arrays.asList(
"&7Place this item onto an",
"&2Upgrade Scroll &7to raise",
"&7its success chance!",
"&8&oThis failure is special",
"&8&obecause it was made by",
"&8&o{name} :)"
)));
stack.setDurability((short) 11);
ItemStackExtensionsKt.setCustomModelData(stack, 500);
item = stack;
}

public static boolean isSimilar(ItemStack stack) {
return stack.getType() == item.getType() && stack.getDurability() == 11 && ItemStackExtensionsKt
.getDisplayName(item).equals(ItemStackExtensionsKt.getDisplayName(stack));
return stack.getType() == item.getType() && MaterialUtil.getCustomData(stack) == 500 && FAILURE_NAME
.equals(ItemStackExtensionsKt.getDisplayName(stack));
}
}
67 changes: 51 additions & 16 deletions src/main/java/info/faceland/loot/listeners/DeconstructListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@
import info.faceland.loot.events.LootDeconstructEvent.DeconstructType;
import info.faceland.loot.items.prefabs.ShardOfFailure;
import info.faceland.loot.math.LootRandom;
import info.faceland.loot.utils.InventoryUtil;
import info.faceland.loot.tier.Tier;
import info.faceland.loot.utils.MaterialUtil;
import io.pixeloutlaw.minecraft.spigot.hilt.ItemStackExtensionsKt;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import land.face.strife.data.champion.LifeSkillType;
import land.face.strife.util.PlayerDataUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand Down Expand Up @@ -135,8 +139,7 @@ private void doCraftDeconstruct(LootDeconstructEvent event) {

int toolQuality = 1;
if (cursorItem.hasItemMeta()) {
toolQuality = (int) ItemStackExtensionsKt.getLore(cursorItem).get(1).chars()
.filter(ch -> ch == '✪').count();
toolQuality = (int) ItemStackExtensionsKt.getLore(cursorItem).get(1).chars().filter(ch -> ch == '✪').count();
}

double levelAdvantage = getLevelAdvantage(craftingLevel, itemLevel);
Expand All @@ -153,10 +156,17 @@ private void doCraftDeconstruct(LootDeconstructEvent event) {
List<String> lore = ItemStackExtensionsKt.getLore(targetItem);
List<String> possibleStats = new ArrayList<>();
for (String str : lore) {
if (str.startsWith("" + ChatColor.GREEN) || str.startsWith("" + ChatColor.YELLOW)) {
if (str.contains(":")) {
continue;
if (!ChatColor.stripColor(str).startsWith("+")) {
continue;
}
net.md_5.bungee.api.ChatColor color = getHexFromString(str);
if (color != null) {
if (isValidStealColor(color.getColor())) {
possibleStats.add(str);
}
continue;
}
if (str.startsWith(ChatColor.GREEN + "") || str.startsWith(ChatColor.YELLOW + "")) {
possibleStats.add(str);
}
}
Expand All @@ -178,20 +188,28 @@ private void doCraftDeconstruct(LootDeconstructEvent event) {

player.playSound(player.getEyeLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 0.8F);
event.setTargetItem(null);
player.getInventory().addItem(craftMaterial);
if (player.getInventory().firstEmpty() != -1) {
player.getInventory().addItem(craftMaterial);
} else {
Item item = player.getWorld().dropItem(player.getLocation(), craftMaterial);
item.setOwner(player.getUniqueId());
}

double essChance = 0.1 + 0.1 * toolQuality + Math.min(effectiveLevelAdvantage * 0.015, 0.35);
if (possibleStats.size() > 0 && random.nextDouble() < essChance) {
if (possibleStats.size() > 0) {
player.playSound(player.getEyeLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.4F, 2F);
String type = InventoryUtil.getItemType(targetItem);
ItemStack essence = buildEssence(type, itemLevel, craftingLevel, toolQuality,
possibleStats, player.hasPotionEffect(PotionEffectType.LUCK));
Tier tier = MaterialUtil.getTierFromStack(targetItem);

ItemStack essence = buildEssence(tier, itemLevel, effectiveLevelAdvantage, toolQuality, possibleStats,
player.hasPotionEffect(PotionEffectType.LUCK));

if (player.getInventory().firstEmpty() != -1) {
player.getInventory().addItem(essence);
} else {
player.getWorld().dropItem(player.getLocation(), essence);
Item item = player.getWorld().dropItem(player.getLocation(), essence);
item.setOwner(player.getUniqueId());
}
}

List<String> toolLore = ItemStackExtensionsKt.getLore(cursorItem);
if (ChatColor.stripColor(toolLore.get(toolLore.size() - 1)).startsWith("Remaining Uses: ")) {
int uses = getDigit(ChatColor.stripColor(toolLore.get(toolLore.size() - 1)));
Expand All @@ -205,9 +223,9 @@ private void doCraftDeconstruct(LootDeconstructEvent event) {
event.setCursorItem(cursorItem);
}
}
double exp = 2 + Math.pow((double) itemLevel / 4, 1.2);
plugin.getStrifePlugin().getSkillExperienceManager().addExperience(player,
LifeSkillType.CRAFTING, exp, false, false);
double exp = 5 + itemLevel * 1.1;
plugin.getStrifePlugin().getSkillExperienceManager()
.addExperience(player, LifeSkillType.CRAFTING, exp, false, false);
}

private void doEnchantDeconstruct(LootDeconstructEvent event) {
Expand Down Expand Up @@ -237,4 +255,21 @@ public static int getLevelAdvantage(int craftLevel, int itemLevel) {
int lvlReq = 20 + (int) Math.floor((double) craftLevel / 10) * 14;
return lvlReq - itemLevel;
}

private boolean isValidStealColor(Color color) {
float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
return hsb[0] >= 0.14 && hsb[0] <= 0.34 && hsb[1] >= 0.7 && hsb[1] <= 0.72 && hsb[2] >= 0.99 && hsb[2] <= 1.01;
}

private final Pattern hexPattern = Pattern.compile("§x(§[A-Fa-f0-9]){6}");

public net.md_5.bungee.api.ChatColor getHexFromString(String message) {
Matcher matcher = hexPattern.matcher(message);
if (matcher.find()) {
String str = "#" + matcher.group().replace("§x", "").replace("§", "");
Bukkit.getLogger().warning(str);
return net.md_5.bungee.api.ChatColor.of(str);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void onEntityDeathEvent(EntityDeathEvent event) {
return;
}

Player killer = mob.getKiller();
Player killer = mob.getTopDamager();
if (killer == null) {
killer = event.getEntity().getKiller();
if (killer == null) {
Expand Down
84 changes: 66 additions & 18 deletions src/main/java/info/faceland/loot/listeners/InteractListener.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
/**
* The MIT License Copyright (c) 2015 Teal Cube Games
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package info.faceland.loot.listeners;

Expand All @@ -41,6 +39,7 @@
import info.faceland.loot.tier.Tier;
import info.faceland.loot.utils.InventoryUtil;
import info.faceland.loot.utils.MaterialUtil;
import io.pixeloutlaw.minecraft.spigot.garbage.StringExtensionsKt;
import io.pixeloutlaw.minecraft.spigot.hilt.ItemStackExtensionsKt;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -163,15 +162,64 @@ public void onPlayerDropItem(PlayerDropItemEvent e) {
MessageUtils.sendMessage(e.getPlayer(), noDropMessage);
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onQuickShard(InventoryClickEvent event) {
if (event.getClick() != ClickType.SHIFT_RIGHT || !(event.getClickedInventory() instanceof PlayerInventory)) {
return;
}
if (event.getCurrentItem() == null || event.getCursor() == null || event.getCurrentItem().getType() == Material.AIR
|| event.getCursor().getType() == Material.AIR || !(event.getWhoClicked() instanceof Player)) {
return;
}

Player player = (Player) event.getWhoClicked();
ItemStack targetItem = new ItemStack(event.getCurrentItem());
ItemStack cursor = new ItemStack(event.getCursor());
String cursorName = ItemStackExtensionsKt.getDisplayName(cursor);
int amount = cursor.getAmount();

if (StringUtils.isBlank(cursorName) || !ShardOfFailure.isSimilar(cursor)) {
return;
}

UpgradeScroll scroll = plugin.getScrollManager().getScroll(targetItem);
if (scroll == null) {
return;
}
if (targetItem.getAmount() > 1) {
sendMessage(player, plugin.getSettings().getString("language.augment.stack-size", ""));
return;
}
List<String> lore = ItemStackExtensionsKt.getLore(targetItem);
int failureBonus = MaterialUtil.getFailureBonus(targetItem);
if (failureBonus > 0) {
lore.set(0, StringExtensionsKt.chatColorize(FAILURE_BONUS + " +" + (failureBonus + amount)));
} else {
lore.add(0, StringExtensionsKt.chatColorize(FAILURE_BONUS + " +" + amount));
}
ItemStackExtensionsKt.setLore(targetItem, lore);
event.setCurrentItem(targetItem);
event.getCursor().setAmount(0);
event.setCursor(null);
event.setCancelled(true);
event.setResult(Event.Result.DENY);
player.updateInventory();

player.playSound(player.getEyeLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1L, 2F);

plugin.getStrifePlugin().getSkillExperienceManager()
.addExperience(player, LifeSkillType.ENCHANTING, amount * 22, false, false);
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onRightClickUse(InventoryClickEvent event) {
if (!(event.getClickedInventory() instanceof PlayerInventory)) {
if (event.getClick() != ClickType.RIGHT || !(event.getClickedInventory() instanceof PlayerInventory)) {
return;
}
if (event.getCurrentItem() == null || event.getCursor() == null ||
event.getCurrentItem().getType() == Material.AIR ||
event.getCursor().getType() == Material.AIR ||
!(event.getWhoClicked() instanceof Player) || event.getClick() != ClickType.RIGHT) {
!(event.getWhoClicked() instanceof Player)) {
return;
}

Expand Down Expand Up @@ -332,7 +380,7 @@ public void onRightClickUse(InventoryClickEvent event) {
player.updateInventory();
player.playSound(player.getEyeLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1L, 2F);
plugin.getStrifePlugin().getSkillExperienceManager().addExperience(player,
LifeSkillType.ENCHANTING, 1, false, false);
LifeSkillType.ENCHANTING, 22, false, false);
} else if (cursorName.equals(ChatColor.WHITE + "Item Rename Tag")) {
if (ItemStackExtensionsKt.getLore(cursor).get(3).equals(ChatColor.WHITE + "none")) {
sendMessage(player, plugin.getSettings().getString("language.rename.notset", ""));
Expand Down
Loading

0 comments on commit ab32677

Please sign in to comment.