recipe update

This commit is contained in:
ImproperIssues
2023-04-16 13:17:43 -07:00
parent 56ff34b8fc
commit da7e81c342
6 changed files with 112 additions and 26 deletions

View File

@@ -3,6 +3,7 @@ package io.github.itzispyder.ogredupealias;
import io.github.itzispyder.ogredupealias.commands.commands.*; import io.github.itzispyder.ogredupealias.commands.commands.*;
import io.github.itzispyder.ogredupealias.data.Config; import io.github.itzispyder.ogredupealias.data.Config;
import io.github.itzispyder.ogredupealias.events.*; import io.github.itzispyder.ogredupealias.events.*;
import io.github.itzispyder.ogredupealias.plugin.custom.forging.CraftingKeys;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@@ -23,6 +24,7 @@ public final class OgreDupeAlias extends JavaPlugin {
instance = this; instance = this;
this.init(); this.init();
this.initConfig(); this.initConfig();
CraftingKeys.initRecipes();
} }
@Override @Override
@@ -51,6 +53,8 @@ public final class OgreDupeAlias extends JavaPlugin {
getCommand("socialspy").setTabCompleter(new SocialSpyCommand()); getCommand("socialspy").setTabCompleter(new SocialSpyCommand());
getCommand("commandspy").setExecutor(new CommandSpyCommand()); getCommand("commandspy").setExecutor(new CommandSpyCommand());
getCommand("commandspy").setTabCompleter(new CommandSpyCommand()); getCommand("commandspy").setTabCompleter(new CommandSpyCommand());
getCommand("recipespy").setExecutor(new RecipeSpyCommand());
getCommand("recipespy").setTabCompleter(new RecipeSpyCommand());
getCommand("irepair").setExecutor(new IRepairCommand()); getCommand("irepair").setExecutor(new IRepairCommand());
getCommand("irepair").setTabCompleter(new IRepairCommand()); getCommand("irepair").setTabCompleter(new IRepairCommand());
} }

View File

@@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return new ArrayList<>();
}
}

View File

@@ -1,37 +1,15 @@
package io.github.itzispyder.ogredupealias.plugin.custom.forging; package io.github.itzispyder.ogredupealias.plugin.custom.forging;
import io.github.itzispyder.ogredupealias.plugin.ItemPresets;
import io.github.itzispyder.ogredupealias.utils.ArrayUtils; import io.github.itzispyder.ogredupealias.utils.ArrayUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class CraftingKey { public class CraftingKey {
private static final Map<String,ItemStack> REGISTERED_KEYS = new HashMap<>();
public final String key; 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+NEav3GlVlIcgm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rap:{}");
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<ItemStack> input) { public CraftingKey(Iterable<ItemStack> input) {
this.key = String.join("-", ArrayUtils.toNewList(input,this::keyOfStack)); this.key = String.join("-", ArrayUtils.toNewList(input,this::keyOfStack));
} }

View File

@@ -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<String,ItemStack> 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:\"pXTxO6vKSFkC2d9r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iAgfQp9\"}]}}}-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);
}
}

View File

@@ -1,5 +1,8 @@
package io.github.itzispyder.ogredupealias.plugin.custom.forging; 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.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
@@ -8,11 +11,13 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
public class CustomTable { public class CustomTable {
public static final RecipientList recipeSpies = new RecipientList();
private final Inventory inv; private final Inventory inv;
public CustomTable(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)); getGrid().stream().filter(Objects::nonNull).forEach(item -> item.setAmount(item.getAmount() - 1));
} }
public List<ItemStack> getGrid() { public List<ItemStack> getGrid(boolean shapeless) {
List<ItemStack> list = new ArrayList<>(); List<ItemStack> list = new ArrayList<>();
for (int x = 0; x < 3; x++) { for (int x = 0; x < 3; x++) {
for (int i = 1; i < 4; i++) list.add(inv.getItem(i + (x * 9))); 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; return list;
} }
public List<ItemStack> getGrid() {
return getGrid(false);
}
public CraftingKey getGridKey() { public CraftingKey getGridKey() {
return new CraftingKey(getGrid()); return getGridKey(false);
}
public CraftingKey getGridKey(boolean shapeless) {
return new CraftingKey(getGrid(shapeless));
} }
public ItemStack getResult() { public ItemStack getResult() {
@@ -48,10 +64,10 @@ public class CustomTable {
} }
public boolean attemptCraft() { 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()); ItemStack resultSlotItem = inv.getItem(this.getResultSlot());
if (resultSlotItem != null && !resultSlotItem.getType().isAir()) return false; if (resultSlotItem != null && !resultSlotItem.getType().isAir()) return false;
ItemStack result = CraftingKey.getResult(this.getGridKey()); ItemStack result = CraftingKeys.getResult(this.getGridKey());
this.clearGrid(); this.clearGrid();
inv.setItem(this.getResultSlot(),result); inv.setItem(this.getResultSlot(),result);
return true; return true;
@@ -82,6 +98,11 @@ public class CustomTable {
if (slot == table.getCraftingSlot()) { if (slot == table.getCraftingSlot()) {
e.setCancelled(true); 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); 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); else p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK,1,1);
} }

View File

@@ -23,6 +23,9 @@ permissions:
oda.commands.commandspy: oda.commands.commandspy:
description: Access to commandspy. description: Access to commandspy.
default: op default: op
oda.commands.recipespy:
description: Access to recipespy.
default: op
oda.commands.irepair: oda.commands.irepair:
description: Access to irepair. description: Access to irepair.
default: op default: op
@@ -78,6 +81,12 @@ commands:
aliases: aliases:
- cspy - cspy
- cmdspy - cmdspy
recipespy:
description: Read what recipes you are crafting
usage: /recipespy
permission: oda.commands.recipespy
aliases:
- rspy
irepair: irepair:
description: Repairs and restocks your inventory! description: Repairs and restocks your inventory!
usage: /irepair usage: /irepair