diff --git a/README.md b/README.md index 15c9f0d..ae99890 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,9 @@ To find out what versions have been tested look at TestedVersions.txt in the pro We will likely be slow to test new Minecraft versions, but you can probably assume that EsTools will be fully functional on new versions. -**We officially support Spigot/Bukkit/Paper 1.0.0 and above.** +**We officially support the following:** +- Bukkit/Spigot/Paper 1.0.0+ +- Folia Latest Build For support DM us at: Discord: @copokbl and @calcilore. Or email support@serble.net. diff --git a/TestedVersions.txt b/TestedVersions.txt index 2804932..499f5be 100644 --- a/TestedVersions.txt +++ b/TestedVersions.txt @@ -1,5 +1,11 @@ -1.20.4 +Folia: +1.20.4 Failing (/estools test) + +Bukkit: +1.21 +1.20.6 1.19.4 +1.18.2 1.17.1 1.16.1 1.15.2 @@ -15,6 +21,4 @@ 1.5.2 1.4.7 1.3.2 -1.2.5 -1.1.0 -1.0.0 \ No newline at end of file +1.2.5 \ No newline at end of file diff --git a/abstraction.md b/abstraction.md new file mode 100644 index 0000000..c62ed5f --- /dev/null +++ b/abstraction.md @@ -0,0 +1,3 @@ +# TODO +- Fix testing on folia +- Fix teleport event not working on folia \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6764ab7..b6b4a7a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.serble.EsTools EsTools - 4.3.2 + 5.0.0 jar EsTools @@ -37,7 +37,36 @@ org.bstats net.serble.estools + + co.aikar.taskchain + net.serble.taskchain + + + org.yaml.snakeyaml + net.serble.snakeyaml + + + com.google.gson + net.serble.gson + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + META-INF/MANIFEST.MF + + + + + + + + + @@ -70,6 +99,19 @@ jitpack.io https://jitpack.io + + papermc + https://repo.papermc.io/repository/maven-public/ + + + aikar + https://repo.aikar.co/content/groups/aikar/ + + + Sonatype-public + SnakeYAML repository + http://oss.sonatype.org/content/groups/public/ + @@ -95,6 +137,29 @@ com.google.code.gson gson 2.11.0 + compile + + + io.papermc + paperlib + 1.0.7 + compile + + + dev.folia + folia-api + 1.20.4-R0.1-SNAPSHOT + provided + + + co.aikar + taskchain-bukkit + 3.7.2 + + + org.yaml + snakeyaml + 2.2-SNAPSHOT diff --git a/src/main/java/net/serble/estools/Bitmask.java b/src/main/java/net/serble/estools/Bitmask.java new file mode 100644 index 0000000..59b9b49 --- /dev/null +++ b/src/main/java/net/serble/estools/Bitmask.java @@ -0,0 +1,26 @@ +package net.serble.estools; + +public class Bitmask { + private final boolean[] bits; + + public Bitmask(int value) { + bits = new boolean[32]; + for (int i = 0; i < 32; i++) { + bits[i] = (value & (1 << i)) != 0; + } + } + + public boolean getBit(int i) { + return bits[i]; + } + + public int getValueOfFirstBits(int amount) { + int value = 0; + for (int i = 0; i < amount; i++) { + if (bits[i]) { + value |= 1 << i; + } + } + return value; + } +} diff --git a/src/main/java/net/serble/estools/Commands/Back.java b/src/main/java/net/serble/estools/Commands/Back.java index 6db555a..50a9c64 100644 --- a/src/main/java/net/serble/estools/Commands/Back.java +++ b/src/main/java/net/serble/estools/Commands/Back.java @@ -3,35 +3,38 @@ import java.util.HashMap; import java.util.UUID; +import net.serble.estools.ServerApi.EsEventListener; +import net.serble.estools.ServerApi.EsLocation; import net.serble.estools.Main; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityEvent; -import org.bukkit.event.entity.PlayerDeathEvent; +import net.serble.estools.ServerApi.EsTeleportCause; +import net.serble.estools.ServerApi.Events.EsPlayerDeathEvent; +import net.serble.estools.ServerApi.Events.EsPlayerTeleportEvent; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsEvent; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import net.serble.estools.EsToolsCommand; -import org.bukkit.event.player.PlayerTeleportEvent; +import net.serble.estools.ServerApi.ServerPlatform; -public class Back extends EsToolsCommand implements Listener { - private static final HashMap prevLocations = new HashMap<>(); +public class Back extends EsToolsCommand implements EsEventListener { + private static final HashMap prevLocations = new HashMap<>(); @Override public void onEnable() { - Bukkit.getServer().getPluginManager().registerEvents(this, Main.plugin); + Main.registerEvents(this); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } + + if (Main.platform == ServerPlatform.Folia) { + send(sender, "&cCurrently due to Folia issues /back only works for death locations"); + } - Player p = (Player) sender; + EsPlayer p = (EsPlayer) sender; if (prevLocations.containsKey(p.getUniqueId())) { p.teleport(prevLocations.get(p.getUniqueId())); send(sender, "&aTeleported to last location!"); @@ -42,24 +45,22 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return true; } - @EventHandler - public void onDeath(PlayerDeathEvent e) { - if (Main.majorVersion > 1) { - prevLocations.put(e.getEntity().getUniqueId(), e.getEntity().getLocation()); - return; - } + @Override + public void executeEvent(EsEvent event) { + if (event instanceof EsPlayerDeathEvent) { + EsPlayerDeathEvent e = (EsPlayerDeathEvent) event; - try { - Player p = (Player)EntityEvent.class.getMethod("getEntity").invoke(e); + EsPlayer p = e.getPlayer(); prevLocations.put(p.getUniqueId(), p.getLocation()); - } catch (Exception ex) { - Bukkit.getLogger().severe(ex.toString()); + return; } - } - @EventHandler - public void onTeleport(PlayerTeleportEvent e) { - if (equalsOr(e.getCause(), PlayerTeleportEvent.TeleportCause.COMMAND, PlayerTeleportEvent.TeleportCause.PLUGIN)) { + if (event instanceof EsPlayerTeleportEvent) { + EsPlayerTeleportEvent e = (EsPlayerTeleportEvent) event; + if (Main.minecraftVersion.getMinor() > 9 && + !equalsOr(e.getCause(), EsTeleportCause.Command, EsTeleportCause.Plugin, EsTeleportCause.Unknown)) { + return; + } prevLocations.put(e.getPlayer().getUniqueId(), e.getPlayer().getLocation()); } } diff --git a/src/main/java/net/serble/estools/Commands/Buddha.java b/src/main/java/net/serble/estools/Commands/Buddha.java index 2aa7029..8e8d6fa 100644 --- a/src/main/java/net/serble/estools/Commands/Buddha.java +++ b/src/main/java/net/serble/estools/Commands/Buddha.java @@ -1,36 +1,33 @@ package net.serble.estools.Commands; -import net.serble.estools.ConfigManager; +import net.serble.estools.Config.ConfigManager; import net.serble.estools.EntityCommand; import net.serble.estools.Main; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageEvent; +import net.serble.estools.ServerApi.EsEventListener; +import net.serble.estools.ServerApi.Events.EsEntityDamageEvent; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsEvent; +import net.serble.estools.ServerApi.Interfaces.EsLivingEntity; import java.util.*; -public class Buddha extends EntityCommand implements Listener { +public class Buddha extends EntityCommand implements EsEventListener { private static final HashMap currentPlayers = new HashMap<>(); private static final String usage = genUsage("/buddha [entity] [time]"); + private static final String configFile = "buddhas.yml"; - @Override + @SuppressWarnings("unchecked") // I'm right, trust me + @Override public void onEnable() { - Bukkit.getServer().getPluginManager().registerEvents(this, Main.plugin); + Main.registerEvents(this); - FileConfiguration f = ConfigManager.load("gods.yml"); - List buddhas = f.getStringList("buddhas"); - buddhas.forEach(w -> currentPlayers.put(UUID.fromString(w), -1)); + List f = (List) ConfigManager.load(configFile, ArrayList.class); + f.forEach(w -> currentPlayers.put(UUID.fromString(w), -1)); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - LivingEntity p; + public boolean execute(EsCommandSender sender, String[] args) { + EsLivingEntity p; int timer = -1; if (args.length == 0) { @@ -38,7 +35,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - p = (LivingEntity) sender; + p = (EsLivingEntity) sender; } else { p = getEntity(sender, args[0]); @@ -65,10 +62,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if (taskId == -1) { save(); } else { - Bukkit.getScheduler().cancelTask(taskId); + Main.server.cancelTask(taskId); } - send(sender, "&aBuddha mode &6disabled&a for &6%s", getEntityName(p)); + send(sender, "&aBuddha mode &6disabled&a for &6%s", p.getName()); } else { int taskId = -1; @@ -77,7 +74,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if (timer >= 0) { timerStr = timer / 20d + " seconds"; - taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> currentPlayers.remove(uid), timer); + taskId = Main.server.runTaskLater(() -> currentPlayers.remove(uid), timer); } currentPlayers.put(uid, taskId); @@ -85,51 +82,40 @@ public boolean onCommand(CommandSender sender, Command command, String label, St save(); } - send(sender, "&aBuddha mode &6enabled&a for &6%s&a for &6%s", getEntityName(p), timerStr); + send(sender, "&aBuddha mode &6enabled&a for &6%s&a for &6%s", p.getName(), timerStr); } return true; } - private double getDamageFromEvent(EntityDamageEvent e) { - if (Main.majorVersion > 5) { - return e.getDamage(); + private static void save() { + List buddhas = new ArrayList<>(); + for (Map.Entry kv : currentPlayers.entrySet()) { + // only save if there isn't a time limit! + if (kv.getValue() == -1) { + buddhas.add(kv.getKey().toString()); + } } - try { - return (double)(int)EntityDamageEvent.class.getMethod("getDamage").invoke(e); - } catch (Exception ex) { - Bukkit.getLogger().severe(ex.toString()); - return 0d; - } + ConfigManager.save(configFile, buddhas); } - private void setDamageFromEvent(EntityDamageEvent e, @SuppressWarnings("SameParameterValue") double d) { - if (Main.majorVersion > 5) { - e.setDamage(d); + @Override + public void executeEvent(EsEvent event) { + if (!(event instanceof EsEntityDamageEvent)) { return; } + EsEntityDamageEvent e = (EsEntityDamageEvent) event; - try { - //noinspection JavaReflectionMemberAccess, It's an int in older versions - EntityDamageEvent.class.getMethod("setDamage", int.class).invoke(e, (int) d); - } catch (Exception ex) { - Bukkit.getLogger().severe(ex.toString()); - } - } - - @EventHandler - public void damage(EntityDamageEvent e) { - if (!(e.getEntity() instanceof LivingEntity) || !currentPlayers.containsKey(e.getEntity().getUniqueId())) { + if (!(e.getEntity() instanceof EsLivingEntity) || !currentPlayers.containsKey(e.getEntity().getUniqueId())) { return; } - - LivingEntity entity = (LivingEntity) e.getEntity(); + EsLivingEntity entity = (EsLivingEntity) e.getEntity(); // Get all our vars since Minecraft broke everything in 1.6 - double damage = getDamageFromEvent(e); - double health = getHealth(entity); - double maxHealth = getMaxHealth(entity); + double damage = e.getDamage(); + double health = entity.getHealth(); + double maxHealth = entity.getMaxHealth(); if (damage < health) { // Not lethal return; @@ -139,22 +125,7 @@ public void damage(EntityDamageEvent e) { double extraDamage = damage - health; double resultingDamageTaken = extraDamage % maxHealth; - setDamageFromEvent(e, 0); - setHealth(entity, maxHealth - resultingDamageTaken); - } - - private static void save() { - FileConfiguration f = new YamlConfiguration(); - - List buddhas = new ArrayList<>(); - for (Map.Entry kv : currentPlayers.entrySet()) { - // only save if there isn't a time limit! - if (kv.getValue() == -1) { - buddhas.add(kv.getKey().toString()); - } - } - - f.set("buddhas", buddhas); - ConfigManager.save("gods.yml", f); + e.setDamage(0); + entity.setHealth(maxHealth - resultingDamageTaken); } } diff --git a/src/main/java/net/serble/estools/Commands/CChest.java b/src/main/java/net/serble/estools/Commands/CChest.java index 271ad1c..f29b923 100644 --- a/src/main/java/net/serble/estools/Commands/CChest.java +++ b/src/main/java/net/serble/estools/Commands/CChest.java @@ -1,49 +1,38 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import net.serble.estools.ConfigManager; +import net.serble.estools.Config.ConfigManager; import net.serble.estools.Main; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.*; -import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; +import net.serble.estools.ServerApi.*; +import net.serble.estools.ServerApi.Events.*; +import net.serble.estools.ServerApi.Interfaces.*; import java.util.*; -public class CChest extends EsToolsCommand implements Listener { +public class CChest extends EsToolsCommand implements EsEventListener { - public static HashMap cChests = new HashMap<>(); + public static HashMap cChests = new HashMap<>(); @Override public void onEnable() { - if (Main.majorVersion > 4) { - Bukkit.getServer().getPluginManager().registerEvents(this, Main.plugin); + if (Main.minecraftVersion.getMinor() > 4) { + Main.registerEvents(this); } } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - if (Main.majorVersion < 7) { + if (Main.minecraftVersion.getMinor() < 7) { send(sender, "&cWarning: CChest doesn't work to full capacity"); } - Player p = (Player)sender; + EsPlayer p = (EsPlayer) sender; - if (p.getGameMode().equals(GameMode.CREATIVE)) { + if (p.getGameMode().equals(EsGameMode.Creative)) { if (checkPerms(sender, "cchest.creative")) { return false; } @@ -54,14 +43,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } UUID uid = p.getUniqueId(); - Inventory inv = cChests.get(uid); + EsInventory inv = cChests.get(uid); if (inv == null) { - Inventory loaded = loadPlayer(p); + EsInventory loaded = loadPlayer(p); if (loaded != null) { inv = loaded; } else { - inv = Bukkit.createInventory(null, 54, translate("&1Creative Chest")); + inv = Main.server.createInventory(null, 54, translate("&1Creative Chest")); } } @@ -71,28 +60,27 @@ public boolean onCommand(CommandSender sender, Command command, String label, St cChests.put(uid, inv); return true; } - - @EventHandler - public void inventoryClick(final InventoryClickEvent e) { - UUID uid = e.getWhoClicked().getUniqueId(); - ItemStack currentItem = e.getCurrentItem(); - + + private void onInventoryClick(final EsInventoryClickEvent e) { + UUID uid = e.getPlayer().getUniqueId(); + EsItemStack currentItem = e.getCurrentItem(); + // Check if inventory is cChest - if (!cChests.containsKey(uid) || !cChests.get(uid).equals(e.getInventory()) || e.getClickedInventory() == null) { + if (!cChests.containsKey(uid) || !e.getInventory().isEqualTo(cChests.get(uid)) || e.getClickedInventory() == null) { return; } - if (e.getAction().equals(InventoryAction.COLLECT_TO_CURSOR)) { + if (e.getAction().equals(EsInventoryAction.CollectToCursor)) { e.setCancelled(true); - ItemStack cursor = e.getCursor(); + EsItemStack cursor = e.getCursor(); if (cursor == null) { return; } - Inventory pInv = e.getWhoClicked().getInventory(); - for (Map.Entry i : pInv.all(cursor.getType()).entrySet()) { - ItemStack item = i.getValue(); + EsInventory pInv = e.getPlayer().getInventory(); + for (Map.Entry i : pInv.all(cursor.getType()).entrySet()) { + EsItemStack item = i.getValue(); if (item == null) { continue; @@ -113,9 +101,9 @@ public void inventoryClick(final InventoryClickEvent e) { } // If player inventory - if (!e.getClickedInventory().equals(cChests.get(uid))) { + if (!e.getClickedInventory().isEqualTo(cChests.get(uid))) { // Shift click into cChest - if (equalsOr(e.getClick(), ClickType.SHIFT_LEFT, ClickType.SHIFT_RIGHT) && currentItem != null) { + if (equalsOr(e.getClick(), EsClickType.ShiftLeft, EsClickType.ShiftRight) && currentItem != null) { e.setCancelled(true); e.getInventory().addItem(currentItem.clone()); @@ -125,23 +113,23 @@ public void inventoryClick(final InventoryClickEvent e) { } // Right click in cChest (clear item) - if (e.getClick().equals(ClickType.RIGHT) && currentItem != null) { + if (e.getClick().equals(EsClickType.Right) && currentItem != null) { e.setCancelled(true); e.getClickedInventory().setItem(e.getSlot(), null); return; } // Add to chest - if (equalsOr(e.getAction(), InventoryAction.PLACE_ALL, InventoryAction.PLACE_ONE, InventoryAction.PLACE_SOME)) { + if (equalsOr(e.getAction(), EsInventoryAction.PlaceAll, EsInventoryAction.PlaceOne, EsInventoryAction.PlaceSome)) { e.setCancelled(true); - ItemStack item = e.getCursor(); + EsItemStack item = e.getCursor(); if (item == null) { return; } - ItemStack finalItem = item.clone(); + EsItemStack finalItem = item.clone(); - if (equalsOr(e.getAction(), InventoryAction.PLACE_ONE, InventoryAction.PLACE_SOME)) { + if (equalsOr(e.getAction(), EsInventoryAction.PlaceOne, EsInventoryAction.PlaceSome)) { finalItem.setAmount(1); } @@ -150,83 +138,116 @@ public void inventoryClick(final InventoryClickEvent e) { } // Remove from cChest - if (equalsOr(e.getClick(), ClickType.LEFT, ClickType.DROP, ClickType.CONTROL_DROP, - ClickType.SHIFT_LEFT, ClickType.SHIFT_RIGHT) && currentItem != null) { - ItemStack item = currentItem.clone(); + if (equalsOr(e.getClick(), EsClickType.Left, EsClickType.Drop, EsClickType.ControlDrop, + EsClickType.ShiftLeft, EsClickType.ShiftRight) && currentItem != null) { + EsItemStack item = currentItem.clone(); setItemTask(e.getInventory(), e.getSlot(), item); } } - private static void setItemTask(Inventory inv, int slot, ItemStack item) { - Bukkit.getScheduler().runTask(Main.plugin, () -> inv.setItem(slot, item)); + private static void setItemTask(EsInventory inv, int slot, EsItemStack item) { + Main.server.runTask(() -> inv.setItem(slot, item)); } // Cancel drag if inside cChest - @EventHandler - public void onInventoryDrag(final InventoryDragEvent e) { - Inventory inv = cChests.get(e.getWhoClicked().getUniqueId()); - if (!e.getInventory().equals(inv)) { + private void onInventoryDrag(final EsInventoryDragEvent e) { + EsInventory inv = cChests.get(e.getPlayer().getUniqueId()); + if (!e.getInventory().isEqualTo(inv)) { return; } // Check if any of the slots dragged are in the cChest - for (int slot : e.getRawSlots()) { - if (inv.equals(e.getView().getInventory(slot))) { + for (int slot : e.getChangedSlots()) { + if (e.getView().getInventory(slot).isEqualTo(inv)) { e.setCancelled(true); return; } } } - public static Inventory loadPlayer(Player p) { + public static EsInventory loadPlayer(EsPlayer p) { UUID uid = p.getUniqueId(); - FileConfiguration f = ConfigManager.load("cchests/" + uid + ".yml"); - - if (!f.contains("items")) { - return null; - } - - @SuppressWarnings("unchecked") - ItemStack[] content = ((ArrayList) Objects.requireNonNull(f.get("items"))).toArray(new ItemStack[0]); + @SuppressWarnings("unchecked") + List f = (List) ConfigManager.load( + "cchests/" + uid + ".yml", + ArrayList.class, + EsSerialisableItemStack.class); + EsItemStack[] content = new EsItemStack[f.size()]; + for (int i = 0; i < content.length; i++) { + if (f.get(i) == null) { + content[i] = null; + continue; + } + content[i] = f.get(i).toItemStack(); + } - Inventory inv = Bukkit.createInventory(null, 54, translate("&1Creative Chest")); + EsInventory inv = Main.server.createInventory(null, 54, translate("&1Creative Chest")); inv.setContents(content); cChests.put(uid, inv); return inv; } - - public static void savePlayer(Player p) { + + public static void savePlayer(EsPlayer p) { UUID uid = p.getUniqueId(); if (!cChests.containsKey(uid)) { return; } - - FileConfiguration f = new YamlConfiguration(); - f.set("items", cChests.get(uid).getContents()); - ConfigManager.save("cchests/" + uid + ".yml", f); + + EsInventory inv = cChests.get(uid); + EsSerialisableItemStack[] contents = new EsSerialisableItemStack[inv.getContents().length]; + for (int i = 0; i < inv.getContents().length; i++) { + EsItemStack stack = inv.getContents()[i]; + contents[i] = stack == null ? null : EsSerialisableItemStack.generate(stack); + } + + ConfigManager.save("cchests/" + uid + ".yml", contents); } - @EventHandler - public void onClose(InventoryCloseEvent e) { + private void onClose(EsInventoryCloseEvent e) { UUID uid = e.getPlayer().getUniqueId(); - if (e.getInventory().equals(cChests.get(uid))) { - savePlayer((Player)e.getPlayer()); + if (e.getInventory().isEqualTo(cChests.get(uid))) { + savePlayer(e.getPlayer()); } } - @EventHandler - public void onQuit(PlayerQuitEvent e) { + private void onQuit(EsPlayerQuitEvent e) { savePlayer(e.getPlayer()); cChests.remove(e.getPlayer().getUniqueId()); } - - @EventHandler - public void onKick(PlayerKickEvent e) { + + private void onKick(EsPlayerKickEvent e) { savePlayer(e.getPlayer()); cChests.remove(e.getPlayer().getUniqueId()); } + + @Override + public void executeEvent(EsEvent event) { + if (event instanceof EsPlayerQuitEvent) { + onQuit((EsPlayerQuitEvent) event); + return; + } + + if (event instanceof EsPlayerKickEvent) { + onKick((EsPlayerKickEvent) event); + return; + } + + if (event instanceof EsInventoryClickEvent) { + onInventoryClick((EsInventoryClickEvent) event); + return; + } + + if (event instanceof EsInventoryCloseEvent) { + onClose((EsInventoryCloseEvent) event); + return; + } + + if (event instanceof EsInventoryDragEvent) { + onInventoryDrag((EsInventoryDragEvent) event); + } + } } diff --git a/src/main/java/net/serble/estools/Commands/ClearInv.java b/src/main/java/net/serble/estools/Commands/ClearInv.java index 99983b7..d84f683 100644 --- a/src/main/java/net/serble/estools/Commands/ClearInv.java +++ b/src/main/java/net/serble/estools/Commands/ClearInv.java @@ -1,9 +1,8 @@ package net.serble.estools.Commands; import net.serble.estools.MultiPlayerCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.ArrayList; @@ -11,15 +10,15 @@ public class ClearInv extends MultiPlayerCommand { private static final String usage = genUsage("/ci [player2]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - ArrayList players = new ArrayList<>(); + public boolean execute(EsCommandSender sender, String[] args) { + ArrayList players = new ArrayList<>(); if (args.length == 0) { if (isNotPlayer(sender, usage)) { return false; } - players.add((Player)sender); + players.add((EsPlayer) sender); } else { players = getPlayers(sender, args); @@ -28,7 +27,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } } - for (Player p : players) { + for (EsPlayer p : players) { p.getInventory().clear(); } diff --git a/src/main/java/net/serble/estools/Commands/Day.java b/src/main/java/net/serble/estools/Commands/Day.java index ff18a30..7b60114 100644 --- a/src/main/java/net/serble/estools/Commands/Day.java +++ b/src/main/java/net/serble/estools/Commands/Day.java @@ -1,19 +1,18 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class Day extends EsToolsCommand { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - ((Player)sender).getWorld().setTime(1000); + ((EsPlayer) sender).getWorld().setTime(1000); send(sender, "&aSet time to &6day"); return true; } diff --git a/src/main/java/net/serble/estools/Commands/Dismount.java b/src/main/java/net/serble/estools/Commands/Dismount.java index dd76759..7a1f84f 100644 --- a/src/main/java/net/serble/estools/Commands/Dismount.java +++ b/src/main/java/net/serble/estools/Commands/Dismount.java @@ -2,10 +2,8 @@ import net.serble.estools.EntityCommand; import net.serble.estools.Main; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsEntity; import java.util.ArrayList; import java.util.List; @@ -13,10 +11,10 @@ public class Dismount extends EntityCommand { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - List targets = new ArrayList<>(); + public boolean execute(EsCommandSender sender, String[] args) { + List targets = new ArrayList<>(); for (String arg : args) { // Can only be living Entity in pre 1.2 - Entity entity = Main.majorVersion >= 2 ? getNonLivingEntity(sender, arg) : getEntity(sender, arg); + EsEntity entity = Main.minecraftVersion.getMinor() >= 2 ? getNonLivingEntity(sender, arg) : getEntity(sender, arg); if (entity == null) { return false; } @@ -24,21 +22,17 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } if (targets.isEmpty()) { - if (!(sender instanceof Entity)) { + if (!(sender instanceof EsEntity)) { send(sender, "&cConsole must specify a rider"); return false; } - targets.add((Entity) sender); + targets.add((EsEntity) sender); } boolean anySuccess = false; - for (Entity entity : targets) { - if (Main.majorVersion >= 2) { - anySuccess = anySuccess || entity.leaveVehicle(); - } else { - anySuccess = anySuccess || ((LivingEntity) sender).leaveVehicle(); - } + for (EsEntity entity : targets) { + anySuccess = anySuccess || entity.leaveVehicle(); } if (!anySuccess) { diff --git a/src/main/java/net/serble/estools/Commands/EditSign.java b/src/main/java/net/serble/estools/Commands/EditSign.java index 521d8ee..d7940ec 100644 --- a/src/main/java/net/serble/estools/Commands/EditSign.java +++ b/src/main/java/net/serble/estools/Commands/EditSign.java @@ -2,24 +2,16 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.Main; -import org.bukkit.Bukkit; -import org.bukkit.block.Block; -import org.bukkit.block.Sign; -import org.bukkit.block.sign.SignSide; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.*; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; public class EditSign extends EsToolsCommand { private static final String usage = genUsage("/editsign [line]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } @@ -29,16 +21,16 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - Player p = (Player) sender; + EsPlayer p = (EsPlayer) sender; - Block signB = getTargetBlock(p); + EsBlock signB = p.getTargetBlock(); - if (signB == null || !(signB.getState() instanceof Sign)) { + if (!(signB instanceof EsSign)) { send(sender, "&cYou must be looking at a sign!"); return false; } - Sign sign = (Sign) signB.getState(); + EsSign sign = (EsSign) signB; switch (args[0].toLowerCase()) { case "glow": @@ -79,11 +71,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St String lineText = translate(lineTextBuilder.toString()).trim(); - if (Main.majorVersion >= 20) { - SignSide side = sign.getTargetSide(p); + if (Main.minecraftVersion.getMinor() >= 20) { + EsSignSide side = sign.getTargetSide(p); side.setLine(lineNum - 1, lineText); } else { - //noinspection deprecation sign.setLine(lineNum - 1, lineText); } sign.update(); @@ -98,7 +89,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); if (args.length == 1) { @@ -107,7 +98,7 @@ public List tabComplete(CommandSender sender, String[] args, String lArg tab.add("3"); tab.add("4"); - if (Main.majorVersion >= 17) { // only add glow autocomplete if it exists + if (Main.minecraftVersion.getMinor() >= 17) { // only add glow autocomplete if it exists tab.add("glow"); tab.add("unglow"); } @@ -116,27 +107,9 @@ public List tabComplete(CommandSender sender, String[] args, String lArg return tab; } - public Block getTargetBlock(Player p) { - if (Main.majorVersion > 12) { - return p.getTargetBlockExact(5); - } else if (Main.majorVersion > 7) { - return p.getTargetBlock(null, 5); - } else { - try { - //noinspection JavaReflectionMemberAccess - return (Block) LivingEntity.class.getMethod("getTargetBlock", HashSet.class, int.class).invoke(p, null, 5); - } - catch (Exception e) { - Bukkit.getLogger().severe(e.toString()); - return null; - } - } - } - - @SuppressWarnings("deprecation") - public boolean setGlow(Sign sign, Player p, boolean glow) { - if (Main.majorVersion >= 20) { - SignSide side = sign.getTargetSide(p); + public boolean setGlow(EsSign sign, EsPlayer p, boolean glow) { + if (Main.minecraftVersion.getMinor() >= 20) { + EsSignSide side = sign.getTargetSide(p); if (side.isGlowingText() == glow) { if (glow) { @@ -150,7 +123,7 @@ public boolean setGlow(Sign sign, Player p, boolean glow) { side.setGlowingText(glow); } - else if (Main.majorVersion >= 17) { + else if (Main.minecraftVersion.getMinor() >= 17) { if (sign.isGlowingText() == glow) { if (glow) { send(p, "&cThis sign is already &6glowing!"); diff --git a/src/main/java/net/serble/estools/Commands/Eff.java b/src/main/java/net/serble/estools/Commands/Eff.java index 5fe7935..c0fc81d 100644 --- a/src/main/java/net/serble/estools/Commands/Eff.java +++ b/src/main/java/net/serble/estools/Commands/Eff.java @@ -1,31 +1,27 @@ package net.serble.estools.Commands; -import net.serble.estools.Effects; +import net.serble.estools.ServerApi.EsPotionEffect; +import net.serble.estools.ServerApi.EsPotionEffectType; import net.serble.estools.Main; import net.serble.estools.MultiPlayerCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.ArrayList; import java.util.List; -import java.util.Map; public class Eff extends MultiPlayerCommand { private static final String usage = genUsage("/eff [amplifier] [duration] [players]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (args.length == 0) { send(sender, usage); return false; } - PotionEffectType effect = Effects.getByName(args[0]); - - if (effect == null) { + EsPotionEffectType effectType = EsPotionEffectType.fromKey(args[0]); + if (effectType == null) { send(sender, "&cEffect not found!"); return false; } @@ -54,7 +50,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St durationStr = String.format("%s seconds", duration / 20); if (duration == 32767) { - if (Main.majorVersion >= 19) { + if (Main.minecraftVersion.getMinor() >= 19) { duration = -1; } @@ -62,14 +58,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } } - ArrayList players = new ArrayList<>(); + ArrayList players = new ArrayList<>(); if (args.length < 4) { if (isNotPlayer(sender, usage)) { return false; } - players.add((Player)sender); + players.add((EsPlayer) sender); } else { players = getPlayers(sender, removeArgs(args, 3)); @@ -78,12 +74,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } } - for (Player p : players) { - p.removePotionEffect(effect); - p.addPotionEffect(new PotionEffect(effect, duration, amplifier)); + for (EsPlayer p : players) { + p.removePotionEffect(effectType); + p.addPotionEffect(new EsPotionEffect(effectType, amplifier, duration)); } - send(sender, "&aAdded effect &6%s&a at level &6%s&a for &6%s", Effects.getName(effect), amplifier + 1, durationStr); + send(sender, "&aAdded effect &6%s&a at level &6%s&a for &6%s", effectType.getKey(), amplifier + 1, durationStr); return true; } @@ -106,12 +102,12 @@ private int calculateDuration(String input) { } @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); switch (args.length) { case 1: - for (Map.Entry e : Effects.entrySet()) { + for (EsPotionEffectType e : Main.server.getPotionEffectTypes()) { tab.add(e.getKey().toLowerCase()); } break; diff --git a/src/main/java/net/serble/estools/Commands/Ench.java b/src/main/java/net/serble/estools/Commands/Ench.java index 8af2cc8..b4ddb0c 100644 --- a/src/main/java/net/serble/estools/Commands/Ench.java +++ b/src/main/java/net/serble/estools/Commands/Ench.java @@ -2,17 +2,14 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; +import java.util.Objects; -import net.serble.estools.Enchantments; import net.serble.estools.Main; -import org.bukkit.NamespacedKey; -import org.bukkit.Registry; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; +import net.serble.estools.ServerApi.EsEnchantment; +import net.serble.estools.ServerApi.EsMaterial; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import net.serble.estools.EsToolsCommand; @@ -20,13 +17,17 @@ public class Ench extends EsToolsCommand { private static final String usage = genUsage("/ench [level] [player]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (args.length == 0) { send(sender, usage); return false; } - - ItemStack is; + + EsEnchantment enchantment = EsEnchantment.fromKey(args[0]); + if (enchantment == null) { + send(sender, "&cEnchantment does not exist!"); + return false; + } int level = 1; if (args.length > 1) { @@ -37,66 +38,52 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } } - + + EsItemStack is; if (args.length <= 2) { if (isNotPlayer(sender, usage)) { return false; } - is = getMainHand(((Player) sender)); + is = ((EsPlayer) sender).getMainHand(); + + if (is == null || Objects.equals(is.getType(), EsMaterial.createUnchecked("AIR"))) { + send(sender, "&cYou must be holding an item to enchant it"); + return false; + } } else { - Player p = getPlayer(sender, args[2]); + EsPlayer p = getPlayer(sender, args[2]); if (p == null) { return false; } - is = getMainHand(p); - } - - Enchantment ench; - try { - if (Main.majorVersion > 12) { - ench = Registry.ENCHANTMENT.get(NamespacedKey.minecraft(args[0].toLowerCase())); - } else { - ench = Enchantments.getByName(args[0].toLowerCase()); - } - } catch (IllegalArgumentException e) { - send(sender, usage); - return false; - } - - - if (ench != null && is != null) { - is.addUnsafeEnchantment(ench, level); - send(sender, "&aEnchantment &6%s&a at level &6%s&a was added!", args[0].toLowerCase(), level); - } - else { - send(sender, usage); + is = p.getMainHand(); + + if (is == null || Objects.equals(is.getType(), EsMaterial.createUnchecked("AIR"))) { + send(sender, "&c" + p.getName() + " isn't holding an item"); + return false; + } } + + is.addEnchantment(enchantment, level); + send(sender, "&aEnchantment &6%s&a at level &6%s&a was added!", args[0].toLowerCase(), level); return true; } @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); switch (args.length) { case 1: - if (Main.majorVersion > 12) { - for (Enchantment e : Registry.ENCHANTMENT) { - tab.add(e.getKey().getKey()); - } - } else { - for (Map.Entry e : Enchantments.entrySet()) { - tab.add(e.getKey()); - } + for (EsEnchantment enchantment : Main.server.getEnchantments()) { + tab.add(enchantment.getKey()); } - break; case 3: - for (Player p : getOnlinePlayers()) { + for (EsPlayer p : Main.server.getOnlinePlayers()) { tab.add(p.getName()); } break; diff --git a/src/main/java/net/serble/estools/Commands/EsTools.java b/src/main/java/net/serble/estools/Commands/EsTools.java index 85b7ee9..e6449b8 100644 --- a/src/main/java/net/serble/estools/Commands/EsTools.java +++ b/src/main/java/net/serble/estools/Commands/EsTools.java @@ -1,23 +1,28 @@ package net.serble.estools.Commands; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import net.serble.estools.ServerApi.ServerPlatform; import net.serble.estools.Tester; import net.serble.estools.Updater; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import net.serble.estools.EsToolsCommand; -import net.serble.estools.Commands.Give.Give; import net.serble.estools.Main; public class EsTools extends EsToolsCommand { - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + @SuppressWarnings({"resource", "ResultOfMethodCallIgnored"}) + @Override + public boolean execute(EsCommandSender sender, String[] args) { if (args.length == 0) { if (checkPerms(sender, "version")) { return false; @@ -34,15 +39,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St send(sender, "&aReloading..."); - Give.enable(); - - for (Player p : getOnlinePlayers()) { - CChest.savePlayer(p); - } - - for (Player p : getOnlinePlayers()) { - CChest.loadPlayer(p); - } + Main.plugin.enable(); send(sender, "&aReloaded!"); } else if (args[0].equalsIgnoreCase("reset")) { // Resets all configuration files @@ -51,14 +48,18 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } if (args.length > 1 && args[1].equalsIgnoreCase("confirm")) { - File f = new File(Main.plugin.getDataFolder(), "give.yml"); - if (!f.delete()) { + File f = Main.server.getDataFolder(); + try { + Files.walk(Paths.get(f.getPath())) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } catch (IOException e) { send(sender, "&cFailed to delete data."); return false; } - - Give.enable(); - send(sender, "&cAll data deleted!"); + + send(sender, "&cAll data has been deleted, &6/estools reload &cto apply changes!"); return true; } @@ -68,12 +69,17 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - if (!(sender instanceof Player)) { + if (!(sender instanceof EsPlayer)) { send(sender, "&cYou must be a player to use this command."); return false; } - Player p = (Player) sender; + if (Main.platform == ServerPlatform.Folia) { // TODO: Fix + send(sender, "&cDue to scheduler limitations, /estools test is not currently supported on Folia"); + return false; + } + + EsPlayer p = (EsPlayer) sender; Tester tester = Tester.runningTests.get(p.getUniqueId()); if (tester != null) { @@ -104,7 +110,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - send(sender, "&aDownloading version: &6" + Main.newVersion.getString()); + send(sender, "&aDownloading version: &6" + Main.newVersion); Updater.downloadNewUpdate(sender); } else if (args[0].equalsIgnoreCase("forceupdate")) { send(sender, "&aForce updating &c(This might downgrade your plugin)"); @@ -117,7 +123,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); if (args.length == 1) { @@ -134,12 +140,12 @@ public List tabComplete(CommandSender sender, String[] args, String lArg return tab; } - private void sendVersion(CommandSender sender) { + private void sendVersion(EsCommandSender sender) { if (Main.newVersion == null) { - send(sender, "&aEsTools v" + Main.plugin.getDescription().getVersion()); + send(sender, "&aEsTools v" + Main.server.getPluginVersion().toString()); } else { - send(sender, "&aEsTools &cv" + Main.plugin.getDescription().getVersion() + ".&c An update is available, use " + - "&6/estools update&c to update to &6v" + Main.newVersion.getString()); + send(sender, "&aEsTools &cv" + Main.server.getPluginVersion().toString() + ".&c An update is available, use " + + "&6/estools update&c to update to &6v" + Main.newVersion.toString()); } } diff --git a/src/main/java/net/serble/estools/Commands/Feed.java b/src/main/java/net/serble/estools/Commands/Feed.java index 3a80dcd..55ac241 100644 --- a/src/main/java/net/serble/estools/Commands/Feed.java +++ b/src/main/java/net/serble/estools/Commands/Feed.java @@ -1,9 +1,8 @@ package net.serble.estools.Commands; import net.serble.estools.MultiPlayerCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.ArrayList; @@ -11,15 +10,15 @@ public class Feed extends MultiPlayerCommand { private static final String usage = genUsage("/feed "); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - ArrayList players = new ArrayList<>(); + public boolean execute(EsCommandSender sender, String[] args) { + ArrayList players = new ArrayList<>(); if (args.length == 0) { if (isNotPlayer(sender, usage)) { return false; } - players.add((Player) sender); + players.add((EsPlayer) sender); } else { players = getPlayers(sender, args); @@ -28,7 +27,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } } - for (Player p : players) { + for (EsPlayer p : players) { p.setFoodLevel(20); p.setSaturation(20); } diff --git a/src/main/java/net/serble/estools/Commands/Fix.java b/src/main/java/net/serble/estools/Commands/Fix.java index a55bf81..b272787 100644 --- a/src/main/java/net/serble/estools/Commands/Fix.java +++ b/src/main/java/net/serble/estools/Commands/Fix.java @@ -4,13 +4,7 @@ import java.util.List; import net.serble.estools.Main; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; -import org.bukkit.inventory.meta.Damageable; -import org.bukkit.inventory.meta.ItemMeta; +import net.serble.estools.ServerApi.Interfaces.*; import net.serble.estools.PlayerCommand; @@ -18,15 +12,15 @@ public class Fix extends PlayerCommand { private static final String usage = genUsage("/fix [hand/offhand/helmet/chestplate/leggings/boots/all] [player]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Player p; + public boolean execute(EsCommandSender sender, String[] args) { + EsPlayer p; if (args.length < 2) { if (isNotPlayer(sender, usage)) { return false; } - p = (Player) sender; + p = (EsPlayer) sender; } else { p = getPlayer(sender, args[1]); @@ -35,16 +29,16 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } } - PlayerInventory pInv = p.getInventory(); - ItemStack is = getMainHand(p); + EsPlayerInventory pInv = p.getInventory(); + EsItemStack is = p.getMainHand(); boolean all = false; if (args.length > 0) { switch (args[0].toLowerCase()) { case "offhand": - if (Main.majorVersion > 8) { - is = pInv.getItemInOffHand(); + if (Main.minecraftVersion.getMinor() > 8) { + is = pInv.getOffHand(); } break; @@ -71,8 +65,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } if (all) { - ItemStack[] contents = p.getInventory().getContents(); - for (ItemStack i : contents) { + EsItemStack[] contents = p.getInventory().getContents(); + for (EsItemStack i : contents) { repair(i); } @@ -81,37 +75,27 @@ public boolean onCommand(CommandSender sender, Command command, String label, St repair(is); } - send(sender, "&aRepaired &6%s's &aitem(s)!", getEntityName(p)); + send(sender, "&aRepaired &6%s's &aitem(s)!", p.getName()); return true; } - public static void repair(ItemStack is) { + public static void repair(EsItemStack is) { if (is == null) { return; } - if (Main.majorVersion > 12) { - ItemMeta im = is.getItemMeta(); - if (im == null) return; - - ((Damageable) im).setDamage(0); - - is.setItemMeta(im); - } else { - //noinspection deprecation - is.setDurability((short) 0); - } + is.setDamage(0); } @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); if (args.length == 1) { tab.add("hand"); tab.add("helmet"); tab.add("chestplate"); tab.add("leggings"); tab.add("boots"); tab.add("all"); - if (Main.majorVersion > 8) { + if (Main.minecraftVersion.getMinor() > 8) { tab.add("offhand"); } } else if (args.length == 2) { diff --git a/src/main/java/net/serble/estools/Commands/Fly.java b/src/main/java/net/serble/estools/Commands/Fly.java index 62ca1eb..9306f56 100644 --- a/src/main/java/net/serble/estools/Commands/Fly.java +++ b/src/main/java/net/serble/estools/Commands/Fly.java @@ -1,9 +1,8 @@ package net.serble.estools.Commands; import net.serble.estools.MultiPlayerCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.ArrayList; import java.util.Objects; @@ -12,15 +11,15 @@ public class Fly extends MultiPlayerCommand { private static final String usage = genUsage("/fly [Player]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - ArrayList players = new ArrayList<>(); + public boolean execute(EsCommandSender sender, String[] args) { + ArrayList players = new ArrayList<>(); if (args.length == 0) { if (isNotPlayer(sender, usage)) { return false; } - players.add((Player) sender); + players.add((EsPlayer) sender); } else { players = getPlayers(sender, args[0]); @@ -29,7 +28,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } } - for (Player p : players) { + for (EsPlayer p : players) { boolean isFly = p.getAllowFlight(); if (args.length != 0 && !Objects.equals(args[0], "*")) { diff --git a/src/main/java/net/serble/estools/Commands/GameModeCommand.java b/src/main/java/net/serble/estools/Commands/GameModeCommand.java index a2c591e..fceea8d 100644 --- a/src/main/java/net/serble/estools/Commands/GameModeCommand.java +++ b/src/main/java/net/serble/estools/Commands/GameModeCommand.java @@ -1,33 +1,31 @@ package net.serble.estools.Commands; import net.serble.estools.MultiPlayerCommand; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.EsGameMode; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.ArrayList; public class GameModeCommand extends MultiPlayerCommand { - private GameMode gameMode; + private final EsGameMode gameMode; + private final String cmd; - public GameModeCommand(String gameMode) { - // If it's an old version it will throw when trying to get Enum Value, so we ignore it. - try { - this.gameMode = GameMode.valueOf(gameMode); - } catch (IllegalArgumentException ignored) {} + public GameModeCommand(EsGameMode gameMode, String cmd) { + this.gameMode = gameMode; + this.cmd = cmd; } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - ArrayList ps = new ArrayList<>(); + public boolean execute(EsCommandSender sender, String[] args) { + ArrayList ps = new ArrayList<>(); if (args.length == 0) { - if (isNotPlayer(sender, genUsage("/%s [player]"), label)) { + if (isNotPlayer(sender, genUsage("/%s [player]"), cmd)) { return false; } - ps.add((Player) sender); + ps.add((EsPlayer) sender); send(sender, "&aGamemode set to &6%s", gameMode.toString()); } else { @@ -39,7 +37,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St send(sender, "&aGamemode set to &6%s&a for &6%s", gameMode.toString(), argsToString(args, 0)); } - for (Player p : ps) { + for (EsPlayer p : ps) { p.setGameMode(gameMode); } diff --git a/src/main/java/net/serble/estools/Commands/GetInfo.java b/src/main/java/net/serble/estools/Commands/GetInfo.java index d6116a9..c852b25 100644 --- a/src/main/java/net/serble/estools/Commands/GetInfo.java +++ b/src/main/java/net/serble/estools/Commands/GetInfo.java @@ -1,36 +1,36 @@ package net.serble.estools.Commands; -import net.serble.estools.Effects; +import net.serble.estools.ServerApi.EsPotionEffect; +import net.serble.estools.ServerApi.EsLocation; import net.serble.estools.Main; -import org.bukkit.Location; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; import net.serble.estools.EntityCommand; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffect; +import net.serble.estools.ServerApi.Interfaces.EsEntity; +import net.serble.estools.ServerApi.Interfaces.EsLivingEntity; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; public class GetInfo extends EntityCommand { private static final String usage = genUsage("/getinfo "); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (args.length == 0) { send(sender, usage); return false; } - Entity entity = getNonLivingEntity(sender, args[0]); + EsEntity entity = getNonLivingEntity(sender, args[0]); if (entity == null) { return false; } - Location loc = entity.getLocation(); - String name = getEntityName(entity); + EsLocation loc = entity.getLocation(); + String name = entity.getName(); // Global Values String info = @@ -43,7 +43,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St info = String.format(info, name, - entity.getType().name(), + entity.getType(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), @@ -51,11 +51,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St entity.getUniqueId()); // Passengers - if (Main.majorVersion > 12) { + if (Main.minecraftVersion.getMinor() > 12) { StringBuilder passengerText = new StringBuilder("&aPassengers: &6"); boolean passengersExist = false; - for (Entity passenger : entity.getPassengers()) { - passengerText.append(getEntityName(passenger)).append(" (").append(passenger.getType()).append("), "); + for (EsEntity passenger : entity.getPassengers()) { + passengerText.append(passenger.getName()).append(" (").append(passenger.getType()).append("), "); passengersExist = true; } @@ -68,23 +68,20 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } } - if (entity instanceof LivingEntity) { // Living entity - LivingEntity le = (LivingEntity) entity; - String maxHealth = String.valueOf(Math.round(getMaxHealth(le))); + if (entity instanceof EsLivingEntity) { // Living entity + EsLivingEntity le = (EsLivingEntity) entity; + String maxHealth = String.valueOf(Math.round(le.getMaxHealth())); StringBuilder potionEffects = new StringBuilder(); { - Object[] pos = le.getActivePotionEffects().toArray(); + List potions = le.getActivePotionEffects(); - if (pos.length == 0) { + if (potions.isEmpty()) { potionEffects.append("None"); } else { - for (int i = 0; i < pos.length - 1; i++) { - PotionEffect po = (PotionEffect) pos[i]; - potionEffects.append(Effects.getName(po.getType())).append(", "); - } - - potionEffects.append(Effects.getName(((PotionEffect) pos[pos.length - 1]).getType())); + potionEffects.append(potions.stream() + .map(pot -> String.format("%s at %s for %s seconds", pot.getType(), pot.getAmp()+1, pot.getDuration()/20)) + .collect(Collectors.joining(", "))); } } @@ -93,13 +90,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St "&aMax Health: &6%s\n" + "&aPotion Effects: &6%s\n"; livingEntityInfo = String.format(livingEntityInfo, - getHealth(le), + le.getHealth(), maxHealth, potionEffects); info += livingEntityInfo; - if (Main.majorVersion > 12) { + if (Main.minecraftVersion.getMinor() > 12) { // Scoreboard tags StringBuilder tags = new StringBuilder("&aScoreboard Tags: &6"); boolean tagsExist = false; @@ -118,8 +115,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } } - if (entity instanceof Player) { // Players - Player player = (Player) entity; + if (entity instanceof EsPlayer) { // Players + EsPlayer player = (EsPlayer) entity; String playerInfo = "&aHunger: &6%s\n" + @@ -129,7 +126,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St player.getFoodLevel(), player.getSaturation()); - if (Main.majorVersion > 1) { + if (Main.minecraftVersion.getMinor() > 1) { playerInfo += "&aCan Fly: &6%s\n" + "&aIs Flying: &6%s\n"; diff --git a/src/main/java/net/serble/estools/Commands/GetPersistentData.java b/src/main/java/net/serble/estools/Commands/GetPersistentData.java index d1e356b..97eac1e 100644 --- a/src/main/java/net/serble/estools/Commands/GetPersistentData.java +++ b/src/main/java/net/serble/estools/Commands/GetPersistentData.java @@ -1,17 +1,10 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsPersistentDataType; +import net.serble.estools.ServerApi.Interfaces.*; import net.serble.estools.Tuple; import org.apache.commons.lang.ArrayUtils; -import org.bukkit.NamespacedKey; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; -import org.bukkit.persistence.PersistentDataType; import java.util.ArrayList; import java.util.List; @@ -20,7 +13,7 @@ public class GetPersistentData extends EsToolsCommand { public static final String usage = genUsage("/getpersistentdata "); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) return false; @@ -29,27 +22,27 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - String tagString = args[0].toLowerCase(); + String key = args[0].toLowerCase(); String typeString = args[1].toLowerCase(); - ItemStack item = getMainHand((Player) sender); - NamespacedKey key = getNamespacedKey(tagString); - if (key == null) { - send(sender, "&cInvalid key! examples: 'estools:count', 'backpacks:size', etc"); - return false; - } + EsItemStack item = ((EsPlayer) sender).getMainHand(); +// NamespacedKey key = getNamespacedKey(key); +// if (key == null) { +// send(sender, "&cInvalid key! examples: 'estools:count', 'backpacks:size', etc"); +// return false; +// } - ItemMeta meta = item.getItemMeta(); + EsItemMeta meta = item.getItemMeta(); if (meta == null) { send(sender, "&cItem does not have nbt tags!"); return false; } - PersistentDataContainer data = meta.getPersistentDataContainer(); + EsPersistentDataContainer data = meta.getPersistentDataContainer(); Tuple value = getData(typeString, key, data); if (value.a() == 3) { - send(sender, "&cNBT tag &e\"" + tagString + "\"&c does not exist!"); + send(sender, "&cNBT tag &e\"" + key + "\"&c does not exist!"); return false; } @@ -59,19 +52,19 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } if (value.a() == 2) { - send(sender, "&cNBT tag &e\"" + tagString + "\"&c exists, but is not a " + typeString + "!"); + send(sender, "&cNBT tag &e\"" + key + "\"&c exists, but is not a " + typeString + "!"); return false; } - send(sender, "&aNBT tag &e\"" + tagString + "\"&a is &e" + value.b() + "&a!"); + send(sender, "&aNBT tag &e\"" + key + "\"&a is &e" + value.b() + "&a!"); return true; } - private static Tuple getData(String type, NamespacedKey key, PersistentDataContainer data) { + private static Tuple getData(String type, String key, EsPersistentDataContainer data) { try { switch (type) { case "string": { - String value = data.get(key, PersistentDataType.STRING); + String value = (String) data.get(key, EsPersistentDataType.String); if (value == null) { return new Tuple<>(3, null); } @@ -80,7 +73,7 @@ private static Tuple getData(String type, NamespacedKey key, Pe } case "integer": { - Integer value = data.get(key, PersistentDataType.INTEGER); + Integer value = (Integer) data.get(key, EsPersistentDataType.Integer); if (value == null) { return new Tuple<>(3, null); } @@ -88,7 +81,7 @@ private static Tuple getData(String type, NamespacedKey key, Pe } case "double": { - Double value = data.get(key, PersistentDataType.DOUBLE); + Double value = (Double) data.get(key, EsPersistentDataType.Double); if (value == null) { return new Tuple<>(3, null); } @@ -96,7 +89,7 @@ private static Tuple getData(String type, NamespacedKey key, Pe } case "float": { - Float value = data.get(key, PersistentDataType.FLOAT); + Float value = (Float) data.get(key, EsPersistentDataType.Float); if (value == null) { return new Tuple<>(3, null); } @@ -104,7 +97,7 @@ private static Tuple getData(String type, NamespacedKey key, Pe } case "long": { - Long value = data.get(key, PersistentDataType.LONG); + Long value = (Long) data.get(key, EsPersistentDataType.Long); if (value == null) { return new Tuple<>(3, null); } @@ -112,7 +105,7 @@ private static Tuple getData(String type, NamespacedKey key, Pe } case "short": { - Short value = data.get(key, PersistentDataType.SHORT); + Short value = (Short) data.get(key, EsPersistentDataType.Short); if (value == null) { return new Tuple<>(3, null); } @@ -120,7 +113,7 @@ private static Tuple getData(String type, NamespacedKey key, Pe } case "byte": { - Byte value = data.get(key, PersistentDataType.BYTE); + Byte value = (Byte) data.get(key, EsPersistentDataType.Byte); if (value == null) { return new Tuple<>(3, null); } @@ -128,7 +121,7 @@ private static Tuple getData(String type, NamespacedKey key, Pe } case "byte_array": { - byte[] value = data.get(key, PersistentDataType.BYTE_ARRAY); + byte[] value = (byte[]) data.get(key, EsPersistentDataType.ByteArray); if (value == null) { return new Tuple<>(3, null); } @@ -137,7 +130,7 @@ private static Tuple getData(String type, NamespacedKey key, Pe } case "int_array": { - int[] value = data.get(key, PersistentDataType.INTEGER_ARRAY); + int[] value = (int[]) data.get(key, EsPersistentDataType.IntArray); if (value == null) { return new Tuple<>(3, null); } @@ -146,7 +139,7 @@ private static Tuple getData(String type, NamespacedKey key, Pe } case "long_array": { - long[] value = data.get(key, PersistentDataType.LONG_ARRAY); + long[] value = (long[]) data.get(key, EsPersistentDataType.LongArray); if (value == null) { return new Tuple<>(3, null); } @@ -161,23 +154,6 @@ private static Tuple getData(String type, NamespacedKey key, Pe return new Tuple<>(1, null); } - @SuppressWarnings("UnstableApiUsage") - public static NamespacedKey getNamespacedKey(String keyString) { - if (Main.majorVersion >= 16) { - return NamespacedKey.fromString(keyString, Main.plugin); - } - - String[] parts = keyString.split(":"); - if (parts.length == 2) { - return new NamespacedKey(parts[0], parts[1]); - } else if (parts.length == 1) { // Incorrectly formatted key - String pluginName = Main.getPlugin(Main.class).getName(); - return new NamespacedKey(pluginName, parts[0]); - } - - return null; - } - private static StringBuilder buildString(T[] values) { StringBuilder sb = new StringBuilder("["); for (T value : values) { @@ -190,7 +166,7 @@ private static StringBuilder buildString(T[] values) { } @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); if (args.length == 2) { diff --git a/src/main/java/net/serble/estools/Commands/Give/Give.java b/src/main/java/net/serble/estools/Commands/Give/Give.java index 98ec0f3..f87d807 100644 --- a/src/main/java/net/serble/estools/Commands/Give/Give.java +++ b/src/main/java/net/serble/estools/Commands/Give/Give.java @@ -1,35 +1,31 @@ package net.serble.estools.Commands.Give; import net.serble.estools.*; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.inventory.ItemStack; - -import java.io.*; -import java.nio.file.Files; +import net.serble.estools.Config.ConfigManager; +import net.serble.estools.Config.Schemas.Give.GiveConfig; +import net.serble.estools.ServerApi.EsMaterial; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; + import java.util.*; import java.util.Map.Entry; public class Give implements EsToolsTabCompleter { - private static HashMap materialNames; + private static HashMap materialNames; - public static ItemStack getItem(String name, int amount) { - name = name.toUpperCase(); - Material mat = materialNames.get(name); + public static EsItemStack getItem(String name, int amount) { + name = name.toLowerCase(); + EsMaterial mat = materialNames.get(name); if (mat == null) { return null; } - return new ItemStack(mat, amount); + return Main.server.createItemStack(mat, amount); } @Override - public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + public List onTabComplete(EsCommandSender sender, String[] args) { List tab = new ArrayList<>(); if (args.length == 1) { @@ -44,49 +40,30 @@ public List onTabComplete(CommandSender sender, Command command, String return EsToolsCommand.fixTabComplete(tab, args[args.length - 1]); } - - @SuppressWarnings("DataFlowIssue") // Not possible + public static void enable() { // initialise hashmaps //noinspection Convert2Diamond - materialNames = new HashMap(); + materialNames = new HashMap(); // Load config - FileConfiguration f = ConfigManager.load("give.yml"); + GiveConfig config = ConfigManager.load("give.yml", GiveConfig.class); // check if it has settings - HashMap materials = new HashMap<>(); - - if ( f.contains("settings") && - f.contains("settings.addWithoutUnderscores") && - f.contains("settings.removeWithUnderscores")) { // if it has these values then load files - - materials = loadItems(f); - } - - if (materials.isEmpty()) { // if it hasn't loaded or if it cant load anything - Bukkit.getLogger().info("Creating new give.yml"); - - try { - copyDefaultGiveYML(); - f = ConfigManager.load(new File(Main.plugin.getDataFolder(), "give.yml")); - materials = loadItems(f); - } catch (Exception ignored) { } - } + Map materials = config.getItems(); // Load normal items - boolean addWithoutUnderscores = (boolean) f.get("settings.addWithoutUnderscores"); - boolean removeWithUnderscores = (boolean) f.get("settings.removeWithUnderscores"); - - for (Material mat : Material.values()) { - if (Main.majorVersion >= 12 && !mat.isItem()) continue; - - String name = mat.toString().toUpperCase(); + Set builtinMats = Main.server.getMaterials(true); + for (EsMaterial mat : builtinMats) { + if (mat == null) { + continue; + } - if (name.contains("_") && addWithoutUnderscores) { + String name = mat.getKey().toLowerCase(); + if (name.contains("_") && config.getSettings().isAddWithoutUnderscores()) { materialNames.put(name.replace("_",""), mat); - if (removeWithUnderscores) { + if (config.getSettings().isRemoveWithUnderscores()) { continue; } } @@ -96,53 +73,20 @@ public static void enable() { // Load custom items for (Entry s : materials.entrySet()) { - Material mat = Material.getMaterial(s.getValue().toUpperCase()); + if (s == null) { + continue; + } - if (mat != null) { - materialNames.put(s.getKey().toUpperCase(), mat); + EsMaterial material = EsMaterial.fromKey(s.getValue().toLowerCase()); + if (material == null) { + continue; // Don't trust users, if it doesn't exist then skip } + + materialNames.put(s.getKey().toLowerCase(), material); } } - - private static HashMap loadItems(FileConfiguration f) { - HashMap ms = new HashMap<>(); - - if (f.contains("items")) { - ConfigurationSection itemsSection = f.getConfigurationSection("items"); - assert itemsSection != null; - - itemsSection.getKeys(false).forEach(key -> { - String content = (String) f.get("items." + key); - ms.put(key, content); - }); - } - - return ms; - } - - private static void copyDefaultGiveYML() throws IOException { - // The class loader that loaded the class - ClassLoader classLoader = Give.class.getClassLoader(); - InputStream inputStream = classLoader.getResourceAsStream("give.yml"); - - // the stream holding the file content - if (inputStream == null) { - return; - } - - byte[] buffer = new byte[inputStream.available()]; - //noinspection ResultOfMethodCallIgnored - inputStream.read(buffer); - - File targetFile = new File(Main.plugin.getDataFolder(), "give.yml"); - OutputStream outStream = Files.newOutputStream(targetFile.toPath()); - outStream.write(buffer); - - inputStream.close(); - outStream.close(); - } - - public static ItemStack parseArgs(String[] args) { + + public static EsItemStack parseArgs(String[] args) { if (args.length == 0) { throw new IllegalArgumentException(); } diff --git a/src/main/java/net/serble/estools/Commands/Give/GiveItem.java b/src/main/java/net/serble/estools/Commands/Give/GiveItem.java index 5bbae96..0c61b88 100644 --- a/src/main/java/net/serble/estools/Commands/Give/GiveItem.java +++ b/src/main/java/net/serble/estools/Commands/Give/GiveItem.java @@ -1,22 +1,21 @@ package net.serble.estools.Commands.Give; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; import net.serble.estools.EsToolsCommand; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class GiveItem extends EsToolsCommand { private static final String usage = genUsage("/i [amount]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - ItemStack item; + EsItemStack item; try { item = Give.parseArgs(args); } catch (IllegalArgumentException e) { @@ -24,11 +23,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - Player p = (Player) sender; + EsPlayer p = (EsPlayer) sender; if (item != null) { p.getInventory().addItem(item); - send(sender, "&aGave &6%s", item.getType().name()); + send(sender, "&aGave &6%s", item.getType()); } else { send(sender, "&cItem &6%s&c not found", args[0]); } diff --git a/src/main/java/net/serble/estools/Commands/Give/SetHandItem.java b/src/main/java/net/serble/estools/Commands/Give/SetHandItem.java index 617bc7d..b4b5ab9 100644 --- a/src/main/java/net/serble/estools/Commands/Give/SetHandItem.java +++ b/src/main/java/net/serble/estools/Commands/Give/SetHandItem.java @@ -1,22 +1,21 @@ package net.serble.estools.Commands.Give; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; import net.serble.estools.EsToolsCommand; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class SetHandItem extends EsToolsCommand { private static final String usage = genUsage("/h [amount]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - ItemStack item; + EsItemStack item; try { item = Give.parseArgs(args); } catch (IllegalArgumentException e) { @@ -24,11 +23,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - Player p = (Player) sender; + EsPlayer p = (EsPlayer) sender; if (item != null) { - setMainHand(p, item); - send(sender, "&aGave &6%s", item.getType().name()); + p.setMainHand(item); + send(sender, "&aGave &6%s", item.getType()); } else { send(sender, "&cItem &6%s&c not found", args[0]); } diff --git a/src/main/java/net/serble/estools/Commands/God.java b/src/main/java/net/serble/estools/Commands/God.java index c12950b..42ffa60 100644 --- a/src/main/java/net/serble/estools/Commands/God.java +++ b/src/main/java/net/serble/estools/Commands/God.java @@ -1,36 +1,33 @@ package net.serble.estools.Commands; -import net.serble.estools.ConfigManager; +import net.serble.estools.Config.ConfigManager; import net.serble.estools.EntityCommand; import net.serble.estools.Main; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageEvent; +import net.serble.estools.ServerApi.EsEventListener; +import net.serble.estools.ServerApi.Events.EsEntityDamageEvent; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsEvent; +import net.serble.estools.ServerApi.Interfaces.EsLivingEntity; import java.util.*; -public class God extends EntityCommand implements Listener { +public class God extends EntityCommand implements EsEventListener { private static final HashMap currentPlayers = new HashMap<>(); private static final String usage = genUsage("/god [entity] [time]"); + private static final String configFile = "gods.yml"; + @SuppressWarnings("unchecked") // I'm right, trust me @Override public void onEnable() { - Bukkit.getServer().getPluginManager().registerEvents(this, Main.plugin); + Main.registerEvents(this); - FileConfiguration f = ConfigManager.load("gods.yml"); - List godList = f.getStringList("gods"); - godList.forEach(w -> currentPlayers.put(UUID.fromString(w), -1)); + List f = (List) ConfigManager.load(configFile, ArrayList.class); + f.forEach(w -> currentPlayers.put(UUID.fromString(w), -1)); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - LivingEntity p; + public boolean execute(EsCommandSender sender, String[] args) { + EsLivingEntity p; int timer = -1; if (args.length == 0) { @@ -38,7 +35,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - p = (LivingEntity) sender; + p = (EsLivingEntity) sender; } else { p = getEntity(sender, args[0]); @@ -65,10 +62,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if (taskId == -1) { save(); } else { - Bukkit.getScheduler().cancelTask(taskId); + Main.server.cancelTask(taskId); } - send(sender, "&aGod mode &6disabled&a for &6%s", getEntityName(p)); + send(sender, "&aGod mode &6disabled&a for &6%s", p.getName()); } else { int taskId = -1; @@ -77,7 +74,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if (timer >= 0) { timerStr = timer / 20d + " seconds"; - taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> currentPlayers.remove(uid), timer); + taskId = Main.server.runTaskLater(() -> currentPlayers.remove(uid), timer); } currentPlayers.put(uid, taskId); @@ -85,22 +82,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St save(); } - send(sender, "&aGod mode &6enabled&a for &6%s&a for &6%s", getEntityName(p), timerStr); + send(sender, "&aGod mode &6enabled&a for &6%s&a for &6%s", p.getName(), timerStr); } return true; } - @EventHandler - public void damage(EntityDamageEvent e) { - if (currentPlayers.containsKey(e.getEntity().getUniqueId())) { - e.setCancelled(true); - } - } - private static void save() { - FileConfiguration f = new YamlConfiguration(); - List gods = new ArrayList<>(); for (Map.Entry kv : currentPlayers.entrySet()) { // only save if there isn't a time limit! @@ -109,7 +97,18 @@ private static void save() { } } - f.set("gods", gods); - ConfigManager.save("gods.yml", f); + ConfigManager.save(configFile, gods); + } + + @Override + public void executeEvent(EsEvent event) { + if (!(event instanceof EsEntityDamageEvent)) { + return; + } + EsEntityDamageEvent e = (EsEntityDamageEvent) event; + + if (currentPlayers.containsKey(e.getEntity().getUniqueId())) { + e.setCancelled(true); + } } } diff --git a/src/main/java/net/serble/estools/Commands/Heal.java b/src/main/java/net/serble/estools/Commands/Heal.java index 00af820..9c2f487 100644 --- a/src/main/java/net/serble/estools/Commands/Heal.java +++ b/src/main/java/net/serble/estools/Commands/Heal.java @@ -1,22 +1,21 @@ package net.serble.estools.Commands; import net.serble.estools.EntityCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.LivingEntity; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsLivingEntity; public class Heal extends EntityCommand { private static final String usage = genUsage("/heal [entity]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - LivingEntity entity; + public boolean execute(EsCommandSender sender, String[] args) { + EsLivingEntity entity; if (args.length == 0) { if (isNotEntity(sender, usage)) { return false; } - entity = (LivingEntity) sender; + entity = (EsLivingEntity) sender; send(sender, "&aHealed!"); } else { entity = getEntity(sender, args[0]); @@ -25,11 +24,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - send(sender, "&aHealed &6%s", getEntityName(entity)); + send(sender, "&aHealed &6%s", entity.getName()); } - setHealth(entity, getMaxHealth(entity)); - entity.setFireTicks(0); + entity.setHealth(entity.getMaxHealth()); + entity.setOnFireTicks(0); return true; } diff --git a/src/main/java/net/serble/estools/Commands/HideFlags.java b/src/main/java/net/serble/estools/Commands/HideFlags.java index 09c0c68..6285b7a 100644 --- a/src/main/java/net/serble/estools/Commands/HideFlags.java +++ b/src/main/java/net/serble/estools/Commands/HideFlags.java @@ -1,37 +1,38 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; +import net.serble.estools.ServerApi.EsItemFlag; +import net.serble.estools.ServerApi.EsMaterial; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemMeta; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; + +import java.util.Objects; public class HideFlags extends EsToolsCommand { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - ItemStack is = getMainHand((Player) sender); + EsItemStack is = ((EsPlayer) sender).getMainHand(); - if (is == null || is.getType() == Material.AIR || is.getItemMeta() == null) { + if (is == null || Objects.equals(is.getType(), EsMaterial.createUnchecked("AIR")) || is.getItemMeta() == null) { send(sender, "&cMust be a damageable item"); return false; } - ItemMeta im = is.getItemMeta(); + EsItemMeta im = is.getItemMeta(); String un; if (!im.getItemFlags().isEmpty()) { - im.removeItemFlags(ItemFlag.values()); + im.removeItemFlags(EsItemFlag.values()); un = "&aRemoved Item Flags"; } else { - im.addItemFlags(ItemFlag.values()); + im.addItemFlags(EsItemFlag.values()); un = "&aAdded Item Flags"; } diff --git a/src/main/java/net/serble/estools/Commands/Infinite.java b/src/main/java/net/serble/estools/Commands/Infinite.java index 71ad4c0..220dc30 100644 --- a/src/main/java/net/serble/estools/Commands/Infinite.java +++ b/src/main/java/net/serble/estools/Commands/Infinite.java @@ -2,33 +2,32 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.Main; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.inventory.ItemStack; +import net.serble.estools.ServerApi.EsEquipmentSlot; +import net.serble.estools.ServerApi.EsEventListener; +import net.serble.estools.ServerApi.Events.EsBlockPlaceEvent; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsEvent; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.ArrayList; import java.util.UUID; -public class Infinite extends EsToolsCommand implements Listener { +public class Infinite extends EsToolsCommand implements EsEventListener { private static final ArrayList currentPlayers = new ArrayList<>(); @Override public void onEnable() { - Bukkit.getServer().getPluginManager().registerEvents(this, Main.plugin); + Main.registerEvents(this); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - UUID pu = ((Player)sender).getUniqueId(); + UUID pu = ((EsPlayer) sender).getUniqueId(); if (!currentPlayers.contains(pu)) { currentPlayers.add(pu); @@ -41,19 +40,20 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return true; } - @EventHandler - public void blockPlace(BlockPlaceEvent e) { + @Override + public void executeEvent(EsEvent event) { + if (!(event instanceof EsBlockPlaceEvent)) { + return; + } + EsBlockPlaceEvent e = (EsBlockPlaceEvent) event; + if (!currentPlayers.contains(e.getPlayer().getUniqueId())) { return; } - ItemStack item = e.getItemInHand().clone(); + EsItemStack item = e.getPlacedItem().clone(); + EsEquipmentSlot slot = e.getHand(); - Bukkit.getScheduler().runTask(Main.plugin, () -> { - setMainHand(e.getPlayer(), item); - // A bug exists where the item is not updated in the player's inventory, this is needed for that - //noinspection UnstableApiUsage - e.getPlayer().updateInventory(); - }); + Main.server.runTask(() -> e.getPlayer().getInventory().setItem(slot, item)); } } diff --git a/src/main/java/net/serble/estools/Commands/InvSee.java b/src/main/java/net/serble/estools/Commands/InvSee.java index 000d764..7a43aa4 100644 --- a/src/main/java/net/serble/estools/Commands/InvSee.java +++ b/src/main/java/net/serble/estools/Commands/InvSee.java @@ -1,15 +1,14 @@ package net.serble.estools.Commands; import net.serble.estools.PlayerCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class InvSee extends PlayerCommand { private static final String usage = genUsage("/invsee "); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } @@ -19,13 +18,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - Player target = getPlayer(sender, args[0]); + EsPlayer target = getPlayer(sender, args[0]); if (target == null) { return false; } - ((Player) sender).openInventory(target.getInventory()); + ((EsPlayer) sender).openInventory(target.getInventory()); send(sender, "&aOpened &6%s's &aInventory", target.getName()); return true; } diff --git a/src/main/java/net/serble/estools/Commands/Lore.java b/src/main/java/net/serble/estools/Commands/Lore.java index ae1b157..bc01cb5 100644 --- a/src/main/java/net/serble/estools/Commands/Lore.java +++ b/src/main/java/net/serble/estools/Commands/Lore.java @@ -1,11 +1,10 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import net.serble.estools.MetaHandler; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemMeta; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.ArrayList; import java.util.Arrays; @@ -17,7 +16,7 @@ public class Lore extends EsToolsCommand { "/lore "); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } @@ -27,15 +26,17 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - Player p = (Player)sender; - ItemStack is = getMainHand(p); + EsPlayer p = (EsPlayer)sender; + EsItemStack is = p.getMainHand(); if (is.getItemMeta() == null) { send(sender, "&cThis item cannot have lore!"); return false; } - List lore = MetaHandler.getLore(is); + EsItemMeta meta = is.getItemMeta(); + + List lore = meta.getLore(); switch (args[0].toLowerCase()) { case "add": { @@ -82,11 +83,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - MetaHandler.setLore(is, lore); + meta.setLore(lore); + is.setItemMeta(meta); return true; } - private int getLine(CommandSender sender, String num, int limit) { + private int getLine(EsCommandSender sender, String num, int limit) { try { int line = Integer.parseInt(num) - 1; @@ -108,7 +110,7 @@ private String getLore(String[] args, int start) { } @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); if (args.length == 1) { @@ -117,13 +119,13 @@ public List tabComplete(CommandSender sender, String[] args, String lArg tab.add("insert"); tab.add("remove"); } else if (args.length == 2 && equalsOr(args[0].toLowerCase(), "set", "insert", "remove")) { - if (!(sender instanceof Player)) { + if (!(sender instanceof EsPlayer)) { tab.add("1"); return tab; } - ItemStack is = getMainHand((Player)sender); - List lore = MetaHandler.getLore(is); + EsItemStack is = ((EsPlayer)sender).getMainHand(); + List lore = is.getItemMeta().getLore(); for (int i = 1; i <= lore.size(); i++) { tab.add(String.valueOf(i)); } diff --git a/src/main/java/net/serble/estools/Commands/Midnight.java b/src/main/java/net/serble/estools/Commands/Midnight.java index fcc0c76..c1ce3c3 100644 --- a/src/main/java/net/serble/estools/Commands/Midnight.java +++ b/src/main/java/net/serble/estools/Commands/Midnight.java @@ -1,19 +1,18 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class Midnight extends EsToolsCommand { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - ((Player)sender).getWorld().setTime(18000); + ((EsPlayer)sender).getWorld().setTime(18000); send(sender, "&aSet time to &6midnight"); return true; } diff --git a/src/main/java/net/serble/estools/Commands/Mount.java b/src/main/java/net/serble/estools/Commands/Mount.java index 3cc82af..fd7a1fc 100644 --- a/src/main/java/net/serble/estools/Commands/Mount.java +++ b/src/main/java/net/serble/estools/Commands/Mount.java @@ -1,10 +1,8 @@ package net.serble.estools.Commands; import net.serble.estools.EntityCommand; -import net.serble.estools.Main; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsEntity; import java.util.ArrayList; import java.util.List; @@ -13,38 +11,42 @@ public class Mount extends EntityCommand { private static final String usage = genUsage("/mount [rider1] [rider2]..."); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (args.length == 0) { send(sender, usage); return false; } - Entity target = getNonLivingEntity(sender, args[0]); + EsEntity target = getNonLivingEntity(sender, args[0]); if (target == null) { return false; } - List riders = new ArrayList<>(); + List riders = new ArrayList<>(); for (int i = 1; i < args.length; i++) { - riders.add(getNonLivingEntity(sender, args[i])); + EsEntity rider = getNonLivingEntity(sender, args[i]); + if (rider == null) { + return false; + } + riders.add(rider); } if (riders.isEmpty()) { - if (!(sender instanceof Entity)) { + if (!(sender instanceof EsEntity)) { send(sender, "&cConsole must specify a rider"); return false; } - riders.add((Entity) sender); + riders.add((EsEntity) sender); } - for (Entity entity : riders) { - if (Main.majorVersion > 11) { - target.addPassenger(entity); - } else { - //noinspection deprecation - target.setPassenger(entity); + for (EsEntity entity : riders) { + if (entity.getUniqueId() == target.getUniqueId()) { + send(sender, "&cSorry, but you cant ride yourself! (the world ends)"); + return false; } + + target.addPassenger(entity); target = entity; } diff --git a/src/main/java/net/serble/estools/Commands/MoveSpeed/FlySpeed.java b/src/main/java/net/serble/estools/Commands/MoveSpeed/FlySpeed.java index ac4c109..98379c7 100644 --- a/src/main/java/net/serble/estools/Commands/MoveSpeed/FlySpeed.java +++ b/src/main/java/net/serble/estools/Commands/MoveSpeed/FlySpeed.java @@ -1,9 +1,8 @@ package net.serble.estools.Commands.MoveSpeed; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import net.serble.estools.Tuple; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import java.util.List; @@ -16,14 +15,14 @@ public String getUsage() { } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Tuple, Float> result = getTargets(sender, args); + public boolean execute(EsCommandSender sender, String[] args) { + Tuple, Float> result = getTargets(sender, args); if (result == null) { return false; } - for (Player p : result.a()) { + for (EsPlayer p : result.a()) { p.setFlySpeed(result.b()); } diff --git a/src/main/java/net/serble/estools/Commands/MoveSpeed/MoveSpeed.java b/src/main/java/net/serble/estools/Commands/MoveSpeed/MoveSpeed.java index f1080a4..209dea2 100644 --- a/src/main/java/net/serble/estools/Commands/MoveSpeed/MoveSpeed.java +++ b/src/main/java/net/serble/estools/Commands/MoveSpeed/MoveSpeed.java @@ -1,9 +1,9 @@ package net.serble.estools.Commands.MoveSpeed; import net.serble.estools.MultiPlayerCommand; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import net.serble.estools.Tuple; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; @@ -11,20 +11,20 @@ public abstract class MoveSpeed extends MultiPlayerCommand { protected abstract String getUsage(); - public Tuple, Float> getTargets(CommandSender sender, String[] args) { + public Tuple, Float> getTargets(EsCommandSender sender, String[] args) { if (args.length == 0) { send(sender, getUsage()); return null; } - ArrayList players = new ArrayList<>(); + ArrayList players = new ArrayList<>(); if (args.length == 1) { if (isNotPlayer(sender, getUsage())) { return null; } - players.add((Player)sender); + players.add((EsPlayer)sender); } else { players = getPlayers(sender, removeArgs(args, 1)); @@ -51,7 +51,7 @@ public Tuple, Float> getTargets(CommandSender sender, String[] args } @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); if (args.length == 1) { diff --git a/src/main/java/net/serble/estools/Commands/MoveSpeed/WalkSpeed.java b/src/main/java/net/serble/estools/Commands/MoveSpeed/WalkSpeed.java index e012537..479e01d 100644 --- a/src/main/java/net/serble/estools/Commands/MoveSpeed/WalkSpeed.java +++ b/src/main/java/net/serble/estools/Commands/MoveSpeed/WalkSpeed.java @@ -1,9 +1,8 @@ package net.serble.estools.Commands.MoveSpeed; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import net.serble.estools.Tuple; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import java.util.List; @@ -16,14 +15,14 @@ protected String getUsage() { } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Tuple, Float> result = getTargets(sender, args); + public boolean execute(EsCommandSender sender, String[] args) { + Tuple, Float> result = getTargets(sender, args); if (result == null) { return false; } - for (Player p : result.a()) { + for (EsPlayer p : result.a()) { p.setWalkSpeed(result.b()); } diff --git a/src/main/java/net/serble/estools/Commands/Music.java b/src/main/java/net/serble/estools/Commands/Music.java index ed9f72d..6264788 100644 --- a/src/main/java/net/serble/estools/Commands/Music.java +++ b/src/main/java/net/serble/estools/Commands/Music.java @@ -2,92 +2,70 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.Main; -import org.bukkit.*; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.EsSound; +import net.serble.estools.ServerApi.EsSoundCategory; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.ArrayList; import java.util.List; import java.util.Random; public class Music extends EsToolsCommand { - private static final String usage = genUsage("/music [song]"); - private static final List musics = new ArrayList<>(); + private static final List randomDiscs = new ArrayList<>(); // discs that can be picked randomly private static final List tabComplete = new ArrayList<>(); private static final Random random = new Random(); @Override public void onEnable() { - if (Main.majorVersion > 12) { - for (Sound s : Sound.values()) { - if (s.name().startsWith("MUSIC_DISC")) { - musics.add(s); - tabComplete.add(s.name().toLowerCase().substring(11)); - } - } - - musics.remove(Sound.MUSIC_DISC_13); - musics.remove(Sound.MUSIC_DISC_11); - } else { - for (Sound s : Sound.values()) { - String name = s.name(); - if (name.startsWith("RECORD")) { - tabComplete.add(s.name().toLowerCase().substring(7)); - - if (!name.equals("RECORD_11") && !name.equals("RECORD_13")) { - musics.add(s); - } - } + for (EsSound s : Main.server.getSounds()) { + if (s.getKey().startsWith("music_disc")) { + randomDiscs.add(s); + tabComplete.add(s.getKey().substring(11)); } } + randomDiscs.remove(EsSound.createUnchecked("music_disc.13")); + randomDiscs.remove(EsSound.createUnchecked("music_disc.11")); + randomDiscs.remove(EsSound.createUnchecked("music_disc.5")); + tabComplete.add("random"); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - - Player p = (Player) sender; - Sound sound; + EsPlayer p = (EsPlayer) sender; + + EsSound sound; if (args.length > 0 && !args[0].equalsIgnoreCase("random")) { - try { - if (Main.majorVersion > 12) { - sound = Sound.valueOf("MUSIC_DISC_" + args[0].toUpperCase()); - } - else { - sound = Sound.valueOf("RECORD_" + args[0].toUpperCase()); - } - } catch (IllegalArgumentException e) { - send(sender, usage); + sound = EsSound.fromKey("music_disc." + args[0]); + + if (sound == null) { + send(sender, "&cThat music disc does not exist!"); return false; } } else { - sound = musics.get(random.nextInt(musics.size())); + sound = randomDiscs.get(random.nextInt(randomDiscs.size())); } - if (Main.majorVersion >= 11) { - p.playSound(p.getLocation().add(0, 1000, 0), sound, SoundCategory.RECORDS, 100000, 1); - } - else { - p.playSound(p.getLocation().add(0, 1000, 0), sound, 100000, 1); - } + // play very high up and with large volume so that the sound doesn't pan + // volume doesn't make the sound louder, it just increases its range. + p.playSound(sound, EsSoundCategory.Records, p.getLocation().add(0, 1000, 0), 100000, 1); - // Substring away the MUSIC_DISK_ or the RECORD_ depending on the version - // then reformat to be all lowercase except for the first character - String name = sound.name().toLowerCase().substring(Main.majorVersion > 12 ? 11 : 7); + // Substring away the music_disc, then reformat to capitalise the first letter + String name = sound.getKey().toLowerCase().substring(11); name = String.valueOf(name.charAt(0)).toUpperCase() + name.substring(1); - + send(sender, "&aNow Playing: &6%s", name); return true; } @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { if (args.length == 1) { return new ArrayList<>(tabComplete); } diff --git a/src/main/java/net/serble/estools/Commands/Night.java b/src/main/java/net/serble/estools/Commands/Night.java index 3d4233e..4089b4d 100644 --- a/src/main/java/net/serble/estools/Commands/Night.java +++ b/src/main/java/net/serble/estools/Commands/Night.java @@ -1,19 +1,18 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class Night extends EsToolsCommand { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - ((Player)sender).getWorld().setTime(13000); + ((EsPlayer)sender).getWorld().setTime(13000); send(sender, "&aSet time to &6night"); return true; } diff --git a/src/main/java/net/serble/estools/Commands/Noon.java b/src/main/java/net/serble/estools/Commands/Noon.java index d177ad2..fb115aa 100644 --- a/src/main/java/net/serble/estools/Commands/Noon.java +++ b/src/main/java/net/serble/estools/Commands/Noon.java @@ -1,19 +1,18 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class Noon extends EsToolsCommand { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - ((Player)sender).getWorld().setTime(6000); + ((EsPlayer)sender).getWorld().setTime(6000); send(sender, "&aSet time to &6noon"); return true; } diff --git a/src/main/java/net/serble/estools/Commands/Potion.java b/src/main/java/net/serble/estools/Commands/Potion.java index 154abd0..2b8e5c0 100644 --- a/src/main/java/net/serble/estools/Commands/Potion.java +++ b/src/main/java/net/serble/estools/Commands/Potion.java @@ -1,70 +1,84 @@ package net.serble.estools.Commands; -import net.serble.estools.Effects; +import net.serble.estools.ServerApi.EsPotionEffect; +import net.serble.estools.ServerApi.EsPotionEffectType; import net.serble.estools.EntityCommand; import net.serble.estools.Main; -import net.serble.estools.MetaHandler; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.potion.PotionType; +import net.serble.estools.ServerApi.EsPotType; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.ArrayList; import java.util.List; -import java.util.Map; public class Potion extends EntityCommand { private static final String usage = genUsage("/potion [amplifier] [duration] [amount] [drink/splash/lingering] [player]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (args.length == 0) { send(sender, usage); return false; } + EsPotionEffectType type = EsPotionEffectType.fromKey(args[0]); + if (type == null) { + send(sender, "Potion type does not exist!"); + return false; + } + int amount = 1; if (args.length >= 4) { amount = tryParseInt(args[3], 1); } - int amp = 1; + int amp = 0; if (args.length >= 2) { - amp = tryParseInt(args[1], 1); + // amp 0 is level 1, so subtract 1 from player input + amp = tryParseInt(args[1], 1) - 1; + + if (Main.minecraftVersion.getMinor() <= 7 && amp < 0 || amp > 1) { + send(sender, "&cAmplifier must be 1 or 2!"); + return false; + } } int duration = 60*20*5; if (args.length >= 3) { - duration = tryParseInt(args[2], 60*5)*20; + duration = (int) (tryParseDouble(args[2], 60d*5d)*20d); } - PotType potType = PotType.drink; + EsPotType potType = EsPotType.drink; if (args.length >= 5) { try { - potType = PotType.valueOf(args[4].toLowerCase()); + potType = EsPotType.valueOf(args[4].toLowerCase()); } catch (IllegalArgumentException ignored) { - send(sender, "&cInvalid potion type, must be drink, splash, or lingering (if on 1.9+)"); + if (Main.minecraftVersion.getMinor() >= 9) { + send(sender, "&cInvalid potion type, must be drink, splash, or lingering"); + } else { + send(sender, "&cInvalid potion type, must be drink or splash"); + } + return false; } // Check versions - if (Main.majorVersion < 9 && potType == PotType.lingering) { + if (Main.minecraftVersion.getMinor() < 9 && potType == EsPotType.lingering) { // Doesn't exist send(sender, "&cLingering potions don't exist in this version"); return false; } } - Player player; + EsPlayer player; if (args.length >= 6) { player = getPlayer(sender, args[5]); if (player == null) return false; } else { - if (sender instanceof Player) { + if (sender instanceof EsPlayer) { // Give to them - player = (Player) sender; + player = (EsPlayer) sender; } else { // They are console send(sender, "&cConsole must specify a player"); @@ -72,13 +86,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } } - if (Main.majorVersion <= 3) { - send(sender, "&cPotions are not yet supported in this version, they may be in the future."); - return false; - } - - ItemStack pot = MetaHandler.getPotion(sender, potType, args[0], duration, amp, amount); + EsItemStack pot = Main.server.createPotion(potType, new EsPotionEffect(type, amp, duration), amount); if (pot == null) { + send(sender, "&cInvalid potion effect!"); return false; } @@ -92,26 +102,20 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return true; } - public enum PotType { - drink, - splash, - lingering - } - @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); // /potion [amplifier] [duration] [amount] [drink/splash/lingering] [player] switch (args.length) { case 1: - if (Main.majorVersion <= 8) { - for (Map.Entry e : Effects.potionEntrySet()) { + if (Main.minecraftVersion.getMinor() <= 8) { + for (EsPotionEffectType e : Main.server.getOldPotionTypes()) { tab.add(e.getKey().toLowerCase()); } } else { - for (Map.Entry e : Effects.entrySet()) { + for (EsPotionEffectType e : Main.server.getPotionEffectTypes()) { tab.add(e.getKey().toLowerCase()); } } @@ -129,7 +133,7 @@ public List tabComplete(CommandSender sender, String[] args, String lArg case 5: tab.add("drink"); tab.add("splash"); - if (Main.majorVersion >= 9) tab.add("lingering"); + if (Main.minecraftVersion.getMinor() >= 9) tab.add("lingering"); break; case 6: diff --git a/src/main/java/net/serble/estools/Commands/PowerPick/PowerAxe.java b/src/main/java/net/serble/estools/Commands/PowerPick/PowerAxe.java index 54c7749..36bdda2 100644 --- a/src/main/java/net/serble/estools/Commands/PowerPick/PowerAxe.java +++ b/src/main/java/net/serble/estools/Commands/PowerPick/PowerAxe.java @@ -2,28 +2,27 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.Main; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; +import net.serble.estools.ServerApi.EsEnchantment; +import net.serble.estools.ServerApi.EsMaterial; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; public class PowerAxe extends EsToolsCommand { - private static ItemStack powerItem; + private static EsItemStack powerItem; public static void init() { - if (Main.majorVersion > 15) { - powerItem = new ItemStack(Material.NETHERITE_AXE); + if (Main.minecraftVersion.getMinor() > 15) { + powerItem = Main.server.createItemStack(EsMaterial.fromKey("NETHERITE_AXE"), 1); } else { - powerItem = new ItemStack(Material.DIAMOND_AXE, 1); + powerItem = Main.server.createItemStack(EsMaterial.fromKey("DIAMOND_AXE"), 1); } - PowerTool.setupItem(powerItem, Enchantment.DIG_SPEED); + PowerTool.setupItem(powerItem, EsEnchantment.createUnchecked("efficiency")); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { PowerTool.cmd(sender, powerItem); return true; } diff --git a/src/main/java/net/serble/estools/Commands/PowerPick/PowerHoe.java b/src/main/java/net/serble/estools/Commands/PowerPick/PowerHoe.java index c194248..1038a13 100644 --- a/src/main/java/net/serble/estools/Commands/PowerPick/PowerHoe.java +++ b/src/main/java/net/serble/estools/Commands/PowerPick/PowerHoe.java @@ -2,28 +2,27 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.Main; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; +import net.serble.estools.ServerApi.EsEnchantment; +import net.serble.estools.ServerApi.EsMaterial; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; public class PowerHoe extends EsToolsCommand { - private static ItemStack powerItem; + private static EsItemStack powerItem; public static void init() { - if (Main.majorVersion > 15) { - powerItem = new ItemStack(Material.NETHERITE_HOE); + if (Main.minecraftVersion.getMinor() > 15) { + powerItem = Main.server.createItemStack(EsMaterial.fromKey("NETHERITE_HOE"), 1); } else { - powerItem = new ItemStack(Material.DIAMOND_HOE, 1); + powerItem = Main.server.createItemStack(EsMaterial.fromKey("DIAMOND_HOE"), 1); } - PowerTool.setupItem(powerItem, Enchantment.DIG_SPEED); + PowerTool.setupItem(powerItem, EsEnchantment.createUnchecked("efficiency")); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { PowerTool.cmd(sender, powerItem); return true; } diff --git a/src/main/java/net/serble/estools/Commands/PowerPick/PowerPick.java b/src/main/java/net/serble/estools/Commands/PowerPick/PowerPick.java index c9e59fb..dd85779 100644 --- a/src/main/java/net/serble/estools/Commands/PowerPick/PowerPick.java +++ b/src/main/java/net/serble/estools/Commands/PowerPick/PowerPick.java @@ -2,28 +2,27 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.Main; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; +import net.serble.estools.ServerApi.EsEnchantment; +import net.serble.estools.ServerApi.EsMaterial; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; public class PowerPick extends EsToolsCommand { - private static ItemStack powerItem; + private static EsItemStack powerItem; public static void init() { - if (Main.majorVersion > 15) { - powerItem = new ItemStack(Material.NETHERITE_PICKAXE); + if (Main.minecraftVersion.getMinor() > 15) { + powerItem = Main.server.createItemStack(EsMaterial.fromKey("NETHERITE_PICKAXE"), 1); } else { - powerItem = new ItemStack(Material.DIAMOND_PICKAXE, 1); + powerItem = Main.server.createItemStack(EsMaterial.fromKey("DIAMOND_PICKAXE"), 1); } - PowerTool.setupItem(powerItem, Enchantment.DIG_SPEED); + PowerTool.setupItem(powerItem, EsEnchantment.createUnchecked("efficiency")); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { PowerTool.cmd(sender, powerItem); return true; } diff --git a/src/main/java/net/serble/estools/Commands/PowerPick/PowerShovel.java b/src/main/java/net/serble/estools/Commands/PowerPick/PowerShovel.java index 9f20a2e..ef908be 100644 --- a/src/main/java/net/serble/estools/Commands/PowerPick/PowerShovel.java +++ b/src/main/java/net/serble/estools/Commands/PowerPick/PowerShovel.java @@ -2,31 +2,28 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.Main; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; - -import java.util.Objects; +import net.serble.estools.ServerApi.EsEnchantment; +import net.serble.estools.ServerApi.EsMaterial; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; public class PowerShovel extends EsToolsCommand { - private static ItemStack powerItem; + private static EsItemStack powerItem; public static void init() { - if (Main.majorVersion > 15) { - powerItem = new ItemStack(Material.NETHERITE_SHOVEL); - } else if (Main.majorVersion > 12) { - powerItem = new ItemStack(Material.DIAMOND_SHOVEL); + if (Main.minecraftVersion.getMinor() > 15) { + powerItem = Main.server.createItemStack(EsMaterial.fromKey("NETHERITE_SHOVEL"), 1); + } else if (Main.minecraftVersion.getMinor() > 12) { + powerItem = Main.server.createItemStack(EsMaterial.fromKey("DIAMOND_SHOVEL"), 1); } else { - powerItem = new ItemStack(Objects.requireNonNull(Material.getMaterial("DIAMOND_SPADE")), 1); + powerItem = Main.server.createItemStack(EsMaterial.fromKey("DIAMOND_SPADE"), 1); } - PowerTool.setupItem(powerItem, Enchantment.DIG_SPEED); + PowerTool.setupItem(powerItem, EsEnchantment.createUnchecked("efficiency")); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { PowerTool.cmd(sender, powerItem); return true; } diff --git a/src/main/java/net/serble/estools/Commands/PowerPick/PowerSword.java b/src/main/java/net/serble/estools/Commands/PowerPick/PowerSword.java index a4cba1a..b0c5982 100644 --- a/src/main/java/net/serble/estools/Commands/PowerPick/PowerSword.java +++ b/src/main/java/net/serble/estools/Commands/PowerPick/PowerSword.java @@ -2,29 +2,26 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.Main; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; - -import java.util.Objects; +import net.serble.estools.ServerApi.EsEnchantment; +import net.serble.estools.ServerApi.EsMaterial; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; public class PowerSword extends EsToolsCommand { - private static ItemStack powerPick; + private static EsItemStack powerPick; public static void init() { - if (Main.majorVersion > 12) { - powerPick = new ItemStack(Material.SALMON); + if (Main.minecraftVersion.getMinor() > 12) { + powerPick = Main.server.createItemStack(EsMaterial.fromKey("SALMON"), 1); } else { - powerPick = new ItemStack(Objects.requireNonNull(Material.getMaterial("RAW_FISH")), 1); + powerPick = Main.server.createItemStack(EsMaterial.fromKey("RAW_FISH"), 1); } - PowerTool.setupItem(powerPick, Enchantment.DAMAGE_ALL); + PowerTool.setupItem(powerPick, EsEnchantment.createUnchecked("sharpness")); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { PowerTool.cmd(sender, powerPick); return true; } diff --git a/src/main/java/net/serble/estools/Commands/PowerPick/PowerTool.java b/src/main/java/net/serble/estools/Commands/PowerPick/PowerTool.java index c35b416..b49f7d2 100644 --- a/src/main/java/net/serble/estools/Commands/PowerPick/PowerTool.java +++ b/src/main/java/net/serble/estools/Commands/PowerPick/PowerTool.java @@ -2,11 +2,11 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.Main; -import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; +import net.serble.estools.ServerApi.EsEnchantment; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemMeta; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class PowerTool { public static void init() { @@ -17,25 +17,24 @@ public static void init() { PowerSword.init(); } - public static void setupItem(ItemStack item, Enchantment enchantment) { - item.addUnsafeEnchantment(enchantment, 32767); + public static void setupItem(EsItemStack item, EsEnchantment enchantment) { + item.addEnchantment(enchantment, 32767); - if (Main.majorVersion > 10) { - ItemMeta im = item.getItemMeta(); - assert im != null; + if (Main.minecraftVersion.getMinor() > 10) { + EsItemMeta im = item.getItemMeta(); im.setUnbreakable(true); item.setItemMeta(im); } else { - item.addUnsafeEnchantment(Enchantment.DURABILITY, 32767); + item.addEnchantment(EsEnchantment.createUnchecked("unbreaking"), 32767); } } - public static void cmd(CommandSender sender, ItemStack pp) { + public static void cmd(EsCommandSender sender, EsItemStack pp) { if (EsToolsCommand.isNotPlayer(sender)) { return; } - Player p = (Player)sender; + EsPlayer p = (EsPlayer) sender; p.getInventory().addItem(pp); EsToolsCommand.send(sender, "&aThere you go!"); diff --git a/src/main/java/net/serble/estools/Commands/Rain.java b/src/main/java/net/serble/estools/Commands/Rain.java index f67b839..5453b1e 100644 --- a/src/main/java/net/serble/estools/Commands/Rain.java +++ b/src/main/java/net/serble/estools/Commands/Rain.java @@ -1,21 +1,20 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import net.serble.estools.ServerApi.Interfaces.EsWorld; public class Rain extends EsToolsCommand { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - World world = ((Player) sender).getWorld(); - world.setStorm(true); + EsWorld world = ((EsPlayer) sender).getWorld(); + world.setStorming(true); world.setThundering(false); send(sender, "&aSet weather to &6rain"); diff --git a/src/main/java/net/serble/estools/Commands/RemovePersistentData.java b/src/main/java/net/serble/estools/Commands/RemovePersistentData.java index f694ff4..25cf4f5 100644 --- a/src/main/java/net/serble/estools/Commands/RemovePersistentData.java +++ b/src/main/java/net/serble/estools/Commands/RemovePersistentData.java @@ -1,18 +1,16 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import org.bukkit.NamespacedKey; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemMeta; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class RemovePersistentData extends EsToolsCommand { public static final String usage = genUsage("/removepersistentdata "); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) return false; @@ -21,16 +19,16 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return true; } - String tagString = args[0].toLowerCase(); + String key = args[0].toLowerCase(); - ItemStack item = getMainHand((Player) sender); - NamespacedKey key = GetPersistentData.getNamespacedKey(tagString); - if (key == null) { - send(sender, "&cInvalid key! examples: 'estools:count', 'backpacks:size', etc"); - return false; - } + EsItemStack item = ((EsPlayer) sender).getMainHand(); +// NamespacedKey key = GetPersistentData.getNamespacedKey(tagString); +// if (key == null) { +// send(sender, "&cInvalid key! examples: 'estools:count', 'backpacks:size', etc"); +// return false; +// } - ItemMeta meta = item.getItemMeta(); + EsItemMeta meta = item.getItemMeta(); if (meta == null) { send(sender, "&cItem does not have nbt tags!"); return false; @@ -39,7 +37,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St meta.getPersistentDataContainer().remove(key); item.setItemMeta(meta); - send(sender, "&aRemove NBT tag &e\"" + tagString + "\"&a!"); + send(sender, "&aRemove NBT tag &e\"" + key + "\"&a!"); return true; } } diff --git a/src/main/java/net/serble/estools/Commands/Rename.java b/src/main/java/net/serble/estools/Commands/Rename.java index 26da7aa..22d2366 100644 --- a/src/main/java/net/serble/estools/Commands/Rename.java +++ b/src/main/java/net/serble/estools/Commands/Rename.java @@ -1,33 +1,40 @@ package net.serble.estools.Commands; -import net.serble.estools.MetaHandler; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - import net.serble.estools.EsToolsCommand; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemMeta; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class Rename extends EsToolsCommand { public static final String usage = genUsage("/rename [name]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - Player p = (Player)sender; - ItemStack is = getMainHand(p); + EsPlayer p = (EsPlayer) sender; + EsItemStack is = p.getMainHand(); + + EsItemMeta meta = is.getItemMeta(); + + if (meta == null) { + send(sender, "&cYou must be holding an item"); + return false; + } if (args.length == 0) { - MetaHandler.renameItem(is, ""); + meta.setDisplayName(""); + is.setItemMeta(meta); send(sender, "&aRemoved item name"); return false; } String name = translate("&r" + String.join(" ", args)); - MetaHandler.renameItem(is, name); + meta.setDisplayName(name); + is.setItemMeta(meta); send(sender, "&aItem renamed to &6%s", name); return true; } diff --git a/src/main/java/net/serble/estools/Commands/SafeTp.java b/src/main/java/net/serble/estools/Commands/SafeTp.java index f03ec1f..20f305d 100644 --- a/src/main/java/net/serble/estools/Commands/SafeTp.java +++ b/src/main/java/net/serble/estools/Commands/SafeTp.java @@ -2,24 +2,29 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.Main; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerTeleportEvent; - -public class SafeTp extends EsToolsCommand implements Listener { +import net.serble.estools.ServerApi.EsEventListener; +import net.serble.estools.ServerApi.EsTeleportCause; +import net.serble.estools.ServerApi.Events.EsPlayerTeleportEvent; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsEvent; +import net.serble.estools.ServerApi.ServerPlatform; + +public class SafeTp extends EsToolsCommand implements EsEventListener { public static boolean enabled = true; @Override public void onEnable() { - enabled = Main.plugin.getConfig().getBoolean("safetp", true); - Bukkit.getServer().getPluginManager().registerEvents(this, Main.plugin); + enabled = Main.plugin.getConfig().isSafeTp(); + Main.registerEvents(this); } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { + if (Main.platform == ServerPlatform.Folia) { + send(sender, "&cCurrently due to Folia issues SafeTP is not supported"); + return false; + } + if (enabled) { enabled = false; send(sender, "&aTeleporting now &6&lWILL&a make you take fall damage!"); @@ -28,15 +33,19 @@ public boolean onCommand(CommandSender sender, Command command, String label, St send(sender, "&aTeleporting now &6&lWILL NOT&a make you take fall damage!"); } - Main.plugin.getConfig().set("safetp", enabled); + Main.plugin.getConfig().setSafeTp(enabled); Main.plugin.saveConfig(); return true; } - @EventHandler - public void teleport(final PlayerTeleportEvent e) { - if (enabled && equalsOr(e.getCause(), PlayerTeleportEvent.TeleportCause.COMMAND, - PlayerTeleportEvent.TeleportCause.PLUGIN, PlayerTeleportEvent.TeleportCause.UNKNOWN)) { + @Override + public void executeEvent(EsEvent event) { + if (!(event instanceof EsPlayerTeleportEvent)) { + return; + } + EsPlayerTeleportEvent e = (EsPlayerTeleportEvent) event; + + if (enabled && equalsOr(e.getCause(), EsTeleportCause.Command, EsTeleportCause.Plugin, EsTeleportCause.Unknown)) { e.getPlayer().setFallDistance(0); } } diff --git a/src/main/java/net/serble/estools/Commands/SetHealth.java b/src/main/java/net/serble/estools/Commands/SetHealth.java index 61f1f59..ea4c885 100644 --- a/src/main/java/net/serble/estools/Commands/SetHealth.java +++ b/src/main/java/net/serble/estools/Commands/SetHealth.java @@ -1,20 +1,19 @@ package net.serble.estools.Commands; import net.serble.estools.EntityCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.LivingEntity; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsLivingEntity; public class SetHealth extends EntityCommand { private static final String usage = genUsage("/sethealth [entity]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (args.length == 0) { send(sender, usage); } - LivingEntity entity; + EsLivingEntity entity; if (args.length > 1) { entity = getEntity(sender, args[1]); @@ -26,7 +25,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - entity = (LivingEntity) sender; + entity = (EsLivingEntity) sender; } double health; @@ -42,15 +41,15 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - double maxhealth = getMaxHealth(entity); + double maxhealth = entity.getMaxHealth(); if (maxhealth < health) { health = maxhealth; } - setHealth(entity, health); + entity.setHealth(health); if (args.length > 1) { - send(sender, "&aSet health for &6%s&a to &6%s", getEntityName(entity), String.valueOf(health)); + send(sender, "&aSet health for &6%s&a to &6%s", entity.getName(), String.valueOf(health)); } else { send(sender, "&aSet health to &6%s", String.valueOf(health)); } diff --git a/src/main/java/net/serble/estools/Commands/SetHunger.java b/src/main/java/net/serble/estools/Commands/SetHunger.java index d358956..28da151 100644 --- a/src/main/java/net/serble/estools/Commands/SetHunger.java +++ b/src/main/java/net/serble/estools/Commands/SetHunger.java @@ -2,21 +2,20 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.PlayerCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class SetHunger extends PlayerCommand { private static final String usage = genUsage("/sethunger [player]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (args.length == 0) { send(sender, usage); return false; } - Player p; + EsPlayer p; int hunger; if (args.length > 1) { @@ -30,7 +29,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - p = (Player)sender; + p = (EsPlayer)sender; } try { diff --git a/src/main/java/net/serble/estools/Commands/SetMaxHealth.java b/src/main/java/net/serble/estools/Commands/SetMaxHealth.java index 9a740e4..aea70d3 100644 --- a/src/main/java/net/serble/estools/Commands/SetMaxHealth.java +++ b/src/main/java/net/serble/estools/Commands/SetMaxHealth.java @@ -1,15 +1,14 @@ package net.serble.estools.Commands; import net.serble.estools.EntityCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.LivingEntity; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsLivingEntity; public class SetMaxHealth extends EntityCommand { private static final String usage = genUsage("/setmaxhealth [entity]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (args.length == 0) { send(sender, usage); } @@ -22,7 +21,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - LivingEntity entity; + EsLivingEntity entity; if (args.length > 1) { entity = getEntity(sender, args[1]); @@ -30,18 +29,18 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - send(sender, "&aSet max health for &6%s&a to &6%s", getEntityName(entity), String.valueOf(health)); + send(sender, "&aSet max health for &6%s&a to &6%s", entity.getName(), String.valueOf(health)); } else { if (isNotEntity(sender)) { return false; } - entity = (LivingEntity) sender; + entity = (EsLivingEntity) sender; send(sender, "&aSet max health to &6%s", String.valueOf(health)); } - setMaxHealth(entity, health); + entity.setMaxHealth(health); return true; } diff --git a/src/main/java/net/serble/estools/Commands/SetPersistentData.java b/src/main/java/net/serble/estools/Commands/SetPersistentData.java index 468ef94..8c2af43 100644 --- a/src/main/java/net/serble/estools/Commands/SetPersistentData.java +++ b/src/main/java/net/serble/estools/Commands/SetPersistentData.java @@ -1,14 +1,8 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import org.bukkit.NamespacedKey; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; -import org.bukkit.persistence.PersistentDataType; +import net.serble.estools.ServerApi.EsPersistentDataType; +import net.serble.estools.ServerApi.Interfaces.*; import java.util.ArrayList; import java.util.List; @@ -17,7 +11,7 @@ public class SetPersistentData extends EsToolsCommand { public static final String usage = genUsage("/setpersistentdata "); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) return false; @@ -26,7 +20,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return true; } - String keyString = args[0].toLowerCase(); + String key = args[0].toLowerCase(); String typeString = args[1].toLowerCase(); String valueString; @@ -40,21 +34,21 @@ public boolean onCommand(CommandSender sender, Command command, String label, St valueString = valueBuilder.toString(); } - ItemStack item = getMainHand((Player) sender); - NamespacedKey key = GetPersistentData.getNamespacedKey(keyString); + EsItemStack item = ((EsPlayer) sender).getMainHand(); +// NamespacedKey key = GetPersistentData.getNamespacedKey(key); +// +// if (key == null) { +// send(sender, "&cInvalid key! examples: 'estools:count', 'backpacks:size', etc"); +// return false; +// } - if (key == null) { - send(sender, "&cInvalid key! examples: 'estools:count', 'backpacks:size', etc"); - return false; - } - - ItemMeta meta = item.getItemMeta(); + EsItemMeta meta = item.getItemMeta(); if (meta == null) { send(sender, "&cItem does not have nbt tags!"); return false; } - PersistentDataContainer data = meta.getPersistentDataContainer(); + EsPersistentDataContainer data = meta.getPersistentDataContainer(); int code = setNbt(typeString, key, data, valueString); if (code == 1) { @@ -74,15 +68,15 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } // 0 = success, 1 = unsupported, 2 = invalid value - public static int setNbt(String type, NamespacedKey key, PersistentDataContainer data, String value) { + public static int setNbt(String type, String key, EsPersistentDataContainer data, String value) { switch (type) { case "string": - data.set(key, PersistentDataType.STRING, value); + data.set(key, EsPersistentDataType.String, value); break; case "integer": try { - data.set(key, PersistentDataType.INTEGER, Integer.parseInt(value)); + data.set(key, EsPersistentDataType.Integer, Integer.parseInt(value)); } catch (NumberFormatException e) { return 2; @@ -91,7 +85,7 @@ public static int setNbt(String type, NamespacedKey key, PersistentDataContainer case "double": try { - data.set(key, PersistentDataType.DOUBLE, Double.parseDouble(value)); + data.set(key, EsPersistentDataType.Double, Double.parseDouble(value)); } catch (NumberFormatException e) { return 2; @@ -100,7 +94,7 @@ public static int setNbt(String type, NamespacedKey key, PersistentDataContainer case "float": try { - data.set(key, PersistentDataType.FLOAT, Float.parseFloat(value)); + data.set(key, EsPersistentDataType.Float, Float.parseFloat(value)); } catch (NumberFormatException e) { return 2; @@ -109,7 +103,7 @@ public static int setNbt(String type, NamespacedKey key, PersistentDataContainer case "long": try { - data.set(key, PersistentDataType.LONG, Long.parseLong(value)); + data.set(key, EsPersistentDataType.Long, Long.parseLong(value)); } catch (NumberFormatException e) { return 2; @@ -118,7 +112,7 @@ public static int setNbt(String type, NamespacedKey key, PersistentDataContainer case "short": try { - data.set(key, PersistentDataType.SHORT, Short.parseShort(value)); + data.set(key, EsPersistentDataType.Short, Short.parseShort(value)); } catch (NumberFormatException e) { return 2; @@ -127,7 +121,7 @@ public static int setNbt(String type, NamespacedKey key, PersistentDataContainer case "byte": try { - data.set(key, PersistentDataType.BYTE, Byte.parseByte(value)); + data.set(key, EsPersistentDataType.Byte, Byte.parseByte(value)); } catch (NumberFormatException e) { return 2; @@ -147,7 +141,7 @@ public static int setNbt(String type, NamespacedKey key, PersistentDataContainer } } - data.set(key, PersistentDataType.BYTE_ARRAY, bytes); + data.set(key, EsPersistentDataType.ByteArray, bytes); break; } @@ -164,7 +158,7 @@ public static int setNbt(String type, NamespacedKey key, PersistentDataContainer } } - data.set(key, PersistentDataType.INTEGER_ARRAY, ints); + data.set(key, EsPersistentDataType.IntArray, ints); break; } @@ -181,7 +175,7 @@ public static int setNbt(String type, NamespacedKey key, PersistentDataContainer } } - data.set(key, PersistentDataType.LONG_ARRAY, longs); + data.set(key, EsPersistentDataType.LongArray, longs); break; } @@ -194,7 +188,7 @@ public static int setNbt(String type, NamespacedKey key, PersistentDataContainer } @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); if (args.length == 2) { diff --git a/src/main/java/net/serble/estools/Commands/SetSaturation.java b/src/main/java/net/serble/estools/Commands/SetSaturation.java index fbc9f55..7408a70 100644 --- a/src/main/java/net/serble/estools/Commands/SetSaturation.java +++ b/src/main/java/net/serble/estools/Commands/SetSaturation.java @@ -2,21 +2,20 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.PlayerCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class SetSaturation extends PlayerCommand { private static final String usage = genUsage("/setsaturation [player]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (args.length == 0) { send(sender, usage); return false; } - Player p; + EsPlayer p; if (args.length > 1) { p = EsToolsCommand.getPlayer(sender, args[1]); @@ -28,7 +27,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - p = (Player)sender; + p = (EsPlayer) sender; } float saturation; diff --git a/src/main/java/net/serble/estools/Commands/SetStack.java b/src/main/java/net/serble/estools/Commands/SetStack.java index d1690ff..cd2b708 100644 --- a/src/main/java/net/serble/estools/Commands/SetStack.java +++ b/src/main/java/net/serble/estools/Commands/SetStack.java @@ -1,16 +1,15 @@ package net.serble.estools.Commands; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; import net.serble.estools.EsToolsCommand; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class SetStack extends EsToolsCommand { private static final String usage = genUsage("/setstack "); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } @@ -28,7 +27,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - getMainHand(((Player)sender)).setAmount(amount); + ((EsPlayer)sender).getMainHand().setAmount(amount); send(sender, "&aSet stack size to &6%d", amount); return true; } diff --git a/src/main/java/net/serble/estools/Commands/SetUnbreakable.java b/src/main/java/net/serble/estools/Commands/SetUnbreakable.java index 69cc8b8..9f49c2d 100644 --- a/src/main/java/net/serble/estools/Commands/SetUnbreakable.java +++ b/src/main/java/net/serble/estools/Commands/SetUnbreakable.java @@ -2,32 +2,33 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.Main; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; +import net.serble.estools.ServerApi.EsEnchantment; +import net.serble.estools.ServerApi.EsMaterial; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsItemMeta; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; + +import java.util.Objects; public class SetUnbreakable extends EsToolsCommand { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - ItemStack item = getMainHand((Player) sender); - if (item == null || item.getType() == Material.AIR || (Main.majorVersion > 10 && item.getItemMeta() == null)) { + EsItemStack item = ((EsPlayer) sender).getMainHand(); + if (item == null || Objects.equals(item.getType(), EsMaterial.createUnchecked("AIR")) || (Main.minecraftVersion.getMinor() > 10 && item.getItemMeta() == null)) { send(sender, "&cMust be a damageable item"); return false; } String message = "&aSet item to &6Breakable!"; - if (Main.majorVersion > 10) { - ItemMeta itemMeta = item.getItemMeta(); + if (Main.minecraftVersion.getMinor() > 10) { + EsItemMeta itemMeta = item.getItemMeta(); itemMeta.setUnbreakable(!itemMeta.isUnbreakable()); item.setItemMeta(itemMeta); @@ -35,10 +36,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St message = "&aSet item to &6Unbreakable!"; } } else { - if (item.getEnchantments().containsKey(Enchantment.DURABILITY)) { - item.removeEnchantment(Enchantment.DURABILITY); + if (item.getEnchantments().keySet().stream() + .anyMatch(c -> c != null && c.getKey().equalsIgnoreCase("unbreaking"))) { + item.removeEnchantment(EsEnchantment.createUnchecked("unbreaking")); } else { - item.addUnsafeEnchantment(Enchantment.DURABILITY, 32767); + item.addEnchantment(EsEnchantment.createUnchecked("unbreaking"), 32767); message = "&aSet item to &6Unbreakable!"; } } diff --git a/src/main/java/net/serble/estools/Commands/Smite.java b/src/main/java/net/serble/estools/Commands/Smite.java index 4fc7a27..11fd29c 100644 --- a/src/main/java/net/serble/estools/Commands/Smite.java +++ b/src/main/java/net/serble/estools/Commands/Smite.java @@ -1,23 +1,21 @@ package net.serble.estools.Commands; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.LivingEntity; - import net.serble.estools.EntityCommand; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsLivingEntity; public class Smite extends EntityCommand { private static final String usage = genUsage("/smite [entity2] [entity3]..."); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (args.length == 0) { send(sender, usage); return false; } for (String arg : args) { - LivingEntity target = getEntity(sender, arg); + EsLivingEntity target = getEntity(sender, arg); if (target == null) { return false; diff --git a/src/main/java/net/serble/estools/Commands/Sudo.java b/src/main/java/net/serble/estools/Commands/Sudo.java index ebbf79f..137bbc3 100644 --- a/src/main/java/net/serble/estools/Commands/Sudo.java +++ b/src/main/java/net/serble/estools/Commands/Sudo.java @@ -1,31 +1,29 @@ package net.serble.estools.Commands; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - +import net.serble.estools.Main; import net.serble.estools.PlayerCommand; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class Sudo extends PlayerCommand { private static final String usage = genUsage("/sudo "); @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (args.length < 2) { send(sender, usage); return false; } - Player p = getPlayer(sender, args[0]); + EsPlayer p = getPlayer(sender, args[0]); if (p == null) { return false; } String command = argsToString(args, 1); - - Bukkit.dispatchCommand(p, command); + + Main.server.dispatchCommand(p, command); send(sender, "&aExecuted command &6%s&a as &6%s", command, p.getName()); return true; } diff --git a/src/main/java/net/serble/estools/Commands/Suicide.java b/src/main/java/net/serble/estools/Commands/Suicide.java index b4b7f46..8a3f076 100644 --- a/src/main/java/net/serble/estools/Commands/Suicide.java +++ b/src/main/java/net/serble/estools/Commands/Suicide.java @@ -1,22 +1,20 @@ package net.serble.estools.Commands; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.LivingEntity; - import net.serble.estools.PlayerCommand; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsLivingEntity; public class Suicide extends PlayerCommand { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - LivingEntity p = (LivingEntity) sender; + EsLivingEntity p = (EsLivingEntity) sender; - setHealth(p, 0); + p.setHealth(0); send(sender, "&aRest in peace"); return true; } diff --git a/src/main/java/net/serble/estools/Commands/Sun.java b/src/main/java/net/serble/estools/Commands/Sun.java index 0e97077..510188c 100644 --- a/src/main/java/net/serble/estools/Commands/Sun.java +++ b/src/main/java/net/serble/estools/Commands/Sun.java @@ -1,21 +1,20 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import net.serble.estools.ServerApi.Interfaces.EsWorld; public class Sun extends EsToolsCommand { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - World world = ((Player) sender).getWorld(); - world.setStorm(false); + EsWorld world = ((EsPlayer) sender).getWorld(); + world.setStorming(false); world.setThundering(false); send(sender, "&aSet weather to &6clear"); diff --git a/src/main/java/net/serble/estools/Commands/Teleport/TpAll.java b/src/main/java/net/serble/estools/Commands/Teleport/TpAll.java index b48bf03..d721fd0 100644 --- a/src/main/java/net/serble/estools/Commands/Teleport/TpAll.java +++ b/src/main/java/net/serble/estools/Commands/Teleport/TpAll.java @@ -1,19 +1,19 @@ package net.serble.estools.Commands.Teleport; import net.serble.estools.EntityCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.LivingEntity; +import net.serble.estools.Main; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsLivingEntity; public class TpAll extends EntityCommand { private static final String usage = genUsage("/tpall [entity]"); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - LivingEntity p; + public boolean execute(EsCommandSender sender, String[] args) { + EsLivingEntity p; if (args.length == 0) { - p = (LivingEntity) sender; + p = (EsLivingEntity) sender; if (isNotEntity(sender, usage)) { return false; @@ -22,13 +22,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St p = getEntity(sender, args[0]); } - for (LivingEntity t : getOnlinePlayers()) { + for (EsLivingEntity t : Main.server.getOnlinePlayers()) { assert p != null; - t.teleport(p); + t.teleport(p.getLocation()); } assert p != null; - send(sender, "&aTeleported all players to &6%s", getEntityName(p)); + send(sender, "&aTeleported all players to &6%s", p.getName()); return true; } } diff --git a/src/main/java/net/serble/estools/Commands/Teleport/TpHere.java b/src/main/java/net/serble/estools/Commands/Teleport/TpHere.java index df845c1..2ffed2d 100644 --- a/src/main/java/net/serble/estools/Commands/Teleport/TpHere.java +++ b/src/main/java/net/serble/estools/Commands/Teleport/TpHere.java @@ -1,15 +1,14 @@ package net.serble.estools.Commands.Teleport; import net.serble.estools.EntityCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.LivingEntity; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsLivingEntity; public class TpHere extends EntityCommand { private static final String usage = genUsage("/tphere [entity2] [entity3]..."); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotEntity(sender)) { return false; } @@ -19,18 +18,18 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - LivingEntity p = (LivingEntity) sender; + EsLivingEntity p = (EsLivingEntity) sender; for (String arg : args) { - LivingEntity t = getEntity(sender, arg); + EsLivingEntity t = getEntity(sender, arg); if (t != null) { - t.teleport(p); + t.teleport(p.getLocation()); } else { return false; } } - send(sender, "&aTeleported &6%s&a to &6%s", argsToString(args, 0), getEntityName(p)); + send(sender, "&aTeleported &6%s&a to &6%s", argsToString(args, 0), p.getName()); return true; } } diff --git a/src/main/java/net/serble/estools/Commands/Thunder.java b/src/main/java/net/serble/estools/Commands/Thunder.java index 88920c7..05b514e 100644 --- a/src/main/java/net/serble/estools/Commands/Thunder.java +++ b/src/main/java/net/serble/estools/Commands/Thunder.java @@ -1,21 +1,20 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import net.serble.estools.ServerApi.Interfaces.EsWorld; public class Thunder extends EsToolsCommand { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - World world = ((Player) sender).getWorld(); - world.setStorm(true); + EsWorld world = ((EsPlayer) sender).getWorld(); + world.setStorming(true); world.setThundering(true); send(sender, "&aSet weather to &6thunder"); diff --git a/src/main/java/net/serble/estools/Commands/Warps/Warp.java b/src/main/java/net/serble/estools/Commands/Warps/Warp.java index 93b20f4..311ff75 100644 --- a/src/main/java/net/serble/estools/Commands/Warps/Warp.java +++ b/src/main/java/net/serble/estools/Commands/Warps/Warp.java @@ -1,9 +1,8 @@ package net.serble.estools.Commands.Warps; import net.serble.estools.EsToolsCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.ArrayList; import java.util.List; @@ -12,12 +11,12 @@ public class Warp extends EsToolsCommand { private static final String usage = genUsage("/warp "); @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (isNotPlayer(sender)) { return false; } - Player p = (Player)sender; + EsPlayer p = (EsPlayer) sender; if (args.length == 0) { send(p, usage); @@ -37,22 +36,22 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return false; } - p.teleport(warp.location); + p.teleport(warp.getLocation()); send(p, "&aTeleported to warp &6%s&a.", warpName); return true; } - private static boolean canUseWarp(Player p, WarpLocation warp) { + private static boolean canUseWarp(EsPlayer p, WarpLocation warp) { if (warp == null) { return false; } boolean hasManage = p.hasPermission("estools.warps.manage"); boolean hasDefault = p.hasPermission("estools.warps.default"); - String warpPermission = "estools.warp." + warp.name; + String warpPermission = "estools.warp." + warp.getName(); // you can only use global warps if you are in the same world, or have manage permission - if (!warp.global && !hasManage && !p.getWorld().equals(warp.location.getWorld())) { + if (!warp.isGlobal() && !hasManage && !p.getWorld().equals(warp.getLocation().getWorld())) { return false; } @@ -62,17 +61,17 @@ private static boolean canUseWarp(Player p, WarpLocation warp) { } @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); - Player p = (Player)sender; + EsPlayer p = (EsPlayer)sender; if (args.length == 1) { for (WarpLocation warp : WarpManager.warps.values()) { - boolean inSameWorld = p.getWorld().equals(warp.location.getWorld()); + boolean inSameWorld = p.getWorld().equals(warp.getLocation().getWorld()); - if (canUseWarp(p, warp) && (warp.global || inSameWorld)) { - tab.add(warp.name); + if (canUseWarp(p, warp) && (warp.isGlobal() || inSameWorld)) { + tab.add(warp.getName()); } } } diff --git a/src/main/java/net/serble/estools/Commands/Warps/WarpLocation.java b/src/main/java/net/serble/estools/Commands/Warps/WarpLocation.java index eb7ce60..8768997 100644 --- a/src/main/java/net/serble/estools/Commands/Warps/WarpLocation.java +++ b/src/main/java/net/serble/estools/Commands/Warps/WarpLocation.java @@ -1,37 +1,33 @@ package net.serble.estools.Commands.Warps; -import org.bukkit.Location; -import org.bukkit.configuration.serialization.ConfigurationSerializable; -import org.bukkit.configuration.serialization.SerializableAs; +import net.serble.estools.ServerApi.EsLocation; -import java.util.Map; -import java.util.HashMap; +public class WarpLocation { + private EsLocation location; + private String name; + private boolean global; -@SerializableAs("WarpLocation") -public class WarpLocation implements ConfigurationSerializable { - public Location location; - public String name; - public boolean global; - - @Override - public Map serialize() { - Map result = new HashMap<>(); + public String getName() { + return name; + } - result.put("location", location); - result.put("name", name); - result.put("global", global); + public EsLocation getLocation() { + return location; + } - return result; + public boolean isGlobal() { + return global; } - @SuppressWarnings("unused") - public static WarpLocation deserialize(Map args) { - WarpLocation warp = new WarpLocation(); + public void setLocation(EsLocation location) { + this.location = location; + } - warp.location = (Location)args.get("location"); - warp.name = (String)args.get("name"); - warp.global = (boolean)args.get("global"); + public void setGlobal(boolean global) { + this.global = global; + } - return warp; + public void setName(String name) { + this.name = name; } } diff --git a/src/main/java/net/serble/estools/Commands/Warps/WarpManager.java b/src/main/java/net/serble/estools/Commands/Warps/WarpManager.java index 42d6a67..b9e329e 100644 --- a/src/main/java/net/serble/estools/Commands/Warps/WarpManager.java +++ b/src/main/java/net/serble/estools/Commands/Warps/WarpManager.java @@ -1,18 +1,15 @@ package net.serble.estools.Commands.Warps; import net.serble.estools.EsToolsCommand; -import net.serble.estools.ConfigManager; -import org.bukkit.Location; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.configuration.serialization.ConfigurationSerialization; -import org.bukkit.entity.Player; +import net.serble.estools.Config.ConfigManager; +import net.serble.estools.ServerApi.EsLocation; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; // this command is /warps public class WarpManager extends EsToolsCommand { @@ -23,48 +20,19 @@ public class WarpManager extends EsToolsCommand { private static final String consoleUsage = genUsage("/warps list"); - public static final HashMap warps = new HashMap<>(); + public static Map warps = new HashMap<>(); + @SuppressWarnings("unchecked") @Override public void onEnable() { - ConfigurationSerialization.registerClass(WarpLocation.class, "WarpLocation"); - - FileConfiguration f = ConfigManager.load("warps.yml"); - - List warpList = f.getList("warps"); - if (warpList == null) { - return; - } - - warpList.sort((w1, w2) -> { - if (w1 instanceof WarpLocation && w2 instanceof WarpLocation) { - WarpLocation warp1 = (WarpLocation)w1; - WarpLocation warp2 = (WarpLocation)w1; - - return warp1.name.compareTo(warp2.name); - } - - return 0; - }); - - warpList.forEach(w -> { - if (w instanceof WarpLocation) { - WarpLocation warp = (WarpLocation)w; - warps.put(warp.name, warp); - } - }); + warps = ConfigManager.load("warps.yml", HashMap.class, WarpLocation.class); } private static void saveWarps() { - FileConfiguration f = new YamlConfiguration(); - - List warpList = new ArrayList<>(warps.values()); - f.set("warps", warpList); - - ConfigManager.save("warps.yml", f); + ConfigManager.save("warps.yml", warps); } - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { if (args.length == 0) { if (isNotPlayer(sender, consoleUsage)) { return false; @@ -86,8 +54,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String for (WarpLocation warp : warps.values()) { warpList.append(translate("\n&6%s &aat &6%s &ain &6%s &ais &6%s", - warp.name, locationToString(warp.location), - warp.location.getWorld().getName(), warp.global ? "global" : "local")); + warp.getName(), locationToString(warp.getLocation()), + warp.getLocation().getWorld().getName(), warp.isGlobal() ? "global" : "local")); } send(sender, warpList.toString()); @@ -138,11 +106,11 @@ warp.name, locationToString(warp.location), switch (args[0].toLowerCase()) { case "add": { if (warp != null) { - send(sender, "&cWarp does not exist, please use add to create it."); + send(sender, "&cWarp already exists."); return false; } - if (createWarp((Player)sender, warpName, args, global)) { + if (createWarp((EsPlayer)sender, warpName, args, global)) { return false; } @@ -156,7 +124,7 @@ warp.name, locationToString(warp.location), return false; } - if (createWarp((Player)sender, warpName, args, global)) { + if (createWarp((EsPlayer)sender, warpName, args, global)) { return false; } @@ -172,10 +140,10 @@ warp.name, locationToString(warp.location), } // returns true if failed - private static boolean createWarp(Player p, String warpName, String[] args, boolean global) { + private static boolean createWarp(EsPlayer p, String warpName, String[] args, boolean global) { // /warps [LOCAL/global] [x] [y] [z] [yaw] [pitch] - Location loc; + EsLocation loc; if (args.length <= 3) { loc = p.getLocation(); } @@ -184,7 +152,7 @@ else if (args.length < 6) { // if you supplied only some of the coordinates, wha return true; } else { - loc = new Location(p.getWorld(), + loc = new EsLocation(p.getWorld(), parseCoordinate(args[3], p.getLocation().getX()), parseCoordinate(args[4], p.getLocation().getY()), parseCoordinate(args[5], p.getLocation().getZ()) @@ -210,9 +178,9 @@ else if (args.length < 6) { // if you supplied only some of the coordinates, wha } WarpLocation warp = new WarpLocation(); - warp.location = loc; - warp.global = global; - warp.name = warpName; + warp.setLocation(loc); + warp.setGlobal(global); + warp.setName(warpName); warps.put(warpName, warp); saveWarps(); @@ -221,7 +189,7 @@ else if (args.length < 6) { // if you supplied only some of the coordinates, wha } @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); // /warps [LOCAL/global] [x] [y] [z] [yaw] [pitch] // /warps remove diff --git a/src/main/java/net/serble/estools/Commands/WrongVersion.java b/src/main/java/net/serble/estools/Commands/WrongVersion.java index e3665e8..f11dc39 100644 --- a/src/main/java/net/serble/estools/Commands/WrongVersion.java +++ b/src/main/java/net/serble/estools/Commands/WrongVersion.java @@ -1,8 +1,7 @@ package net.serble.estools.Commands; import net.serble.estools.EsToolsCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; public class WrongVersion extends EsToolsCommand { private final String minVersion; @@ -16,7 +15,7 @@ public WrongVersion(String ver) { } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean execute(EsCommandSender sender, String[] args) { send(sender, "&cThis command requires Minecraft to be at least 1.%s", minVersion); return true; } diff --git a/src/main/java/net/serble/estools/Config/ConfigManager.java b/src/main/java/net/serble/estools/Config/ConfigManager.java new file mode 100644 index 0000000..18552fd --- /dev/null +++ b/src/main/java/net/serble/estools/Config/ConfigManager.java @@ -0,0 +1,94 @@ +package net.serble.estools.Config; + +import java.io.*; +import java.util.Arrays; + +import net.serble.estools.Main; +import org.jetbrains.annotations.NotNull; +import org.yaml.snakeyaml.LoaderOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.Constructor; +import org.yaml.snakeyaml.inspector.TagInspector; + +public class ConfigManager { + + @SuppressWarnings("rawtypes") + public static T load(String fileName, Class base, Class... allowedClasses) { + String[] cs = new String[allowedClasses.length]; + for (int i = 0; i < cs.length; i++) { + cs[i] = allowedClasses[i].getName(); + } + File file = new File(Main.server.getDataFolder(), fileName); + return load(file, base, cs); + } + + public static T load(String fileName, Class base, String... allowedClasses) { + File file = new File(Main.server.getDataFolder(), fileName); + return load(file, base, allowedClasses); + } + + // Exists so the above 2 don't make ambig reference when array is not supplied + public static T load(String fileName, Class base) { + File file = new File(Main.server.getDataFolder(), fileName); + return load(file, base); + } + + public static T load(File configFile, Class base, String... allowedClasses) { + if (!configFile.exists()) { + // Save a default version + try { + Object instance = base.newInstance(); + save(configFile, instance); + } catch (IllegalAccessException | InstantiationException e) { + Main.logger.severe("Failed to save default config, this is a bug"); + throw new RuntimeException("Bug with saving default config: " + e); + } + } + + Yaml yaml = createYamlLoader(base, allowedClasses); + try { + return yaml.load(new FileInputStream(configFile)); + } catch (FileNotFoundException e) { + Main.logger.severe("Impossible situation reached, files that we created don't exist"); + throw new RuntimeException("Impossible"); + } + } + + private static @NotNull Yaml createYamlLoader(Class base, String[] allowedClasses) { + LoaderOptions options = new LoaderOptions(); + TagInspector taginspector = tag -> + tag.getClassName().equals(base.getName()) || + Arrays.stream(allowedClasses).anyMatch(c -> c.equals(tag.getClassName())) || + Arrays.stream(Main.server.getRelevantInternalTypes()).anyMatch(c -> tag.getClassName().endsWith(c) || + tag.getClassName().startsWith("net.serble.estools.ServerApi")); // Allow all server api classes (Stuff like EsMaterial) + options.setTagInspector(taginspector); + return new Yaml(new Constructor(base, options)); + } + + public static void save(String file, Object obj) { + File configFile = new File(Main.server.getDataFolder(), file); + save(configFile, obj); + } + + @SuppressWarnings("ResultOfMethodCallIgnored") + public static void save(File configFile, Object obj) { + if (!configFile.exists()) { + configFile.getParentFile().mkdirs(); + try { + configFile.createNewFile(); + } catch (IOException e) { + Main.logger.warning("Failed to create config file: " + e); + } + } + + Yaml yaml = new Yaml(); + String contents = yaml.dump(obj); + try { + FileWriter writer = new FileWriter(configFile); + writer.write(contents); + writer.close(); + } catch (IOException e) { + Main.logger.severe("Failed to save config file: " + e); + } + } +} diff --git a/src/main/java/net/serble/estools/Config/Schemas/GeneralConfig/EsToolsConfig.java b/src/main/java/net/serble/estools/Config/Schemas/GeneralConfig/EsToolsConfig.java new file mode 100644 index 0000000..205eb83 --- /dev/null +++ b/src/main/java/net/serble/estools/Config/Schemas/GeneralConfig/EsToolsConfig.java @@ -0,0 +1,32 @@ +package net.serble.estools.Config.Schemas.GeneralConfig; + +@SuppressWarnings("unused") // SnakeYAML needs the setters +public class EsToolsConfig { + private boolean safeTp = false; + private boolean metrics = true; + private UpdaterConfig updater = new UpdaterConfig(); + + public boolean isSafeTp() { + return safeTp; + } + + public void setSafeTp(boolean safeTp) { + this.safeTp = safeTp; + } + + public boolean isMetrics() { + return metrics; + } + + public void setMetrics(boolean metrics) { + this.metrics = metrics; + } + + public UpdaterConfig getUpdater() { + return updater; + } + + public void setUpdater(UpdaterConfig updater) { + this.updater = updater; + } +} diff --git a/src/main/java/net/serble/estools/Config/Schemas/GeneralConfig/UpdaterConfig.java b/src/main/java/net/serble/estools/Config/Schemas/GeneralConfig/UpdaterConfig.java new file mode 100644 index 0000000..5097183 --- /dev/null +++ b/src/main/java/net/serble/estools/Config/Schemas/GeneralConfig/UpdaterConfig.java @@ -0,0 +1,41 @@ +package net.serble.estools.Config.Schemas.GeneralConfig; + +@SuppressWarnings("unused") // SnakeYAML needs the setters +public class UpdaterConfig { + private String githubReleasesUrl = "https://api.github.com/repos/CoPokBl/EsTools/releases/latest"; + private boolean autoUpdate = false; + private boolean warnOnOutdated = false; + private boolean logOnOutdated = true; + + public boolean isAutoUpdate() { + return autoUpdate; + } + + public boolean isLogOnOutdated() { + return logOnOutdated; + } + + public boolean isWarnOnOutdated() { + return warnOnOutdated; + } + + public void setAutoUpdate(boolean autoUpdate) { + this.autoUpdate = autoUpdate; + } + + public String getGithubReleasesUrl() { + return githubReleasesUrl; + } + + public void setGithubReleasesUrl(String githubReleasesUrl) { + this.githubReleasesUrl = githubReleasesUrl; + } + + public void setLogOnOutdated(boolean logOnOutdated) { + this.logOnOutdated = logOnOutdated; + } + + public void setWarnOnOutdated(boolean warnOnOutdated) { + this.warnOnOutdated = warnOnOutdated; + } +} diff --git a/src/main/java/net/serble/estools/Config/Schemas/Give/GiveConfig.java b/src/main/java/net/serble/estools/Config/Schemas/Give/GiveConfig.java new file mode 100644 index 0000000..da31169 --- /dev/null +++ b/src/main/java/net/serble/estools/Config/Schemas/Give/GiveConfig.java @@ -0,0 +1,43 @@ +package net.serble.estools.Config.Schemas.Give; + +import java.util.HashMap; +import java.util.Map; + +@SuppressWarnings("unused") // SnakeYAML needs the setters +public class GiveConfig { + private GiveSettings settings = new GiveSettings(); + private Map items = new HashMap() {{ + put("boat", "oak_boat"); + put("pearl", "ender_pearl"); + put("sign", "oak_sign"); + put("button", "stone_button"); + put("sapling", "oak_sapling"); + put("log", "oak_log"); + put("door", "oak_door"); + put("fence", "oak_fence"); + put("fence_gate", "oak_fence_gate"); + put("leaves", "oak_leaves"); + put("planks", "oak_planks"); + put("pressure_plate", "stone_pressure_plate"); + put("trapdoor", "oak_trapdoor"); + put("steak", "cooked_beef"); + put("water", "water_bucket"); + put("lava", "lava_bucket"); + }}; + + public GiveSettings getSettings() { + return settings; + } + + public void setSettings(GiveSettings settings) { + this.settings = settings; + } + + public Map getItems() { + return items; + } + + public void setItems(Map items) { + this.items = items; + } +} diff --git a/src/main/java/net/serble/estools/Config/Schemas/Give/GiveSettings.java b/src/main/java/net/serble/estools/Config/Schemas/Give/GiveSettings.java new file mode 100644 index 0000000..54b3bee --- /dev/null +++ b/src/main/java/net/serble/estools/Config/Schemas/Give/GiveSettings.java @@ -0,0 +1,23 @@ +package net.serble.estools.Config.Schemas.Give; + +@SuppressWarnings("unused") // SnakeYAML needs the setters +public class GiveSettings { + private boolean addWithoutUnderscores = true; + private boolean removeWithUnderscores = false; + + public boolean isAddWithoutUnderscores() { + return addWithoutUnderscores; + } + + public boolean isRemoveWithUnderscores() { + return removeWithUnderscores; + } + + public void setAddWithoutUnderscores(boolean addWithoutUnderscores) { + this.addWithoutUnderscores = addWithoutUnderscores; + } + + public void setRemoveWithUnderscores(boolean removeWithUnderscores) { + this.removeWithUnderscores = removeWithUnderscores; + } +} diff --git a/src/main/java/net/serble/estools/ConfigManager.java b/src/main/java/net/serble/estools/ConfigManager.java deleted file mode 100644 index af3acbf..0000000 --- a/src/main/java/net/serble/estools/ConfigManager.java +++ /dev/null @@ -1,113 +0,0 @@ -package net.serble.estools; - -import java.io.*; -import java.util.Set; - -import org.bukkit.Bukkit; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; - -public class ConfigManager { - - public static final Main plugin = Main.plugin; - - public static FileConfiguration load(String fileName) { - return load(new File(plugin.getDataFolder(), fileName)); - } - - @SuppressWarnings("ResultOfMethodCallIgnored") - public static FileConfiguration load(File configFile) { - if (!configFile.exists()) { - configFile.getParentFile().mkdirs(); - try { - configFile.createNewFile(); - } catch (IOException e) { - Bukkit.getLogger().warning("Failed to create config file: " + e); - } - } - - FileConfiguration config = new YamlConfiguration(); - try { - config.load(configFile); - } catch (IOException | InvalidConfigurationException | IllegalArgumentException e) { - Bukkit.getLogger().severe("Failed to read config file: " + e); - } - - return config; - } - - @SuppressWarnings("ResultOfMethodCallIgnored") - public static void save(String file, FileConfiguration config) { - File configFile = new File(plugin.getDataFolder(), file); - if (!configFile.exists()) { - configFile.getParentFile().mkdirs(); - try { - configFile.createNewFile(); - } catch (IOException e) { - Bukkit.getLogger().warning("Failed to create config file: " + e); - } - } - - try { - config.save(configFile); - } catch (IOException e) { - Bukkit.getLogger().severe("Failed to save config file: " + e); - } - } - - // Make sure to save the file after you run this, we don't do that automatically - public static boolean patchDefaults(FileConfiguration config, FileConfiguration defaults) { - return patchDefaults("", config, defaults); - } - - // Patch a section, needed because we must recursively traverse the key hierarchy - private static boolean patchDefaults(String path, FileConfiguration config, FileConfiguration defaults) { - Main.asrt(path != null); - Main.asrt(config != null); - Main.asrt(defaults != null); - - boolean changedAnything = false; - - ConfigurationSection section = defaults.getConfigurationSection(path); - if (section == null) { - if (!config.contains(path)) { - config.set(path, defaults.get(path)); - changedAnything = true; - } - } else { - Set keys = section.getKeys(false); - for (String key : keys) { - String updatedPath = path.isEmpty() ? key : path + "." + key; - changedAnything = patchDefaults(updatedPath, config, defaults) || changedAnything; - } - } - - return changedAnything; - } - - public static boolean patchDefaults(FileConfiguration config, InputStream defaultsRes) { - InputStreamReader reader = new InputStreamReader(defaultsRes); - FileConfiguration defaults = new YamlConfiguration(); - String fileContents; - try { - StringBuilder contentsBuilder = new StringBuilder(); - BufferedReader bufferedReader = new BufferedReader(reader); - - String line; - while ((line = bufferedReader.readLine()) != null) { - contentsBuilder.append(line).append("\n"); - } - - bufferedReader.close(); - fileContents = contentsBuilder.toString(); - defaults.loadFromString(fileContents); - } catch (IOException | InvalidConfigurationException e) { - Bukkit.getLogger().severe("Could not load default config file, there is a good chance this is bug with EsTools"); - return false; - } - - return patchDefaults(config, defaults); - } -} diff --git a/src/main/java/net/serble/estools/Effects.java b/src/main/java/net/serble/estools/Effects.java deleted file mode 100644 index 6bb0915..0000000 --- a/src/main/java/net/serble/estools/Effects.java +++ /dev/null @@ -1,94 +0,0 @@ -package net.serble.estools; - -import org.bukkit.potion.PotionEffectType; -import org.bukkit.potion.PotionType; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -@SuppressWarnings("deprecation") -public class Effects { - private static final Map EFFECTS = new HashMap<>(); - private static final Map POTIONS = new HashMap<>(); - - public static PotionEffectType getByName(String name) { - return EFFECTS.get(name.toLowerCase(Locale.ENGLISH)); - } - - public static PotionType getPotionByName(String name) { - return POTIONS.get(name.toLowerCase(Locale.ENGLISH)); - } - - public static String getName(PotionEffectType effect) { - for (Map.Entry a : EFFECTS.entrySet()) { - if (a.getValue().equals(effect)) { - return a.getKey(); - } - } - - return "invalid"; - } - - public static Set> entrySet() { - return EFFECTS.entrySet(); - } - - public static Set> potionEntrySet() { - return POTIONS.entrySet(); - } - - static { - if (Main.majorVersion <= 8) { // 1.8 only potions be funky - POTIONS.put("regeneration", PotionType.REGEN); - POTIONS.put("speed", PotionType.SPEED); - POTIONS.put("fire_resistance", PotionType.FIRE_RESISTANCE); - POTIONS.put("poison", PotionType.POISON); - POTIONS.put("instant_health", PotionType.INSTANT_HEAL); - POTIONS.put("weakness", PotionType.WEAKNESS); - POTIONS.put("strength", PotionType.STRENGTH); - POTIONS.put("slowness", PotionType.SLOWNESS); - POTIONS.put("instant_damage", PotionType.INSTANT_DAMAGE); - - if (Main.majorVersion >= 4 && Main.minorVersion >= 2) { // Night vision was added in 1.4.2 - POTIONS.put("night_vision", PotionType.NIGHT_VISION); - POTIONS.put("invisibility", PotionType.INVISIBILITY); - } - - if (Main.majorVersion >= 7 && Main.minorVersion >= 2) { // 1.7.2 - POTIONS.put("water_breathing", PotionType.WATER); - } - - if (Main.majorVersion >= 8) { // 1.8 - POTIONS.put("jump_boost", PotionType.JUMP); - } - } - - HashMap nameReplacers = new HashMap() {{ - put("confusion", "nausea"); - put("damage_resistance", "resistance"); - put("fast_digging", "haste"); - put("harm", "instant_damage"); - put("heal", "instant_health"); - put("increase_damage", "strength"); - put("slow", "slowness"); - put("slow_digging", "mining_fatigue"); - put("jump", "jump_boost"); - }}; - - for (PotionEffectType p : PotionEffectType.values()) { - if (p == null) { // 1.1 has null values in here... - continue; - } - - String name = p.getName().toLowerCase(Locale.ENGLISH); - - if (nameReplacers.containsKey(name)) { - name = nameReplacers.get(name); - } - - EFFECTS.put(name, p); - } - } -} diff --git a/src/main/java/net/serble/estools/Enchantments.java b/src/main/java/net/serble/estools/Enchantments.java deleted file mode 100644 index bdae7df..0000000 --- a/src/main/java/net/serble/estools/Enchantments.java +++ /dev/null @@ -1,66 +0,0 @@ -package net.serble.estools; - -import org.bukkit.enchantments.Enchantment; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -// This class exists because the registry doesn't exist pre 1.13, so all the enchantments names have to be hardcoded. -// only enchantments before 1.13 need to be here because this class isn't used past 1.13 -public class Enchantments { - private static final Map ENCHANTMENTS = new HashMap<>(); - - public static Enchantment getByName(String name) { - return ENCHANTMENTS.get(name.toLowerCase(Locale.ENGLISH)); - } - - public static Set> entrySet() { - return ENCHANTMENTS.entrySet(); - } - - static { AddEnchants(); } - - private static void AddEnchants() { - ENCHANTMENTS.put("sharpness", Enchantment.DAMAGE_ALL); - ENCHANTMENTS.put("baneofarthropods", Enchantment.DAMAGE_ARTHROPODS); - ENCHANTMENTS.put("smite", Enchantment.DAMAGE_UNDEAD); - ENCHANTMENTS.put("efficiency", Enchantment.DIG_SPEED); - ENCHANTMENTS.put("unbreaking", Enchantment.DURABILITY); - ENCHANTMENTS.put("fireaspect", Enchantment.FIRE_ASPECT); - ENCHANTMENTS.put("knockback", Enchantment.KNOCKBACK); - ENCHANTMENTS.put("looting", Enchantment.LOOT_BONUS_MOBS); - ENCHANTMENTS.put("respiration", Enchantment.OXYGEN); - ENCHANTMENTS.put("protection", Enchantment.PROTECTION_ENVIRONMENTAL); - ENCHANTMENTS.put("blastprotect", Enchantment.PROTECTION_EXPLOSIONS); - ENCHANTMENTS.put("featherfall", Enchantment.PROTECTION_FALL); - ENCHANTMENTS.put("projectileprotection", Enchantment.PROTECTION_PROJECTILE); - ENCHANTMENTS.put("silktouch", Enchantment.SILK_TOUCH); - ENCHANTMENTS.put("aquaaffinity", Enchantment.WATER_WORKER); - ENCHANTMENTS.put("flame", Enchantment.ARROW_FIRE); - ENCHANTMENTS.put("power", Enchantment.ARROW_DAMAGE); - ENCHANTMENTS.put("punch", Enchantment.ARROW_KNOCKBACK); - ENCHANTMENTS.put("infinity", Enchantment.ARROW_INFINITE); - ENCHANTMENTS.put("fortune", Enchantment.LOOT_BONUS_BLOCKS); - - if (Main.majorVersion <= 3) return; - ENCHANTMENTS.put("thorns", Enchantment.THORNS); - - if (Main.majorVersion <= 6) return; - ENCHANTMENTS.put("luck", Enchantment.LUCK); - ENCHANTMENTS.put("lure", Enchantment.LURE); - - if (Main.majorVersion <= 7) return; - ENCHANTMENTS.put("depthstrider", Enchantment.DEPTH_STRIDER); - - if (Main.majorVersion <= 8) return; - ENCHANTMENTS.put("frostwalker", Enchantment.FROST_WALKER); - ENCHANTMENTS.put("mending", Enchantment.MENDING); - - if (Main.majorVersion <= 10) return; - ENCHANTMENTS.put("bindingcurse", Enchantment.BINDING_CURSE); - ENCHANTMENTS.put("vanishingcurse", Enchantment.VANISHING_CURSE); - ENCHANTMENTS.put("sweepingedge", Enchantment.SWEEPING_EDGE); - } -} diff --git a/src/main/java/net/serble/estools/EntityCommand.java b/src/main/java/net/serble/estools/EntityCommand.java index ceccabb..4d0c756 100644 --- a/src/main/java/net/serble/estools/EntityCommand.java +++ b/src/main/java/net/serble/estools/EntityCommand.java @@ -1,71 +1,56 @@ package net.serble.estools; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsEntity; +import net.serble.estools.ServerApi.Interfaces.EsLivingEntity; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import net.serble.estools.ServerApi.Position; + import java.util.ArrayList; import java.util.List; import java.util.UUID; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - public abstract class EntityCommand extends EsToolsCommand { @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); - if (sender instanceof Player) { - Player p = (Player) sender; + if (sender instanceof EsPlayer) { + EsPlayer p = (EsPlayer) sender; - List ens = p.getNearbyEntities(5, 5, 5); + List ens = p.getWorld().getNearbyEntities(p.getLocation(), 5, 5, 5); - Entity en = getTarget(p, ens); + EsEntity en = getTarget(p, ens); - if (en != null && !(en instanceof Player)) { + if (en != null && !(en instanceof EsPlayer)) { String eu = en.getUniqueId().toString(); tab.add(eu); } } - for (Player p : Bukkit.getOnlinePlayers()) { + for (EsPlayer p : Main.server.getOnlinePlayers()) { tab.add(p.getName()); } return tab; } - public static LivingEntity getEntity(CommandSender sender, String name) { - Entity entity = getNonLivingEntity(sender, name); - if (entity instanceof LivingEntity) return (LivingEntity) entity; + public static EsLivingEntity getEntity(EsCommandSender sender, String name) { + EsEntity entity = getNonLivingEntity(sender, name); + if (entity instanceof EsLivingEntity) return (EsLivingEntity) entity; if (entity != null) { send(sender, "&cPlayer/Entity not found."); } return null; } - public static Entity getNonLivingEntity(CommandSender sender, String name) { - Entity p = Bukkit.getPlayer(name); + public static EsEntity getNonLivingEntity(EsCommandSender sender, String name) { + EsEntity p = Main.server.getPlayer(name); if (p == null) { try { UUID uid = UUID.fromString(name); - - if (Main.majorVersion > 11) { - p = Bukkit.getEntity(uid); - } else { - if (sender instanceof Player) { - List entities = ((Player)sender).getWorld().getEntities(); - - for (Entity e : entities) { - if (e.getUniqueId().equals(uid)) { - p = e; - break; - } - } - } - } + p = Main.server.getEntity(uid); if (p != null) { return p; @@ -78,39 +63,39 @@ public static Entity getNonLivingEntity(CommandSender sender, String name) { return p; } - public static T getTarget(final Entity entity, - final Iterable entities) { + public static T getTarget(final EsEntity entity, + final Iterable entities) { if (entity == null) return null; T target = null; final double threshold = 1; for (final T other : entities) { - final Vector n = other.getLocation().toVector() - .subtract(entity.getLocation().toVector()); - if (entity.getLocation().getDirection().normalize().crossProduct(n) + final Position n = other.getLocation() + .subtract(entity.getLocation()).toPosition(); + if (entity.getLocation().getDirection().normalise().crossProduct(n) .lengthSquared() < threshold - && n.normalize().dot( - entity.getLocation().getDirection().normalize()) >= 0) { + && n.normalise().dot( + entity.getLocation().getDirection().normalise()) >= 0) { if (target == null || target.getLocation().distanceSquared( - entity.getLocation()) > other.getLocation() - .distanceSquared(entity.getLocation())) + entity.getLocation().toPosition()) > other.getLocation() + .distanceSquared(entity.getLocation().toPosition())) target = other; } } return target; } - public static boolean isNotEntity(CommandSender sender, String usage, Object... a) { - if (!(sender instanceof LivingEntity)) { + public static boolean isNotEntity(EsCommandSender sender, String usage, Object... a) { + if (!(sender instanceof EsLivingEntity)) { send(sender, usage, a); return true; } return false; } - public static boolean isNotEntity(CommandSender sender) { - if (!(sender instanceof LivingEntity)) { + public static boolean isNotEntity(EsCommandSender sender) { + if (!(sender instanceof EsLivingEntity)) { send(sender, "&cYou must be a player to run this command!"); return true; } diff --git a/src/main/java/net/serble/estools/Entrypoints/EsToolsBukkit.java b/src/main/java/net/serble/estools/Entrypoints/EsToolsBukkit.java new file mode 100644 index 0000000..582b476 --- /dev/null +++ b/src/main/java/net/serble/estools/Entrypoints/EsToolsBukkit.java @@ -0,0 +1,46 @@ +package net.serble.estools.Entrypoints; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitEffectHelper; +import net.serble.estools.ServerApi.ServerPlatform; +import org.bukkit.plugin.java.JavaPlugin; + +/** This will be called for Bukkit and Folia platforms */ +public class EsToolsBukkit extends JavaPlugin { + /** Will be null if plugin is not Bukkit */ + public static EsToolsBukkit plugin; + + @Override + public void onEnable() { + // This is needed for SnakeYAML to work on Spigot, see https://www.spigotmc.org/threads/cannot-use-shaded-snakeyaml-to-construct-class-object.136707/#post-4329381 + Thread.currentThread().setContextClassLoader(this.getClassLoader()); + + plugin = this; + + ServerPlatform platform = isFolia() ? ServerPlatform.Folia : ServerPlatform.Bukkit; + + Main main = new Main(platform, this); + main.enable(); + + // Init any Bukkit helpers that need it. + // It's best to do it here because Folia and Bukkit + // need it. + // This must come after Main.enable() so that mcVersion is set. + // It also only works on 1.1+ + if (Main.minecraftVersion.isAtLeast(1, 1, 0)) { + BukkitEffectHelper.load(); + } + } + + @Override + public void onDisable() { /* Needed for older versions, which require an onDisable method */ } + + private static boolean isFolia() { + try { + Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } +} diff --git a/src/main/java/net/serble/estools/EsToolsCommand.java b/src/main/java/net/serble/estools/EsToolsCommand.java index cb8e49d..9caaa54 100644 --- a/src/main/java/net/serble/estools/EsToolsCommand.java +++ b/src/main/java/net/serble/estools/EsToolsCommand.java @@ -1,26 +1,18 @@ package net.serble.estools; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.attribute.Attribute; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; +import net.serble.estools.ServerApi.EsLocation; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.*; -public abstract class EsToolsCommand implements CommandExecutor, EsToolsTabCompleter { +public abstract class EsToolsCommand implements EsToolsTabCompleter { - public void onEnable() {} + public void onEnable() { } @Override - public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { - if (Main.majorVersion < 7) { + public List onTabComplete(EsCommandSender sender, String[] args) { + if (Main.minecraftVersion.getMinor() < 7) { return new ArrayList<>(); } @@ -35,12 +27,14 @@ public static List fixTabComplete(List inList, String arg) { return inList; } - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { return new ArrayList<>(); } + + public abstract boolean execute(EsCommandSender sender, String[] args); - public static void send(CommandSender s, String m, Object... a) { - if (Main.majorVersion > 1) { + public static void send(EsCommandSender s, String m, Object... a) { + if (Main.minecraftVersion.getMinor() > 1) { s.sendMessage(translate(m, a)); return; } @@ -53,30 +47,21 @@ public static void send(CommandSender s, String m, Object... a) { } } - public static void send(Player s, String m, Object... a) { - s.sendMessage(translate(m, a)); - } - public static String translate(String m, Object... a) { - if (Main.majorVersion > 1) { - return ChatColor.translateAlternateColorCodes('&', String.format(m, a)); - } - - // translateAlternateColorCodes doesn't exist in 1.1 and 1.0 - // do it manually + // This works for every Minecraft :) return String.format(m, a).replace('&', '§'); } - public static boolean isNotPlayer(CommandSender sender, String usage, Object... a) { - if (!(sender instanceof Player)) { + public static boolean isNotPlayer(EsCommandSender sender, String usage, Object... a) { + if (!(sender instanceof EsPlayer)) { send(sender, usage, a); return true; } return false; } - public static boolean isNotPlayer(CommandSender sender) { - if (!(sender instanceof Player)) { + public static boolean isNotPlayer(EsCommandSender sender) { + if (!(sender instanceof EsPlayer)) { send(sender, "&cYou must be a player to run this command!"); return true; } @@ -100,11 +85,11 @@ public static double tryParseDouble(String obj, double defaultValue) { } // This is different from checkPerms because it doesn't display any messages - public static boolean hasPerm(CommandSender sender, String perm) { + public static boolean hasPerm(EsCommandSender sender, String perm) { return sender.hasPermission("estools." + perm); } - public static boolean checkPerms(CommandSender sender, String perm) { + public static boolean checkPerms(EsCommandSender sender, String perm) { if (!sender.hasPermission("estools." + perm)) { send(sender, "&cYou do not have permission to run this command."); return true; @@ -116,8 +101,8 @@ public static String genUsage(String use) { return "&r&c&lUsage: &r&c" + use.replace("\n", "\n "); } - public static Player getPlayer(CommandSender sender, String name) { - Player p = Bukkit.getPlayer(name); + public static EsPlayer getPlayer(EsCommandSender sender, String name) { + EsPlayer p = Main.server.getPlayer(name); if (p == null) { send(sender, "&cPlayer not found."); @@ -158,127 +143,7 @@ public static double parseCoordinate(String coord, double playerLoc) { return tryParseDouble(coord, 0); } - public static String locationToString(Location loc) { + public static String locationToString(EsLocation loc) { return String.format("%d %d %d", Math.round(loc.getX()), Math.round(loc.getY()), Math.round(loc.getZ())); } - - public static ItemStack getMainHand(Player p) { - if (Main.majorVersion > 8) { - return p.getInventory().getItemInMainHand(); - } else { - //noinspection deprecation - return p.getInventory().getItemInHand(); - } - } - - public static void setMainHand(Player p, ItemStack is) { - if (Main.majorVersion > 8) { - p.getInventory().setItemInMainHand(is); - } else { - //noinspection deprecation - p.getInventory().setItemInHand(is); - } - } - - public static double getMaxHealth(LivingEntity p) { - if (Main.majorVersion > 8) { - return Objects.requireNonNull(p.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue(); - } else { - if (Main.majorVersion > 5) { - //noinspection deprecation - return p.getMaxHealth(); - } - - try { - return (double)(int)LivingEntity.class.getMethod("getMaxHealth").invoke(p); - } catch(Exception e) { - Bukkit.getLogger().severe(e.toString()); - return 20d; - } - } - } - - public static void setMaxHealth(LivingEntity p, double value) { - if (Main.majorVersion > 8) { - Objects.requireNonNull(p.getAttribute(Attribute.GENERIC_MAX_HEALTH)).setBaseValue(value); - } else { - if (Main.majorVersion > 5) { - //noinspection deprecation - p.setMaxHealth(value); - return; - } - - try { - //noinspection JavaReflectionMemberAccess - LivingEntity.class.getMethod("setMaxHealth", int.class).invoke(p, (int)value); - } - catch (Exception ex) { - Bukkit.getLogger().severe(ex.toString()); - } - } - } - - public static double getHealth(LivingEntity p) { - if (Main.majorVersion > 5) { - return p.getHealth(); - } - - try { - return (double)(int)LivingEntity.class.getMethod("getHealth").invoke(p); - } - catch (Exception ex) { - Bukkit.getLogger().severe(ex.toString()); - return 20d; - } - } - - public static void setHealth(LivingEntity p, double value) { - if (Main.majorVersion > 5) { - p.setHealth(value); - return; - } - - try { - //noinspection JavaReflectionMemberAccess - LivingEntity.class.getMethod("setHealth", int.class).invoke(p, (int)value); - } - catch (Exception ex) { - Bukkit.getLogger().severe(ex.toString()); - } - } - - public static String getEntityName(Entity p) { - if (Main.majorVersion > 7) { - return p.getName(); - } - - if (p instanceof Player) { - return ((Player)p).getDisplayName(); - } - - if (p instanceof LivingEntity) { - String name = ((LivingEntity)p).getCustomName(); - if (name != null) { - return name; - } - } - - return "Entity"; - } - - public static Collection getOnlinePlayers() { - try { - if (Bukkit.class.getMethod("getOnlinePlayers").getReturnType() == Collection.class) { - return Bukkit.getOnlinePlayers(); - } - else { - Player[] players = (Player[]) Bukkit.class.getMethod("getOnlinePlayers").invoke(null, new Object[0]); - return Arrays.asList(players); - } - - } catch (Exception e) { - Bukkit.getLogger().severe(e.toString()); - return new ArrayList<>(); - } - } } diff --git a/src/main/java/net/serble/estools/EsToolsTabCompleter.java b/src/main/java/net/serble/estools/EsToolsTabCompleter.java index e539383..3347f05 100644 --- a/src/main/java/net/serble/estools/EsToolsTabCompleter.java +++ b/src/main/java/net/serble/estools/EsToolsTabCompleter.java @@ -1,15 +1,9 @@ package net.serble.estools; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.PluginCommand; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; import java.util.List; public interface EsToolsTabCompleter { - default void register(PluginCommand cmd) { - cmd.setTabCompleter(TabCompleteGenerator.generate(this)); - } - - List onTabComplete(CommandSender sender, Command command, String alias, String[] args); + List onTabComplete(EsCommandSender sender, String[] args); } diff --git a/src/main/java/net/serble/estools/Main.java b/src/main/java/net/serble/estools/Main.java index 473265b..78c44e7 100644 --- a/src/main/java/net/serble/estools/Main.java +++ b/src/main/java/net/serble/estools/Main.java @@ -8,76 +8,86 @@ import net.serble.estools.Commands.PowerPick.*; import net.serble.estools.Commands.Teleport.*; import net.serble.estools.Commands.Warps.*; +import net.serble.estools.Config.ConfigManager; +import net.serble.estools.Config.Schemas.GeneralConfig.EsToolsConfig; +import net.serble.estools.Entrypoints.EsToolsBukkit; +import net.serble.estools.ServerApi.EsEventListener; +import net.serble.estools.ServerApi.EsGameMode; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitConfigMigrator; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsEvent; +import net.serble.estools.ServerApi.Interfaces.EsLogger; +import net.serble.estools.ServerApi.Interfaces.EsServer; +import net.serble.estools.ServerApi.ServerPlatform; import net.serble.estools.Signs.SignMain; import org.bstats.bukkit.Metrics; import org.bstats.charts.SimplePie; -import org.bukkit.Bukkit; -import org.bukkit.command.PluginCommand; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.plugin.java.JavaPlugin; import net.serble.estools.Commands.*; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @SuppressWarnings("UnusedReturnValue") -public class Main extends JavaPlugin { +public class Main { public static Main plugin; - public static int majorVersion; - public static int minorVersion; + public static ServerPlatform platform; + public static SemanticVersion minecraftVersion; public static boolean tabCompleteEnabled = true; - private static FileConfiguration config; // Get with overriden getConfig() method - public static PluginVersion newVersion = null; // The version available to download + private static EsToolsConfig config; // Get with overriden getConfig() method + public static SemanticVersion newVersion = null; // The version available to download public static boolean newVersionReady = false; + public static EsServer server; + public static EsLogger logger; + private final Object context; + private static final List eventListeners = new ArrayList<>(); + private static final Map commands = new HashMap<>(); private static final int bStatsId = 21760; - - @Override - public void onEnable() { - plugin = this; - try { - Vault.setupEconomy(); - } catch (Exception e) { - Bukkit.getLogger().warning("No Vault plugin found, please install vault for economy functionality."); - } + public Main(ServerPlatform plat, Object context) { + platform = plat; + this.context = context; + } - getVersion(); // Set the major and minor version variables + public void enable() { + plugin = this; + server = platform.getServerInstance(context); + logger = server.getLogger(); - // Create config if not exists, saveDefaultConfig() doesn't exist in 1.0 - File configFile = new File(plugin.getDataFolder(), "config.yml"); - if (!configFile.exists()) { - saveResource("config.yml", false); - } - config = ConfigManager.load("config.yml"); + minecraftVersion = server.getVersion(); + server.initialise(); + logger.info("Starting EsTools on platform: " + platform.name() + " (MC: " + minecraftVersion.toString() + ")"); - // Add keys that don't exist from the default config - if (ConfigManager.patchDefaults(getConfig(), getResource("config.yml"))) { - ConfigManager.save("config.yml", getConfig()); // Only save if something changed + if (platform == ServerPlatform.Bukkit) { + // We have to support old configs + BukkitConfigMigrator.checkPerformMigration(); } + // Load the config + config = ConfigManager.load("config.yml", EsToolsConfig.class); + // Metrics - if (getConfig().getBoolean("metrics", true)) { - Metrics metrics = new Metrics(this, bStatsId); - metrics.addCustomChart(new SimplePie("vault_enabled", () -> String.valueOf(Vault.economy != null))); - Bukkit.getLogger().info("Started bStat metrics"); + if (config.isMetrics() && platform.supportsMetrics()) { + Metrics metrics = new Metrics(EsToolsBukkit.plugin, bStatsId); + metrics.addCustomChart(new SimplePie("vault_enabled", () -> "false")); + logger.info("Started bStat metrics"); } else { - Bukkit.getLogger().info("Metrics are disabled"); + logger.info("Metrics are disabled"); } - if (majorVersion <= 2) { - Bukkit.getLogger().info("Tab completion is not supported for versions 1.2 and below."); + if (minecraftVersion.getMinor() <= 2) { + logger.info("Tab completion is not supported for versions 1.2 and below."); tabCompleteEnabled = false; } // Commands - sc("gms", "gamemode.survival", new GameModeCommand("SURVIVAL")); - sc("gmc", "gamemode.creative", new GameModeCommand("CREATIVE")); - sc("gma", "gamemode.adventure", new GameModeCommand("ADVENTURE"), 3); - sc("gmsp", "gamemode.spectator", new GameModeCommand("SPECTATOR"), 8); + sc("gms", "gamemode.survival", new GameModeCommand(EsGameMode.Survival, "gms")); + sc("gmc", "gamemode.creative", new GameModeCommand(EsGameMode.Creative, "gmc")); + sc("gma", "gamemode.adventure", new GameModeCommand(EsGameMode.Adventure, "gma"), 3); + sc("gmsp", "gamemode.spectator", new GameModeCommand(EsGameMode.Spectator, "gmsp"), 8); sc("tphere", "tp", new TpHere()); sc("tpall", "tp", new TpAll()); sc("feed", "feed", new Feed()); @@ -94,7 +104,7 @@ public void onEnable() { sc("setstack", "setstack", new SetStack()); sc("ci", "clearinv", new ClearInv()); sc("day", "time", new Day()); - sc("moon", "time", new Night()); + sc("night", "time", new Night()); sc("noon", "time", new Noon()); sc("midnight", "time", new Midnight()); sc("sun", "weather", new Sun()); @@ -132,7 +142,7 @@ public void onEnable() { sc("buddha", "god", new Buddha(), 1); sc("music", "music", new Music(), 9); - sc("potion", "potion", new Potion(), 4); + sc("potion", "potion", new Potion()); sc("setpersistentdata", "setpersistentdata", new SetPersistentData(), 14); sc("getpersistentdata", "getpersistentdata", new GetPersistentData(), 14); @@ -145,139 +155,95 @@ public void onEnable() { sc("dismount", "mount", new Dismount()); // Load other features - if (majorVersion > 0) { // Enchants and events don't work on 1.0.0 + if (minecraftVersion.getMinor() > 0) { // Enchants and events don't work on 1.0.0 PowerTool.init(); SignMain.init(); } Give.enable(); Updater.checkForUpdate(); + + server.startEvents(); // Events will now trigger + } + + public static void callEvent(EsEvent event) { + for (EsEventListener listener : eventListeners) { + listener.executeEvent(event); + } } - @Override - public void onDisable() { /* Needed for older versions, which require an onDisable method */ } + public static boolean executeCommand(EsCommandSender sender, String cmd, String[] args) { + if (!commands.containsKey(cmd)) { + logger.severe("&cThe command: '" + cmd + "', does not exist"); + return false; + } + + return commands.get(cmd).execute(sender, args); + } + public static void registerEvents(EsEventListener listener) { + eventListeners.add(listener); + } // Setup Command Overloads - public PluginCommand sc(String name, EsToolsCommand ce) { - PluginCommand cmd = getCommand(name); - assert cmd != null; - cmd.setExecutor(ce); + public void sc(String name, EsToolsCommand ce) { + server.registerCommand(name, ce); + commands.put(name, ce); ce.onEnable(); - - if (tabCompleteEnabled && cmd.getTabCompleter() == null) { - ce.register(cmd); - } - return cmd; } - public PluginCommand sc(String name, EsToolsCommand ce, int minVer) { - if (Main.majorVersion >= minVer) return sc(name, ce); - else return sc(name, new WrongVersion(minVer)); + public void sc(String name, EsToolsCommand ce, int minVer) { + if (minecraftVersion.getMinor() >= minVer) { + sc(name, ce); + return; + } + sc(name, new WrongVersion(minVer)); } - public PluginCommand sc(String name, EsToolsCommand ce, EsToolsTabCompleter tc) { - PluginCommand cmd = sc(name, ce); + public void sc(String name, EsToolsCommand ce, EsToolsTabCompleter tc) { + sc(name, ce); if (tabCompleteEnabled) { - tc.register(cmd); + server.setTabCompleter(name, tc); } - return cmd; } - public PluginCommand sc(String name, String perm, EsToolsCommand ce, EsToolsTabCompleter tc, int minMajor, int minMinor) { + public void sc(String name, String perm, EsToolsCommand ce, EsToolsTabCompleter tc, int minMajor, int minMinor) { String versionName = minMajor + "." + minMinor; - if (Main.majorVersion > minMajor || (Main.majorVersion == minMajor && Main.minorVersion >= minMinor)) { + if (minecraftVersion.getMinor() > minMajor || (minecraftVersion.getMinor() == minMajor && minecraftVersion.getPatch() >= minMinor)) { if (tc == null) { - return sc(name, perm, ce); + sc(name, perm, ce); + return; } - return sc(name, perm, ce, tc); - } else return sc(name, new WrongVersion(versionName), new WrongVersion(versionName)); + sc(name, perm, ce, tc); + } else sc(name, new WrongVersion(versionName), new WrongVersion(versionName)); } - public PluginCommand sc(String name, String perm, EsToolsCommand ce) { - PluginCommand cmd = sc(name, ce); - cmd.setPermission("estools." + perm); - - if (Main.majorVersion > 0) { // Permission errors weren't a thing in 1.0 - //noinspection deprecation, is still useful in pre 1.13 and technically is useful in rare situations post 1.13 - cmd.setPermissionMessage(EsToolsCommand.translate("&cYou do not have permission to run this command.")); - } - - if (tabCompleteEnabled && cmd.getTabCompleter() == null) { // Give every command tab complete if they haven't already registered it - ce.register(cmd); - } - return cmd; + public void sc(String name, String perm, EsToolsCommand ce) { + sc(name, ce); + server.setCommandPermission(name, "estools." + perm); } - public PluginCommand sc(String name, String perm, EsToolsCommand ce, int minVer) { - if (Main.majorVersion >= minVer) return sc(name, perm, ce); - else return sc(name, perm, new WrongVersion(minVer)); + public void sc(String name, String perm, EsToolsCommand ce, int minVer) { + if (minecraftVersion.getMinor() >= minVer) sc(name, perm, ce); + else sc(name, perm, new WrongVersion(minVer)); } - public PluginCommand sc(String name, String perm, EsToolsCommand ce, EsToolsTabCompleter tc) { - PluginCommand cmd = sc(name, perm, ce); + public void sc(String name, String perm, EsToolsCommand ce, EsToolsTabCompleter tc) { + sc(name, perm, ce); if (tabCompleteEnabled) { - tc.register(cmd); + server.setTabCompleter(name, tc); } - return cmd; - } - - private void getVersion() { // Parse the minecraft version from the Bukkit version string - String versionS = Bukkit.getVersion(); - - if (versionS.contains("(MC: ")) { - int posOfMC = versionS.indexOf("(MC: ") + 5; - versionS = versionS.substring(posOfMC, versionS.indexOf(')', posOfMC)); - } else { - Bukkit.getLogger().warning("Could not detect version from: " + versionS); - return; - } - - for (int i = 0; i < 99; i++) { - if (versionS.contains("1." + i)) { - majorVersion = i; - } - } - - for (int i = 0; i < 99; i++) { - if (versionS.contains("1." + majorVersion + '.' + i)) { - minorVersion = i; - } - } - - Bukkit.getLogger().info("Version detected as: 1." + majorVersion + '.' + minorVersion + " from: " + versionS); } // Overriding to create more predictable behaviour between versions - @Override - public FileConfiguration getConfig() { + public EsToolsConfig getConfig() { return config; } - // Overriding because method doesn't exist in very early versions - public void saveResource(String res, boolean replace) { - InputStream resource = getResource(res); - File file = new File(getDataFolder(), res); - - if (file.exists()) { - Bukkit.getLogger().info("Tried to copy resource but it already exists: " + res); - return; - } - - try { - Files.createDirectories(file.getParentFile().toPath()); - asrt(resource != null); - Files.copy(resource, file.toPath()); - Bukkit.getLogger().info("Copied " + res + " to " + file.toPath()); - } catch (IOException e) { - e.printStackTrace(); - Bukkit.getLogger().severe("Failed to save resource: " + e); - } - } - - public static void asrt(boolean condition) { + @SuppressWarnings("unused") + public static void asrt(boolean condition) { asrt(condition, "Condition is false"); } @@ -285,12 +251,18 @@ public static void asrt(boolean condition) { public static void asrt(boolean condition, String msg) { assert condition : msg; - if (condition) { + // Asserts aren't enforced most of the time + //noinspection ConstantValue + if (condition) { return; } - Bukkit.getLogger().severe("Assertion failed: " + msg); + logger.severe("Assertion failed: " + msg); throw new AssertionError(msg); } + + public void saveConfig() { + ConfigManager.save("config.yml", config); + } } diff --git a/src/main/java/net/serble/estools/MetaHandler.java b/src/main/java/net/serble/estools/MetaHandler.java deleted file mode 100644 index d8ac910..0000000 --- a/src/main/java/net/serble/estools/MetaHandler.java +++ /dev/null @@ -1,79 +0,0 @@ -package net.serble.estools; - -import net.serble.estools.Commands.Potion; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.potion.PotionType; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -// This class exists because Minecraft < 1.4 doesn't have ItemMeta. It just encapsulates all ItemMeta methods. -public class MetaHandler { - - public static ItemStack getPotion(CommandSender sender, Potion.PotType potType, String effect, int duration, int amp, int amount) { - if (Main.majorVersion >= 9) { - String type = potType == Potion.PotType.drink ? - "POTION" : - potType.toString().toUpperCase() + "_POTION"; - ItemStack pot = new ItemStack(Material.valueOf(type), amount); - - PotionEffectType effType; - try { - effType = Effects.getByName(effect); - } catch (IllegalArgumentException e) { - EsToolsCommand.send(sender, "&cInvalid potion effect"); - return null; - } - - PotionMeta meta = (PotionMeta) pot.getItemMeta(); - assert meta != null; - meta.addCustomEffect(new PotionEffect(effType, duration, amp-1), true); - pot.setItemMeta(meta); - return pot; - } else if (Main.majorVersion >= 4) { - PotionType effType; - try { - effType = Effects.getPotionByName(effect); - } catch (IllegalArgumentException e) { - EsToolsCommand.send(sender, "&cInvalid potion effect"); - return null; - } - - @SuppressWarnings("deprecation") - org.bukkit.potion.Potion potion = new org.bukkit.potion.Potion(effType, amp); - potion.setSplash(potType == Potion.PotType.splash); - return potion.toItemStack(1); - } else { // This isn't possible to get to because this class won't load on 1.3 and below - EsToolsCommand.send(sender, "&cPotions are not yet supported in this version, they may be in the future."); - return null; - } - } - - public static void renameItem(ItemStack item, String name) { - ItemMeta meta = Objects.requireNonNull(item.getItemMeta()); - meta.setDisplayName(name); - item.setItemMeta(meta); - } - - public static List getLore(ItemStack item) { - ItemMeta meta = item.getItemMeta(); - if (meta == null || !meta.hasLore()) { - return new ArrayList<>(); - } - - return meta.getLore(); - } - - public static void setLore(ItemStack item, List lore) { - ItemMeta meta = Objects.requireNonNull(item.getItemMeta()); - meta.setLore(lore); - item.setItemMeta(meta); - } -} diff --git a/src/main/java/net/serble/estools/MultiPlayerCommand.java b/src/main/java/net/serble/estools/MultiPlayerCommand.java index 0e40e23..3f69b3b 100644 --- a/src/main/java/net/serble/estools/MultiPlayerCommand.java +++ b/src/main/java/net/serble/estools/MultiPlayerCommand.java @@ -1,8 +1,7 @@ package net.serble.estools; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.ArrayList; import java.util.List; @@ -10,10 +9,10 @@ public abstract class MultiPlayerCommand extends EsToolsCommand { @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); - for (Player p : getOnlinePlayers()) { + for (EsPlayer p : Main.server.getOnlinePlayers()) { tab.add(p.getName()); } @@ -22,19 +21,19 @@ public List tabComplete(CommandSender sender, String[] args, String lArg return tab; } - public static ArrayList getPlayers(CommandSender sender, String[] names) { + public static ArrayList getPlayers(EsCommandSender sender, String[] names) { if (names.length == 0) { return new ArrayList<>(); } if (names[0].equals("*")) { - return new ArrayList<>(getOnlinePlayers()); + return new ArrayList<>(Main.server.getOnlinePlayers()); } - ArrayList players = new ArrayList<>(); + ArrayList players = new ArrayList<>(); for (String name : names) { - Player p = Bukkit.getPlayer(name); + EsPlayer p = Main.server.getPlayer(name); if (p == null) { send(sender, "&cPlayer &6%s&c not found.", name); @@ -46,14 +45,14 @@ public static ArrayList getPlayers(CommandSender sender, String[] names) return players; } - public static ArrayList getPlayers(CommandSender sender, String name) { + public static ArrayList getPlayers(EsCommandSender sender, String name) { if (name.equals("*")) { - return new ArrayList<>(getOnlinePlayers()); + return new ArrayList<>(Main.server.getOnlinePlayers()); } - ArrayList players = new ArrayList<>(); + ArrayList players = new ArrayList<>(); - Player p = Bukkit.getPlayer(name); + EsPlayer p = Main.server.getPlayer(name); if (p == null) { send(sender, "&cPlayer &6%s&c not found.", name); diff --git a/src/main/java/net/serble/estools/PlayerCommand.java b/src/main/java/net/serble/estools/PlayerCommand.java index c7b3480..f557cd1 100644 --- a/src/main/java/net/serble/estools/PlayerCommand.java +++ b/src/main/java/net/serble/estools/PlayerCommand.java @@ -1,7 +1,7 @@ package net.serble.estools; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; import java.util.ArrayList; import java.util.List; @@ -9,10 +9,10 @@ public abstract class PlayerCommand extends EsToolsCommand { @Override - public List tabComplete(CommandSender sender, String[] args, String lArg) { + public List tabComplete(EsCommandSender sender, String[] args, String lArg) { List tab = new ArrayList<>(); - for (Player p : getOnlinePlayers()) { + for (EsPlayer p : Main.server.getOnlinePlayers()) { tab.add(p.getName()); } diff --git a/src/main/java/net/serble/estools/PluginVersion.java b/src/main/java/net/serble/estools/PluginVersion.java deleted file mode 100644 index 31d3537..0000000 --- a/src/main/java/net/serble/estools/PluginVersion.java +++ /dev/null @@ -1,48 +0,0 @@ -package net.serble.estools; - -public class PluginVersion { - private final int major; - private final int minor; - private final int patch; - private final String string; - - public PluginVersion(String str) { - String[] parts = str.split("\\."); - major = Integer.parseInt(parts[0]); - minor = Integer.parseInt(parts[1]); - patch = Integer.parseInt(parts[2]); - string = str; - } - - public int getMajor() { - return major; - } - - public int getMinor() { - return minor; - } - - public int getPatch() { - return patch; - } - - public String getString() { - return string; - } - - public boolean isLowerThan(PluginVersion other) { - if (getMajor() < other.getMajor()) { - return true; - } else if (getMajor() > other.getMajor()) { - return false; - } - - if (getMinor() < other.getMinor()) { - return true; - } else if (getMinor() > other.getMinor()) { - return false; - } - - return getPatch() < other.getPatch(); - } -} diff --git a/src/main/java/net/serble/estools/SemanticVersion.java b/src/main/java/net/serble/estools/SemanticVersion.java new file mode 100644 index 0000000..ff86a76 --- /dev/null +++ b/src/main/java/net/serble/estools/SemanticVersion.java @@ -0,0 +1,101 @@ +package net.serble.estools; + +@SuppressWarnings("unused") // Future-proof, it's a util class why not +public class SemanticVersion { + private final int major; + private final int minor; + private final int patch; + private final String string; + + public SemanticVersion(String str) { + String[] parts = str.split("\\."); + major = Integer.parseInt(parts[0]); + minor = Integer.parseInt(parts[1]); + patch = Integer.parseInt(parts[2]); + string = str; + } + + public SemanticVersion(int major, int minor, int patch) { + this.major = major; + this.minor = minor; + this.patch = patch; + string = major + "." + minor + "." + patch; + } + + public int getMajor() { + return major; + } + + public int getMinor() { + return minor; + } + + public int getPatch() { + return patch; + } + + @Override + public String toString() { + return string; + } + + public boolean isLowerThan(SemanticVersion other) { + return isLowerThan(other.major, other.minor, other.patch); + } + + public boolean isLowerThan(int major, int minor, int patch) { + if (getMajor() < major) { + return true; + } else if (getMajor() > major) { + return false; + } + + if (getMinor() < minor) { + return true; + } else if (getMinor() > minor) { + return false; + } + + return getPatch() < patch; + } + + public boolean isAtLeast(SemanticVersion other) { + return isAtLeast(other.major, other.minor, other.patch); + } + + public boolean isAtLeast(int major, int minor, int patch) { + if (getMajor() < major) { + return false; + } else if (getMajor() > major) { + return true; + } + + if (getMinor() < minor) { + return false; + } else if (getMinor() > minor) { + return true; + } + + return getPatch() >= patch; + } + + public boolean isMoreThan(int major, int minor, int patch) { + if (getMajor() > major) { + return true; + } else if (getMajor() < major) { + return false; + } + + if (getMinor() > minor) { + return true; + } else if (getMinor() < minor) { + return false; + } + + return getPatch() > patch; + } + + public boolean isMoreThan(SemanticVersion other) { + return isMoreThan(other.major, other.minor, other.patch); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsAction.java b/src/main/java/net/serble/estools/ServerApi/EsAction.java new file mode 100644 index 0000000..fcec21a --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsAction.java @@ -0,0 +1,32 @@ +package net.serble.estools.ServerApi; + +public enum EsAction { + /** + * Left-clicking a block + */ + LeftClickBlock, + /** + * Right-clicking a block + */ + RightClickBlock, + /** + * Left-clicking the air + */ + LeftClickAir, + /** + * Right-clicking the air + */ + RightClickAir, + /** + * Stepping onto or into a block (Ass-pressure) + *

+ * Examples: + *

    + *
  • Jumping on soil + *
  • Standing on pressure plate + *
  • Triggering redstone ore + *
  • Triggering tripwire + *
+ */ + Physical +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsClickType.java b/src/main/java/net/serble/estools/ServerApi/EsClickType.java new file mode 100644 index 0000000..6f048d7 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsClickType.java @@ -0,0 +1,129 @@ +package net.serble.estools.ServerApi; + +import org.jetbrains.annotations.ApiStatus; + +/** + * How the action was triggered, not what it did, see {@link net.serble.estools.ServerApi.EsInventoryAction} + * for the action. + */ +public enum EsClickType { + + /** + * The left (or primary) mouse button. + */ + Left, + /** + * Holding shift while pressing the left mouse button. + */ + ShiftLeft, + /** + * The right mouse button. + */ + Right, + /** + * Holding shift while pressing the right mouse button. + */ + ShiftRight, + /** + * Clicking the left mouse button on the grey area around the inventory. + */ + WindowBorderLeft, + /** + * Clicking the right mouse button on the grey area around the inventory. + */ + WindowBorderRight, + /** + * The middle mouse button, or a "scrollwheel click". + */ + Middle, + /** + * One of the number keys 1-9, correspond to slots on the hotbar. + */ + NumberKey, + /** + * Pressing the left mouse button twice in quick succession. + */ + DoubleClick, + /** + * The "Drop" key (defaults to Q). + */ + Drop, + /** + * Holding Ctrl while pressing the "Drop" key (defaults to Q). + */ + ControlDrop, + /** + * Any action done with the Creative inventory open. + */ + Creative, + /** + * The "swap item with offhand" key (defaults to F). + */ + SwapOffhand, + /** + * Should only be called if the implementation is not updated for a Minecraft version. + * Getting this value is a sign of a bug. + */ + @ApiStatus.Experimental + Unknown, + ; + + /** + * Gets whether this ClickType represents the pressing of a key on a + * keyboard. + * + * @return true if this ClickType represents the pressing of a key + */ + public boolean isKeyboardClick() { + return (this == EsClickType.NumberKey) || (this == EsClickType.Drop) || (this == EsClickType.ControlDrop) || (this == EsClickType.SwapOffhand); + } + + /** + * Gets whether this ClickType represents the pressing of a mouse button + * + * @return true if this ClickType represents the pressing of a mouse button + */ + public boolean isMouseClick() { + return (this == EsClickType.DoubleClick) || (this == EsClickType.Left) || (this == EsClickType.Right) || (this == EsClickType.Middle) + || (this == EsClickType.WindowBorderLeft) || (this == EsClickType.ShiftLeft) || (this == EsClickType.ShiftRight) || (this == EsClickType.WindowBorderRight); + } + + /** + * Gets whether this ClickType represents an action that can only be + * performed by a Player in creative mode. + * + * @return true if this action requires Creative mode + */ + public boolean isCreativeAction() { + // Why use middle click? + return (this == EsClickType.Middle) || (this == EsClickType.Creative); + } + + /** + * Gets whether this ClickType represents a right click. + * + * @return true if this ClickType represents a right click + */ + public boolean isRightClick() { + return (this == EsClickType.Right) || (this == EsClickType.ShiftRight); + } + + /** + * Gets whether this ClickType represents a left click. + * + * @return true if this ClickType represents a left click + */ + public boolean isLeftClick() { + return (this == EsClickType.Left) || (this == EsClickType.ShiftLeft) || (this == EsClickType.DoubleClick) || (this == EsClickType.Creative); + } + + /** + * Gets whether this ClickType indicates that the shift key was pressed + * down when the click was made. + * + * @return true if the action uses Shift. + */ + public boolean isShiftClick() { + return (this == EsClickType.ShiftLeft) || (this == EsClickType.ShiftRight); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsEnchantment.java b/src/main/java/net/serble/estools/ServerApi/EsEnchantment.java new file mode 100644 index 0000000..e7b5743 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsEnchantment.java @@ -0,0 +1,54 @@ +package net.serble.estools.ServerApi; + +import net.serble.estools.Main; +import net.serble.estools.Utils; +import org.jetbrains.annotations.Nullable; + +public class EsEnchantment { + private String key; + + public static EsEnchantment createUnchecked(String key) { + EsEnchantment type = new EsEnchantment(); + type.key = key.toLowerCase(); + + return type; + } + + public static @Nullable EsEnchantment fromKey(String key) { + EsEnchantment type = EsEnchantment.createUnchecked(key); + + if (Main.server.getEnchantments().contains(type)) { + return type; + } + + return null; + } + + public String getKey() { + return key; + } + + /** This exists for YAML serialisation only, DO NOT USE, use EsSound.fromKey(String) instead. */ + public void setKey(String key) { + this.key = key; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof EsEnchantment) { + return ((EsEnchantment) obj).getKey().equals(key); + } + + return false; + } + + @Override + public int hashCode() { + return key.hashCode(); + } + + @Override + public String toString() { + return Utils.keyToDisplayName(key); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsEquipmentSlot.java b/src/main/java/net/serble/estools/ServerApi/EsEquipmentSlot.java new file mode 100644 index 0000000..46492a7 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsEquipmentSlot.java @@ -0,0 +1,10 @@ +package net.serble.estools.ServerApi; + +public enum EsEquipmentSlot { + Hand, + OffHand, + Feet, + Legs, + Chest, + Head +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsEventListener.java b/src/main/java/net/serble/estools/ServerApi/EsEventListener.java new file mode 100644 index 0000000..7cb0793 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsEventListener.java @@ -0,0 +1,7 @@ +package net.serble.estools.ServerApi; + +import net.serble.estools.ServerApi.Interfaces.EsEvent; + +public interface EsEventListener { + void executeEvent(EsEvent event); +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsEventResult.java b/src/main/java/net/serble/estools/ServerApi/EsEventResult.java new file mode 100644 index 0000000..5c9e797 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsEventResult.java @@ -0,0 +1,7 @@ +package net.serble.estools.ServerApi; + +public enum EsEventResult { + DENY, + DEFAULT, + ALLOW +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsGameMode.java b/src/main/java/net/serble/estools/ServerApi/EsGameMode.java new file mode 100644 index 0000000..8a5bae2 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsGameMode.java @@ -0,0 +1,18 @@ +package net.serble.estools.ServerApi; + +public enum EsGameMode { + Survival(0), + Creative(1), + Adventure(2), + Spectator(3); + + private final int ordinal; + + EsGameMode(int val) { + ordinal = val; + } + + public int getOrdinal() { + return ordinal; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsInventoryAction.java b/src/main/java/net/serble/estools/ServerApi/EsInventoryAction.java new file mode 100644 index 0000000..7450df0 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsInventoryAction.java @@ -0,0 +1,88 @@ +package net.serble.estools.ServerApi; + +/** + * The action that was triggered by the player's input + */ +public enum EsInventoryAction { + /** + * Nothing happened, I'm not sure why you would ever call the event for this, but it's here. + */ + Nothing, + /** + * All the items on the clicked slot are moved to the cursor. + */ + PickupAll, + /** + * Some of the items on the clicked slot are moved to the cursor. + */ + PickupSome, + /** + * Half of the items on the clicked slot are moved to the cursor. + */ + PickupHalf, + /** + * One of the items on the clicked slot are moved to the cursor. + */ + PickupOne, + /** + * All the items on the cursor are moved to the clicked slot. + */ + PlaceAll, + /** + * Some of the items from the cursor are moved to the clicked slot + * (usually up to the max stack size). + */ + PlaceSome, + /** + * A single item from the cursor is moved to the clicked slot. + */ + PlaceOne, + /** + * The clicked item and the cursor are exchanged. + */ + SwapWithCursor, + /** + * The entire cursor item is dropped. + */ + DropAllCursor, + /** + * One item is dropped from the cursor. + */ + DropOneCursor, + /** + * The entire clicked slot is dropped. + */ + DropAllSlot, + /** + * One item is dropped from the clicked slot. + */ + DropOneSlot, + /** + * The item is moved to the opposite inventory if a space is found. + */ + MoveToOtherInventory, + /** + * The clicked item is moved to the hotbar, and the item currently there + * is re-added to the player's inventory. + * The hotbar includes the player's offhand. + */ + HotbarMoveAndReadd, + /** + * The clicked slot and the picked hotbar slot are swapped. + * The hotbar includes the player's offhand. + */ + HotbarSwap, + /** + * A max-size stack of the clicked item is put on the cursor. + */ + CloneStack, + /** + * The inventory is searched for the same material, and they are put on + * the cursor up to the max stack size. + */ + CollectToCursor, + /** + * An unrecognized ClickType. + */ + Unknown +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsItemFlag.java b/src/main/java/net/serble/estools/ServerApi/EsItemFlag.java new file mode 100644 index 0000000..5e5cc56 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsItemFlag.java @@ -0,0 +1,37 @@ +package net.serble.estools.ServerApi; + +public enum EsItemFlag { + /** + * Setting to show/hide enchants + */ + HIDE_ENCHANTS, + /** + * Setting to show/hide Attributes like Damage + */ + HIDE_ATTRIBUTES, + /** + * Setting to show/hide the unbreakable State + */ + HIDE_UNBREAKABLE, + /** + * Setting to show/hide what the ItemStack can break/destroy + */ + HIDE_DESTROYS, + /** + * Setting to show/hide where this ItemStack can be build/placed on + */ + HIDE_PLACED_ON, + /** + * Setting to show/hide potion effects, book and firework information, map + * tooltips, patterns of banners, and enchantments of enchanted books. + */ + HIDE_POTION_EFFECTS, + /** + * Setting to show/hide dyes from colored leather armor. + */ + HIDE_DYE, + /** + * Setting to show/hide armor trim from leather armor. + */ + HIDE_ARMOR_TRIM; +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsLocation.java b/src/main/java/net/serble/estools/ServerApi/EsLocation.java new file mode 100644 index 0000000..8fb42e4 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsLocation.java @@ -0,0 +1,105 @@ +package net.serble.estools.ServerApi; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.Interfaces.EsWorld; + +@SuppressWarnings("unused") // SnakeYAML needs the setters +public class EsLocation extends Position { + private EsWorld world; + private String worldName; + private Position direction; + private double yaw; + private double pitch; + + public EsLocation(EsWorld world, double x, double y, double z) { + this.world = world; + this.worldName = world.getName(); + setX(x); + setY(y); + setZ(z); + } + + public EsLocation(EsWorld world, Position dir, double x, double y, double z) { + this.world = world; + this.worldName = world.getName(); + direction = dir; + setX(x); + setY(y); + setZ(z); + } + + public EsLocation(EsWorld world, Position dir, double x, double y, double z, double yaw, double pitch) { + this.world = world; + this.worldName = world.getName(); + direction = dir; + this.yaw = yaw; + this.pitch = pitch; + setX(x); + setY(y); + setZ(z); + } + + /** You probably shouldn't use this, it's here for SnakeYAML */ + public EsLocation() { } + + public EsWorld getWorld() { + return world; + } + + public String getWorldName() { + return worldName; + } + + public void setWorldName(String worldName) { // Sets world based on name, for SnakeYAML to correctly use locations + this.worldName = worldName; + world = Main.server.getWorld(worldName); + } + + public double distanceTo(EsLocation other) { + return super.distanceTo(other); + } + + public Position getDirection() { + return direction; + } + + public void setDirection(Position direction) { + this.direction = direction; + } + + public double getPitch() { + return pitch; + } + + public double getYaw() { + return yaw; + } + + public void setPitch(double pitch) { + this.pitch = pitch; + } + + public void setYaw(double yaw) { + this.yaw = yaw; + } + + public int getBlockX() { + return (int) Math.round(getX()); + } + + public int getBlockY() { + return (int) Math.round(getY()); + } + + public int getBlockZ() { + return (int) Math.round(getZ()); + } + + public EsLocation add(Position other) { + return add(other.getX(), other.getY(), other.getZ()); + } + + public EsLocation add(double x, double y, double z) { + return new EsLocation(world, getX() + x, getY() + y, getZ() + z); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsMaterial.java b/src/main/java/net/serble/estools/ServerApi/EsMaterial.java new file mode 100644 index 0000000..9f6c153 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsMaterial.java @@ -0,0 +1,54 @@ +package net.serble.estools.ServerApi; + +import net.serble.estools.Main; +import net.serble.estools.Utils; +import org.jetbrains.annotations.Nullable; + +public class EsMaterial { + private String key; + + public static EsMaterial createUnchecked(String key) { + EsMaterial type = new EsMaterial(); + type.key = key.toLowerCase(); + + return type; + } + + public static @Nullable EsMaterial fromKey(String key) { + EsMaterial type = EsMaterial.createUnchecked(key); + + if (Main.server.getMaterials(false).contains(type)) { + return type; + } + + return null; + } + + public String getKey() { + return key; + } + + /** This exists for YAML serialisation only, DO NOT USE, use EsMaterial.fromKey(String) instead. */ + public void setKey(String key) { + this.key = key; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof EsMaterial) { + return ((EsMaterial) obj).getKey().equals(key); + } + + return false; + } + + @Override + public int hashCode() { + return key.hashCode(); + } + + @Override + public String toString() { + return Utils.keyToDisplayName(key); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsPersistentDataType.java b/src/main/java/net/serble/estools/ServerApi/EsPersistentDataType.java new file mode 100644 index 0000000..286ad77 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsPersistentDataType.java @@ -0,0 +1,15 @@ +package net.serble.estools.ServerApi; + +public enum EsPersistentDataType { + String, + Boolean, + Integer, + Byte, + Float, + Double, + Short, + Long, + ByteArray, + IntArray, + LongArray +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsPotType.java b/src/main/java/net/serble/estools/ServerApi/EsPotType.java new file mode 100644 index 0000000..b6e9de8 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsPotType.java @@ -0,0 +1,7 @@ +package net.serble.estools.ServerApi; + +public enum EsPotType { + drink, + lingering, + splash +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsPotionEffect.java b/src/main/java/net/serble/estools/ServerApi/EsPotionEffect.java new file mode 100644 index 0000000..7a079a2 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsPotionEffect.java @@ -0,0 +1,42 @@ +package net.serble.estools.ServerApi; + +@SuppressWarnings("unused") // Needs the methods for serialiser +public class EsPotionEffect { + private EsPotionEffectType type; + private int amp; + private int duration; + + public EsPotionEffect(EsPotionEffectType type, int amp, int duration) { + this.type = type; + this.amp = amp; + this.duration = duration; + } + + public EsPotionEffect() { // Serialiser needs this + + } + + public int getAmp() { + return amp; + } + + public int getDuration() { + return duration; + } + + public EsPotionEffectType getType() { + return type; + } + + public void setAmp(int amp) { + this.amp = amp; + } + + public void setDuration(int duration) { + this.duration = duration; + } + + public void setType(EsPotionEffectType type) { + this.type = type; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsPotionEffectType.java b/src/main/java/net/serble/estools/ServerApi/EsPotionEffectType.java new file mode 100644 index 0000000..33519ed --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsPotionEffectType.java @@ -0,0 +1,54 @@ +package net.serble.estools.ServerApi; + +import net.serble.estools.Main; +import net.serble.estools.Utils; +import org.jetbrains.annotations.Nullable; + +public class EsPotionEffectType { + private String key; + + public static EsPotionEffectType createUnchecked(String key) { + EsPotionEffectType type = new EsPotionEffectType(); + type.key = key.toLowerCase(); + + return type; + } + + public static @Nullable EsPotionEffectType fromKey(String key) { + EsPotionEffectType type = EsPotionEffectType.createUnchecked(key); + + if (Main.server.getPotionEffectTypes().contains(type)) { + return type; + } + + return null; + } + + public String getKey() { + return key; + } + + /** This exists for YAML serialisation only, DO NOT USE, use EsPotionEffectType.fromKey(String) instead. */ + public void setKey(String key) { + this.key = key; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof EsPotionEffectType) { + return ((EsPotionEffectType) obj).getKey().equals(key); + } + + return false; + } + + @Override + public int hashCode() { + return key.hashCode(); + } + + @Override + public String toString() { + return Utils.keyToDisplayName(key); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsSerialisableItemStack.java b/src/main/java/net/serble/estools/ServerApi/EsSerialisableItemStack.java new file mode 100644 index 0000000..d5f80de --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsSerialisableItemStack.java @@ -0,0 +1,99 @@ +package net.serble.estools.ServerApi; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPotion; + +import java.util.Map; + +/** + * This class is entirely platform independent and replies on the ability to export ItemMeta is a string. + */ +@SuppressWarnings("unused") // Needs the methods for YAML serialiser +public class EsSerialisableItemStack { + private EsMaterial material; + private int amount; + private String itemMeta; + private Map enchantments; + private boolean isPotion; + private EsPotType potType; + + /** Public constructor for serialiser */ + public EsSerialisableItemStack() { } + + public static EsSerialisableItemStack generate(EsItemStack stack) { + EsSerialisableItemStack result = new EsSerialisableItemStack(); + result.setMaterial(stack.getType()); + result.setAmount(stack.getAmount()); + result.setEnchantments(stack.getEnchantments()); + result.setItemMeta(stack.exportItemMeta()); + + if (stack instanceof EsPotion) { + EsPotion pot = (EsPotion) stack; + result.setPotType(pot.getPotionType()); + result.setIsPotion(true); + } else { + result.setIsPotion(false); + } + + return result; + } + + public EsItemStack toItemStack() { + EsItemStack stack = isPotion ? + Main.server.createPotion(potType) : + Main.server.createItemStack(material, 1); + + stack.setAmount(amount); + stack.importItemMeta(itemMeta); + return stack; + } + + public int getAmount() { + return amount; + } + + public EsMaterial getMaterial() { + return material; + } + + public void setAmount(int amount) { + this.amount = amount; + } + + public void setMaterial(EsMaterial material) { + this.material = material; + } + + public Map getEnchantments() { + return enchantments; + } + + public void setEnchantments(Map enchantments) { + this.enchantments = enchantments; + } + + public String getItemMeta() { + return itemMeta; + } + + public void setItemMeta(String itemMeta) { + this.itemMeta = itemMeta; + } + + public boolean getIsPotion() { + return isPotion; + } + + public void setIsPotion(boolean isPotion) { + this.isPotion = isPotion; + } + + public EsPotType getPotType() { + return potType; + } + + public void setPotType(EsPotType potType) { + this.potType = potType; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsSound.java b/src/main/java/net/serble/estools/ServerApi/EsSound.java new file mode 100644 index 0000000..136a0a3 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsSound.java @@ -0,0 +1,54 @@ +package net.serble.estools.ServerApi; + +import net.serble.estools.Main; +import net.serble.estools.Utils; +import org.jetbrains.annotations.Nullable; + +public class EsSound { + private String key; + + public static EsSound createUnchecked(String key) { + EsSound type = new EsSound(); + type.key = key.toLowerCase(); + + return type; + } + + public static @Nullable EsSound fromKey(String key) { + EsSound type = EsSound.createUnchecked(key); + + if (Main.server.getSounds().contains(type)) { + return type; + } + + return null; + } + + public String getKey() { + return key; + } + + /** This exists for YAML serialisation only, DO NOT USE, use EsSound.fromKey(String) instead. */ + public void setKey(String key) { + this.key = key; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof EsSound) { + return ((EsSound) obj).getKey().equals(key); + } + + return false; + } + + @Override + public int hashCode() { + return key.hashCode(); + } + + @Override + public String toString() { + return Utils.keyToDisplayName(key); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsSoundCategory.java b/src/main/java/net/serble/estools/ServerApi/EsSoundCategory.java new file mode 100644 index 0000000..cafc14e --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsSoundCategory.java @@ -0,0 +1,14 @@ +package net.serble.estools.ServerApi; + +public enum EsSoundCategory { + Master, + Music, + Records, + Weather, + Blocks, + Hostile, + Neutral, + Players, + Ambient, + Voice +} diff --git a/src/main/java/net/serble/estools/ServerApi/EsTeleportCause.java b/src/main/java/net/serble/estools/ServerApi/EsTeleportCause.java new file mode 100644 index 0000000..875268b --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/EsTeleportCause.java @@ -0,0 +1,15 @@ +package net.serble.estools.ServerApi; + +public enum EsTeleportCause { + EnderPearl, + Command, + Plugin, + NetherPortal, + EndPortal, + Spectate, + EndGateway, + ChorusFruit, + Dismount, + ExitBed, + Unknown +} diff --git a/src/main/java/net/serble/estools/ServerApi/Events/EsBlockPlaceEvent.java b/src/main/java/net/serble/estools/ServerApi/Events/EsBlockPlaceEvent.java new file mode 100644 index 0000000..0a35056 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Events/EsBlockPlaceEvent.java @@ -0,0 +1,30 @@ +package net.serble.estools.ServerApi.Events; + +import net.serble.estools.ServerApi.EsEquipmentSlot; +import net.serble.estools.ServerApi.Interfaces.EsCancellableEvent; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; + +public class EsBlockPlaceEvent extends EsCancellableEvent { + private final EsPlayer player; + private final EsItemStack placedItem; + private final EsEquipmentSlot hand; + + public EsBlockPlaceEvent(EsPlayer p, EsItemStack item, EsEquipmentSlot ha) { + player = p; + placedItem = item; + hand = ha; + } + + public EsPlayer getPlayer() { + return player; + } + + public EsItemStack getPlacedItem() { + return placedItem; + } + + public EsEquipmentSlot getHand() { + return hand; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Events/EsEntityDamageEvent.java b/src/main/java/net/serble/estools/ServerApi/Events/EsEntityDamageEvent.java new file mode 100644 index 0000000..0db45e9 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Events/EsEntityDamageEvent.java @@ -0,0 +1,26 @@ +package net.serble.estools.ServerApi.Events; + +import net.serble.estools.ServerApi.Interfaces.EsCancellableEvent; +import net.serble.estools.ServerApi.Interfaces.EsEntity; + +public class EsEntityDamageEvent extends EsCancellableEvent { + private final EsEntity entity; + private double damage; + + public EsEntityDamageEvent(EsEntity entity, double dmg) { + this.entity = entity; + damage = dmg; + } + + public EsEntity getEntity() { + return entity; + } + + public double getDamage() { + return damage; + } + + public void setDamage(double damage) { + this.damage = damage; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Events/EsInventoryClickEvent.java b/src/main/java/net/serble/estools/ServerApi/Events/EsInventoryClickEvent.java new file mode 100644 index 0000000..02f662b --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Events/EsInventoryClickEvent.java @@ -0,0 +1,62 @@ +package net.serble.estools.ServerApi.Events; + +import net.serble.estools.ServerApi.EsClickType; +import net.serble.estools.ServerApi.EsInventoryAction; +import net.serble.estools.ServerApi.Interfaces.EsCancellableEvent; +import net.serble.estools.ServerApi.Interfaces.EsInventory; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; + +public class EsInventoryClickEvent extends EsCancellableEvent { + private final EsInventory clickedInv; + private final EsInventory inv; + private final EsItemStack currentItem; + private final EsInventoryAction action; + private final EsClickType click; + private final EsPlayer player; + private final EsItemStack cursor; + private final int slot; + + public EsInventoryClickEvent(EsPlayer player, int slot, EsItemStack cursor, EsInventory inv, EsInventory clickedInv, EsItemStack currentItem, EsInventoryAction action, EsClickType click) { + this.clickedInv = clickedInv; + this.inv = inv; + this.currentItem = currentItem; + this.action = action; + this.click = click; + this.player = player; + this.cursor = cursor; + this.slot = slot; + } + + public EsInventory getClickedInventory() { + return clickedInv; + } + + public EsItemStack getCurrentItem() { + return currentItem; + } + + public EsInventoryAction getAction() { + return action; + } + + public EsClickType getClick() { + return click; + } + + public EsPlayer getPlayer() { + return player; + } + + public EsInventory getInventory() { + return inv; + } + + public EsItemStack getCursor() { + return cursor; + } + + public int getSlot() { + return slot; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Events/EsInventoryCloseEvent.java b/src/main/java/net/serble/estools/ServerApi/Events/EsInventoryCloseEvent.java new file mode 100644 index 0000000..710dae0 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Events/EsInventoryCloseEvent.java @@ -0,0 +1,23 @@ +package net.serble.estools.ServerApi.Events; + +import net.serble.estools.ServerApi.Interfaces.EsEvent; +import net.serble.estools.ServerApi.Interfaces.EsInventory; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; + +public class EsInventoryCloseEvent implements EsEvent { + private final EsPlayer player; + private final EsInventory inv; + + public EsInventoryCloseEvent(EsPlayer player, EsInventory inv) { + this.player = player; + this.inv = inv; + } + + public EsPlayer getPlayer() { + return player; + } + + public EsInventory getInventory() { + return inv; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Events/EsInventoryDragEvent.java b/src/main/java/net/serble/estools/ServerApi/Events/EsInventoryDragEvent.java new file mode 100644 index 0000000..a126ac2 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Events/EsInventoryDragEvent.java @@ -0,0 +1,38 @@ +package net.serble.estools.ServerApi.Events; + +import net.serble.estools.ServerApi.Interfaces.EsCancellableEvent; +import net.serble.estools.ServerApi.Interfaces.EsInventory; +import net.serble.estools.ServerApi.Interfaces.EsInventoryView; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; + +import java.util.Set; + +public class EsInventoryDragEvent extends EsCancellableEvent { + private final EsPlayer player; + private final EsInventory inv; + private final Set changedSlots; + private final EsInventoryView view; + + public EsInventoryDragEvent(EsPlayer player, EsInventory inv, Set changedSlots, EsInventoryView view) { + this.player = player; + this.inv = inv; + this.changedSlots = changedSlots; + this.view = view; + } + + public EsPlayer getPlayer() { + return player; + } + + public EsInventory getInventory() { + return inv; + } + + public Set getChangedSlots() { + return changedSlots; + } + + public EsInventoryView getView() { + return view; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerDeathEvent.java b/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerDeathEvent.java new file mode 100644 index 0000000..6dd6b09 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerDeathEvent.java @@ -0,0 +1,16 @@ +package net.serble.estools.ServerApi.Events; + +import net.serble.estools.ServerApi.Interfaces.EsEvent; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; + +public class EsPlayerDeathEvent implements EsEvent { + private final EsPlayer player; + + public EsPlayerDeathEvent(EsPlayer p) { + player = p; + } + + public EsPlayer getPlayer() { + return player; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerInteractEvent.java b/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerInteractEvent.java new file mode 100644 index 0000000..796ac4a --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerInteractEvent.java @@ -0,0 +1,50 @@ +package net.serble.estools.ServerApi.Events; + +import net.serble.estools.ServerApi.EsAction; +import net.serble.estools.ServerApi.EsEventResult; +import net.serble.estools.ServerApi.Interfaces.EsBlock; +import net.serble.estools.ServerApi.Interfaces.EsEvent; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import org.jetbrains.annotations.Nullable; + +public class EsPlayerInteractEvent implements EsEvent { + private final EsPlayer player; + private final @Nullable EsBlock clickedBlock; + private final EsAction action; + private EsEventResult useInteractedBlock; + private EsEventResult useItemInHand; + + public EsPlayerInteractEvent(EsPlayer player, @Nullable EsBlock clickedBlock, EsAction action) { + this.player = player; + this.clickedBlock = clickedBlock; + this.action = action; + } + + public EsPlayer getPlayer() { + return player; + } + + public EsAction getAction() { + return action; + } + + public @Nullable EsBlock getClickedBlock() { + return clickedBlock; + } + + public EsEventResult getUseItemInHand() { + return useItemInHand; + } + + public void setUseItemInHand(EsEventResult useItemInHand) { + this.useItemInHand = useItemInHand; + } + + public EsEventResult getUseInteractedBlock() { + return useInteractedBlock; + } + + public void setUseInteractedBlock(EsEventResult useInteractedBlock) { + this.useInteractedBlock = useInteractedBlock; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerKickEvent.java b/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerKickEvent.java new file mode 100644 index 0000000..5e957a0 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerKickEvent.java @@ -0,0 +1,16 @@ +package net.serble.estools.ServerApi.Events; + +import net.serble.estools.ServerApi.Interfaces.EsEvent; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; + +public class EsPlayerKickEvent implements EsEvent { + private final EsPlayer player; + + public EsPlayerKickEvent(EsPlayer player) { + this.player = player; + } + + public EsPlayer getPlayer() { + return player; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerQuitEvent.java b/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerQuitEvent.java new file mode 100644 index 0000000..a588eb6 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerQuitEvent.java @@ -0,0 +1,16 @@ +package net.serble.estools.ServerApi.Events; + +import net.serble.estools.ServerApi.Interfaces.EsEvent; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; + +public class EsPlayerQuitEvent implements EsEvent { + private final EsPlayer player; + + public EsPlayerQuitEvent(EsPlayer player) { + this.player = player; + } + + public EsPlayer getPlayer() { + return player; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerTeleportEvent.java b/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerTeleportEvent.java new file mode 100644 index 0000000..7fe9bcb --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Events/EsPlayerTeleportEvent.java @@ -0,0 +1,26 @@ +package net.serble.estools.ServerApi.Events; + +import net.serble.estools.ServerApi.EsLocation; +import net.serble.estools.ServerApi.EsTeleportCause; +import net.serble.estools.ServerApi.Interfaces.EsCancellableEvent; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; + +public class EsPlayerTeleportEvent extends EsCancellableEvent { + private final EsPlayer player; + private final EsTeleportCause cause; + private final EsLocation to; + + public EsPlayerTeleportEvent(EsPlayer p, EsTeleportCause c, EsLocation to) { + player = p; + cause = c; + this.to = to; + } + + public EsPlayer getPlayer() { + return player; + } + + public EsTeleportCause getCause() { + return cause; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Events/EsSignChangeEvent.java b/src/main/java/net/serble/estools/ServerApi/Events/EsSignChangeEvent.java new file mode 100644 index 0000000..373b28d --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Events/EsSignChangeEvent.java @@ -0,0 +1,30 @@ +package net.serble.estools.ServerApi.Events; + +import net.serble.estools.ServerApi.Interfaces.EsCancellableEvent; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; + +public class EsSignChangeEvent extends EsCancellableEvent { + private final EsPlayer player; + private final String[] lines; + + public EsSignChangeEvent(EsPlayer player, String[] lines) { + this.player = player; + this.lines = lines; + } + + public EsPlayer getPlayer() { + return player; + } + + public String[] getLines() { + return lines; + } + + public String getLine(int line) { + return lines[line]; + } + + public void setLine(int line, String text) { + lines[line] = text; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitBlock.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitBlock.java new file mode 100644 index 0000000..9dc3ddf --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitBlock.java @@ -0,0 +1,42 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.ServerApi.Interfaces.EsBlock; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; + +public class BukkitBlock implements EsBlock { + private final BlockState bukkitState; + + public BukkitBlock(BlockState block) { + bukkitState = block; + } + + private Block getBukkitBlock() { + return bukkitState.getBlock(); + } + + @Override + public boolean breakNaturally() { + return getBukkitBlock().breakNaturally(); + } + + @Override + public int getX() { + return getBukkitBlock().getX(); + } + + @Override + public int getY() { + return getBukkitBlock().getY(); + } + + @Override + public int getZ() { + return getBukkitBlock().getZ(); + } + + @Override + public String getType() { + return bukkitState.getType().name(); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitCommandBlockSender.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitCommandBlockSender.java new file mode 100644 index 0000000..5374df2 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitCommandBlockSender.java @@ -0,0 +1,32 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.ServerApi.Interfaces.EsCommandBlockSender; +import net.serble.estools.ServerApi.Interfaces.EsConsoleSender; +import org.bukkit.command.BlockCommandSender; + +public class BukkitCommandBlockSender implements EsCommandBlockSender { + private final BlockCommandSender bukkitSender; + + public BukkitCommandBlockSender(BlockCommandSender child) { + bukkitSender = child; + } + + public BlockCommandSender getBukkitSender() { + return bukkitSender; + } + + @Override + public void sendMessage(String... msg) { + bukkitSender.sendMessage(msg); + } + + @Override + public boolean hasPermission(String node) { + return bukkitSender.hasPermission(node); + } + + @Override + public boolean isPermissionSet(String node) { + return bukkitSender.isPermissionSet(node); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitConsoleSender.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitConsoleSender.java new file mode 100644 index 0000000..ffebb26 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitConsoleSender.java @@ -0,0 +1,73 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.Interfaces.EsConsoleSender; +import net.serble.estools.Utils; +import org.bukkit.command.ConsoleCommandSender; + +// We have to execute methods using reflection because +// in 1.0 ConsoleCommandSender is a class not an interface +public class BukkitConsoleSender implements EsConsoleSender { + private final ConsoleCommandSender bukkitSender; + + public BukkitConsoleSender(ConsoleCommandSender child) { + bukkitSender = child; + } + + @Override + public void sendMessage(String... msg) { + if (Main.minecraftVersion.isAtLeast(1, 2, 0)) { + bukkitSender.sendMessage(msg); + return; + } + + // The sendMessage(String[]) method doesn't exist + // So combine the args into one String + StringBuilder sb = new StringBuilder(); + for (String s : msg) { + sb.append(s); + } + + if (Main.minecraftVersion.isLowerThan(1, 1, 0)) { + try { + ConsoleCommandSender.class.getMethod("sendMessage", String.class).invoke(bukkitSender, sb.toString()); + } catch (Exception e) { + Main.logger.severe(Utils.getStacktrace(e)); + } + return; + } + bukkitSender.sendMessage(sb.toString()); + } + + @Override + public boolean hasPermission(String node) { + if (Main.minecraftVersion.isLowerThan(1, 1, 0)) { + try { + return (boolean) ConsoleCommandSender.class + .getMethod("hasPermission", String.class) + .invoke(bukkitSender, node); + } catch (Exception e) { + Main.logger.severe(Utils.getStacktrace(e)); + } + return false; + } + + return bukkitSender.hasPermission(node); + } + + @Override + public boolean isPermissionSet(String node) { + if (Main.minecraftVersion.isLowerThan(1, 1, 0)) { + try { + return (boolean) ConsoleCommandSender.class + .getMethod("isPermissionSet", String.class) + .invoke(bukkitSender, node); + } catch (Exception e) { + Main.logger.severe(Utils.getStacktrace(e)); + } + return false; + } + + return bukkitSender.isPermissionSet(node); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitEntity.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitEntity.java new file mode 100644 index 0000000..39fbf56 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitEntity.java @@ -0,0 +1,156 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.ServerApi.EsLocation; +import net.serble.estools.Main; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.EsEntity; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +public class BukkitEntity implements EsEntity { + private final Entity bukkitEntity; + + public BukkitEntity(Entity bukkitEntity) { + this.bukkitEntity = bukkitEntity; + } + + public Entity getBukkitEntity() { + return bukkitEntity; + } + + @Override + public void teleport(EsLocation loc) { + // This was moved from PaperLib.teleport() because the PaperLib class imports + // things that don't exist in Bukkit 1.0 and therefore can't load. + bukkitEntity.teleport(BukkitHelper.toBukkitLocation(loc)); + } + + @Override + public String getType() { + if (Main.minecraftVersion.isAtLeast(1, 1, 0)) { + return bukkitEntity.getType().name(); + } + + // getType() doesn't exist + return "ID " + bukkitEntity.getEntityId(); + } + + @Override + public String getName() { + if (Main.minecraftVersion.getMinor() > 7) { + return bukkitEntity.getName(); + } + + if (bukkitEntity instanceof Player) { + return ((Player)bukkitEntity).getDisplayName(); + } + + if (bukkitEntity instanceof LivingEntity) { + // Cast isn't redundant because that method is only in LivingEntity in old versions + @SuppressWarnings("RedundantCast") String name = ((LivingEntity)bukkitEntity).getCustomName(); + if (name != null) { + return name; + } + } + + return "Entity"; + } + + @Override + public UUID getUniqueId() { + return bukkitEntity.getUniqueId(); + } + + @Override + public boolean hasPermission(String node) { + return bukkitEntity.hasPermission(node); + } + + @Override + public boolean isPermissionSet(String node) { + return bukkitEntity.isPermissionSet(node); + } + + @Override + public void sendMessage(String... msg) { + if (Main.minecraftVersion.isAtLeast(1, 2, 0)) { + bukkitEntity.sendMessage(msg); + return; + } + + // The sendMessage(String[]) method doesn't exist + // So combine the args into one String + StringBuilder sb = new StringBuilder(); + for (String s : msg) { + sb.append(s); + } + bukkitEntity.sendMessage(sb.toString()); + } + + @Override + public EsLocation getLocation() { + return BukkitHelper.fromBukkitLocation(bukkitEntity.getLocation()); + } + + @Override + public boolean leaveVehicle() { + if (bukkitEntity instanceof LivingEntity) { + // Not redundant for below 1.3 + //noinspection RedundantCast + return ((LivingEntity) bukkitEntity).leaveVehicle(); + } else { + return bukkitEntity.leaveVehicle(); + } + } + + @Override + public List getPassengers() { + List bukkitList = bukkitEntity.getPassengers(); + List list = new ArrayList<>(); + for (Entity entity : bukkitList) { + list.add(BukkitHelper.fromBukkitEntity(entity)); + } + return list; + } + + @Override + public Set getScoreboardTags() { + return bukkitEntity.getScoreboardTags(); + } + + @Override + public void addScoreboardTag(String tag) { + bukkitEntity.addScoreboardTag(tag); + } + + @Override + public boolean hasScoreboardTag(String tag) { + return bukkitEntity.getScoreboardTags().contains(tag); + } + + @Override + public void setOnFireTicks(int ticks) { + bukkitEntity.setFireTicks(ticks); + } + + @Override + public void addPassenger(EsEntity entity) { + if (Main.minecraftVersion.getMinor() > 11) { + bukkitEntity.addPassenger(((BukkitEntity) entity).getBukkitEntity()); + } else { + //noinspection deprecation + bukkitEntity.setPassenger(((BukkitEntity) entity).getBukkitEntity()); + } + } + + @Override + public void setFallDistance(float dis) { + bukkitEntity.setFallDistance(dis); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitInventory.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitInventory.java new file mode 100644 index 0000000..dba4330 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitInventory.java @@ -0,0 +1,104 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.ServerApi.EsMaterial; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.EsInventory; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import org.bukkit.Material; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import java.util.*; + +public class BukkitInventory implements EsInventory { + private final org.bukkit.inventory.Inventory bukkitInv; + + public BukkitInventory(Inventory inv) { + bukkitInv = inv; + if (inv == null) { + throw new NullPointerException("inv"); + } + } + + public BukkitInventory() { + bukkitInv = null; + } + + @Override + public void setItem(int slot, EsItemStack item) { + ItemStack stack = item == null ? null : ((BukkitItemStack) item).getBukkitItem(); + bukkitInv.setItem(slot, stack); + } + + @Override + public EsItemStack getItem(int slot) { + return BukkitHelper.fromBukkitItem(bukkitInv.getItem(slot)); + } + + @Override + public void addItem(EsItemStack stack) { + bukkitInv.addItem(((BukkitItemStack) stack).getBukkitItem()); + } + + @Override + public void setContents(EsItemStack[] items) { + ItemStack[] bukkitItems = new ItemStack[items.length]; + for (int i = 0; i < items.length; i++) { + if (items[i] == null) { + bukkitItems[i] = null; + continue; + } + bukkitItems[i] = ((BukkitItemStack) items[i]).getBukkitItem(); + } + bukkitInv.setContents(bukkitItems); + } + + @Override + public EsItemStack[] getContents() { + org.bukkit.inventory.ItemStack[] bukkitItems = bukkitInv.getContents(); + EsItemStack[] items = new EsItemStack[bukkitItems.length]; + for (int i = 0; i < bukkitItems.length; i++) { + if (bukkitItems[i] == null) { + items[i] = null; + continue; + } + items[i] = BukkitHelper.fromBukkitItem(bukkitItems[i]); + } + return items; + } + + @Override + public void clear() { + bukkitInv.clear(); + } + + public Inventory getBukkitInventory() { + return bukkitInv; + } + + @Override + public boolean isEqualTo(EsInventory inv) { + if (inv == null) { + return false; + } + return ((BukkitInventory) inv).getBukkitInventory().equals(bukkitInv); + } + + @Override + public int getSize() { + return bukkitInv.getSize(); + } + + @Override + public Map all(EsMaterial material) { + Material mat = BukkitHelper.toBukkitMaterial(material); + Map out = new HashMap<>(); + + assert bukkitInv != null; + for (Map.Entry entry : bukkitInv.all(mat).entrySet()) { + out.put(entry.getKey(), BukkitHelper.fromBukkitItem(entry.getValue())); + } + + return out; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitInventoryView.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitInventoryView.java new file mode 100644 index 0000000..88528c1 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitInventoryView.java @@ -0,0 +1,43 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.EsInventory; +import net.serble.estools.ServerApi.Interfaces.EsInventoryView; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; + +public class BukkitInventoryView implements EsInventoryView { + private final InventoryView bukkitView; + + public BukkitInventoryView(InventoryView child) { + bukkitView = child; + } + + @Override + public EsInventory getTopInventory() { + return BukkitHelper.fromBukkitInventory(bukkitView.getTopInventory()); + } + + @Override + public EsInventory getBottomInventory() { + return BukkitHelper.fromBukkitInventory(bukkitView.getBottomInventory()); + } + + @Override + public EsInventory getInventory(int slot) { + if (Main.minecraftVersion.getMinor() <= 12) { // .getInventory(slot) doesn't exist + if (slot >= getTopInventory().getSize()) { // Bottom inv + return getBottomInventory(); + } + return getTopInventory(); + } + return BukkitHelper.fromBukkitInventory(bukkitView.getInventory(slot)); + } + + @Override + public EsPlayer getPlayer() { + return new BukkitPlayer((Player) bukkitView.getPlayer()); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitItemMeta.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitItemMeta.java new file mode 100644 index 0000000..24c28f6 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitItemMeta.java @@ -0,0 +1,96 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.ServerApi.EsItemFlag; +import net.serble.estools.ServerApi.Interfaces.EsItemMeta; +import net.serble.estools.ServerApi.Interfaces.EsPersistentDataContainer; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class BukkitItemMeta implements EsItemMeta { + private final ItemMeta bukkitMeta; + + public BukkitItemMeta(ItemMeta meta) { + if (meta == null) { + throw new NullPointerException("Meta is null"); + } + bukkitMeta = meta; + } + + @Override + public void setUnbreakable(boolean val) { + bukkitMeta.setUnbreakable(val); + } + + @Override + public boolean isUnbreakable() { + return bukkitMeta.isUnbreakable(); + } + + @Override + public Set getItemFlags() { + Set bukkitFlags = bukkitMeta.getItemFlags(); + Set out = new HashSet<>(); + for (ItemFlag flag : bukkitFlags) { + out.add(EsItemFlag.valueOf(flag.name())); + } + return out; + } + + @Override + public void addItemFlags(EsItemFlag... flags) { + bukkitMeta.addItemFlags(convertFlags(flags)); + } + + @Override + public void removeItemFlags(EsItemFlag... flags) { + bukkitMeta.removeItemFlags(convertFlags(flags)); + } + + private ItemFlag[] convertFlags(EsItemFlag[] flags) { + List bukkitFlags = new ArrayList<>(flags.length); + for (EsItemFlag flag : flags) { + try { + bukkitFlags.add(ItemFlag.valueOf(flag.name())); + } catch (IllegalArgumentException ignored) {} // doesnt exist, dont add + } + + return bukkitFlags.toArray(new ItemFlag[0]); + } + + @Override + public void setDisplayName(String val) { + bukkitMeta.setDisplayName(val); + } + + @Override + public String getDisplayName() { + return bukkitMeta.getDisplayName(); + } + + @Override + public List getLore() { + if (!bukkitMeta.hasLore()) { + return new ArrayList<>(); + } + return bukkitMeta.getLore(); + } + + @Override + public void setLore(List val) { + bukkitMeta.setLore(val); + } + + @Override + public EsPersistentDataContainer getPersistentDataContainer() { + return new BukkitPersistentDataContainer(bukkitMeta.getPersistentDataContainer()); + } + + public ItemMeta getBukkitMeta() { + return bukkitMeta; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitItemStack.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitItemStack.java new file mode 100644 index 0000000..559eb11 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitItemStack.java @@ -0,0 +1,160 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsEnchantment; +import net.serble.estools.ServerApi.EsMaterial; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitEnchantmentHelper; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitMetaHelper; +import net.serble.estools.ServerApi.Interfaces.EsItemMeta; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class BukkitItemStack implements EsItemStack { + private final ItemStack bukkitItem; + + public BukkitItemStack(EsMaterial mat, int amount) { + bukkitItem = new ItemStack(BukkitHelper.toBukkitMaterial(mat), amount); + } + + public BukkitItemStack(ItemStack child) { + bukkitItem = child; + } + + public ItemStack getBukkitItem() { + return bukkitItem; + } + + @Override + public EsMaterial getType() { + return BukkitHelper.fromBukkitMaterial(bukkitItem.getType()); + } + + @Override + public void setType(EsMaterial val) { + bukkitItem.setType(BukkitHelper.toBukkitMaterial(val)); + } + + @Override + public int getAmount() { + return bukkitItem.getAmount(); + } + + @Override + public void setAmount(int val) { + bukkitItem.setAmount(val); + } + + @Override + public void addEnchantment(EsEnchantment enchantment, int level) { + bukkitItem.addUnsafeEnchantment(BukkitEnchantmentHelper.toBukkitEnchantment(enchantment), level); + } + + @Override + public void removeEnchantment(EsEnchantment enchantment) { + bukkitItem.removeEnchantment(BukkitEnchantmentHelper.toBukkitEnchantment(enchantment)); + } + + @Override + public EsItemMeta getItemMeta() { + return BukkitMetaHelper.fromBukkitItemMeta(bukkitItem.getItemMeta()); + } + + @Override + public String exportItemMeta() { + YamlConfiguration config = new YamlConfiguration(); + config.set("item", bukkitItem.getItemMeta()); + return config.saveToString(); + } + + @Override + public void importItemMeta(String meta) { + YamlConfiguration config = new YamlConfiguration(); + try { + config.loadFromString(meta); + } catch (InvalidConfigurationException e) { + throw new RuntimeException(e); + } + + ItemMeta itemMeta = (ItemMeta)config.get("item"); + bukkitItem.setItemMeta(itemMeta); + } + + @Override + public void setItemMeta(EsItemMeta meta) { + bukkitItem.setItemMeta(((BukkitItemMeta) meta).getBukkitMeta()); + } + + @SuppressWarnings("deprecation") + @Override + public void setDamage(int val) { + if (Main.minecraftVersion.getMinor() > 12) { + ItemMeta meta = bukkitItem.getItemMeta(); + if (meta instanceof Damageable) { + ((Damageable) meta).setDamage(val); + } + bukkitItem.setItemMeta(meta); + } else { + if (val > Short.MAX_VALUE) { + val = Short.MAX_VALUE; + } + + bukkitItem.setDurability((short) val); + } + } + + @SuppressWarnings("deprecation") + @Override + public int getDamage() { + if (Main.minecraftVersion.getMinor() > 12) { + return bukkitItem.getDurability(); + } + + ItemMeta meta = bukkitItem.getItemMeta(); + if (meta instanceof Damageable) { + return ((Damageable) meta).getDamage(); + } + return 0; + } + + @SuppressWarnings("MethodDoesntCallSuperMethod") // I don't care, it doesn't work like that + @Override + public EsItemStack clone() { + return BukkitHelper.fromBukkitItem(bukkitItem.clone()); + } + + @Override + public boolean isSimilar(EsItemStack stack) { + return ((BukkitItemStack) stack).getBukkitItem().isSimilar(bukkitItem); + } + + @Override + public int getMaxStackSize() { + return bukkitItem.getMaxStackSize(); + } + + @Override + public Object getInternalObject() { + return bukkitItem; + } + + @Override + public Map getEnchantments() { + Set> bEnchs = bukkitItem.getEnchantments().entrySet(); + Map enchs = new HashMap<>(bEnchs.size()); + for (Map.Entry ench : bEnchs) { + enchs.put(BukkitEnchantmentHelper.fromBukkitEnchantment(ench.getKey()), ench.getValue()); + } + + return enchs; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitLivingEntity.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitLivingEntity.java new file mode 100644 index 0000000..10a3997 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitLivingEntity.java @@ -0,0 +1,132 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsPotionEffect; +import net.serble.estools.ServerApi.EsPotionEffectType; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitEffectHelper; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.EsLivingEntity; +import net.serble.estools.ServerApi.Interfaces.EsWorld; +import org.bukkit.Bukkit; +import org.bukkit.attribute.Attribute; +import org.bukkit.entity.LivingEntity; +import org.bukkit.potion.PotionEffect; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; + +public class BukkitLivingEntity extends BukkitEntity implements EsLivingEntity { + private final org.bukkit.entity.LivingEntity bukkitEntity; + + public BukkitLivingEntity(org.bukkit.entity.LivingEntity entity) { + super(entity); + bukkitEntity = entity; + } + + public LivingEntity getBukkitEntity() { + return bukkitEntity; + } + + @Override + public double getMaxHealth() { + if (Main.minecraftVersion.getMinor() > 8) { + return Objects.requireNonNull(bukkitEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue(); + } else { + if (Main.minecraftVersion.getMinor() > 5) { + //noinspection deprecation + return bukkitEntity.getMaxHealth(); + } + + try { + return (double)(int) org.bukkit.entity.LivingEntity.class.getMethod("getMaxHealth").invoke(bukkitEntity); + } catch(Exception e) { + Bukkit.getLogger().severe(e.toString()); + return 20d; + } + } + } + + @Override + public void setMaxHealth(double val) { + if (Main.minecraftVersion.getMinor() > 8) { + Objects.requireNonNull(bukkitEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH)).setBaseValue(val); + } else { + if (Main.minecraftVersion.getMinor() > 5) { + //noinspection deprecation + bukkitEntity.setMaxHealth(val); + return; + } + + try { + //noinspection JavaReflectionMemberAccess + org.bukkit.entity.LivingEntity.class.getMethod("setMaxHealth", int.class).invoke(bukkitEntity, (int)val); + } + catch (Exception ex) { + Bukkit.getLogger().severe(ex.toString()); + } + } + } + + @Override + public double getHealth() { + if (Main.minecraftVersion.getMinor() > 5) { + return bukkitEntity.getHealth(); + } + + try { + return (double)(int) org.bukkit.entity.LivingEntity.class.getMethod("getHealth").invoke(bukkitEntity); + } + catch (Exception ex) { + Bukkit.getLogger().severe(ex.toString()); + return 20d; + } + } + + @Override + public void setHealth(double val) { + if (Main.minecraftVersion.getMinor() > 5) { + bukkitEntity.setHealth(val); + return; + } + + try { + //noinspection JavaReflectionMemberAccess + org.bukkit.entity.LivingEntity.class.getMethod("setHealth", int.class).invoke(bukkitEntity, (int)val); + } + catch (Exception ex) { + Bukkit.getLogger().severe(ex.toString()); + } + } + + @Override + public void addPotionEffect(EsPotionEffect effect) { + bukkitEntity.addPotionEffect(BukkitHelper.toBukkitPotionEffect(effect)); + } + + @Override + public void removePotionEffect(EsPotionEffectType effect) { + bukkitEntity.removePotionEffect(BukkitEffectHelper.toBukkitEffectType(effect)); + } + + @Override + public List getActivePotionEffects() { + if (Main.minecraftVersion.isLowerThan(1, 1, 0)) { + return new ArrayList<>(); + } + + Collection bukkitEffects = bukkitEntity.getActivePotionEffects(); + List out = new ArrayList<>(bukkitEffects.size()); + for (PotionEffect eff : bukkitEffects) { + out.add(BukkitHelper.fromBukkitPotionEffect(eff)); + } + + return out; + } + + @Override + public EsWorld getWorld() { + return new BukkitWorld(bukkitEntity.getWorld()); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitLogger.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitLogger.java new file mode 100644 index 0000000..9edcd40 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitLogger.java @@ -0,0 +1,26 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.ServerApi.Interfaces.EsLogger; +import org.bukkit.Bukkit; + +public class BukkitLogger implements EsLogger { + @Override + public void debug(String msg) { + Bukkit.getLogger().info(msg); + } + + @Override + public void info(String msg) { + Bukkit.getLogger().info(msg); + } + + @Override + public void warning(String msg) { + Bukkit.getLogger().warning(msg); + } + + @Override + public void severe(String msg) { + Bukkit.getLogger().severe(msg); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPersistentDataContainer.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPersistentDataContainer.java new file mode 100644 index 0000000..d45726f --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPersistentDataContainer.java @@ -0,0 +1,34 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.ServerApi.EsPersistentDataType; +import net.serble.estools.ServerApi.Implementations.Folia.FoliaHelper; +import net.serble.estools.ServerApi.Interfaces.EsPersistentDataContainer; +import org.bukkit.persistence.PersistentDataContainer; + +import java.util.Objects; + +import static net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper.*; + +@SuppressWarnings("unchecked") // Trust me bro +public class BukkitPersistentDataContainer implements EsPersistentDataContainer { + private final PersistentDataContainer bukkitContainer; + + public BukkitPersistentDataContainer(PersistentDataContainer container) { + bukkitContainer = container; + } + + @Override + public void set(String key, EsPersistentDataType type, Object val) { + bukkitContainer.set(Objects.requireNonNull(getNamespacedKey(key)), FoliaHelper.toBukkitPersistentDataType(type), val); + } + + @Override + public Object get(String key, EsPersistentDataType type) { + return bukkitContainer.get(Objects.requireNonNull(getNamespacedKey(key)), FoliaHelper.toBukkitPersistentDataType(type)); + } + + @Override + public void remove(String key) { + bukkitContainer.remove(Objects.requireNonNull(getNamespacedKey(key))); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPlayer.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPlayer.java new file mode 100644 index 0000000..5f93bdc --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPlayer.java @@ -0,0 +1,201 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsGameMode; +import net.serble.estools.ServerApi.EsLocation; +import net.serble.estools.ServerApi.EsSound; +import net.serble.estools.ServerApi.EsSoundCategory; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.*; +import org.bukkit.Bukkit; +import org.bukkit.block.Block; +import org.bukkit.entity.LivingEntity; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Nullable; + +import java.util.HashSet; + +public class BukkitPlayer extends BukkitLivingEntity implements EsPlayer { + private final org.bukkit.entity.Player bukkitPlayer; + + public BukkitPlayer(org.bukkit.entity.Player entity) { + super(entity); + bukkitPlayer = entity; + } + + public org.bukkit.entity.Player getBukkitPlayer() { + return bukkitPlayer; + } + + @Override + public int getFoodLevel() { + return bukkitPlayer.getFoodLevel(); + } + + @Override + public void setFoodLevel(int val) { + bukkitPlayer.setFoodLevel(val); + } + + @Override + public double getSaturation() { + return bukkitPlayer.getSaturation(); + } + + @Override + public void setSaturation(double val) { + bukkitPlayer.setSaturation((float) val); + } + + @Override + public EsItemStack getMainHand() { + ItemStack mainHand = bukkitGetMainHand(); + if (mainHand == null) { + return null; + } + return BukkitHelper.fromBukkitItem(mainHand); + } + + @Override + public void setMainHand(EsItemStack item) { + setMainHandBukkit(bukkitPlayer, ((BukkitItemStack) item).getBukkitItem()); + } + + @Override + public void openInventory(EsInventory inv) { + bukkitPlayer.openInventory(((BukkitInventory) inv).getBukkitInventory()); + } + + @Override + public void closeInventory() { + bukkitPlayer.closeInventory(); + } + + @Override + public EsPlayerInventory getInventory() { + return new BukkitPlayerInventory(bukkitPlayer.getInventory()); + } + + @Override + public void setFlySpeed(float val) { + bukkitPlayer.setFlySpeed(val); + } + + @Override + public void setWalkSpeed(float val) { + bukkitPlayer.setWalkSpeed(val); + } + + @Override + public void setGameMode(EsGameMode mode) { + bukkitPlayer.setGameMode(BukkitHelper.toBukkitGameMode(mode)); + } + + @Override + public EsGameMode getGameMode() { + return BukkitHelper.fromBukkitGameMode(bukkitPlayer.getGameMode()); + } + + @Override + public @Nullable EsBlock getTargetBlock() { + Block target = bukkitGetTargetBlock(); + if (target == null) { + return null; + } + return BukkitHelper.fromBukkitBlock(target.getState()); + } + + @Override + public boolean getAllowFlight() { + return bukkitPlayer.getAllowFlight(); + } + + @Override + public void setAllowFlight(boolean val) { + bukkitPlayer.setAllowFlight(val); + } + + @Override + public boolean isFlying() { + return bukkitPlayer.isFlying(); + } + + @Override + public void playSound(EsSound sound, EsSoundCategory category, EsLocation loc, int volume, int pitch) { + if (Main.minecraftVersion.getMinor() < 11) { + bukkitPlayer.playSound(BukkitHelper.toBukkitLocation(loc), BukkitHelper.toBukkitSound(sound), volume, pitch); + return; + } + bukkitPlayer.playSound(BukkitHelper.toBukkitLocation(loc), BukkitHelper.toBukkitSound(sound), BukkitHelper.toBukkitSoundCategory(category), volume, pitch); + } + + @SuppressWarnings("UnstableApiUsage") // Yes I know it's a bug + @Override + public void updateInventory() { + bukkitPlayer.updateInventory(); + } + + private Block bukkitGetTargetBlock() { + if (Main.minecraftVersion.getMinor() > 12) { + return bukkitPlayer.getTargetBlockExact(5); + } else if (Main.minecraftVersion.getMinor() > 7) { + return bukkitPlayer.getTargetBlock(null, 5); + } else { + try { + //noinspection JavaReflectionMemberAccess + return (Block) LivingEntity.class.getMethod("getTargetBlock", HashSet.class, int.class).invoke(bukkitPlayer, null, 5); + } + catch (Exception e) { + Bukkit.getLogger().severe(e.toString()); + return null; + } + } + } + + private org.bukkit.inventory.ItemStack bukkitGetMainHand() { + if (Main.minecraftVersion.getMinor() > 8) { + return bukkitPlayer.getInventory().getItemInMainHand(); + } else { + //noinspection deprecation + return bukkitPlayer.getInventory().getItemInHand(); + } + } + + private void setMainHandBukkit(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is) { + if (Main.minecraftVersion.getMinor() > 8) { + p.getInventory().setItemInMainHand(is); + } else { + //noinspection deprecation + p.getInventory().setItemInHand(is); + } + } + + @Override + public boolean hasPermission(String node) { + return bukkitPlayer.hasPermission(node); + } + + // I know that this overrides the BukkitEntity.sendMessage method + // It has to because Entity.sendMessage() doesn't exist in old versions + // so Player.sendMessage() needs to be used where possible. + @Override + public void sendMessage(String... args) { + if (Main.minecraftVersion.isAtLeast(1, 2, 0)) { + bukkitPlayer.sendMessage(args); + return; + } + + // The sendMessage(String[]) method doesn't exist + // So combine the args into one String + StringBuilder sb = new StringBuilder(); + for (String s : args) { + sb.append(s); + } + bukkitPlayer.sendMessage(sb.toString()); + } + + @Override + public boolean isPermissionSet(String node) { + return bukkitPlayer.isPermissionSet(node); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPlayerInventory.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPlayerInventory.java new file mode 100644 index 0000000..e7efa76 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPlayerInventory.java @@ -0,0 +1,96 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsEquipmentSlot; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitEquipmentSlotHelper; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayerInventory; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.PlayerInventory; + +public class BukkitPlayerInventory extends BukkitInventory implements EsPlayerInventory { + private final PlayerInventory bukkitInv; + + public BukkitPlayerInventory(PlayerInventory inv) { + super(inv); + bukkitInv = inv; + } + + public BukkitPlayerInventory() { + bukkitInv = null; + } + + @Override + public PlayerInventory getBukkitInventory() { + return bukkitInv; + } + + @Override + public EsItemStack getOffHand() { + return BukkitHelper.fromBukkitItem(bukkitInv.getItemInOffHand()); + } + + @Override + public EsItemStack getMainHand() { + return BukkitHelper.fromBukkitItem(bukkitInv.getItemInMainHand()); + } + + @Override + public EsItemStack getHelmet() { + return BukkitHelper.fromBukkitItem(bukkitInv.getHelmet()); + } + + @Override + public EsItemStack getLeggings() { + return BukkitHelper.fromBukkitItem(bukkitInv.getLeggings()); + } + + @Override + public EsItemStack getChestplate() { + return BukkitHelper.fromBukkitItem(bukkitInv.getChestplate()); + } + + @Override + public EsItemStack getBoots() { + return BukkitHelper.fromBukkitItem(bukkitInv.getBoots()); + } + + @Override + public void setItem(EsEquipmentSlot slot, EsItemStack item) { + if (Main.minecraftVersion.getMinor() <= 14) { + int slotId; + switch (slot) { + case Head: + slotId = 5; + break; + + case Chest: + slotId = 6; + break; + + case Legs: + slotId = 7; + break; + + case Feet: + slotId = 8; + break; + + case Hand: + slotId = bukkitInv.getHeldItemSlot(); + break; + + case OffHand: + slotId = 40; + break; + + default: + throw new IllegalStateException("Unexpected value: " + slot); + } + ((Inventory) bukkitInv).setItem(slotId, ((BukkitItemStack) item).getBukkitItem()); + return; + } + bukkitInv.setItem(BukkitEquipmentSlotHelper.toBukkitEquipmentSlot(slot), ((BukkitItemStack) item).getBukkitItem()); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPotion.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPotion.java new file mode 100644 index 0000000..79989fa --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPotion.java @@ -0,0 +1,87 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsPotType; +import net.serble.estools.ServerApi.EsPotionEffect; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitEffectHelper; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.EsPotion; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.PotionMeta; // TODO: pre 1.9 errors because no PotionMeta and pre 1.4 errors +import org.bukkit.potion.Potion; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionType; + +import java.util.ArrayList; +import java.util.List; + +@SuppressWarnings("deprecation") // This whole class depends on the deprecated Potion class +public class BukkitPotion extends BukkitItemStack implements EsPotion { + /** Only used when old is true */ + private Potion bukkitPotion; + + /** Only used when old is false */ + private PotionMeta bukkitMeta; + private boolean old; + + public BukkitPotion(ItemStack is) { + super(is); + calcOld(); + + if (old) { + bukkitPotion = Potion.fromItemStack(is); + } else { + bukkitMeta = (PotionMeta) is.getItemMeta(); + } + } + + private void calcOld() { + if (Main.minecraftVersion.getMinor() >= 9) { + old = false; + } else if (Main.minecraftVersion.getMinor() >= 4) { + old = true; + } else { + throw new RuntimeException("Potion are not supported in this Minecraft version"); + } + } + + @Override + public EsPotionEffect[] getEffects() { + PotionEffect[] in; + if (old) { + in = bukkitPotion.getEffects().toArray(new PotionEffect[0]); + } else { + PotionType baseType = bukkitMeta.getBasePotionType(); + List baseEffects = new ArrayList<>(baseType.getPotionEffects()); // What's the difference between base and custom effects? + if (bukkitMeta.hasCustomEffects()) { // The docs say to do this + baseEffects.addAll(bukkitMeta.getCustomEffects()); + } + in = baseEffects.toArray(new PotionEffect[0]); + } + + EsPotionEffect[] out = new EsPotionEffect[in.length]; + for (int i = 0; i < out.length; i++) { + PotionEffect effect = in[i]; + out[i] = new EsPotionEffect(BukkitEffectHelper.fromBukkitEffectType(effect.getType()), effect.getAmplifier(), effect.getDuration()); + } + return out; + } + + @Override + public EsPotType getPotionType() { + if (old) { + return BukkitHelper.fromBukkitPotType(bukkitPotion.toItemStack(0).getType()); + } else { + return BukkitHelper.fromBukkitPotType(getBukkitItem().getType()); + } + } + + @Override + public void addEffect(EsPotionEffect effect) { // TODO: This just doesn't work, same with the Folia implementation + if (old) { + bukkitPotion.getEffects().add(BukkitHelper.toBukkitPotionEffect(effect)); + } else { + bukkitMeta.addCustomEffect(BukkitHelper.toBukkitPotionEffect(effect), true); + } + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPotionVeryOld.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPotionVeryOld.java new file mode 100644 index 0000000..adce9c3 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitPotionVeryOld.java @@ -0,0 +1,48 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.Bitmask; +import net.serble.estools.ServerApi.EsPotType; +import net.serble.estools.ServerApi.EsPotionEffect; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitPotionsHelper1_3; +import net.serble.estools.ServerApi.Interfaces.EsPotion; +import org.bukkit.inventory.ItemStack; + +/** + * Potions didn't used to have special code qualities in 1.3 and prior. + * The potion was dictated by its durability value. + * So in this case we need just a simple wrapper of BukkitItemStack that does + * nothing extra. + */ +@SuppressWarnings("deprecation") // This class is for 1.3 and below +public class BukkitPotionVeryOld extends BukkitItemStack implements EsPotion { + private final Bitmask data; + private static final short splashBit = 14; // Decimal val: 16384. 2^14=16384 + private static final short potionNameBits = 6; // There are max of 64 vals, 2^6=64 https://minecraft.wiki/w/Java_Edition_data_values/Pre-flattening#%22Potion_name%22_bits + + public BukkitPotionVeryOld(ItemStack is) { + super(is); + data = new Bitmask(is.getDurability()); + } + + @Override + public EsPotionEffect[] getEffects() { + return new EsPotionEffect[] { + new EsPotionEffect( + BukkitPotionsHelper1_3.getEffectTypeFromRawId((short) data.getValueOfFirstBits(potionNameBits)), + 0, 1) // Amp and duration are ignored because they can't be customised + }; + } + + @Override + public EsPotType getPotionType() { + if (data.getBit(splashBit)) { + return EsPotType.splash; + } + return EsPotType.drink; + } + + @Override + public void addEffect(EsPotionEffect effect) { + // This isn't possible because custom effects don't exist + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitServer.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitServer.java new file mode 100644 index 0000000..7c9e73f --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitServer.java @@ -0,0 +1,352 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.*; +import net.serble.estools.Entrypoints.EsToolsBukkit; +import net.serble.estools.ServerApi.*; +import net.serble.estools.ServerApi.Implementations.Bukkit.EventHandlers.BukkitEventsListener; +import net.serble.estools.ServerApi.Implementations.Bukkit.EventHandlers.BukkitEventsListenerPost1_1; +import net.serble.estools.ServerApi.Implementations.Bukkit.EventHandlers.BukkitEventsListenerPost1_4; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.*; +import net.serble.estools.ServerApi.Interfaces.*; +import org.bukkit.*; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.PluginCommand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.util.*; + +public class BukkitServer implements EsServer { + private final JavaPlugin plugin; + private final List listeners; + private final CommandExecutor cmdExecutor; + private static final Set materials = new HashSet<>(); + private static final Set itemMaterials = new HashSet<>(); + private static Set sounds = new HashSet<>(); + + public BukkitServer(Object pluginObj) { + plugin = (JavaPlugin) pluginObj; + + listeners = new ArrayList<>(); + + SemanticVersion mcVer = getVersion(); + if (mcVer.isAtLeast(1, 5, 0)) { + listeners.add(new BukkitEventsListenerPost1_4()); + } + if (mcVer.isAtLeast(1, 2, 0)) { + listeners.add(new BukkitEventsListenerPost1_1()); + } + + BukkitEventsListener bel = new BukkitEventsListener(); + listeners.add(bel); + cmdExecutor = bel; + } + + @Override + public void initialise() { + for (Material mat : Material.values()) { + EsMaterial esMat; + if (Main.minecraftVersion.getMinor() > 12) { + esMat = EsMaterial.createUnchecked(mat.getKey().getKey().toLowerCase()); + + if (mat.isItem()) { + itemMaterials.add(esMat); + } + } else { + esMat = EsMaterial.createUnchecked(mat.name().toLowerCase()); + + itemMaterials.add(esMat); + } + + materials.add(esMat); + } + + sounds = BukkitSoundHelper.getSounds(); + } + + @Override + public EsPlayer getPlayer(String name) { + Player p = Bukkit.getPlayer(name); + if (p == null) { + return null; + } + return new BukkitPlayer(p); + } + + @Override + public EsEntity getEntity(UUID uuid) { + if (Main.minecraftVersion.getMinor() > 11) { + Entity entity = Bukkit.getEntity(uuid); + if (entity == null) { + return null; + } + return BukkitHelper.fromBukkitEntity(entity); + } + + for (World world : Bukkit.getWorlds()) { + for (Entity entity : world.getEntities()) { + if (entity.getUniqueId().equals(uuid)) { + return BukkitHelper.fromBukkitEntity(entity); + } + } + } + + return null; + } + + @Override + public SemanticVersion getVersion() { // Parse the minecraft version from the Bukkit version string + String versionS = Bukkit.getVersion(); + int minor = 0; + int patch = 0; + + if (versionS.contains("(MC: ")) { + int posOfMC = versionS.indexOf("(MC: ") + 5; + versionS = versionS.substring(posOfMC, versionS.indexOf(')', posOfMC)); + } else { + Bukkit.getLogger().warning("Could not detect version from: " + versionS); + throw new RuntimeException("Could not detect version"); + } + + for (int i = 0; i < 99; i++) { + if (versionS.contains("1." + i)) { + minor = i; + } + } + + for (int i = 0; i < 99; i++) { + if (versionS.contains("1." + minor + '.' + i)) { + patch = i; + } + } + + return new SemanticVersion(1, minor, patch); + } + + @Override + public Collection getOnlinePlayers() { + try { + if (Bukkit.class.getMethod("getOnlinePlayers").getReturnType() == Collection.class) { + List players = new ArrayList<>(); + for (Player p : Bukkit.getOnlinePlayers()) { + players.add(new BukkitPlayer(p)); + } + return players; + } + else { + Player[] players = (Player[]) Bukkit.class.getMethod("getOnlinePlayers").invoke(null, new Object[0]); + List users = new ArrayList<>(); + for (Player p : players) { + users.add(new BukkitPlayer(p)); + } + return users; + } + + } catch (Exception e) { + Bukkit.getLogger().severe(e.toString()); + return new ArrayList<>(); + } + } + + @Override + public EsItemStack createItemStack(EsMaterial material, int amount) { + return new BukkitItemStack(material, amount); + } + + @SuppressWarnings("deprecation") + @Override + public EsPotion createPotion(EsPotType potType, EsPotionEffect effect, int amount) { + if (Main.minecraftVersion.getMinor() >= 9) { + String type = potType == EsPotType.drink ? + "POTION" : + potType.toString().toUpperCase() + "_POTION"; + ItemStack pot = new ItemStack(Material.valueOf(type), amount); + + BukkitMetaHelper.setPotionType(pot, effect); // No ItemMeta allowed + + return new BukkitPotion(pot); + } else if (Main.minecraftVersion.getMinor() >= 4) { + return BukkitPotionsHelper.createPotion1_4(potType, effect, amount); + } else { + short potionDat = BukkitPotionsHelper1_3.getPotionIdFromEffectType(effect.getType()); + if (potType == EsPotType.splash || potType == EsPotType.lingering) { + potionDat += 16384; + } + ItemStack stack = new ItemStack(Material.POTION, 1, potionDat); + return new BukkitPotionVeryOld(stack); + } + } + + @Override + public EsPotion createPotion(EsPotType potType) { + if (Main.minecraftVersion.getMinor() >= 9) { + String type = potType == EsPotType.drink ? + "POTION" : + potType.toString().toUpperCase() + "_POTION"; + + ItemStack pot = new ItemStack(Material.valueOf(type), 1); + + return new BukkitPotion(pot); + } else if (Main.minecraftVersion.getMinor() >= 4) { + return BukkitPotionsHelper.createPotion1_4(potType); + } else { + // This method isn't called pre 1.4 because CChest doesn't work + // With the way this works it wouldn't work in pre 1.4. + throw new UnsupportedOperationException("Proper support in this version has not been implemented."); + } + } + + @Override + public EsInventory createInventory(EsPlayer owner, int size, String title) { + if (!Main.minecraftVersion.isAtLeast(1, 2, 0)) { + // Creating inventories was not a feature in this version + // InventoryHolder also didn't exist, hence why we must use + // a helper class + throw new UnsupportedOperationException("Creating inventories is not supported in this version"); + } + return BukkitInventoryHelper.createInventory(owner, size, title); + } + + @Override + public Set getPotionEffectTypes() { + if (Main.minecraftVersion.isLowerThan(1, 1, 0)) { + return BukkitPotionsHelper1_3.getPotionList(); + } + return BukkitEffectHelper.getEffectList(); + } + + @Override + public Set getOldPotionTypes() { + if (Main.minecraftVersion.isLowerThan(1, 1, 0)) { + return BukkitPotionsHelper1_3.getPotionList(); + } + return BukkitEffectHelper.getPotionList(); + } + + @Override + public Set getEnchantments() { + return BukkitEnchantmentHelper.getEnchantmentList(); + } + + @Override + public Set getSounds() { + return sounds; + } + + @Override + public File getDataFolder() { + return plugin.getDataFolder(); + } + + @Override + public void dispatchCommand(EsCommandSender sender, String cmd) { + Bukkit.dispatchCommand(BukkitHelper.toBukkitCommandSender(sender), cmd); + } + + @Override + public EsCommandSender getConsoleSender() { + return null; + } + + @Override + public SemanticVersion getPluginVersion() { + return new SemanticVersion(plugin.getDescription().getVersion()); + } + + @Override + public String getPluginName() { + return plugin.getDescription().getName(); + } + + @Override + public int runTaskLater(Runnable task, long ticks) { + return Bukkit.getScheduler().scheduleSyncDelayedTask(EsToolsBukkit.plugin, task, ticks); + } + + @Override + public void runTask(Runnable task) { + Bukkit.getScheduler().scheduleSyncDelayedTask(EsToolsBukkit.plugin, task); + } + + @Override + public void cancelTask(int id) { + Bukkit.getScheduler().cancelTask(id); + } + + @Override + public EsLogger getLogger() { + return new BukkitLogger(); + } + + @Override + public void startEvents() { + if (Main.minecraftVersion.isMoreThan(1, 0, 0)) { // Events work differently in 1.0 + for (Listener l : listeners) { + Bukkit.getPluginManager().registerEvents(l, EsToolsBukkit.plugin); + } + return; + } + + // TODO: 1.0 events + Main.logger.warning("Events are not currently functional in Minecraft 1.0.0 and below"); + } + + @Override + public void registerCommand(String cmd, EsToolsTabCompleter tab) { + PluginCommand command = Objects.requireNonNull(Bukkit.getPluginCommand(cmd)); + if (!Main.tabCompleteEnabled || command.getTabCompleter() == null) { + command.setExecutor(cmdExecutor); + } + if (Main.tabCompleteEnabled) { + command.setTabCompleter(BukkitTabCompleteGenerator.generate(tab)); + } + } + + @Override + public void setTabCompleter(String cmd, EsToolsTabCompleter tab) { + PluginCommand command = Objects.requireNonNull(Bukkit.getPluginCommand(cmd)); + if (Main.tabCompleteEnabled) { + command.setTabCompleter(BukkitTabCompleteGenerator.generate(tab)); + } + } + + @Override + public void setCommandPermission(String cmd, String perm) { + PluginCommand command = Objects.requireNonNull(Bukkit.getPluginCommand(cmd)); + command.setPermission(perm); + + if (Main.minecraftVersion.getMinor() > 0) { + //noinspection deprecation, is still useful in pre 1.13 and technically is useful in rare situations post 1.13 + command.setPermissionMessage(EsToolsCommand.translate("&cYou do not have permission to run this command.")); + } + } + + @Override + public void broadcast(String msg, String perm) { + Bukkit.broadcast(msg, perm); + } + + @Override + public void broadcast(String msg) { + Bukkit.broadcastMessage(msg); + } + + @Override + public Set getMaterials(boolean onlyItems) { + return onlyItems ? itemMaterials : materials; + } + + @Override + public EsWorld getWorld(String name) { + return new BukkitWorld(Bukkit.getWorld(name)); + } + + @Override + public String[] getRelevantInternalTypes() { + return new String[] {}; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitSign.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitSign.java new file mode 100644 index 0000000..3d94530 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitSign.java @@ -0,0 +1,55 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import net.serble.estools.ServerApi.Interfaces.EsSign; +import net.serble.estools.ServerApi.Interfaces.EsSignSide; +import org.bukkit.block.Sign; + +public class BukkitSign extends BukkitBlock implements EsSign { + private final Sign bukkitSign; + + public BukkitSign(Sign block) { + super(block); + bukkitSign = block; + } + + @Override + public void update() { + bukkitSign.update(); + } + + @SuppressWarnings("deprecation") // Method is version specific + @Override + public void setGlowingText(boolean glowing) { + bukkitSign.setGlowingText(glowing); + } + + @SuppressWarnings("deprecation") // Method is version specific + @Override + public boolean isGlowingText() { + return bukkitSign.isGlowingText(); + } + + @SuppressWarnings("deprecation") // Method is version specific + @Override + public void setLine(int line, String text) { + bukkitSign.setLine(line, text); + } + + @Override + public EsSignSide getTargetSide(EsPlayer player) { + return new BukkitSignSide(bukkitSign.getTargetSide(((BukkitPlayer) player).getBukkitPlayer())); + } + + @SuppressWarnings("deprecation") + @Override + public String getLine(int line) { + return bukkitSign.getLine(line); + } + + @SuppressWarnings("deprecation") + @Override + public String[] getLines() { + return bukkitSign.getLines(); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitSignSide.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitSignSide.java new file mode 100644 index 0000000..0de9198 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitSignSide.java @@ -0,0 +1,27 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.ServerApi.Interfaces.EsSignSide; +import org.bukkit.block.sign.SignSide; + +public class BukkitSignSide implements EsSignSide { + private final SignSide bukkitSide; + + public BukkitSignSide(SignSide side) { + this.bukkitSide = side; + } + + @Override + public void setGlowingText(boolean glowing) { + bukkitSide.setGlowingText(glowing); + } + + @Override + public boolean isGlowingText() { + return bukkitSide.isGlowingText(); + } + + @Override + public void setLine(int line, String text) { + bukkitSide.setLine(line, text); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitTabCompleteGenerator.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitTabCompleteGenerator.java new file mode 100644 index 0000000..b0d0d8e --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitTabCompleteGenerator.java @@ -0,0 +1,24 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.EsToolsTabCompleter; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class BukkitTabCompleteGenerator { + + public static TabCompleter generate(EsToolsTabCompleter tabCompleter) { + return new TabCompleter() { + @Nullable + @Override + public List onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, @NotNull String[] args) { + return tabCompleter.onTabComplete(BukkitHelper.fromBukkitCommandSender(sender), args); + } + }; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitWorld.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitWorld.java new file mode 100644 index 0000000..1af5c4c --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/BukkitWorld.java @@ -0,0 +1,79 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsLocation; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.EsEntity; +import net.serble.estools.ServerApi.Interfaces.EsWorld; +import org.bukkit.World; +import org.bukkit.entity.Entity; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +public class BukkitWorld implements EsWorld { + private final org.bukkit.World bukkitWorld; + + public BukkitWorld(World world) { + bukkitWorld = world; + } + + @Override + public String getName() { + return bukkitWorld.getName(); + } + + @Override + public List getEntities() { + List bEntities = bukkitWorld.getEntities(); + List entities = new ArrayList<>(); + for (Entity bEntity : bEntities) { + entities.add(BukkitHelper.fromBukkitEntity(bEntity)); + } + return entities; + } + + private boolean isWithin(EsLocation loc, double xoff, double yoff, double zoff, Entity entity) { + return Math.abs(loc.getX() - entity.getLocation().getX()) <= xoff && + Math.abs(loc.getY() - entity.getLocation().getY()) <= yoff && + Math.abs(loc.getZ() - entity.getLocation().getZ()) <= zoff; + } + + @Override + public List getNearbyEntities(EsLocation loc, double xoff, double yoff, double zoff) { + Collection bEntities; + if (Main.minecraftVersion.getMinor() > 7) { + bEntities = bukkitWorld.getNearbyEntities(BukkitHelper.toBukkitLocation(loc), xoff, yoff, zoff); + } else { + Collection allEntities = bukkitWorld.getEntities(); + bEntities = allEntities.stream().filter(e -> isWithin(loc, xoff, yoff, zoff, e)).collect(Collectors.toList()); + } + List entities = new ArrayList<>(bEntities.size()); + for (Entity bEntity : bEntities) { + entities.add(BukkitHelper.fromBukkitEntity(bEntity)); + } + return entities; + } + + @Override + public void setTime(long time) { + bukkitWorld.setTime(time); + } + + @Override + public void setStorming(boolean val) { + bukkitWorld.setStorm(val); + } + + @Override + public void setThundering(boolean val) { + bukkitWorld.setThundering(val); + } + + @Override + public void strikeLightning(EsLocation loc) { + bukkitWorld.strikeLightning(BukkitHelper.toBukkitLocation(loc)); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/EventHandlers/BukkitEventsListener.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/EventHandlers/BukkitEventsListener.java new file mode 100644 index 0000000..b5ccb5a --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/EventHandlers/BukkitEventsListener.java @@ -0,0 +1,148 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.EventHandlers; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsAction; +import net.serble.estools.ServerApi.EsEquipmentSlot; +import net.serble.estools.ServerApi.Events.*; +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitPlayer; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitEnums1_1Plus; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitEquipmentSlotHelper; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.*; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.InvocationTargetException; +import java.util.Objects; + +public class BukkitEventsListener implements Listener, CommandExecutor { + + private double getDamageFromEvent(EntityDamageEvent e) { + if (Main.minecraftVersion.getMinor() > 5) { + return e.getDamage(); + } + + try { + return (double)(int)EntityDamageEvent.class.getMethod("getDamage").invoke(e); + } catch (Exception ex) { + Bukkit.getLogger().severe(ex.toString()); + return 0d; + } + } + + private void setDamageFromEvent(EntityDamageEvent e, @SuppressWarnings("SameParameterValue") double d) { + if (Main.minecraftVersion.getMinor() > 5) { + e.setDamage(d); + return; + } + + try { + //noinspection JavaReflectionMemberAccess, It's an int in older versions + EntityDamageEvent.class.getMethod("setDamage", int.class).invoke(e, (int) d); + } catch (Exception ex) { + Bukkit.getLogger().severe(ex.toString()); + } + } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent e) { + EsEquipmentSlot slot = EsEquipmentSlot.Hand; + if (Main.minecraftVersion.getMinor() > 8) { + slot = BukkitEquipmentSlotHelper.fromBukkitEquipmentSlot(e.getHand()); + } + EsBlockPlaceEvent ee = new EsBlockPlaceEvent(new BukkitPlayer(e.getPlayer()), BukkitHelper.fromBukkitItem(e.getItemInHand()), slot); + ee.setCancelled(e.isCancelled()); + Main.callEvent(ee); + e.setCancelled(ee.isCancelled()); + } + + @EventHandler + public void onTeleport(PlayerTeleportEvent e) { + EsPlayerTeleportEvent ee = new EsPlayerTeleportEvent( + new BukkitPlayer(e.getPlayer()), + BukkitEnums1_1Plus.fromBukkitTeleportCause(e.getCause()), + BukkitHelper.fromBukkitLocation(Objects.requireNonNull(e.getTo()))); + ee.setCancelled(e.isCancelled()); + Main.callEvent(ee); + e.setCancelled(ee.isCancelled()); + } + + @EventHandler + public void onPlayerDeath(PlayerDeathEvent e) { + try { + // In old versions getEntity() isn't in PlayerDeathEvent it is in EntityDeathEvent which + // returns a LivingEntity, so we have to use reflection to get it and then cast it to a Player + Player p = (Player) EntityEvent.class.getMethod("getEntity").invoke(e); + + EsPlayerDeathEvent ee = new EsPlayerDeathEvent(new BukkitPlayer(p)); + Main.callEvent(ee); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + Main.logger.severe(ex.toString()); + } + } + + @EventHandler + public void onEntityDamage(EntityDamageEvent e) { + EsEntityDamageEvent ee = new EsEntityDamageEvent(BukkitHelper.fromBukkitEntity(e.getEntity()), getDamageFromEvent(e)); + ee.setCancelled(e.isCancelled()); + Main.callEvent(ee); + setDamageFromEvent(e, ee.getDamage()); + e.setCancelled(ee.isCancelled()); + } + + @EventHandler + public void onQuit(PlayerQuitEvent e) { + Main.callEvent(new EsPlayerQuitEvent(new BukkitPlayer(e.getPlayer()))); + } + + @EventHandler + public void onKick(PlayerQuitEvent e) { + Main.callEvent(new EsPlayerQuitEvent(new BukkitPlayer(e.getPlayer()))); + } + + @EventHandler + public void onInteract(PlayerInteractEvent e) { + EsBlock cb = BukkitHelper.fromBukkitBlock(e.getClickedBlock()); + EsPlayer p = new BukkitPlayer(e.getPlayer()); + EsAction ac = BukkitHelper.fromBukkitAction(e.getAction()); + EsPlayerInteractEvent ee = new EsPlayerInteractEvent(p, cb, ac); + + ee.setUseInteractedBlock(BukkitHelper.fromBukkitEventResult(e.useInteractedBlock())); + ee.setUseItemInHand(BukkitHelper.fromBukkitEventResult(e.useItemInHand())); + Main.callEvent(ee); + e.setUseInteractedBlock(BukkitHelper.toBukkitEventResult(ee.getUseInteractedBlock())); + e.setUseItemInHand(BukkitHelper.toBukkitEventResult(ee.getUseItemInHand())); + } + + @EventHandler + public void onSignChange(SignChangeEvent e) { + EsPlayer p = new BukkitPlayer(e.getPlayer()); + String[] lines = e.getLines(); + EsSignChangeEvent ee = new EsSignChangeEvent(p, lines); + ee.setCancelled(e.isCancelled()); + Main.callEvent(ee); + e.setCancelled(ee.isCancelled()); + for (int i = 0; i < lines.length; i++) { + e.setLine(i, ee.getLine(i)); + } + } + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + return Main.executeCommand(BukkitHelper.fromBukkitCommandSender(sender), command.getName(), args); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/EventHandlers/BukkitEventsListenerPost1_1.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/EventHandlers/BukkitEventsListenerPost1_1.java new file mode 100644 index 0000000..9ef897c --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/EventHandlers/BukkitEventsListenerPost1_1.java @@ -0,0 +1,68 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.EventHandlers; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsClickType; +import net.serble.estools.ServerApi.EsInventoryAction; +import net.serble.estools.ServerApi.Events.EsInventoryClickEvent; +import net.serble.estools.ServerApi.Events.EsInventoryCloseEvent; +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitPlayer; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitInventoryClickHelper; +import net.serble.estools.ServerApi.Interfaces.EsInventory; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; + +// Apparently inheriting BukkitEventsListener stops the events from working in BukkitEventsListener +public class BukkitEventsListenerPost1_1 implements Listener { + + @EventHandler + public void onInvClick(InventoryClickEvent e) { + EsInventory clInv; + if (Main.minecraftVersion.isAtLeast(1, 8, 0)) { + clInv = BukkitHelper.fromBukkitInventory(e.getClickedInventory()); + } else { + clInv = BukkitHelper.fromBukkitInventory(e.getInventory()); // Get clicked inv doesn't exist + } + + EsInventory inv = BukkitHelper.fromBukkitInventory(e.getInventory()); + + EsClickType ct; + if (Main.minecraftVersion.isAtLeast(1, 5, 0)) { + ct = BukkitInventoryClickHelper.fromBukkitClickType(e.getClick()); + } else { + ct = EsClickType.Unknown; // getClick() doesn't exist in 1.4.x + } + + EsInventoryAction ac; + if (Main.minecraftVersion.isAtLeast(1, 5, 0)) { + ac = BukkitInventoryClickHelper.fromBukkitInventoryAction(e.getAction()); + } else { + ac = EsInventoryAction.Unknown; // getAction() doesn't exist in 1.4.x + } + + EsItemStack ci = BukkitHelper.fromBukkitItem(e.getCurrentItem()); + EsPlayer cl = new BukkitPlayer((Player) e.getWhoClicked()); + EsItemStack cu = BukkitHelper.fromBukkitItem(e.getCursor()); + int sl = e.getSlot(); + EsInventoryClickEvent ee = new EsInventoryClickEvent(cl, sl, cu, inv, clInv, ci, ac, ct); + ee.setCancelled(e.isCancelled()); + boolean wasCancelled = e.isCancelled(); + Main.callEvent(ee); + if (wasCancelled != ee.isCancelled()) { // Fix bug where it cancels + e.setCancelled(ee.isCancelled()); + } + } + + @EventHandler + public void onInvClose(InventoryCloseEvent e) { + EsInventory inv = BukkitHelper.fromBukkitInventory(e.getInventory()); + EsPlayer pl = new BukkitPlayer((Player) e.getPlayer()); + EsInventoryCloseEvent ee = new EsInventoryCloseEvent(pl, inv); + Main.callEvent(ee); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/EventHandlers/BukkitEventsListenerPost1_4.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/EventHandlers/BukkitEventsListenerPost1_4.java new file mode 100644 index 0000000..0edc79c --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/EventHandlers/BukkitEventsListenerPost1_4.java @@ -0,0 +1,32 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.EventHandlers; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.Events.EsInventoryDragEvent; +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitInventoryView; +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitPlayer; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.EsInventory; +import net.serble.estools.ServerApi.Interfaces.EsInventoryView; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryDragEvent; + +import java.util.Set; + +// Apparently inheriting BukkitEventsListener stops the events from working in BukkitEventsListener +public class BukkitEventsListenerPost1_4 implements Listener { + + @EventHandler + public void onDrag(InventoryDragEvent e) { + EsInventory inv = BukkitHelper.fromBukkitInventory(e.getInventory()); + EsPlayer pl = new BukkitPlayer((Player) e.getWhoClicked()); + Set cs = e.getRawSlots(); + EsInventoryView view = new BukkitInventoryView(e.getView()); + EsInventoryDragEvent ee = new EsInventoryDragEvent(pl, inv, cs, view); + ee.setCancelled(e.isCancelled()); + Main.callEvent(ee); + e.setCancelled(ee.isCancelled()); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitConfigMigrator.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitConfigMigrator.java new file mode 100644 index 0000000..1995139 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitConfigMigrator.java @@ -0,0 +1,316 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import net.serble.estools.Commands.Warps.WarpLocation; +import net.serble.estools.Config.ConfigManager; +import net.serble.estools.Config.Schemas.GeneralConfig.EsToolsConfig; +import net.serble.estools.Config.Schemas.GeneralConfig.UpdaterConfig; +import net.serble.estools.Config.Schemas.Give.GiveConfig; +import net.serble.estools.Config.Schemas.Give.GiveSettings; +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsSerialisableItemStack; +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitItemStack; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.configuration.serialization.ConfigurationSerialization; +import org.bukkit.inventory.ItemStack; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.*; + +/** + * Tool for migrating from legacy Bukkit configs to v5 compatible configs. + * Once migration is complete an empty file ".configsmigrated" is created. +*/ +public class BukkitConfigMigrator { + private static final String migratedFile = ".configsmigrated"; + private static final String mainConfig = "config.yml"; + private static final String giveConfig = "give.yml"; + private static final String godsConfig = "gods.yml"; + private static final String buddhaConfig = "buddhas.yml"; + private static final String warpsConfig = "warps.yml"; + private static final String cchestsFolder = "cchests"; + + public static void checkPerformMigration() { + File migratedAlreadyFile = new File(Main.server.getDataFolder(), migratedFile); + + // If we have already migrated, or we have no data to migrate then return + if (migratedAlreadyFile.exists()) { + return; + } + + // If there is no data at all then we don't need to migrate so mark as migrated + if (!Main.server.getDataFolder().exists()) { + try { + boolean ignored = migratedAlreadyFile.getParentFile().mkdirs(); + boolean ignored2 = migratedAlreadyFile.createNewFile(); + } catch (IOException e) { + Main.logger.severe("[EsTools] Failed to create file specifying that configs are migrated"); + } + } + + Main.logger.warning("[EsTools] It seems you are using an outdated config, migrating files to v5"); + + migrateMainConfig(); + migrateGiveConfig(); + migrateGodsConfig(); + migrateWarpsConfig(); + migrateCChestsConfig(); + + Main.logger.info("[EsTools] Successfully migrated all existing config files"); + try { + boolean ignored = migratedAlreadyFile.createNewFile(); + } catch (IOException e) { + Main.logger.severe("[EsTools] Failed to create file specifying that configs are migrated"); + } + } + + private static void migrateMainConfig() { // config.yml + File file = new File(Main.server.getDataFolder(), mainConfig); + if (!file.exists()) { + return; + } + + if (file.length() == 0) { + boolean ignored = file.delete(); + return; + } + + try { // We will now try to get all the values, defaulting to their current defaults + FileConfiguration config = new YamlConfiguration(); + config.load(file); + + EsToolsConfig newConfig = new EsToolsConfig(); + newConfig.setSafeTp(config.getBoolean("safetp", newConfig.isSafeTp())); + newConfig.setMetrics(config.getBoolean("metrics", newConfig.isMetrics())); + + UpdaterConfig updaterConfig = newConfig.getUpdater(); + updaterConfig.setGithubReleasesUrl(config.getString("updater.github-release-url", updaterConfig.getGithubReleasesUrl())); + updaterConfig.setAutoUpdate(config.getBoolean("updater.auto-update", updaterConfig.isAutoUpdate())); + updaterConfig.setWarnOnOutdated(config.getBoolean("updater.warn-on-outdated", updaterConfig.isWarnOnOutdated())); + updaterConfig.setLogOnOutdated(config.getBoolean("updater.log-on-outdated", updaterConfig.isLogOnOutdated())); + + // Move file to file.old + File oldFile = new File(Main.server.getDataFolder(), mainConfig + ".old"); + if (!file.renameTo(oldFile)) { + throw new FileNotFoundException("Failed to rename old config file"); + } + + // Save new config + ConfigManager.save(file, newConfig); + + Main.logger.info("[EsTools] Successfully migrated " + mainConfig); + } catch (IOException | InvalidConfigurationException e) { + Main.logger.severe("[EsTools] Failed to migrate main config, it might be invalid"); + Main.logger.severe("[EsTools] You may need to delete config.yml for it to function again"); + Main.logger.severe("[EsTools] Your current setting ARE NOT BEING RESPECTED"); + } + } + + private static void migrateGiveConfig() { // config.yml + File file = new File(Main.server.getDataFolder(), giveConfig); + if (!file.exists()) { + return; + } + + if (file.length() == 0) { + boolean ignored = file.delete(); + return; + } + + try { // We will now try to get all the values, defaulting to their current defaults + FileConfiguration config = new YamlConfiguration(); + config.load(file); + + GiveConfig newConfig = new GiveConfig(); + GiveSettings settings = newConfig.getSettings(); + settings.setAddWithoutUnderscores(config.getBoolean("settings.addWithoutUnderscores", settings.isAddWithoutUnderscores())); + settings.setRemoveWithUnderscores(config.getBoolean("settings.removeWithUnderscores", settings.isRemoveWithUnderscores())); + + ConfigurationSection itemsSec = config.getConfigurationSection("items"); + if (itemsSec != null) { + Map items = new HashMap<>(); + for (String key : itemsSec.getKeys(false)) { + items.put(key, itemsSec.getString(key)); + } + + newConfig.setItems(items); + } + + // Move file to file.old + File oldFile = new File(Main.server.getDataFolder(), giveConfig + ".old"); + if (!file.renameTo(oldFile)) { + throw new FileNotFoundException("Failed to rename old config file"); + } + + // Save new config + ConfigManager.save(file, newConfig); + + Main.logger.info("[EsTools] Successfully migrated " + giveConfig); + } catch (IOException | InvalidConfigurationException e) { + Main.logger.severe("[EsTools] Failed to migrate config, it might be invalid"); + Main.logger.severe("[EsTools] You may need to delete " + giveConfig + " for it to function again"); + Main.logger.severe("[EsTools] Your current setting ARE NOT BEING RESPECTED"); + } + } + + private static void migrateGodsConfig() { // config.yml + File file = new File(Main.server.getDataFolder(), godsConfig); + if (!file.exists()) { + return; + } + + if (file.length() == 0) { + boolean ignored = file.delete(); + return; + } + + try { // We will now try to get all the values, defaulting to their current defaults + FileConfiguration config = new YamlConfiguration(); + config.load(file); + + List gods = config.getStringList("gods"); + List buddhas = config.getStringList("buddhas"); + + // Move file to file.old + File oldFile = new File(Main.server.getDataFolder(), godsConfig + ".old"); + if (!file.renameTo(oldFile)) { + throw new FileNotFoundException("Failed to rename old config file"); + } + + // Save gods.yml and buddhas.yml + ConfigManager.save(file, gods); + ConfigManager.save(buddhaConfig, buddhas); + + Main.logger.info("[EsTools] Successfully migrated " + godsConfig); + } catch (IOException | InvalidConfigurationException e) { + Main.logger.severe("[EsTools] Failed to migrate config, it might be invalid"); + Main.logger.severe("[EsTools] You may need to delete " + godsConfig + " for it to function again"); + Main.logger.severe("[EsTools] Your current setting ARE NOT BEING RESPECTED"); + } + } + + private static void migrateWarpsConfig() { // config.yml + File file = new File(Main.server.getDataFolder(), warpsConfig); + if (!file.exists()) { + return; + } + + if (file.length() == 0) { + boolean ignored = file.delete(); + return; + } + + try { // We will now try to get all the values, defaulting to their current defaults + // Register the old WarpLocation class, so it can be parsed + ConfigurationSerialization.registerClass(OldWarpLocation.class, "WarpLocation"); + FileConfiguration config = new YamlConfiguration(); + config.load(file); + + Map newConfig = new HashMap<>(); + + List warpList = config.getList("warps"); + if (warpList == null) { + return; + } + + warpList.sort((w1, w2) -> { + if (w1 instanceof OldWarpLocation && w2 instanceof OldWarpLocation) { + OldWarpLocation warp1 = (OldWarpLocation)w1; + OldWarpLocation warp2 = (OldWarpLocation)w1; + + return warp1.name.compareTo(warp2.name); + } + + return 0; + }); + + warpList.forEach(w -> { + if (w instanceof OldWarpLocation) { + OldWarpLocation warp = (OldWarpLocation)w; + WarpLocation loc = new WarpLocation(); + loc.setGlobal(warp.global); + loc.setName(warp.name); + loc.setLocation(BukkitHelper.fromBukkitLocation(warp.location)); + newConfig.put(warp.name, loc); + } + }); + + // Move file to file.old + File oldFile = new File(Main.server.getDataFolder(), warpsConfig + ".old"); + if (!file.renameTo(oldFile)) { + throw new FileNotFoundException("Failed to rename old config file"); + } + + // Save new config + ConfigManager.save(file, newConfig); + + Main.logger.info("[EsTools] Successfully migrated " + warpsConfig); + } catch (IOException | InvalidConfigurationException e) { + Main.logger.severe("[EsTools] Failed to migrate config, it might be invalid"); + Main.logger.severe("[EsTools] You may need to delete " + warpsConfig + " for it to function again"); + Main.logger.severe("[EsTools] Your current setting ARE NOT BEING RESPECTED"); + } + } + + private static void migrateCChestsConfig() { // config.yml + File folder = new File(Main.server.getDataFolder(), cchestsFolder); + + File[] files = folder.listFiles(); + if (files == null) { + return; + } + + List savedPlayers = new ArrayList<>(Arrays.asList(files)); + savedPlayers.removeIf(file -> { + if (file.length() == 0) { + boolean ignored = file.delete(); + return true; + } + + return false; + }); + + Main.logger.warning("[EsTools] Now migrating CChest config files, this may take a while"); + + for (File file : savedPlayers) { + try { // We will now try to get all the values, defaulting to their current defaults + FileConfiguration config = new YamlConfiguration(); + config.load(file); + + if (!config.contains("items")) { + continue; + } + + @SuppressWarnings("unchecked") + ArrayList content = (ArrayList) Objects.requireNonNull(config.get("items")); + + EsSerialisableItemStack[] newConfig = new EsSerialisableItemStack[content.size()]; + for (int i = 0; i < content.size(); i++) { + if (content.get(i) == null) { + newConfig[i] = null; + continue; + } + + newConfig[i] = EsSerialisableItemStack.generate(new BukkitItemStack(content.get(i))); + } + + // Move file to file.old + File oldFile = new File(file.getName() + ".old"); + if (!file.renameTo(oldFile)) { + throw new FileNotFoundException("Failed to rename old config file"); + } + + // Save new config + ConfigManager.save(file, newConfig); + + Main.logger.info("[EsTools] Successfully migrated CChest: " + file.getName()); + } catch (IOException | InvalidConfigurationException e) { + Main.logger.severe("[EsTools] Failed to migrate CChest config, data may be lost"); + } + } + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitEffectHelper.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitEffectHelper.java new file mode 100644 index 0000000..96bb11e --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitEffectHelper.java @@ -0,0 +1,109 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsPotionEffectType; +import org.bukkit.Registry; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.potion.PotionType; + +import java.util.*; + +public class BukkitEffectHelper { + private static final Map OLD_POTIONS = new HashMap<>(); + + // Potion effect types, because getKey() doesnt exist pre 1.18 + private static final Map ES_TO_BUKKIT = new HashMap<>(); + private static final Map BUKKIT_TO_ES = new HashMap<>(); + + public static PotionEffectType toBukkitEffectType(EsPotionEffectType effect) { + return ES_TO_BUKKIT.get(effect); + } + + public static EsPotionEffectType fromBukkitEffectType(PotionEffectType effect) { + return BUKKIT_TO_ES.get(effect); + } + + public static PotionType getPotionFromEffectType(EsPotionEffectType type) { + return OLD_POTIONS.get(type); + } + + public static Set getEffectList() { + return ES_TO_BUKKIT.keySet(); + } + + public static Set getPotionList() { + return OLD_POTIONS.keySet(); + } + + @SuppressWarnings("deprecation") // It's for old versions + public static void load() { + // in 1.8 and below, there were no custom potions, just some hardcoded ones. + // these are PotionTypes, and we need to generate them based on EsPotionEffectTypes + if (Main.minecraftVersion.getMinor() <= 8) { + OLD_POTIONS.put(EsPotionEffectType.createUnchecked("regeneration"), PotionType.REGEN); + OLD_POTIONS.put(EsPotionEffectType.createUnchecked("speed"), PotionType.SPEED); + OLD_POTIONS.put(EsPotionEffectType.createUnchecked("fire_resistance"), PotionType.FIRE_RESISTANCE); + OLD_POTIONS.put(EsPotionEffectType.createUnchecked("poison"), PotionType.POISON); + OLD_POTIONS.put(EsPotionEffectType.createUnchecked("instant_health"), PotionType.INSTANT_HEAL); + OLD_POTIONS.put(EsPotionEffectType.createUnchecked("weakness"), PotionType.WEAKNESS); + OLD_POTIONS.put(EsPotionEffectType.createUnchecked("strength"), PotionType.STRENGTH); + OLD_POTIONS.put(EsPotionEffectType.createUnchecked("slowness"), PotionType.SLOWNESS); + OLD_POTIONS.put(EsPotionEffectType.createUnchecked("instant_damage"), PotionType.INSTANT_DAMAGE); + + if (Main.minecraftVersion.getMinor() >= 4 && Main.minecraftVersion.getMinor() >= 2) { // Night vision was added in 1.4.2 + OLD_POTIONS.put(EsPotionEffectType.createUnchecked("night_vision"), PotionType.NIGHT_VISION); + OLD_POTIONS.put(EsPotionEffectType.createUnchecked("invisibility"), PotionType.INVISIBILITY); + } + + if (Main.minecraftVersion.getMinor() >= 7 && Main.minecraftVersion.getMinor() >= 2) { // 1.7.2 + OLD_POTIONS.put(EsPotionEffectType.createUnchecked("water_breathing"), PotionType.WATER); + } + + if (Main.minecraftVersion.getMinor() >= 8) { // 1.8 + OLD_POTIONS.put(EsPotionEffectType.createUnchecked("jump_boost"), PotionType.JUMP); + } + } + + final HashMap nameReplacers = new HashMap() {{ + put("confusion", "nausea"); + put("damage_resistance", "resistance"); + put("fast_digging", "haste"); + put("harm", "instant_damage"); + put("heal", "instant_health"); + put("increase_damage", "strength"); + put("slow", "slowness"); + put("slow_digging", "mining_fatigue"); + put("jump", "jump_boost"); + }}; + + // Registry.EFFECT was added in 1.20.3... + if (Main.minecraftVersion.isAtLeast(1, 20, 3)) { + for (PotionEffectType type : Registry.EFFECT) { + EsPotionEffectType esType = EsPotionEffectType.createUnchecked(type.getKey().getKey()); + ES_TO_BUKKIT.put(esType, type); + BUKKIT_TO_ES.put(type, esType); + } + } else { + for (PotionEffectType type : PotionEffectType.values()) { + if (type == null) { + continue; + } + + String name; + if (Main.minecraftVersion.getMinor() >= 18) { + name = type.getKey().getKey(); + } else { + name = type.getName(); + + if (nameReplacers.containsKey(name)) { + name = nameReplacers.get(name); + } + } + + EsPotionEffectType esType = EsPotionEffectType.createUnchecked(name); + ES_TO_BUKKIT.put(esType, type); + BUKKIT_TO_ES.put(type, esType); + } + } + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitEnchantmentHelper.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitEnchantmentHelper.java new file mode 100644 index 0000000..c158209 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitEnchantmentHelper.java @@ -0,0 +1,77 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsEnchantment; +import org.bukkit.Registry; +import org.bukkit.enchantments.Enchantment; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +// This class exists because the registry doesn't exist pre 1.13, so all the enchantments names have to be hardcoded. +// only enchantments before 1.13 need to be here because this class isn't used past 1.13 +public class BukkitEnchantmentHelper { + private static final Map ES_TO_BUKKIT = new HashMap<>(); + private static final Map BUKKIT_TO_ES = new HashMap<>(); + + public static EsEnchantment fromBukkitEnchantment(Enchantment ench) { + return BUKKIT_TO_ES.get(ench); + } + + public static Enchantment toBukkitEnchantment(EsEnchantment ench) { + return ES_TO_BUKKIT.get(ench); + } + + public static Set getEnchantmentList() { + return ES_TO_BUKKIT.keySet(); + } + + static { + final HashMap nameReplacers = new HashMap() {{ + put("damage_all", "sharpness"); + put("damage_undead", "smite"); + put("damage_arthropods", "bane_of_arthropods"); + put("dig_speed", "efficiency"); + put("durability", "unbreaking"); + put("loot_bonus_mobs", "looting"); + put("oxygen", "respiration"); + put("protection_environmental", "protection"); + put("protection_explosions", "blast_protection"); + put("protection_fall", "feather_falling"); + put("protection_projectile", "projectile_protection"); + put("water_worker", "aqua_affinity"); + put("arrow_fire", "flame"); + put("arrow_damage", "power"); + put("arrow_knockback", "punch"); + put("arrow_infinite", "infinity"); + put("loot_bonus_blocks", "fortune"); + }}; + + // Registry.ENCHANTMENT was added in 1.14 + if (Main.minecraftVersion.getMinor() > 13) { + for (Enchantment ench : Registry.ENCHANTMENT) { + EsEnchantment esEnch = EsEnchantment.createUnchecked(ench.getKey().getKey()); + ES_TO_BUKKIT.put(esEnch, ench); + BUKKIT_TO_ES.put(ench, esEnch); + } + } else { + for (Enchantment ench : Enchantment.values()) { + String name; + if (Main.minecraftVersion.getMinor() >= 13) { + name = ench.getKey().getKey(); + } else { + name = ench.getName().toLowerCase(); + + if (nameReplacers.containsKey(name)) { + name = nameReplacers.get(name); + } + } + + EsEnchantment esType = EsEnchantment.createUnchecked(name); + ES_TO_BUKKIT.put(esType, ench); + BUKKIT_TO_ES.put(ench, esType); + } + } + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitEnums1_1Plus.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitEnums1_1Plus.java new file mode 100644 index 0000000..f98e1eb --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitEnums1_1Plus.java @@ -0,0 +1,69 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import net.serble.estools.ServerApi.EsTeleportCause; +import org.bukkit.event.player.PlayerTeleportEvent; + +/** + * Min version: 1.1 + */ +@SuppressWarnings("unused") +public class BukkitEnums1_1Plus { + + public static PlayerTeleportEvent.TeleportCause toBukkitTeleportCause(EsTeleportCause esCause) { + switch (esCause) { + case EnderPearl: + return PlayerTeleportEvent.TeleportCause.ENDER_PEARL; + case Command: + return PlayerTeleportEvent.TeleportCause.COMMAND; + case Plugin: + return PlayerTeleportEvent.TeleportCause.PLUGIN; + case NetherPortal: + return PlayerTeleportEvent.TeleportCause.NETHER_PORTAL; + case EndPortal: + return PlayerTeleportEvent.TeleportCause.END_PORTAL; + case Spectate: + return PlayerTeleportEvent.TeleportCause.SPECTATE; + case EndGateway: + return PlayerTeleportEvent.TeleportCause.END_GATEWAY; + case ChorusFruit: + return PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT; + case Dismount: + return PlayerTeleportEvent.TeleportCause.DISMOUNT; + case ExitBed: + return PlayerTeleportEvent.TeleportCause.EXIT_BED; + case Unknown: + return PlayerTeleportEvent.TeleportCause.UNKNOWN; + default: + throw new IllegalArgumentException("Unknown EsTeleportCause: " + esCause); + } + } + + public static EsTeleportCause fromBukkitTeleportCause(PlayerTeleportEvent.TeleportCause bukkitCause) { + switch (bukkitCause) { + case ENDER_PEARL: + return EsTeleportCause.EnderPearl; + case COMMAND: + return EsTeleportCause.Command; + case PLUGIN: + return EsTeleportCause.Plugin; + case NETHER_PORTAL: + return EsTeleportCause.NetherPortal; + case END_PORTAL: + return EsTeleportCause.EndPortal; + case SPECTATE: + return EsTeleportCause.Spectate; + case END_GATEWAY: + return EsTeleportCause.EndGateway; + case CHORUS_FRUIT: + return EsTeleportCause.ChorusFruit; + case DISMOUNT: + return EsTeleportCause.Dismount; + case EXIT_BED: + return EsTeleportCause.ExitBed; + case UNKNOWN: + return EsTeleportCause.Unknown; + default: + throw new IllegalArgumentException("Invalid TeleportCause"); + } + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitEquipmentSlotHelper.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitEquipmentSlotHelper.java new file mode 100644 index 0000000..7f2ed8a --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitEquipmentSlotHelper.java @@ -0,0 +1,44 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import net.serble.estools.ServerApi.EsEquipmentSlot; + +public class BukkitEquipmentSlotHelper { + + public static org.bukkit.inventory.EquipmentSlot toBukkitEquipmentSlot(EsEquipmentSlot slot) { + switch (slot) { + case Feet: + return org.bukkit.inventory.EquipmentSlot.FEET; + case Hand: + return org.bukkit.inventory.EquipmentSlot.HAND; + case Head: + return org.bukkit.inventory.EquipmentSlot.HEAD; + case Legs: + return org.bukkit.inventory.EquipmentSlot.LEGS; + case Chest: + return org.bukkit.inventory.EquipmentSlot.CHEST; + case OffHand: + return org.bukkit.inventory.EquipmentSlot.OFF_HAND; + } + + throw new RuntimeException("idfk"); + } + + public static EsEquipmentSlot fromBukkitEquipmentSlot(org.bukkit.inventory.EquipmentSlot slot) { + switch (slot) { + case FEET: + return EsEquipmentSlot.Feet; + case HAND: + return EsEquipmentSlot.Hand; + case HEAD: + return EsEquipmentSlot.Head; + case LEGS: + return EsEquipmentSlot.Legs; + case CHEST: + return EsEquipmentSlot.Chest; + case OFF_HAND: + return EsEquipmentSlot.OffHand; + default: + throw new IllegalArgumentException("Invalid EquipmentSlot"); + } + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitHelper.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitHelper.java new file mode 100644 index 0000000..e9843c4 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitHelper.java @@ -0,0 +1,406 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import net.serble.estools.Entrypoints.EsToolsBukkit; +import net.serble.estools.ServerApi.*; +import net.serble.estools.Main; +import net.serble.estools.ServerApi.Implementations.Bukkit.*; +import net.serble.estools.ServerApi.Interfaces.*; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.block.Action; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.potion.PotionEffect; +import org.bukkit.util.Vector; + +// DO NOT IMPORT THE FOLLOWING BECAUSE THEY BREAK OLDER VERSIONS BECAUSE THEY DON'T EXIST +// org.bukkit.inventory.EquipmentSlot +// org.bukkit.event.player.PlayerTeleportEvent +// org.bukkit.potion.Potion +// org.bukkit.potion.PotionType +// org.bukkit.inventory.InventoryHolder +// org.bukkit.inventory.meta.PotionMeta +// org.bukkit.inventory.meta.ItemMeta +// org.bukkit.Sound +// org.bukkit.event.inventory.ClickType +// org.bukkit.event.inventory.InventoryAction + +/** + * Min version: 1.0 + */ +@SuppressWarnings("unused") +public class BukkitHelper { + public static Location toBukkitLocation(EsLocation loc) { + Location bLoc = new Location(Bukkit.getWorld(loc.getWorld().getName()), loc.getX(), loc.getY(), loc.getZ()); + bLoc.setPitch((float) loc.getPitch()); + bLoc.setYaw((float) loc.getYaw()); + return bLoc; + } + + public static EsLocation fromBukkitLocation(Location loc) { + return new EsLocation( + new BukkitWorld(loc.getWorld()), + fromVector(loc.getDirection()), + loc.getX(), + loc.getY(), + loc.getZ(), + loc.getYaw(), + loc.getPitch()); + } + + public static Sound toBukkitSound(EsSound sound) { + if (Main.minecraftVersion.isAtLeast(1, 16, 4)) { + return Registry.SOUNDS.get(NamespacedKey.minecraft(sound.getKey())); + } else { + return Sound.valueOf(BukkitSoundEnumConverter.convertKeyToEnum(sound)); + } + } + + public static EsSound fromBukkitSound(Sound sound) { + if (Main.minecraftVersion.isAtLeast(1, 16, 4)) { + return EsSound.createUnchecked(sound.getKey().getKey()); + } else { + return BukkitSoundEnumConverter.convertEnumToKey(sound.name()); + } + } + + public static Position fromVector(Vector vec) { + return new Position(vec.getX(), vec.getY(), vec.getZ()); + } + + public static Vector toVector(Position pos) { + return new Vector(pos.getX(), pos.getY(), pos.getZ()); + } + + public static EsCommandSender fromBukkitCommandSender(CommandSender sender) { + if (sender == null) { + return null; + } + + if (sender instanceof Player) { + return new BukkitPlayer((Player) sender); + } + + if (sender instanceof LivingEntity) { + return new BukkitLivingEntity((LivingEntity) sender); + } + + if (sender instanceof Entity) { + return new BukkitEntity((Entity) sender); + } + + if (sender instanceof ConsoleCommandSender) { + return new BukkitConsoleSender((ConsoleCommandSender) sender); + } + + if (sender instanceof BlockCommandSender) { + return new BukkitCommandBlockSender((BlockCommandSender) sender); + } + + throw new RuntimeException("Unrecognised command sender"); + } + + public static CommandSender toBukkitCommandSender(EsCommandSender sender) { + if (sender instanceof EsPlayer) { + return ((BukkitPlayer) sender).getBukkitPlayer(); + } + + if (sender instanceof EsLivingEntity) { + return ((BukkitLivingEntity) sender).getBukkitEntity(); + } + + if (sender instanceof EsEntity) { + return ((BukkitEntity) sender).getBukkitEntity(); + } + + if (sender instanceof EsConsoleSender) { + return Bukkit.getConsoleSender(); + } + + if (sender instanceof EsCommandBlockSender) { + return ((BukkitCommandBlockSender) sender).getBukkitSender(); + } + + throw new RuntimeException("Unrecognised command sender"); + } + + public static EsEntity fromBukkitEntity(Entity entity) { + if (entity instanceof Player) { + return new BukkitPlayer((Player) entity); + } + + if (entity instanceof LivingEntity) { + return new BukkitLivingEntity((LivingEntity) entity); + } + + return new BukkitEntity(entity); + } + + public static GameMode toBukkitGameMode(EsGameMode mode) { + switch (mode) { + case Creative: + return GameMode.CREATIVE; + case Survival: + return GameMode.SURVIVAL; + case Adventure: + return GameMode.ADVENTURE; + case Spectator: + return GameMode.SPECTATOR; + } + + throw new RuntimeException("Invalid GameMode"); + } + + public static EsGameMode fromBukkitGameMode(GameMode mode) { + switch (mode) { + case CREATIVE: + return EsGameMode.Creative; + case SURVIVAL: + return EsGameMode.Survival; + case ADVENTURE: + return EsGameMode.Adventure; + case SPECTATOR: + return EsGameMode.Spectator; + } + + throw new RuntimeException("Invalid GameMode"); + } + + public static EsBlock fromBukkitBlock(Block block) { + if (block == null) { + return null; + } + + BlockState state = block.getState(); + return fromBukkitBlock(state); + } + + @SuppressWarnings("rawtypes") + public static PersistentDataType toBukkitPersistentDataType(EsPersistentDataType type) { + switch (type) { + case Byte: + return PersistentDataType.BYTE; + case Long: + return PersistentDataType.LONG; + case Float: + return PersistentDataType.FLOAT; + case Short: + return PersistentDataType.SHORT; + case Double: + return PersistentDataType.DOUBLE; + case String: + return PersistentDataType.STRING; + case Boolean: + return PersistentDataType.BOOLEAN; + case Integer: + return PersistentDataType.INTEGER; + case IntArray: + return PersistentDataType.INTEGER_ARRAY; + case ByteArray: + return PersistentDataType.BYTE_ARRAY; + case LongArray: + return PersistentDataType.LONG_ARRAY; + } + + throw new RuntimeException("Unsupported data type"); + } + + @SuppressWarnings("UnstableApiUsage") + public static NamespacedKey getNamespacedKey(String keyString) { + if (Main.minecraftVersion.getMinor() >= 17) { + return NamespacedKey.fromString(keyString, EsToolsBukkit.plugin); + } + + String[] parts = keyString.split(":"); + if (parts.length == 2) { + return new NamespacedKey(parts[0], parts[1]); + } else if (parts.length == 1) { // Incorrectly formatted key + String pluginName = Main.server.getPluginName(); + return new NamespacedKey(pluginName, parts[0]); + } + + return null; + } + + public static EsBlock fromBukkitBlock(BlockState block) { + if (block == null) { + return null; + } + + if (block instanceof Sign) { + return new BukkitSign((Sign) block); + } + + return new BukkitBlock(block); + } + + public static EsItemStack fromBukkitItem(ItemStack item) { + if (item == null) { + return null; + } + + if (Main.minecraftVersion.getMinor() >= 9) { + if (item.getItemMeta() != null && item.getItemMeta() instanceof PotionMeta) { + return new BukkitPotion(item); + } + + return new BukkitItemStack(item); + } else if (Main.minecraftVersion.getMinor() >= 4) { + if (item.getType().name().endsWith("POTION")) { + return new BukkitPotion(item); + } + + return new BukkitItemStack(item); + } else { + if (item.getType().name().endsWith("POTION")) { + return new BukkitPotionVeryOld(item); // The Potion and PotionMeta classes don't exist + } + + return new BukkitItemStack(item); + } + } + + public static EsPotType fromBukkitPotType(Material type) { + return fromBukkitPotType(type.name()); + } + + public static EsPotType fromBukkitPotType(String type) { + switch (type) { + case "SPLASH_POTION": + return EsPotType.splash; + case "POTION": + return EsPotType.drink; + case "LINGERING_POTION": + return EsPotType.lingering; + } + + return null; + } + + public static PotionEffect toBukkitPotionEffect(EsPotionEffect effect) { + return new PotionEffect(BukkitEffectHelper.toBukkitEffectType(effect.getType()), effect.getDuration(), effect.getAmp()); + } + + public static EsPotionEffect fromBukkitPotionEffect(PotionEffect effect) { + return new EsPotionEffect(BukkitEffectHelper.fromBukkitEffectType(effect.getType()), effect.getAmplifier(), effect.getDuration()); + } + + public static Material toBukkitMaterial(EsMaterial mat) { + if (Main.minecraftVersion.getMinor() > 13) { + return Registry.MATERIAL.get(NamespacedKey.minecraft(mat.getKey())); + } + + return Material.valueOf(mat.getKey().toUpperCase()); + } + + public static EsMaterial fromBukkitMaterial(Material mat) { + if (Main.minecraftVersion.getMinor() > 13) { + return EsMaterial.createUnchecked(mat.getKey().getKey()); + } + + return EsMaterial.createUnchecked(mat.name()); + } + + public static boolean isFolia() { + try { + Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } + + public static SoundCategory toBukkitSoundCategory(EsSoundCategory esSoundCategory) { + switch (esSoundCategory) { + case Master: + return SoundCategory.MASTER; + case Music: + return SoundCategory.MUSIC; + case Records: + return SoundCategory.RECORDS; + case Weather: + return SoundCategory.WEATHER; + case Blocks: + return SoundCategory.BLOCKS; + case Hostile: + return SoundCategory.HOSTILE; + case Neutral: + return SoundCategory.NEUTRAL; + case Players: + return SoundCategory.PLAYERS; + case Ambient: + return SoundCategory.AMBIENT; + case Voice: + return SoundCategory.VOICE; + default: + throw new IllegalArgumentException("Invalid EsSoundCategory"); + } + } + + public static EsAction fromBukkitAction(Action action) { + switch (action) { + case LEFT_CLICK_BLOCK: + return EsAction.LeftClickBlock; + case RIGHT_CLICK_BLOCK: + return EsAction.RightClickBlock; + case LEFT_CLICK_AIR: + return EsAction.LeftClickAir; + case RIGHT_CLICK_AIR: + return EsAction.RightClickAir; + case PHYSICAL: + return EsAction.Physical; + default: + throw new IllegalArgumentException("Invalid Action"); + } + } + + public static EsInventory fromBukkitInventory(Inventory inv) { + if (inv == null) { + return null; + } + + if (inv instanceof PlayerInventory) { + return new BukkitPlayerInventory((PlayerInventory) inv); + } + + return new BukkitInventory(inv); + } + + public static EsEventResult fromBukkitEventResult(Event.Result result) { + switch (result) { + case ALLOW: + return EsEventResult.ALLOW; + case DENY: + return EsEventResult.DENY; + case DEFAULT: + return EsEventResult.DEFAULT; + default: + throw new IllegalArgumentException("Invalid Event.Result"); + } + } + + public static Event.Result toBukkitEventResult(EsEventResult result) { + switch (result) { + case ALLOW: + return Event.Result.ALLOW; + case DENY: + return Event.Result.DENY; + case DEFAULT: + return Event.Result.DEFAULT; + default: + throw new IllegalArgumentException("Invalid EsEventResult"); + } + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitInventoryClickHelper.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitInventoryClickHelper.java new file mode 100644 index 0000000..2bf438f --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitInventoryClickHelper.java @@ -0,0 +1,172 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import net.serble.estools.ServerApi.EsClickType; +import net.serble.estools.ServerApi.EsInventoryAction; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryAction; + +/** + * Min version: 1.5 + */ +@SuppressWarnings("unused") +public class BukkitInventoryClickHelper { + public static EsInventoryAction fromBukkitInventoryAction(InventoryAction action) { + switch (action) { + case NOTHING: + return EsInventoryAction.Nothing; + case PICKUP_ALL: + return EsInventoryAction.PickupAll; + case PICKUP_SOME: + return EsInventoryAction.PickupSome; + case PICKUP_HALF: + return EsInventoryAction.PickupHalf; + case PICKUP_ONE: + return EsInventoryAction.PickupOne; + case PLACE_ALL: + return EsInventoryAction.PlaceAll; + case PLACE_SOME: + return EsInventoryAction.PlaceSome; + case PLACE_ONE: + return EsInventoryAction.PlaceOne; + case SWAP_WITH_CURSOR: + return EsInventoryAction.SwapWithCursor; + case DROP_ALL_CURSOR: + return EsInventoryAction.DropAllCursor; + case DROP_ONE_CURSOR: + return EsInventoryAction.DropOneCursor; + case DROP_ALL_SLOT: + return EsInventoryAction.DropAllSlot; + case DROP_ONE_SLOT: + return EsInventoryAction.DropOneSlot; + case MOVE_TO_OTHER_INVENTORY: + return EsInventoryAction.MoveToOtherInventory; + case HOTBAR_MOVE_AND_READD: + return EsInventoryAction.HotbarMoveAndReadd; + case HOTBAR_SWAP: + return EsInventoryAction.HotbarSwap; + case CLONE_STACK: + return EsInventoryAction.CloneStack; + case COLLECT_TO_CURSOR: + return EsInventoryAction.CollectToCursor; + case UNKNOWN: + return EsInventoryAction.Unknown; + default: + throw new IllegalArgumentException("Invalid InventoryAction"); + } + } + + public static InventoryAction toBukkitInventoryAction(EsInventoryAction esAction) { + switch (esAction) { + case Nothing: + return InventoryAction.NOTHING; + case PickupAll: + return InventoryAction.PICKUP_ALL; + case PickupSome: + return InventoryAction.PICKUP_SOME; + case PickupHalf: + return InventoryAction.PICKUP_HALF; + case PickupOne: + return InventoryAction.PICKUP_ONE; + case PlaceAll: + return InventoryAction.PLACE_ALL; + case PlaceSome: + return InventoryAction.PLACE_SOME; + case PlaceOne: + return InventoryAction.PLACE_ONE; + case SwapWithCursor: + return InventoryAction.SWAP_WITH_CURSOR; + case DropAllCursor: + return InventoryAction.DROP_ALL_CURSOR; + case DropOneCursor: + return InventoryAction.DROP_ONE_CURSOR; + case DropAllSlot: + return InventoryAction.DROP_ALL_SLOT; + case DropOneSlot: + return InventoryAction.DROP_ONE_SLOT; + case MoveToOtherInventory: + return InventoryAction.MOVE_TO_OTHER_INVENTORY; + case HotbarMoveAndReadd: + return InventoryAction.HOTBAR_MOVE_AND_READD; + case HotbarSwap: + return InventoryAction.HOTBAR_SWAP; + case CloneStack: + return InventoryAction.CLONE_STACK; + case CollectToCursor: + return InventoryAction.COLLECT_TO_CURSOR; + case Unknown: + return InventoryAction.UNKNOWN; + default: + throw new IllegalArgumentException("Invalid EsInventoryAction"); + } + } + + public static EsClickType fromBukkitClickType(ClickType click) { + switch (click) { + case CREATIVE: + return EsClickType.Creative; + case DROP: + return EsClickType.Drop; + case LEFT: + return EsClickType.Left; + case RIGHT: + return EsClickType.Right; + case SHIFT_LEFT: + return EsClickType.ShiftLeft; + case SHIFT_RIGHT: + return EsClickType.ShiftRight; + case MIDDLE: + return EsClickType.Middle; + case UNKNOWN: + return EsClickType.Unknown; + case NUMBER_KEY: + return EsClickType.NumberKey; + case CONTROL_DROP: + return EsClickType.ControlDrop; + case DOUBLE_CLICK: + return EsClickType.DoubleClick; + case SWAP_OFFHAND: + return EsClickType.SwapOffhand; + case WINDOW_BORDER_LEFT: + return EsClickType.WindowBorderLeft; + case WINDOW_BORDER_RIGHT: + return EsClickType.WindowBorderRight; + default: + throw new RuntimeException("Invalid click type"); + } + } + + public static ClickType toBukkitClickType(EsClickType esClick) { + switch (esClick) { + case Creative: + return ClickType.CREATIVE; + case Drop: + return ClickType.DROP; + case Left: + return ClickType.LEFT; + case Right: + return ClickType.RIGHT; + case ShiftLeft: + return ClickType.SHIFT_LEFT; + case ShiftRight: + return ClickType.SHIFT_RIGHT; + case Middle: + return ClickType.MIDDLE; + case Unknown: + return ClickType.UNKNOWN; + case NumberKey: + return ClickType.NUMBER_KEY; + case ControlDrop: + return ClickType.CONTROL_DROP; + case DoubleClick: + return ClickType.DOUBLE_CLICK; + case SwapOffhand: + return ClickType.SWAP_OFFHAND; + case WindowBorderLeft: + return ClickType.WINDOW_BORDER_LEFT; + case WindowBorderRight: + return ClickType.WINDOW_BORDER_RIGHT; + default: + throw new IllegalArgumentException("Invalid EsClickType"); + } + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitInventoryHelper.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitInventoryHelper.java new file mode 100644 index 0000000..460bd9a --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitInventoryHelper.java @@ -0,0 +1,15 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitPlayer; +import net.serble.estools.ServerApi.Interfaces.EsInventory; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import org.bukkit.Bukkit; +import org.bukkit.inventory.InventoryHolder; + +public class BukkitInventoryHelper { + + public static EsInventory createInventory(EsPlayer owner, int size, String title) { + InventoryHolder holder = owner == null ? null : ((BukkitPlayer) owner).getBukkitPlayer(); + return BukkitHelper.fromBukkitInventory(Bukkit.createInventory(holder, size, title)); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitMetaHelper.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitMetaHelper.java new file mode 100644 index 0000000..ef017e1 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitMetaHelper.java @@ -0,0 +1,29 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import net.serble.estools.ServerApi.EsPotionEffect; +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitItemMeta; +import net.serble.estools.ServerApi.Interfaces.EsItemMeta; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.PotionMeta; + +/** + * Min version: 1.4 + */ +public class BukkitMetaHelper { + + public static void setPotionType(ItemStack pot, EsPotionEffect effect) { + PotionMeta meta = (PotionMeta) pot.getItemMeta(); + assert meta != null; + meta.addCustomEffect(BukkitHelper.toBukkitPotionEffect(effect), true); + pot.setItemMeta(meta); + } + + public static EsItemMeta fromBukkitItemMeta(ItemMeta meta) { + if (meta == null) { + return null; + } + + return new BukkitItemMeta(meta); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitPotionsHelper.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitPotionsHelper.java new file mode 100644 index 0000000..a4b6d90 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitPotionsHelper.java @@ -0,0 +1,48 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsPotType; +import net.serble.estools.ServerApi.EsPotionEffect; +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitPotion; +import net.serble.estools.ServerApi.Interfaces.EsPotion; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.Potion; +import org.bukkit.potion.PotionType; + +/** + * Min version: 1.4 + */ +@SuppressWarnings("deprecation") // Old versions go brrrr +public class BukkitPotionsHelper { + + /** Used for 1.4-1.8 */ + public static EsPotion createPotion1_4(EsPotType potType, EsPotionEffect effect, int amount) { + PotionType type = BukkitEffectHelper.getPotionFromEffectType(effect.getType()); + if (type == null) { // This can fail if the effect doesn't have a potion for it + return null; + } + + // in 1.7 and below potions start at amplifier 1, and can only be 1 or 2, after that it starts at 0 + int amplifier = effect.getAmp(); + if (Main.minecraftVersion.getMinor() <= 8) { + amplifier++; + if (amplifier < 1 || amplifier > 2) { + return null; + } + } + + Potion potion = new Potion(type, amplifier); + potion.setSplash(potType == EsPotType.splash); + + return new BukkitPotion(potion.toItemStack(amount)); + } + + /** Used for 1.4-1.8 */ + public static EsPotion createPotion1_4(EsPotType potType) { + Potion potion = Potion.fromItemStack(new ItemStack(Material.valueOf("POTION"))); + potion.setSplash(potType == EsPotType.splash); + + return new BukkitPotion(potion.toItemStack(1)); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitPotionsHelper1_3.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitPotionsHelper1_3.java new file mode 100644 index 0000000..0fa5c84 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitPotionsHelper1_3.java @@ -0,0 +1,40 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import net.serble.estools.ServerApi.EsPotionEffectType; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class BukkitPotionsHelper1_3 { + private static final Map POTIONS = new HashMap<>(); + + static { // Potion Type IDs https://minecraft.wiki/w/Java_Edition_data_values/Pre-flattening#%22Potion_effect%22_bits + POTIONS.put(EsPotionEffectType.createUnchecked("regeneration"), (short) 1); + POTIONS.put(EsPotionEffectType.createUnchecked("speed"), (short) 2); + POTIONS.put(EsPotionEffectType.createUnchecked("fire_resistance"), (short) 3); + POTIONS.put(EsPotionEffectType.createUnchecked("poison"), (short) 4); + POTIONS.put(EsPotionEffectType.createUnchecked("instant_health"), (short) 5); + POTIONS.put(EsPotionEffectType.createUnchecked("weakness"), (short) 8); + POTIONS.put(EsPotionEffectType.createUnchecked("strength"), (short) 9); + POTIONS.put(EsPotionEffectType.createUnchecked("slowness"), (short) 10); + POTIONS.put(EsPotionEffectType.createUnchecked("instant_damage"), (short) 12); + } + + public static short getPotionIdFromEffectType(EsPotionEffectType type) { + return POTIONS.get(type); + } + + public static EsPotionEffectType getEffectTypeFromRawId(short id) { + for (Map.Entry entry : POTIONS.entrySet()) { + if (entry.getValue() == id) { + return entry.getKey(); + } + } + return null; + } + + public static Set getPotionList() { + return POTIONS.keySet(); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitSoundEnumConverter.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitSoundEnumConverter.java new file mode 100644 index 0000000..129cc08 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitSoundEnumConverter.java @@ -0,0 +1,1053 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsSound; + +/** + * This class converts the Sound.name() to an EsSound, EsSounds use the sound key and Sound.name() is a semi arbitrary + * name, since there is no way to differentiate between underscores and dots in Sound.name() names, + * I generated a switch statement that converts between them. + *

+ * This was generated from minecraft 1.16.5, newer versions can use Sound.getKey().getKey() to get this info. + *

+ * Unfortunately, some old keys will be different, but I made Records convert to the new types. + */ +public class BukkitSoundEnumConverter { + public static String convertKeyToEnum(EsSound sound) { + String key = sound.getKey(); + + // music discs used ot be called records + if (Main.minecraftVersion.getMinor() <= 12) { + switch (key) { + case "music_disc.11": return "RECORD_11"; + case "music_disc.13": return "RECORD_13"; + case "music_disc.blocks": return "RECORD_BLOCKS"; + case "music_disc.cat": return "RECORD_CAT"; + case "music_disc.chirp": return "RECORD_CHIRP"; + case "music_disc.far": return "RECORD_FAR"; + case "music_disc.mall": return "RECORD_MALL"; + case "music_disc.mellohi": return "RECORD_MELLOHI"; + case "music_disc.stal": return "RECORD_STAL"; + case "music_disc.strad": return "RECORD_STRAD"; + case "music_disc.wait": return "RECORD_WAIT"; + case "music_disc.ward": return "RECORD_WARD"; + } + } + + return key.toUpperCase().replace('.', '_'); + } + + public static EsSound convertEnumToKey(String eVal) { + switch (eVal) { + case "AMBIENT_BASALT_DELTAS_ADDITIONS": return EsSound.createUnchecked("ambient.basalt_deltas.additions"); + case "AMBIENT_BASALT_DELTAS_LOOP": return EsSound.createUnchecked("ambient.basalt_deltas.loop"); + case "AMBIENT_BASALT_DELTAS_MOOD": return EsSound.createUnchecked("ambient.basalt_deltas.mood"); + case "AMBIENT_CAVE": return EsSound.createUnchecked("ambient.cave"); + case "AMBIENT_CRIMSON_FOREST_ADDITIONS": return EsSound.createUnchecked("ambient.crimson_forest.additions"); + case "AMBIENT_CRIMSON_FOREST_LOOP": return EsSound.createUnchecked("ambient.crimson_forest.loop"); + case "AMBIENT_CRIMSON_FOREST_MOOD": return EsSound.createUnchecked("ambient.crimson_forest.mood"); + case "AMBIENT_NETHER_WASTES_ADDITIONS": return EsSound.createUnchecked("ambient.nether_wastes.additions"); + case "AMBIENT_NETHER_WASTES_LOOP": return EsSound.createUnchecked("ambient.nether_wastes.loop"); + case "AMBIENT_NETHER_WASTES_MOOD": return EsSound.createUnchecked("ambient.nether_wastes.mood"); + case "AMBIENT_SOUL_SAND_VALLEY_ADDITIONS": return EsSound.createUnchecked("ambient.soul_sand_valley.additions"); + case "AMBIENT_SOUL_SAND_VALLEY_LOOP": return EsSound.createUnchecked("ambient.soul_sand_valley.loop"); + case "AMBIENT_SOUL_SAND_VALLEY_MOOD": return EsSound.createUnchecked("ambient.soul_sand_valley.mood"); + case "AMBIENT_UNDERWATER_ENTER": return EsSound.createUnchecked("ambient.underwater.enter"); + case "AMBIENT_UNDERWATER_EXIT": return EsSound.createUnchecked("ambient.underwater.exit"); + case "AMBIENT_UNDERWATER_LOOP": return EsSound.createUnchecked("ambient.underwater.loop"); + case "AMBIENT_UNDERWATER_LOOP_ADDITIONS": return EsSound.createUnchecked("ambient.underwater.loop.additions"); + case "AMBIENT_UNDERWATER_LOOP_ADDITIONS_RARE": return EsSound.createUnchecked("ambient.underwater.loop.additions.rare"); + case "AMBIENT_UNDERWATER_LOOP_ADDITIONS_ULTRA_RARE": return EsSound.createUnchecked("ambient.underwater.loop.additions.ultra_rare"); + case "AMBIENT_WARPED_FOREST_ADDITIONS": return EsSound.createUnchecked("ambient.warped_forest.additions"); + case "AMBIENT_WARPED_FOREST_LOOP": return EsSound.createUnchecked("ambient.warped_forest.loop"); + case "AMBIENT_WARPED_FOREST_MOOD": return EsSound.createUnchecked("ambient.warped_forest.mood"); + case "BLOCK_ANCIENT_DEBRIS_BREAK": return EsSound.createUnchecked("block.ancient_debris.break"); + case "BLOCK_ANCIENT_DEBRIS_FALL": return EsSound.createUnchecked("block.ancient_debris.fall"); + case "BLOCK_ANCIENT_DEBRIS_HIT": return EsSound.createUnchecked("block.ancient_debris.hit"); + case "BLOCK_ANCIENT_DEBRIS_PLACE": return EsSound.createUnchecked("block.ancient_debris.place"); + case "BLOCK_ANCIENT_DEBRIS_STEP": return EsSound.createUnchecked("block.ancient_debris.step"); + case "BLOCK_ANVIL_BREAK": return EsSound.createUnchecked("block.anvil.break"); + case "BLOCK_ANVIL_DESTROY": return EsSound.createUnchecked("block.anvil.destroy"); + case "BLOCK_ANVIL_FALL": return EsSound.createUnchecked("block.anvil.fall"); + case "BLOCK_ANVIL_HIT": return EsSound.createUnchecked("block.anvil.hit"); + case "BLOCK_ANVIL_LAND": return EsSound.createUnchecked("block.anvil.land"); + case "BLOCK_ANVIL_PLACE": return EsSound.createUnchecked("block.anvil.place"); + case "BLOCK_ANVIL_STEP": return EsSound.createUnchecked("block.anvil.step"); + case "BLOCK_ANVIL_USE": return EsSound.createUnchecked("block.anvil.use"); + case "BLOCK_BAMBOO_BREAK": return EsSound.createUnchecked("block.bamboo.break"); + case "BLOCK_BAMBOO_FALL": return EsSound.createUnchecked("block.bamboo.fall"); + case "BLOCK_BAMBOO_HIT": return EsSound.createUnchecked("block.bamboo.hit"); + case "BLOCK_BAMBOO_PLACE": return EsSound.createUnchecked("block.bamboo.place"); + case "BLOCK_BAMBOO_SAPLING_BREAK": return EsSound.createUnchecked("block.bamboo_sapling.break"); + case "BLOCK_BAMBOO_SAPLING_HIT": return EsSound.createUnchecked("block.bamboo_sapling.hit"); + case "BLOCK_BAMBOO_SAPLING_PLACE": return EsSound.createUnchecked("block.bamboo_sapling.place"); + case "BLOCK_BAMBOO_STEP": return EsSound.createUnchecked("block.bamboo.step"); + case "BLOCK_BARREL_CLOSE": return EsSound.createUnchecked("block.barrel.close"); + case "BLOCK_BARREL_OPEN": return EsSound.createUnchecked("block.barrel.open"); + case "BLOCK_BASALT_BREAK": return EsSound.createUnchecked("block.basalt.break"); + case "BLOCK_BASALT_FALL": return EsSound.createUnchecked("block.basalt.fall"); + case "BLOCK_BASALT_HIT": return EsSound.createUnchecked("block.basalt.hit"); + case "BLOCK_BASALT_PLACE": return EsSound.createUnchecked("block.basalt.place"); + case "BLOCK_BASALT_STEP": return EsSound.createUnchecked("block.basalt.step"); + case "BLOCK_BEACON_ACTIVATE": return EsSound.createUnchecked("block.beacon.activate"); + case "BLOCK_BEACON_AMBIENT": return EsSound.createUnchecked("block.beacon.ambient"); + case "BLOCK_BEACON_DEACTIVATE": return EsSound.createUnchecked("block.beacon.deactivate"); + case "BLOCK_BEACON_POWER_SELECT": return EsSound.createUnchecked("block.beacon.power_select"); + case "BLOCK_BEEHIVE_DRIP": return EsSound.createUnchecked("block.beehive.drip"); + case "BLOCK_BEEHIVE_ENTER": return EsSound.createUnchecked("block.beehive.enter"); + case "BLOCK_BEEHIVE_EXIT": return EsSound.createUnchecked("block.beehive.exit"); + case "BLOCK_BEEHIVE_SHEAR": return EsSound.createUnchecked("block.beehive.shear"); + case "BLOCK_BEEHIVE_WORK": return EsSound.createUnchecked("block.beehive.work"); + case "BLOCK_BELL_RESONATE": return EsSound.createUnchecked("block.bell.resonate"); + case "BLOCK_BELL_USE": return EsSound.createUnchecked("block.bell.use"); + case "BLOCK_BLASTFURNACE_FIRE_CRACKLE": return EsSound.createUnchecked("block.blastfurnace.fire_crackle"); + case "BLOCK_BONE_BLOCK_BREAK": return EsSound.createUnchecked("block.bone_block.break"); + case "BLOCK_BONE_BLOCK_FALL": return EsSound.createUnchecked("block.bone_block.fall"); + case "BLOCK_BONE_BLOCK_HIT": return EsSound.createUnchecked("block.bone_block.hit"); + case "BLOCK_BONE_BLOCK_PLACE": return EsSound.createUnchecked("block.bone_block.place"); + case "BLOCK_BONE_BLOCK_STEP": return EsSound.createUnchecked("block.bone_block.step"); + case "BLOCK_BREWING_STAND_BREW": return EsSound.createUnchecked("block.brewing_stand.brew"); + case "BLOCK_BUBBLE_COLUMN_BUBBLE_POP": return EsSound.createUnchecked("block.bubble_column.bubble_pop"); + case "BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT": return EsSound.createUnchecked("block.bubble_column.upwards_ambient"); + case "BLOCK_BUBBLE_COLUMN_UPWARDS_INSIDE": return EsSound.createUnchecked("block.bubble_column.upwards_inside"); + case "BLOCK_BUBBLE_COLUMN_WHIRLPOOL_AMBIENT": return EsSound.createUnchecked("block.bubble_column.whirlpool_ambient"); + case "BLOCK_BUBBLE_COLUMN_WHIRLPOOL_INSIDE": return EsSound.createUnchecked("block.bubble_column.whirlpool_inside"); + case "BLOCK_CAMPFIRE_CRACKLE": return EsSound.createUnchecked("block.campfire.crackle"); + case "BLOCK_CHAIN_BREAK": return EsSound.createUnchecked("block.chain.break"); + case "BLOCK_CHAIN_FALL": return EsSound.createUnchecked("block.chain.fall"); + case "BLOCK_CHAIN_HIT": return EsSound.createUnchecked("block.chain.hit"); + case "BLOCK_CHAIN_PLACE": return EsSound.createUnchecked("block.chain.place"); + case "BLOCK_CHAIN_STEP": return EsSound.createUnchecked("block.chain.step"); + case "BLOCK_CHEST_CLOSE": return EsSound.createUnchecked("block.chest.close"); + case "BLOCK_CHEST_LOCKED": return EsSound.createUnchecked("block.chest.locked"); + case "BLOCK_CHEST_OPEN": return EsSound.createUnchecked("block.chest.open"); + case "BLOCK_CHORUS_FLOWER_DEATH": return EsSound.createUnchecked("block.chorus_flower.death"); + case "BLOCK_CHORUS_FLOWER_GROW": return EsSound.createUnchecked("block.chorus_flower.grow"); + case "BLOCK_COMPARATOR_CLICK": return EsSound.createUnchecked("block.comparator.click"); + case "BLOCK_COMPOSTER_EMPTY": return EsSound.createUnchecked("block.composter.empty"); + case "BLOCK_COMPOSTER_FILL": return EsSound.createUnchecked("block.composter.fill"); + case "BLOCK_COMPOSTER_FILL_SUCCESS": return EsSound.createUnchecked("block.composter.fill_success"); + case "BLOCK_COMPOSTER_READY": return EsSound.createUnchecked("block.composter.ready"); + case "BLOCK_CONDUIT_ACTIVATE": return EsSound.createUnchecked("block.conduit.activate"); + case "BLOCK_CONDUIT_AMBIENT": return EsSound.createUnchecked("block.conduit.ambient"); + case "BLOCK_CONDUIT_AMBIENT_SHORT": return EsSound.createUnchecked("block.conduit.ambient.short"); + case "BLOCK_CONDUIT_ATTACK_TARGET": return EsSound.createUnchecked("block.conduit.attack.target"); + case "BLOCK_CONDUIT_DEACTIVATE": return EsSound.createUnchecked("block.conduit.deactivate"); + case "BLOCK_CORAL_BLOCK_BREAK": return EsSound.createUnchecked("block.coral_block.break"); + case "BLOCK_CORAL_BLOCK_FALL": return EsSound.createUnchecked("block.coral_block.fall"); + case "BLOCK_CORAL_BLOCK_HIT": return EsSound.createUnchecked("block.coral_block.hit"); + case "BLOCK_CORAL_BLOCK_PLACE": return EsSound.createUnchecked("block.coral_block.place"); + case "BLOCK_CORAL_BLOCK_STEP": return EsSound.createUnchecked("block.coral_block.step"); + case "BLOCK_CROP_BREAK": return EsSound.createUnchecked("block.crop.break"); + case "BLOCK_DISPENSER_DISPENSE": return EsSound.createUnchecked("block.dispenser.dispense"); + case "BLOCK_DISPENSER_FAIL": return EsSound.createUnchecked("block.dispenser.fail"); + case "BLOCK_DISPENSER_LAUNCH": return EsSound.createUnchecked("block.dispenser.launch"); + case "BLOCK_ENCHANTMENT_TABLE_USE": return EsSound.createUnchecked("block.enchantment_table.use"); + case "BLOCK_ENDER_CHEST_CLOSE": return EsSound.createUnchecked("block.ender_chest.close"); + case "BLOCK_ENDER_CHEST_OPEN": return EsSound.createUnchecked("block.ender_chest.open"); + case "BLOCK_END_GATEWAY_SPAWN": return EsSound.createUnchecked("block.end_gateway.spawn"); + case "BLOCK_END_PORTAL_FRAME_FILL": return EsSound.createUnchecked("block.end_portal_frame.fill"); + case "BLOCK_END_PORTAL_SPAWN": return EsSound.createUnchecked("block.end_portal.spawn"); + case "BLOCK_FENCE_GATE_CLOSE": return EsSound.createUnchecked("block.fence_gate.close"); + case "BLOCK_FENCE_GATE_OPEN": return EsSound.createUnchecked("block.fence_gate.open"); + case "BLOCK_FIRE_AMBIENT": return EsSound.createUnchecked("block.fire.ambient"); + case "BLOCK_FIRE_EXTINGUISH": return EsSound.createUnchecked("block.fire.extinguish"); + case "BLOCK_FUNGUS_BREAK": return EsSound.createUnchecked("block.fungus.break"); + case "BLOCK_FUNGUS_FALL": return EsSound.createUnchecked("block.fungus.fall"); + case "BLOCK_FUNGUS_HIT": return EsSound.createUnchecked("block.fungus.hit"); + case "BLOCK_FUNGUS_PLACE": return EsSound.createUnchecked("block.fungus.place"); + case "BLOCK_FUNGUS_STEP": return EsSound.createUnchecked("block.fungus.step"); + case "BLOCK_FURNACE_FIRE_CRACKLE": return EsSound.createUnchecked("block.furnace.fire_crackle"); + case "BLOCK_GILDED_BLACKSTONE_BREAK": return EsSound.createUnchecked("block.gilded_blackstone.break"); + case "BLOCK_GILDED_BLACKSTONE_FALL": return EsSound.createUnchecked("block.gilded_blackstone.fall"); + case "BLOCK_GILDED_BLACKSTONE_HIT": return EsSound.createUnchecked("block.gilded_blackstone.hit"); + case "BLOCK_GILDED_BLACKSTONE_PLACE": return EsSound.createUnchecked("block.gilded_blackstone.place"); + case "BLOCK_GILDED_BLACKSTONE_STEP": return EsSound.createUnchecked("block.gilded_blackstone.step"); + case "BLOCK_GLASS_BREAK": return EsSound.createUnchecked("block.glass.break"); + case "BLOCK_GLASS_FALL": return EsSound.createUnchecked("block.glass.fall"); + case "BLOCK_GLASS_HIT": return EsSound.createUnchecked("block.glass.hit"); + case "BLOCK_GLASS_PLACE": return EsSound.createUnchecked("block.glass.place"); + case "BLOCK_GLASS_STEP": return EsSound.createUnchecked("block.glass.step"); + case "BLOCK_GRASS_BREAK": return EsSound.createUnchecked("block.grass.break"); + case "BLOCK_GRASS_FALL": return EsSound.createUnchecked("block.grass.fall"); + case "BLOCK_GRASS_HIT": return EsSound.createUnchecked("block.grass.hit"); + case "BLOCK_GRASS_PLACE": return EsSound.createUnchecked("block.grass.place"); + case "BLOCK_GRASS_STEP": return EsSound.createUnchecked("block.grass.step"); + case "BLOCK_GRAVEL_BREAK": return EsSound.createUnchecked("block.gravel.break"); + case "BLOCK_GRAVEL_FALL": return EsSound.createUnchecked("block.gravel.fall"); + case "BLOCK_GRAVEL_HIT": return EsSound.createUnchecked("block.gravel.hit"); + case "BLOCK_GRAVEL_PLACE": return EsSound.createUnchecked("block.gravel.place"); + case "BLOCK_GRAVEL_STEP": return EsSound.createUnchecked("block.gravel.step"); + case "BLOCK_GRINDSTONE_USE": return EsSound.createUnchecked("block.grindstone.use"); + case "BLOCK_HONEY_BLOCK_BREAK": return EsSound.createUnchecked("block.honey_block.break"); + case "BLOCK_HONEY_BLOCK_FALL": return EsSound.createUnchecked("block.honey_block.fall"); + case "BLOCK_HONEY_BLOCK_HIT": return EsSound.createUnchecked("block.honey_block.hit"); + case "BLOCK_HONEY_BLOCK_PLACE": return EsSound.createUnchecked("block.honey_block.place"); + case "BLOCK_HONEY_BLOCK_SLIDE": return EsSound.createUnchecked("block.honey_block.slide"); + case "BLOCK_HONEY_BLOCK_STEP": return EsSound.createUnchecked("block.honey_block.step"); + case "BLOCK_IRON_DOOR_CLOSE": return EsSound.createUnchecked("block.iron_door.close"); + case "BLOCK_IRON_DOOR_OPEN": return EsSound.createUnchecked("block.iron_door.open"); + case "BLOCK_IRON_TRAPDOOR_CLOSE": return EsSound.createUnchecked("block.iron_trapdoor.close"); + case "BLOCK_IRON_TRAPDOOR_OPEN": return EsSound.createUnchecked("block.iron_trapdoor.open"); + case "BLOCK_LADDER_BREAK": return EsSound.createUnchecked("block.ladder.break"); + case "BLOCK_LADDER_FALL": return EsSound.createUnchecked("block.ladder.fall"); + case "BLOCK_LADDER_HIT": return EsSound.createUnchecked("block.ladder.hit"); + case "BLOCK_LADDER_PLACE": return EsSound.createUnchecked("block.ladder.place"); + case "BLOCK_LADDER_STEP": return EsSound.createUnchecked("block.ladder.step"); + case "BLOCK_LANTERN_BREAK": return EsSound.createUnchecked("block.lantern.break"); + case "BLOCK_LANTERN_FALL": return EsSound.createUnchecked("block.lantern.fall"); + case "BLOCK_LANTERN_HIT": return EsSound.createUnchecked("block.lantern.hit"); + case "BLOCK_LANTERN_PLACE": return EsSound.createUnchecked("block.lantern.place"); + case "BLOCK_LANTERN_STEP": return EsSound.createUnchecked("block.lantern.step"); + case "BLOCK_LAVA_AMBIENT": return EsSound.createUnchecked("block.lava.ambient"); + case "BLOCK_LAVA_EXTINGUISH": return EsSound.createUnchecked("block.lava.extinguish"); + case "BLOCK_LAVA_POP": return EsSound.createUnchecked("block.lava.pop"); + case "BLOCK_LEVER_CLICK": return EsSound.createUnchecked("block.lever.click"); + case "BLOCK_LILY_PAD_PLACE": return EsSound.createUnchecked("block.lily_pad.place"); + case "BLOCK_LODESTONE_BREAK": return EsSound.createUnchecked("block.lodestone.break"); + case "BLOCK_LODESTONE_FALL": return EsSound.createUnchecked("block.lodestone.fall"); + case "BLOCK_LODESTONE_HIT": return EsSound.createUnchecked("block.lodestone.hit"); + case "BLOCK_LODESTONE_PLACE": return EsSound.createUnchecked("block.lodestone.place"); + case "BLOCK_LODESTONE_STEP": return EsSound.createUnchecked("block.lodestone.step"); + case "BLOCK_METAL_BREAK": return EsSound.createUnchecked("block.metal.break"); + case "BLOCK_METAL_FALL": return EsSound.createUnchecked("block.metal.fall"); + case "BLOCK_METAL_HIT": return EsSound.createUnchecked("block.metal.hit"); + case "BLOCK_METAL_PLACE": return EsSound.createUnchecked("block.metal.place"); + case "BLOCK_METAL_PRESSURE_PLATE_CLICK_OFF": return EsSound.createUnchecked("block.metal_pressure_plate.click_off"); + case "BLOCK_METAL_PRESSURE_PLATE_CLICK_ON": return EsSound.createUnchecked("block.metal_pressure_plate.click_on"); + case "BLOCK_METAL_STEP": return EsSound.createUnchecked("block.metal.step"); + case "BLOCK_NETHERITE_BLOCK_BREAK": return EsSound.createUnchecked("block.netherite_block.break"); + case "BLOCK_NETHERITE_BLOCK_FALL": return EsSound.createUnchecked("block.netherite_block.fall"); + case "BLOCK_NETHERITE_BLOCK_HIT": return EsSound.createUnchecked("block.netherite_block.hit"); + case "BLOCK_NETHERITE_BLOCK_PLACE": return EsSound.createUnchecked("block.netherite_block.place"); + case "BLOCK_NETHERITE_BLOCK_STEP": return EsSound.createUnchecked("block.netherite_block.step"); + case "BLOCK_NETHERRACK_BREAK": return EsSound.createUnchecked("block.netherrack.break"); + case "BLOCK_NETHERRACK_FALL": return EsSound.createUnchecked("block.netherrack.fall"); + case "BLOCK_NETHERRACK_HIT": return EsSound.createUnchecked("block.netherrack.hit"); + case "BLOCK_NETHERRACK_PLACE": return EsSound.createUnchecked("block.netherrack.place"); + case "BLOCK_NETHERRACK_STEP": return EsSound.createUnchecked("block.netherrack.step"); + case "BLOCK_NETHER_BRICKS_BREAK": return EsSound.createUnchecked("block.nether_bricks.break"); + case "BLOCK_NETHER_BRICKS_FALL": return EsSound.createUnchecked("block.nether_bricks.fall"); + case "BLOCK_NETHER_BRICKS_HIT": return EsSound.createUnchecked("block.nether_bricks.hit"); + case "BLOCK_NETHER_BRICKS_PLACE": return EsSound.createUnchecked("block.nether_bricks.place"); + case "BLOCK_NETHER_BRICKS_STEP": return EsSound.createUnchecked("block.nether_bricks.step"); + case "BLOCK_NETHER_GOLD_ORE_BREAK": return EsSound.createUnchecked("block.nether_gold_ore.break"); + case "BLOCK_NETHER_GOLD_ORE_FALL": return EsSound.createUnchecked("block.nether_gold_ore.fall"); + case "BLOCK_NETHER_GOLD_ORE_HIT": return EsSound.createUnchecked("block.nether_gold_ore.hit"); + case "BLOCK_NETHER_GOLD_ORE_PLACE": return EsSound.createUnchecked("block.nether_gold_ore.place"); + case "BLOCK_NETHER_GOLD_ORE_STEP": return EsSound.createUnchecked("block.nether_gold_ore.step"); + case "BLOCK_NETHER_ORE_BREAK": return EsSound.createUnchecked("block.nether_ore.break"); + case "BLOCK_NETHER_ORE_FALL": return EsSound.createUnchecked("block.nether_ore.fall"); + case "BLOCK_NETHER_ORE_HIT": return EsSound.createUnchecked("block.nether_ore.hit"); + case "BLOCK_NETHER_ORE_PLACE": return EsSound.createUnchecked("block.nether_ore.place"); + case "BLOCK_NETHER_ORE_STEP": return EsSound.createUnchecked("block.nether_ore.step"); + case "BLOCK_NETHER_SPROUTS_BREAK": return EsSound.createUnchecked("block.nether_sprouts.break"); + case "BLOCK_NETHER_SPROUTS_FALL": return EsSound.createUnchecked("block.nether_sprouts.fall"); + case "BLOCK_NETHER_SPROUTS_HIT": return EsSound.createUnchecked("block.nether_sprouts.hit"); + case "BLOCK_NETHER_SPROUTS_PLACE": return EsSound.createUnchecked("block.nether_sprouts.place"); + case "BLOCK_NETHER_SPROUTS_STEP": return EsSound.createUnchecked("block.nether_sprouts.step"); + case "BLOCK_NETHER_WART_BREAK": return EsSound.createUnchecked("block.nether_wart.break"); + case "BLOCK_NOTE_BLOCK_BANJO": return EsSound.createUnchecked("block.note_block.banjo"); + case "BLOCK_NOTE_BLOCK_BASEDRUM": return EsSound.createUnchecked("block.note_block.basedrum"); + case "BLOCK_NOTE_BLOCK_BASS": return EsSound.createUnchecked("block.note_block.bass"); + case "BLOCK_NOTE_BLOCK_BELL": return EsSound.createUnchecked("block.note_block.bell"); + case "BLOCK_NOTE_BLOCK_BIT": return EsSound.createUnchecked("block.note_block.bit"); + case "BLOCK_NOTE_BLOCK_CHIME": return EsSound.createUnchecked("block.note_block.chime"); + case "BLOCK_NOTE_BLOCK_COW_BELL": return EsSound.createUnchecked("block.note_block.cow_bell"); + case "BLOCK_NOTE_BLOCK_DIDGERIDOO": return EsSound.createUnchecked("block.note_block.didgeridoo"); + case "BLOCK_NOTE_BLOCK_FLUTE": return EsSound.createUnchecked("block.note_block.flute"); + case "BLOCK_NOTE_BLOCK_GUITAR": return EsSound.createUnchecked("block.note_block.guitar"); + case "BLOCK_NOTE_BLOCK_HARP": return EsSound.createUnchecked("block.note_block.harp"); + case "BLOCK_NOTE_BLOCK_HAT": return EsSound.createUnchecked("block.note_block.hat"); + case "BLOCK_NOTE_BLOCK_IRON_XYLOPHONE": return EsSound.createUnchecked("block.note_block.iron_xylophone"); + case "BLOCK_NOTE_BLOCK_PLING": return EsSound.createUnchecked("block.note_block.pling"); + case "BLOCK_NOTE_BLOCK_SNARE": return EsSound.createUnchecked("block.note_block.snare"); + case "BLOCK_NOTE_BLOCK_XYLOPHONE": return EsSound.createUnchecked("block.note_block.xylophone"); + case "BLOCK_NYLIUM_BREAK": return EsSound.createUnchecked("block.nylium.break"); + case "BLOCK_NYLIUM_FALL": return EsSound.createUnchecked("block.nylium.fall"); + case "BLOCK_NYLIUM_HIT": return EsSound.createUnchecked("block.nylium.hit"); + case "BLOCK_NYLIUM_PLACE": return EsSound.createUnchecked("block.nylium.place"); + case "BLOCK_NYLIUM_STEP": return EsSound.createUnchecked("block.nylium.step"); + case "BLOCK_PISTON_CONTRACT": return EsSound.createUnchecked("block.piston.contract"); + case "BLOCK_PISTON_EXTEND": return EsSound.createUnchecked("block.piston.extend"); + case "BLOCK_PORTAL_AMBIENT": return EsSound.createUnchecked("block.portal.ambient"); + case "BLOCK_PORTAL_TRAVEL": return EsSound.createUnchecked("block.portal.travel"); + case "BLOCK_PORTAL_TRIGGER": return EsSound.createUnchecked("block.portal.trigger"); + case "BLOCK_PUMPKIN_CARVE": return EsSound.createUnchecked("block.pumpkin.carve"); + case "BLOCK_REDSTONE_TORCH_BURNOUT": return EsSound.createUnchecked("block.redstone_torch.burnout"); + case "BLOCK_RESPAWN_ANCHOR_AMBIENT": return EsSound.createUnchecked("block.respawn_anchor.ambient"); + case "BLOCK_RESPAWN_ANCHOR_CHARGE": return EsSound.createUnchecked("block.respawn_anchor.charge"); + case "BLOCK_RESPAWN_ANCHOR_DEPLETE": return EsSound.createUnchecked("block.respawn_anchor.deplete"); + case "BLOCK_RESPAWN_ANCHOR_SET_SPAWN": return EsSound.createUnchecked("block.respawn_anchor.set_spawn"); + case "BLOCK_ROOTS_BREAK": return EsSound.createUnchecked("block.roots.break"); + case "BLOCK_ROOTS_FALL": return EsSound.createUnchecked("block.roots.fall"); + case "BLOCK_ROOTS_HIT": return EsSound.createUnchecked("block.roots.hit"); + case "BLOCK_ROOTS_PLACE": return EsSound.createUnchecked("block.roots.place"); + case "BLOCK_ROOTS_STEP": return EsSound.createUnchecked("block.roots.step"); + case "BLOCK_SAND_BREAK": return EsSound.createUnchecked("block.sand.break"); + case "BLOCK_SAND_FALL": return EsSound.createUnchecked("block.sand.fall"); + case "BLOCK_SAND_HIT": return EsSound.createUnchecked("block.sand.hit"); + case "BLOCK_SAND_PLACE": return EsSound.createUnchecked("block.sand.place"); + case "BLOCK_SAND_STEP": return EsSound.createUnchecked("block.sand.step"); + case "BLOCK_SCAFFOLDING_BREAK": return EsSound.createUnchecked("block.scaffolding.break"); + case "BLOCK_SCAFFOLDING_FALL": return EsSound.createUnchecked("block.scaffolding.fall"); + case "BLOCK_SCAFFOLDING_HIT": return EsSound.createUnchecked("block.scaffolding.hit"); + case "BLOCK_SCAFFOLDING_PLACE": return EsSound.createUnchecked("block.scaffolding.place"); + case "BLOCK_SCAFFOLDING_STEP": return EsSound.createUnchecked("block.scaffolding.step"); + case "BLOCK_SHROOMLIGHT_BREAK": return EsSound.createUnchecked("block.shroomlight.break"); + case "BLOCK_SHROOMLIGHT_FALL": return EsSound.createUnchecked("block.shroomlight.fall"); + case "BLOCK_SHROOMLIGHT_HIT": return EsSound.createUnchecked("block.shroomlight.hit"); + case "BLOCK_SHROOMLIGHT_PLACE": return EsSound.createUnchecked("block.shroomlight.place"); + case "BLOCK_SHROOMLIGHT_STEP": return EsSound.createUnchecked("block.shroomlight.step"); + case "BLOCK_SHULKER_BOX_CLOSE": return EsSound.createUnchecked("block.shulker_box.close"); + case "BLOCK_SHULKER_BOX_OPEN": return EsSound.createUnchecked("block.shulker_box.open"); + case "BLOCK_SLIME_BLOCK_BREAK": return EsSound.createUnchecked("block.slime_block.break"); + case "BLOCK_SLIME_BLOCK_FALL": return EsSound.createUnchecked("block.slime_block.fall"); + case "BLOCK_SLIME_BLOCK_HIT": return EsSound.createUnchecked("block.slime_block.hit"); + case "BLOCK_SLIME_BLOCK_PLACE": return EsSound.createUnchecked("block.slime_block.place"); + case "BLOCK_SLIME_BLOCK_STEP": return EsSound.createUnchecked("block.slime_block.step"); + case "BLOCK_SMITHING_TABLE_USE": return EsSound.createUnchecked("block.smithing_table.use"); + case "BLOCK_SMOKER_SMOKE": return EsSound.createUnchecked("block.smoker.smoke"); + case "BLOCK_SNOW_BREAK": return EsSound.createUnchecked("block.snow.break"); + case "BLOCK_SNOW_FALL": return EsSound.createUnchecked("block.snow.fall"); + case "BLOCK_SNOW_HIT": return EsSound.createUnchecked("block.snow.hit"); + case "BLOCK_SNOW_PLACE": return EsSound.createUnchecked("block.snow.place"); + case "BLOCK_SNOW_STEP": return EsSound.createUnchecked("block.snow.step"); + case "BLOCK_SOUL_SAND_BREAK": return EsSound.createUnchecked("block.soul_sand.break"); + case "BLOCK_SOUL_SAND_FALL": return EsSound.createUnchecked("block.soul_sand.fall"); + case "BLOCK_SOUL_SAND_HIT": return EsSound.createUnchecked("block.soul_sand.hit"); + case "BLOCK_SOUL_SAND_PLACE": return EsSound.createUnchecked("block.soul_sand.place"); + case "BLOCK_SOUL_SAND_STEP": return EsSound.createUnchecked("block.soul_sand.step"); + case "BLOCK_SOUL_SOIL_BREAK": return EsSound.createUnchecked("block.soul_soil.break"); + case "BLOCK_SOUL_SOIL_FALL": return EsSound.createUnchecked("block.soul_soil.fall"); + case "BLOCK_SOUL_SOIL_HIT": return EsSound.createUnchecked("block.soul_soil.hit"); + case "BLOCK_SOUL_SOIL_PLACE": return EsSound.createUnchecked("block.soul_soil.place"); + case "BLOCK_SOUL_SOIL_STEP": return EsSound.createUnchecked("block.soul_soil.step"); + case "BLOCK_STEM_BREAK": return EsSound.createUnchecked("block.stem.break"); + case "BLOCK_STEM_FALL": return EsSound.createUnchecked("block.stem.fall"); + case "BLOCK_STEM_HIT": return EsSound.createUnchecked("block.stem.hit"); + case "BLOCK_STEM_PLACE": return EsSound.createUnchecked("block.stem.place"); + case "BLOCK_STEM_STEP": return EsSound.createUnchecked("block.stem.step"); + case "BLOCK_STONE_BREAK": return EsSound.createUnchecked("block.stone.break"); + case "BLOCK_STONE_BUTTON_CLICK_OFF": return EsSound.createUnchecked("block.stone_button.click_off"); + case "BLOCK_STONE_BUTTON_CLICK_ON": return EsSound.createUnchecked("block.stone_button.click_on"); + case "BLOCK_STONE_FALL": return EsSound.createUnchecked("block.stone.fall"); + case "BLOCK_STONE_HIT": return EsSound.createUnchecked("block.stone.hit"); + case "BLOCK_STONE_PLACE": return EsSound.createUnchecked("block.stone.place"); + case "BLOCK_STONE_PRESSURE_PLATE_CLICK_OFF": return EsSound.createUnchecked("block.stone_pressure_plate.click_off"); + case "BLOCK_STONE_PRESSURE_PLATE_CLICK_ON": return EsSound.createUnchecked("block.stone_pressure_plate.click_on"); + case "BLOCK_STONE_STEP": return EsSound.createUnchecked("block.stone.step"); + case "BLOCK_SWEET_BERRY_BUSH_BREAK": return EsSound.createUnchecked("block.sweet_berry_bush.break"); + case "BLOCK_SWEET_BERRY_BUSH_PLACE": return EsSound.createUnchecked("block.sweet_berry_bush.place"); + case "BLOCK_TRIPWIRE_ATTACH": return EsSound.createUnchecked("block.tripwire.attach"); + case "BLOCK_TRIPWIRE_CLICK_OFF": return EsSound.createUnchecked("block.tripwire.click_off"); + case "BLOCK_TRIPWIRE_CLICK_ON": return EsSound.createUnchecked("block.tripwire.click_on"); + case "BLOCK_TRIPWIRE_DETACH": return EsSound.createUnchecked("block.tripwire.detach"); + case "BLOCK_VINE_STEP": return EsSound.createUnchecked("block.vine.step"); + case "BLOCK_WART_BLOCK_BREAK": return EsSound.createUnchecked("block.wart_block.break"); + case "BLOCK_WART_BLOCK_FALL": return EsSound.createUnchecked("block.wart_block.fall"); + case "BLOCK_WART_BLOCK_HIT": return EsSound.createUnchecked("block.wart_block.hit"); + case "BLOCK_WART_BLOCK_PLACE": return EsSound.createUnchecked("block.wart_block.place"); + case "BLOCK_WART_BLOCK_STEP": return EsSound.createUnchecked("block.wart_block.step"); + case "BLOCK_WATER_AMBIENT": return EsSound.createUnchecked("block.water.ambient"); + case "BLOCK_WEEPING_VINES_BREAK": return EsSound.createUnchecked("block.weeping_vines.break"); + case "BLOCK_WEEPING_VINES_FALL": return EsSound.createUnchecked("block.weeping_vines.fall"); + case "BLOCK_WEEPING_VINES_HIT": return EsSound.createUnchecked("block.weeping_vines.hit"); + case "BLOCK_WEEPING_VINES_PLACE": return EsSound.createUnchecked("block.weeping_vines.place"); + case "BLOCK_WEEPING_VINES_STEP": return EsSound.createUnchecked("block.weeping_vines.step"); + case "BLOCK_WET_GRASS_BREAK": return EsSound.createUnchecked("block.wet_grass.break"); + case "BLOCK_WET_GRASS_FALL": return EsSound.createUnchecked("block.wet_grass.fall"); + case "BLOCK_WET_GRASS_HIT": return EsSound.createUnchecked("block.wet_grass.hit"); + case "BLOCK_WET_GRASS_PLACE": return EsSound.createUnchecked("block.wet_grass.place"); + case "BLOCK_WET_GRASS_STEP": return EsSound.createUnchecked("block.wet_grass.step"); + case "BLOCK_WOODEN_BUTTON_CLICK_OFF": return EsSound.createUnchecked("block.wooden_button.click_off"); + case "BLOCK_WOODEN_BUTTON_CLICK_ON": return EsSound.createUnchecked("block.wooden_button.click_on"); + case "BLOCK_WOODEN_DOOR_CLOSE": return EsSound.createUnchecked("block.wooden_door.close"); + case "BLOCK_WOODEN_DOOR_OPEN": return EsSound.createUnchecked("block.wooden_door.open"); + case "BLOCK_WOODEN_PRESSURE_PLATE_CLICK_OFF": return EsSound.createUnchecked("block.wooden_pressure_plate.click_off"); + case "BLOCK_WOODEN_PRESSURE_PLATE_CLICK_ON": return EsSound.createUnchecked("block.wooden_pressure_plate.click_on"); + case "BLOCK_WOODEN_TRAPDOOR_CLOSE": return EsSound.createUnchecked("block.wooden_trapdoor.close"); + case "BLOCK_WOODEN_TRAPDOOR_OPEN": return EsSound.createUnchecked("block.wooden_trapdoor.open"); + case "BLOCK_WOOD_BREAK": return EsSound.createUnchecked("block.wood.break"); + case "BLOCK_WOOD_FALL": return EsSound.createUnchecked("block.wood.fall"); + case "BLOCK_WOOD_HIT": return EsSound.createUnchecked("block.wood.hit"); + case "BLOCK_WOOD_PLACE": return EsSound.createUnchecked("block.wood.place"); + case "BLOCK_WOOD_STEP": return EsSound.createUnchecked("block.wood.step"); + case "BLOCK_WOOL_BREAK": return EsSound.createUnchecked("block.wool.break"); + case "BLOCK_WOOL_FALL": return EsSound.createUnchecked("block.wool.fall"); + case "BLOCK_WOOL_HIT": return EsSound.createUnchecked("block.wool.hit"); + case "BLOCK_WOOL_PLACE": return EsSound.createUnchecked("block.wool.place"); + case "BLOCK_WOOL_STEP": return EsSound.createUnchecked("block.wool.step"); + case "ENCHANT_THORNS_HIT": return EsSound.createUnchecked("enchant.thorns.hit"); + case "ENTITY_ARMOR_STAND_BREAK": return EsSound.createUnchecked("entity.armor_stand.break"); + case "ENTITY_ARMOR_STAND_FALL": return EsSound.createUnchecked("entity.armor_stand.fall"); + case "ENTITY_ARMOR_STAND_HIT": return EsSound.createUnchecked("entity.armor_stand.hit"); + case "ENTITY_ARMOR_STAND_PLACE": return EsSound.createUnchecked("entity.armor_stand.place"); + case "ENTITY_ARROW_HIT": return EsSound.createUnchecked("entity.arrow.hit"); + case "ENTITY_ARROW_HIT_PLAYER": return EsSound.createUnchecked("entity.arrow.hit_player"); + case "ENTITY_ARROW_SHOOT": return EsSound.createUnchecked("entity.arrow.shoot"); + case "ENTITY_BAT_AMBIENT": return EsSound.createUnchecked("entity.bat.ambient"); + case "ENTITY_BAT_DEATH": return EsSound.createUnchecked("entity.bat.death"); + case "ENTITY_BAT_HURT": return EsSound.createUnchecked("entity.bat.hurt"); + case "ENTITY_BAT_LOOP": return EsSound.createUnchecked("entity.bat.loop"); + case "ENTITY_BAT_TAKEOFF": return EsSound.createUnchecked("entity.bat.takeoff"); + case "ENTITY_BEE_DEATH": return EsSound.createUnchecked("entity.bee.death"); + case "ENTITY_BEE_HURT": return EsSound.createUnchecked("entity.bee.hurt"); + case "ENTITY_BEE_LOOP": return EsSound.createUnchecked("entity.bee.loop"); + case "ENTITY_BEE_LOOP_AGGRESSIVE": return EsSound.createUnchecked("entity.bee.loop_aggressive"); + case "ENTITY_BEE_POLLINATE": return EsSound.createUnchecked("entity.bee.pollinate"); + case "ENTITY_BEE_STING": return EsSound.createUnchecked("entity.bee.sting"); + case "ENTITY_BLAZE_AMBIENT": return EsSound.createUnchecked("entity.blaze.ambient"); + case "ENTITY_BLAZE_BURN": return EsSound.createUnchecked("entity.blaze.burn"); + case "ENTITY_BLAZE_DEATH": return EsSound.createUnchecked("entity.blaze.death"); + case "ENTITY_BLAZE_HURT": return EsSound.createUnchecked("entity.blaze.hurt"); + case "ENTITY_BLAZE_SHOOT": return EsSound.createUnchecked("entity.blaze.shoot"); + case "ENTITY_BOAT_PADDLE_LAND": return EsSound.createUnchecked("entity.boat.paddle_land"); + case "ENTITY_BOAT_PADDLE_WATER": return EsSound.createUnchecked("entity.boat.paddle_water"); + case "ENTITY_CAT_AMBIENT": return EsSound.createUnchecked("entity.cat.ambient"); + case "ENTITY_CAT_BEG_FOR_FOOD": return EsSound.createUnchecked("entity.cat.beg_for_food"); + case "ENTITY_CAT_DEATH": return EsSound.createUnchecked("entity.cat.death"); + case "ENTITY_CAT_EAT": return EsSound.createUnchecked("entity.cat.eat"); + case "ENTITY_CAT_HISS": return EsSound.createUnchecked("entity.cat.hiss"); + case "ENTITY_CAT_HURT": return EsSound.createUnchecked("entity.cat.hurt"); + case "ENTITY_CAT_PURR": return EsSound.createUnchecked("entity.cat.purr"); + case "ENTITY_CAT_PURREOW": return EsSound.createUnchecked("entity.cat.purreow"); + case "ENTITY_CAT_STRAY_AMBIENT": return EsSound.createUnchecked("entity.cat.stray_ambient"); + case "ENTITY_CHICKEN_AMBIENT": return EsSound.createUnchecked("entity.chicken.ambient"); + case "ENTITY_CHICKEN_DEATH": return EsSound.createUnchecked("entity.chicken.death"); + case "ENTITY_CHICKEN_EGG": return EsSound.createUnchecked("entity.chicken.egg"); + case "ENTITY_CHICKEN_HURT": return EsSound.createUnchecked("entity.chicken.hurt"); + case "ENTITY_CHICKEN_STEP": return EsSound.createUnchecked("entity.chicken.step"); + case "ENTITY_COD_AMBIENT": return EsSound.createUnchecked("entity.cod.ambient"); + case "ENTITY_COD_DEATH": return EsSound.createUnchecked("entity.cod.death"); + case "ENTITY_COD_FLOP": return EsSound.createUnchecked("entity.cod.flop"); + case "ENTITY_COD_HURT": return EsSound.createUnchecked("entity.cod.hurt"); + case "ENTITY_COW_AMBIENT": return EsSound.createUnchecked("entity.cow.ambient"); + case "ENTITY_COW_DEATH": return EsSound.createUnchecked("entity.cow.death"); + case "ENTITY_COW_HURT": return EsSound.createUnchecked("entity.cow.hurt"); + case "ENTITY_COW_MILK": return EsSound.createUnchecked("entity.cow.milk"); + case "ENTITY_COW_STEP": return EsSound.createUnchecked("entity.cow.step"); + case "ENTITY_CREEPER_DEATH": return EsSound.createUnchecked("entity.creeper.death"); + case "ENTITY_CREEPER_HURT": return EsSound.createUnchecked("entity.creeper.hurt"); + case "ENTITY_CREEPER_PRIMED": return EsSound.createUnchecked("entity.creeper.primed"); + case "ENTITY_DOLPHIN_AMBIENT": return EsSound.createUnchecked("entity.dolphin.ambient"); + case "ENTITY_DOLPHIN_AMBIENT_WATER": return EsSound.createUnchecked("entity.dolphin.ambient_water"); + case "ENTITY_DOLPHIN_ATTACK": return EsSound.createUnchecked("entity.dolphin.attack"); + case "ENTITY_DOLPHIN_DEATH": return EsSound.createUnchecked("entity.dolphin.death"); + case "ENTITY_DOLPHIN_EAT": return EsSound.createUnchecked("entity.dolphin.eat"); + case "ENTITY_DOLPHIN_HURT": return EsSound.createUnchecked("entity.dolphin.hurt"); + case "ENTITY_DOLPHIN_JUMP": return EsSound.createUnchecked("entity.dolphin.jump"); + case "ENTITY_DOLPHIN_PLAY": return EsSound.createUnchecked("entity.dolphin.play"); + case "ENTITY_DOLPHIN_SPLASH": return EsSound.createUnchecked("entity.dolphin.splash"); + case "ENTITY_DOLPHIN_SWIM": return EsSound.createUnchecked("entity.dolphin.swim"); + case "ENTITY_DONKEY_AMBIENT": return EsSound.createUnchecked("entity.donkey.ambient"); + case "ENTITY_DONKEY_ANGRY": return EsSound.createUnchecked("entity.donkey.angry"); + case "ENTITY_DONKEY_CHEST": return EsSound.createUnchecked("entity.donkey.chest"); + case "ENTITY_DONKEY_DEATH": return EsSound.createUnchecked("entity.donkey.death"); + case "ENTITY_DONKEY_EAT": return EsSound.createUnchecked("entity.donkey.eat"); + case "ENTITY_DONKEY_HURT": return EsSound.createUnchecked("entity.donkey.hurt"); + case "ENTITY_DRAGON_FIREBALL_EXPLODE": return EsSound.createUnchecked("entity.dragon_fireball.explode"); + case "ENTITY_DROWNED_AMBIENT": return EsSound.createUnchecked("entity.drowned.ambient"); + case "ENTITY_DROWNED_AMBIENT_WATER": return EsSound.createUnchecked("entity.drowned.ambient_water"); + case "ENTITY_DROWNED_DEATH": return EsSound.createUnchecked("entity.drowned.death"); + case "ENTITY_DROWNED_DEATH_WATER": return EsSound.createUnchecked("entity.drowned.death_water"); + case "ENTITY_DROWNED_HURT": return EsSound.createUnchecked("entity.drowned.hurt"); + case "ENTITY_DROWNED_HURT_WATER": return EsSound.createUnchecked("entity.drowned.hurt_water"); + case "ENTITY_DROWNED_SHOOT": return EsSound.createUnchecked("entity.drowned.shoot"); + case "ENTITY_DROWNED_STEP": return EsSound.createUnchecked("entity.drowned.step"); + case "ENTITY_DROWNED_SWIM": return EsSound.createUnchecked("entity.drowned.swim"); + case "ENTITY_EGG_THROW": return EsSound.createUnchecked("entity.egg.throw"); + case "ENTITY_ELDER_GUARDIAN_AMBIENT": return EsSound.createUnchecked("entity.elder_guardian.ambient"); + case "ENTITY_ELDER_GUARDIAN_AMBIENT_LAND": return EsSound.createUnchecked("entity.elder_guardian.ambient_land"); + case "ENTITY_ELDER_GUARDIAN_CURSE": return EsSound.createUnchecked("entity.elder_guardian.curse"); + case "ENTITY_ELDER_GUARDIAN_DEATH": return EsSound.createUnchecked("entity.elder_guardian.death"); + case "ENTITY_ELDER_GUARDIAN_DEATH_LAND": return EsSound.createUnchecked("entity.elder_guardian.death_land"); + case "ENTITY_ELDER_GUARDIAN_FLOP": return EsSound.createUnchecked("entity.elder_guardian.flop"); + case "ENTITY_ELDER_GUARDIAN_HURT": return EsSound.createUnchecked("entity.elder_guardian.hurt"); + case "ENTITY_ELDER_GUARDIAN_HURT_LAND": return EsSound.createUnchecked("entity.elder_guardian.hurt_land"); + case "ENTITY_ENDERMAN_AMBIENT": return EsSound.createUnchecked("entity.enderman.ambient"); + case "ENTITY_ENDERMAN_DEATH": return EsSound.createUnchecked("entity.enderman.death"); + case "ENTITY_ENDERMAN_HURT": return EsSound.createUnchecked("entity.enderman.hurt"); + case "ENTITY_ENDERMAN_SCREAM": return EsSound.createUnchecked("entity.enderman.scream"); + case "ENTITY_ENDERMAN_STARE": return EsSound.createUnchecked("entity.enderman.stare"); + case "ENTITY_ENDERMAN_TELEPORT": return EsSound.createUnchecked("entity.enderman.teleport"); + case "ENTITY_ENDERMITE_AMBIENT": return EsSound.createUnchecked("entity.endermite.ambient"); + case "ENTITY_ENDERMITE_DEATH": return EsSound.createUnchecked("entity.endermite.death"); + case "ENTITY_ENDERMITE_HURT": return EsSound.createUnchecked("entity.endermite.hurt"); + case "ENTITY_ENDERMITE_STEP": return EsSound.createUnchecked("entity.endermite.step"); + case "ENTITY_ENDER_DRAGON_AMBIENT": return EsSound.createUnchecked("entity.ender_dragon.ambient"); + case "ENTITY_ENDER_DRAGON_DEATH": return EsSound.createUnchecked("entity.ender_dragon.death"); + case "ENTITY_ENDER_DRAGON_FLAP": return EsSound.createUnchecked("entity.ender_dragon.flap"); + case "ENTITY_ENDER_DRAGON_GROWL": return EsSound.createUnchecked("entity.ender_dragon.growl"); + case "ENTITY_ENDER_DRAGON_HURT": return EsSound.createUnchecked("entity.ender_dragon.hurt"); + case "ENTITY_ENDER_DRAGON_SHOOT": return EsSound.createUnchecked("entity.ender_dragon.shoot"); + case "ENTITY_ENDER_EYE_DEATH": return EsSound.createUnchecked("entity.ender_eye.death"); + case "ENTITY_ENDER_EYE_LAUNCH": return EsSound.createUnchecked("entity.ender_eye.launch"); + case "ENTITY_ENDER_PEARL_THROW": return EsSound.createUnchecked("entity.ender_pearl.throw"); + case "ENTITY_EVOKER_AMBIENT": return EsSound.createUnchecked("entity.evoker.ambient"); + case "ENTITY_EVOKER_CAST_SPELL": return EsSound.createUnchecked("entity.evoker.cast_spell"); + case "ENTITY_EVOKER_CELEBRATE": return EsSound.createUnchecked("entity.evoker.celebrate"); + case "ENTITY_EVOKER_DEATH": return EsSound.createUnchecked("entity.evoker.death"); + case "ENTITY_EVOKER_FANGS_ATTACK": return EsSound.createUnchecked("entity.evoker_fangs.attack"); + case "ENTITY_EVOKER_HURT": return EsSound.createUnchecked("entity.evoker.hurt"); + case "ENTITY_EVOKER_PREPARE_ATTACK": return EsSound.createUnchecked("entity.evoker.prepare_attack"); + case "ENTITY_EVOKER_PREPARE_SUMMON": return EsSound.createUnchecked("entity.evoker.prepare_summon"); + case "ENTITY_EVOKER_PREPARE_WOLOLO": return EsSound.createUnchecked("entity.evoker.prepare_wololo"); + case "ENTITY_EXPERIENCE_BOTTLE_THROW": return EsSound.createUnchecked("entity.experience_bottle.throw"); + case "ENTITY_EXPERIENCE_ORB_PICKUP": return EsSound.createUnchecked("entity.experience_orb.pickup"); + case "ENTITY_FIREWORK_ROCKET_BLAST": return EsSound.createUnchecked("entity.firework_rocket.blast"); + case "ENTITY_FIREWORK_ROCKET_BLAST_FAR": return EsSound.createUnchecked("entity.firework_rocket.blast_far"); + case "ENTITY_FIREWORK_ROCKET_LARGE_BLAST": return EsSound.createUnchecked("entity.firework_rocket.large_blast"); + case "ENTITY_FIREWORK_ROCKET_LARGE_BLAST_FAR": return EsSound.createUnchecked("entity.firework_rocket.large_blast_far"); + case "ENTITY_FIREWORK_ROCKET_LAUNCH": return EsSound.createUnchecked("entity.firework_rocket.launch"); + case "ENTITY_FIREWORK_ROCKET_SHOOT": return EsSound.createUnchecked("entity.firework_rocket.shoot"); + case "ENTITY_FIREWORK_ROCKET_TWINKLE": return EsSound.createUnchecked("entity.firework_rocket.twinkle"); + case "ENTITY_FIREWORK_ROCKET_TWINKLE_FAR": return EsSound.createUnchecked("entity.firework_rocket.twinkle_far"); + case "ENTITY_FISHING_BOBBER_RETRIEVE": return EsSound.createUnchecked("entity.fishing_bobber.retrieve"); + case "ENTITY_FISHING_BOBBER_SPLASH": return EsSound.createUnchecked("entity.fishing_bobber.splash"); + case "ENTITY_FISHING_BOBBER_THROW": return EsSound.createUnchecked("entity.fishing_bobber.throw"); + case "ENTITY_FISH_SWIM": return EsSound.createUnchecked("entity.fish.swim"); + case "ENTITY_FOX_AGGRO": return EsSound.createUnchecked("entity.fox.aggro"); + case "ENTITY_FOX_AMBIENT": return EsSound.createUnchecked("entity.fox.ambient"); + case "ENTITY_FOX_BITE": return EsSound.createUnchecked("entity.fox.bite"); + case "ENTITY_FOX_DEATH": return EsSound.createUnchecked("entity.fox.death"); + case "ENTITY_FOX_EAT": return EsSound.createUnchecked("entity.fox.eat"); + case "ENTITY_FOX_HURT": return EsSound.createUnchecked("entity.fox.hurt"); + case "ENTITY_FOX_SCREECH": return EsSound.createUnchecked("entity.fox.screech"); + case "ENTITY_FOX_SLEEP": return EsSound.createUnchecked("entity.fox.sleep"); + case "ENTITY_FOX_SNIFF": return EsSound.createUnchecked("entity.fox.sniff"); + case "ENTITY_FOX_SPIT": return EsSound.createUnchecked("entity.fox.spit"); + case "ENTITY_FOX_TELEPORT": return EsSound.createUnchecked("entity.fox.teleport"); + case "ENTITY_GENERIC_BIG_FALL": return EsSound.createUnchecked("entity.generic.big_fall"); + case "ENTITY_GENERIC_BURN": return EsSound.createUnchecked("entity.generic.burn"); + case "ENTITY_GENERIC_DEATH": return EsSound.createUnchecked("entity.generic.death"); + case "ENTITY_GENERIC_DRINK": return EsSound.createUnchecked("entity.generic.drink"); + case "ENTITY_GENERIC_EAT": return EsSound.createUnchecked("entity.generic.eat"); + case "ENTITY_GENERIC_EXPLODE": return EsSound.createUnchecked("entity.generic.explode"); + case "ENTITY_GENERIC_EXTINGUISH_FIRE": return EsSound.createUnchecked("entity.generic.extinguish_fire"); + case "ENTITY_GENERIC_HURT": return EsSound.createUnchecked("entity.generic.hurt"); + case "ENTITY_GENERIC_SMALL_FALL": return EsSound.createUnchecked("entity.generic.small_fall"); + case "ENTITY_GENERIC_SPLASH": return EsSound.createUnchecked("entity.generic.splash"); + case "ENTITY_GENERIC_SWIM": return EsSound.createUnchecked("entity.generic.swim"); + case "ENTITY_GHAST_AMBIENT": return EsSound.createUnchecked("entity.ghast.ambient"); + case "ENTITY_GHAST_DEATH": return EsSound.createUnchecked("entity.ghast.death"); + case "ENTITY_GHAST_HURT": return EsSound.createUnchecked("entity.ghast.hurt"); + case "ENTITY_GHAST_SCREAM": return EsSound.createUnchecked("entity.ghast.scream"); + case "ENTITY_GHAST_SHOOT": return EsSound.createUnchecked("entity.ghast.shoot"); + case "ENTITY_GHAST_WARN": return EsSound.createUnchecked("entity.ghast.warn"); + case "ENTITY_GUARDIAN_AMBIENT": return EsSound.createUnchecked("entity.guardian.ambient"); + case "ENTITY_GUARDIAN_AMBIENT_LAND": return EsSound.createUnchecked("entity.guardian.ambient_land"); + case "ENTITY_GUARDIAN_ATTACK": return EsSound.createUnchecked("entity.guardian.attack"); + case "ENTITY_GUARDIAN_DEATH": return EsSound.createUnchecked("entity.guardian.death"); + case "ENTITY_GUARDIAN_DEATH_LAND": return EsSound.createUnchecked("entity.guardian.death_land"); + case "ENTITY_GUARDIAN_FLOP": return EsSound.createUnchecked("entity.guardian.flop"); + case "ENTITY_GUARDIAN_HURT": return EsSound.createUnchecked("entity.guardian.hurt"); + case "ENTITY_GUARDIAN_HURT_LAND": return EsSound.createUnchecked("entity.guardian.hurt_land"); + case "ENTITY_HOGLIN_AMBIENT": return EsSound.createUnchecked("entity.hoglin.ambient"); + case "ENTITY_HOGLIN_ANGRY": return EsSound.createUnchecked("entity.hoglin.angry"); + case "ENTITY_HOGLIN_ATTACK": return EsSound.createUnchecked("entity.hoglin.attack"); + case "ENTITY_HOGLIN_CONVERTED_TO_ZOMBIFIED": return EsSound.createUnchecked("entity.hoglin.converted_to_zombified"); + case "ENTITY_HOGLIN_DEATH": return EsSound.createUnchecked("entity.hoglin.death"); + case "ENTITY_HOGLIN_HURT": return EsSound.createUnchecked("entity.hoglin.hurt"); + case "ENTITY_HOGLIN_RETREAT": return EsSound.createUnchecked("entity.hoglin.retreat"); + case "ENTITY_HOGLIN_STEP": return EsSound.createUnchecked("entity.hoglin.step"); + case "ENTITY_HORSE_AMBIENT": return EsSound.createUnchecked("entity.horse.ambient"); + case "ENTITY_HORSE_ANGRY": return EsSound.createUnchecked("entity.horse.angry"); + case "ENTITY_HORSE_ARMOR": return EsSound.createUnchecked("entity.horse.armor"); + case "ENTITY_HORSE_BREATHE": return EsSound.createUnchecked("entity.horse.breathe"); + case "ENTITY_HORSE_DEATH": return EsSound.createUnchecked("entity.horse.death"); + case "ENTITY_HORSE_EAT": return EsSound.createUnchecked("entity.horse.eat"); + case "ENTITY_HORSE_GALLOP": return EsSound.createUnchecked("entity.horse.gallop"); + case "ENTITY_HORSE_HURT": return EsSound.createUnchecked("entity.horse.hurt"); + case "ENTITY_HORSE_JUMP": return EsSound.createUnchecked("entity.horse.jump"); + case "ENTITY_HORSE_LAND": return EsSound.createUnchecked("entity.horse.land"); + case "ENTITY_HORSE_SADDLE": return EsSound.createUnchecked("entity.horse.saddle"); + case "ENTITY_HORSE_STEP": return EsSound.createUnchecked("entity.horse.step"); + case "ENTITY_HORSE_STEP_WOOD": return EsSound.createUnchecked("entity.horse.step_wood"); + case "ENTITY_HOSTILE_BIG_FALL": return EsSound.createUnchecked("entity.hostile.big_fall"); + case "ENTITY_HOSTILE_DEATH": return EsSound.createUnchecked("entity.hostile.death"); + case "ENTITY_HOSTILE_HURT": return EsSound.createUnchecked("entity.hostile.hurt"); + case "ENTITY_HOSTILE_SMALL_FALL": return EsSound.createUnchecked("entity.hostile.small_fall"); + case "ENTITY_HOSTILE_SPLASH": return EsSound.createUnchecked("entity.hostile.splash"); + case "ENTITY_HOSTILE_SWIM": return EsSound.createUnchecked("entity.hostile.swim"); + case "ENTITY_HUSK_AMBIENT": return EsSound.createUnchecked("entity.husk.ambient"); + case "ENTITY_HUSK_CONVERTED_TO_ZOMBIE": return EsSound.createUnchecked("entity.husk.converted_to_zombie"); + case "ENTITY_HUSK_DEATH": return EsSound.createUnchecked("entity.husk.death"); + case "ENTITY_HUSK_HURT": return EsSound.createUnchecked("entity.husk.hurt"); + case "ENTITY_HUSK_STEP": return EsSound.createUnchecked("entity.husk.step"); + case "ENTITY_ILLUSIONER_AMBIENT": return EsSound.createUnchecked("entity.illusioner.ambient"); + case "ENTITY_ILLUSIONER_CAST_SPELL": return EsSound.createUnchecked("entity.illusioner.cast_spell"); + case "ENTITY_ILLUSIONER_DEATH": return EsSound.createUnchecked("entity.illusioner.death"); + case "ENTITY_ILLUSIONER_HURT": return EsSound.createUnchecked("entity.illusioner.hurt"); + case "ENTITY_ILLUSIONER_MIRROR_MOVE": return EsSound.createUnchecked("entity.illusioner.mirror_move"); + case "ENTITY_ILLUSIONER_PREPARE_BLINDNESS": return EsSound.createUnchecked("entity.illusioner.prepare_blindness"); + case "ENTITY_ILLUSIONER_PREPARE_MIRROR": return EsSound.createUnchecked("entity.illusioner.prepare_mirror"); + case "ENTITY_IRON_GOLEM_ATTACK": return EsSound.createUnchecked("entity.iron_golem.attack"); + case "ENTITY_IRON_GOLEM_DAMAGE": return EsSound.createUnchecked("entity.iron_golem.damage"); + case "ENTITY_IRON_GOLEM_DEATH": return EsSound.createUnchecked("entity.iron_golem.death"); + case "ENTITY_IRON_GOLEM_HURT": return EsSound.createUnchecked("entity.iron_golem.hurt"); + case "ENTITY_IRON_GOLEM_REPAIR": return EsSound.createUnchecked("entity.iron_golem.repair"); + case "ENTITY_IRON_GOLEM_STEP": return EsSound.createUnchecked("entity.iron_golem.step"); + case "ENTITY_ITEM_BREAK": return EsSound.createUnchecked("entity.item.break"); + case "ENTITY_ITEM_FRAME_ADD_ITEM": return EsSound.createUnchecked("entity.item_frame.add_item"); + case "ENTITY_ITEM_FRAME_BREAK": return EsSound.createUnchecked("entity.item_frame.break"); + case "ENTITY_ITEM_FRAME_PLACE": return EsSound.createUnchecked("entity.item_frame.place"); + case "ENTITY_ITEM_FRAME_REMOVE_ITEM": return EsSound.createUnchecked("entity.item_frame.remove_item"); + case "ENTITY_ITEM_FRAME_ROTATE_ITEM": return EsSound.createUnchecked("entity.item_frame.rotate_item"); + case "ENTITY_ITEM_PICKUP": return EsSound.createUnchecked("entity.item.pickup"); + case "ENTITY_LEASH_KNOT_BREAK": return EsSound.createUnchecked("entity.leash_knot.break"); + case "ENTITY_LEASH_KNOT_PLACE": return EsSound.createUnchecked("entity.leash_knot.place"); + case "ENTITY_LIGHTNING_BOLT_IMPACT": return EsSound.createUnchecked("entity.lightning_bolt.impact"); + case "ENTITY_LIGHTNING_BOLT_THUNDER": return EsSound.createUnchecked("entity.lightning_bolt.thunder"); + case "ENTITY_LINGERING_POTION_THROW": return EsSound.createUnchecked("entity.lingering_potion.throw"); + case "ENTITY_LLAMA_AMBIENT": return EsSound.createUnchecked("entity.llama.ambient"); + case "ENTITY_LLAMA_ANGRY": return EsSound.createUnchecked("entity.llama.angry"); + case "ENTITY_LLAMA_CHEST": return EsSound.createUnchecked("entity.llama.chest"); + case "ENTITY_LLAMA_DEATH": return EsSound.createUnchecked("entity.llama.death"); + case "ENTITY_LLAMA_EAT": return EsSound.createUnchecked("entity.llama.eat"); + case "ENTITY_LLAMA_HURT": return EsSound.createUnchecked("entity.llama.hurt"); + case "ENTITY_LLAMA_SPIT": return EsSound.createUnchecked("entity.llama.spit"); + case "ENTITY_LLAMA_STEP": return EsSound.createUnchecked("entity.llama.step"); + case "ENTITY_LLAMA_SWAG": return EsSound.createUnchecked("entity.llama.swag"); + case "ENTITY_MAGMA_CUBE_DEATH": return EsSound.createUnchecked("entity.magma_cube.death"); + case "ENTITY_MAGMA_CUBE_DEATH_SMALL": return EsSound.createUnchecked("entity.magma_cube.death_small"); + case "ENTITY_MAGMA_CUBE_HURT": return EsSound.createUnchecked("entity.magma_cube.hurt"); + case "ENTITY_MAGMA_CUBE_HURT_SMALL": return EsSound.createUnchecked("entity.magma_cube.hurt_small"); + case "ENTITY_MAGMA_CUBE_JUMP": return EsSound.createUnchecked("entity.magma_cube.jump"); + case "ENTITY_MAGMA_CUBE_SQUISH": return EsSound.createUnchecked("entity.magma_cube.squish"); + case "ENTITY_MAGMA_CUBE_SQUISH_SMALL": return EsSound.createUnchecked("entity.magma_cube.squish_small"); + case "ENTITY_MINECART_INSIDE": return EsSound.createUnchecked("entity.minecart.inside"); + case "ENTITY_MINECART_RIDING": return EsSound.createUnchecked("entity.minecart.riding"); + case "ENTITY_MOOSHROOM_CONVERT": return EsSound.createUnchecked("entity.mooshroom.convert"); + case "ENTITY_MOOSHROOM_EAT": return EsSound.createUnchecked("entity.mooshroom.eat"); + case "ENTITY_MOOSHROOM_MILK": return EsSound.createUnchecked("entity.mooshroom.milk"); + case "ENTITY_MOOSHROOM_SHEAR": return EsSound.createUnchecked("entity.mooshroom.shear"); + case "ENTITY_MOOSHROOM_SUSPICIOUS_MILK": return EsSound.createUnchecked("entity.mooshroom.suspicious_milk"); + case "ENTITY_MULE_AMBIENT": return EsSound.createUnchecked("entity.mule.ambient"); + case "ENTITY_MULE_ANGRY": return EsSound.createUnchecked("entity.mule.angry"); + case "ENTITY_MULE_CHEST": return EsSound.createUnchecked("entity.mule.chest"); + case "ENTITY_MULE_DEATH": return EsSound.createUnchecked("entity.mule.death"); + case "ENTITY_MULE_EAT": return EsSound.createUnchecked("entity.mule.eat"); + case "ENTITY_MULE_HURT": return EsSound.createUnchecked("entity.mule.hurt"); + case "ENTITY_OCELOT_AMBIENT": return EsSound.createUnchecked("entity.ocelot.ambient"); + case "ENTITY_OCELOT_DEATH": return EsSound.createUnchecked("entity.ocelot.death"); + case "ENTITY_OCELOT_HURT": return EsSound.createUnchecked("entity.ocelot.hurt"); + case "ENTITY_PAINTING_BREAK": return EsSound.createUnchecked("entity.painting.break"); + case "ENTITY_PAINTING_PLACE": return EsSound.createUnchecked("entity.painting.place"); + case "ENTITY_PANDA_AGGRESSIVE_AMBIENT": return EsSound.createUnchecked("entity.panda.aggressive_ambient"); + case "ENTITY_PANDA_AMBIENT": return EsSound.createUnchecked("entity.panda.ambient"); + case "ENTITY_PANDA_BITE": return EsSound.createUnchecked("entity.panda.bite"); + case "ENTITY_PANDA_CANT_BREED": return EsSound.createUnchecked("entity.panda.cant_breed"); + case "ENTITY_PANDA_DEATH": return EsSound.createUnchecked("entity.panda.death"); + case "ENTITY_PANDA_EAT": return EsSound.createUnchecked("entity.panda.eat"); + case "ENTITY_PANDA_HURT": return EsSound.createUnchecked("entity.panda.hurt"); + case "ENTITY_PANDA_PRE_SNEEZE": return EsSound.createUnchecked("entity.panda.pre_sneeze"); + case "ENTITY_PANDA_SNEEZE": return EsSound.createUnchecked("entity.panda.sneeze"); + case "ENTITY_PANDA_STEP": return EsSound.createUnchecked("entity.panda.step"); + case "ENTITY_PANDA_WORRIED_AMBIENT": return EsSound.createUnchecked("entity.panda.worried_ambient"); + case "ENTITY_PARROT_AMBIENT": return EsSound.createUnchecked("entity.parrot.ambient"); + case "ENTITY_PARROT_DEATH": return EsSound.createUnchecked("entity.parrot.death"); + case "ENTITY_PARROT_EAT": return EsSound.createUnchecked("entity.parrot.eat"); + case "ENTITY_PARROT_FLY": return EsSound.createUnchecked("entity.parrot.fly"); + case "ENTITY_PARROT_HURT": return EsSound.createUnchecked("entity.parrot.hurt"); + case "ENTITY_PARROT_IMITATE_BLAZE": return EsSound.createUnchecked("entity.parrot.imitate.blaze"); + case "ENTITY_PARROT_IMITATE_CREEPER": return EsSound.createUnchecked("entity.parrot.imitate.creeper"); + case "ENTITY_PARROT_IMITATE_DROWNED": return EsSound.createUnchecked("entity.parrot.imitate.drowned"); + case "ENTITY_PARROT_IMITATE_ELDER_GUARDIAN": return EsSound.createUnchecked("entity.parrot.imitate.elder_guardian"); + case "ENTITY_PARROT_IMITATE_ENDERMITE": return EsSound.createUnchecked("entity.parrot.imitate.endermite"); + case "ENTITY_PARROT_IMITATE_ENDER_DRAGON": return EsSound.createUnchecked("entity.parrot.imitate.ender_dragon"); + case "ENTITY_PARROT_IMITATE_EVOKER": return EsSound.createUnchecked("entity.parrot.imitate.evoker"); + case "ENTITY_PARROT_IMITATE_GHAST": return EsSound.createUnchecked("entity.parrot.imitate.ghast"); + case "ENTITY_PARROT_IMITATE_GUARDIAN": return EsSound.createUnchecked("entity.parrot.imitate.guardian"); + case "ENTITY_PARROT_IMITATE_HOGLIN": return EsSound.createUnchecked("entity.parrot.imitate.hoglin"); + case "ENTITY_PARROT_IMITATE_HUSK": return EsSound.createUnchecked("entity.parrot.imitate.husk"); + case "ENTITY_PARROT_IMITATE_ILLUSIONER": return EsSound.createUnchecked("entity.parrot.imitate.illusioner"); + case "ENTITY_PARROT_IMITATE_MAGMA_CUBE": return EsSound.createUnchecked("entity.parrot.imitate.magma_cube"); + case "ENTITY_PARROT_IMITATE_PHANTOM": return EsSound.createUnchecked("entity.parrot.imitate.phantom"); + case "ENTITY_PARROT_IMITATE_PIGLIN": return EsSound.createUnchecked("entity.parrot.imitate.piglin"); + case "ENTITY_PARROT_IMITATE_PIGLIN_BRUTE": return EsSound.createUnchecked("entity.parrot.imitate.piglin_brute"); + case "ENTITY_PARROT_IMITATE_PILLAGER": return EsSound.createUnchecked("entity.parrot.imitate.pillager"); + case "ENTITY_PARROT_IMITATE_RAVAGER": return EsSound.createUnchecked("entity.parrot.imitate.ravager"); + case "ENTITY_PARROT_IMITATE_SHULKER": return EsSound.createUnchecked("entity.parrot.imitate.shulker"); + case "ENTITY_PARROT_IMITATE_SILVERFISH": return EsSound.createUnchecked("entity.parrot.imitate.silverfish"); + case "ENTITY_PARROT_IMITATE_SKELETON": return EsSound.createUnchecked("entity.parrot.imitate.skeleton"); + case "ENTITY_PARROT_IMITATE_SLIME": return EsSound.createUnchecked("entity.parrot.imitate.slime"); + case "ENTITY_PARROT_IMITATE_SPIDER": return EsSound.createUnchecked("entity.parrot.imitate.spider"); + case "ENTITY_PARROT_IMITATE_STRAY": return EsSound.createUnchecked("entity.parrot.imitate.stray"); + case "ENTITY_PARROT_IMITATE_VEX": return EsSound.createUnchecked("entity.parrot.imitate.vex"); + case "ENTITY_PARROT_IMITATE_VINDICATOR": return EsSound.createUnchecked("entity.parrot.imitate.vindicator"); + case "ENTITY_PARROT_IMITATE_WITCH": return EsSound.createUnchecked("entity.parrot.imitate.witch"); + case "ENTITY_PARROT_IMITATE_WITHER": return EsSound.createUnchecked("entity.parrot.imitate.wither"); + case "ENTITY_PARROT_IMITATE_WITHER_SKELETON": return EsSound.createUnchecked("entity.parrot.imitate.wither_skeleton"); + case "ENTITY_PARROT_IMITATE_ZOGLIN": return EsSound.createUnchecked("entity.parrot.imitate.zoglin"); + case "ENTITY_PARROT_IMITATE_ZOMBIE": return EsSound.createUnchecked("entity.parrot.imitate.zombie"); + case "ENTITY_PARROT_IMITATE_ZOMBIE_VILLAGER": return EsSound.createUnchecked("entity.parrot.imitate.zombie_villager"); + case "ENTITY_PARROT_STEP": return EsSound.createUnchecked("entity.parrot.step"); + case "ENTITY_PHANTOM_AMBIENT": return EsSound.createUnchecked("entity.phantom.ambient"); + case "ENTITY_PHANTOM_BITE": return EsSound.createUnchecked("entity.phantom.bite"); + case "ENTITY_PHANTOM_DEATH": return EsSound.createUnchecked("entity.phantom.death"); + case "ENTITY_PHANTOM_FLAP": return EsSound.createUnchecked("entity.phantom.flap"); + case "ENTITY_PHANTOM_HURT": return EsSound.createUnchecked("entity.phantom.hurt"); + case "ENTITY_PHANTOM_SWOOP": return EsSound.createUnchecked("entity.phantom.swoop"); + case "ENTITY_PIGLIN_ADMIRING_ITEM": return EsSound.createUnchecked("entity.piglin.admiring_item"); + case "ENTITY_PIGLIN_AMBIENT": return EsSound.createUnchecked("entity.piglin.ambient"); + case "ENTITY_PIGLIN_ANGRY": return EsSound.createUnchecked("entity.piglin.angry"); + case "ENTITY_PIGLIN_BRUTE_AMBIENT": return EsSound.createUnchecked("entity.piglin_brute.ambient"); + case "ENTITY_PIGLIN_BRUTE_ANGRY": return EsSound.createUnchecked("entity.piglin_brute.angry"); + case "ENTITY_PIGLIN_BRUTE_CONVERTED_TO_ZOMBIFIED": return EsSound.createUnchecked("entity.piglin_brute.converted_to_zombified"); + case "ENTITY_PIGLIN_BRUTE_DEATH": return EsSound.createUnchecked("entity.piglin_brute.death"); + case "ENTITY_PIGLIN_BRUTE_HURT": return EsSound.createUnchecked("entity.piglin_brute.hurt"); + case "ENTITY_PIGLIN_BRUTE_STEP": return EsSound.createUnchecked("entity.piglin_brute.step"); + case "ENTITY_PIGLIN_CELEBRATE": return EsSound.createUnchecked("entity.piglin.celebrate"); + case "ENTITY_PIGLIN_CONVERTED_TO_ZOMBIFIED": return EsSound.createUnchecked("entity.piglin.converted_to_zombified"); + case "ENTITY_PIGLIN_DEATH": return EsSound.createUnchecked("entity.piglin.death"); + case "ENTITY_PIGLIN_HURT": return EsSound.createUnchecked("entity.piglin.hurt"); + case "ENTITY_PIGLIN_JEALOUS": return EsSound.createUnchecked("entity.piglin.jealous"); + case "ENTITY_PIGLIN_RETREAT": return EsSound.createUnchecked("entity.piglin.retreat"); + case "ENTITY_PIGLIN_STEP": return EsSound.createUnchecked("entity.piglin.step"); + case "ENTITY_PIG_AMBIENT": return EsSound.createUnchecked("entity.pig.ambient"); + case "ENTITY_PIG_DEATH": return EsSound.createUnchecked("entity.pig.death"); + case "ENTITY_PIG_HURT": return EsSound.createUnchecked("entity.pig.hurt"); + case "ENTITY_PIG_SADDLE": return EsSound.createUnchecked("entity.pig.saddle"); + case "ENTITY_PIG_STEP": return EsSound.createUnchecked("entity.pig.step"); + case "ENTITY_PILLAGER_AMBIENT": return EsSound.createUnchecked("entity.pillager.ambient"); + case "ENTITY_PILLAGER_CELEBRATE": return EsSound.createUnchecked("entity.pillager.celebrate"); + case "ENTITY_PILLAGER_DEATH": return EsSound.createUnchecked("entity.pillager.death"); + case "ENTITY_PILLAGER_HURT": return EsSound.createUnchecked("entity.pillager.hurt"); + case "ENTITY_PLAYER_ATTACK_CRIT": return EsSound.createUnchecked("entity.player.attack.crit"); + case "ENTITY_PLAYER_ATTACK_KNOCKBACK": return EsSound.createUnchecked("entity.player.attack.knockback"); + case "ENTITY_PLAYER_ATTACK_NODAMAGE": return EsSound.createUnchecked("entity.player.attack.nodamage"); + case "ENTITY_PLAYER_ATTACK_STRONG": return EsSound.createUnchecked("entity.player.attack.strong"); + case "ENTITY_PLAYER_ATTACK_SWEEP": return EsSound.createUnchecked("entity.player.attack.sweep"); + case "ENTITY_PLAYER_ATTACK_WEAK": return EsSound.createUnchecked("entity.player.attack.weak"); + case "ENTITY_PLAYER_BIG_FALL": return EsSound.createUnchecked("entity.player.big_fall"); + case "ENTITY_PLAYER_BREATH": return EsSound.createUnchecked("entity.player.breath"); + case "ENTITY_PLAYER_BURP": return EsSound.createUnchecked("entity.player.burp"); + case "ENTITY_PLAYER_DEATH": return EsSound.createUnchecked("entity.player.death"); + case "ENTITY_PLAYER_HURT": return EsSound.createUnchecked("entity.player.hurt"); + case "ENTITY_PLAYER_HURT_DROWN": return EsSound.createUnchecked("entity.player.hurt_drown"); + case "ENTITY_PLAYER_HURT_ON_FIRE": return EsSound.createUnchecked("entity.player.hurt_on_fire"); + case "ENTITY_PLAYER_HURT_SWEET_BERRY_BUSH": return EsSound.createUnchecked("entity.player.hurt_sweet_berry_bush"); + case "ENTITY_PLAYER_LEVELUP": return EsSound.createUnchecked("entity.player.levelup"); + case "ENTITY_PLAYER_SMALL_FALL": return EsSound.createUnchecked("entity.player.small_fall"); + case "ENTITY_PLAYER_SPLASH": return EsSound.createUnchecked("entity.player.splash"); + case "ENTITY_PLAYER_SPLASH_HIGH_SPEED": return EsSound.createUnchecked("entity.player.splash.high_speed"); + case "ENTITY_PLAYER_SWIM": return EsSound.createUnchecked("entity.player.swim"); + case "ENTITY_POLAR_BEAR_AMBIENT": return EsSound.createUnchecked("entity.polar_bear.ambient"); + case "ENTITY_POLAR_BEAR_AMBIENT_BABY": return EsSound.createUnchecked("entity.polar_bear.ambient_baby"); + case "ENTITY_POLAR_BEAR_DEATH": return EsSound.createUnchecked("entity.polar_bear.death"); + case "ENTITY_POLAR_BEAR_HURT": return EsSound.createUnchecked("entity.polar_bear.hurt"); + case "ENTITY_POLAR_BEAR_STEP": return EsSound.createUnchecked("entity.polar_bear.step"); + case "ENTITY_POLAR_BEAR_WARNING": return EsSound.createUnchecked("entity.polar_bear.warning"); + case "ENTITY_PUFFER_FISH_AMBIENT": return EsSound.createUnchecked("entity.puffer_fish.ambient"); + case "ENTITY_PUFFER_FISH_BLOW_OUT": return EsSound.createUnchecked("entity.puffer_fish.blow_out"); + case "ENTITY_PUFFER_FISH_BLOW_UP": return EsSound.createUnchecked("entity.puffer_fish.blow_up"); + case "ENTITY_PUFFER_FISH_DEATH": return EsSound.createUnchecked("entity.puffer_fish.death"); + case "ENTITY_PUFFER_FISH_FLOP": return EsSound.createUnchecked("entity.puffer_fish.flop"); + case "ENTITY_PUFFER_FISH_HURT": return EsSound.createUnchecked("entity.puffer_fish.hurt"); + case "ENTITY_PUFFER_FISH_STING": return EsSound.createUnchecked("entity.puffer_fish.sting"); + case "ENTITY_RABBIT_AMBIENT": return EsSound.createUnchecked("entity.rabbit.ambient"); + case "ENTITY_RABBIT_ATTACK": return EsSound.createUnchecked("entity.rabbit.attack"); + case "ENTITY_RABBIT_DEATH": return EsSound.createUnchecked("entity.rabbit.death"); + case "ENTITY_RABBIT_HURT": return EsSound.createUnchecked("entity.rabbit.hurt"); + case "ENTITY_RABBIT_JUMP": return EsSound.createUnchecked("entity.rabbit.jump"); + case "ENTITY_RAVAGER_AMBIENT": return EsSound.createUnchecked("entity.ravager.ambient"); + case "ENTITY_RAVAGER_ATTACK": return EsSound.createUnchecked("entity.ravager.attack"); + case "ENTITY_RAVAGER_CELEBRATE": return EsSound.createUnchecked("entity.ravager.celebrate"); + case "ENTITY_RAVAGER_DEATH": return EsSound.createUnchecked("entity.ravager.death"); + case "ENTITY_RAVAGER_HURT": return EsSound.createUnchecked("entity.ravager.hurt"); + case "ENTITY_RAVAGER_ROAR": return EsSound.createUnchecked("entity.ravager.roar"); + case "ENTITY_RAVAGER_STEP": return EsSound.createUnchecked("entity.ravager.step"); + case "ENTITY_RAVAGER_STUNNED": return EsSound.createUnchecked("entity.ravager.stunned"); + case "ENTITY_SALMON_AMBIENT": return EsSound.createUnchecked("entity.salmon.ambient"); + case "ENTITY_SALMON_DEATH": return EsSound.createUnchecked("entity.salmon.death"); + case "ENTITY_SALMON_FLOP": return EsSound.createUnchecked("entity.salmon.flop"); + case "ENTITY_SALMON_HURT": return EsSound.createUnchecked("entity.salmon.hurt"); + case "ENTITY_SHEEP_AMBIENT": return EsSound.createUnchecked("entity.sheep.ambient"); + case "ENTITY_SHEEP_DEATH": return EsSound.createUnchecked("entity.sheep.death"); + case "ENTITY_SHEEP_HURT": return EsSound.createUnchecked("entity.sheep.hurt"); + case "ENTITY_SHEEP_SHEAR": return EsSound.createUnchecked("entity.sheep.shear"); + case "ENTITY_SHEEP_STEP": return EsSound.createUnchecked("entity.sheep.step"); + case "ENTITY_SHULKER_AMBIENT": return EsSound.createUnchecked("entity.shulker.ambient"); + case "ENTITY_SHULKER_BULLET_HIT": return EsSound.createUnchecked("entity.shulker_bullet.hit"); + case "ENTITY_SHULKER_BULLET_HURT": return EsSound.createUnchecked("entity.shulker_bullet.hurt"); + case "ENTITY_SHULKER_CLOSE": return EsSound.createUnchecked("entity.shulker.close"); + case "ENTITY_SHULKER_DEATH": return EsSound.createUnchecked("entity.shulker.death"); + case "ENTITY_SHULKER_HURT": return EsSound.createUnchecked("entity.shulker.hurt"); + case "ENTITY_SHULKER_HURT_CLOSED": return EsSound.createUnchecked("entity.shulker.hurt_closed"); + case "ENTITY_SHULKER_OPEN": return EsSound.createUnchecked("entity.shulker.open"); + case "ENTITY_SHULKER_SHOOT": return EsSound.createUnchecked("entity.shulker.shoot"); + case "ENTITY_SHULKER_TELEPORT": return EsSound.createUnchecked("entity.shulker.teleport"); + case "ENTITY_SILVERFISH_AMBIENT": return EsSound.createUnchecked("entity.silverfish.ambient"); + case "ENTITY_SILVERFISH_DEATH": return EsSound.createUnchecked("entity.silverfish.death"); + case "ENTITY_SILVERFISH_HURT": return EsSound.createUnchecked("entity.silverfish.hurt"); + case "ENTITY_SILVERFISH_STEP": return EsSound.createUnchecked("entity.silverfish.step"); + case "ENTITY_SKELETON_AMBIENT": return EsSound.createUnchecked("entity.skeleton.ambient"); + case "ENTITY_SKELETON_DEATH": return EsSound.createUnchecked("entity.skeleton.death"); + case "ENTITY_SKELETON_HORSE_AMBIENT": return EsSound.createUnchecked("entity.skeleton_horse.ambient"); + case "ENTITY_SKELETON_HORSE_AMBIENT_WATER": return EsSound.createUnchecked("entity.skeleton_horse.ambient_water"); + case "ENTITY_SKELETON_HORSE_DEATH": return EsSound.createUnchecked("entity.skeleton_horse.death"); + case "ENTITY_SKELETON_HORSE_GALLOP_WATER": return EsSound.createUnchecked("entity.skeleton_horse.gallop_water"); + case "ENTITY_SKELETON_HORSE_HURT": return EsSound.createUnchecked("entity.skeleton_horse.hurt"); + case "ENTITY_SKELETON_HORSE_JUMP_WATER": return EsSound.createUnchecked("entity.skeleton_horse.jump_water"); + case "ENTITY_SKELETON_HORSE_STEP_WATER": return EsSound.createUnchecked("entity.skeleton_horse.step_water"); + case "ENTITY_SKELETON_HORSE_SWIM": return EsSound.createUnchecked("entity.skeleton_horse.swim"); + case "ENTITY_SKELETON_HURT": return EsSound.createUnchecked("entity.skeleton.hurt"); + case "ENTITY_SKELETON_SHOOT": return EsSound.createUnchecked("entity.skeleton.shoot"); + case "ENTITY_SKELETON_STEP": return EsSound.createUnchecked("entity.skeleton.step"); + case "ENTITY_SLIME_ATTACK": return EsSound.createUnchecked("entity.slime.attack"); + case "ENTITY_SLIME_DEATH": return EsSound.createUnchecked("entity.slime.death"); + case "ENTITY_SLIME_DEATH_SMALL": return EsSound.createUnchecked("entity.slime.death_small"); + case "ENTITY_SLIME_HURT": return EsSound.createUnchecked("entity.slime.hurt"); + case "ENTITY_SLIME_HURT_SMALL": return EsSound.createUnchecked("entity.slime.hurt_small"); + case "ENTITY_SLIME_JUMP": return EsSound.createUnchecked("entity.slime.jump"); + case "ENTITY_SLIME_JUMP_SMALL": return EsSound.createUnchecked("entity.slime.jump_small"); + case "ENTITY_SLIME_SQUISH": return EsSound.createUnchecked("entity.slime.squish"); + case "ENTITY_SLIME_SQUISH_SMALL": return EsSound.createUnchecked("entity.slime.squish_small"); + case "ENTITY_SNOWBALL_THROW": return EsSound.createUnchecked("entity.snowball.throw"); + case "ENTITY_SNOW_GOLEM_AMBIENT": return EsSound.createUnchecked("entity.snow_golem.ambient"); + case "ENTITY_SNOW_GOLEM_DEATH": return EsSound.createUnchecked("entity.snow_golem.death"); + case "ENTITY_SNOW_GOLEM_HURT": return EsSound.createUnchecked("entity.snow_golem.hurt"); + case "ENTITY_SNOW_GOLEM_SHEAR": return EsSound.createUnchecked("entity.snow_golem.shear"); + case "ENTITY_SNOW_GOLEM_SHOOT": return EsSound.createUnchecked("entity.snow_golem.shoot"); + case "ENTITY_SPIDER_AMBIENT": return EsSound.createUnchecked("entity.spider.ambient"); + case "ENTITY_SPIDER_DEATH": return EsSound.createUnchecked("entity.spider.death"); + case "ENTITY_SPIDER_HURT": return EsSound.createUnchecked("entity.spider.hurt"); + case "ENTITY_SPIDER_STEP": return EsSound.createUnchecked("entity.spider.step"); + case "ENTITY_SPLASH_POTION_BREAK": return EsSound.createUnchecked("entity.splash_potion.break"); + case "ENTITY_SPLASH_POTION_THROW": return EsSound.createUnchecked("entity.splash_potion.throw"); + case "ENTITY_SQUID_AMBIENT": return EsSound.createUnchecked("entity.squid.ambient"); + case "ENTITY_SQUID_DEATH": return EsSound.createUnchecked("entity.squid.death"); + case "ENTITY_SQUID_HURT": return EsSound.createUnchecked("entity.squid.hurt"); + case "ENTITY_SQUID_SQUIRT": return EsSound.createUnchecked("entity.squid.squirt"); + case "ENTITY_STRAY_AMBIENT": return EsSound.createUnchecked("entity.stray.ambient"); + case "ENTITY_STRAY_DEATH": return EsSound.createUnchecked("entity.stray.death"); + case "ENTITY_STRAY_HURT": return EsSound.createUnchecked("entity.stray.hurt"); + case "ENTITY_STRAY_STEP": return EsSound.createUnchecked("entity.stray.step"); + case "ENTITY_STRIDER_AMBIENT": return EsSound.createUnchecked("entity.strider.ambient"); + case "ENTITY_STRIDER_DEATH": return EsSound.createUnchecked("entity.strider.death"); + case "ENTITY_STRIDER_EAT": return EsSound.createUnchecked("entity.strider.eat"); + case "ENTITY_STRIDER_HAPPY": return EsSound.createUnchecked("entity.strider.happy"); + case "ENTITY_STRIDER_HURT": return EsSound.createUnchecked("entity.strider.hurt"); + case "ENTITY_STRIDER_RETREAT": return EsSound.createUnchecked("entity.strider.retreat"); + case "ENTITY_STRIDER_SADDLE": return EsSound.createUnchecked("entity.strider.saddle"); + case "ENTITY_STRIDER_STEP": return EsSound.createUnchecked("entity.strider.step"); + case "ENTITY_STRIDER_STEP_LAVA": return EsSound.createUnchecked("entity.strider.step_lava"); + case "ENTITY_TNT_PRIMED": return EsSound.createUnchecked("entity.tnt.primed"); + case "ENTITY_TROPICAL_FISH_AMBIENT": return EsSound.createUnchecked("entity.tropical_fish.ambient"); + case "ENTITY_TROPICAL_FISH_DEATH": return EsSound.createUnchecked("entity.tropical_fish.death"); + case "ENTITY_TROPICAL_FISH_FLOP": return EsSound.createUnchecked("entity.tropical_fish.flop"); + case "ENTITY_TROPICAL_FISH_HURT": return EsSound.createUnchecked("entity.tropical_fish.hurt"); + case "ENTITY_TURTLE_AMBIENT_LAND": return EsSound.createUnchecked("entity.turtle.ambient_land"); + case "ENTITY_TURTLE_DEATH": return EsSound.createUnchecked("entity.turtle.death"); + case "ENTITY_TURTLE_DEATH_BABY": return EsSound.createUnchecked("entity.turtle.death_baby"); + case "ENTITY_TURTLE_EGG_BREAK": return EsSound.createUnchecked("entity.turtle.egg_break"); + case "ENTITY_TURTLE_EGG_CRACK": return EsSound.createUnchecked("entity.turtle.egg_crack"); + case "ENTITY_TURTLE_EGG_HATCH": return EsSound.createUnchecked("entity.turtle.egg_hatch"); + case "ENTITY_TURTLE_HURT": return EsSound.createUnchecked("entity.turtle.hurt"); + case "ENTITY_TURTLE_HURT_BABY": return EsSound.createUnchecked("entity.turtle.hurt_baby"); + case "ENTITY_TURTLE_LAY_EGG": return EsSound.createUnchecked("entity.turtle.lay_egg"); + case "ENTITY_TURTLE_SHAMBLE": return EsSound.createUnchecked("entity.turtle.shamble"); + case "ENTITY_TURTLE_SHAMBLE_BABY": return EsSound.createUnchecked("entity.turtle.shamble_baby"); + case "ENTITY_TURTLE_SWIM": return EsSound.createUnchecked("entity.turtle.swim"); + case "ENTITY_VEX_AMBIENT": return EsSound.createUnchecked("entity.vex.ambient"); + case "ENTITY_VEX_CHARGE": return EsSound.createUnchecked("entity.vex.charge"); + case "ENTITY_VEX_DEATH": return EsSound.createUnchecked("entity.vex.death"); + case "ENTITY_VEX_HURT": return EsSound.createUnchecked("entity.vex.hurt"); + case "ENTITY_VILLAGER_AMBIENT": return EsSound.createUnchecked("entity.villager.ambient"); + case "ENTITY_VILLAGER_CELEBRATE": return EsSound.createUnchecked("entity.villager.celebrate"); + case "ENTITY_VILLAGER_DEATH": return EsSound.createUnchecked("entity.villager.death"); + case "ENTITY_VILLAGER_HURT": return EsSound.createUnchecked("entity.villager.hurt"); + case "ENTITY_VILLAGER_NO": return EsSound.createUnchecked("entity.villager.no"); + case "ENTITY_VILLAGER_TRADE": return EsSound.createUnchecked("entity.villager.trade"); + case "ENTITY_VILLAGER_WORK_ARMORER": return EsSound.createUnchecked("entity.villager.work_armorer"); + case "ENTITY_VILLAGER_WORK_BUTCHER": return EsSound.createUnchecked("entity.villager.work_butcher"); + case "ENTITY_VILLAGER_WORK_CARTOGRAPHER": return EsSound.createUnchecked("entity.villager.work_cartographer"); + case "ENTITY_VILLAGER_WORK_CLERIC": return EsSound.createUnchecked("entity.villager.work_cleric"); + case "ENTITY_VILLAGER_WORK_FARMER": return EsSound.createUnchecked("entity.villager.work_farmer"); + case "ENTITY_VILLAGER_WORK_FISHERMAN": return EsSound.createUnchecked("entity.villager.work_fisherman"); + case "ENTITY_VILLAGER_WORK_FLETCHER": return EsSound.createUnchecked("entity.villager.work_fletcher"); + case "ENTITY_VILLAGER_WORK_LEATHERWORKER": return EsSound.createUnchecked("entity.villager.work_leatherworker"); + case "ENTITY_VILLAGER_WORK_LIBRARIAN": return EsSound.createUnchecked("entity.villager.work_librarian"); + case "ENTITY_VILLAGER_WORK_MASON": return EsSound.createUnchecked("entity.villager.work_mason"); + case "ENTITY_VILLAGER_WORK_SHEPHERD": return EsSound.createUnchecked("entity.villager.work_shepherd"); + case "ENTITY_VILLAGER_WORK_TOOLSMITH": return EsSound.createUnchecked("entity.villager.work_toolsmith"); + case "ENTITY_VILLAGER_WORK_WEAPONSMITH": return EsSound.createUnchecked("entity.villager.work_weaponsmith"); + case "ENTITY_VILLAGER_YES": return EsSound.createUnchecked("entity.villager.yes"); + case "ENTITY_VINDICATOR_AMBIENT": return EsSound.createUnchecked("entity.vindicator.ambient"); + case "ENTITY_VINDICATOR_CELEBRATE": return EsSound.createUnchecked("entity.vindicator.celebrate"); + case "ENTITY_VINDICATOR_DEATH": return EsSound.createUnchecked("entity.vindicator.death"); + case "ENTITY_VINDICATOR_HURT": return EsSound.createUnchecked("entity.vindicator.hurt"); + case "ENTITY_WANDERING_TRADER_AMBIENT": return EsSound.createUnchecked("entity.wandering_trader.ambient"); + case "ENTITY_WANDERING_TRADER_DEATH": return EsSound.createUnchecked("entity.wandering_trader.death"); + case "ENTITY_WANDERING_TRADER_DISAPPEARED": return EsSound.createUnchecked("entity.wandering_trader.disappeared"); + case "ENTITY_WANDERING_TRADER_DRINK_MILK": return EsSound.createUnchecked("entity.wandering_trader.drink_milk"); + case "ENTITY_WANDERING_TRADER_DRINK_POTION": return EsSound.createUnchecked("entity.wandering_trader.drink_potion"); + case "ENTITY_WANDERING_TRADER_HURT": return EsSound.createUnchecked("entity.wandering_trader.hurt"); + case "ENTITY_WANDERING_TRADER_NO": return EsSound.createUnchecked("entity.wandering_trader.no"); + case "ENTITY_WANDERING_TRADER_REAPPEARED": return EsSound.createUnchecked("entity.wandering_trader.reappeared"); + case "ENTITY_WANDERING_TRADER_TRADE": return EsSound.createUnchecked("entity.wandering_trader.trade"); + case "ENTITY_WANDERING_TRADER_YES": return EsSound.createUnchecked("entity.wandering_trader.yes"); + case "ENTITY_WITCH_AMBIENT": return EsSound.createUnchecked("entity.witch.ambient"); + case "ENTITY_WITCH_CELEBRATE": return EsSound.createUnchecked("entity.witch.celebrate"); + case "ENTITY_WITCH_DEATH": return EsSound.createUnchecked("entity.witch.death"); + case "ENTITY_WITCH_DRINK": return EsSound.createUnchecked("entity.witch.drink"); + case "ENTITY_WITCH_HURT": return EsSound.createUnchecked("entity.witch.hurt"); + case "ENTITY_WITCH_THROW": return EsSound.createUnchecked("entity.witch.throw"); + case "ENTITY_WITHER_AMBIENT": return EsSound.createUnchecked("entity.wither.ambient"); + case "ENTITY_WITHER_BREAK_BLOCK": return EsSound.createUnchecked("entity.wither.break_block"); + case "ENTITY_WITHER_DEATH": return EsSound.createUnchecked("entity.wither.death"); + case "ENTITY_WITHER_HURT": return EsSound.createUnchecked("entity.wither.hurt"); + case "ENTITY_WITHER_SHOOT": return EsSound.createUnchecked("entity.wither.shoot"); + case "ENTITY_WITHER_SKELETON_AMBIENT": return EsSound.createUnchecked("entity.wither_skeleton.ambient"); + case "ENTITY_WITHER_SKELETON_DEATH": return EsSound.createUnchecked("entity.wither_skeleton.death"); + case "ENTITY_WITHER_SKELETON_HURT": return EsSound.createUnchecked("entity.wither_skeleton.hurt"); + case "ENTITY_WITHER_SKELETON_STEP": return EsSound.createUnchecked("entity.wither_skeleton.step"); + case "ENTITY_WITHER_SPAWN": return EsSound.createUnchecked("entity.wither.spawn"); + case "ENTITY_WOLF_AMBIENT": return EsSound.createUnchecked("entity.wolf.ambient"); + case "ENTITY_WOLF_DEATH": return EsSound.createUnchecked("entity.wolf.death"); + case "ENTITY_WOLF_GROWL": return EsSound.createUnchecked("entity.wolf.growl"); + case "ENTITY_WOLF_HOWL": return EsSound.createUnchecked("entity.wolf.howl"); + case "ENTITY_WOLF_HURT": return EsSound.createUnchecked("entity.wolf.hurt"); + case "ENTITY_WOLF_PANT": return EsSound.createUnchecked("entity.wolf.pant"); + case "ENTITY_WOLF_SHAKE": return EsSound.createUnchecked("entity.wolf.shake"); + case "ENTITY_WOLF_STEP": return EsSound.createUnchecked("entity.wolf.step"); + case "ENTITY_WOLF_WHINE": return EsSound.createUnchecked("entity.wolf.whine"); + case "ENTITY_ZOGLIN_AMBIENT": return EsSound.createUnchecked("entity.zoglin.ambient"); + case "ENTITY_ZOGLIN_ANGRY": return EsSound.createUnchecked("entity.zoglin.angry"); + case "ENTITY_ZOGLIN_ATTACK": return EsSound.createUnchecked("entity.zoglin.attack"); + case "ENTITY_ZOGLIN_DEATH": return EsSound.createUnchecked("entity.zoglin.death"); + case "ENTITY_ZOGLIN_HURT": return EsSound.createUnchecked("entity.zoglin.hurt"); + case "ENTITY_ZOGLIN_STEP": return EsSound.createUnchecked("entity.zoglin.step"); + case "ENTITY_ZOMBIE_AMBIENT": return EsSound.createUnchecked("entity.zombie.ambient"); + case "ENTITY_ZOMBIE_ATTACK_IRON_DOOR": return EsSound.createUnchecked("entity.zombie.attack_iron_door"); + case "ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR": return EsSound.createUnchecked("entity.zombie.attack_wooden_door"); + case "ENTITY_ZOMBIE_BREAK_WOODEN_DOOR": return EsSound.createUnchecked("entity.zombie.break_wooden_door"); + case "ENTITY_ZOMBIE_CONVERTED_TO_DROWNED": return EsSound.createUnchecked("entity.zombie.converted_to_drowned"); + case "ENTITY_ZOMBIE_DEATH": return EsSound.createUnchecked("entity.zombie.death"); + case "ENTITY_ZOMBIE_DESTROY_EGG": return EsSound.createUnchecked("entity.zombie.destroy_egg"); + case "ENTITY_ZOMBIE_HORSE_AMBIENT": return EsSound.createUnchecked("entity.zombie_horse.ambient"); + case "ENTITY_ZOMBIE_HORSE_DEATH": return EsSound.createUnchecked("entity.zombie_horse.death"); + case "ENTITY_ZOMBIE_HORSE_HURT": return EsSound.createUnchecked("entity.zombie_horse.hurt"); + case "ENTITY_ZOMBIE_HURT": return EsSound.createUnchecked("entity.zombie.hurt"); + case "ENTITY_ZOMBIE_INFECT": return EsSound.createUnchecked("entity.zombie.infect"); + case "ENTITY_ZOMBIE_STEP": return EsSound.createUnchecked("entity.zombie.step"); + case "ENTITY_ZOMBIE_VILLAGER_AMBIENT": return EsSound.createUnchecked("entity.zombie_villager.ambient"); + case "ENTITY_ZOMBIE_VILLAGER_CONVERTED": return EsSound.createUnchecked("entity.zombie_villager.converted"); + case "ENTITY_ZOMBIE_VILLAGER_CURE": return EsSound.createUnchecked("entity.zombie_villager.cure"); + case "ENTITY_ZOMBIE_VILLAGER_DEATH": return EsSound.createUnchecked("entity.zombie_villager.death"); + case "ENTITY_ZOMBIE_VILLAGER_HURT": return EsSound.createUnchecked("entity.zombie_villager.hurt"); + case "ENTITY_ZOMBIE_VILLAGER_STEP": return EsSound.createUnchecked("entity.zombie_villager.step"); + case "ENTITY_ZOMBIFIED_PIGLIN_AMBIENT": return EsSound.createUnchecked("entity.zombified_piglin.ambient"); + case "ENTITY_ZOMBIFIED_PIGLIN_ANGRY": return EsSound.createUnchecked("entity.zombified_piglin.angry"); + case "ENTITY_ZOMBIFIED_PIGLIN_DEATH": return EsSound.createUnchecked("entity.zombified_piglin.death"); + case "ENTITY_ZOMBIFIED_PIGLIN_HURT": return EsSound.createUnchecked("entity.zombified_piglin.hurt"); + case "EVENT_RAID_HORN": return EsSound.createUnchecked("event.raid.horn"); + case "ITEM_ARMOR_EQUIP_CHAIN": return EsSound.createUnchecked("item.armor.equip_chain"); + case "ITEM_ARMOR_EQUIP_DIAMOND": return EsSound.createUnchecked("item.armor.equip_diamond"); + case "ITEM_ARMOR_EQUIP_ELYTRA": return EsSound.createUnchecked("item.armor.equip_elytra"); + case "ITEM_ARMOR_EQUIP_GENERIC": return EsSound.createUnchecked("item.armor.equip_generic"); + case "ITEM_ARMOR_EQUIP_GOLD": return EsSound.createUnchecked("item.armor.equip_gold"); + case "ITEM_ARMOR_EQUIP_IRON": return EsSound.createUnchecked("item.armor.equip_iron"); + case "ITEM_ARMOR_EQUIP_LEATHER": return EsSound.createUnchecked("item.armor.equip_leather"); + case "ITEM_ARMOR_EQUIP_NETHERITE": return EsSound.createUnchecked("item.armor.equip_netherite"); + case "ITEM_ARMOR_EQUIP_TURTLE": return EsSound.createUnchecked("item.armor.equip_turtle"); + case "ITEM_AXE_STRIP": return EsSound.createUnchecked("item.axe.strip"); + case "ITEM_BOOK_PAGE_TURN": return EsSound.createUnchecked("item.book.page_turn"); + case "ITEM_BOOK_PUT": return EsSound.createUnchecked("item.book.put"); + case "ITEM_BOTTLE_EMPTY": return EsSound.createUnchecked("item.bottle.empty"); + case "ITEM_BOTTLE_FILL": return EsSound.createUnchecked("item.bottle.fill"); + case "ITEM_BOTTLE_FILL_DRAGONBREATH": return EsSound.createUnchecked("item.bottle.fill_dragonbreath"); + case "ITEM_BUCKET_EMPTY": return EsSound.createUnchecked("item.bucket.empty"); + case "ITEM_BUCKET_EMPTY_FISH": return EsSound.createUnchecked("item.bucket.empty_fish"); + case "ITEM_BUCKET_EMPTY_LAVA": return EsSound.createUnchecked("item.bucket.empty_lava"); + case "ITEM_BUCKET_FILL": return EsSound.createUnchecked("item.bucket.fill"); + case "ITEM_BUCKET_FILL_FISH": return EsSound.createUnchecked("item.bucket.fill_fish"); + case "ITEM_BUCKET_FILL_LAVA": return EsSound.createUnchecked("item.bucket.fill_lava"); + case "ITEM_CHORUS_FRUIT_TELEPORT": return EsSound.createUnchecked("item.chorus_fruit.teleport"); + case "ITEM_CROP_PLANT": return EsSound.createUnchecked("item.crop.plant"); + case "ITEM_CROSSBOW_HIT": return EsSound.createUnchecked("item.crossbow.hit"); + case "ITEM_CROSSBOW_LOADING_END": return EsSound.createUnchecked("item.crossbow.loading_end"); + case "ITEM_CROSSBOW_LOADING_MIDDLE": return EsSound.createUnchecked("item.crossbow.loading_middle"); + case "ITEM_CROSSBOW_LOADING_START": return EsSound.createUnchecked("item.crossbow.loading_start"); + case "ITEM_CROSSBOW_QUICK_CHARGE_1": return EsSound.createUnchecked("item.crossbow.quick_charge_1"); + case "ITEM_CROSSBOW_QUICK_CHARGE_2": return EsSound.createUnchecked("item.crossbow.quick_charge_2"); + case "ITEM_CROSSBOW_QUICK_CHARGE_3": return EsSound.createUnchecked("item.crossbow.quick_charge_3"); + case "ITEM_CROSSBOW_SHOOT": return EsSound.createUnchecked("item.crossbow.shoot"); + case "ITEM_ELYTRA_FLYING": return EsSound.createUnchecked("item.elytra.flying"); + case "ITEM_FIRECHARGE_USE": return EsSound.createUnchecked("item.firecharge.use"); + case "ITEM_FLINTANDSTEEL_USE": return EsSound.createUnchecked("item.flintandsteel.use"); + case "ITEM_HOE_TILL": return EsSound.createUnchecked("item.hoe.till"); + case "ITEM_HONEY_BOTTLE_DRINK": return EsSound.createUnchecked("item.honey_bottle.drink"); + case "ITEM_LODESTONE_COMPASS_LOCK": return EsSound.createUnchecked("item.lodestone_compass.lock"); + case "ITEM_NETHER_WART_PLANT": return EsSound.createUnchecked("item.nether_wart.plant"); + case "ITEM_SHIELD_BLOCK": return EsSound.createUnchecked("item.shield.block"); + case "ITEM_SHIELD_BREAK": return EsSound.createUnchecked("item.shield.break"); + case "ITEM_SHOVEL_FLATTEN": return EsSound.createUnchecked("item.shovel.flatten"); + case "ITEM_SWEET_BERRIES_PICK_FROM_BUSH": return EsSound.createUnchecked("item.sweet_berries.pick_from_bush"); + case "ITEM_TOTEM_USE": return EsSound.createUnchecked("item.totem.use"); + case "ITEM_TRIDENT_HIT": return EsSound.createUnchecked("item.trident.hit"); + case "ITEM_TRIDENT_HIT_GROUND": return EsSound.createUnchecked("item.trident.hit_ground"); + case "ITEM_TRIDENT_RETURN": return EsSound.createUnchecked("item.trident.return"); + case "ITEM_TRIDENT_RIPTIDE_1": return EsSound.createUnchecked("item.trident.riptide_1"); + case "ITEM_TRIDENT_RIPTIDE_2": return EsSound.createUnchecked("item.trident.riptide_2"); + case "ITEM_TRIDENT_RIPTIDE_3": return EsSound.createUnchecked("item.trident.riptide_3"); + case "ITEM_TRIDENT_THROW": return EsSound.createUnchecked("item.trident.throw"); + case "ITEM_TRIDENT_THUNDER": return EsSound.createUnchecked("item.trident.thunder"); + case "MUSIC_CREATIVE": return EsSound.createUnchecked("music.creative"); + case "MUSIC_CREDITS": return EsSound.createUnchecked("music.credits"); + case "MUSIC_DISC_11": return EsSound.createUnchecked("music_disc.11"); + case "MUSIC_DISC_13": return EsSound.createUnchecked("music_disc.13"); + case "MUSIC_DISC_BLOCKS": return EsSound.createUnchecked("music_disc.blocks"); + case "MUSIC_DISC_CAT": return EsSound.createUnchecked("music_disc.cat"); + case "MUSIC_DISC_CHIRP": return EsSound.createUnchecked("music_disc.chirp"); + case "MUSIC_DISC_FAR": return EsSound.createUnchecked("music_disc.far"); + case "MUSIC_DISC_MALL": return EsSound.createUnchecked("music_disc.mall"); + case "MUSIC_DISC_MELLOHI": return EsSound.createUnchecked("music_disc.mellohi"); + case "MUSIC_DISC_PIGSTEP": return EsSound.createUnchecked("music_disc.pigstep"); + case "MUSIC_DISC_STAL": return EsSound.createUnchecked("music_disc.stal"); + case "MUSIC_DISC_STRAD": return EsSound.createUnchecked("music_disc.strad"); + case "MUSIC_DISC_WAIT": return EsSound.createUnchecked("music_disc.wait"); + case "MUSIC_DISC_WARD": return EsSound.createUnchecked("music_disc.ward"); + case "MUSIC_DRAGON": return EsSound.createUnchecked("music.dragon"); + case "MUSIC_END": return EsSound.createUnchecked("music.end"); + case "MUSIC_GAME": return EsSound.createUnchecked("music.game"); + case "MUSIC_MENU": return EsSound.createUnchecked("music.menu"); + case "MUSIC_NETHER_BASALT_DELTAS": return EsSound.createUnchecked("music.nether.basalt_deltas"); + case "MUSIC_NETHER_CRIMSON_FOREST": return EsSound.createUnchecked("music.nether.crimson_forest"); + case "MUSIC_NETHER_NETHER_WASTES": return EsSound.createUnchecked("music.nether.nether_wastes"); + case "MUSIC_NETHER_SOUL_SAND_VALLEY": return EsSound.createUnchecked("music.nether.soul_sand_valley"); + case "MUSIC_NETHER_WARPED_FOREST": return EsSound.createUnchecked("music.nether.warped_forest"); + case "MUSIC_UNDER_WATER": return EsSound.createUnchecked("music.under_water"); + case "PARTICLE_SOUL_ESCAPE": return EsSound.createUnchecked("particle.soul_escape"); + case "UI_BUTTON_CLICK": return EsSound.createUnchecked("ui.button.click"); + case "UI_CARTOGRAPHY_TABLE_TAKE_RESULT": return EsSound.createUnchecked("ui.cartography_table.take_result"); + case "UI_LOOM_SELECT_PATTERN": return EsSound.createUnchecked("ui.loom.select_pattern"); + case "UI_LOOM_TAKE_RESULT": return EsSound.createUnchecked("ui.loom.take_result"); + case "UI_STONECUTTER_SELECT_RECIPE": return EsSound.createUnchecked("ui.stonecutter.select_recipe"); + case "UI_STONECUTTER_TAKE_RESULT": return EsSound.createUnchecked("ui.stonecutter.take_result"); + case "UI_TOAST_CHALLENGE_COMPLETE": return EsSound.createUnchecked("ui.toast.challenge_complete"); + case "UI_TOAST_IN": return EsSound.createUnchecked("ui.toast.in"); + case "UI_TOAST_OUT": return EsSound.createUnchecked("ui.toast.out"); + case "WEATHER_RAIN": return EsSound.createUnchecked("weather.rain"); + case "WEATHER_RAIN_ABOVE": return EsSound.createUnchecked("weather.rain.above"); + + // Older versions had different sounds, these I have converted. + case "RECORD_11": return EsSound.createUnchecked("music_disc.11"); + case "RECORD_13": return EsSound.createUnchecked("music_disc.13"); + case "RECORD_BLOCKS": return EsSound.createUnchecked("music_disc.blocks"); + case "RECORD_CAT": return EsSound.createUnchecked("music_disc.cat"); + case "RECORD_CHIRP": return EsSound.createUnchecked("music_disc.chirp"); + case "RECORD_FAR": return EsSound.createUnchecked("music_disc.far"); + case "RECORD_MALL": return EsSound.createUnchecked("music_disc.mall"); + case "RECORD_MELLOHI": return EsSound.createUnchecked("music_disc.mellohi"); + case "RECORD_STAL": return EsSound.createUnchecked("music_disc.stal"); + case "RECORD_STRAD": return EsSound.createUnchecked("music_disc.strad"); + case "RECORD_WAIT": return EsSound.createUnchecked("music_disc.wait"); + case "RECORD_WARD": return EsSound.createUnchecked("music_disc.ward"); + + // this sound used to be called something else, until we need it we can generate an incorrect name. + default: return EsSound.createUnchecked(eVal.replace('_', '.')); + } + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitSoundHelper.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitSoundHelper.java new file mode 100644 index 0000000..5277da6 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/BukkitSoundHelper.java @@ -0,0 +1,32 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsSound; +import org.bukkit.Registry; +import org.bukkit.Sound; + +import java.util.HashSet; + +/** + * Min version: 1.0 + */ +public class BukkitSoundHelper { + + public static HashSet getSounds() { + HashSet sounds = new HashSet<>(); + + if (Main.minecraftVersion.isAtLeast(1, 16, 4)) { + for (Sound sound : Registry.SOUNDS) { + EsSound esSound = EsSound.createUnchecked(sound.getKey().getKey()); + sounds.add(esSound); + } + } else if (Main.minecraftVersion.isAtLeast(1, 3, 0)) { + for (Sound sound : Sound.values()) { + EsSound esSound = BukkitSoundEnumConverter.convertEnumToKey(sound.name()); + sounds.add(esSound); + } + } // Sounds do not exist in the same way in pre 1.3 + + return sounds; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/OldWarpLocation.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/OldWarpLocation.java new file mode 100644 index 0000000..ddd5ce3 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Bukkit/Helpers/OldWarpLocation.java @@ -0,0 +1,41 @@ +package net.serble.estools.ServerApi.Implementations.Bukkit.Helpers; + +import org.bukkit.Location; +import org.bukkit.configuration.serialization.ConfigurationSerializable; +import org.bukkit.configuration.serialization.SerializableAs; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.Map; + +/** + * This class exists for the BukkitConfigMigrator so that it can parse the old warps.yml file. + */ +@SerializableAs("WarpLocation") +public class OldWarpLocation implements ConfigurationSerializable { + public Location location; + public String name; + public boolean global; + + @Override + public @NotNull Map serialize() { + Map result = new HashMap<>(); + + result.put("location", location); + result.put("name", name); + result.put("global", global); + + return result; + } + + @SuppressWarnings("unused") + public static OldWarpLocation deserialize(Map args) { + OldWarpLocation warp = new OldWarpLocation(); + + warp.location = (Location)args.get("location"); + warp.name = (String)args.get("name"); + warp.global = (boolean)args.get("global"); + + return warp; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaBlock.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaBlock.java new file mode 100644 index 0000000..ee95ac7 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaBlock.java @@ -0,0 +1,13 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitBlock; +import org.bukkit.block.BlockState; + +public class FoliaBlock extends BukkitBlock { + private final BlockState bukkitState; + + public FoliaBlock(BlockState block) { + super(block); + bukkitState = block; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaCommandBlockSender.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaCommandBlockSender.java new file mode 100644 index 0000000..996c140 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaCommandBlockSender.java @@ -0,0 +1,13 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitCommandBlockSender; +import org.bukkit.command.BlockCommandSender; + +public class FoliaCommandBlockSender extends BukkitCommandBlockSender { + private final BlockCommandSender bukkitSender; + + public FoliaCommandBlockSender(BlockCommandSender child) { + super(child); + bukkitSender = child; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaConsoleSender.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaConsoleSender.java new file mode 100644 index 0000000..bda8ea7 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaConsoleSender.java @@ -0,0 +1,13 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitConsoleSender; +import org.bukkit.command.ConsoleCommandSender; + +public class FoliaConsoleSender extends BukkitConsoleSender { + private final ConsoleCommandSender bukkitSender; + + public FoliaConsoleSender(ConsoleCommandSender child) { + super(child); + bukkitSender = child; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaEnchantmentHelper.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaEnchantmentHelper.java new file mode 100644 index 0000000..85fa7be --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaEnchantmentHelper.java @@ -0,0 +1,6 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitEnchantmentHelper; + +// This is here just in case something changes in Folia that requires methods to be overridden +public class FoliaEnchantmentHelper extends BukkitEnchantmentHelper { } diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaEntity.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaEntity.java new file mode 100644 index 0000000..4274bad --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaEntity.java @@ -0,0 +1,51 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import io.papermc.lib.PaperLib; +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsLocation; +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitEntity; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.EsEntity; +import org.bukkit.entity.Entity; + +import java.util.ArrayList; +import java.util.List; + +public class FoliaEntity extends BukkitEntity { + private final Entity bukkitEntity; + + public FoliaEntity(Entity bukkitEntity) { + super(bukkitEntity); + this.bukkitEntity = bukkitEntity; + } + + @Override + public List getPassengers() { + List bukkitList = bukkitEntity.getPassengers(); + List list = new ArrayList<>(); + for (Entity entity : bukkitList) { + list.add(BukkitHelper.fromBukkitEntity(entity)); + } + return list; + } + + @Override + public void addPassenger(EsEntity entity) { + if (Main.minecraftVersion.getMinor() > 11) { + bukkitEntity.addPassenger(((FoliaEntity) entity).getBukkitEntity()); + } else { + //noinspection deprecation + bukkitEntity.setPassenger(((FoliaEntity) entity).getBukkitEntity()); + } + } + + @Override + public EsLocation getLocation() { + return FoliaHelper.fromBukkitLocation(bukkitEntity.getLocation()); + } + + @Override + public void teleport(EsLocation loc) { + PaperLib.teleportAsync(bukkitEntity, FoliaHelper.toBukkitLocation(loc)); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaEventsListener.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaEventsListener.java new file mode 100644 index 0000000..5829fb2 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaEventsListener.java @@ -0,0 +1,168 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsAction; +import net.serble.estools.ServerApi.EsClickType; +import net.serble.estools.ServerApi.EsInventoryAction; +import net.serble.estools.ServerApi.Events.*; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitEnums1_1Plus; +import net.serble.estools.ServerApi.Interfaces.*; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryDragEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.InvocationTargetException; +import java.util.Objects; +import java.util.Set; + +public class FoliaEventsListener implements Listener, CommandExecutor { + + private double getDamageFromEvent(EntityDamageEvent e) { + if (Main.minecraftVersion.getMinor() > 5) { + return e.getDamage(); + } + + try { + return (double)(int)EntityDamageEvent.class.getMethod("getDamage").invoke(e); + } catch (Exception ex) { + Bukkit.getLogger().severe(ex.toString()); + return 0d; + } + } + + private void setDamageFromEvent(EntityDamageEvent e, @SuppressWarnings("SameParameterValue") double d) { + if (Main.minecraftVersion.getMinor() > 5) { + e.setDamage(d); + return; + } + + try { + //noinspection JavaReflectionMemberAccess, It's an int in older versions + EntityDamageEvent.class.getMethod("setDamage", int.class).invoke(e, (int) d); + } catch (Exception ex) { + Bukkit.getLogger().severe(ex.toString()); + } + } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent e) { + EsBlockPlaceEvent ee = new EsBlockPlaceEvent(new FoliaPlayer(e.getPlayer()), FoliaHelper.fromBukkitItem(e.getItemInHand()), FoliaHelper.fromBukkitEquipmentSlot(e.getHand())); + ee.setCancelled(e.isCancelled()); + Main.callEvent(ee); + e.setCancelled(ee.isCancelled()); + } + + @EventHandler + public void onTeleport(PlayerTeleportEvent e) { + EsPlayerTeleportEvent ee = new EsPlayerTeleportEvent( + new FoliaPlayer(e.getPlayer()), + BukkitEnums1_1Plus.fromBukkitTeleportCause(e.getCause()), + FoliaHelper.fromBukkitLocation(Objects.requireNonNull(e.getTo()))); + ee.setCancelled(e.isCancelled()); + Main.callEvent(ee); + e.setCancelled(ee.isCancelled()); + } + + @EventHandler + public void onPlayerDeath(PlayerDeathEvent e) { + try { + // In old versions getEntity() isn't in PlayerDeathEvent it is in EntityDeathEvent which + // returns a LivingEntity, so we have to use reflection to get it and then cast it to a Player + Player p = (Player) EntityEvent.class.getMethod("getEntity").invoke(e); + + EsPlayerDeathEvent ee = new EsPlayerDeathEvent(new FoliaPlayer(p)); + Main.callEvent(ee); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + Main.logger.severe(ex.toString()); + } + } + + @EventHandler + public void onEntityDamage(EntityDamageEvent e) { + EsEntityDamageEvent ee = new EsEntityDamageEvent(FoliaHelper.fromBukkitEntity(e.getEntity()), getDamageFromEvent(e)); + ee.setCancelled(e.isCancelled()); + Main.callEvent(ee); + setDamageFromEvent(e, ee.getDamage()); + e.setCancelled(ee.isCancelled()); + } + + @EventHandler + public void onInvClick(InventoryClickEvent e) { + EsInventory clInv = FoliaHelper.fromBukkitInventory(e.getClickedInventory()); + EsInventory inv = FoliaHelper.fromBukkitInventory(e.getInventory()); + EsClickType ct = FoliaHelper.fromBukkitClickType(e.getClick()); + EsInventoryAction ac = FoliaHelper.fromBukkitInventoryAction(e.getAction()); + EsItemStack ci = FoliaHelper.fromBukkitItem(e.getCurrentItem()); + EsPlayer cl = new FoliaPlayer((Player) e.getWhoClicked()); + EsItemStack cu = FoliaHelper.fromBukkitItem(e.getCursor()); + int sl = e.getSlot(); + EsInventoryClickEvent ee = new EsInventoryClickEvent(cl, sl, cu, inv, clInv, ci, ac, ct); + ee.setCancelled(e.isCancelled()); + Main.callEvent(ee); + e.setCancelled(ee.isCancelled()); + } + + @EventHandler + public void onQuit(PlayerQuitEvent e) { + Main.callEvent(new EsPlayerQuitEvent(new FoliaPlayer(e.getPlayer()))); + } + + @EventHandler + public void onKick(PlayerQuitEvent e) { + Main.callEvent(new EsPlayerQuitEvent(new FoliaPlayer(e.getPlayer()))); + } + + @EventHandler + public void onInvClose(InventoryCloseEvent e) { + EsInventory inv = FoliaHelper.fromBukkitInventory(e.getInventory()); + EsPlayer pl = new FoliaPlayer((Player) e.getPlayer()); + EsInventoryCloseEvent ee = new EsInventoryCloseEvent(pl, inv); + Main.callEvent(ee); + } + + @EventHandler + public void onDrag(InventoryDragEvent e) { + EsInventory inv = FoliaHelper.fromBukkitInventory(e.getInventory()); + EsPlayer pl = new FoliaPlayer((Player) e.getWhoClicked()); + Set cs = e.getRawSlots(); + EsInventoryView view = new FoliaInventoryView(e.getView()); + EsInventoryDragEvent ee = new EsInventoryDragEvent(pl, inv, cs, view); + ee.setCancelled(e.isCancelled()); + Main.callEvent(ee); + e.setCancelled(ee.isCancelled()); + } + + @EventHandler + public void onInteract(PlayerInteractEvent e) { + EsBlock cb = FoliaHelper.fromBukkitBlock(e.getClickedBlock()); + EsPlayer p = new FoliaPlayer(e.getPlayer()); + EsAction ac = FoliaHelper.fromBukkitAction(e.getAction()); + EsPlayerInteractEvent ee = new EsPlayerInteractEvent(p, cb, ac); + + ee.setUseInteractedBlock(FoliaHelper.fromBukkitEventResult(e.useInteractedBlock())); + ee.setUseItemInHand(FoliaHelper.fromBukkitEventResult(e.useItemInHand())); + Main.callEvent(ee); + e.setUseInteractedBlock(FoliaHelper.toBukkitEventResult(ee.getUseInteractedBlock())); + e.setUseItemInHand(FoliaHelper.toBukkitEventResult(ee.getUseItemInHand())); + } + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + return Main.executeCommand(FoliaHelper.fromBukkitCommandSender(sender), command.getName(), args); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaHelper.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaHelper.java new file mode 100644 index 0000000..e4e3379 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaHelper.java @@ -0,0 +1,458 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import io.papermc.paper.threadedregions.scheduler.EntityScheduler; +import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; +import io.papermc.paper.threadedregions.scheduler.RegionScheduler; +import io.papermc.paper.threadedregions.scheduler.ScheduledTask; +import net.serble.estools.Entrypoints.EsToolsBukkit; +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsClickType; +import net.serble.estools.ServerApi.EsEquipmentSlot; +import net.serble.estools.ServerApi.EsInventoryAction; +import net.serble.estools.ServerApi.EsLocation; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.*; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.PotionMeta; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +@SuppressWarnings("unused") +public class FoliaHelper extends BukkitHelper { + + public static GlobalRegionScheduler getGlobalScheduler() { + GlobalRegionScheduler grs; + try { + Object serverInstance = EsToolsBukkit.plugin.getServer(); + + Method getSchedulerMethod = serverInstance.getClass().getMethod("getGlobalRegionScheduler"); + Object schObject = getSchedulerMethod.invoke(serverInstance); + + if (schObject instanceof GlobalRegionScheduler) { + grs = (GlobalRegionScheduler) schObject; + } else { + Main.logger.severe("schObject is not an instance of GlobalRegionScheduler"); + throw new RuntimeException("Failed to get global scheduler, are you running folia?"); + } + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException("Failed to get global scheduler, are you running folia?"); + } + + return grs; + } + + private static RegionScheduler getRegionScheduler() { + RegionScheduler grs; + try { + Object serverInstance = EsToolsBukkit.plugin.getServer(); + + Method getSchedulerMethod = serverInstance.getClass().getMethod("getRegionScheduler"); + Object schObject = getSchedulerMethod.invoke(serverInstance); + + if (schObject instanceof RegionScheduler) { + grs = (RegionScheduler) schObject; + } else { + Main.logger.severe("schObject is not an instance of RegionScheduler"); + throw new RuntimeException("Failed to get regional scheduler, are you running folia?"); + } + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException("Failed to get regional scheduler, are you running folia?"); + } + + return grs; + } + + private static EntityScheduler getEntityScheduler(Entity entity) { + EntityScheduler grs; + try { + Method getSchedulerMethod = entity.getClass().getMethod("getScheduler"); + Object schObject = getSchedulerMethod.invoke(entity); + + if (schObject instanceof EntityScheduler) { + grs = (EntityScheduler) schObject; + } else { + Main.logger.severe("schObject is not an instance of EntityScheduler"); + throw new RuntimeException("Failed to get entity scheduler, are you running folia?"); + } + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException("Failed to get entity scheduler, are you running folia?"); + } + + return grs; + } + + public static ScheduledTask runTaskLater(Runnable task, long ticks) { + return getGlobalScheduler().runDelayed(EsToolsBukkit.plugin, (t) -> task.run(), ticks); + } + + public static void runTaskOnNextTick(Runnable task) { + getGlobalScheduler().run(EsToolsBukkit.plugin, (t) -> task.run()); + } + + public static void runFromLocation(EsLocation loc, Runnable task) { + runFromLocation(toBukkitLocation(loc), task); + } + + public static void runFromLocation(Location loc, Runnable task) { + getRegionScheduler().run(EsToolsBukkit.plugin, loc, (t) -> task.run()); + } + + public static void runFromEntity(EsEntity entity, Runnable task) { + runFromEntity(((FoliaEntity)entity).getBukkitEntity(), task); + } + + public static void runFromEntity(Entity entity, Runnable task) { + getEntityScheduler(entity).run(EsToolsBukkit.plugin, (t) -> task.run(), null); + } + + public static void runSync(Runnable task) { + FoliaServer.newChain().sync(task::run).sync(() -> Bukkit.getLogger().info("Main thread: " + Thread.currentThread().getName())).execute(); + } + + public static EsCommandSender fromBukkitCommandSender(org.bukkit.command.CommandSender sender) { + if (sender == null) { + return null; + } + + if (sender instanceof Player) { + return new FoliaPlayer((Player) sender); + } + + if (sender instanceof LivingEntity) { + return new FoliaLivingEntity((org.bukkit.entity.LivingEntity) sender); + } + + if (sender instanceof Entity) { + return new FoliaEntity((org.bukkit.entity.Entity) sender); + } + + if (sender instanceof ConsoleCommandSender) { + return new FoliaConsoleSender((ConsoleCommandSender) sender); + } + + if (sender instanceof BlockCommandSender) { + return new FoliaCommandBlockSender((BlockCommandSender) sender); + } + + throw new RuntimeException("Unrecognised command sender"); + } + + public static CommandSender toBukkitCommandSender(EsCommandSender sender) { + if (sender instanceof EsPlayer) { + return ((FoliaPlayer) sender).getBukkitPlayer(); + } + + if (sender instanceof EsLivingEntity) { + return ((FoliaLivingEntity) sender).getBukkitEntity(); + } + + if (sender instanceof EsEntity) { + return ((FoliaEntity) sender).getBukkitEntity(); + } + + if (sender instanceof EsConsoleSender) { + return Bukkit.getConsoleSender(); + } + + if (sender instanceof EsCommandBlockSender) { + return ((FoliaCommandBlockSender) sender).getBukkitSender(); + } + + throw new RuntimeException("Unrecognised command sender"); + } + + public static EsEntity fromBukkitEntity(Entity entity) { + if (entity instanceof Player) { + return new FoliaPlayer((Player) entity); + } + + if (entity instanceof LivingEntity) { + return new FoliaLivingEntity((LivingEntity) entity); + } + + return new FoliaEntity(entity); + } + + public static EsBlock fromBukkitBlock(Block block) { + if (block == null) { + return null; + } + + BlockState state = block.getState(); + + if (state instanceof Sign) { + return new FoliaSign((Sign) state); + } + + return new FoliaBlock(state); + } + + public static EsItemStack fromBukkitItem(ItemStack item) { + if (item == null) { + return null; + } + + if (Main.minecraftVersion.getMinor() >= 9) { + if (item.getItemMeta() instanceof PotionMeta) { + return new FoliaPotion(item); + } + + return new FoliaItemStack(item); + } else if (Main.minecraftVersion.getMinor() >= 4) { + if (item.getType().name().endsWith("POTION")) { + return new FoliaPotion(item); + } + + return new FoliaItemStack(item); + } else { + throw new RuntimeException("Potions aren't support in this Minecraft version"); + } + } + + public static EsBlock fromBukkitBlock(BlockState block) { + if (block == null) { + return null; + } + + if (block instanceof Sign) { + return new FoliaSign((Sign) block); + } + + return new FoliaBlock(block); + } + + public static EsInventoryAction fromBukkitInventoryAction(InventoryAction action) { + switch (action) { + case NOTHING: + return EsInventoryAction.Nothing; + case PICKUP_ALL: + return EsInventoryAction.PickupAll; + case PICKUP_SOME: + return EsInventoryAction.PickupSome; + case PICKUP_HALF: + return EsInventoryAction.PickupHalf; + case PICKUP_ONE: + return EsInventoryAction.PickupOne; + case PLACE_ALL: + return EsInventoryAction.PlaceAll; + case PLACE_SOME: + return EsInventoryAction.PlaceSome; + case PLACE_ONE: + return EsInventoryAction.PlaceOne; + case SWAP_WITH_CURSOR: + return EsInventoryAction.SwapWithCursor; + case DROP_ALL_CURSOR: + return EsInventoryAction.DropAllCursor; + case DROP_ONE_CURSOR: + return EsInventoryAction.DropOneCursor; + case DROP_ALL_SLOT: + return EsInventoryAction.DropAllSlot; + case DROP_ONE_SLOT: + return EsInventoryAction.DropOneSlot; + case MOVE_TO_OTHER_INVENTORY: + return EsInventoryAction.MoveToOtherInventory; + case HOTBAR_MOVE_AND_READD: + return EsInventoryAction.HotbarMoveAndReadd; + case HOTBAR_SWAP: + return EsInventoryAction.HotbarSwap; + case CLONE_STACK: + return EsInventoryAction.CloneStack; + case COLLECT_TO_CURSOR: + return EsInventoryAction.CollectToCursor; + case UNKNOWN: + return EsInventoryAction.Unknown; + default: + throw new IllegalArgumentException("Invalid InventoryAction"); + } + } + + public static InventoryAction toBukkitInventoryAction(EsInventoryAction esAction) { + switch (esAction) { + case Nothing: + return InventoryAction.NOTHING; + case PickupAll: + return InventoryAction.PICKUP_ALL; + case PickupSome: + return InventoryAction.PICKUP_SOME; + case PickupHalf: + return InventoryAction.PICKUP_HALF; + case PickupOne: + return InventoryAction.PICKUP_ONE; + case PlaceAll: + return InventoryAction.PLACE_ALL; + case PlaceSome: + return InventoryAction.PLACE_SOME; + case PlaceOne: + return InventoryAction.PLACE_ONE; + case SwapWithCursor: + return InventoryAction.SWAP_WITH_CURSOR; + case DropAllCursor: + return InventoryAction.DROP_ALL_CURSOR; + case DropOneCursor: + return InventoryAction.DROP_ONE_CURSOR; + case DropAllSlot: + return InventoryAction.DROP_ALL_SLOT; + case DropOneSlot: + return InventoryAction.DROP_ONE_SLOT; + case MoveToOtherInventory: + return InventoryAction.MOVE_TO_OTHER_INVENTORY; + case HotbarMoveAndReadd: + return InventoryAction.HOTBAR_MOVE_AND_READD; + case HotbarSwap: + return InventoryAction.HOTBAR_SWAP; + case CloneStack: + return InventoryAction.CLONE_STACK; + case CollectToCursor: + return InventoryAction.COLLECT_TO_CURSOR; + case Unknown: + return InventoryAction.UNKNOWN; + default: + throw new IllegalArgumentException("Invalid EsInventoryAction"); + } + } + + public static EsClickType fromBukkitClickType(ClickType click) { + switch (click) { + case CREATIVE: + return EsClickType.Creative; + case DROP: + return EsClickType.Drop; + case LEFT: + return EsClickType.Left; + case RIGHT: + return EsClickType.Right; + case SHIFT_LEFT: + return EsClickType.ShiftLeft; + case SHIFT_RIGHT: + return EsClickType.ShiftRight; + case MIDDLE: + return EsClickType.Middle; + case UNKNOWN: + return EsClickType.Unknown; + case NUMBER_KEY: + return EsClickType.NumberKey; + case CONTROL_DROP: + return EsClickType.ControlDrop; + case DOUBLE_CLICK: + return EsClickType.DoubleClick; + case SWAP_OFFHAND: + return EsClickType.SwapOffhand; + case WINDOW_BORDER_LEFT: + return EsClickType.WindowBorderLeft; + case WINDOW_BORDER_RIGHT: + return EsClickType.WindowBorderRight; + default: + throw new RuntimeException("Invalid click type"); + } + } + + public static ClickType toBukkitClickType(EsClickType esClick) { + switch (esClick) { + case Creative: + return ClickType.CREATIVE; + case Drop: + return ClickType.DROP; + case Left: + return ClickType.LEFT; + case Right: + return ClickType.RIGHT; + case ShiftLeft: + return ClickType.SHIFT_LEFT; + case ShiftRight: + return ClickType.SHIFT_RIGHT; + case Middle: + return ClickType.MIDDLE; + case Unknown: + return ClickType.UNKNOWN; + case NumberKey: + return ClickType.NUMBER_KEY; + case ControlDrop: + return ClickType.CONTROL_DROP; + case DoubleClick: + return ClickType.DOUBLE_CLICK; + case SwapOffhand: + return ClickType.SWAP_OFFHAND; + case WindowBorderLeft: + return ClickType.WINDOW_BORDER_LEFT; + case WindowBorderRight: + return ClickType.WINDOW_BORDER_RIGHT; + default: + throw new IllegalArgumentException("Invalid EsClickType"); + } + } + + public static EsInventory fromBukkitInventory(Inventory inv) { + if (inv == null) { + return null; + } + + if (inv instanceof PlayerInventory) { + return new FoliaPlayerInventory((PlayerInventory) inv); + } + + return new FoliaInventory(inv); + } + + public static EquipmentSlot toBukkitEquipmentSlot(EsEquipmentSlot slot) { + switch (slot) { + case Feet: + return EquipmentSlot.FEET; + case Hand: + return EquipmentSlot.HAND; + case Head: + return EquipmentSlot.HEAD; + case Legs: + return EquipmentSlot.LEGS; + case Chest: + return EquipmentSlot.CHEST; + case OffHand: + return EquipmentSlot.OFF_HAND; + } + + throw new RuntimeException("idfk"); + } + + public static EsEquipmentSlot fromBukkitEquipmentSlot(EquipmentSlot slot) { + switch (slot) { + case FEET: + return EsEquipmentSlot.Feet; + case HAND: + return EsEquipmentSlot.Hand; + case HEAD: + return EsEquipmentSlot.Head; + case LEGS: + return EsEquipmentSlot.Legs; + case CHEST: + return EsEquipmentSlot.Chest; + case OFF_HAND: + return EsEquipmentSlot.OffHand; + default: + throw new IllegalArgumentException("Invalid EquipmentSlot"); + } + } + + public static EsItemMeta fromBukkitItemMeta(ItemMeta meta) { + if (meta == null) { + return null; + } + + return new FoliaItemMeta(meta); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaInventory.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaInventory.java new file mode 100644 index 0000000..1c09eea --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaInventory.java @@ -0,0 +1,97 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.ServerApi.EsMaterial; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.EsInventory; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import org.bukkit.Material; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import java.util.HashMap; +import java.util.Map; + +public class FoliaInventory implements EsInventory { + private final Inventory bukkitInv; + + public FoliaInventory(Inventory inv) { + bukkitInv = inv; + } + + public Inventory getBukkitInventory() { + return bukkitInv; + } + + @Override + public EsItemStack[] getContents() { + ItemStack[] bukkitItems = bukkitInv.getContents(); + EsItemStack[] items = new EsItemStack[bukkitItems.length]; + for (int i = 0; i < bukkitItems.length; i++) { + if (bukkitItems[i] == null) { + items[i] = null; + continue; + } + items[i] = FoliaHelper.fromBukkitItem(bukkitItems[i]); + } + return items; + } + + @Override + public EsItemStack getItem(int slot) { + return FoliaHelper.fromBukkitItem(bukkitInv.getItem(slot)); + } + + @Override + public boolean isEqualTo(EsInventory inv) { + if (inv == null) { + return false; + } + return ((FoliaInventory) inv).getBukkitInventory().equals(bukkitInv); + } + + @Override + public int getSize() { + return bukkitInv.getSize(); + } + + @Override + public Map all(EsMaterial material) { + Material mat = BukkitHelper.toBukkitMaterial(material); + Map out = new HashMap<>(); + + for (Map.Entry entry : bukkitInv.all(mat).entrySet()) { + out.put(entry.getKey(), FoliaHelper.fromBukkitItem(entry.getValue())); + } + + return out; + } + + @Override + public void setContents(EsItemStack[] items) { + ItemStack[] bukkitItems = new ItemStack[items.length]; + for (int i = 0; i < items.length; i++) { + if (items[i] == null) { + bukkitItems[i] = null; + continue; + } + bukkitItems[i] = ((FoliaItemStack) items[i]).getBukkitItem(); + } + bukkitInv.setContents(bukkitItems); + } + + @Override + public void setItem(int slot, EsItemStack item) { + ItemStack stack = item == null ? null : ((FoliaItemStack) item).getBukkitItem(); + bukkitInv.setItem(slot, stack); + } + + @Override + public void addItem(EsItemStack stack) { + bukkitInv.addItem(((FoliaItemStack) stack).getBukkitItem()); + } + + @Override + public void clear() { + bukkitInv.clear(); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaInventoryView.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaInventoryView.java new file mode 100644 index 0000000..69ecc6a --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaInventoryView.java @@ -0,0 +1,36 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitInventoryView; +import net.serble.estools.ServerApi.Interfaces.EsInventory; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryView; + +public class FoliaInventoryView extends BukkitInventoryView { + private final InventoryView bukkitView; + + public FoliaInventoryView(InventoryView child) { + super(child); + bukkitView = child; + } + + @Override + public EsInventory getTopInventory() { + return FoliaHelper.fromBukkitInventory(bukkitView.getTopInventory()); + } + + @Override + public EsInventory getBottomInventory() { + return FoliaHelper.fromBukkitInventory(bukkitView.getBottomInventory()); + } + + @Override + public EsInventory getInventory(int slot) { + return FoliaHelper.fromBukkitInventory(bukkitView.getInventory(slot)); + } + + @Override + public EsPlayer getPlayer() { + return new FoliaPlayer((Player) bukkitView.getPlayer()); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaItemMeta.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaItemMeta.java new file mode 100644 index 0000000..3b02f1c --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaItemMeta.java @@ -0,0 +1,19 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitItemMeta; +import net.serble.estools.ServerApi.Interfaces.EsPersistentDataContainer; +import org.bukkit.inventory.meta.ItemMeta; + +public class FoliaItemMeta extends BukkitItemMeta { + private final ItemMeta bukkitMeta; + + public FoliaItemMeta(ItemMeta meta) { + super(meta); + bukkitMeta = meta; + } + + @Override + public EsPersistentDataContainer getPersistentDataContainer() { + return new FoliaPersistentDataContainer(bukkitMeta.getPersistentDataContainer()); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaItemStack.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaItemStack.java new file mode 100644 index 0000000..99c6d0c --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaItemStack.java @@ -0,0 +1,159 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsEnchantment; +import net.serble.estools.ServerApi.EsMaterial; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitEnchantmentHelper; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.EsItemMeta; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class FoliaItemStack implements EsItemStack { + private final ItemStack bukkitItem; + + public FoliaItemStack(EsMaterial mat, int amount) { + bukkitItem = new ItemStack(BukkitHelper.toBukkitMaterial(mat), amount); + } + + public FoliaItemStack(ItemStack child) { + bukkitItem = child; + } + + public ItemStack getBukkitItem() { + return bukkitItem; + } + + @Override + public int getAmount() { + return bukkitItem.getAmount(); + } + + @Override + public void setAmount(int val) { + bukkitItem.setAmount(val); + } + + @Override + public EsMaterial getType() { + return BukkitHelper.fromBukkitMaterial(bukkitItem.getType()); + } + + @Override + public void setType(EsMaterial val) { + bukkitItem.setType(BukkitHelper.toBukkitMaterial(val)); + } + + @Override + public EsItemMeta getItemMeta() { + return FoliaHelper.fromBukkitItemMeta(bukkitItem.getItemMeta()); + } + + @Override + public String exportItemMeta() { + YamlConfiguration config = new YamlConfiguration(); + config.set("item", bukkitItem.getItemMeta()); + return config.saveToString(); + } + + @Override + public void importItemMeta(String meta) { + YamlConfiguration config = new YamlConfiguration(); + try { + config.loadFromString(meta); + } catch (InvalidConfigurationException e) { + throw new RuntimeException(e); + } + + ItemMeta itemMeta = (ItemMeta)config.get("item"); + bukkitItem.setItemMeta(itemMeta); + } + + @Override + public void setItemMeta(EsItemMeta meta) { + bukkitItem.setItemMeta(((FoliaItemMeta) meta).getBukkitMeta()); + } + + @SuppressWarnings("deprecation") + @Override + public void setDamage(int val) { + if (Main.minecraftVersion.getMinor() > 12) { + ItemMeta meta = bukkitItem.getItemMeta(); + if (meta instanceof Damageable) { + ((Damageable) meta).setDamage(val); + } + bukkitItem.setItemMeta(meta); + } else { + if (val > Short.MAX_VALUE) { + val = Short.MAX_VALUE; + } + + bukkitItem.setDurability((short) val); + } + } + + @SuppressWarnings("deprecation") + @Override + public int getDamage() { + if (Main.minecraftVersion.getMinor() > 12) { + return bukkitItem.getDurability(); + } + + ItemMeta meta = bukkitItem.getItemMeta(); + if (meta instanceof Damageable) { + return ((Damageable) meta).getDamage(); + } + return 0; + } + + @SuppressWarnings("MethodDoesntCallSuperMethod") // I don't care, it doesn't work like that + @Override + public EsItemStack clone() { + return FoliaHelper.fromBukkitItem(bukkitItem.clone()); + } + + @Override + public boolean isSimilar(EsItemStack stack) { + return ((FoliaItemStack) stack).bukkitItem.isSimilar(bukkitItem); + } + + @Override + public void addEnchantment(EsEnchantment enchantment, int level) { + bukkitItem.addUnsafeEnchantment(FoliaEnchantmentHelper.toBukkitEnchantment(enchantment), level); + } + + @Override + public void removeEnchantment(EsEnchantment enchantment) { + bukkitItem.removeEnchantment(FoliaEnchantmentHelper.toBukkitEnchantment(enchantment)); + } + + @Override + public int getMaxStackSize() { + return bukkitItem.getMaxStackSize(); + } + + @Override + public Object getInternalObject() { + return bukkitItem; + } + + @Override + public Map getEnchantments() { + Set> bEnchs = bukkitItem.getEnchantments().entrySet(); + Map enchs = new HashMap<>(bEnchs.size()); + for (Map.Entry ench : bEnchs) { + enchs.put(BukkitEnchantmentHelper.fromBukkitEnchantment(ench.getKey()), ench.getValue()); + } + + return enchs; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaLivingEntity.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaLivingEntity.java new file mode 100644 index 0000000..782d220 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaLivingEntity.java @@ -0,0 +1,128 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsPotionEffect; +import net.serble.estools.ServerApi.EsPotionEffectType; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitEffectHelper; +import net.serble.estools.ServerApi.Interfaces.EsLivingEntity; +import net.serble.estools.ServerApi.Interfaces.EsWorld; +import org.bukkit.Bukkit; +import org.bukkit.attribute.Attribute; +import org.bukkit.entity.LivingEntity; +import org.bukkit.potion.PotionEffect; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; + +// Can't extend BukkitEntity because it needs to extend FoliaEntity for it to work +public class FoliaLivingEntity extends FoliaEntity implements EsLivingEntity { + private final org.bukkit.entity.LivingEntity bukkitEntity; + + public FoliaLivingEntity(org.bukkit.entity.LivingEntity entity) { + super(entity); + bukkitEntity = entity; + } + + public LivingEntity getBukkitEntity() { + return bukkitEntity; + } + + @Override + public double getMaxHealth() { + if (Main.minecraftVersion.getMinor() > 8) { + return Objects.requireNonNull(bukkitEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue(); + } else { + if (Main.minecraftVersion.getMinor() > 5) { + //noinspection deprecation + return bukkitEntity.getMaxHealth(); + } + + try { + return (double)(int) org.bukkit.entity.LivingEntity.class.getMethod("getMaxHealth").invoke(bukkitEntity); + } catch(Exception e) { + Bukkit.getLogger().severe(e.toString()); + return 20d; + } + } + } + + @Override + public void setMaxHealth(double val) { + if (Main.minecraftVersion.getMinor() > 8) { + Objects.requireNonNull(bukkitEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH)).setBaseValue(val); + } else { + if (Main.minecraftVersion.getMinor() > 5) { + //noinspection deprecation + bukkitEntity.setMaxHealth(val); + return; + } + + try { + //noinspection JavaReflectionMemberAccess + org.bukkit.entity.LivingEntity.class.getMethod("setMaxHealth", int.class).invoke(bukkitEntity, (int)val); + } + catch (Exception ex) { + Bukkit.getLogger().severe(ex.toString()); + } + } + } + + @Override + public double getHealth() { + if (Main.minecraftVersion.getMinor() > 5) { + return bukkitEntity.getHealth(); + } + + try { + return (double)(int) org.bukkit.entity.LivingEntity.class.getMethod("getHealth").invoke(bukkitEntity); + } + catch (Exception ex) { + Bukkit.getLogger().severe(ex.toString()); + return 20d; + } + } + + @Override + public void setHealth(double val) { + if (Main.minecraftVersion.getMinor() > 5) { + bukkitEntity.setHealth(val); + return; + } + + try { + //noinspection JavaReflectionMemberAccess + org.bukkit.entity.LivingEntity.class.getMethod("setHealth", int.class).invoke(bukkitEntity, (int)val); + } + catch (Exception ex) { + Bukkit.getLogger().severe(ex.toString()); + } + } + + @Override + public void addPotionEffect(EsPotionEffect effect) { + bukkitEntity.addPotionEffect(FoliaHelper.toBukkitPotionEffect(effect)); + } + + @Override + public void removePotionEffect(EsPotionEffectType effect) { + bukkitEntity.removePotionEffect(BukkitEffectHelper.toBukkitEffectType(effect)); + } + + @Override + public List getActivePotionEffects() { + Collection bukkitEffects = bukkitEntity.getActivePotionEffects(); + List out = new ArrayList<>(bukkitEffects.size()); + for (PotionEffect eff : bukkitEffects) { + out.add(FoliaHelper.fromBukkitPotionEffect(eff)); + } + + return out; + } + + @Override + public EsWorld getWorld() { + return new FoliaWorld(bukkitEntity.getWorld()); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaLogger.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaLogger.java new file mode 100644 index 0000000..08fb961 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaLogger.java @@ -0,0 +1,5 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitLogger; + +public class FoliaLogger extends BukkitLogger { } diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaPersistentDataContainer.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaPersistentDataContainer.java new file mode 100644 index 0000000..89c9e2b --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaPersistentDataContainer.java @@ -0,0 +1,13 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitPersistentDataContainer; +import org.bukkit.persistence.PersistentDataContainer; + +public class FoliaPersistentDataContainer extends BukkitPersistentDataContainer { + private final PersistentDataContainer bukkitContainer; + + public FoliaPersistentDataContainer(PersistentDataContainer container) { + super(container); + bukkitContainer = container; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaPlayer.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaPlayer.java new file mode 100644 index 0000000..ecc1ed3 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaPlayer.java @@ -0,0 +1,170 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsGameMode; +import net.serble.estools.ServerApi.EsLocation; +import net.serble.estools.ServerApi.EsSound; +import net.serble.estools.ServerApi.EsSoundCategory; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitHelper; +import net.serble.estools.ServerApi.Interfaces.*; +import org.bukkit.Bukkit; +import org.bukkit.block.Block; +import org.bukkit.entity.LivingEntity; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Nullable; + +import java.util.HashSet; + +// Can't extend BukkitEntity because it needs to extend FoliaLivingEntity for it to work +public class FoliaPlayer extends FoliaLivingEntity implements EsPlayer { + private final org.bukkit.entity.Player bukkitPlayer; + + public FoliaPlayer(org.bukkit.entity.Player entity) { + super(entity); + bukkitPlayer = entity; + } + + public org.bukkit.entity.Player getBukkitPlayer() { + return bukkitPlayer; + } + + @Override + public int getFoodLevel() { + return bukkitPlayer.getFoodLevel(); + } + + @Override + public void setFoodLevel(int val) { + bukkitPlayer.setFoodLevel(val); + } + + @Override + public double getSaturation() { + return bukkitPlayer.getSaturation(); + } + + @Override + public void setSaturation(double val) { + bukkitPlayer.setSaturation((float) val); + } + + @Override + public EsItemStack getMainHand() { + ItemStack mainHand = bukkitGetMainHand(); + if (mainHand == null) { + return null; + } + return FoliaHelper.fromBukkitItem(mainHand); + } + + @Override + public void setMainHand(EsItemStack item) { + setMainHandBukkit(bukkitPlayer, ((FoliaItemStack) item).getBukkitItem()); + } + + @Override + public void openInventory(EsInventory inv) { + bukkitPlayer.openInventory(((FoliaInventory) inv).getBukkitInventory()); + } + + @Override + public void closeInventory() { + bukkitPlayer.closeInventory(); + } + + @Override + public EsPlayerInventory getInventory() { + return new net.serble.estools.ServerApi.Implementations.Folia.FoliaPlayerInventory(bukkitPlayer.getInventory()); + } + + @Override + public void setFlySpeed(float val) { + bukkitPlayer.setFlySpeed(val); + } + + @Override + public void setWalkSpeed(float val) { + bukkitPlayer.setWalkSpeed(val); + } + + @Override + public void setGameMode(EsGameMode mode) { + bukkitPlayer.setGameMode(FoliaHelper.toBukkitGameMode(mode)); + } + + @Override + public EsGameMode getGameMode() { + return FoliaHelper.fromBukkitGameMode(bukkitPlayer.getGameMode()); + } + + @Override + public @Nullable EsBlock getTargetBlock() { + Block target = bukkitGetTargetBlock(); + if (target == null) { + return null; + } + + return FoliaHelper.fromBukkitBlock(target); + } + + @Override + public boolean getAllowFlight() { + return bukkitPlayer.getAllowFlight(); + } + + @Override + public void setAllowFlight(boolean val) { + bukkitPlayer.setAllowFlight(val); + } + + @Override + public boolean isFlying() { + return bukkitPlayer.isFlying(); + } + + @Override + public void playSound(EsSound sound, EsSoundCategory category, EsLocation loc, int volume, int pitch) { + bukkitPlayer.playSound(FoliaHelper.toBukkitLocation(loc), BukkitHelper.toBukkitSound(sound), FoliaHelper.toBukkitSoundCategory(category), volume, pitch); + } + + @SuppressWarnings("UnstableApiUsage") // Yes I know it's a bug + @Override + public void updateInventory() { + bukkitPlayer.updateInventory(); + } + + private Block bukkitGetTargetBlock() { + if (Main.minecraftVersion.getMinor() > 12) { + return bukkitPlayer.getTargetBlockExact(5); + } else if (Main.minecraftVersion.getMinor() > 7) { + return bukkitPlayer.getTargetBlock(null, 5); + } else { + try { + //noinspection JavaReflectionMemberAccess + return (Block) LivingEntity.class.getMethod("getTargetBlock", HashSet.class, int.class).invoke(bukkitPlayer, null, 5); + } + catch (Exception e) { + Bukkit.getLogger().severe(e.toString()); + return null; + } + } + } + + private org.bukkit.inventory.ItemStack bukkitGetMainHand() { + if (Main.minecraftVersion.getMinor() > 8) { + return bukkitPlayer.getInventory().getItemInMainHand(); + } else { + //noinspection deprecation + return bukkitPlayer.getInventory().getItemInHand(); + } + } + + private void setMainHandBukkit(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack is) { + if (Main.minecraftVersion.getMinor() > 8) { + p.getInventory().setItemInMainHand(is); + } else { + //noinspection deprecation + p.getInventory().setItemInHand(is); + } + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaPlayerInventory.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaPlayerInventory.java new file mode 100644 index 0000000..5dc3d11 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaPlayerInventory.java @@ -0,0 +1,55 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.ServerApi.EsEquipmentSlot; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayerInventory; +import org.bukkit.inventory.PlayerInventory; + +public class FoliaPlayerInventory extends FoliaInventory implements EsPlayerInventory { + private final PlayerInventory bukkitInv; + + public FoliaPlayerInventory(PlayerInventory inv) { + super(inv); + bukkitInv = inv; + } + + @Override + public PlayerInventory getBukkitInventory() { + return bukkitInv; + } + + @Override + public EsItemStack getOffHand() { + return FoliaHelper.fromBukkitItem(bukkitInv.getItemInOffHand()); + } + + @Override + public EsItemStack getMainHand() { + return FoliaHelper.fromBukkitItem(bukkitInv.getItemInMainHand()); + } + + @Override + public EsItemStack getHelmet() { + return FoliaHelper.fromBukkitItem(bukkitInv.getHelmet()); + } + + @Override + public EsItemStack getLeggings() { + return FoliaHelper.fromBukkitItem(bukkitInv.getLeggings()); + } + + @Override + public EsItemStack getChestplate() { + return FoliaHelper.fromBukkitItem(bukkitInv.getChestplate()); + } + + @Override + public EsItemStack getBoots() { + return FoliaHelper.fromBukkitItem(bukkitInv.getBoots()); + } + + @Override + public void setItem(EsEquipmentSlot slot, EsItemStack item) { + bukkitInv.setItem(FoliaHelper.toBukkitEquipmentSlot(slot), ((FoliaItemStack) item).getBukkitItem()); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaPotion.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaPotion.java new file mode 100644 index 0000000..054af0b --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaPotion.java @@ -0,0 +1,83 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.Main; +import net.serble.estools.ServerApi.EsPotType; +import net.serble.estools.ServerApi.EsPotionEffect; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitEffectHelper; +import net.serble.estools.ServerApi.Interfaces.EsPotion; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.Potion; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionType; + +import java.util.ArrayList; +import java.util.List; + +@SuppressWarnings("deprecation") // This whole class depends on the deprecated Potion class +public class FoliaPotion extends FoliaItemStack implements EsPotion { + private Potion bukkitPotion; + private PotionMeta bukkitMeta; + private boolean old; + + public FoliaPotion(ItemStack is) { + super(is); + calcOld(); + + if (old) { + bukkitMeta = (PotionMeta) is.getItemMeta(); + } else { + bukkitPotion = Potion.fromItemStack(is); + } + } + + private void calcOld() { + if (Main.minecraftVersion.getMinor() >= 9) { + old = false; + } else if (Main.minecraftVersion.getMinor() >= 4) { + old = true; + } else { + throw new RuntimeException("Potion are not supported in this Minecraft version"); + } + } + + @Override + public EsPotionEffect[] getEffects() { + PotionEffect[] in; + if (old) { + in = bukkitPotion.getEffects().toArray(new PotionEffect[0]); + } else { + PotionType baseType = bukkitMeta.getBasePotionType(); + List baseEffects = new ArrayList<>(baseType.getPotionEffects()); // What's the difference between base and custom effects? + if (bukkitMeta.hasCustomEffects()) { // The docs say to do this + baseEffects.addAll(bukkitMeta.getCustomEffects()); + } + in = baseEffects.toArray(new PotionEffect[0]); + } + + EsPotionEffect[] out = new EsPotionEffect[in.length]; + for (int i = 0; i < out.length; i++) { + PotionEffect effect = in[i]; + out[i] = new EsPotionEffect(BukkitEffectHelper.fromBukkitEffectType(effect.getType()), effect.getAmplifier(), effect.getDuration()); + } + return out; + } + + @Override + public EsPotType getPotionType() { + if (old) { + return FoliaHelper.fromBukkitPotType(bukkitPotion.toItemStack(0).getType()); + } else { + return FoliaHelper.fromBukkitPotType(getBukkitItem().getType()); + } + } + + @Override + public void addEffect(EsPotionEffect effect) { + if (old) { + bukkitPotion.getEffects().add(FoliaHelper.toBukkitPotionEffect(effect)); + } else { + bukkitMeta.addCustomEffect(FoliaHelper.toBukkitPotionEffect(effect), true); + } + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaServer.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaServer.java new file mode 100644 index 0000000..9ec2851 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaServer.java @@ -0,0 +1,329 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import co.aikar.taskchain.BukkitTaskChainFactory; +import co.aikar.taskchain.TaskChain; +import co.aikar.taskchain.TaskChainFactory; +import io.papermc.paper.threadedregions.scheduler.ScheduledTask; +import net.serble.estools.*; +import net.serble.estools.Entrypoints.EsToolsBukkit; +import net.serble.estools.ServerApi.*; +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitTabCompleteGenerator; +import net.serble.estools.ServerApi.Implementations.Bukkit.Helpers.BukkitEffectHelper; +import net.serble.estools.ServerApi.Interfaces.*; +import org.bukkit.*; +import org.bukkit.command.PluginCommand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.util.*; + +public class FoliaServer implements EsServer { + private final JavaPlugin plugin; + private final FoliaEventsListener listener; + private final Map tasks = new HashMap<>(); + private static TaskChainFactory taskChainFactory; + private static final Set materials = new HashSet<>(); + private static final Set itemMaterials = new HashSet<>(); + private static final Set sounds = new HashSet<>(); + + public FoliaServer(Object pluginObj) { + plugin = (JavaPlugin) pluginObj; + taskChainFactory = BukkitTaskChainFactory.create(plugin); + listener = new FoliaEventsListener(); + } + + @Override + public void initialise() { + for (Material mat : Material.values()) { + EsMaterial esMat = EsMaterial.createUnchecked(mat.getKey().getKey().toLowerCase()); + if (mat.isItem()) { + itemMaterials.add(esMat); + } + + materials.add(esMat); + } + + for (Sound sound : Registry.SOUNDS) { + EsSound esSound = EsSound.createUnchecked(sound.getKey().getKey()); + sounds.add(esSound); + } + } + + public static TaskChain newChain() { + return taskChainFactory.newChain(); + } + + @Override + public EsPlayer getPlayer(String name) { + Player p = Bukkit.getPlayer(name); + if (p == null) { + return null; + } + return new FoliaPlayer(p); + } + + @Override + public EsEntity getEntity(UUID uuid) { + if (Main.minecraftVersion.getMinor() > 11) { + Entity entity = Bukkit.getEntity(uuid); + if (entity == null) { + return null; + } + return FoliaHelper.fromBukkitEntity(entity); + } + + for (World world : Bukkit.getWorlds()) { + for (Entity entity : world.getEntities()) { + if (entity.getUniqueId() == uuid) { + return new FoliaEntity(entity); + } + } + } + + return null; + } + + @Override + public SemanticVersion getVersion() { // Parse the minecraft version from the Bukkit version string + String versionS = Bukkit.getVersion(); + int minor = 0; + int patch = 0; + + if (versionS.contains("(MC: ")) { + int posOfMC = versionS.indexOf("(MC: ") + 5; + versionS = versionS.substring(posOfMC, versionS.indexOf(')', posOfMC)); + } else { + Main.logger.warning("Could not detect version from: " + versionS); + throw new RuntimeException("Could not detect version"); + } + + for (int i = 0; i < 99; i++) { + if (versionS.contains("1." + i)) { + minor = i; + } + } + + for (int i = 0; i < 99; i++) { + if (versionS.contains("1." + minor + '.' + i)) { + patch = i; + } + } + + return new SemanticVersion(1, minor, patch); + } + + @Override + public Collection getOnlinePlayers() { + try { + if (Bukkit.class.getMethod("getOnlinePlayers").getReturnType() == Collection.class) { + List players = new ArrayList<>(); + for (Player p : Bukkit.getOnlinePlayers()) { + players.add(new FoliaPlayer(p)); + } + return players; + } + else { + Player[] players = (Player[]) Bukkit.class.getMethod("getOnlinePlayers").invoke(null, new Object[0]); + List users = new ArrayList<>(); + for (Player p : players) { + users.add(new FoliaPlayer(p)); + } + return users; + } + + } catch (Exception e) { + Bukkit.getLogger().severe(e.toString()); + return new ArrayList<>(); + } + } + + @Override + public EsItemStack createItemStack(EsMaterial material, int amount) { + return new FoliaItemStack(material, amount); + } + + @Override + public EsPotion createPotion(EsPotType potType, EsPotionEffect effect, int amount) { + String type = potType == EsPotType.drink ? + "POTION" : + potType.toString().toUpperCase() + "_POTION"; + ItemStack pot = new ItemStack(Material.valueOf(type), amount); + + PotionMeta meta = (PotionMeta) pot.getItemMeta(); + assert meta != null; + meta.addCustomEffect(FoliaHelper.toBukkitPotionEffect(effect), true); + pot.setItemMeta(meta); + + return new FoliaPotion(pot); + } + + @Override + public EsPotion createPotion(EsPotType potType) { + String type = potType == EsPotType.drink ? + "POTION" : + potType.toString().toUpperCase() + "_POTION"; + + ItemStack pot = new ItemStack(Material.valueOf(type), 1); + + return new FoliaPotion(pot); + } + + @Override + public EsInventory createInventory(EsPlayer owner, int size, String title) { + InventoryHolder holder = owner == null ? null : ((FoliaPlayer) owner).getBukkitPlayer(); + return new FoliaInventory(Bukkit.createInventory(holder, size, title)); + } + + @Override + public Set getPotionEffectTypes() { + return BukkitEffectHelper.getEffectList(); + } + + @Override + public Set getOldPotionTypes() { + return BukkitEffectHelper.getPotionList(); + } + + @Override + public Set getEnchantments() { + return FoliaEnchantmentHelper.getEnchantmentList(); + } + + @Override + public Set getSounds() { + return sounds; + } + + @Override + public Set getMaterials(boolean onlyItems) { + return onlyItems ? itemMaterials : materials; + } + + @Override + public File getDataFolder() { + return plugin.getDataFolder(); + } + + @Override + public void dispatchCommand(EsCommandSender sender, String cmd) { +// CompletableFuture> completeTask = new CompletableFuture>() +// .whenComplete((c, exception) -> { +// Main.logger.info("WE DID THE WHEN COMPLETE"); +// Bukkit.dispatchCommand(c.getKey(), c.getValue()); +// }); +// +// FoliaHelper.getGlobalScheduler().runDelayed(plugin, task -> { +// completeTask.complete(new AbstractMap.SimpleImmutableEntry<>(((FoliaPlayer) sender).getBukkitPlayer(), cmd)); +// }, 1L); + FoliaHelper.runSync(() -> Bukkit.dispatchCommand(FoliaHelper.toBukkitCommandSender(sender), cmd)); + } + + @Override + public EsCommandSender getConsoleSender() { + return null; + } + + @Override + public SemanticVersion getPluginVersion() { + return new SemanticVersion(plugin.getDescription().getVersion()); + } + + @Override + public String getPluginName() { + return plugin.getDescription().getName(); + } + + @Override + public int runTaskLater(Runnable task, long ticks) { + ScheduledTask foliaTask = FoliaHelper.runTaskLater(task, ticks); + int id = foliaTask.hashCode(); + if (tasks.containsKey(id)) { + throw new RuntimeException("Hash collision?"); + } + + tasks.put(id, foliaTask); + return id; + } + + @Override + public void runTask(Runnable task) { + FoliaHelper.runTaskOnNextTick(task); + } + + @Override + public void cancelTask(int id) { + if (!tasks.containsKey(id)) { + throw new RuntimeException("That task doesn't exist"); + } + + ScheduledTask task = tasks.get(id); + if (task.isCancelled() || task.getExecutionState() == ScheduledTask.ExecutionState.FINISHED) { + return; + } + + task.cancel(); + } + + @Override + public EsLogger getLogger() { + return new FoliaLogger(); + } + + @Override + public void startEvents() { + Bukkit.getPluginManager().registerEvents(listener, EsToolsBukkit.plugin); + } + + @Override + public void registerCommand(String cmd, EsToolsTabCompleter tab) { + PluginCommand command = Objects.requireNonNull(Bukkit.getPluginCommand(cmd)); + command.setExecutor(listener); + if (Main.tabCompleteEnabled) { + command.setTabCompleter(BukkitTabCompleteGenerator.generate(tab)); + } + } + + @Override + public void setTabCompleter(String cmd, EsToolsTabCompleter tab) { + PluginCommand command = Objects.requireNonNull(Bukkit.getPluginCommand(cmd)); + if (Main.tabCompleteEnabled) { + command.setTabCompleter(BukkitTabCompleteGenerator.generate(tab)); + } + } + + @Override + public void setCommandPermission(String cmd, String perm) { + PluginCommand command = Objects.requireNonNull(Bukkit.getPluginCommand(cmd)); + command.setPermission(perm); + + if (Main.minecraftVersion.getMinor() > 0) { + //noinspection deprecation, is still useful in pre 1.13 and technically is useful in rare situations post 1.13 + command.setPermissionMessage(EsToolsCommand.translate("&cYou do not have permission to run this command.")); + } + } + + @Override + public void broadcast(String msg, String perm) { + Bukkit.broadcast(msg, perm); + } + + @Override + public void broadcast(String msg) { + Bukkit.broadcastMessage(msg); + } + + @Override + public EsWorld getWorld(String name) { + return new FoliaWorld(Bukkit.getWorld(name)); + } + + @Override + public String[] getRelevantInternalTypes() { + return new String[] {}; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaSign.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaSign.java new file mode 100644 index 0000000..518cf41 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaSign.java @@ -0,0 +1,55 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.ServerApi.Interfaces.EsPlayer; +import net.serble.estools.ServerApi.Interfaces.EsSign; +import net.serble.estools.ServerApi.Interfaces.EsSignSide; +import org.bukkit.block.Sign; + +public class FoliaSign extends FoliaBlock implements EsSign { + private final Sign bukkitSign; + + public FoliaSign(Sign block) { + super(block); + bukkitSign = block; + } + + @Override + public void update() { + bukkitSign.update(); + } + + @SuppressWarnings("deprecation") // Method is version specific + @Override + public void setGlowingText(boolean glowing) { + bukkitSign.setGlowingText(glowing); + } + + @SuppressWarnings("deprecation") // Method is version specific + @Override + public boolean isGlowingText() { + return bukkitSign.isGlowingText(); + } + + @SuppressWarnings("deprecation") // Method is version specific + @Override + public void setLine(int line, String text) { + bukkitSign.setLine(line, text); + } + + @SuppressWarnings("deprecation") + @Override + public String getLine(int line) { + return bukkitSign.getLine(line); + } + + @SuppressWarnings("deprecation") + @Override + public String[] getLines() { + return bukkitSign.getLines(); + } + + @Override + public EsSignSide getTargetSide(EsPlayer player) { + return new FoliaSignSide(bukkitSign.getTargetSide(((FoliaPlayer) player).getBukkitPlayer())); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaSignSide.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaSignSide.java new file mode 100644 index 0000000..825457d --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaSignSide.java @@ -0,0 +1,13 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitSignSide; +import org.bukkit.block.sign.SignSide; + +public class FoliaSignSide extends BukkitSignSide { + private final SignSide bukkitSide; + + public FoliaSignSide(SignSide side) { + super(side); + this.bukkitSide = side; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaWorld.java b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaWorld.java new file mode 100644 index 0000000..7129165 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Implementations/Folia/FoliaWorld.java @@ -0,0 +1,60 @@ +package net.serble.estools.ServerApi.Implementations.Folia; + +import net.serble.estools.ServerApi.EsLocation; +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitWorld; +import net.serble.estools.ServerApi.Interfaces.EsEntity; +import org.bukkit.World; +import org.bukkit.entity.Entity; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class FoliaWorld extends BukkitWorld { + private final World bukkitWorld; + + public FoliaWorld(World world) { + super(world); + bukkitWorld = world; + } + + @Override + public List getEntities() { + List bEntities = bukkitWorld.getEntities(); + List entities = new ArrayList<>(); + for (Entity bEntity : bEntities) { + entities.add(FoliaHelper.fromBukkitEntity(bEntity)); + } + return entities; + } + + @Override + public List getNearbyEntities(EsLocation loc, double xoff, double yoff, double zoff) { + Collection bEntities = bukkitWorld.getNearbyEntities(FoliaHelper.toBukkitLocation(loc), xoff, yoff, zoff); + List entities = new ArrayList<>(); + for (Entity bEntity : bEntities) { + entities.add(FoliaHelper.fromBukkitEntity(bEntity)); + } + return entities; + } + + @Override + public void setTime(long time) { + FoliaHelper.runTaskOnNextTick(() -> bukkitWorld.setTime(time)); + } + + @Override + public void setStorming(boolean val) { + FoliaHelper.runTaskOnNextTick(() -> bukkitWorld.setStorm(val)); + } + + @Override + public void setThundering(boolean val) { + FoliaHelper.runTaskOnNextTick(() -> bukkitWorld.setThundering(val)); + } + + @Override + public void strikeLightning(EsLocation loc) { + bukkitWorld.strikeLightning(FoliaHelper.toBukkitLocation(loc)); + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsBlock.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsBlock.java new file mode 100644 index 0000000..c8ffc30 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsBlock.java @@ -0,0 +1,10 @@ +package net.serble.estools.ServerApi.Interfaces; + +@SuppressWarnings("unused") +public interface EsBlock { + boolean breakNaturally(); + int getX(); + int getY(); + int getZ(); + String getType(); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsCancellableEvent.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsCancellableEvent.java new file mode 100644 index 0000000..f2c6003 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsCancellableEvent.java @@ -0,0 +1,13 @@ +package net.serble.estools.ServerApi.Interfaces; + +public abstract class EsCancellableEvent implements EsEvent { + private boolean cancelled = false; + + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsCommandBlockSender.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsCommandBlockSender.java new file mode 100644 index 0000000..8eae6eb --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsCommandBlockSender.java @@ -0,0 +1,5 @@ +package net.serble.estools.ServerApi.Interfaces; + +public interface EsCommandBlockSender extends EsCommandSender { + +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsCommandSender.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsCommandSender.java new file mode 100644 index 0000000..d260ccc --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsCommandSender.java @@ -0,0 +1,7 @@ +package net.serble.estools.ServerApi.Interfaces; + +public interface EsCommandSender { + void sendMessage(String... msg); + boolean hasPermission(String node); + boolean isPermissionSet(String node); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsConsoleSender.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsConsoleSender.java new file mode 100644 index 0000000..951f672 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsConsoleSender.java @@ -0,0 +1,5 @@ +package net.serble.estools.ServerApi.Interfaces; + +public interface EsConsoleSender extends EsCommandSender { + +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsEntity.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsEntity.java new file mode 100644 index 0000000..3cc5b6d --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsEntity.java @@ -0,0 +1,23 @@ +package net.serble.estools.ServerApi.Interfaces; + +import net.serble.estools.ServerApi.EsLocation; + +import java.util.List; +import java.util.Set; +import java.util.UUID; + +public interface EsEntity extends EsCommandSender { + String getType(); + String getName(); + UUID getUniqueId(); + void teleport(EsLocation loc); + EsLocation getLocation(); + boolean leaveVehicle(); + List getPassengers(); + Set getScoreboardTags(); + void addScoreboardTag(String tag); + boolean hasScoreboardTag(String tag); + void setOnFireTicks(int ticks); + void addPassenger(EsEntity entity); + void setFallDistance(float dis); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsEvent.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsEvent.java new file mode 100644 index 0000000..f6f70eb --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsEvent.java @@ -0,0 +1,4 @@ +package net.serble.estools.ServerApi.Interfaces; + +public interface EsEvent { +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsInventory.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsInventory.java new file mode 100644 index 0000000..d450d70 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsInventory.java @@ -0,0 +1,27 @@ +package net.serble.estools.ServerApi.Interfaces; + +import net.serble.estools.ServerApi.EsMaterial; + +import java.util.Map; + +public interface EsInventory { + void setItem(int slot, EsItemStack item); + EsItemStack getItem(int slot); + void addItem(EsItemStack stack); + void setContents(EsItemStack[] items); + EsItemStack[] getContents(); + void clear(); + boolean isEqualTo(EsInventory inv); + int getSize(); + + /** + * Gets a list of slots and the items in those slots that are of a specific material. + * + * @param material + * The material to look for. + * + * @return + * A list of slot to item mappings. + */ + Map all(EsMaterial material); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsInventoryView.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsInventoryView.java new file mode 100644 index 0000000..d2a2fd6 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsInventoryView.java @@ -0,0 +1,8 @@ +package net.serble.estools.ServerApi.Interfaces; + +public interface EsInventoryView { + EsInventory getTopInventory(); + EsInventory getBottomInventory(); + EsInventory getInventory(int slot); + EsPlayer getPlayer(); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsItemMeta.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsItemMeta.java new file mode 100644 index 0000000..004b415 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsItemMeta.java @@ -0,0 +1,19 @@ +package net.serble.estools.ServerApi.Interfaces; + +import net.serble.estools.ServerApi.EsItemFlag; + +import java.util.List; +import java.util.Set; + +public interface EsItemMeta { + void setUnbreakable(boolean val); + boolean isUnbreakable(); + Set getItemFlags(); + void addItemFlags(EsItemFlag... flags); + void removeItemFlags(EsItemFlag... flags); + void setDisplayName(String val); + String getDisplayName(); + List getLore(); + void setLore(List val); + EsPersistentDataContainer getPersistentDataContainer(); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsItemStack.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsItemStack.java new file mode 100644 index 0000000..92707d6 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsItemStack.java @@ -0,0 +1,26 @@ +package net.serble.estools.ServerApi.Interfaces; + +import net.serble.estools.ServerApi.EsEnchantment; +import net.serble.estools.ServerApi.EsMaterial; + +import java.util.Map; + +public interface EsItemStack { + EsMaterial getType(); + void setType(EsMaterial val); + int getAmount(); + void setAmount(int amount); + void addEnchantment(EsEnchantment enchantment, int level); + void removeEnchantment(EsEnchantment enchantment); + EsItemMeta getItemMeta(); + String exportItemMeta(); + void importItemMeta(String meta); + void setItemMeta(EsItemMeta meta); + void setDamage(int val); + int getDamage(); + EsItemStack clone(); + boolean isSimilar(EsItemStack stack); + int getMaxStackSize(); + Object getInternalObject(); + Map getEnchantments(); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsLivingEntity.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsLivingEntity.java new file mode 100644 index 0000000..b665e31 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsLivingEntity.java @@ -0,0 +1,18 @@ +package net.serble.estools.ServerApi.Interfaces; + +import net.serble.estools.ServerApi.EsPotionEffect; +import net.serble.estools.ServerApi.EsPotionEffectType; + +import java.util.List; + +public interface EsLivingEntity extends EsEntity { + double getMaxHealth(); + void setMaxHealth(double val); + double getHealth(); + void setHealth(double val); + void sendMessage(String... msg); + void addPotionEffect(EsPotionEffect effect); + void removePotionEffect(EsPotionEffectType effect); + List getActivePotionEffects(); + EsWorld getWorld(); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsLogger.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsLogger.java new file mode 100644 index 0000000..836504e --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsLogger.java @@ -0,0 +1,8 @@ +package net.serble.estools.ServerApi.Interfaces; + +public interface EsLogger { + void debug(String msg); + void info(String msg); + void warning(String msg); + void severe(String msg); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsPersistentDataContainer.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsPersistentDataContainer.java new file mode 100644 index 0000000..6bba113 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsPersistentDataContainer.java @@ -0,0 +1,9 @@ +package net.serble.estools.ServerApi.Interfaces; + +import net.serble.estools.ServerApi.EsPersistentDataType; + +public interface EsPersistentDataContainer { + void set(String key, EsPersistentDataType type, Object val); + Object get(String key, EsPersistentDataType type); + void remove(String key); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsPlayer.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsPlayer.java new file mode 100644 index 0000000..0fc174b --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsPlayer.java @@ -0,0 +1,32 @@ +package net.serble.estools.ServerApi.Interfaces; + +import net.serble.estools.ServerApi.EsGameMode; +import net.serble.estools.ServerApi.EsLocation; +import net.serble.estools.ServerApi.EsSound; +import net.serble.estools.ServerApi.EsSoundCategory; + +@SuppressWarnings("unused") +public interface EsPlayer extends EsLivingEntity { + int getFoodLevel(); + void setFoodLevel(int val); + double getSaturation(); + void setSaturation(double val); + EsItemStack getMainHand(); + void setMainHand(EsItemStack item); + void openInventory(EsInventory inv); + void closeInventory(); + EsPlayerInventory getInventory(); + void setFlySpeed(float val); + void setWalkSpeed(float val); + void setGameMode(EsGameMode mode); + EsGameMode getGameMode(); + EsBlock getTargetBlock(); + boolean getAllowFlight(); + void setAllowFlight(boolean val); + boolean isFlying(); + void playSound(EsSound sound, EsSoundCategory category, EsLocation loc, int volume, int pitch); + void updateInventory(); + boolean hasPermission(String node); + boolean isPermissionSet(String node); + void sendMessage(String... args); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsPlayerInventory.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsPlayerInventory.java new file mode 100644 index 0000000..8d6f95e --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsPlayerInventory.java @@ -0,0 +1,13 @@ +package net.serble.estools.ServerApi.Interfaces; + +import net.serble.estools.ServerApi.EsEquipmentSlot; + +public interface EsPlayerInventory extends EsInventory { + EsItemStack getOffHand(); + EsItemStack getMainHand(); + EsItemStack getHelmet(); + EsItemStack getLeggings(); + EsItemStack getChestplate(); + EsItemStack getBoots(); + void setItem(EsEquipmentSlot slot, EsItemStack item); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsPotion.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsPotion.java new file mode 100644 index 0000000..414a1f5 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsPotion.java @@ -0,0 +1,10 @@ +package net.serble.estools.ServerApi.Interfaces; + +import net.serble.estools.ServerApi.EsPotType; +import net.serble.estools.ServerApi.EsPotionEffect; + +public interface EsPotion extends EsItemStack { + EsPotionEffect[] getEffects(); + EsPotType getPotionType(); + void addEffect(EsPotionEffect effect); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsServer.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsServer.java new file mode 100644 index 0000000..900cc5b --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsServer.java @@ -0,0 +1,53 @@ +package net.serble.estools.ServerApi.Interfaces; + +import net.serble.estools.EsToolsTabCompleter; +import net.serble.estools.SemanticVersion; +import net.serble.estools.ServerApi.*; + +import java.io.File; +import java.util.Collection; +import java.util.Set; +import java.util.UUID; + +@SuppressWarnings("unused") +public interface EsServer { + EsPlayer getPlayer(String name); + EsEntity getEntity(UUID uuid); + SemanticVersion getVersion(); + Collection getOnlinePlayers(); + EsItemStack createItemStack(EsMaterial material, int amount); + EsPotion createPotion(EsPotType potType, EsPotionEffect effect, int amount); + EsPotion createPotion(EsPotType potType); + EsInventory createInventory(EsPlayer owner, int size, String title); + Set getPotionEffectTypes(); + Set getOldPotionTypes(); + Set getEnchantments(); + Set getSounds(); + void initialise(); + + /** + * @param onlyItems + * Whether to only include materials that are classified as items + * */ + Set getMaterials(boolean onlyItems); + + File getDataFolder(); + void dispatchCommand(EsCommandSender sender, String cmd); + EsCommandSender getConsoleSender(); + SemanticVersion getPluginVersion(); + String getPluginName(); + int runTaskLater(Runnable task, long ticks); + void runTask(Runnable task); + void cancelTask(int id); + EsLogger getLogger(); + void startEvents(); + void registerCommand(String cmd, EsToolsTabCompleter tab); + void setTabCompleter(String cmd, EsToolsTabCompleter tab); + void setCommandPermission(String cmd, String perm); + void broadcast(String msg, String perm); + void broadcast(String msg); + EsWorld getWorld(String name); + + /** Get a list of classes that SnakeYAML needs to accept for proper config serialisation */ + String[] getRelevantInternalTypes(); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsSign.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsSign.java new file mode 100644 index 0000000..2ce470c --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsSign.java @@ -0,0 +1,17 @@ +package net.serble.estools.ServerApi.Interfaces; + +public interface EsSign extends EsBlock { + void update(); + + /** Only for 1.17-1.19 where signs are single sided but support glow */ + void setGlowingText(boolean glowing); + boolean isGlowingText(); + + /** Only for pre 1.20 where signs are singlesided */ + void setLine(int line, String text); + String getLine(int line); + String[] getLines(); + + /** Gets the side targeted by the player, only for 1.20+ */ + EsSignSide getTargetSide(EsPlayer player); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsSignSide.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsSignSide.java new file mode 100644 index 0000000..63826e3 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsSignSide.java @@ -0,0 +1,8 @@ +package net.serble.estools.ServerApi.Interfaces; + +/** This should only be used if the version is 1.20+ where double-sided signs exist */ +public interface EsSignSide { + void setGlowingText(boolean glowing); + boolean isGlowingText(); + void setLine(int line, String text); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Interfaces/EsWorld.java b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsWorld.java new file mode 100644 index 0000000..41dabd9 --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Interfaces/EsWorld.java @@ -0,0 +1,15 @@ +package net.serble.estools.ServerApi.Interfaces; + +import net.serble.estools.ServerApi.EsLocation; + +import java.util.List; + +public interface EsWorld { + String getName(); + List getEntities(); + List getNearbyEntities(EsLocation loc, double xoff, double yoff, double zoff); + void setTime(long time); + void setStorming(boolean val); + void setThundering(boolean val); + void strikeLightning(EsLocation loc); +} diff --git a/src/main/java/net/serble/estools/ServerApi/Position.java b/src/main/java/net/serble/estools/ServerApi/Position.java new file mode 100644 index 0000000..3e40e7c --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/Position.java @@ -0,0 +1,78 @@ +package net.serble.estools.ServerApi; + +public class Position { + private double x; + private double y; + private double z; + + public Position() { + + } + + public Position(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public double getZ() { + return z; + } + + public void setX(double x) { + this.x = x; + } + + public void setY(double y) { + this.y = y; + } + + public void setZ(double z) { + this.z = z; + } + + public double distanceTo(Position other) { + return Math.sqrt(distanceSquared(other)); + } + + public double distanceSquared(Position other) { + return Math.pow(x - other.x, 2) + Math.pow(y - other.y, 2) + Math.pow(z - other.z, 2); + } + + public Position subtract(Position other) { + return new Position(x - other.x, y - other.y, z - other.z); + } + + public Position normalise() { + double length = length(); + return new Position(x / length, y / length, z / length); + } + + public Position crossProduct(Position other) { + return new Position(y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x); + } + + public double lengthSquared() { + return (x * x + y * y + z * z); + } + + public double length() { + return Math.sqrt(x * x + y * y + z * z); + } + + public double dot(Position other) { + return x * other.x + y * other.y + z * other.z; + } + + public Position toPosition() { + return this; + } +} diff --git a/src/main/java/net/serble/estools/ServerApi/ServerPlatform.java b/src/main/java/net/serble/estools/ServerApi/ServerPlatform.java new file mode 100644 index 0000000..754d9ee --- /dev/null +++ b/src/main/java/net/serble/estools/ServerApi/ServerPlatform.java @@ -0,0 +1,33 @@ +package net.serble.estools.ServerApi; + +import net.serble.estools.ServerApi.Implementations.Bukkit.BukkitServer; +import net.serble.estools.ServerApi.Implementations.Folia.FoliaServer; +import net.serble.estools.ServerApi.Interfaces.EsServer; + +public enum ServerPlatform { + Bukkit(true), // Includes all derivatives + Folia(true); + + final boolean hasMetrics; + + ServerPlatform(boolean bStats) { + hasMetrics = bStats; + } + + public boolean supportsMetrics() { + return hasMetrics; + } + + public EsServer getServerInstance(Object context) { + switch (this) { + case Bukkit: + return new BukkitServer(context); + + case Folia: + return new FoliaServer(context); + + default: + throw new IllegalArgumentException("Unsupported server software"); + } + } +} diff --git a/src/main/java/net/serble/estools/Signs/Balance.java b/src/main/java/net/serble/estools/Signs/Balance.java deleted file mode 100644 index e022d16..0000000 --- a/src/main/java/net/serble/estools/Signs/Balance.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.serble.estools.Signs; - -import net.serble.estools.Vault; -import org.bukkit.entity.Player; - -public class Balance extends SignType { - @Override - public void run(Player p, String[] lines) { - send(p, "&aYour current balance is &6$%s", String.valueOf(Vault.economy.getBalance(p))); - } -} diff --git a/src/main/java/net/serble/estools/Signs/Disposal.java b/src/main/java/net/serble/estools/Signs/Disposal.java index f6ba08a..16f7ce4 100644 --- a/src/main/java/net/serble/estools/Signs/Disposal.java +++ b/src/main/java/net/serble/estools/Signs/Disposal.java @@ -1,12 +1,13 @@ package net.serble.estools.Signs; import net.serble.estools.EsToolsCommand; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; +import net.serble.estools.Main; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class Disposal extends SignType { + @Override - public void run(Player p, String[] lines) { - p.openInventory(Bukkit.createInventory(null, 54, EsToolsCommand.translate("&cDisposal"))); + public void run(EsPlayer p, String[] lines) { + p.openInventory(Main.server.createInventory(null, 54, EsToolsCommand.translate("&cDisposal"))); } } diff --git a/src/main/java/net/serble/estools/Signs/Feed.java b/src/main/java/net/serble/estools/Signs/Feed.java index 3576deb..a50ca5a 100644 --- a/src/main/java/net/serble/estools/Signs/Feed.java +++ b/src/main/java/net/serble/estools/Signs/Feed.java @@ -1,15 +1,11 @@ package net.serble.estools.Signs; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class Feed extends SignType { @Override - public void run(Player p, String[] lines) { - if (!takeMoney(lines[1], p)) { - return; - } - + public void run(EsPlayer p, String[] lines) { p.setFoodLevel(20); p.setSaturation(6); } diff --git a/src/main/java/net/serble/estools/Signs/Give.java b/src/main/java/net/serble/estools/Signs/Give.java index 5e8ee1c..e42e71e 100644 --- a/src/main/java/net/serble/estools/Signs/Give.java +++ b/src/main/java/net/serble/estools/Signs/Give.java @@ -1,29 +1,24 @@ package net.serble.estools.Signs; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class Give extends SignType { @Override - public void run(Player p, String[] lines) { + public void run(EsPlayer p, String[] lines) { int amount = 1; try { amount = Integer.parseInt(lines[2]); } catch (NumberFormatException e) { /* Ignored */ } - ItemStack item = net.serble.estools.Commands.Give.Give.getItem(lines[1], amount); + EsItemStack item = net.serble.estools.Commands.Give.Give.getItem(lines[1], amount); if (item == null) { send(p, "&cItem not found!"); return; } - if (!takeMoney(lines[3], p)) { - send(p, "&cYou cannot afford this!"); - return; - } - p.getInventory().addItem(item.clone()); } } diff --git a/src/main/java/net/serble/estools/Signs/Heal.java b/src/main/java/net/serble/estools/Signs/Heal.java index 663a6ea..3e76b5f 100644 --- a/src/main/java/net/serble/estools/Signs/Heal.java +++ b/src/main/java/net/serble/estools/Signs/Heal.java @@ -1,18 +1,12 @@ package net.serble.estools.Signs; -import net.serble.estools.EsToolsCommand; -import org.bukkit.entity.Player; - -import static net.serble.estools.EsToolsCommand.setHealth; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class Heal extends SignType { - @Override - public void run(Player p, String[] lines) { - if (!takeMoney(lines[1], p)) { - return; - } - setHealth(p, EsToolsCommand.getMaxHealth(p)); - p.setFireTicks(0); + @Override + public void run(EsPlayer p, String[] lines) { + p.setHealth(p.getMaxHealth()); + p.setOnFireTicks(0); } } diff --git a/src/main/java/net/serble/estools/Signs/Repair.java b/src/main/java/net/serble/estools/Signs/Repair.java index 823afd0..d8348bb 100644 --- a/src/main/java/net/serble/estools/Signs/Repair.java +++ b/src/main/java/net/serble/estools/Signs/Repair.java @@ -1,18 +1,14 @@ package net.serble.estools.Signs; import net.serble.estools.Commands.Fix; -import net.serble.estools.EsToolsCommand; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; +import net.serble.estools.ServerApi.Interfaces.EsItemStack; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public class Repair extends SignType { - @Override - public void run(Player p, String[] lines) { - if (!takeMoney(lines[1], p)) { - return; - } - ItemStack item = EsToolsCommand.getMainHand(p); + @Override + public void run(EsPlayer p, String[] lines) { + EsItemStack item = p.getMainHand(); Fix.repair(item); } } diff --git a/src/main/java/net/serble/estools/Signs/Sell.java b/src/main/java/net/serble/estools/Signs/Sell.java deleted file mode 100644 index 8aeb8ee..0000000 --- a/src/main/java/net/serble/estools/Signs/Sell.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.serble.estools.Signs; - -import net.serble.estools.Commands.Give.Give; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class Sell extends SignType { - @Override - public void run(Player p, String[] lines) { - int amount = 1; - try { - amount = Integer.parseInt(lines[3]); - } catch (Exception e) { /* ignore */ } - - ItemStack item = Give.getItem(lines[1], amount); - if (item == null) { - send(p, "&cItem not found!"); - return; - } - - for (ItemStack e : p.getInventory().getContents()) { - if (!e.getType().equals(item.getType()) || e.getAmount() < item.getAmount()) { - continue; - } - - if (payMoney(lines[2], p)) { - e.setAmount(e.getAmount() - item.getAmount()); - } - return; - } - - send(p, "&cCant find item!"); - } -} diff --git a/src/main/java/net/serble/estools/Signs/SignMain.java b/src/main/java/net/serble/estools/Signs/SignMain.java index 0b2d6b0..a261aa9 100644 --- a/src/main/java/net/serble/estools/Signs/SignMain.java +++ b/src/main/java/net/serble/estools/Signs/SignMain.java @@ -2,62 +2,75 @@ import net.serble.estools.EsToolsCommand; import net.serble.estools.Main; -import org.bukkit.Bukkit; -import org.bukkit.block.Sign; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.event.player.PlayerInteractEvent; +import net.serble.estools.SemanticVersion; +import net.serble.estools.ServerApi.EsAction; +import net.serble.estools.ServerApi.EsEventListener; +import net.serble.estools.ServerApi.EsEventResult; +import net.serble.estools.ServerApi.Events.EsPlayerInteractEvent; +import net.serble.estools.ServerApi.Events.EsSignChangeEvent; +import net.serble.estools.ServerApi.Interfaces.EsEvent; +import net.serble.estools.ServerApi.Interfaces.EsSign; +import net.serble.estools.Tuple; import java.util.HashMap; -public class SignMain implements Listener { +public class SignMain implements EsEventListener { private static final HashMap signs = new HashMap<>(); - private static final HashMap signConversions = new HashMap<>(); + private static final HashMap> signConversions = new HashMap<>(); public static void init() { - addSign(new Disposal(), "[disposal]", EsToolsCommand.translate("&1[Disposal]")); - addSign(new Give(), "[give]", EsToolsCommand.translate("&1[Give]")); - addSign(new Heal(), "[heal]", EsToolsCommand.translate("&1[Heal]")); - addSign(new Feed(), "[feed]", EsToolsCommand.translate("&1[Feed]")); - addSign(new Balance(), "[balance]", EsToolsCommand.translate("&1[Balance]")); - addSign(new Repair(), "[repair]", EsToolsCommand.translate("&1[Repair]")); - addSign(new Sell(), "[sell]", EsToolsCommand.translate("&1[Sell]")); - - Bukkit.getServer().getPluginManager().registerEvents(new SignMain(), Main.plugin); + addSign(new Disposal(), "[disposal]", EsToolsCommand.translate("&1[Disposal]"), new SemanticVersion(1, 2, 0)); + addSign(new Give(), "[give]", EsToolsCommand.translate("&1[Give]"), new SemanticVersion(1, 1, 0)); + addSign(new Heal(), "[heal]", EsToolsCommand.translate("&1[Heal]"), new SemanticVersion(1, 1, 0)); + addSign(new Feed(), "[feed]", EsToolsCommand.translate("&1[Feed]"), new SemanticVersion(1, 1, 0)); + addSign(new Repair(), "[repair]", EsToolsCommand.translate("&1[Repair]"), new SemanticVersion(1, 1, 0)); + + Main.registerEvents(new SignMain()); } - public static void addSign(SignType signType, String conversion, String sign) { - signConversions.put(conversion, sign); + public static void addSign(SignType signType, String conversion, String sign, SemanticVersion minVersion) { + signConversions.put(conversion, new Tuple<>(sign, minVersion)); signs.put(sign, signType); } - @SuppressWarnings("deprecation") - @EventHandler - public void interact(PlayerInteractEvent e) { - if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.getClickedBlock().getType().name().endsWith("SIGN")) { - Sign state = (Sign)e.getClickedBlock().getState(); + public void interact(EsPlayerInteractEvent e) { + if (e.getAction().equals(EsAction.RightClickBlock) && e.getClickedBlock() instanceof EsSign) { + EsSign state = (EsSign) e.getClickedBlock(); SignType signType = signs.get(state.getLine(0)); if (signType != null) { - e.setCancelled(true); + e.setUseInteractedBlock(EsEventResult.DENY); signType.run(e.getPlayer(), state.getLines()); } } } - @EventHandler - public void changeSign(SignChangeEvent e) { + public void changeSign(EsSignChangeEvent e) { if (!e.getPlayer().hasPermission("estools.signs")) { return; } - String str = signConversions.get(e.getLine(0).toLowerCase()); + Tuple conversion = signConversions.get(e.getLine(0).toLowerCase()); + + if (conversion != null) { + if (Main.minecraftVersion.isAtLeast(conversion.b())) { + e.setLine(0, conversion.a()); + } else { + EsToolsCommand.send(e.getPlayer(), "&cThis sign is requires minecraft version %s or higher", conversion.b().toString()); + } + } + } + + @Override + public void executeEvent(EsEvent event) { + if (event instanceof EsPlayerInteractEvent) { + interact((EsPlayerInteractEvent) event); + return; + } - if (str != null) { - e.setLine(0, str); + if (event instanceof EsSignChangeEvent) { + changeSign((EsSignChangeEvent) event); } } } diff --git a/src/main/java/net/serble/estools/Signs/SignType.java b/src/main/java/net/serble/estools/Signs/SignType.java index 68db0c4..65dc5e0 100644 --- a/src/main/java/net/serble/estools/Signs/SignType.java +++ b/src/main/java/net/serble/estools/Signs/SignType.java @@ -1,38 +1,13 @@ package net.serble.estools.Signs; import net.serble.estools.EsToolsCommand; -import net.serble.estools.Vault; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; public abstract class SignType { - public void run(Player p, String[] lines) { } + public void run(EsPlayer p, String[] lines) { } - public static double getSignMoney(String line, Player p) { - double price = 0; - try { - String priceString = line.substring(1); - - if (!line.startsWith("$")) { - send(p, "&cMoney must be formatted with \"$COST\""); - return -1; - } - - price = Double.parseDouble(priceString); - } catch (NumberFormatException e) { /* Ignored */ } - - return price; - } - - public static boolean takeMoney(String line, Player p) { - return Vault.takeMoney(getSignMoney(line, p), p); - } - - public static boolean payMoney(String line, Player p) { - return Vault.payMoney(getSignMoney(line, p), p); - } - - public static void send(CommandSender s, String msg, Object... args) { + public static void send(EsCommandSender s, String msg, Object... args) { EsToolsCommand.send(s, msg, args); } } diff --git a/src/main/java/net/serble/estools/TabCompleteGenerator.java b/src/main/java/net/serble/estools/TabCompleteGenerator.java deleted file mode 100644 index 0572679..0000000 --- a/src/main/java/net/serble/estools/TabCompleteGenerator.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.serble.estools; - -import org.bukkit.command.TabCompleter; - -public class TabCompleteGenerator { - public static TabCompleter generate(EsToolsTabCompleter tabCompleter) { - return tabCompleter::onTabComplete; - } -} diff --git a/src/main/java/net/serble/estools/TestCommand.java b/src/main/java/net/serble/estools/TestCommand.java new file mode 100644 index 0000000..178c5ec --- /dev/null +++ b/src/main/java/net/serble/estools/TestCommand.java @@ -0,0 +1,34 @@ +package net.serble.estools; + +/** + * A command schema containing information for the Tester. + */ +public class TestCommand { + private final String cmd; + private final double waitAfter; + private final SemanticVersion minVersion; + + public TestCommand(String cmd, double waitAfter, SemanticVersion minVersion) { + this.cmd = cmd; + this.waitAfter = waitAfter; + this.minVersion = minVersion; + } + + public TestCommand(String cmd, double waitAfter) { + this.cmd = cmd; + this.waitAfter = waitAfter; + minVersion = null; + } + + public double getWaitAfter() { + return waitAfter; + } + + public SemanticVersion getMinVersion() { + return minVersion; + } + + public String getCmd() { + return cmd; + } +} diff --git a/src/main/java/net/serble/estools/Tester.java b/src/main/java/net/serble/estools/Tester.java index 8b0230b..5ccd23f 100644 --- a/src/main/java/net/serble/estools/Tester.java +++ b/src/main/java/net/serble/estools/Tester.java @@ -1,106 +1,115 @@ package net.serble.estools; import net.serble.estools.Commands.SafeTp; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; +import net.serble.estools.ServerApi.Interfaces.EsEntity; +import net.serble.estools.ServerApi.Interfaces.EsPlayer; -import java.io.PrintWriter; -import java.io.StringWriter; import java.util.HashMap; import java.util.UUID; public class Tester { - private final Player player; + private final EsPlayer player; private int currentCommand = 0; public static final HashMap runningTests = new HashMap<>(); - @SuppressWarnings("unchecked") // It doesn't allow specifying type - private static final Tuple[] routine = new Tuple[] { - new Tuple<>("gmsp", 1.5), - new Tuple<>("gmc", 1.5), - new Tuple<>("gma", 1.5), - new Tuple<>("gms", 1.5), - new Tuple<>("i apple", 2), - new Tuple<>("h dirt", 2), - new Tuple<>("fly", 4), - new Tuple<>("flyspeed 10", 2), - new Tuple<>("flyspeed 2", 0.1), - new Tuple<>("fly", 0.1), - new Tuple<>("walkspeed 10", 3), - new Tuple<>("walkspeed 2", 0.1), - new Tuple<>("ps", 0.1), - new Tuple<>("pp", 0.1), - new Tuple<>("pa", 0.1), - new Tuple<>("psh", 0.1), - new Tuple<>("ph", 3), - new Tuple<>("tphere {randomplayer}", 3), - new Tuple<>("tpall", 2), - new Tuple<>("warps add test", 2), - new Tuple<>("safetp", 2), - new Tuple<>("tp ~50 ~5000 ~50", 1), - new Tuple<>("warp test", 2), - new Tuple<>("warps remove test", 2), - new Tuple<>("tp ~50 ~5000 ~50", 1), - new Tuple<>("back", 1), - new Tuple<>("cchest", -1), - new Tuple<>("ci", 1), - new Tuple<>("h sign", 0.1), - new Tuple<>("msg {player} Place and look at the sign (leave it empty)", -1), - new Tuple<>("editsign 1 Hello World!", 1), - new Tuple<>("editsign glow", 1), - new Tuple<>("editsign unglow", 1), - new Tuple<>("editsign 2 Does it work?", 1), - new Tuple<>("msg {player} Look at the back of the sign", -1), - new Tuple<>("editsign 1 Hello World!", 1), - new Tuple<>("editsign glow", 1), - new Tuple<>("editsign unglow", 1), - new Tuple<>("editsign 2 Does it work?", 1), - new Tuple<>("eff speed 1 60 {player}", 3), - new Tuple<>("h iron_sword", 0.1), - new Tuple<>("ench knockback 10", 3), - new Tuple<>("estools", 1), - new Tuple<>("sethealth 1", 2), - new Tuple<>("sethunger 1", 2), - new Tuple<>("feed", 0.1), - new Tuple<>("setsaturation 0", 0.1), - new Tuple<>("msg {player} If you heal health and don't lose hunger, setsaturation didn't work", 6), - new Tuple<>("heal", 1), - new Tuple<>("msg {player} Mine a block with the sword and hold it", -1), - new Tuple<>("fix", 1), - new Tuple<>("getinfo {player}", 3), - new Tuple<>("god", 0.1), - new Tuple<>("tp ~ ~10 ~", 5), - new Tuple<>("smite {player}", 2), - new Tuple<>("god", 0.1), - new Tuple<>("hideflags", 4), - new Tuple<>("h dirt", 0.1), - new Tuple<>("infinite", -1), - new Tuple<>("invsee {randomplayer}", -1), - new Tuple<>("h dirt", 0.1), - new Tuple<>("lore add Silly &ldirt", 4), - new Tuple<>("lore insert 1 &cNot very", 2), - new Tuple<>("lore remove 1", 2), - new Tuple<>("music", 3), - new Tuple<>("night", 1), - new Tuple<>("day", 1), - new Tuple<>("potion speed", 2), - new Tuple<>("rename &6This dirt is special", 4), - new Tuple<>("setmaxhealth 30", 2), - new Tuple<>("setstack 127", 2), - new Tuple<>("h iron_sword", 0.1), - new Tuple<>("setunbreakable", 4), - new Tuple<>("heal", 0.1), - new Tuple<>("sudo {randomplayer} say I have been sudoed", 2), - new Tuple<>("h dirt", 0.1), - new Tuple<>("setpersistentdata estools:hello string wassup", 2), - new Tuple<>("getpersistentdata estools:hello string", 2), - new Tuple<>("removepersistentdata estools:hello", 2), - new Tuple<>("getpersistentdata estools:hello string", 2), - new Tuple<>("suicide", 4) + private static final TestCommand[] routine = new TestCommand[] { + new TestCommand("music", 1, new SemanticVersion(1, 9, 0)), + new TestCommand("gmsp", 1.5, new SemanticVersion(1, 8, 0)), + new TestCommand("gmc", 1.5), + new TestCommand("gma", 1.5, new SemanticVersion(1, 3, 0)), + new TestCommand("gms", 1.5), + new TestCommand("i apple", 2), + new TestCommand("h dirt", 2), + new TestCommand("fly", 4, new SemanticVersion(1, 2, 0)), + new TestCommand("flyspeed 10", 2, new SemanticVersion(1, 3, 0)), + new TestCommand("flyspeed 2", 0.1, new SemanticVersion(1, 3, 0)), + new TestCommand("fly", 0.1, new SemanticVersion(1, 2, 0)), + new TestCommand("walkspeed 10", 3, new SemanticVersion(1, 4, 0)), + new TestCommand("walkspeed 2", 0.1, new SemanticVersion(1, 4, 0)), + new TestCommand("ps", 0.1, new SemanticVersion(1, 1, 0)), + new TestCommand("pp", 0.1, new SemanticVersion(1, 1, 0)), + new TestCommand("pa", 0.1, new SemanticVersion(1, 1, 0)), + new TestCommand("psh", 0.1, new SemanticVersion(1, 1, 0)), + new TestCommand("ph", 3, new SemanticVersion(1, 1, 0)), + new TestCommand("tphere {randomplayer}", 3), + new TestCommand("tpall", 2), + new TestCommand("warps add test", 2), + new TestCommand("safetp", 2, new SemanticVersion(1, 1, 0)), + new TestCommand("tp {player} 0 512 0", 1), + new TestCommand("warp test", 2), + new TestCommand("warps remove test", 2), + new TestCommand("tp {player} 0 512 0", 1, new SemanticVersion(1, 1, 0)), + new TestCommand("back", 1, new SemanticVersion(1, 1, 0)), + new TestCommand("cchest", -1, new SemanticVersion(1, 7, 0)), + new TestCommand("ci", 1), + new TestCommand("h sign", 0.1), + new TestCommand("msg Place and look at the sign (leave it empty)", -1), + new TestCommand("editsign 1 Hello World!", 1), + new TestCommand("editsign glow", 1, new SemanticVersion(1, 17,0)), + new TestCommand("editsign unglow", 1, new SemanticVersion(1, 17, 0)), + new TestCommand("editsign 2 Does it work?", 1), + new TestCommand("msg {player} Look at the back of the sign", -1, new SemanticVersion(1, 20, 0)), + new TestCommand("editsign 1 Hello World!", 1, new SemanticVersion(1, 20, 0)), + new TestCommand("editsign glow", 1, new SemanticVersion(1, 20, 0)), + new TestCommand("editsign unglow", 1, new SemanticVersion(1, 20, 0)), + new TestCommand("editsign 2 Does it work?", 1, new SemanticVersion(1, 20 ,0)), + new TestCommand("eff speed 1 60 {player}", 3, new SemanticVersion(1, 1, 0)), + new TestCommand("h iron_sword", 0.1), + new TestCommand("ench knockback 10", 3, new SemanticVersion(1, 1, 0)), + new TestCommand("estools", 0.1), + new TestCommand("sethealth 1", 2), + new TestCommand("sethunger 1", 2), + new TestCommand("feed", 0.1), + new TestCommand("setsaturation 0", 0.1), + new TestCommand("msg If you heal health and don't lose hunger, setsaturation didn't work", 6), + new TestCommand("heal", 1), + new TestCommand("msg Mine a block with the sword and hold it", -1), + new TestCommand("fix", 1), + new TestCommand("getinfo {player}", 3), + new TestCommand("god", 0.1, new SemanticVersion(1, 1, 0)), + new TestCommand("smite {player}", 2), + new TestCommand("god", 0.1, new SemanticVersion(1, 1, 0)), + new TestCommand("hideflags", 4, new SemanticVersion(1, 8, 0)), + new TestCommand("h dirt", 0.1), + new TestCommand("infinite", -1, new SemanticVersion(1, 1, 0)), + new TestCommand("invsee {randomplayer}", -1, new SemanticVersion(1, 2, 0)), + new TestCommand("h dirt", 0.1), + new TestCommand("lore add Silly &ldirt", 4, new SemanticVersion(1, 4, 6)), + new TestCommand("lore insert 1 &cNot very", 2, new SemanticVersion(1, 4, 6)), + new TestCommand("lore remove 1", 2, new SemanticVersion(1, 4, 6)), + new TestCommand("rain", 3), + new TestCommand("sun", 3), + new TestCommand("thunder", 3), + new TestCommand("night", 1), + new TestCommand("noon", 1), + new TestCommand("midnight", 1), + new TestCommand("day", 1), + new TestCommand("potion speed", 2), + new TestCommand("rename &6This dirt is special", 4, new SemanticVersion(1, 4, 6)), + new TestCommand("setmaxhealth 30", 2, new SemanticVersion(1, 4, 0)), + new TestCommand("setstack 127", 2), + new TestCommand("h iron_sword", 0.1), + new TestCommand("setunbreakable", 4, new SemanticVersion(1, 1, 0)), + new TestCommand("heal", 0.1), + new TestCommand("sudo {randomplayer} say I have been sudoed", 2), + new TestCommand("h dirt", 0.1), + new TestCommand("setpersistentdata estools:hello string wassup", 2, new SemanticVersion(1, 14, 0)), + new TestCommand("getpersistentdata estools:hello string", 2, new SemanticVersion(1, 14, 0)), + new TestCommand("removepersistentdata estools:hello", 2, new SemanticVersion(1, 14, 0)), + new TestCommand("getpersistentdata estools:hello string", 2, new SemanticVersion(1, 14, 0)), + new TestCommand("mount {entity}", 2), + new TestCommand("dismount", 1), + new TestCommand("dismount", 1), + new TestCommand("mount {player}", 1), + new TestCommand("mount {player} {entity}", 2), + new TestCommand("dismount {entity}", 1), + new TestCommand("sethealth 1", 0.1), + new TestCommand("buddha", -1, new SemanticVersion(1, 1, 0)), + new TestCommand("suicide", 1), }; - public Tester(Player p) { + public Tester(EsPlayer p) { player = p; } @@ -110,6 +119,11 @@ public void startTests() { // Init some stuff SafeTp.enabled = false; + // Find starting command (Where the version is valid) + while (routine[currentCommand].getMinVersion() != null && !Main.minecraftVersion.isAtLeast(routine[currentCommand].getMinVersion())) { + currentCommand++; + } + execNextCommand(); } @@ -124,14 +138,16 @@ private void execNextCommand() { return; } - Tuple cCmd = routine[currentCommand]; - currentCommand++; + TestCommand cCmd = routine[currentCommand]; + do { + currentCommand++; + } while (routine.length != currentCommand && routine[currentCommand].getMinVersion() != null && !Main.minecraftVersion.isAtLeast(routine[currentCommand].getMinVersion())); - String cmd = cCmd.a(); + String cmd = cCmd.getCmd(); if (cmd.contains("{randomplayer}")) { // Find a random player that isn't player - Player randomPlayer = null; - for (Player p : Bukkit.getOnlinePlayers()) { + EsPlayer randomPlayer = null; + for (EsPlayer p : Main.server.getOnlinePlayers()) { if (p != player) { randomPlayer = p; break; @@ -144,6 +160,31 @@ private void execNextCommand() { cmd = cmd.replace("{randomplayer}", randomPlayer.getName()); } + + if (cmd.contains("{entity}")) { + // Find the nearest entity + EsEntity nearestEntity = null; + double nearestDistance = 60000000; + + for (EsEntity en : player.getWorld().getEntities()) { + if (en instanceof EsPlayer) { + continue; + } + + double distance = player.getLocation().distanceTo(en.getLocation()); + if (distance < nearestDistance) { + nearestDistance = distance; + nearestEntity = en; + } + } + + if (nearestEntity == null) { + nearestEntity = player; + } + + cmd = cmd.replace("{entity}", nearestEntity.getUniqueId().toString()); + } + cmd = cmd.replace("{player}", player.getName()); try { @@ -152,23 +193,20 @@ private void execNextCommand() { EsToolsCommand.send(player, "&cFailed to execute the following command: " + cmd); // Print the full stacktrace not just the message - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - e.printStackTrace(pw); - String stackTrace = sw.toString(); + String stackTrace = Utils.getStacktrace(e); EsToolsCommand.send(player, "&c" + stackTrace); - Bukkit.getLogger().severe(stackTrace); + Main.logger.severe(stackTrace); return; } - Double secVal; - Object val = cCmd.b(); + double secVal; + Object val = cCmd.getWaitAfter(); //noinspection ConstantValue, it's not constant if (val instanceof Integer) { // Stupid java being dumb secVal = ((Integer) val).doubleValue(); } else { - secVal = cCmd.b(); + secVal = cCmd.getWaitAfter(); } if (secVal < 0) { @@ -177,12 +215,16 @@ private void execNextCommand() { } @SuppressWarnings("WrapperTypeMayBePrimitive") Double timeInTicks = (secVal * 20.0); // The type cannot be primitive - Bukkit.getScheduler().runTaskLater(Main.plugin, this::execNextCommand, timeInTicks.longValue()); - EsToolsCommand.send(player, "&bWaiting &6" + cCmd.b() + " seconds"); + Main.server.runTaskLater(this::execNextCommand, timeInTicks.longValue()); + EsToolsCommand.send(player, "&bWaiting &6" + cCmd.getWaitAfter() + " seconds"); } private void exec(String cmd) { + if (cmd.startsWith("msg ")) { // Overwrite msg to make a fancier way to talking to the player + EsToolsCommand.send(player, "&b[Tester] " + cmd.replace("msg ", "")); + return; + } EsToolsCommand.send(player, "&aExecuting: " + cmd); - Bukkit.dispatchCommand(player, cmd); + Main.server.dispatchCommand(player, cmd); } } diff --git a/src/main/java/net/serble/estools/Updater.java b/src/main/java/net/serble/estools/Updater.java index 00bb3d5..c5f5af6 100644 --- a/src/main/java/net/serble/estools/Updater.java +++ b/src/main/java/net/serble/estools/Updater.java @@ -2,8 +2,7 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; +import net.serble.estools.ServerApi.Interfaces.EsCommandSender; import java.io.*; import java.net.HttpURLConnection; @@ -15,13 +14,13 @@ public class Updater { private static void checkForUpdateBlocking() { try { - URL url = new URL(Objects.requireNonNull(Main.plugin.getConfig().getString("updater.github-release-url"))); + URL url = new URL(Objects.requireNonNull(Main.plugin.getConfig().getUpdater().getGithubReleasesUrl())); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.connect(); if (con.getResponseCode() != 200) { - Bukkit.getLogger().severe("[EsTools Updater] GitHub gave unsuccessful response code: " + con.getResponseCode()); + Main.logger.severe("[EsTools Updater] GitHub gave unsuccessful response code: " + con.getResponseCode()); return; } @@ -44,14 +43,8 @@ private static void checkForUpdateBlocking() { .get("browser_download_url") .getAsString(); - PluginVersion onlineVersion = new PluginVersion(response.get("tag_name").getAsString()); - String cVersion = Main.plugin.getDescription().getVersion(); - - if (cVersion.contains("-")) { - cVersion = cVersion.substring(0, cVersion.indexOf("-")); - } - - PluginVersion currentVersion = new PluginVersion(cVersion); + SemanticVersion onlineVersion = new SemanticVersion(response.get("tag_name").getAsString()); + SemanticVersion currentVersion = Main.server.getPluginVersion(); // Provide download URL just in case we force update waitingDownloadUrl = downloadUrl; @@ -64,22 +57,22 @@ private static void checkForUpdateBlocking() { Main.newVersion = onlineVersion; // Announcements - if (Main.plugin.getConfig().getBoolean("updater.warn-on-outdated", false)) { - Bukkit.broadcast(EsToolsCommand.translate("&a[EsTools] &cAn update is available, &6" + cVersion + " -> " + onlineVersion.getString()), "estools.update"); + if (Main.plugin.getConfig().getUpdater().isWarnOnOutdated()) { + Main.server.broadcast(EsToolsCommand.translate("&a[EsTools] &cAn update is available, &6" + currentVersion + " -> " + onlineVersion), "estools.update"); } - if (Main.plugin.getConfig().getBoolean("updater.log-on-outdated", false)) { - Bukkit.getLogger().info(EsToolsCommand.translate("&a[EsTools] &cAn update is available, &6" + cVersion + " -> " + onlineVersion.getString())); + if (Main.plugin.getConfig().getUpdater().isLogOnOutdated()) { + Main.logger.info(EsToolsCommand.translate("&a[EsTools] &cAn update is available, &6" + currentVersion + " -> " + onlineVersion)); } - if (!Main.plugin.getConfig().getBoolean("updater.auto-update", false)) { + if (!Main.plugin.getConfig().getUpdater().isAutoUpdate()) { return; } downloadNewUpdate(); - Bukkit.getLogger().info("[EsTools Updater] Downloaded latest plugin version"); + Main.logger.info("[EsTools Updater] Downloaded latest plugin version"); Main.newVersionReady = true; } catch (IOException e) { - Bukkit.getLogger().severe("[EsTools Updater] Failed to check for updates, invalid releases URL configured"); + Main.logger.severe("[EsTools Updater] Failed to check for updates, invalid releases URL configured"); } } @@ -87,7 +80,7 @@ public static void downloadNewUpdate() { downloadNewUpdate(null); } - public static void downloadNewUpdate(CommandSender reportTo) { + public static void downloadNewUpdate(EsCommandSender reportTo) { if (waitingDownloadUrl == null) { throw new RuntimeException("We aren't waiting for an update"); } @@ -96,7 +89,7 @@ public static void downloadNewUpdate(CommandSender reportTo) { downloadFile(waitingDownloadUrl); Main.newVersionReady = true; } catch (IOException e) { - Bukkit.getLogger().severe("Failed to update: " + e); + Main.logger.severe("Failed to update: " + e); return; } @@ -122,7 +115,7 @@ public static void downloadFile(String fileURL) InputStream inputStream = httpConn.getInputStream(); String saveFilePath = Main.plugin.getClass().getProtectionDomain() .getCodeSource().getLocation().getFile().replace("%20", " "); - Bukkit.getLogger().info("Save file path: " + saveFilePath); + Main.logger.info("Save file path: " + saveFilePath); FileOutputStream outputStream = new FileOutputStream(saveFilePath); diff --git a/src/main/java/net/serble/estools/Utils.java b/src/main/java/net/serble/estools/Utils.java new file mode 100644 index 0000000..49f4a25 --- /dev/null +++ b/src/main/java/net/serble/estools/Utils.java @@ -0,0 +1,30 @@ +package net.serble.estools; + +import java.io.PrintWriter; +import java.io.StringWriter; + +public class Utils { + public static String keyToDisplayName(String key) { + StringBuilder name = new StringBuilder(key); + name.setCharAt(0, Character.toUpperCase(name.charAt(0))); + + int index = name.indexOf("_"); + while (index != -1) { + name.setCharAt(index, ' '); + if (index < name.length()) { // Edge case where item id ends with '_' + name.setCharAt(index+1, Character.toUpperCase(name.charAt(index+1))); + } + + index = name.indexOf("_"); + } + + return name.toString(); + } + + public static String getStacktrace(Exception e) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + return sw.toString(); + } +} diff --git a/src/main/java/net/serble/estools/Vault.java b/src/main/java/net/serble/estools/Vault.java deleted file mode 100644 index f376b0d..0000000 --- a/src/main/java/net/serble/estools/Vault.java +++ /dev/null @@ -1,61 +0,0 @@ -package net.serble.estools; - -import net.milkbowl.vault.economy.Economy; -import net.milkbowl.vault.economy.EconomyResponse; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.RegisteredServiceProvider; - -public class Vault { - public static Economy economy = null; - - public static void setupEconomy() { - if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) { - Bukkit.getLogger().warning("No Vault plugin found, please install vault for economy functionality"); - return; - } - - RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); - if (rsp == null) { - Bukkit.getLogger().warning("No vault service found, make sure vault and a economy plugin is installed!"); - return; - } - - economy = rsp.getProvider(); - - //noinspection ConstantValue - if (economy == null) { - Bukkit.getLogger().warning("Vault functionality failed to initialise"); - } - - } - - public static boolean takeMoney(double price, Player p) { - if (price <= 0) { - return true; - } - - if (Vault.economy == null) { - EsToolsCommand.send(p, "&cVault is required for economy!"); - return false; - } - - if (Vault.economy.getBalance(p) < price) { - EsToolsCommand.send(p, "&cYou do not have enough money to purchase this item."); - return false; - } - - Vault.economy.withdrawPlayer(p, price); - return true; - } - - public static boolean payMoney(double price, Player p) { - if (Vault.economy == null) { - EsToolsCommand.send(p, "&cVault is required for economy!"); - return false; - } - - EconomyResponse economyResponse = Vault.economy.depositPlayer(p, price); - return economyResponse.transactionSuccess(); - } -} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9f0f405..4add2bc 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,7 +1,7 @@ # Go to https://estools.serble.net/configuration.html for information on configuring the plugin # Stops players taking fall damage when they teleport -safetp: true +safeTp: true # Toggle bStats metrics metrics: true @@ -10,14 +10,14 @@ metrics: true updater: # The GitHub API path to query for the latest version, change if you want to use a fork - github-release-url: "https://api.github.com/repos/CoPokBl/EsTools/releases/latest" + githubReleasesUrl: "https://api.github.com/repos/CoPokBl/EsTools/releases/latest" # Whether to automatically install updates if they are available - auto-update: false + autoUpdate: false # Whether to notify operators when they join the server if the plugin is outdated # Leave this off if you enable auto-update, this will prompt user to type /estools update - warn-on-outdated: false + warnOnOutdated: false # Log to the console when the plugin is out of date - log-on-outdated: true + logOnOutdated: true diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fa7a96b..dbf9a94 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,10 +1,11 @@ -main: net.serble.estools.Main +main: net.serble.estools.Entrypoints.EsToolsBukkit name: EsTools description: Simple highly compatible general purpose plugin. version: '${project.version}' -softdepend: [Vault] +softdepend: [] authors: [Calcilator, CoPokBl] api-version: 1.13 +folia-supported: true commands: estools: