diff --git a/src/main/java/me/dueris/genesismc/GenesisMC.java b/src/main/java/me/dueris/genesismc/GenesisMC.java index 99d2ee878..9c4c117fb 100644 --- a/src/main/java/me/dueris/genesismc/GenesisMC.java +++ b/src/main/java/me/dueris/genesismc/GenesisMC.java @@ -1,30 +1,24 @@ package me.dueris.genesismc; import io.papermc.paper.event.player.PlayerFailMoveEvent; -import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; -import javassist.bytecode.Descriptor.Iterator; import me.dueris.genesismc.choosing.ChoosingCORE; import me.dueris.genesismc.choosing.ChoosingCUSTOM; import me.dueris.genesismc.choosing.ChoosingGUI; import me.dueris.genesismc.commands.OriginCommand; -import me.dueris.genesismc.commands.PlayerSelector; import me.dueris.genesismc.commands.PowerCommand; import me.dueris.genesismc.commands.ResourceCommand; -import me.dueris.genesismc.commands.TabAutoComplete; import me.dueris.genesismc.commands.subcommands.origin.Info.InInfoCheck; import me.dueris.genesismc.commands.subcommands.origin.Info.Info; import me.dueris.genesismc.commands.subcommands.origin.Recipe; import me.dueris.genesismc.enchantments.Anvil; import me.dueris.genesismc.enchantments.EnchantTable; import me.dueris.genesismc.enchantments.WaterProtection; -import me.dueris.genesismc.enchantments.WaterProtectionNMSImpl; import me.dueris.genesismc.entity.InventorySerializer; import me.dueris.genesismc.entity.OriginPlayerUtils; import me.dueris.genesismc.events.EventListeners; import me.dueris.genesismc.events.RegisterPowersEvent; import me.dueris.genesismc.factory.CraftApoli; import me.dueris.genesismc.factory.TagRegistry; -import me.dueris.genesismc.factory.conditions.Condition; import me.dueris.genesismc.factory.conditions.ConditionExecutor; import me.dueris.genesismc.factory.conditions.CraftCondition; import me.dueris.genesismc.factory.conditions.biEntity.BiEntityCondition; @@ -36,13 +30,14 @@ import me.dueris.genesismc.factory.conditions.item.ItemCondition; import me.dueris.genesismc.factory.powers.CraftPower; import me.dueris.genesismc.factory.powers.block.WaterBreathe; -import me.dueris.genesismc.factory.powers.player.FlightElytra; import me.dueris.genesismc.factory.powers.player.PlayerRender; +import me.dueris.genesismc.factory.powers.player.inventory.Inventory; import me.dueris.genesismc.factory.powers.simple.BounceSlimeBlock; import me.dueris.genesismc.factory.powers.simple.MimicWarden; import me.dueris.genesismc.factory.powers.world.EntityGroupManager; import me.dueris.genesismc.files.GenesisDataFiles; import me.dueris.genesismc.files.TempStorageContainer; +import me.dueris.genesismc.generation.VillagerTradeHook; import me.dueris.genesismc.generation.WaterProtBookGen; import me.dueris.genesismc.hooks.papi.PlaceholderApiExtension; import me.dueris.genesismc.items.GenesisItems; @@ -53,31 +48,21 @@ import me.dueris.genesismc.utils.translation.LangConfig; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextColor; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.util.thread.NamedThreadFactory; -import net.minecraft.world.damagesource.DamageType; import org.bukkit.*; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.PluginCommand; -import org.bukkit.craftbukkit.v1_20_R3.CraftRegistry; -import org.bukkit.craftbukkit.v1_20_R3.enchantments.CraftEnchantment; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerChatEvent; -import org.bukkit.event.player.PlayerCommandSendEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scoreboard.Team; -import org.jetbrains.annotations.NotNull; import org.spigotmc.WatchdogThread; import java.io.IOException; @@ -85,7 +70,6 @@ import java.util.ArrayList; import java.util.EnumSet; import java.util.HashMap; -import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; @@ -405,13 +389,13 @@ public static void sendDebug(Object string){ @EventHandler public void chatEventTest(PlayerChatEvent e){ Player p = e.getPlayer(); - if(e.getMessage().equals("./test attempt remove origins:elytra")){ - PowerContainer power = CraftApoli.keyedPowerContainers.get("origins:elytra"); + if(e.getMessage().equals("./test attempt remove origins:shulker_inventory")){ + PowerContainer power = CraftApoli.keyedPowerContainers.get("origins:shulker_inventory"); if(OriginPlayerUtils.powerContainer.get(e.getPlayer()).get(CraftApoli.getLayerFromTag("origins:origin")).contains(power)){ OriginPlayerUtils.powerContainer.get(e.getPlayer()).get(CraftApoli.getLayerFromTag("origins:origin")).remove(power); ArrayList powerRemovedTypes = new ArrayList<>(); ArrayList> powerRemovedClasses = new ArrayList<>(); - Class c = FlightElytra.class; + Class c = Inventory.class; CraftPower craftPower = null; try { craftPower = c.newInstance(); @@ -435,14 +419,14 @@ public void chatEventTest(PlayerChatEvent e){ }else{ e.getPlayer().sendMessage("power not contained"); } - } else if (e.getMessage().equals("./test attempt grant origins:elytra")) { - PowerContainer power = CraftApoli.keyedPowerContainers.get("origins:elytra"); + } else if (e.getMessage().equals("./test attempt grant origins:shulker_inventory")) { + PowerContainer power = CraftApoli.keyedPowerContainers.get("origins:shulker_inventory"); try { ArrayList powerAppliedTypes = new ArrayList<>(); ArrayList> powerAppliedClasses = new ArrayList<>(); if(!OriginPlayerUtils.powerContainer.get(e.getPlayer()).get(CraftApoli.getLayerFromTag("origins:origin")).contains(power)){ OriginPlayerUtils.powerContainer.get(e.getPlayer()).get(CraftApoli.getLayerFromTag("origins:origin")).add(power); - Class c = FlightElytra.class; + Class c = Inventory.class; CraftPower craftPower = null; try { @@ -474,10 +458,17 @@ public void chatEventTest(PlayerChatEvent e){ } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } + } else if(e.getMessage().equals("./test attempt dump origins:shulker_inventory")){ + PowerContainer power = CraftApoli.keyedPowerContainers.get("origins:shulker_inventory"); + for(int i = 0; i < power.getJsonData().length; i++){ + System.out.println(power.getJsonData()[i]); + p.sendMessage(power.getJsonData()[i]); + } } p.getPersistentDataContainer().set(new NamespacedKey(GenesisMC.getPlugin(), "originLayer"), PersistentDataType.STRING, CraftApoli.toSaveFormat(OriginPlayerUtils.getOrigin(p), p)); } + private void start(){ getServer().getPluginManager().registerEvents(new InventorySerializer(), this); getServer().getPluginManager().registerEvents(this, this); @@ -498,6 +489,7 @@ private void start(){ getServer().getPluginManager().registerEvents(new MimicWarden(), this); getServer().getPluginManager().registerEvents(new BounceSlimeBlock(), this); getServer().getPluginManager().registerEvents(new LogoutBugWorkaround(), this); + getServer().getPluginManager().registerEvents(new VillagerTradeHook(), this); getServer().getPluginManager().registerEvents(new FoliaOriginScheduler.OriginSchedulerTree(), this); Bukkit.getServer().getPluginManager().registerEvents(new KeybindUtils(), GenesisMC.getPlugin()); if (getServer().getPluginManager().isPluginEnabled("SkinsRestorer")) { diff --git a/src/main/java/me/dueris/genesismc/commands/PowerCommand.java b/src/main/java/me/dueris/genesismc/commands/PowerCommand.java index 5acc1489e..48d58e374 100644 --- a/src/main/java/me/dueris/genesismc/commands/PowerCommand.java +++ b/src/main/java/me/dueris/genesismc/commands/PowerCommand.java @@ -1,8 +1,8 @@ package me.dueris.genesismc.commands; import me.dueris.genesismc.commands.subcommands.SubCommand; +import me.dueris.genesismc.commands.subcommands.power.*; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -13,7 +13,15 @@ public PowerCommand(){ super("power"); } - private final ArrayList subCommands = new ArrayList<>(); + private static final ArrayList subCommands = new ArrayList<>(); + static{ + subCommands.add(new Clear()); + subCommands.add(new Remove()); + subCommands.add(new Has()); + subCommands.add(new me.dueris.genesismc.commands.subcommands.power.List()); + subCommands.add(new Dump()); + subCommands.add(new Grant()); + } public ArrayList getSubCommands() { return subCommands; diff --git a/src/main/java/me/dueris/genesismc/commands/TabAutoComplete.java b/src/main/java/me/dueris/genesismc/commands/TabAutoComplete.java index 2d8327d63..d886afc41 100644 --- a/src/main/java/me/dueris/genesismc/commands/TabAutoComplete.java +++ b/src/main/java/me/dueris/genesismc/commands/TabAutoComplete.java @@ -165,7 +165,7 @@ public class TabAutoComplete implements TabCompleter { return new ArrayList<>(); } - } else if (command.getName().equalsIgnoreCase("power")) { + } else if (command.getName().equalsIgnoreCase("power")) { // /power grant Dueris if (args.length == 1) { List arguments = new ArrayList<>(); arguments.add("clear"); @@ -173,48 +173,51 @@ public class TabAutoComplete implements TabCompleter { arguments.add("has"); arguments.add("list"); arguments.add("remove"); - arguments.add("revoke"); - arguments.add("revokeall"); - arguments.add("sources"); + arguments.add("dump"); return arguments; } else if (args.length == 2) { - Collection players = Bukkit.getOnlinePlayers(); - List playernames = new ArrayList<>(); - for (Player player : players) playernames.add(player.getName()); - playernames.add("@a"); - playernames.add("@s"); - playernames.add("@e"); - playernames.add("@p"); - playernames.add("@r"); - return playernames; - } else if (args.length == 3) { - List argS = new ArrayList<>(); - for (PowerContainer c : CraftApoli.getPowers()) { - if (args[1].equalsIgnoreCase("has")) { - argS.add(c.getTag()); - } - if (args[1].equalsIgnoreCase("grant")) { - argS.add(c.getTag()); - } - if (args[1].equalsIgnoreCase("remove")) { - argS.add(c.getTag()); - } - if (args[1].equalsIgnoreCase("revoke")) { - argS.add(c.getTag()); + if(!args[0].equalsIgnoreCase("dump")){ + Collection players = Bukkit.getOnlinePlayers(); + List playernames = new ArrayList<>(); + for (Player player : players) playernames.add(player.getName()); + playernames.add("@a"); + playernames.add("@s"); + playernames.add("@e"); + playernames.add("@p"); + playernames.add("@r"); + return playernames; + }else{ + List pows = new ArrayList<>(); + for(String string : CraftApoli.keyedPowerContainers.keySet()){ + pows.add(string); } + return pows; } - - for (OriginContainer origin : CraftApoli.getOrigins()) { - if (args[1].equalsIgnoreCase("revokeall")) { - argS.add(origin.getTag()); + } else if (args.length == 3) { + if(args[0].equalsIgnoreCase("grant") + || args[0].equalsIgnoreCase("remove") + || args[0].equalsIgnoreCase("has")){ + List pows = new ArrayList<>(); + for(String string : CraftApoli.keyedPowerContainers.keySet()){ + if(!CraftApoli.keyedPowerContainers.get(string).isOriginMultipleSubPower()){ + pows.add(string); + } } + return pows; } - - return argS; - } else if (args.length >= 4) { - List ba = new ArrayList<>(); - return ba; + if(args[0].equalsIgnoreCase("grant") + || args[0].equalsIgnoreCase("remove") + || args[0].equalsIgnoreCase("has")){ + List pows = new ArrayList<>(); + for(LayerContainer layer : CraftApoli.getLayers()){ + pows.add(layer.getTag()); + } + return pows; + }else{ + List ba = new ArrayList<>(); + return ba; + } } } else if(command.getName().equals("resource")){ if(args.length == 1){ @@ -237,13 +240,13 @@ public class TabAutoComplete implements TabCompleter { return playernames; } if(args.length == 3){ - List ba = new ArrayList<>(); - for(OriginContainer origin : CraftApoli.getOrigins()){ - for(PowerContainer powerContainer : origin.getPowerContainers()){ - ba.add(powerContainer.getTag()); + List pows = new ArrayList<>(); + for(String string : CraftApoli.keyedPowerContainers.keySet()){ + if(!CraftApoli.keyedPowerContainers.get(string).isOriginMultipleSubPower()){ + pows.add(string); } } - return ba; + return pows; } if(args.length >= 4){ List ba = new ArrayList<>(); diff --git a/src/main/java/me/dueris/genesismc/commands/subcommands/power/Clear.java b/src/main/java/me/dueris/genesismc/commands/subcommands/power/Clear.java new file mode 100644 index 000000000..b636521e4 --- /dev/null +++ b/src/main/java/me/dueris/genesismc/commands/subcommands/power/Clear.java @@ -0,0 +1,26 @@ +package me.dueris.genesismc.commands.subcommands.power; + +import me.dueris.genesismc.commands.subcommands.SubCommand; +import org.bukkit.command.CommandSender; + +public class Clear extends SubCommand { + @Override + public String getName() { + return "clear"; + } + + @Override + public String getDescription() { + return "clears a power"; + } + + @Override + public String getSyntax() { + return "/power clear "; + } + + @Override + public void perform(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/dueris/genesismc/commands/subcommands/power/Dump.java b/src/main/java/me/dueris/genesismc/commands/subcommands/power/Dump.java new file mode 100644 index 000000000..bbae2e2a3 --- /dev/null +++ b/src/main/java/me/dueris/genesismc/commands/subcommands/power/Dump.java @@ -0,0 +1,26 @@ +package me.dueris.genesismc.commands.subcommands.power; + +import me.dueris.genesismc.commands.subcommands.SubCommand; +import org.bukkit.command.CommandSender; + +public class Dump extends SubCommand { + @Override + public String getName() { + return "dump"; + } + + @Override + public String getDescription() { + return "dumps the json data of a specified power"; + } + + @Override + public String getSyntax() { + return "/power dump "; + } + + @Override + public void perform(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/dueris/genesismc/commands/subcommands/power/Grant.java b/src/main/java/me/dueris/genesismc/commands/subcommands/power/Grant.java new file mode 100644 index 000000000..4a4a2f470 --- /dev/null +++ b/src/main/java/me/dueris/genesismc/commands/subcommands/power/Grant.java @@ -0,0 +1,26 @@ +package me.dueris.genesismc.commands.subcommands.power; + +import me.dueris.genesismc.commands.subcommands.SubCommand; +import org.bukkit.command.CommandSender; + +public class Grant extends SubCommand { + @Override + public String getName() { + return "grant"; + } + + @Override + public String getDescription() { + return "grants a power"; + } + + @Override + public String getSyntax() { + return "/power grant "; + } + + @Override + public void perform(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/dueris/genesismc/commands/subcommands/power/Has.java b/src/main/java/me/dueris/genesismc/commands/subcommands/power/Has.java new file mode 100644 index 000000000..40bde6553 --- /dev/null +++ b/src/main/java/me/dueris/genesismc/commands/subcommands/power/Has.java @@ -0,0 +1,26 @@ +package me.dueris.genesismc.commands.subcommands.power; + +import me.dueris.genesismc.commands.subcommands.SubCommand; +import org.bukkit.command.CommandSender; + +public class Has extends SubCommand { + @Override + public String getName() { + return "has"; + } + + @Override + public String getDescription() { + return "returns if the player has that power"; + } + + @Override + public String getSyntax() { + return "/power has "; + } + + @Override + public void perform(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/dueris/genesismc/commands/subcommands/power/List.java b/src/main/java/me/dueris/genesismc/commands/subcommands/power/List.java new file mode 100644 index 000000000..ab0cc9e9a --- /dev/null +++ b/src/main/java/me/dueris/genesismc/commands/subcommands/power/List.java @@ -0,0 +1,26 @@ +package me.dueris.genesismc.commands.subcommands.power; + +import me.dueris.genesismc.commands.subcommands.SubCommand; +import org.bukkit.command.CommandSender; + +public class List extends SubCommand { + @Override + public String getName() { + return "list"; + } + + @Override + public String getDescription() { + return "lists the powers the player has"; + } + + @Override + public String getSyntax() { + return "/power list "; + } + + @Override + public void perform(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/dueris/genesismc/commands/subcommands/power/Remove.java b/src/main/java/me/dueris/genesismc/commands/subcommands/power/Remove.java new file mode 100644 index 000000000..b788e31f5 --- /dev/null +++ b/src/main/java/me/dueris/genesismc/commands/subcommands/power/Remove.java @@ -0,0 +1,26 @@ +package me.dueris.genesismc.commands.subcommands.power; + +import me.dueris.genesismc.commands.subcommands.SubCommand; +import org.bukkit.command.CommandSender; + +public class Remove extends SubCommand { + @Override + public String getName() { + return "remove"; + } + + @Override + public String getDescription() { + return "removes a power"; + } + + @Override + public String getSyntax() { + return "/power remove "; + } + + @Override + public void perform(CommandSender sender, String[] args) { + + } +} diff --git a/src/main/java/me/dueris/genesismc/enchantments/Anvil.java b/src/main/java/me/dueris/genesismc/enchantments/Anvil.java index a9ab5adc4..e79c28d37 100644 --- a/src/main/java/me/dueris/genesismc/enchantments/Anvil.java +++ b/src/main/java/me/dueris/genesismc/enchantments/Anvil.java @@ -3,11 +3,17 @@ import me.dueris.genesismc.Bootstrap; import me.dueris.genesismc.GenesisMC; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.md_5.bungee.api.chat.BaseComponent; +import net.minecraft.server.commands.EnchantCommand; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.enchantment.EnchantmentCategory; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.craftbukkit.v1_20_R3.CraftRegistry; import org.bukkit.craftbukkit.v1_20_R3.enchantments.CraftEnchantment; import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; import org.bukkit.enchantments.Enchantment; @@ -17,6 +23,7 @@ import org.bukkit.event.inventory.PrepareAnvilEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Array; import java.util.ArrayList; @@ -25,7 +32,8 @@ import static me.dueris.genesismc.GenesisMC.waterProtectionEnchant; public class Anvil implements Listener { - public static WaterProtectionNMSImpl eimpl = Bootstrap.waterProtection; + private static EquipmentSlot[] slots = {EquipmentSlot.CHEST, EquipmentSlot.FEET, EquipmentSlot.HEAD, EquipmentSlot.LEGS}; + public static @Nullable net.minecraft.world.item.enchantment.Enchantment eimpl = CraftEnchantment.bukkitToMinecraft(CraftRegistry.ENCHANTMENT.get(new NamespacedKey("origins", "water_protection"))); public static ArrayList conflictenchantments = new ArrayList<>(); static { conflictenchantments.add(Enchantment.PROTECTION_FIRE); @@ -35,62 +43,17 @@ public class Anvil implements Listener { conflictenchantments.add(Enchantment.PROTECTION_PROJECTILE); } - @EventHandler - public void onAnvil(PrepareAnvilEvent e) { - boolean conflicts = false; - if(e.getInventory().getItem(0) != null && e.getInventory().getItem(1) != null){ - if(e.getInventory().getItem(0).containsEnchantment(CraftEnchantment.minecraftToBukkit(eimpl)) || e.getInventory().getItem(1).containsEnchantment(CraftEnchantment.minecraftToBukkit(eimpl))){ - Enchantment waterProt = CraftEnchantment.minecraftToBukkit(eimpl); - - for(Enchantment possConf : e.getInventory().getItem(0).getEnchantments().keySet()){ - if(!conflicts){ - if(!eimpl.isCompatibleWith(((CraftEnchantment)possConf).getHandle())){ - conflicts = true; - e.setResult(null); - } - } - } - for(Enchantment possConf : e.getInventory().getItem(1).getEnchantments().keySet()){ - if(!conflicts){ - if(!eimpl.isCompatibleWith(((CraftEnchantment)possConf).getHandle())){ - conflicts = true; - e.setResult(null); - } - } - } - } - } - if(e.getResult() != null && !conflicts && e.getInventory().getItem(0) != null && e.getInventory().getItem(1) != null){ - // begin anvil calculations. no conflicts and the result != null - if(e.getInventory().getItem(0).containsEnchantment(CraftEnchantment.minecraftToBukkit(eimpl)) || e.getInventory().getItem(1).containsEnchantment(CraftEnchantment.minecraftToBukkit(eimpl))){ - boolean firstContains = e.getInventory().getItem(0).containsEnchantment(CraftEnchantment.minecraftToBukkit(eimpl)); - boolean secondContains = e.getInventory().getItem(1).containsEnchantment(CraftEnchantment.minecraftToBukkit(eimpl)); - if(firstContains && secondContains){ - int firstlvl = e.getInventory().getItem(0).getEnchantments().get(CraftEnchantment.minecraftToBukkit(eimpl)); - int secondlvl = e.getInventory().getItem(1).getEnchantments().get(CraftEnchantment.minecraftToBukkit(eimpl)); - int finl = 1; - if(firstlvl > secondlvl){ - finl = firstlvl; - } else if(firstlvl < secondlvl){ - finl = secondlvl; - } else if(firstlvl == secondlvl){ - finl = firstlvl + 1; - } - setWaterProtCustomEnchantLevel(finl, e.getResult()); - } else if(firstContains && !secondContains){ - int firstlvl = e.getInventory().getItem(0).getEnchantments().get(CraftEnchantment.minecraftToBukkit(eimpl)); - setWaterProtCustomEnchantLevel(firstlvl, e.getResult()); - } else if(!firstContains && !secondContains){ - // why is this even coded bro this is unreachable - } else if(!firstContains && secondContains){ - int secondlvl = e.getInventory().getItem(1).getEnchantments().get(CraftEnchantment.minecraftToBukkit(eimpl)); - setWaterProtCustomEnchantLevel(secondlvl, e.getResult()); - } + private boolean isCompatibleWith(net.minecraft.world.item.enchantment.Enchantment other){ + for(org.bukkit.enchantments.Enchantment enchant : Anvil.conflictenchantments){ + CraftEnchantment enchantt = (CraftEnchantment) enchant; + if(other == enchantt.getHandle()){ + return true; } } + return false; } - protected static void setWaterProtCustomEnchantLevel(int lvl, ItemStack item) { + public static void setWaterProtCustomEnchantLevel(int lvl, ItemStack item) { String level = numberToRomanNum(lvl); ItemMeta meta = item.getItemMeta().clone(); meta.setCustomModelData(lvl); @@ -113,7 +76,6 @@ protected static void setWaterProtCustomEnchantLevel(int lvl, ItemStack item) { net.minecraft.world.item.ItemStack stack = CraftItemStack.asNMSCopy(item); stack.enchant(eimpl, lvl); } - private static String numberToRomanNum(int lvl){ if(lvl > 10){ diff --git a/src/main/java/me/dueris/genesismc/factory/CraftApoli.java b/src/main/java/me/dueris/genesismc/factory/CraftApoli.java index cef1b0053..84ba82c69 100644 --- a/src/main/java/me/dueris/genesismc/factory/CraftApoli.java +++ b/src/main/java/me/dueris/genesismc/factory/CraftApoli.java @@ -71,7 +71,7 @@ public static PowerContainer getPowerContainerFromTag(String tag){ * @return A copy of The null origin. **/ public static OriginContainer nullOrigin() { - return new OriginContainer(new NamespacedKey("genesis", "origin-null"), new FileContainer(new ArrayList<>(List.of("hidden", "origins")), new ArrayList<>(List.of(true, "genesis:origin-null"))), new HashMap(Map.of("impact", "0", "icon", "minecraft:player_head", "powers", "genesis:null", "order", "0", "unchooseable", true)), new ArrayList<>(List.of(new PowerContainer(new NamespacedKey("genesis", "null"), new FileContainer(new ArrayList<>(), new ArrayList<>()), false)))); + return new OriginContainer(new NamespacedKey("genesis", "origin-null"), new FileContainer(new ArrayList<>(List.of("hidden", "origins")), new ArrayList<>(List.of(true, "genesis:origin-null"))), new HashMap(Map.of("impact", "0", "icon", "minecraft:player_head", "powers", "genesis:null", "order", "0", "unchooseable", true)), new ArrayList<>(List.of(new PowerContainer(new NamespacedKey("genesis", "null"), new FileContainer(new ArrayList<>(), new ArrayList<>()), null, false)))); } @@ -124,7 +124,7 @@ public static void processNestedPowers(PowerContainer powerContainer, ArrayList< if (subPowerValue instanceof JSONObject subPowerJson) { FileContainer subPowerFile = fileToFileContainer(subPowerJson); - PowerContainer newPower = new PowerContainer(new NamespacedKey(powerFolder, powerFileName + "_" + key), subPowerFile, true, false); + PowerContainer newPower = new PowerContainer(new NamespacedKey(powerFolder, powerFileName + "_" + key), subPowerFile, subPowerJson.toJSONString().split("\n"), true, false); powerContainers.add(newPower); keyedPowerContainers.put(powerFolder + ":" + powerFileName + "_" + key, newPower); newPowerContainers.add(newPower); @@ -276,13 +276,13 @@ public static void loadOrigins() { JSONObject powerParser = (JSONObject) new JSONParser().parse(new FileReader(datapack.getAbsolutePath() + File.separator + "data" + File.separator + powerFolder + File.separator + "powers" + File.separator + powerFileName + ".json")); if (powerParser.containsKey("type") && "origins:multiple".equals(powerParser.get("type"))) { - PowerContainer powerContainer = new PowerContainer(new NamespacedKey(powerFolder, powerFileName), fileToFileContainer(powerParser), false, true); + PowerContainer powerContainer = new PowerContainer(new NamespacedKey(powerFolder, powerFileName), fileToFileContainer(powerParser), Utils.readJSONFileAsString(new File(datapack.getAbsolutePath() + File.separator + "data" + File.separator + powerFolder + File.separator + "powers" + File.separator + powerFileName + ".json")), false, true); powerContainers.add(powerContainer); keyedPowerContainers.put(powerFolder + ":" + powerFileName, powerContainer); System.out.println(new NamespacedKey(powerFolder, powerFileName).asString()); processNestedPowers(powerContainer, new ArrayList<>(), powerFolder, powerFileName); } else { - PowerContainer power = new PowerContainer(new NamespacedKey(powerFolder, powerFileName), fileToFileContainer(powerParser), false); + PowerContainer power = new PowerContainer(new NamespacedKey(powerFolder, powerFileName), fileToFileContainer(powerParser), Utils.readJSONFileAsString(new File(datapack.getAbsolutePath() + File.separator + "data" + File.separator + powerFolder + File.separator + "powers" + File.separator + powerFileName + ".json")), false); powerContainers.add(power); keyedPowerContainers.put(powerFolder + ":" + powerFileName, power); } @@ -366,7 +366,6 @@ public static void loadOrigins() { } for(PowerContainer power : getNestedPowers(keyedPowerContainers.get(string), string.split(":")[0], string.split(":")[1])){ if(power != null){ - System.out.println(power.getTag()); powerContainers.add(power); finished = true; } @@ -380,11 +379,11 @@ public static void loadOrigins() { try { JSONObject powerParser = (JSONObject) new JSONParser().parse(new FileReader(datapack.getAbsolutePath() + File.separator + "data" + File.separator + powerFolder + File.separator + "powers" + File.separator + powerFileName + ".json")); if (powerParser.containsKey("type") && "origins:multiple".equals(powerParser.get("type"))) { - PowerContainer powerContainer = new PowerContainer(new NamespacedKey(powerFolder, powerFileName), fileToFileContainer(powerParser), false, true); + PowerContainer powerContainer = new PowerContainer(new NamespacedKey(powerFolder, powerFileName), fileToFileContainer(powerParser), Utils.readJSONFileAsString(new File(datapack.getAbsolutePath() + File.separator + "data" + File.separator + powerFolder + File.separator + "powers" + File.separator + powerFileName + ".json")), false, true); powerContainers.add(powerContainer); processNestedPowers(powerContainer, powerContainers, powerFolder, powerFileName); } else { - powerContainers.add(new PowerContainer(new NamespacedKey(powerFolder, powerFileName), fileToFileContainer(powerParser), false)); + powerContainers.add(new PowerContainer(new NamespacedKey(powerFolder, powerFileName), fileToFileContainer(powerParser), Utils.readJSONFileAsString(new File(datapack.getAbsolutePath() + File.separator + "data" + File.separator + powerFolder + File.separator + "powers" + File.separator + powerFileName + ".json")), false)); } } catch (FileNotFoundException fileNotFoundException) { if (showErrors) diff --git a/src/main/java/me/dueris/genesismc/factory/powers/value_modifying/ModifyBreakSpeedPower.java b/src/main/java/me/dueris/genesismc/factory/powers/value_modifying/ModifyBreakSpeedPower.java index 6db58a35b..dc164da74 100644 --- a/src/main/java/me/dueris/genesismc/factory/powers/value_modifying/ModifyBreakSpeedPower.java +++ b/src/main/java/me/dueris/genesismc/factory/powers/value_modifying/ModifyBreakSpeedPower.java @@ -11,6 +11,7 @@ import me.dueris.genesismc.utils.PowerContainer; import me.dueris.genesismc.utils.translation.LangConfig; import org.bukkit.Bukkit; +import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -90,7 +91,7 @@ public void swing(PlayerArmSwingEvent e){ new PotionEffect( PotionEffectType.SLOW_DIGGING, 50, - Math.round(valueModifyingSuperClass.getPersistentAttributeContainer(p, MODIFYING_KEY)), + Math.round(valueModifyingSuperClass.getPersistentAttributeContainer(p, MODIFYING_KEY)) + 1, false, false, false ) ); @@ -100,18 +101,20 @@ public void swing(PlayerArmSwingEvent e){ new PotionEffect( PotionEffectType.FAST_DIGGING, 50, - Math.round(valueModifyingSuperClass.getPersistentAttributeContainer(p, MODIFYING_KEY)), + Math.round(valueModifyingSuperClass.getPersistentAttributeContainer(p, MODIFYING_KEY)) + 1, false, false, false ) ); } - shouldDrop.add(p); - new BukkitRunnable() { - @Override - public void run() { - shouldDrop.remove(p); - } - }.runTaskLater(GenesisMC.getPlugin(), 40); + if(p.getGameMode() != GameMode.CREATIVE){ + shouldDrop.add(p); + new BukkitRunnable() { + @Override + public void run() { + shouldDrop.remove(p); + } + }.runTaskLater(GenesisMC.getPlugin(), 40); + } } } else { setActive(p, power.getTag(), false); diff --git a/src/main/java/me/dueris/genesismc/factory/powers/value_modifying/ModifyHarvestPower.java b/src/main/java/me/dueris/genesismc/factory/powers/value_modifying/ModifyHarvestPower.java index acb3d4959..4592ab2ed 100644 --- a/src/main/java/me/dueris/genesismc/factory/powers/value_modifying/ModifyHarvestPower.java +++ b/src/main/java/me/dueris/genesismc/factory/powers/value_modifying/ModifyHarvestPower.java @@ -41,7 +41,7 @@ public void runD(BlockBreakEvent e) { ConditionExecutor conditionExecutor = me.dueris.genesismc.GenesisMC.getConditionExecutor(); for (PowerContainer power : OriginPlayerUtils.getMultiPowerFileFromType(p, getPowerFile(), layer)) { if (conditionExecutor.check("block_condition", "block_conditions", p, power, "origins:modify_harvest", p, null, e.getBlock(), null, p.getItemInHand(), null)) { - if (power.get("allow", null) == "true") { + if (power.get("allow", null) != "true") { e.setDropItems(false); setActive(p, power.getTag(), true); diff --git a/src/main/java/me/dueris/genesismc/generation/VillagerTradeHook.java b/src/main/java/me/dueris/genesismc/generation/VillagerTradeHook.java new file mode 100644 index 000000000..0ca641be3 --- /dev/null +++ b/src/main/java/me/dueris/genesismc/generation/VillagerTradeHook.java @@ -0,0 +1,45 @@ +package me.dueris.genesismc.generation; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.VillagerAcquireTradeEvent; + +public class VillagerTradeHook implements Listener { + @EventHandler + public void test(VillagerAcquireTradeEvent e){ +// Villager villager = (Villager) e.getEntity(); +// if(villager.getProfession().equals(Villager.Profession.LIBRARIAN)){ +// Random chanceOfSpawnRandom = new Random(); +// if(chanceOfSpawnRandom.nextInt(100) > 97 && (e.getRecipe().getResult().getType().equals(Material.ENCHANTED_BOOK))){ +// Random emeraldCountRandom = new Random(); +// Random shouldAddBookRandom = new Random(); +// Random chanceOfLevelRandom = new Random(); +// Random maxUsesRandom = new Random(); +// int maxUses = maxUsesRandom.nextInt(11); +// int chanceOfLevel = chanceOfLevelRandom.nextInt(1000); +// boolean shouldAddBook = shouldAddBookRandom.nextBoolean(); +// int emeraldCount = emeraldCountRandom.nextInt(53); +// int lvl; +// if(chanceOfLevel <= 40){ +// lvl = 1; +// } else if(chanceOfLevel <= 65 && chanceOfLevel >= 41){ +// lvl = 2; +// } else if(chanceOfLevel <= 85 && chanceOfLevel >= 66){ +// lvl = 3; +// } else if(chanceOfLevel <= 100 && chanceOfLevel >= 86){ +// lvl = 4; +// } else { +// lvl = 1; +// } +// ItemStack item = new ItemStack(Material.ENCHANTED_BOOK); +// Anvil.setWaterProtCustomEnchantLevel(lvl, item); +// MerchantRecipe recipe = new MerchantRecipe(item, maxUses); +// recipe.addIngredient(new ItemStack(Material.EMERALD, emeraldCount)); +// if(shouldAddBook){ +// recipe.addIngredient(new ItemStack(Material.BOOK, 1)); +// } +// e.setRecipe(recipe); +// } +// } + } +} diff --git a/src/main/java/me/dueris/genesismc/utils/PowerContainer.java b/src/main/java/me/dueris/genesismc/utils/PowerContainer.java index ff8408052..ead000b8f 100644 --- a/src/main/java/me/dueris/genesismc/utils/PowerContainer.java +++ b/src/main/java/me/dueris/genesismc/utils/PowerContainer.java @@ -19,17 +19,19 @@ public class PowerContainer implements Serializable { FileContainer powerFile; boolean originMultiple; boolean originMultipleParent; + String[] jsonData; /** * @param powerTag The power tag. * @param powerFile The data within a power file. * @param originMultiple Tells the plugin if its an instance of an origins:multiple sub-power */ - public PowerContainer(NamespacedKey powerTag, FileContainer powerFile, boolean originMultiple){ + public PowerContainer(NamespacedKey powerTag, FileContainer powerFile, String[] jsonData, boolean originMultiple){ this.powerTag = powerTag; this.powerFile = powerFile; this.originMultiple = originMultiple; this.originMultipleParent = false; + this.jsonData = jsonData; } /** @@ -38,11 +40,12 @@ public PowerContainer(NamespacedKey powerTag, FileContainer powerFile, boolean o * @param originMultiple Tells the plugin if its an instance of an origins:multiple sub-power * @param originMultipleParent Tells the plugin if its an origins:multiple parent power */ - public PowerContainer(NamespacedKey powerTag, FileContainer powerFile, boolean originMultiple, boolean originMultipleParent){ + public PowerContainer(NamespacedKey powerTag, FileContainer powerFile, String[] jsonData, boolean originMultiple, boolean originMultipleParent){ this.powerTag = powerTag; this.powerFile = powerFile; this.originMultiple = false; this.originMultipleParent = originMultipleParent; + this.jsonData = jsonData; } public FileContainer getPowerFile() { @@ -53,6 +56,10 @@ public boolean isOriginMultipleSubPower(){ return this.originMultiple; } + public String[] getJsonData(){ + return this.jsonData; + } + /** * @return The power tag. */ diff --git a/src/main/java/me/dueris/genesismc/utils/Utils.java b/src/main/java/me/dueris/genesismc/utils/Utils.java index 7d5a8a910..11146d64a 100644 --- a/src/main/java/me/dueris/genesismc/utils/Utils.java +++ b/src/main/java/me/dueris/genesismc/utils/Utils.java @@ -1,12 +1,12 @@ package me.dueris.genesismc.utils; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; -import java.util.Random; +import java.util.*; import java.util.function.BinaryOperator; import java.util.function.Predicate; @@ -45,14 +45,17 @@ public static Registry getRegistry(ResourceKey> registry){ return CraftRegistry.getMinecraftRegistry().registryOrThrow(registry); } - public String readJSONFileAsString(File file) { - String content = ""; - try { - content = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath()))); - } catch (IOException e) { + public static String[] readJSONFileAsString(File file) { + List lines = new ArrayList<>(); + try(BufferedReader br = new BufferedReader(new FileReader(file))) { + String line; + while ((line = br.readLine()) != null){ + lines.add(line); + } + } catch (IOException e){ e.printStackTrace(); } - return content; + return lines.toArray(new String[0]); } public static Predicate booleanToPredicate(boolean value) {