From 4bab27ddf458c892847b7190ebb80dc6a90680e9 Mon Sep 17 00:00:00 2001 From: UltraFaceguy Date: Fri, 4 Jun 2021 10:37:22 -0400 Subject: [PATCH] Tinker gear, command revamp, better discord messages --- pom.xml | 2 +- .../java/info/faceland/loot/LootPlugin.java | 30 +- .../faceland/loot/api/items/CustomItem.java | 10 +- .../loot/api/items/CustomItemBuilder.java | 6 + .../loot/api/managers/CustomItemManager.java | 3 +- .../loot/api/managers/RarityManager.java | 3 + .../faceland/loot/commands/LootCommand.java | 715 ++++-------------- .../faceland/loot/items/LootCustomItem.java | 39 + .../loot/items/LootCustomItemBuilder.java | 185 ++--- .../loot/items/prefabs/TinkerersGear.java | 58 ++ .../loot/listeners/DeconstructListener.java | 6 +- .../loot/listeners/InteractListener.java | 228 ++++-- .../listeners/crafting/CraftingListener.java | 9 +- .../listeners/sockets/CombinerListener.java | 11 +- .../loot/managers/EnchantTomeManager.java | 7 +- .../loot/managers/LootCustomItemManager.java | 247 +++--- .../loot/managers/LootRarityManager.java | 6 + .../faceland/loot/managers/ScrollManager.java | 6 + .../loot/managers/SocketGemManager.java | 5 + .../faceland/loot/managers/TierManager.java | 18 +- .../info/faceland/loot/utils/DropUtil.java | 9 +- .../faceland/loot/utils/InventoryUtil.java | 31 +- .../faceland/loot/utils/MaterialUtil.java | 172 +++-- src/main/resources/plugin.yml | 8 +- 24 files changed, 842 insertions(+), 972 deletions(-) create mode 100644 src/main/java/info/faceland/loot/items/prefabs/TinkerersGear.java diff --git a/pom.xml b/pom.xml index 0cfa01c8..d8537019 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ loot - 1.4.1 + 1.4.2 jar loot diff --git a/src/main/java/info/faceland/loot/LootPlugin.java b/src/main/java/info/faceland/loot/LootPlugin.java index 6c1bf78a..c7eb783e 100644 --- a/src/main/java/info/faceland/loot/LootPlugin.java +++ b/src/main/java/info/faceland/loot/LootPlugin.java @@ -21,6 +21,7 @@ import com.tealcube.minecraft.bukkit.TextUtils; import com.tealcube.minecraft.bukkit.facecore.logging.PluginLogger; import com.tealcube.minecraft.bukkit.facecore.plugin.FacePlugin; +import com.tealcube.minecraft.bukkit.shade.acf.PaperCommandManager; import com.tealcube.minecraft.bukkit.shade.apache.commons.lang3.StringUtils; import info.faceland.loot.api.creatures.CreatureModBuilder; import info.faceland.loot.api.creatures.MobInfo; @@ -56,6 +57,7 @@ import info.faceland.loot.items.prefabs.ArcaneEnhancer; import info.faceland.loot.items.prefabs.PurifyingScroll; import info.faceland.loot.items.prefabs.ShardOfFailure; +import info.faceland.loot.items.prefabs.TinkerersGear; import info.faceland.loot.listeners.DeconstructListener; import info.faceland.loot.listeners.EnchantDegradeListener; import info.faceland.loot.listeners.EnchantMenuListener; @@ -120,9 +122,9 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemFlag; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.RegisteredServiceProvider; -import se.ranzdo.bukkit.methodcommand.CommandHandler; public final class LootPlugin extends FacePlugin { @@ -253,6 +255,7 @@ public void enable() { DropUtil.refresh(); ArcaneEnhancer.rebuild(); + TinkerersGear.rebuild(); PurifyingScroll.rebuild(); ShardOfFailure.rebuild(); @@ -260,8 +263,22 @@ public void enable() { strifePlugin = (StrifePlugin) Bukkit.getPluginManager().getPlugin("Strife"); - CommandHandler handler = new CommandHandler(this); - handler.registerCommands(new LootCommand(this)); + PaperCommandManager commandManager = new PaperCommandManager(this); + commandManager.registerCommand(new LootCommand(this)); + + commandManager.getCommandCompletions() + .registerCompletion("gems", c -> socketGemManager.getGemIds()); + commandManager.getCommandCompletions() + .registerCompletion("tomes", c -> enchantTomeManager.getTomeIds()); + commandManager.getCommandCompletions() + .registerCompletion("tiers", c -> tierManager.getTierIds()); + commandManager.getCommandCompletions() + .registerCompletion("rarities", c -> rarityManager.getRarityIds()); + commandManager.getCommandCompletions() + .registerCompletion("scrolls", c -> scrollManager.getScrollIds()); + commandManager.getCommandCompletions() + .registerCompletion("uniques", c -> customItemManager.listCustomItems()); + Bukkit.getPluginManager().registerEvents(new EntityDeathListener(this), this); Bukkit.getPluginManager().registerEvents(new CombinerListener(this), this); Bukkit.getPluginManager().registerEvents(new InteractListener(this), this); @@ -649,6 +666,13 @@ private void loadCustomItems() { builder.withCustomData(cs.getInt("custom-data-value", -1)); builder.withBroadcast(cs.getBoolean("broadcast")); builder.withQuality(cs.getBoolean("can-be-quality-enhanced")); + List flags = cs.getStringList("flags"); + Set itemFlags = new HashSet<>(); + for (String s : flags) { + itemFlags.add(ItemFlag.valueOf(s)); + } + builder.withFlags(itemFlags); + builder.withCanBreak(new HashSet<>(cs.getStringList("can-break"))); CustomItem ci = builder.build(); customItems.add(ci); loaded.add(ci.getName()); diff --git a/src/main/java/info/faceland/loot/api/items/CustomItem.java b/src/main/java/info/faceland/loot/api/items/CustomItem.java index bf0f73f2..3b0c0016 100644 --- a/src/main/java/info/faceland/loot/api/items/CustomItem.java +++ b/src/main/java/info/faceland/loot/api/items/CustomItem.java @@ -22,12 +22,14 @@ */ package info.faceland.loot.api.items; +import java.util.List; +import java.util.Set; import org.bukkit.Material; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; -import java.util.List; - public interface CustomItem { + String getName(); String getDisplayName(); @@ -51,4 +53,8 @@ public interface CustomItem { boolean isBroadcast(); boolean canBeQuality(); + + Set getFlags(); + + Set getCanBreak(); } diff --git a/src/main/java/info/faceland/loot/api/items/CustomItemBuilder.java b/src/main/java/info/faceland/loot/api/items/CustomItemBuilder.java index 583075ef..80be37f8 100644 --- a/src/main/java/info/faceland/loot/api/items/CustomItemBuilder.java +++ b/src/main/java/info/faceland/loot/api/items/CustomItemBuilder.java @@ -23,6 +23,8 @@ package info.faceland.loot.api.items; import java.util.List; +import java.util.Set; +import org.bukkit.inventory.ItemFlag; public interface CustomItemBuilder { @@ -47,4 +49,8 @@ public interface CustomItemBuilder { CustomItemBuilder withBroadcast(boolean b); CustomItemBuilder withQuality(boolean b); + + CustomItemBuilder withFlags(Set f); + + CustomItemBuilder withCanBreak(Set b); } diff --git a/src/main/java/info/faceland/loot/api/managers/CustomItemManager.java b/src/main/java/info/faceland/loot/api/managers/CustomItemManager.java index 593e916b..f6e2c489 100644 --- a/src/main/java/info/faceland/loot/api/managers/CustomItemManager.java +++ b/src/main/java/info/faceland/loot/api/managers/CustomItemManager.java @@ -23,7 +23,6 @@ package info.faceland.loot.api.managers; import info.faceland.loot.api.items.CustomItem; - import java.util.Map; import java.util.Set; @@ -31,6 +30,8 @@ public interface CustomItemManager { Set getCustomItems(); + Set listCustomItems(); + CustomItem getCustomItem(String name); void addCustomItem(CustomItem ci); diff --git a/src/main/java/info/faceland/loot/api/managers/RarityManager.java b/src/main/java/info/faceland/loot/api/managers/RarityManager.java index 1a0639b8..245eb0a2 100644 --- a/src/main/java/info/faceland/loot/api/managers/RarityManager.java +++ b/src/main/java/info/faceland/loot/api/managers/RarityManager.java @@ -24,6 +24,7 @@ import info.faceland.loot.data.ItemRarity; import java.util.Map; +import java.util.Set; public interface RarityManager { @@ -35,6 +36,8 @@ public interface RarityManager { Map getLoadedRarities(); + Set getRarityIds(); + ItemRarity getRandomRarity(); ItemRarity getRandomIdRarity(); diff --git a/src/main/java/info/faceland/loot/commands/LootCommand.java b/src/main/java/info/faceland/loot/commands/LootCommand.java index 0d2a30fb..f21ff9f9 100644 --- a/src/main/java/info/faceland/loot/commands/LootCommand.java +++ b/src/main/java/info/faceland/loot/commands/LootCommand.java @@ -20,7 +20,15 @@ import static com.tealcube.minecraft.bukkit.facecore.utilities.MessageUtils.sendMessage; +import com.destroystokyo.paper.Namespaced; import com.tealcube.minecraft.bukkit.TextUtils; +import com.tealcube.minecraft.bukkit.shade.acf.BaseCommand; +import com.tealcube.minecraft.bukkit.shade.acf.annotation.CommandAlias; +import com.tealcube.minecraft.bukkit.shade.acf.annotation.CommandCompletion; +import com.tealcube.minecraft.bukkit.shade.acf.annotation.CommandPermission; +import com.tealcube.minecraft.bukkit.shade.acf.annotation.Default; +import com.tealcube.minecraft.bukkit.shade.acf.annotation.Subcommand; +import com.tealcube.minecraft.bukkit.shade.acf.bukkit.contexts.OnlinePlayer; import info.faceland.loot.LootPlugin; import info.faceland.loot.api.items.CustomItem; import info.faceland.loot.api.items.ItemGenerationReason; @@ -28,11 +36,8 @@ import info.faceland.loot.data.UpgradeScroll; import info.faceland.loot.enchantments.EnchantmentTome; import info.faceland.loot.items.prefabs.ArcaneEnhancer; -import info.faceland.loot.items.prefabs.IdentityTome; -import info.faceland.loot.items.prefabs.PurifyingScroll; import info.faceland.loot.items.prefabs.SocketExtender; -import info.faceland.loot.items.prefabs.UnidentifiedItem; -import info.faceland.loot.math.LootRandom; +import info.faceland.loot.items.prefabs.TinkerersGear; import info.faceland.loot.menu.pawn.PawnMenu; import info.faceland.loot.menu.upgrade.EnchantMenu; import info.faceland.loot.sockets.SocketGem; @@ -42,39 +47,35 @@ import info.faceland.loot.utils.MaterialUtil; import io.pixeloutlaw.minecraft.spigot.hilt.ItemStackExtensionsKt; import java.util.List; +import java.util.Random; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import se.ranzdo.bukkit.methodcommand.Arg; -import se.ranzdo.bukkit.methodcommand.Command; -import se.ranzdo.bukkit.methodcommand.FlagArg; -import se.ranzdo.bukkit.methodcommand.Flags; -import se.ranzdo.bukkit.methodcommand.Wildcard; -public final class LootCommand { +@CommandAlias("loot") +public class LootCommand extends BaseCommand { private final LootPlugin plugin; - private final LootRandom random; + private final Random random; private String awardFormat; private String awardFormatSelf; public LootCommand(LootPlugin plugin) { this.plugin = plugin; - this.random = new LootRandom(System.currentTimeMillis()); + this.random = new Random(System.currentTimeMillis()); awardFormat = plugin.getSettings().getString("language.broadcast.reward-item", ""); awardFormatSelf = plugin.getSettings().getString("language.broadcast.reward-item-self", ""); } - @Command(identifier = "loot reward", permissions = "loot.command.spawn", onlyPlayers = false) - public void reward(CommandSender sender, - @Arg(name = "target") Player target, - @Arg(name = "minLevel", def = "1") int minLevel, - @Arg(name = "maxLevel", def = "100") int maxLevel, - @Arg(name = "rarity") String rarity) { - Tier t = DropUtil.getTier(target); + @Subcommand("reward") + @CommandCompletion("@players @range:1-100 @range:1-100") + @CommandPermission("loot.reward") + public void memeCommand(CommandSender sender, OnlinePlayer player, int minLevel, int maxLevel, + String rarity) { + Tier t = DropUtil.getTier(player.getPlayer()); if (t == null) { sendMessage(sender, plugin.getSettings().getString("language.commands.spawn.other-failure", "")); @@ -92,619 +93,197 @@ public void reward(CommandSender sender, .withItemGenerationReason(ItemGenerationReason.COMMAND) .build().getStack(); - target.playSound(target.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1, 1); - target.playSound(target.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1); - target.getInventory().addItem(item); + player.getPlayer().playSound(player.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1, 1); + player.getPlayer() + .playSound(player.getPlayer().getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1); + player.getPlayer().getInventory().addItem(item); if (itemRarity.isBroadcast()) { - InventoryUtil.broadcast(target, item, awardFormat, true); + InventoryUtil.sendToDiscord(player.getPlayer(), item, awardFormat, true); } else { - InventoryUtil.broadcast(target, item, awardFormatSelf, false); + InventoryUtil.sendToDiscord(player.getPlayer(), item, awardFormatSelf, false); } - sendMessage(sender, "Rewarded " + target.getName() + " successfully!"); + sendMessage(sender, "Rewarded " + player.getPlayer().getName() + " successfully!"); } - @Command(identifier = "loot spawn", permissions = "loot.command.spawn") - @Flags(identifier = {"c", "s", "t", "e", "se", "u", "id", "us", "rp"}, - description = {"custom", "socket gem", "tier", "enchantment", "socket extender", - "unidentified", "tome", - "upgrade scroll", "reveal powder"}) - public void spawnCommand(Player sender, @Arg(name = "amount", def = "1") int amount, - @Arg(name = "name", def = "") String name, - @FlagArg("c") boolean custom, - @FlagArg("s") boolean socket, - @FlagArg("t") boolean tier, - @FlagArg("e") boolean enchantment, - @FlagArg("se") boolean socketExtender, - @FlagArg("u") boolean unidentified, - @FlagArg("id") boolean tome, - @FlagArg("us") boolean upgradeScroll) { - if (custom) { - if (name.equals("")) { + @Subcommand("give") + @CommandPermission("loot.give") + public class GiveCommand extends BaseCommand { + + @Subcommand("tier") + @CommandCompletion("@players @tiers @rarities @range:1-100") + public void giveTier(CommandSender sender, OnlinePlayer player, String tier, String rarity, @Default("1") int amount, @Default("-1") int level) { + Tier t = tier.equalsIgnoreCase("random") ? null : plugin.getTierManager().getTier(tier); + ItemRarity r = rarity.equalsIgnoreCase("random") ? null : plugin.getRarityManager().getRarity(rarity); + for (int i = 0; i < amount; i++) { + player.getPlayer().getInventory().addItem( + plugin.getNewItemBuilder().withItemGenerationReason(ItemGenerationReason.COMMAND) + .withTier(t == null ? plugin.getTierManager().getRandomTier() : t) + .withRarity(r == null ? plugin.getRarityManager().getRandomRarity() : r) + .withLevel(level == -1 ? 1 + random.nextInt(100) : level) + .build() + .getStack()); + } + sendMessage(sender, + plugin.getSettings().getString("language.commands.spawn.other-success", ""), + new String[][]{{"%amount%", amount + ""}}); + } + + @Subcommand("tome") + @CommandCompletion("@players @tomes @range:1-100") + public void giveTome(CommandSender sender, OnlinePlayer player, String id, @Default("1") int amount) { + if (id.equalsIgnoreCase("random")) { for (int i = 0; i < amount; i++) { - giveItem(sender, plugin.getCustomItemManager().getRandomCustomItem(true).toItemStack(1)); + player.getPlayer().getInventory().addItem( + plugin.getEnchantTomeManager().getRandomEnchantTome().toItemStack(1)); } sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.custom-success", ""), + plugin.getSettings().getString("language.commands.spawn.stone-success", ""), new String[][]{{"%amount%", amount + ""}}); return; } - CustomItem ci = plugin.getCustomItemManager().getCustomItem(name); - if (ci == null) { + EnchantmentTome es = plugin.getEnchantTomeManager().getEnchantTome(id); + if (es == null) { sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.custom-failure", "")); + plugin.getSettings().getString("language.commands.spawn.stone-failure", "")); return; } for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(ci.toItemStack(1)); + player.getPlayer().getInventory().addItem(es.toItemStack(1)); } sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.custom-success", ""), + plugin.getSettings().getString("language.commands.spawn.stone-success", ""), new String[][]{{"%amount%", amount + ""}}); - return; } - if (socket) { - if (name.equals("")) { + + @Subcommand("gem") + @CommandCompletion("@players @gems @range:1-100") + public void giveGem(CommandSender sender, OnlinePlayer player, String id, @Default("1") int amount) { + if (id.equalsIgnoreCase("random")) { for (int i = 0; i < amount; i++) { - giveItem(sender, plugin.getSocketGemManager().getRandomSocketGem(true).toItemStack(1)); + giveItem(player.getPlayer(), + plugin.getSocketGemManager().getRandomSocketGem(true).toItemStack(1)); } sendMessage(sender, plugin.getSettings().getString("language.commands.spawn.gem-success", ""), new String[][]{{"%amount%", amount + ""}}); return; } - SocketGem sg = plugin.getSocketGemManager().getSocketGem(name); + SocketGem sg = plugin.getSocketGemManager().getSocketGem(id); if (sg == null) { sendMessage(sender, plugin.getSettings().getString("language.commands.spawn.gem-failure", "")); return; } for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(sg.toItemStack(1)); + player.getPlayer().getInventory().addItem(sg.toItemStack(1)); } sendMessage(sender, plugin.getSettings().getString("language.commands.spawn.gem-success", ""), new String[][]{{"%amount%", amount + ""}}); - return; } - if (enchantment) { - if (name.equals("")) { + + @Subcommand("unique") + @CommandCompletion("@players @uniques @range:1-100") + public void giveUnique(CommandSender sender, OnlinePlayer player, String id, @Default("1") int amount) { + if (id.equalsIgnoreCase("random")) { for (int i = 0; i < amount; i++) { - sender.getInventory() - .addItem(plugin.getEnchantTomeManager().getRandomEnchantTome().toItemStack(1)); + giveItem(player.getPlayer(), + plugin.getCustomItemManager().getRandomCustomItem(true).toItemStack(1)); } sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.stone-success", ""), + plugin.getSettings().getString("language.commands.spawn.custom-success", ""), new String[][]{{"%amount%", amount + ""}}); return; } - EnchantmentTome es = plugin.getEnchantTomeManager().getEnchantTome(name); - if (es == null) { + CustomItem ci = plugin.getCustomItemManager().getCustomItem(id); + if (ci == null) { sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.stone-failure", "")); + plugin.getSettings().getString("language.commands.spawn.custom-failure", "")); return; } for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(es.toItemStack(1)); + player.getPlayer().getInventory().addItem(ci.toItemStack(1)); } sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.stone-success", ""), - new String[][]{{"%amount%", amount + ""}}); - return; - } - if (socketExtender) { - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(new SocketExtender()); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.socket-extender", ""), - new String[][]{{"%amount%", amount + ""}}); - return; - } - if (unidentified) { - for (int i = 0; i < amount; i++) { - Tier t = plugin.getTierManager().getRandomTier(); - Material[] array = t.getAllowedMaterials() - .toArray(new Material[t.getAllowedMaterials().size()]); - Material m = array[random.nextInt(array.length)]; - if (plugin.getSettings().getBoolean("config.beast.beast-mode-activate", false)) { - sender.getInventory().addItem(new UnidentifiedItem(m, random.nextInt(100))); - } else { - sender.getInventory().addItem(new UnidentifiedItem(m, -1)); - } - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.unidentified-item", ""), - new String[][]{{"%amount%", amount + ""}}); - return; - } - if (tome) { - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(new IdentityTome()); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.identity-tome", ""), + plugin.getSettings().getString("language.commands.spawn.custom-success", ""), new String[][]{{"%amount%", amount + ""}}); - return; - } - if (tier) { - if (name.equals("")) { - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem( - plugin.getNewItemBuilder().withItemGenerationReason(ItemGenerationReason.COMMAND) - .build() - .getStack()); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.other-success", ""), - new String[][]{{"%amount%", amount + ""}}); - } else { - Tier t = plugin.getTierManager().getTier(name); - if (t == null) { - sendMessage( - sender, plugin.getSettings().getString("language.commands.spawn.other-failure", "")); - return; - } - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(plugin.getNewItemBuilder().withTier(t).build().getStack()); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.other-success", ""), - new String[][]{{"%amount%", amount + ""}}); - } - return; } - if (upgradeScroll) { - if (name.equals("")) { + + @Subcommand("scroll") + @CommandCompletion("@players @scrolls @range:1-100") + public void giveScroll(CommandSender sender, OnlinePlayer player, String id, @Default("1") int amount) { + if (id.equalsIgnoreCase("random")) { for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(plugin.getScrollManager() + player.getPlayer().getInventory().addItem(plugin.getScrollManager() .buildItemStack(plugin.getScrollManager().getRandomScroll())); } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.upgrade-scroll", ""), + sendMessage(sender, plugin.getSettings() + .getString("language.commands.spawn.upgrade-scroll", ""), new String[][]{{"%amount%", amount + ""}}); return; } - UpgradeScroll scroll = plugin.getScrollManager().getScroll(name); + UpgradeScroll scroll = plugin.getScrollManager().getScroll(id); if (scroll == null) { - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.other-failure", "")); + sendMessage(sender, plugin.getSettings() + .getString("language.commands.spawn.other-failure", "")); return; } for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(plugin.getScrollManager().buildItemStack(scroll)); + player.getPlayer().getInventory().addItem(plugin.getScrollManager().buildItemStack(scroll)); } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.upgrade-scroll", "")); - return; + sendMessage(sender, plugin.getSettings() + .getString("language.commands.spawn.upgrade-scroll", "")); } - for (int i = 0; i < amount; i++) { - giveItem(sender, plugin.getNewItemBuilder() - .withItemGenerationReason(ItemGenerationReason.COMMAND) - .withLevel(sender.getLevel()) - .withTier(plugin.getTierManager().getRandomTier()) - .withRarity(plugin.getRarityManager().getRandomRarity()) - .build().getStack()); - } - sendMessage(sender, plugin.getSettings().getString("language.commands.spawn.other-success", ""), - new String[][]{{"%amount%", amount + ""}}); - } - - @Command(identifier = "loot materials", permissions = "loot.command.spawn", onlyPlayers = false) - public void reward(CommandSender sender, @Arg(name = "target") Player target, - @Arg(name = "itemLevel", def = "1") int itemLevel, - @Arg(name = "itemQuality", def = "1") int quality) { - - quality = Math.min(5, Math.max(quality, 1)); - for (Material m : plugin.getCraftMatManager().getCraftMaterials().keySet()) { - ItemStack itemStack = MaterialUtil.buildMaterial(m, - plugin.getCraftMatManager().getCraftMaterials().get(m), itemLevel, quality); - target.getInventory().addItem(itemStack); - } - } - - @Command(identifier = "loot give purify", permissions = "loot.command.spawn", onlyPlayers = false) - public void givePurify(CommandSender sender, @Arg(name = "target") Player target, - @Arg(name = "amount", def = "1") int amount) { - - ItemStack scroll = PurifyingScroll.get(); - scroll.setAmount(amount); - target.getInventory().addItem(scroll); - } - - @Command(identifier = "loot give enhance", permissions = "loot.command.spawn", onlyPlayers = false) - public void giveEnhance(CommandSender sender, @Arg(name = "target") Player target, - @Arg(name = "amount", def = "1") int amount) { - - ItemStack enhancer = ArcaneEnhancer.get(); - enhancer.setAmount(amount); - target.getInventory().addItem(enhancer); - } - - @Command(identifier = "loot simulate", permissions = "loot.command.simulate") - @Flags(identifier = {"c", "s", "t", "e", "se", "u", "id", "us", "rp"}, - description = {"custom", "socket gem", "tier", "enchantment", "socket extender", - "unidentified", "tome", - "upgrade scroll", "reveal powder"}) - public void simulateCommand(Player sender, @Arg(name = "amount", def = "1") int amount, - @Arg(name = "name", def = "") String name, - @FlagArg("c") boolean custom, - @FlagArg("s") boolean socket, - @FlagArg("t") boolean tier, - @FlagArg("e") boolean enchantment, - @FlagArg("se") boolean socketExtender, - @FlagArg("u") boolean unidentified, - @FlagArg("id") boolean tome, - @FlagArg("us") boolean upgradeScroll) { - double distanceFromSpawnSquared = sender.getLocation() - .distanceSquared(sender.getWorld().getSpawnLocation()); - if (custom) { - if (name.equals("")) { - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem( - plugin.getCustomItemManager().getRandomCustomItem(true, distanceFromSpawnSquared) - .toItemStack(1)); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.custom-success", ""), - new String[][]{{"%amount%", amount + ""}}); - } else { - CustomItem ci = plugin.getCustomItemManager().getCustomItem(name); - if (ci == null) { - sendMessage( - sender, plugin.getSettings().getString("language.commands.spawn.custom-failure", "")); - return; - } - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(ci.toItemStack(1)); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.custom-success", ""), - new String[][]{{"%amount%", amount + ""}}); - } - } else if (socket) { - if (name.equals("")) { - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem( - plugin.getSocketGemManager().getRandomSocketGem(true, distanceFromSpawnSquared) - .toItemStack(1)); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.gem-success", ""), - new String[][]{{"%amount%", amount + ""}}); - } else { - SocketGem sg = plugin.getSocketGemManager().getSocketGem(name); - if (sg == null) { - sendMessage( - sender, plugin.getSettings().getString("language.commands.spawn.gem-failure", "")); - return; - } - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(sg.toItemStack(1)); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.gem-success", ""), - new String[][]{{"%amount%", amount + ""}}); - } - } else if (enchantment) { - if (name.equals("")) { - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem( - plugin.getEnchantTomeManager().getRandomEnchantTome().toItemStack(1)); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.stone-success", ""), - new String[][]{{"%amount%", amount + ""}}); - } else { - EnchantmentTome es = plugin.getEnchantTomeManager().getEnchantTome(name); - if (es == null) { - sendMessage( - sender, plugin.getSettings().getString("language.commands.spawn.stone-failure", "")); - return; - } - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(es.toItemStack(1)); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.stone-success", ""), - new String[][]{{"%amount%", amount + ""}}); - } - } else if (socketExtender) { + @Subcommand("extender") + @CommandCompletion("@players @range:1-100") + public void giveExtender(CommandSender sender, OnlinePlayer player, @Default("1") int amount) { for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(new SocketExtender()); + player.getPlayer().getInventory().addItem(new SocketExtender()); } sendMessage(sender, plugin.getSettings().getString("language.commands.spawn.socket-extender", ""), new String[][]{{"%amount%", amount + ""}}); - } else if (unidentified) { + } + + @Subcommand("tinker") + @CommandCompletion("@players @range:1-100") + public void giveTinker(CommandSender sender, OnlinePlayer player, @Default("1") int amount) { for (int i = 0; i < amount; i++) { - Tier t = plugin.getTierManager().getRandomTier(); - Material[] array = t.getAllowedMaterials() - .toArray(new Material[t.getAllowedMaterials().size()]); - Material m = array[random.nextInt(array.length)]; - if (plugin.getSettings().getBoolean("config.beast.beast-mode-activate", false)) { - sender.getInventory().addItem(new UnidentifiedItem(m, random.nextInt(100))); - } else { - sender.getInventory().addItem(new UnidentifiedItem(m, -1)); - } + player.getPlayer().getInventory().addItem(TinkerersGear.get()); } sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.unidentified-item", ""), + plugin.getSettings().getString("language.commands.spawn.tinker-gear", ""), new String[][]{{"%amount%", amount + ""}}); - } else if (tome) { + } + + @Subcommand("enhancer") + @CommandCompletion("@players @range:1-100") + public void giveEnhancer(CommandSender sender, OnlinePlayer player, @Default("1") int amount) { for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(new IdentityTome()); + player.getPlayer().getInventory().addItem(ArcaneEnhancer.get()); } sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.identity-tome", ""), - new String[][]{{"%amount%", amount + ""}}); - } else if (tier) { - if (name.equals("")) { - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem( - plugin.getNewItemBuilder().withItemGenerationReason(ItemGenerationReason.COMMAND) - .build().getStack()); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.other-success", ""), - new String[][]{{"%amount%", amount + ""}}); - } else { - Tier t = plugin.getTierManager().getTier(name); - if (t == null) { - sendMessage( - sender, plugin.getSettings().getString("language.commands.spawn.other-failure", "")); - return; - } - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem( - plugin.getNewItemBuilder().withItemGenerationReason(ItemGenerationReason.COMMAND) - .build().getStack()); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.other-success", ""), - new String[][]{{"%amount%", amount + ""}}); - } - } else if (upgradeScroll) { - if (name.equals("")) { - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(plugin.getScrollManager() - .buildItemStack(plugin.getScrollManager().getRandomScroll())); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.upgrade-scroll", ""), - new String[][]{{"%amount%", amount + ""}}); - } else { - UpgradeScroll scroll = plugin.getScrollManager().getScroll(name); - if (scroll == null) { - sendMessage( - sender, plugin.getSettings().getString("language.commands.spawn.other-failure", "")); - return; - } - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem(plugin.getScrollManager().buildItemStack(scroll)); - } - sendMessage( - sender, plugin.getSettings().getString("language.commands.spawn.upgrade-scroll", "")); - } - } else { - for (int i = 0; i < amount; i++) { - sender.getInventory().addItem( - plugin.getNewItemBuilder().withItemGenerationReason(ItemGenerationReason.COMMAND) - .build().getStack()); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.other-success", ""), + plugin.getSettings().getString("language.commands.spawn.arcane-enhancer", ""), new String[][]{{"%amount%", amount + ""}}); } } - @Command(identifier = "loot give", permissions = "loot.command.give", onlyPlayers = false) - @Flags(identifier = {"c", "s", "t", "e", "se", "u", "id", "us", "rp"}, - description = {"custom", "socket gem", "tier", "enchantment", "socket extender", - "unidentified", "tome", - "upgrade scroll", "reveal powder"}) - public void giveCommand(CommandSender sender, - @Arg(name = "player") Player target, - @Arg(name = "amount", def = "1") int amount, - @Arg(name = "name", def = "") String name, - @FlagArg("c") boolean custom, - @FlagArg("s") boolean socket, - @FlagArg("t") boolean tier, - @FlagArg("e") boolean enchantment, - @FlagArg("se") boolean socketExtender, - @FlagArg("u") boolean unidentified, - @FlagArg("id") boolean tome, - @FlagArg("us") boolean upgradeScroll) { - if (custom) { - if (name.equals("")) { - for (int i = 0; i < amount; i++) { - giveItem(target, plugin.getCustomItemManager().getRandomCustomItem(true).toItemStack(1)); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.custom-success", ""), - new String[][]{{"%amount%", amount + ""}}); - } else { - CustomItem ci = plugin.getCustomItemManager().getCustomItem(name); - if (ci == null) { - sendMessage( - sender, plugin.getSettings().getString("language.commands.spawn.custom-failure", "")); - sendMessage(target, plugin.getSettings().getString("language.commands.give.failure", "")); - target.updateInventory(); - return; - } - for (int i = 0; i < amount; i++) { - target.getInventory().addItem(ci.toItemStack(1)); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.custom-success", ""), - new String[][]{{"%amount%", amount + ""}}); - sendMessage(target, plugin.getSettings().getString("language.commands.give.receive", "")); - } - } else if (socket) { - if (name.equals("")) { - for (int i = 0; i < amount; i++) { - target.getInventory().addItem( - plugin.getSocketGemManager().getRandomSocketGem(true).toItemStack(1)); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.gem-success", ""), - new String[][]{{"%amount%", amount + ""}}); - sendMessage(target, - plugin.getSettings().getString("language.commands.spawn.gem-success", ""), - new String[][]{{"%amount%", amount + ""}}); - } else { - SocketGem sg = plugin.getSocketGemManager().getSocketGem(name); - if (sg == null) { - sendMessage( - sender, plugin.getSettings().getString("language.commands.spawn.gem-failure", "")); - sendMessage(target, plugin.getSettings().getString("language.commands.give.failure", "")); - target.updateInventory(); - return; - } - for (int i = 0; i < amount; i++) { - target.getInventory().addItem(sg.toItemStack(1)); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.gem-success", ""), - new String[][]{{"%amount%", amount + ""}}); - sendMessage(target, plugin.getSettings().getString("language.commands.give.receive", "")); - } - } else if (enchantment) { - if (name.equals("")) { - for (int i = 0; i < amount; i++) { - target.getInventory().addItem( - plugin.getEnchantTomeManager().getRandomEnchantTome().toItemStack(1)); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.stone-success", ""), - new String[][]{{"%amount%", amount + ""}}); - sendMessage(target, plugin.getSettings().getString("language.commands.give.receive", "")); - } else { - EnchantmentTome es = plugin.getEnchantTomeManager().getEnchantTome(name); - if (es == null) { - sendMessage( - sender, plugin.getSettings().getString("language.commands.spawn.stone-failure", "")); - sendMessage(target, plugin.getSettings().getString("language.commands.give.failure", "")); - target.updateInventory(); - return; - } - for (int i = 0; i < amount; i++) { - target.getInventory().addItem(es.toItemStack(1)); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.stone-success", ""), - new String[][]{{"%amount%", amount + ""}}); - sendMessage(target, plugin.getSettings().getString("language.commands.give.receive", "")); - } - } else if (socketExtender) { - for (int i = 0; i < amount; i++) { - target.getInventory().addItem(new SocketExtender()); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.socket-extender", ""), - new String[][]{{"%amount%", amount + ""}}); - sendMessage(target, plugin.getSettings().getString("language.commands.give.receive", "")); - } else if (unidentified) { - for (int i = 0; i < amount; i++) { - Tier t = plugin.getTierManager().getRandomTier(); - Material[] array = t.getAllowedMaterials() - .toArray(new Material[t.getAllowedMaterials().size()]); - Material m = array[random.nextInt(array.length)]; - if (plugin.getSettings().getBoolean("config.beast.beast-mode-activate", false)) { - target.getInventory().addItem(new UnidentifiedItem(m, random.nextInt(100))); - } else { - target.getInventory().addItem(new UnidentifiedItem(m, -1)); - } - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.unidentified-item", ""), - new String[][]{{"%amount%", amount + ""}}); - sendMessage(target, plugin.getSettings().getString("language.commands.give.receive", "")); - } else if (tome) { - for (int i = 0; i < amount; i++) { - target.getInventory().addItem(new IdentityTome()); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.identity-tome", ""), - new String[][]{{"%amount%", amount + ""}}); - sendMessage(target, plugin.getSettings().getString("language.commands.give.receive", "")); - } else if (tier) { - if (name.equals("")) { - for (int i = 0; i < amount; i++) { - plugin.getNewItemBuilder() - .withTier(plugin.getTierManager().getRandomTier()) - .withRarity(plugin.getRarityManager().getRandomRarity()) - .withLevel(random.nextIntRange(1, 100)) - .withItemGenerationReason(ItemGenerationReason.COMMAND).build(); - giveItem(target, - plugin.getNewItemBuilder().withItemGenerationReason(ItemGenerationReason.COMMAND) - .build().getStack()); - target.getInventory().addItem(); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.other-success", ""), - new String[][]{{"%amount%", amount + ""}}); - sendMessage(target, plugin.getSettings().getString("language.commands.give.receive", "")); - } else { - Tier t = plugin.getTierManager().getTier(name); - ItemRarity r = plugin.getRarityManager().getRandomRarity(); - if (t == null) { - sendMessage( - sender, plugin.getSettings().getString("language.commands.spawn.other-failure", "")); - sendMessage(target, plugin.getSettings().getString("language.commands.give.failure", "")); - target.updateInventory(); - return; - } - for (int i = 0; i < amount; i++) { - target.getInventory() - .addItem(plugin.getNewItemBuilder().withTier(t).withRarity(r).build().getStack()); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.other-success", ""), - new String[][]{{"%amount%", amount + ""}}); - sendMessage(target, plugin.getSettings().getString("language.commands.give.receive", "")); - } - } else if (upgradeScroll) { - if (name.equals("")) { - for (int i = 0; i < amount; i++) { - UpgradeScroll scroll = plugin.getScrollManager().getRandomScroll(); - target.getInventory().addItem(plugin.getScrollManager().buildItemStack(scroll)); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.upgrade-scroll", ""), - new String[][]{{"%amount%", amount + ""}}); - sendMessage(target, plugin.getSettings().getString("language.commands.give.receive", "")); - } else { - UpgradeScroll scroll = plugin.getScrollManager().getScroll(name); - if (scroll == null) { - sendMessage( - sender, plugin.getSettings().getString("language.commands.spawn.other-failure", "")); - target.updateInventory(); - return; - } - for (int i = 0; i < amount; i++) { - target.getInventory().addItem(plugin.getScrollManager().buildItemStack(scroll)); - } - sendMessage( - sender, plugin.getSettings().getString("language.commands.spawn.upgrade-scroll", "")); - sendMessage(target, plugin.getSettings().getString("language.commands.give.receive", "")); - } - } else { - for (int i = 0; i < amount; i++) { - target.getInventory().addItem( - plugin.getNewItemBuilder() - .withLevel(random.nextIntRange(1, 100)) - .withRarity(plugin.getRarityManager().getRandomRarity()) - .withTier(plugin.getTierManager().getRandomTier()) - .withItemGenerationReason(ItemGenerationReason.COMMAND).build().getStack()); - } - sendMessage(sender, - plugin.getSettings().getString("language.commands.spawn.other-success", ""), - new String[][]{{"%amount%", amount + ""}}); - sendMessage(target, plugin.getSettings().getString("language.commands.give.receive", "")); + @Subcommand("materials") + @CommandCompletion("@players @range:1-100 @range:1-100") + @CommandPermission("loot.give") + public void materials(CommandSender sender, Player target, int itemLevel, int quality) { + + quality = Math.min(5, Math.max(quality, 1)); + + for (Material m : plugin.getCraftMatManager().getCraftMaterials().keySet()) { + ItemStack itemStack = MaterialUtil.buildMaterial(m, + plugin.getCraftMatManager().getCraftMaterials().get(m), itemLevel, quality); + target.getInventory().addItem(itemStack); } } - @Command(identifier = "loot reload", permissions = "loot.command.reload", onlyPlayers = false) + @Subcommand("reload") + @CommandPermission("loot.reload") public void reloadSubcommand(CommandSender sender) { plugin.disable(); plugin.enable(); @@ -712,26 +291,42 @@ public void reloadSubcommand(CommandSender sender) { plugin.getSettings().getString("language.command.reload", "&aLoot reloaded!")); } - @Command(identifier = "loot upgrade", permissions = "loot.command.reload") - public void upgradeSubcommand(CommandSender sender, @Arg(name = "player") Player target) { - if (target == null || !target.isValid()) { + @Subcommand("upgrade") + @CommandCompletion("@players") + @CommandPermission("loot.upgrade") + public void upgradeSubcommand(CommandSender sender, OnlinePlayer target) { + if (target == null || !target.getPlayer().isValid()) { return; } EnchantMenu menu = new EnchantMenu(plugin); - menu.open(target); + menu.open(target.getPlayer()); } - @Command(identifier = "loot pawn", permissions = "loot.command.reload", onlyPlayers = false) - public void pawnSubcommand(CommandSender sender, @Arg(name = "player") Player target) { - if (target == null || !target.isValid()) { + @Subcommand("pawn") + @CommandCompletion("@players") + @CommandPermission("loot.pawn") + public void pawnSubcommand(CommandSender sender, OnlinePlayer target) { + if (target == null || !target.getPlayer().isValid()) { return; } PawnMenu menu = PawnMenu.getPawnMenu(plugin); - menu.open(target); + menu.open(target.getPlayer()); + } + + @Subcommand("inspectBreakKeys") + @CommandPermission("loot.inspect") + public void inspectKeys(Player sender) { + ItemStack stack = sender.getEquipment().getItemInMainHand(); + for (Namespaced k : stack.getItemMeta().getDestroyableKeys()) { + sendMessage(sender, "key: " + k.getKey()); + sendMessage(sender, "namespace: " + k.getNamespace()); + } } - @Command(identifier = "loot renametag", permissions = "loot.command.renametag", onlyPlayers = true) - public void renameSubcommand(Player sender, @Arg(name = "item name") @Wildcard String newLore) { + @Subcommand("rename") + @CommandCompletion("@players") + @CommandPermission("loot.rename") + public void renameSubcommand(Player sender, String newLore) { ItemStack heldItem = new ItemStack(sender.getEquipment().getItemInMainHand()); if (heldItem.getType() != Material.NAME_TAG) { sendMessage(sender, plugin.getSettings().getString("language.command.renamefail", "")); diff --git a/src/main/java/info/faceland/loot/items/LootCustomItem.java b/src/main/java/info/faceland/loot/items/LootCustomItem.java index 6d0a61de..c061d991 100644 --- a/src/main/java/info/faceland/loot/items/LootCustomItem.java +++ b/src/main/java/info/faceland/loot/items/LootCustomItem.java @@ -18,12 +18,16 @@ */ package info.faceland.loot.items; +import com.destroystokyo.paper.Namespaced; import com.tealcube.minecraft.bukkit.TextUtils; import info.faceland.loot.api.items.CustomItem; import io.pixeloutlaw.minecraft.spigot.hilt.ItemStackExtensionsKt; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attribute; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -42,6 +46,8 @@ public final class LootCustomItem implements CustomItem { private int customDataNumber; private boolean broadcast; private boolean quality; + private Set flags; + private Set canBreak; public LootCustomItem(String name, Material material) { this.name = name; @@ -96,6 +102,23 @@ public ItemStack toItemStack(int amount) { if (customDataNumber != -1) { ItemStackExtensionsKt.setCustomModelData(itemStack, customDataNumber); } + if (!canBreak.isEmpty()) { + ItemMeta iMeta = itemStack.getItemMeta(); + Set breakSpaces = new HashSet<>(); + for (String s : canBreak) { + breakSpaces.add(NamespacedKey.minecraft(s)); + } + iMeta.setDestroyableKeys(breakSpaces); + iMeta.addItemFlags(ItemFlag.HIDE_DESTROYS); + itemStack.setItemMeta(iMeta); + } + if (!flags.isEmpty()) { + ItemMeta iMeta = itemStack.getItemMeta(); + for (ItemFlag flag : flags) { + iMeta.addItemFlags(flag); + } + itemStack.setItemMeta(iMeta); + } return itemStack; } @@ -154,6 +177,22 @@ public boolean canBeQuality() { return quality; } + public Set getFlags() { + return flags; + } + + public void setFlags(Set flags) { + this.flags = flags; + } + + public Set getCanBreak() { + return canBreak; + } + + public void setCanBreak(Set canBreak) { + this.canBreak = canBreak; + } + void setBroadcast(boolean broadcast) { this.broadcast = broadcast; } diff --git a/src/main/java/info/faceland/loot/items/LootCustomItemBuilder.java b/src/main/java/info/faceland/loot/items/LootCustomItemBuilder.java index 1330a67d..768d6c1a 100644 --- a/src/main/java/info/faceland/loot/items/LootCustomItemBuilder.java +++ b/src/main/java/info/faceland/loot/items/LootCustomItemBuilder.java @@ -1,108 +1,117 @@ /** - * The MIT License - * Copyright (c) 2015 Teal Cube Games + * 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 + * 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 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. + * 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; import info.faceland.loot.api.items.CustomItem; import info.faceland.loot.api.items.CustomItemBuilder; -import org.bukkit.Material; - import java.util.List; +import java.util.Set; +import org.bukkit.Material; +import org.bukkit.inventory.ItemFlag; public final class LootCustomItemBuilder implements CustomItemBuilder { - private boolean built = false; - private LootCustomItem customItem; - - public LootCustomItemBuilder(String name, Material material) { - this.customItem = new LootCustomItem(name, material); - } - - @Override - public boolean isBuilt() { - return built; - } - - @Override - public CustomItem build() { - if (isBuilt()) { - throw new IllegalStateException("already built"); - } - this.built = true; - return customItem; - } + private boolean built = false; + private LootCustomItem customItem; - @Override - public CustomItemBuilder withDisplayName(String displayName) { - customItem.setDisplayName(displayName); - return this; - } - - @Override - public CustomItemBuilder withLore(List lore) { - customItem.setLore(lore); - return this; - } + public LootCustomItemBuilder(String name, Material material) { + this.customItem = new LootCustomItem(name, material); + } - @Override - public CustomItemBuilder withWeight(double d) { - customItem.setWeight(d); - return this; - } - - @Override - public CustomItemBuilder withDistanceWeight(double d) { - customItem.setDistanceWeight(d); - return this; - } - - @Override - public CustomItemBuilder withLevelBase(int i) { - customItem.setLevelBase(i); - return this; - } - - @Override - public CustomItemBuilder withLevelRange(int i) { - customItem.setLevelRange(i); - return this; - } - - @Override - public CustomItemBuilder withCustomData(int i) { - customItem.setCustomDataNumber(i); - return this; - } - - @Override - public CustomItemBuilder withBroadcast(boolean b) { - customItem.setBroadcast(b); - return this; - } + @Override + public boolean isBuilt() { + return built; + } - @Override - public CustomItemBuilder withQuality(boolean b) { - customItem.setQuality(b); - return this; + @Override + public CustomItem build() { + if (isBuilt()) { + throw new IllegalStateException("already built"); } + this.built = true; + return customItem; + } + + @Override + public CustomItemBuilder withDisplayName(String displayName) { + customItem.setDisplayName(displayName); + return this; + } + + @Override + public CustomItemBuilder withLore(List lore) { + customItem.setLore(lore); + return this; + } + + @Override + public CustomItemBuilder withWeight(double d) { + customItem.setWeight(d); + return this; + } + + @Override + public CustomItemBuilder withDistanceWeight(double d) { + customItem.setDistanceWeight(d); + return this; + } + + @Override + public CustomItemBuilder withLevelBase(int i) { + customItem.setLevelBase(i); + return this; + } + + @Override + public CustomItemBuilder withLevelRange(int i) { + customItem.setLevelRange(i); + return this; + } + + @Override + public CustomItemBuilder withCustomData(int i) { + customItem.setCustomDataNumber(i); + return this; + } + + @Override + public CustomItemBuilder withBroadcast(boolean b) { + customItem.setBroadcast(b); + return this; + } + + @Override + public CustomItemBuilder withQuality(boolean b) { + customItem.setQuality(b); + return this; + } + + @Override + public CustomItemBuilder withFlags(Set flags) { + customItem.setFlags(flags); + return this; + } + + @Override + public CustomItemBuilder withCanBreak(Set keys) { + customItem.setCanBreak(keys); + return this; + } } diff --git a/src/main/java/info/faceland/loot/items/prefabs/TinkerersGear.java b/src/main/java/info/faceland/loot/items/prefabs/TinkerersGear.java new file mode 100644 index 00000000..8d4a54f4 --- /dev/null +++ b/src/main/java/info/faceland/loot/items/prefabs/TinkerersGear.java @@ -0,0 +1,58 @@ +/** + * 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. + */ +package info.faceland.loot.items.prefabs; + +import com.tealcube.minecraft.bukkit.TextUtils; +import info.faceland.loot.utils.MaterialUtil; +import io.pixeloutlaw.minecraft.spigot.hilt.ItemStackExtensionsKt; +import java.util.Arrays; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +public final class TinkerersGear { + + private static ItemStack item; + private static String TINKER_NAME = ChatColor.RED + "Tinkerer's Gear"; + + public static void rebuild() { + ItemStack stack = new ItemStack(Material.BRICK); + ItemStackExtensionsKt.setDisplayName(stack, ChatColor.RED + "Tinkerer's Gear"); + ItemStackExtensionsKt.setLore(stack, TextUtils.color(Arrays.asList( + "&7This perplexing gear can be", + "&7used on an equipment item to", + "&7turn one random &agreen&7/&eyellow", + "&7stat into an &bEssence Slot&7!", + "&8&oA strange item that seems to", + "&8&obe more science than magic..." + ))); + stack.setDurability((short) 12); + ItemStackExtensionsKt.setCustomModelData(stack, 3000); + item = stack; + } + + public static boolean isSimilar(ItemStack stack) { + return stack.getType() == item.getType() && MaterialUtil.getCustomData(stack) == 3000 && TINKER_NAME + .equals(ItemStackExtensionsKt.getDisplayName(stack)); + } + + public static ItemStack get() { + return item.clone(); + } +} diff --git a/src/main/java/info/faceland/loot/listeners/DeconstructListener.java b/src/main/java/info/faceland/loot/listeners/DeconstructListener.java index 7a1a9c32..f40a1099 100644 --- a/src/main/java/info/faceland/loot/listeners/DeconstructListener.java +++ b/src/main/java/info/faceland/loot/listeners/DeconstructListener.java @@ -262,14 +262,14 @@ public static int getLevelAdvantage(int craftLevel, int itemLevel) { return lvlReq - itemLevel; } - private boolean isValidStealColor(Color color) { + public static 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}"); + private static final Pattern hexPattern = Pattern.compile("§x(§[A-Fa-f0-9]){6}"); - public net.md_5.bungee.api.ChatColor getHexFromString(String message) { + public static net.md_5.bungee.api.ChatColor getHexFromString(String message) { Matcher matcher = hexPattern.matcher(message); if (matcher.find()) { String str = "#" + matcher.group().replace("§x", "").replace("§", ""); diff --git a/src/main/java/info/faceland/loot/listeners/InteractListener.java b/src/main/java/info/faceland/loot/listeners/InteractListener.java index e50f52c0..b5e39cd0 100644 --- a/src/main/java/info/faceland/loot/listeners/InteractListener.java +++ b/src/main/java/info/faceland/loot/listeners/InteractListener.java @@ -1,23 +1,26 @@ /** * 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: + * 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 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. + * 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; import static com.tealcube.minecraft.bukkit.facecore.utilities.MessageUtils.sendMessage; -import static info.faceland.loot.utils.InventoryUtil.broadcast; +import static info.faceland.loot.listeners.DeconstructListener.getHexFromString; +import static info.faceland.loot.listeners.DeconstructListener.isValidStealColor; import static info.faceland.loot.utils.InventoryUtil.getFirstColor; import static info.faceland.loot.utils.InventoryUtil.getLastColor; import static info.faceland.loot.utils.MaterialUtil.FAILURE_BONUS; @@ -33,6 +36,7 @@ import info.faceland.loot.data.ItemRarity; import info.faceland.loot.data.UpgradeScroll; import info.faceland.loot.items.prefabs.ShardOfFailure; +import info.faceland.loot.items.prefabs.TinkerersGear; import info.faceland.loot.math.LootRandom; import info.faceland.loot.menu.upgrade.EnchantMenu; import info.faceland.loot.sockets.SocketGem; @@ -42,8 +46,10 @@ import io.pixeloutlaw.minecraft.spigot.garbage.StringExtensionsKt; import io.pixeloutlaw.minecraft.spigot.hilt.ItemStackExtensionsKt; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; import land.face.strife.data.champion.LifeSkillType; @@ -164,11 +170,14 @@ public void onPlayerDropItem(PlayerDropItemEvent e) { @EventHandler(priority = EventPriority.HIGHEST) public void onQuickShard(InventoryClickEvent event) { - if (event.getClick() != ClickType.SHIFT_RIGHT || !(event.getClickedInventory() instanceof PlayerInventory)) { + 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)) { + if (event.getCurrentItem() == null || event.getCursor() == null + || event.getCurrentItem().getType() == Material.AIR + || event.getCursor().getType() == Material.AIR || !(event + .getWhoClicked() instanceof Player)) { return; } @@ -213,7 +222,8 @@ public void onQuickShard(InventoryClickEvent event) { @EventHandler(priority = EventPriority.HIGHEST) public void onRightClickUse(InventoryClickEvent event) { - if (event.getClick() != ClickType.RIGHT || !(event.getClickedInventory() instanceof PlayerInventory)) { + if (event.getClick() != ClickType.RIGHT || !(event + .getClickedInventory() instanceof PlayerInventory)) { return; } if (event.getCurrentItem() == null || event.getCursor() == null || @@ -312,7 +322,7 @@ public void onRightClickUse(InventoryClickEvent event) { .withLevel(itemLevel) .build().getStack(); if (r.isBroadcast()) { - broadcast(player, targetItem, + InventoryUtil.sendToDiscord(player, targetItem, plugin.getSettings().getString("language.broadcast.ided-item")); } sendMessage(player, plugin.getSettings().getString("language.identify.success", "")); @@ -382,80 +392,138 @@ public void onRightClickUse(InventoryClickEvent event) { plugin.getStrifePlugin().getSkillExperienceManager().addExperience(player, 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", "")); - return; - } - if (isBannedMaterial(targetItem)) { - sendMessage(player, plugin.getSettings().getString("language.rename.invalid", "")); - return; + doItemRenameEffects(targetItem, cursor, targetItemName, player, event); + } else if (cursorName.startsWith(ChatColor.DARK_PURPLE + "Magic Crystal")) { + doRechargeEffects(targetItem, player, event); + } else if (TinkerersGear.isSimilar(cursor)) { + doTinkerEffects(targetItem, player, event); + } + } + + private void doItemRenameEffects(ItemStack targetItem, ItemStack cursor, String targetItemName, + Player player, InventoryClickEvent event) { + if (ItemStackExtensionsKt.getLore(cursor).get(3).equals(ChatColor.WHITE + "none")) { + sendMessage(player, plugin.getSettings().getString("language.rename.notset", "")); + return; + } + if (isBannedMaterial(targetItem)) { + sendMessage(player, plugin.getSettings().getString("language.rename.invalid", "")); + return; + } + if (targetItem.hasItemMeta() && targetItem.getItemMeta().hasLore()) { + for (String s : ItemStackExtensionsKt.getLore(targetItem)) { + if ("[ Crafting Component ]".equals(stripColor(s))) { + sendMessage(player, plugin.getSettings().getString("language.rename.invalid", "")); + return; + } } - if (targetItem.hasItemMeta() && targetItem.getItemMeta().hasLore()) { - for (String s : ItemStackExtensionsKt.getLore(targetItem)) { - if ("[ Crafting Component ]".equals(stripColor(s))) { - sendMessage(player, plugin.getSettings().getString("language.rename.invalid", "")); + } + int level = stripColor(targetItemName).startsWith("+") ? + MaterialUtil.getDigit(targetItemName) : 0; + if (level > 0) { + ItemStackExtensionsKt.setDisplayName( + targetItem, getFirstColor(targetItemName) + "+" + level + " " + + stripColor(ItemStackExtensionsKt.getLore(cursor).get(3))); + } else { + ItemStackExtensionsKt.setDisplayName( + targetItem, getFirstColor(targetItemName) + + stripColor(ItemStackExtensionsKt.getLore(cursor).get(3))); + } + + sendMessage(player, plugin.getSettings().getString("language.rename.success", "")); + player.playSound(player.getEyeLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 0.8F); + updateItem(event, targetItem); + } + + private void doRechargeEffects(ItemStack targetItem, Player player, InventoryClickEvent event) { + List lore = ItemStackExtensionsKt.getLore(targetItem); + boolean valid = false; + int index = 0; + int addAmount = 0; + for (String str : ItemStackExtensionsKt.getLore(targetItem)) { + if (str.startsWith(ChatColor.BLUE + "[")) { + if (str.contains("" + ChatColor.BLACK)) { + valid = true; + int barIndex = str.indexOf("" + ChatColor.BLACK); + if (barIndex == str.length() - 5) { + sendMessage(player, plugin.getSettings().getString("language.enchant.full", "")); return; } + double enchantLevel = PlayerDataUtil + .getLifeSkillLevel(player, LifeSkillType.ENCHANTING); + double itemLevel = MaterialUtil.getLevelRequirement(targetItem); + addAmount = + 2 + (int) (random.nextDouble() * (2 + Math + .max(0, (enchantLevel - itemLevel) * 0.2))); + str = str.replace("" + ChatColor.BLACK, ""); + str = new StringBuilder(str) + .insert(Math.min(str.length() - 3, barIndex + addAmount), ChatColor.BLACK + "") + .toString(); + lore.set(index, str); + } else if (str.contains("" + ChatColor.DARK_RED)) { + sendMessage(player, TextUtils.color(plugin.getSettings().getString( + "language.enchant.no-refill-enhanced", "you cant refill this enchant"))); + return; } } - int level = stripColor(targetItemName).startsWith("+") ? - MaterialUtil.getDigit(targetItemName) : 0; - if (level > 0) { - ItemStackExtensionsKt.setDisplayName( - targetItem, getFirstColor(targetItemName) + "+" + level + " " - + stripColor(ItemStackExtensionsKt.getLore(cursor).get(3))); - } else { - ItemStackExtensionsKt.setDisplayName( - targetItem, getFirstColor(targetItemName) - + stripColor(ItemStackExtensionsKt.getLore(cursor).get(3))); - } - - sendMessage(player, plugin.getSettings().getString("language.rename.success", "")); - player.playSound(player.getEyeLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 0.8F); + index++; + } + if (valid) { + ItemStackExtensionsKt.setLore(targetItem, lore); + plugin.getStrifePlugin().getSkillExperienceManager().addExperience(player, + LifeSkillType.ENCHANTING, 10f + addAmount, false, false); + sendMessage(player, plugin.getSettings().getString("language.enchant.refill", "")); + player.playSound(player.getEyeLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1.2F); + player.playSound(player.getEyeLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1F, 1F); updateItem(event, targetItem); - } else if (cursorName.startsWith(ChatColor.DARK_PURPLE + "Magic Crystal")) { - List lore = ItemStackExtensionsKt.getLore(targetItem); - boolean valid = false; - int index = 0; - int addAmount = 0; - for (String str : ItemStackExtensionsKt.getLore(targetItem)) { - if (str.startsWith(ChatColor.BLUE + "[")) { - if (str.contains("" + ChatColor.BLACK)) { - valid = true; - int barIndex = str.indexOf("" + ChatColor.BLACK); - if (barIndex == str.length() - 5) { - sendMessage(player, plugin.getSettings().getString("language.enchant.full", "")); - return; - } - double enchantLevel = PlayerDataUtil - .getLifeSkillLevel(player, LifeSkillType.ENCHANTING); - double itemLevel = MaterialUtil.getLevelRequirement(targetItem); - addAmount = - 2 + (int) (random.nextDouble() * (2 + Math - .max(0, (enchantLevel - itemLevel) * 0.2))); - str = str.replace("" + ChatColor.BLACK, ""); - str = new StringBuilder(str) - .insert(Math.min(str.length() - 3, barIndex + addAmount), ChatColor.BLACK + "") - .toString(); - lore.set(index, str); - } else if (str.contains("" + ChatColor.DARK_RED)) { - sendMessage(player, TextUtils.color(plugin.getSettings().getString( - "language.enchant.no-refill-enhanced", "you cant refill this enchant"))); - return; - } + } + } + + private void doTinkerEffects(ItemStack targetItem, Player player, InventoryClickEvent event) { + List lore = ItemStackExtensionsKt.getLore(targetItem); + Map validTargetStats = new HashMap<>(); + int loreIndex = -1; + for (String str : lore) { + loreIndex++; + if (str.startsWith(ChatColor.AQUA + "")) { + sendMessage(player, TextUtils.color(plugin.getSettings() + .getString("language.tinker.only-one-crafted-stat", "Only one stat can be tinkered!"))); + return; + } + if (!ChatColor.stripColor(str).startsWith("+")) { + continue; + } + net.md_5.bungee.api.ChatColor color = getHexFromString(str); + if (color != null) { + if (isValidStealColor(color.getColor())) { + validTargetStats.put(loreIndex, str); } - index++; + continue; } - if (valid) { - ItemStackExtensionsKt.setLore(targetItem, lore); - plugin.getStrifePlugin().getSkillExperienceManager().addExperience(player, - LifeSkillType.ENCHANTING, 10f + addAmount, false, false); - sendMessage(player, plugin.getSettings().getString("language.enchant.refill", "")); - player.playSound(player.getEyeLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1.2F); - player.playSound(player.getEyeLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 1F, 1F); - updateItem(event, targetItem); + if (str.startsWith(ChatColor.GREEN + "") || str.startsWith(ChatColor.YELLOW + "")) { + validTargetStats.put(loreIndex, str); } } + + if (validTargetStats.isEmpty()) { + sendMessage(player, TextUtils.color(plugin.getSettings() + .getString("language.tinker.no-valid-stats", "No valid stats to be tinkered!"))); + return; + } + + String essenceText = StringExtensionsKt.chatColorize( + plugin.getSettings().getString("config.crafting.essence-text", "&b(Essence Slot)")); + + List itemLore = new ArrayList<>(ItemStackExtensionsKt.getLore(targetItem)); + List keysAsArray = new ArrayList<>(validTargetStats.keySet()); + int selectedIndex = keysAsArray.get(random.nextInt(keysAsArray.size())); + itemLore.set(selectedIndex, essenceText); + ItemStackExtensionsKt.setLore(targetItem, itemLore); + + player.playSound(player.getEyeLocation(), Sound.BLOCK_PISTON_EXTEND, 1F, 1.5F); + plugin.getStrifePlugin().getSkillExperienceManager() + .addExperience(player, LifeSkillType.CRAFTING, 200, false, false); + updateItem(event, targetItem); } private void updateItem(InventoryClickEvent e, ItemStack currentItem) { diff --git a/src/main/java/info/faceland/loot/listeners/crafting/CraftingListener.java b/src/main/java/info/faceland/loot/listeners/crafting/CraftingListener.java index c281932c..2300ef6b 100644 --- a/src/main/java/info/faceland/loot/listeners/crafting/CraftingListener.java +++ b/src/main/java/info/faceland/loot/listeners/crafting/CraftingListener.java @@ -422,14 +422,7 @@ public void onEssenceInfuse(PrepareItemCraftEvent event) { return; } - List existingCraftStatStrings = new ArrayList<>(); - for (String str : lore) { - if (!str.startsWith(ChatColor.AQUA + "+")) { - continue; - } - str = CharMatcher.javaLetter().or(CharMatcher.is(' ')).retainFrom(ChatColor.stripColor(str).trim()); - existingCraftStatStrings.add(str); - } + List existingCraftStatStrings = MaterialUtil.getValidEssenceStats(lore); String essenceStat = getEssenceStat(essenceStack); String strippedStat = CharMatcher.javaLetter().or(CharMatcher.is(' ')) diff --git a/src/main/java/info/faceland/loot/listeners/sockets/CombinerListener.java b/src/main/java/info/faceland/loot/listeners/sockets/CombinerListener.java index 4850957c..fcf985c3 100644 --- a/src/main/java/info/faceland/loot/listeners/sockets/CombinerListener.java +++ b/src/main/java/info/faceland/loot/listeners/sockets/CombinerListener.java @@ -18,12 +18,11 @@ */ package info.faceland.loot.listeners.sockets; -import static info.faceland.loot.utils.InventoryUtil.broadcast; - import com.tealcube.minecraft.bukkit.TextUtils; import com.tealcube.minecraft.bukkit.facecore.utilities.MessageUtils; import info.faceland.loot.LootPlugin; import info.faceland.loot.sockets.SocketGem; +import info.faceland.loot.utils.InventoryUtil; import io.pixeloutlaw.minecraft.spigot.hilt.ItemStackExtensionsKt; import java.util.ArrayList; import java.util.List; @@ -278,7 +277,7 @@ private ItemStack RandomTransmutedGem(Player player) { SocketGem gem = plugin.getSocketGemManager().getRandomSocketGemByBonus(); ItemStack gemItem = gem.toItemStack(1); if (gem.isBroadcast()) { - broadcast(player, gemItem, transmuteFormat); + InventoryUtil.sendToDiscord(player, gemItem, transmuteFormat); } return gemItem; } @@ -298,10 +297,8 @@ private boolean isSocketGem(ItemStack item) { if (item == null || item.getType() != Material.EMERALD) { return false; } - if (!ItemStackExtensionsKt.getDisplayName(item).startsWith(ChatColor.GOLD + "Socket Gem - ")) { - return false; - } - return true; + String name = ItemStackExtensionsKt.getDisplayName(item); + return StringUtils.isNotBlank(name) && name.startsWith(ChatColor.GOLD + "Socket Gem - "); } private boolean isCombineButton(ItemStack item) { diff --git a/src/main/java/info/faceland/loot/managers/EnchantTomeManager.java b/src/main/java/info/faceland/loot/managers/EnchantTomeManager.java index 24ef4088..202e788d 100644 --- a/src/main/java/info/faceland/loot/managers/EnchantTomeManager.java +++ b/src/main/java/info/faceland/loot/managers/EnchantTomeManager.java @@ -20,9 +20,10 @@ import info.faceland.loot.enchantments.EnchantmentTome; import info.faceland.loot.math.LootRandom; - import java.util.HashMap; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; public final class EnchantTomeManager { @@ -63,6 +64,10 @@ public EnchantmentTome getRandomEnchantTome() { return getRandomEnchantTome(1D); } + public Set getTomeIds() { + return tomeMap.keySet().stream().map(value -> value.replace(" ", "_")).collect(Collectors.toSet()); + } + public EnchantmentTome getRandomEnchantTome(double bonus) { bonus -= 1; double selectedWeight = random.nextDouble() * getTotalWeight(bonus); diff --git a/src/main/java/info/faceland/loot/managers/LootCustomItemManager.java b/src/main/java/info/faceland/loot/managers/LootCustomItemManager.java index 0cd4f3b3..d37cec77 100644 --- a/src/main/java/info/faceland/loot/managers/LootCustomItemManager.java +++ b/src/main/java/info/faceland/loot/managers/LootCustomItemManager.java @@ -1,149 +1,152 @@ /** - * The MIT License - * Copyright (c) 2015 Teal Cube Games + * 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 + * 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 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. + * 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.managers; import info.faceland.loot.api.items.CustomItem; import info.faceland.loot.api.managers.CustomItemManager; import info.faceland.loot.math.LootRandom; - import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; public final class LootCustomItemManager implements CustomItemManager { - private static final double DISTANCE = 1000; - private static final double DISTANCE_SQUARED = Math.pow(DISTANCE, 2); - private final Map customItemMap; - private final LootRandom random; - - public LootCustomItemManager() { - customItemMap = new HashMap<>(); - random = new LootRandom(System.currentTimeMillis()); - } - - @Override - public Set getCustomItems() { - return new HashSet<>(customItemMap.values()); - } - - @Override - public CustomItem getCustomItem(String name) { - if (customItemMap.containsKey(name.toLowerCase())) { - return customItemMap.get(name.toLowerCase()); - } - return null; - } - - @Override - public void addCustomItem(CustomItem ci) { - customItemMap.put(ci.getName().toLowerCase(), ci); - } - - @Override - public void removeCustomItem(String name) { - if (customItemMap.containsKey(name.toLowerCase())) { - customItemMap.remove(name.toLowerCase()); - } + private static final double DISTANCE = 1000; + private static final double DISTANCE_SQUARED = Math.pow(DISTANCE, 2); + private final Map customItemMap; + private final LootRandom random; + + public LootCustomItemManager() { + customItemMap = new HashMap<>(); + random = new LootRandom(System.currentTimeMillis()); + } + + @Override + public Set getCustomItems() { + return new HashSet<>(customItemMap.values()); + } + + @Override + public Set listCustomItems() { + return customItemMap.keySet().stream().map(value -> value.replace(" ", "_")) + .collect(Collectors.toSet()); + } + + @Override + public CustomItem getCustomItem(String name) { + if (customItemMap.containsKey(name.toLowerCase())) { + return customItemMap.get(name.toLowerCase()); } - - @Override - public CustomItem getRandomCustomItem() { - return getRandomCustomItem(false); + return null; + } + + @Override + public void addCustomItem(CustomItem ci) { + customItemMap.put(ci.getName().toLowerCase(), ci); + } + + @Override + public void removeCustomItem(String name) { + if (customItemMap.containsKey(name.toLowerCase())) { + customItemMap.remove(name.toLowerCase()); } - - @Override - public CustomItem getRandomCustomItem(boolean withChance) { - return getRandomCustomItem(withChance, 0D); + } + + @Override + public CustomItem getRandomCustomItem() { + return getRandomCustomItem(false); + } + + @Override + public CustomItem getRandomCustomItem(boolean withChance) { + return getRandomCustomItem(withChance, 0D); + } + + @Override + public CustomItem getRandomCustomItem(boolean withChance, double distance) { + return getRandomCustomItem(withChance, distance, new HashMap()); + } + + @Override + public CustomItem getRandomCustomItem(boolean withChance, double distance, + Map map) { + if (!withChance) { + Set set = getCustomItems(); + CustomItem[] array = set.toArray(new CustomItem[set.size()]); + return array[random.nextInt(array.length)]; } - - @Override - public CustomItem getRandomCustomItem(boolean withChance, double distance) { - return getRandomCustomItem(withChance, distance, new HashMap()); + double selectedWeight = random.nextDouble() * getTotalWeight(); + double currentWeight = 0D; + for (CustomItem ci : getCustomItems()) { + double calcWeight = ci.getWeight() + ((distance / DISTANCE_SQUARED) * ci.getDistanceWeight()); + if (map.containsKey(ci)) { + calcWeight *= map.get(ci); + } + currentWeight += calcWeight; + if (currentWeight >= selectedWeight) { + return ci; + } } - - @Override - public CustomItem getRandomCustomItem(boolean withChance, double distance, Map map) { - if (!withChance) { - Set set = getCustomItems(); - CustomItem[] array = set.toArray(new CustomItem[set.size()]); - return array[random.nextInt(array.length)]; - } - double selectedWeight = random.nextDouble() * getTotalWeight(); - double currentWeight = 0D; - for (CustomItem ci : getCustomItems()) { - double calcWeight = ci.getWeight() + ((distance / DISTANCE_SQUARED) * ci.getDistanceWeight()); - if (map.containsKey(ci)) { - calcWeight *= map.get(ci); - } - currentWeight += calcWeight; - if (currentWeight >= selectedWeight) { - return ci; - } - } - return null; + return null; + } + + @Override + public CustomItem getRandomCustomItemByLevel(int level) { + double selectedWeight = random.nextDouble() * getTotalLevelWeight(level); + double currentWeight = 0D; + for (CustomItem ci : getCustomItems()) { + double diff = Math.abs(ci.getLevelBase() - level); + if (diff >= ci.getLevelRange()) { + continue; + } + double calcWeight = ci.getWeight() * (1 - diff / ci.getLevelRange()); + currentWeight += calcWeight; + if (currentWeight >= selectedWeight) { + return ci; + } } - - @Override - public CustomItem getRandomCustomItemByLevel(int level) { - double selectedWeight = random.nextDouble() * getTotalLevelWeight(level); - double currentWeight = 0D; - for (CustomItem ci : getCustomItems()) { - double diff = Math.abs(ci.getLevelBase() - level); - if (diff >= ci.getLevelRange()) { - continue; - } - double calcWeight = ci.getWeight() * (1 - diff/ci.getLevelRange()); - currentWeight += calcWeight; - if (currentWeight >= selectedWeight) { - return ci; - } - } - return null; - } - - @Override - public double getTotalWeight() { - double d = 0; - for (CustomItem ci : getCustomItems()) { - d += ci.getWeight(); - } - return d; + return null; + } + + @Override + public double getTotalWeight() { + double d = 0; + for (CustomItem ci : getCustomItems()) { + d += ci.getWeight(); } - - @Override - public double getTotalLevelWeight(int level) { - double weight = 0; - for (CustomItem ci : getCustomItems()) { - double diff = Math.abs(ci.getLevelBase() - level); - if (diff >= ci.getLevelRange()) { - continue; - } - double d = ci.getWeight() * (1 - diff/ci.getLevelRange()); - weight += d; - } - return weight; + return d; + } + + @Override + public double getTotalLevelWeight(int level) { + double weight = 0; + for (CustomItem ci : getCustomItems()) { + double diff = Math.abs(ci.getLevelBase() - level); + if (diff >= ci.getLevelRange()) { + continue; + } + double d = ci.getWeight() * (1 - diff / ci.getLevelRange()); + weight += d; } + return weight; + } } diff --git a/src/main/java/info/faceland/loot/managers/LootRarityManager.java b/src/main/java/info/faceland/loot/managers/LootRarityManager.java index 1bba9a96..ba52f629 100644 --- a/src/main/java/info/faceland/loot/managers/LootRarityManager.java +++ b/src/main/java/info/faceland/loot/managers/LootRarityManager.java @@ -5,6 +5,8 @@ import info.faceland.loot.math.LootRandom; import java.util.HashMap; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; public class LootRarityManager implements RarityManager { private final Map itemRarities; @@ -35,6 +37,10 @@ public Map getLoadedRarities() { return itemRarities; } + public Set getRarityIds() { + return itemRarities.keySet().stream().map(value -> value.replace(" ", "_")).collect(Collectors.toSet()); + } + @Override public ItemRarity getRandomRarity() { double selectedWeight = random.nextDouble() * getTotalRarityWeight(); diff --git a/src/main/java/info/faceland/loot/managers/ScrollManager.java b/src/main/java/info/faceland/loot/managers/ScrollManager.java index f9f86b8f..fa9fa0b9 100644 --- a/src/main/java/info/faceland/loot/managers/ScrollManager.java +++ b/src/main/java/info/faceland/loot/managers/ScrollManager.java @@ -6,6 +6,8 @@ import io.pixeloutlaw.minecraft.spigot.hilt.ItemStackExtensionsKt; import java.util.HashMap; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -82,6 +84,10 @@ public UpgradeScroll getRandomScroll() { return null; } + public Set getScrollIds() { + return scrolls.keySet().stream().map(value -> value.replace(" ", "_")).collect(Collectors.toSet()); + } + private double getTotalWeight() { double weight = 0; for (UpgradeScroll scroll : scrolls.values()) { diff --git a/src/main/java/info/faceland/loot/managers/SocketGemManager.java b/src/main/java/info/faceland/loot/managers/SocketGemManager.java index 0c4b09e2..b846961e 100644 --- a/src/main/java/info/faceland/loot/managers/SocketGemManager.java +++ b/src/main/java/info/faceland/loot/managers/SocketGemManager.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -54,6 +55,10 @@ public List getGemNames() { return new ArrayList<>(gemMap.keySet()); } + public Set getGemIds() { + return gemMap.keySet().stream().map(value -> value.replace(" ", "_")).collect(Collectors.toSet()); + } + public List getSortedGems() { List gems = getSocketGems(); Collections.sort(gems); diff --git a/src/main/java/info/faceland/loot/managers/TierManager.java b/src/main/java/info/faceland/loot/managers/TierManager.java index 476ab187..b2e4b51d 100644 --- a/src/main/java/info/faceland/loot/managers/TierManager.java +++ b/src/main/java/info/faceland/loot/managers/TierManager.java @@ -22,23 +22,22 @@ import info.faceland.loot.tier.Tier; import java.util.HashSet; import java.util.Set; +import java.util.stream.Collectors; import org.apache.commons.lang.StringUtils; public final class TierManager { - private Set loadedTiers; - private LootRandom random; - - public TierManager() { - loadedTiers = new HashSet<>(); - random = new LootRandom(); - } + private final Set loadedTiers = new HashSet<>(); + private final LootRandom random = new LootRandom(); public Tier getTier(String name) { if (StringUtils.isBlank(name)) { return null; } for (Tier t : getLoadedTiers()) { + if (name.equalsIgnoreCase(t.getName())) { + return t; + } if (t.getId().replace(" ", "").equalsIgnoreCase(name.replace(" ", ""))) { return t; } @@ -79,6 +78,11 @@ public Set getLoadedTiers() { return new HashSet<>(loadedTiers); } + public Set getTierIds() { + return loadedTiers.stream().map(value -> value.getId() + .replace(" ", "_")).collect(Collectors.toSet()); + } + public double getTotalTierWeight() { double weight = 0; for (Tier t : getLoadedTiers()) { diff --git a/src/main/java/info/faceland/loot/utils/DropUtil.java b/src/main/java/info/faceland/loot/utils/DropUtil.java index 2ac57c57..67883fe2 100644 --- a/src/main/java/info/faceland/loot/utils/DropUtil.java +++ b/src/main/java/info/faceland/loot/utils/DropUtil.java @@ -1,6 +1,5 @@ package info.faceland.loot.utils; -import static info.faceland.loot.utils.InventoryUtil.broadcast; import static info.faceland.loot.utils.InventoryUtil.getFirstColor; import com.tealcube.minecraft.bukkit.shade.apache.commons.lang3.StringUtils; @@ -19,6 +18,7 @@ import info.faceland.loot.items.prefabs.IdentityTome; import info.faceland.loot.items.prefabs.PurifyingScroll; import info.faceland.loot.items.prefabs.SocketExtender; +import info.faceland.loot.items.prefabs.TinkerersGear; import info.faceland.loot.items.prefabs.UnidentifiedItem; import info.faceland.loot.math.LootRandom; import info.faceland.loot.sockets.SocketGem; @@ -59,6 +59,7 @@ public class DropUtil implements Listener { private static double socketDropChance; private static double tomeDropChance; private static double enhancerDropChance; + private static double tinkerGearDropChance; private static double purityDropChance; private static LootRandom random; @@ -77,6 +78,7 @@ public static void refresh() { socketDropChance = plugin.getSettings().getDouble("config.drops.socket-gem", 0D); tomeDropChance = plugin.getSettings().getDouble("config.drops.enchant-gem", 0D); enhancerDropChance = plugin.getSettings().getDouble("config.drops.arcane-enhancer", 0D); + tinkerGearDropChance = plugin.getSettings().getDouble("config.drops.tinker-gear", 0D); purityDropChance = plugin.getSettings().getDouble("config.drops.purity-scroll", 0D); random = new LootRandom(); @@ -210,6 +212,9 @@ public static void dropLoot(LootDropEvent event) { dropItem(event.getLocation(), PurifyingScroll.get(), killer, false, null); } } + if (random.nextDouble() < dropMultiplier * tinkerGearDropChance) { + dropItem(event.getLocation(), TinkerersGear.get(), killer, true, Color.RED); + } if (random.nextDouble() < dropMultiplier * scrollDropChance) { UpgradeScroll us = plugin.getScrollManager().getRandomScroll(); ItemStack stack = plugin.getScrollManager().buildItemStack(us); @@ -369,7 +374,7 @@ private static void dropItem(Location loc, ItemStack itemStack, Player looter, i if (looter != null) { applyDropProtection(drop, looter.getUniqueId()); if (broadcast) { - broadcast(looter, itemStack, itemFoundFormat); + InventoryUtil.sendToDiscord(looter, itemStack, itemFoundFormat); } } } diff --git a/src/main/java/info/faceland/loot/utils/InventoryUtil.java b/src/main/java/info/faceland/loot/utils/InventoryUtil.java index ca5a946f..1bab6fae 100644 --- a/src/main/java/info/faceland/loot/utils/InventoryUtil.java +++ b/src/main/java/info/faceland/loot/utils/InventoryUtil.java @@ -32,6 +32,8 @@ import io.pixeloutlaw.minecraft.spigot.garbage.BroadcastMessageUtil; import io.pixeloutlaw.minecraft.spigot.garbage.BroadcastMessageUtil.BroadcastItemVisibility; import io.pixeloutlaw.minecraft.spigot.garbage.BroadcastMessageUtil.BroadcastTarget; +import io.pixeloutlaw.minecraft.spigot.garbage.StringExtensionsKt; +import io.pixeloutlaw.minecraft.spigot.hilt.ItemStackExtensionsKt; import java.awt.Color; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; @@ -53,31 +55,35 @@ private InventoryUtil() { thechan = DiscordSRV.getPlugin().getMainTextChannel(); } - public static void broadcast(Player player, ItemStack his, String format) { - broadcast(player, his, format, true); + public static void sendToDiscord(Player player, ItemStack his, String format) { + sendToDiscord(player, his, format, true); } - public static void broadcast(Player player, ItemStack item, String format, boolean sendToAll) { + public static void sendToDiscord(Player player, ItemStack item, String format, boolean sendToAll) { + + ItemStack finalItem = item.clone(); BroadcastTarget target = sendToAll ? BroadcastTarget.SERVER : BroadcastTarget.PLAYER; BroadcastMessageUtil.INSTANCE - .broadcastItem(format, player, item, target, BroadcastItemVisibility.SHOW); + .broadcastItem(format, player, finalItem, target, BroadcastItemVisibility.SHOW); + if (sendToAll) { + String finalFormat = ChatColor.stripColor(StringExtensionsKt.chatColorize(format)); Bukkit.getScheduler().runTaskAsynchronously(InteractiveChatDiscordSrvAddon.plugin, () -> { try { List contents = new ArrayList<>(); - BufferedImage image = ImageGeneration.getItemStackImage(item, player); + BufferedImage image = ImageGeneration.getItemStackImage(finalItem, player); ByteArrayOutputStream itemOs = new ByteArrayOutputStream(); ImageIO.write(image, "png", itemOs); - DiscordDescription description = DiscordItemStackUtils.getDiscordDescription(item); + DiscordDescription description = DiscordItemStackUtils.getDiscordDescription(finalItem); - Color color = DiscordItemStackUtils.getDiscordColor(item); + Color color = DiscordItemStackUtils.getDiscordColor(finalItem); DiscordMessageContent content = new DiscordMessageContent(description.getName(), "attachment://Item.png", color); content.addAttachment("Item.png", itemOs.toByteArray()); contents.add(content); - DiscordToolTip discordToolTip = DiscordItemStackUtils.getToolTip(item); + DiscordToolTip discordToolTip = DiscordItemStackUtils.getToolTip(finalItem); if (!discordToolTip.isBaseItem() || InteractiveChatDiscordSrvAddon.plugin.itemUseTooltipImageOnBaseItem) { BufferedImage tooltip = ImageGeneration.getToolTipImage(discordToolTip.getComponents()); @@ -89,7 +95,9 @@ public static void broadcast(Player player, ItemStack item, String format, boole content.addDescription(description.getDescription().orElse(null)); } - broadcast("\uD83C\uDF1F **Dang Son!** " + player.getName() + " got an item!", contents); + String itemName = ItemStackExtensionsKt.getDisplayName(finalItem); + sendToDiscord("\\uD83C\\uDF1F " + finalFormat.replace("%player%", + player.getName()).replace("%item%", itemName), contents); } catch (Exception e) { Bukkit.getLogger().warning("Failed to send dang son to discord"); @@ -98,7 +106,7 @@ public static void broadcast(Player player, ItemStack item, String format, boole } } - private static void broadcast(String originalText, List contents) { + private static void sendToDiscord(String originalText, List contents) { Bukkit.getScheduler().runTaskAsynchronously(LootPlugin.getInstance(), () -> { String text = originalText; @@ -111,7 +119,8 @@ private static void broadcast(String originalText, List c } } - DiscordImageEvent discordImageEvent = new DiscordImageEvent(thechan, text, text, contents, false, true); + DiscordImageEvent discordImageEvent = new DiscordImageEvent(thechan, text, text, contents, + false, true); TextChannel textChannel = discordImageEvent.getChannel(); if (discordImageEvent.isCancelled()) { String restore = discordImageEvent.getOriginalMessage(); diff --git a/src/main/java/info/faceland/loot/utils/MaterialUtil.java b/src/main/java/info/faceland/loot/utils/MaterialUtil.java index 0e14bc39..5ed84953 100644 --- a/src/main/java/info/faceland/loot/utils/MaterialUtil.java +++ b/src/main/java/info/faceland/loot/utils/MaterialUtil.java @@ -1,18 +1,20 @@ /** * 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: + * 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 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. + * 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.utils; @@ -117,7 +119,8 @@ public static void refreshConfig() { .getString("language.extend.fail", ""); } - public static double getSuccessChance(Player player, int targetPlus, ItemStack scrollStack, UpgradeScroll scroll) { + public static double getSuccessChance(Player player, int targetPlus, ItemStack scrollStack, + UpgradeScroll scroll) { double success = scroll.getBaseSuccess(); success -= scroll.getFlatDecay() * targetPlus; success *= 1 - (scroll.getPercentDecay() * targetPlus); @@ -183,6 +186,7 @@ public static void upgradeItem(Player player, ItemStack scrollStack, ItemStack s int itemUpgradeLevel = MaterialUtil.getUpgradeLevel(targetName); int targetLevel = itemUpgradeLevel; + int shards = getFailureBonus(scrollStack); if (stack.getType() == Material.BOOK || stack.getType() == Material.ARROW) { targetLevel += 3; } else { @@ -194,63 +198,59 @@ public static void upgradeItem(Player player, ItemStack scrollStack, ItemStack s scrollStack.setAmount(scrollStack.getAmount() - 1); - // Failure Logic - if (successChance < random.nextDouble()) { - double damagePercentage = getUpgradeFailureDamagePercent(scroll, targetLevel); - short damage; - - if (stack.getType().getMaxDurability() <= 1) { - if (damagePercentage < 1) { - sendMessage(player, upgradeItemNoDamageMsg); - int shards = getFailureBonus(scrollStack); - distributeShards(player, shards); - return; - } - damage = 1000; - } else { - double currentPercentage = 1 - ((double) stack.getDurability() / stack.getType().getMaxDurability()); - if (damagePercentage >= currentPercentage) { - damage = stack.getType().getMaxDurability(); - } else { - damage = stack.getDurability(); - damage += (short) (Math.floor((currentPercentage - damagePercentage) * - (double) stack.getType().getMaxDurability())); - } + // SUCCESS! + if (successChance >= random.nextDouble()) { + bumpItemPlus(stack, itemUpgradeLevel, 1, targetLevel - itemUpgradeLevel); + + double exp = 0.5f + (float) Math.pow(1.4, targetLevel); + LootPlugin.getInstance().getStrifePlugin().getSkillExperienceManager() + .addExperience(player, LifeSkillType.ENCHANTING, exp, false, false); + + sendMessage(player, upgradeSuccessMsg); + player.playSound(player.getEyeLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F); + + if (targetLevel >= 10) { + InventoryUtil.sendToDiscord(player, stack, upgradeSuccessBroadcast); } + return; + } + + // DAMAGED + double damagePercentage = getUpgradeFailureDamagePercent(scroll, targetLevel); + double currentDamagePercentage = ((double) stack.getDurability()) / stack.getType().getMaxDurability(); + short damage; - if (damage >= stack.getType().getMaxDurability()) { - ItemStack clone = stack.clone(); - sendMessage(player, upgradeItemDestroyMsg); - stack.setAmount(0); - player.playSound(player.getEyeLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F); - int shards = getFailureBonus(scrollStack); + // Offhand Upgrade + if (stack.getType().getMaxDurability() <= 1) { + if (damagePercentage < 1) { + sendMessage(player, upgradeItemNoDamageMsg); if (itemUpgradeLevel > 5) { - shards += 1 + random.nextIntRange(0, (int) (Math.pow(itemUpgradeLevel, 1.2) / 6)); + shards += itemUpgradeLevel / 4 + random.nextIntRange(0, itemUpgradeLevel - 5); } distributeShards(player, shards); - InventoryUtil.broadcast(player, clone, upgradeItemDestroyBroadcast); return; - } else { - int shards = getFailureBonus(scrollStack); - distributeShards(player, shards); } - stack.setDurability(damage); - sendMessage(player, upgradeItemDamageMsg); - return; + damage = Short.MAX_VALUE; + } else { + double totalPercentage = damagePercentage + currentDamagePercentage; + damage = (short) (Math.floor(totalPercentage * (double) stack.getType().getMaxDurability())); } - bumpItemPlus(stack, itemUpgradeLevel, 1, targetLevel - itemUpgradeLevel); - - double exp = 0.5f + (float) Math.pow(1.4, targetLevel); - LootPlugin.getInstance().getStrifePlugin().getSkillExperienceManager() - .addExperience(player, LifeSkillType.ENCHANTING, exp, false, false); - - sendMessage(player, upgradeSuccessMsg); - player.playSound(player.getEyeLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 2F); - - if (targetLevel >= 10) { - InventoryUtil.broadcast(player, stack, upgradeSuccessBroadcast); + if (damage >= stack.getType().getMaxDurability()) { + player.playSound(player.getEyeLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F); + sendMessage(player, upgradeItemDestroyMsg); + InventoryUtil.sendToDiscord(player, stack.clone(), upgradeItemDestroyBroadcast); + stack.setAmount(0); + if (itemUpgradeLevel > 5) { + shards += itemUpgradeLevel / 4 + random.nextIntRange(0, itemUpgradeLevel - 5); + } + distributeShards(player, shards); + return; } + + distributeShards(player, shards); + stack.setDurability(damage); + sendMessage(player, upgradeItemDamageMsg); } private static void distributeShards(Player player, int amount) { @@ -274,7 +274,8 @@ public static void bumpItemPlus(ItemStack stack, int currentLevel, int amount) { bumpItemPlus(stack, currentLevel, amount, amount); } - public static void bumpItemPlus(ItemStack stack, int currentLevel, int statAmount, int plusAmount) { + public static void bumpItemPlus(ItemStack stack, int currentLevel, int statAmount, + int plusAmount) { String itemName = ItemStackExtensionsKt.getDisplayName(stack); if (StringUtils.isBlank(itemName)) { itemName = stack.getType().toString().replaceAll("_", " "); @@ -416,7 +417,8 @@ public static void enhanceEnchantment(Player player, ItemStack item, ItemStack e List lore = new ArrayList<>(ItemStackExtensionsKt.getLore(item)); String enchantmentStatString = ChatColor.stripColor(lore.get(index - 1)); - int statValue = NumberUtils.toInt(CharMatcher.digit().or(CharMatcher.is('-')).retainFrom(enchantmentStatString)); + int statValue = NumberUtils + .toInt(CharMatcher.digit().or(CharMatcher.is('-')).retainFrom(enchantmentStatString)); itemLevel = Math.max(1, Math.min(100, itemLevel)); double enchantingLevel = PlayerDataUtil.getEffectiveLifeSkill(player, @@ -429,7 +431,8 @@ public static void enhanceEnchantment(Player player, ItemStack item, ItemStack e newValue++; lore.set(index - 1, - ChatColor.BLUE + enchantmentStatString.replace(Integer.toString(statValue), Integer.toString(newValue))); + ChatColor.BLUE + enchantmentStatString + .replace(Integer.toString(statValue), Integer.toString(newValue))); lore.set(index, lore.get(index).replace(ChatColor.BLACK + "", ChatColor.DARK_RED + "")); ItemStackExtensionsKt.setLore(item, lore); enhancer.setAmount(enhancer.getAmount() - 1); @@ -529,13 +532,16 @@ public static void degradeItemEnchantment(ItemStack item, Player player) { if (index <= 2) { lore.remove(lore.size() - 1); lore.add(ChatColor.BLUE + "(Enchantable)"); - sendMessage(player, LootPlugin.getInstance().getSettings().getString("language.enchant.degrade", "")); + sendMessage(player, + LootPlugin.getInstance().getSettings().getString("language.enchant.degrade", "")); continue; } else if (index <= 5) { - sendMessage(player, LootPlugin.getInstance().getSettings().getString("language.enchant.bar-low", "")); + sendMessage(player, + LootPlugin.getInstance().getSettings().getString("language.enchant.bar-low", "")); } barString = barString.replace("" + incompleteBarColor, ""); - barString = new StringBuilder(barString).insert(index - 1, incompleteBarColor + "").toString(); + barString = new StringBuilder(barString).insert(index - 1, incompleteBarColor + "") + .toString(); barString = barString.replace("[", ChatColor.BLUE + "[").replace("]", ChatColor.BLUE + "]"); lore.add(barString); } @@ -565,7 +571,8 @@ public static boolean enchantItem(Player player, ItemStack tomeStack, ItemStack int index = strippedLore.indexOf("(Enchantable)"); lore.remove(index); - double enchantSkill = PlayerDataUtil.getEffectiveLifeSkill(player, LifeSkillType.ENCHANTING, true); + double enchantSkill = PlayerDataUtil + .getEffectiveLifeSkill(player, LifeSkillType.ENCHANTING, true); List added = new ArrayList<>(); if (!tome.getLore().isEmpty()) { @@ -578,14 +585,16 @@ public static boolean enchantItem(Player player, ItemStack tomeStack, ItemStack double rarity = MaterialUtil.getBaseEnchantBonus(enchantSkill); ItemStat stat = LootPlugin.getInstance().getStatManager().getStat(tome.getStat()); - added.add(LootPlugin.getInstance().getStatManager().getFinalStat(stat, eLevel, rarity, false).getStatString()); + added.add(LootPlugin.getInstance().getStatManager().getFinalStat(stat, eLevel, rarity, false) + .getStatString()); } if (tome.getBar()) { double skillRatio = Math.min(1, enchantSkill / 100); double roll = skillRatio * Math.random() + (1 - skillRatio) * Math.pow(Math.random(), 2.5); double size = 8 + 22 * roll; - String bars = IntStream.range(0, (int) size).mapToObj(i -> "|").collect(Collectors.joining("")); + String bars = IntStream.range(0, (int) size).mapToObj(i -> "|") + .collect(Collectors.joining("")); added.add(ChatColor.BLUE + "[" + bars + "]"); } @@ -753,12 +762,14 @@ public static int getQuality(ItemStack stack) { return 0; } - public static ItemStack buildEssence(Tier tier, double itemLevel, double craftLevelAdvantage, int toolQuality, + public static ItemStack buildEssence(Tier tier, double itemLevel, double craftLevelAdvantage, + int toolQuality, List possibleStats, boolean lucky) { int essLevel = Math.max(1, (int) (Math.floor(itemLevel) / 10) * 10); - String statString = ChatColor.stripColor(possibleStats.get(random.nextInt(possibleStats.size()))); + String statString = ChatColor + .stripColor(possibleStats.get(random.nextInt(possibleStats.size()))); int statVal = getDigit(statString); craftLevelAdvantage = Math.min(craftLevelAdvantage, 200); @@ -794,10 +805,28 @@ public static int getUpgradeLevel(ItemStack stack) { public static int getUpgradeLevel(String name) { name = stripColor(name); - String lev = CharMatcher.digit().or(CharMatcher.is('-')).negate().collapseFrom(name, ' ').trim(); + String lev = CharMatcher.digit().or(CharMatcher.is('-')).negate().collapseFrom(name, ' ') + .trim(); return NumberUtils.toInt(lev.split(" ")[0], 0); } + public static List getValidEssenceStats(List lore) { + List existingCraftStatStrings = new ArrayList<>(); + for (String str : lore) { + String strippedString = ChatColor.stripColor(str); + if (!strippedString.startsWith("+")) { + continue; + } + if (str.startsWith(ChatColor.BLUE + "+") || str.startsWith(ChatColor.GRAY + "+") + || str.startsWith(ChatColor.DARK_PURPLE + "+") || str.startsWith(ChatColor.RED + "+")) { + continue; + } + str = CharMatcher.javaLetter().or(CharMatcher.is(' ')).retainFrom(strippedString.trim()); + existingCraftStatStrings.add(str); + } + return existingCraftStatStrings; + } + public static int getLevelRequirement(ItemStack stack) { if (stack.getItemMeta() == null) { return -1; @@ -815,7 +844,8 @@ public static int getLevelRequirement(ItemStack stack) { public static Tier getTierFromStack(ItemStack stack) { String strTier = ""; int data = MaterialUtil.getCustomData(stack); - for (DeconstructData dd : LootPlugin.getInstance().getCraftMatManager().getDeconstructDataSet()) { + for (DeconstructData dd : LootPlugin.getInstance().getCraftMatManager() + .getDeconstructDataSet()) { if (StringUtils.isBlank(dd.getTierName())) { continue; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 115d9d0d..d6c58f2b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: Loot version: ${project.version} main: info.faceland.loot.LootPlugin -api-version: 1.15 +api-version: 1.16 depend: - Facecore softdepend: @@ -15,9 +15,7 @@ commands: aliases: [l] permissions: - loot.command.spawn: + loot.give: default: op - loot.command.give: - default: op - loot.command.simulate: + loot.reward: default: op \ No newline at end of file