From da7e81c342dcddf460c54d3ed732f08b01e9ea4b Mon Sep 17 00:00:00 2001 From: ImproperIssues Date: Sun, 16 Apr 2023 13:17:43 -0700 Subject: [PATCH] recipe update --- .../ogredupealias/OgreDupeAlias.java | 4 ++ .../commands/commands/RecipeSpyCommand.java | 42 +++++++++++++++++++ .../plugin/custom/forging/CraftingKey.java | 22 ---------- .../plugin/custom/forging/CraftingKeys.java | 32 ++++++++++++++ .../plugin/custom/forging/CustomTable.java | 29 +++++++++++-- src/main/resources/plugin.yml | 9 ++++ 6 files changed, 112 insertions(+), 26 deletions(-) create mode 100644 src/main/java/io/github/itzispyder/ogredupealias/commands/commands/RecipeSpyCommand.java create mode 100644 src/main/java/io/github/itzispyder/ogredupealias/plugin/custom/forging/CraftingKeys.java diff --git a/src/main/java/io/github/itzispyder/ogredupealias/OgreDupeAlias.java b/src/main/java/io/github/itzispyder/ogredupealias/OgreDupeAlias.java index 1eb58e0..108e887 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/OgreDupeAlias.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/OgreDupeAlias.java @@ -3,6 +3,7 @@ package io.github.itzispyder.ogredupealias; import io.github.itzispyder.ogredupealias.commands.commands.*; import io.github.itzispyder.ogredupealias.data.Config; import io.github.itzispyder.ogredupealias.events.*; +import io.github.itzispyder.ogredupealias.plugin.custom.forging.CraftingKeys; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -23,6 +24,7 @@ public final class OgreDupeAlias extends JavaPlugin { instance = this; this.init(); this.initConfig(); + CraftingKeys.initRecipes(); } @Override @@ -51,6 +53,8 @@ public final class OgreDupeAlias extends JavaPlugin { getCommand("socialspy").setTabCompleter(new SocialSpyCommand()); getCommand("commandspy").setExecutor(new CommandSpyCommand()); getCommand("commandspy").setTabCompleter(new CommandSpyCommand()); + getCommand("recipespy").setExecutor(new RecipeSpyCommand()); + getCommand("recipespy").setTabCompleter(new RecipeSpyCommand()); getCommand("irepair").setExecutor(new IRepairCommand()); getCommand("irepair").setTabCompleter(new IRepairCommand()); } diff --git a/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/RecipeSpyCommand.java b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/RecipeSpyCommand.java new file mode 100644 index 0000000..ffdff1f --- /dev/null +++ b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/RecipeSpyCommand.java @@ -0,0 +1,42 @@ +package io.github.itzispyder.ogredupealias.commands.commands; + +import io.github.itzispyder.ogredupealias.commands.CmdExHandler; +import io.github.itzispyder.ogredupealias.plugin.custom.forging.CustomTable; +import io.github.itzispyder.ogredupealias.utils.Text; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class RecipeSpyCommand implements TabExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + try { + Player p = (Player) sender; + boolean isRecipient = CustomTable.recipeSpies.isRecipient(p); + if (isRecipient) CustomTable.recipeSpies.removeRecipient(p); + else CustomTable.recipeSpies.addRecipient(p); + isRecipient = CustomTable.recipeSpies.isRecipient(p); + + sender.sendMessage(Text.builder() + .message("&7[&bRecipeSpy&7] &8>> &3You are " + (isRecipient ? "&anow" : "&cno longer") + " &3a recipient!") + .prefix() + .color() + .build()); + } + catch (Exception ex) { + CmdExHandler handler = new CmdExHandler(ex,command); + sender.sendMessage(handler.getHelp()); + } + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + return new ArrayList<>(); + } +} diff --git a/src/main/java/io/github/itzispyder/ogredupealias/plugin/custom/forging/CraftingKey.java b/src/main/java/io/github/itzispyder/ogredupealias/plugin/custom/forging/CraftingKey.java index 736c2e2..061e7d6 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/plugin/custom/forging/CraftingKey.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/plugin/custom/forging/CraftingKey.java @@ -1,37 +1,15 @@ package io.github.itzispyder.ogredupealias.plugin.custom.forging; -import io.github.itzispyder.ogredupealias.plugin.ItemPresets; import io.github.itzispyder.ogredupealias.utils.ArrayUtils; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; public class CraftingKey { - private static final Map REGISTERED_KEYS = new HashMap<>(); public final String key; - static { - CraftingKey.register(ItemPresets.LEGENDARY_CORE,"netherite_scrap:{}-trident:{}-netherite_scrap:{}-enchanted_golden_apple:{}-player_head:{SkullOwner:{Id:[I;1216354028,1738164382,-1623044432,661086651],Name:\"DeepWarden\",Properties:{textures:[{Signature:\"pXTxO6vKSFkC2d9rWQc0cgSZoNTUsOb1lTiJKr2XwfL6k6XBZifYZramoitpB+NEav3GlVlIcgmC7+dcLIjVQTZAw1G7AyxAVdH2ggk3uArosj+vQlTZU2kGD0JFCrFN74avDlUgdp61E6AaXRgIOvhHs/Oeo/tzjllAvrgqauwxV/hlb/yTy2CRtrF1ooEXFmbti6iwntwfnwrSkzRb5eDvztneGbNQOZ2XYhyEU0lXCDzrrhYYExW8yHOjkqZPR2sd7eOsGRi19UpjQx2F4iX+MWFuiXJmUVrXEwCeggwywsuoQh0DxENwSyQxxGLk6Ck5pU3G19WXKXssN8+D9EdUQpYN58tMS4zO5B/htD0+n43O5ohOv8AgCrsorRiVGMc7wPIeQmgbsdegwiUlI535OHoIVy2Q9QPJhMm4C4kLbh+VbnoCRNzzDboodGeP146izCbd3S1tLv7H1z5vaCoA1tk8dSZeGipky45up6CHyGwrpPY9dOCtqIrAvlbdWNU3NUSDMdj2SqzHkM/7KtIQzOsuJ1/CmbZgFyvVWK4Yo55aatPoOnGI7D96A9VtjqpPC3rfX/Slo9iLVKEnhF6OYvjO+VgiJR5rHvplzGRyFd1cw3Q1n5ZTWUg1pMSd4GIAWeWz4DO6DuXGgdY4qnRSWLqAn5tL64MDLWG1h5Y=\",Value:\"ewogICJ0aW1lc3RhbXAiIDogMTY4MTYyNjMxNTgzOSwKICAicHJvZmlsZUlkIiA6ICI0ODgwMTZlYzY3OWE0ODllOWY0MjRlYjAyNzY3NjFiYiIsCiAgInByb2ZpbGVOYW1lIiA6ICJEZWVwV2FyZGVuIiwKICAic2lnbmF0dXJlUmVxdWlyZWQiIDogdHJ1ZSwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2E4MDRhYTg3YzlmNGQwNmNhODJkNzk3ZWUyYjk0YjdlMjhjZmQ2MDcxMDI3NmEyODhlMjNmNzkwNjI5NDA0NjAiCiAgICB9CiAgfQp9\"}]}}}-enchanted_golden_apple:{}-netherite_scrap:{}-dragon_head:{}-netherite_scrap:{}"); - CraftingKey.register(ItemPresets.LEGENDARY_INGOT,"totem_of_undying:{}-netherite_ingot:{}-totem_of_undying:{}-netherite_ingot:{}-structure_block:{Enchantments:[{id:\"minecraft:lure\",lvl:1s}],HideFlags:1,display:{Lore:['{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"dark_gray\",\"text\":\"- \"},{\"italic\":false,\"color\":\"gray\",\"text\":\"Used for forging\"}],\"text\":\"\"}'],Name:'{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"red\",\"text\":\"Legendary Core\"}],\"text\":\"\"}'}}-netherite_ingot:{}-totem_of_undying:{}-netherite_ingot:{}-totem_of_undying:{}"); - } - - public static void register(ItemStack result, CraftingKey key) { - REGISTERED_KEYS.put(key.getKey(),result); - } - - public static void register(ItemStack result, String key) { - REGISTERED_KEYS.put(key,result); - } - - public static ItemStack getResult(CraftingKey key) { - ItemStack result = REGISTERED_KEYS.get(key.getKey()); - return result != null ? result : new ItemStack(Material.AIR); - } - public CraftingKey(Iterable input) { this.key = String.join("-", ArrayUtils.toNewList(input,this::keyOfStack)); } diff --git a/src/main/java/io/github/itzispyder/ogredupealias/plugin/custom/forging/CraftingKeys.java b/src/main/java/io/github/itzispyder/ogredupealias/plugin/custom/forging/CraftingKeys.java new file mode 100644 index 0000000..3209520 --- /dev/null +++ b/src/main/java/io/github/itzispyder/ogredupealias/plugin/custom/forging/CraftingKeys.java @@ -0,0 +1,32 @@ +package io.github.itzispyder.ogredupealias.plugin.custom.forging; + +import io.github.itzispyder.ogredupealias.plugin.ItemPresets; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import java.util.HashMap; +import java.util.Map; + +public abstract class CraftingKeys { + + private static final Map REGISTERED_KEYS = new HashMap<>(); + + public static void initRecipes() { + register(ItemPresets.LEGENDARY_CORE,"netherite_scrap:{}-trident:{}-netherite_scrap:{}-enchanted_golden_apple:{}-player_head:{SkullOwner:{Id:[I;1216354028,1738164382,-1623044432,661086651],Name:\"DeepWarden\",Properties:{textures:[{Signature:\"pXTxO6vKSFkC2d9rWQc0cgSZoNTUsOb1lTiJKr2XwfL6k6XBZifYZramoitpB+NEav3GlVlIcgmC7+dcLIjVQTZAw1G7AyxAVdH2ggk3uArosj+vQlTZU2kGD0JFCrFN74avDlUgdp61E6AaXRgIOvhHs/Oeo/tzjllAvrgqauwxV/hlb/yTy2CRtrF1ooEXFmbti6iwntwfnwrSkzRb5eDvztneGbNQOZ2XYhyEU0lXCDzrrhYYExW8yHOjkqZPR2sd7eOsGRi19UpjQx2F4iX+MWFuiXJmUVrXEwCeggwywsuoQh0DxENwSyQxxGLk6Ck5pU3G19WXKXssN8+D9EdUQpYN58tMS4zO5B/htD0+n43O5ohOv8AgCrsorRiVGMc7wPIeQmgbsdegwiUlI535OHoIVy2Q9QPJhMm4C4kLbh+VbnoCRNzzDboodGeP146izCbd3S1tLv7H1z5vaCoA1tk8dSZeGipky45up6CHyGwrpPY9dOCtqIrAvlbdWNU3NUSDMdj2SqzHkM/7KtIQzOsuJ1/CmbZgFyvVWK4Yo55aatPoOnGI7D96A9VtjqpPC3rfX/Slo9iLVKEnhF6OYvjO+VgiJR5rHvplzGRyFd1cw3Q1n5ZTWUg1pMSd4GIAWeWz4DO6DuXGgdY4qnRSWLqAn5tL64MDLWG1h5Y=\",Value:\"ewogICJ0aW1lc3RhbXAiIDogMTY4MTYyNjMxNTgzOSwKICAicHJvZmlsZUlkIiA6ICI0ODgwMTZlYzY3OWE0ODllOWY0MjRlYjAyNzY3NjFiYiIsCiAgInByb2ZpbGVOYW1lIiA6ICJEZWVwV2FyZGVuIiwKICAic2lnbmF0dXJlUmVxdWlyZWQiIDogdHJ1ZSwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2E4MDRhYTg3YzlmNGQwNmNhODJkNzk3ZWUyYjk0YjdlMjhjZmQ2MDcxMDI3NmEyODhlMjNmNzkwNjI5NDA0NjAiCiAgICB9CiAgfQp9\"}]}}}-enchanted_golden_apple:{}-netherite_scrap:{}-dragon_head:{}-netherite_scrap:{}"); + register(ItemPresets.LEGENDARY_CORE,"netherite_scrap:{}-trident:{}-netherite_scrap:{}-enchanted_golden_apple:{}-player_head:{SkullOwner:{Id:[I;1216354028,1738164382,-1623044432,661086651],Name:\"DeepWarden\",Properties:{textures:[{Signature:\"DjztLlK1EwqCe+I14DWq9GLO2wfykaWl0RR//OT/Bt0mZoTgooVS61hrqM5Xkd6aXDxlDe9th9dhU1qD4PnFKKTQ/NrV8Ma09XcV56KcfaonVwtJ1D/jN02rTqPDF5Hk08yFEw/aBeU7QHtQJl86YyUdW7Yq+yJEAsa+CLr5HgKniGZGehENpx/jwEBWVxJOjIBTr5GXaEeiPpJ7STz3Qnswt+NNmppNhBoYChp+64jgnn/EtIxSuyNtJ/qghrvNMjrcTb1hMjgVcWB4XuEOkjPSSdAnKzwRRdTTpzx7qkb80SdKi1j9UYctyzbS/mqDQ5VQjbbRUhZXmUxq9c/2vBbAX9ftbyV37nzqoG+2x1TMs33ZRRPbuK9TJixLK2FpOk/XB9pQyH4VBcLn+UD8AnB/u5f9G3VvPZXNs4YC3Oi9bvGwbyaLzNeoi9F0nNbM+k3TL4c2TVj8pz+oAx7kogIAfRfSravST7GTAFNRhsF+xD8hGZYg4h6xsibVK7I2smoNdeatTbIZH0Q+QqIIjua6fdbFIEvAU/pltDoxDeP+fcJ+JA7+e9VH/o7xIhKHYtiojUHJiSICW8WM7sGKd4/Pc/OC5werAlHtNGc70Nip2wdzKWgRr8ozCNPanp4yqVwzUigT47wiH5xvC8m1X8Vm3b8OkwXT5ec+VIcIrR4=\",Value:\"ewogICJ0aW1lc3RhbXAiIDogMTY4MTY1OTU2MjQxNiwKICAicHJvZmlsZUlkIiA6ICI0ODgwMTZlYzY3OWE0ODllOWY0MjRlYjAyNzY3NjFiYiIsCiAgInByb2ZpbGVOYW1lIiA6ICJEZWVwV2FyZGVuIiwKICAic2lnbmF0dXJlUmVxdWlyZWQiIDogdHJ1ZSwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2E4MDRhYTg3YzlmNGQwNmNhODJkNzk3ZWUyYjk0YjdlMjhjZmQ2MDcxMDI3NmEyODhlMjNmNzkwNjI5NDA0NjAiCiAgICB9CiAgfQp9\"}]}}}-enchanted_golden_apple:{}-netherite_scrap:{}-dragon_head:{}-netherite_scrap:{}"); + register(ItemPresets.LEGENDARY_INGOT,"totem_of_undying:{}-netherite_ingot:{}-totem_of_undying:{}-netherite_ingot:{}-structure_block:{Enchantments:[{id:\"minecraft:lure\",lvl:1s}],HideFlags:1,display:{Lore:['{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"dark_gray\",\"text\":\"- \"},{\"italic\":false,\"color\":\"gray\",\"text\":\"Used for forging\"}],\"text\":\"\"}'],Name:'{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"red\",\"text\":\"Legendary Core\"}],\"text\":\"\"}'}}-netherite_ingot:{}-totem_of_undying:{}-netherite_ingot:{}-totem_of_undying:{}"); + } + + public static void register(ItemStack result, CraftingKey key) { + REGISTERED_KEYS.put(key.getKey(),result); + } + + public static void register(ItemStack result, String key) { + REGISTERED_KEYS.put(key,result); + } + + public static ItemStack getResult(CraftingKey key) { + ItemStack result = REGISTERED_KEYS.get(key.getKey()); + return result != null ? result : new ItemStack(Material.AIR); + } +} diff --git a/src/main/java/io/github/itzispyder/ogredupealias/plugin/custom/forging/CustomTable.java b/src/main/java/io/github/itzispyder/ogredupealias/plugin/custom/forging/CustomTable.java index ed0391f..40d9c1d 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/plugin/custom/forging/CustomTable.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/plugin/custom/forging/CustomTable.java @@ -1,5 +1,8 @@ package io.github.itzispyder.ogredupealias.plugin.custom.forging; +import io.github.itzispyder.ogredupealias.plugin.RecipientList; +import io.github.itzispyder.ogredupealias.utils.ServerUtils; +import io.github.itzispyder.ogredupealias.utils.Text; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -8,11 +11,13 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Objects; public class CustomTable { + public static final RecipientList recipeSpies = new RecipientList(); private final Inventory inv; public CustomTable(Inventory inv) { @@ -23,16 +28,27 @@ public class CustomTable { getGrid().stream().filter(Objects::nonNull).forEach(item -> item.setAmount(item.getAmount() - 1)); } - public List getGrid() { + public List getGrid(boolean shapeless) { List list = new ArrayList<>(); for (int x = 0; x < 3; x++) { for (int i = 1; i < 4; i++) list.add(inv.getItem(i + (x * 9))); } + if (shapeless) { + return list.stream().filter(Objects::nonNull).sorted(Comparator.comparing(ItemStack::getTranslationKey)).toList(); + } return list; } + public List getGrid() { + return getGrid(false); + } + public CraftingKey getGridKey() { - return new CraftingKey(getGrid()); + return getGridKey(false); + } + + public CraftingKey getGridKey(boolean shapeless) { + return new CraftingKey(getGrid(shapeless)); } public ItemStack getResult() { @@ -48,10 +64,10 @@ public class CustomTable { } public boolean attemptCraft() { - if (CraftingKey.getResult(this.getGridKey()).getType().isAir()) return false; + if (CraftingKeys.getResult(this.getGridKey()).getType().isAir()) return false; ItemStack resultSlotItem = inv.getItem(this.getResultSlot()); if (resultSlotItem != null && !resultSlotItem.getType().isAir()) return false; - ItemStack result = CraftingKey.getResult(this.getGridKey()); + ItemStack result = CraftingKeys.getResult(this.getGridKey()); this.clearGrid(); inv.setItem(this.getResultSlot(),result); return true; @@ -82,6 +98,11 @@ public class CustomTable { if (slot == table.getCraftingSlot()) { e.setCancelled(true); + ServerUtils.dmEachPlayer(recipeSpies::isRecipient, Text.builder( + "\n&b&lSHAPED: &3" + table.getGridKey(false) + + "\n&b&lSHAPELESS: &3" + table.getGridKey(true) + + "\n " + ).prefix().color().build()); if (table.attemptCraft()) p.playSound(p.getLocation(), Sound.BLOCK_SMITHING_TABLE_USE,1,1); else p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK,1,1); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c69f444..08319f4 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -23,6 +23,9 @@ permissions: oda.commands.commandspy: description: Access to commandspy. default: op + oda.commands.recipespy: + description: Access to recipespy. + default: op oda.commands.irepair: description: Access to irepair. default: op @@ -78,6 +81,12 @@ commands: aliases: - cspy - cmdspy + recipespy: + description: Read what recipes you are crafting + usage: /recipespy + permission: oda.commands.recipespy + aliases: + - rspy irepair: description: Repairs and restocks your inventory! usage: /irepair