diff --git a/pom.xml b/pom.xml index 99f81fe..cc4da53 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,30 @@ com.zaxxer.hikari nl.SBDeveloper.V10Lift.utils.hikari + + com.cryptomorin.xseries + nl.SBDeveloper.V10Lift.utils.xseries + + + + *:* + + com/cryptomorin/xseries/XPotion* + com/cryptomorin/xseries/XItemStack* + com/cryptomorin/xseries/XEntity* + com/cryptomorin/xseries/XEnchantment* + com/cryptomorin/xseries/XBlock* + com/cryptomorin/xseries/XBiome* + com/cryptomorin/xseries/SkullUtils* + com/cryptomorin/xseries/ReflectionUtils* + com/cryptomorin/xseries/NMSExtras* + com/cryptomorin/xseries/NoteBlockMusic* + com/cryptomorin/xseries/particles/* + com/cryptomorin/xseries/messages/* + + + @@ -161,6 +184,14 @@ provided + + + org.yaml + snakeyaml + 1.27 + provided + + org.projectlombok @@ -185,6 +216,13 @@ provided + + + com.github.cryptomorin + XSeries + 7.9.1.1 + + com.google.code.findbugs jsr305 diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/V10LiftPlugin.java b/src/main/lombok/nl/SBDeveloper/V10Lift/V10LiftPlugin.java index 9d22911..686b372 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/V10LiftPlugin.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/V10LiftPlugin.java @@ -10,15 +10,16 @@ import nl.SBDeveloper.V10Lift.listeners.SignChangeListener; import nl.SBDeveloper.V10Lift.managers.DBManager; import nl.SBDeveloper.V10Lift.managers.DataManager; import nl.SBDeveloper.V10Lift.managers.VaultManager; +import nl.SBDeveloper.V10Lift.sbutils.ConfigUpdater; import nl.SBDeveloper.V10Lift.sbutils.UpdateManager; import nl.SBDeveloper.V10Lift.sbutils.YamlFile; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; +import java.io.IOException; import java.sql.SQLException; -import java.time.LocalDate; -import java.util.Objects; +import java.util.Collections; public class V10LiftPlugin extends JavaPlugin { @@ -37,6 +38,14 @@ public class V10LiftPlugin extends JavaPlugin { config = new YamlFile("config"); config.loadDefaults(); + //And update config + try { + ConfigUpdater.update(this, "config.yml", config.getJavaFile(), Collections.emptyList()); + } catch (IOException e) { + Bukkit.getLogger().warning("[V10Lift] Couldn't update the config.yml. Please check the stacktrace below."); + e.printStackTrace(); + } + //Load the messages messages = new YamlFile("messages"); messages.loadDefaults(); @@ -46,6 +55,7 @@ public class V10LiftPlugin extends JavaPlugin { try { dbManager.load(); } catch (SQLException e) { + Bukkit.getLogger().warning("[V10Lift] Couldn't connect to the SQLite database. Please check the stacktrace below."); e.printStackTrace(); } @@ -53,10 +63,9 @@ public class V10LiftPlugin extends JavaPlugin { api = new V10LiftAPI(); //Load vault if found - if (Bukkit.getServer().getPluginManager().getPlugin("Vault") != null) { + if (VaultManager.setupPermissions()) { Bukkit.getLogger().info("[V10Lift] Loading Vault hook for group whitelist support."); vault = true; - VaultManager.setupPermissions(); } //Load the command @@ -75,27 +84,40 @@ public class V10LiftPlugin extends JavaPlugin { metrics.addCustomChart(new Metrics.SingleLineChart("lifts", () -> DataManager.getLifts().size())); //Load the update checker - if (!getSConfig().getFile().contains("CheckUpdates") || getSConfig().getFile().getBoolean("CheckUpdates")) { - UpdateManager manager = new UpdateManager(this, 72317, UpdateManager.CheckType.SPIGOT); + if (getSConfig().getFile().getBoolean("UpdateChecker.Enabled")) { + UpdateManager updateManager = new UpdateManager(this, 72317); - manager.handleResponse((versionResponse, version) -> { - if (versionResponse == UpdateManager.VersionResponse.FOUND_NEW) { - Bukkit.getLogger().warning("[V10Lift] There is a new version available! Current: " + this.getDescription().getVersion() + " New: " + version); - Bukkit.getLogger().info("[V10Lift] Trying to download..."); + updateManager.handleResponse((versionResponse, version) -> { + switch (versionResponse) { + case FOUND_NEW: + Bukkit.getLogger().warning("[V10Lift] There is a new version available! Current: " + this.getDescription().getVersion() + " New: " + version.get()); + if (getSConfig().getFile().getBoolean("UpdateChecker.DownloadOnUpdate")) { + Bukkit.getLogger().info("[V10Lift] Trying to download the update. This could take some time..."); - manager.handleDownloadResponse((downloadResponse, path) -> { - if (downloadResponse == UpdateManager.DownloadResponse.DONE) { - Bukkit.getLogger().info("[V10Lift] Update done! After a restart, it should be loaded."); - } else if (downloadResponse == UpdateManager.DownloadResponse.UNAVAILABLE) { - Bukkit.getLogger().warning("[V10Lift] Couldn't download the update, because it's not a Spigot resource."); - } else if (downloadResponse == UpdateManager.DownloadResponse.ERROR) { - Bukkit.getLogger().severe("[V10Lift] Unable to download the newest file."); + updateManager.handleDownloadResponse((downloadResponse, fileName) -> { + switch (downloadResponse) { + case DONE: + Bukkit.getLogger().info("[V10Lift] Update downloaded! If you restart your server, it will be loaded. Filename: " + fileName); + break; + case ERROR: + Bukkit.getLogger().severe("[V10Lift] Something went wrong when trying downloading the latest version."); + break; + case UNAVAILABLE: + Bukkit.getLogger().warning("[V10Lift] Unable to download the latest version."); + break; + } + }).runUpdate(); } - }).runUpdate(); - } else if (versionResponse == UpdateManager.VersionResponse.LATEST) { - Bukkit.getLogger().info("[V10Lift] You are running the latest version [" + this.getDescription().getVersion() + "]!"); - } else if (versionResponse == UpdateManager.VersionResponse.UNAVAILABLE) { - Bukkit.getLogger().severe("[V10Lift] Unable to perform an update check."); + break; + case LATEST: + Bukkit.getLogger().info("[V10Lift] You are running the latest version [" + this.getDescription().getVersion() + "]!"); + break; + case THIS_NEWER: + Bukkit.getLogger().info("[V10Lift] You are running a newer version [" + this.getDescription().getVersion() + "]! This is probably fine."); + break; + case UNAVAILABLE: + Bukkit.getLogger().severe("[V10Lift] Unable to perform an update check."); + break; } }).check(); } @@ -105,7 +127,7 @@ public class V10LiftPlugin extends JavaPlugin { @Override public void onDisable() { - V10LiftPlugin.getDBManager().removeFromData(); + dbManager.removeFromData(); //TODO Find a better way, override? dbManager.save(); dbManager.closeConnection(); diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/api/V10LiftAPI.java b/src/main/lombok/nl/SBDeveloper/V10Lift/api/V10LiftAPI.java index ce581a5..665f955 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/api/V10LiftAPI.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/api/V10LiftAPI.java @@ -1,5 +1,6 @@ package nl.SBDeveloper.V10Lift.api; +import com.cryptomorin.xseries.XMaterial; import nl.SBDeveloper.V10Lift.V10LiftPlugin; import nl.SBDeveloper.V10Lift.api.objects.*; import nl.SBDeveloper.V10Lift.api.runnables.DoorCloser; @@ -11,7 +12,6 @@ import nl.SBDeveloper.V10Lift.sbutils.LocationSerializer; import nl.SBDeveloper.V10Lift.utils.ConfigUtil; import nl.SBDeveloper.V10Lift.utils.DirectionUtil; import nl.SBDeveloper.V10Lift.utils.DoorUtil; -import nl.SBDeveloper.V10Lift.utils.XMaterial; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -405,13 +405,7 @@ public class V10LiftAPI { lift.setDoorOpen(f); - if (lift.isRealistic()) { - lift.setDoorCloser(new DoorCloser(liftName)); - long doorCloseTime = V10LiftPlugin.getSConfig().getFile().getLong("DoorCloseTime"); - - int pid = Bukkit.getScheduler().scheduleSyncRepeatingTask(V10LiftPlugin.getInstance(), lift.getDoorCloser(), doorCloseTime, doorCloseTime); - lift.getDoorCloser().setPid(pid); - } + if (lift.isRealistic()) lift.setDoorCloser(new DoorCloser(liftName)); return true; } @@ -439,13 +433,7 @@ public class V10LiftAPI { lift.setDoorOpen(f); - if (lift.isRealistic()) { - lift.setDoorCloser(new DoorCloser(liftName)); - long doorCloseTime = V10LiftPlugin.getSConfig().getFile().getLong("DoorCloseTime"); - - int pid = Bukkit.getScheduler().scheduleSyncRepeatingTask(V10LiftPlugin.getInstance(), lift.getDoorCloser(), doorCloseTime, doorCloseTime); - lift.getDoorCloser().setPid(pid); - } + if (lift.isRealistic()) lift.setDoorCloser(new DoorCloser(liftName)); return true; } @@ -502,10 +490,12 @@ public class V10LiftAPI { } state.update(true); } + for (LiftBlock lb : lift.getDoorOpen().getRealDoorBlocks()) { Block block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at closeDoor").getBlockAt(lb.getX(), lb.getY(), lb.getZ()); DoorUtil.closeDoor(block); } + lift.setDoorOpen(null); if (lift.getDoorCloser() != null) lift.getDoorCloser().stop(); } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/api/objects/Floor.java b/src/main/lombok/nl/SBDeveloper/V10Lift/api/objects/Floor.java index 18676f6..7fa28d6 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/api/objects/Floor.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/api/objects/Floor.java @@ -3,13 +3,14 @@ package nl.SBDeveloper.V10Lift.api.objects; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import java.util.ArrayList; import java.util.HashSet; import java.util.UUID; /** A floor object, for a floor in the lift. */ -@Getter @Setter @NoArgsConstructor +@Getter @Setter @NoArgsConstructor @ToString public class Floor { private String world; private int y; @@ -49,16 +50,4 @@ public class Floor { result = prime * result + y; return result; } - - @Override - public String toString() { - return "Floor{" + - "world='" + world + '\'' + - ", y=" + y + - ", doorBlocks=" + doorBlocks + - ", realDoorBlocks=" + realDoorBlocks + - ", userWhitelist=" + userWhitelist + - ", groupWhitelist=" + groupWhitelist + - '}'; - } } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/api/objects/Lift.java b/src/main/lombok/nl/SBDeveloper/V10Lift/api/objects/Lift.java index 5d9fa17..ac89e5c 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/api/objects/Lift.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/api/objects/Lift.java @@ -3,12 +3,13 @@ package nl.SBDeveloper.V10Lift.api.objects; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import nl.SBDeveloper.V10Lift.api.runnables.DoorCloser; import java.util.*; /** A lift object, to create a lift. */ -@NoArgsConstructor +@NoArgsConstructor @ToString public class Lift { @Getter @Setter private String worldName; @Getter @Setter private int y; @@ -59,30 +60,4 @@ public class Lift { this.speed = speed; this.realistic = realistic; } - - @Override - public String toString() { - return "Lift{" + - "worldName='" + worldName + '\'' + - ", y=" + y + - ", owners=" + owners + - ", blocks=" + blocks + - ", floors=" + floors + - ", signs=" + signs + - ", inputs=" + inputs + - ", offlineInputs=" + offlineInputs + - ", queue=" + queue + - ", ropes=" + ropes + - ", toMove=" + toMove + - ", speed=" + speed + - ", realistic=" + realistic + - ", offline=" + offline + - ", sound=" + sound + - ", defective=" + defective + - ", signText='" + signText + '\'' + - ", counter=" + counter + - ", doorOpen=" + doorOpen + - ", doorCloser=" + doorCloser + - '}'; - } } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/api/runnables/DoorCloser.java b/src/main/lombok/nl/SBDeveloper/V10Lift/api/runnables/DoorCloser.java index a3fc217..3f71096 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/api/runnables/DoorCloser.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/api/runnables/DoorCloser.java @@ -1,16 +1,19 @@ package nl.SBDeveloper.V10Lift.api.runnables; -import nl.SBDeveloper.V10Lift.managers.DataManager; import nl.SBDeveloper.V10Lift.V10LiftPlugin; +import nl.SBDeveloper.V10Lift.managers.DataManager; import org.bukkit.Bukkit; -/** The doorcloser runnable, used for checking if the door can be closed. */ +/** The DoorCloser runnable, used for checking if the door can be closed. */ public class DoorCloser implements Runnable { private final String liftName; - private int pid; + private final int taskID; public DoorCloser(String liftName) { this.liftName = liftName; + + final long doorCloseTime = V10LiftPlugin.getSConfig().getFile().getLong("DoorCloseTime"); + this.taskID = Bukkit.getScheduler().runTaskTimer(V10LiftPlugin.getInstance(), this, doorCloseTime, doorCloseTime).getTaskId(); } @Override @@ -18,12 +21,8 @@ public class DoorCloser implements Runnable { if (V10LiftPlugin.getAPI().closeDoor(liftName)) stop(); } - public void setPid(int pid) { - this.pid = pid; - } - public void stop() { - Bukkit.getScheduler().cancelTask(pid); + Bukkit.getScheduler().cancelTask(taskID); if (DataManager.containsLift(liftName)) DataManager.getLift(liftName).setDoorCloser(null); } } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/api/runnables/MoveLift.java b/src/main/lombok/nl/SBDeveloper/V10Lift/api/runnables/MoveLift.java index 1a6177a..0e90219 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/api/runnables/MoveLift.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/api/runnables/MoveLift.java @@ -1,13 +1,13 @@ package nl.SBDeveloper.V10Lift.api.runnables; +import com.cryptomorin.xseries.XMaterial; +import com.cryptomorin.xseries.XSound; import nl.SBDeveloper.V10Lift.V10LiftPlugin; import nl.SBDeveloper.V10Lift.api.objects.*; import nl.SBDeveloper.V10Lift.managers.DataManager; import nl.SBDeveloper.V10Lift.sbutils.LocationSerializer; import nl.SBDeveloper.V10Lift.utils.ConfigUtil; import nl.SBDeveloper.V10Lift.utils.DirectionUtil; -import nl.SBDeveloper.V10Lift.utils.XMaterial; -import nl.SBDeveloper.V10Lift.utils.XSound; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockState; diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/commands/V10LiftCommand.java b/src/main/lombok/nl/SBDeveloper/V10Lift/commands/V10LiftCommand.java index ce40638..6dd7250 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/commands/V10LiftCommand.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/commands/V10LiftCommand.java @@ -1,5 +1,6 @@ package nl.SBDeveloper.V10Lift.commands; +import com.cryptomorin.xseries.XMaterial; import nl.SBDeveloper.V10Lift.V10LiftPlugin; import nl.SBDeveloper.V10Lift.api.objects.Floor; import nl.SBDeveloper.V10Lift.api.objects.Lift; @@ -9,7 +10,6 @@ import nl.SBDeveloper.V10Lift.managers.DataManager; import nl.SBDeveloper.V10Lift.managers.VaultManager; import nl.SBDeveloper.V10Lift.sbutils.LocationSerializer; import nl.SBDeveloper.V10Lift.utils.ConfigUtil; -import nl.SBDeveloper.V10Lift.utils.XMaterial; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockState; diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/listeners/PlayerInteractListener.java b/src/main/lombok/nl/SBDeveloper/V10Lift/listeners/PlayerInteractListener.java index 662bd0f..f3960a3 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/listeners/PlayerInteractListener.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/listeners/PlayerInteractListener.java @@ -1,5 +1,7 @@ package nl.SBDeveloper.V10Lift.listeners; +import com.cryptomorin.xseries.XMaterial; +import nl.SBDeveloper.V10Lift.V10LiftPlugin; import nl.SBDeveloper.V10Lift.api.objects.Floor; import nl.SBDeveloper.V10Lift.api.objects.Lift; import nl.SBDeveloper.V10Lift.api.objects.LiftBlock; @@ -7,8 +9,6 @@ import nl.SBDeveloper.V10Lift.managers.DataManager; import nl.SBDeveloper.V10Lift.managers.VaultManager; import nl.SBDeveloper.V10Lift.utils.ConfigUtil; import nl.SBDeveloper.V10Lift.utils.DoorUtil; -import nl.SBDeveloper.V10Lift.utils.XMaterial; -import nl.SBDeveloper.V10Lift.V10LiftPlugin; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -29,8 +29,7 @@ import org.bukkit.inventory.ItemStack; import java.util.*; public class PlayerInteractListener implements Listener { - - private ArrayList rightClicked = new ArrayList<>(); + private final ArrayList rightClicked = new ArrayList<>(); //BUTTON CLICK @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/managers/AntiCopyBlockManager.java b/src/main/lombok/nl/SBDeveloper/V10Lift/managers/AntiCopyBlockManager.java index 2f750fc..f799a90 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/managers/AntiCopyBlockManager.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/managers/AntiCopyBlockManager.java @@ -1,14 +1,14 @@ package nl.SBDeveloper.V10Lift.managers; -import nl.SBDeveloper.V10Lift.utils.XMaterial; +import com.cryptomorin.xseries.XMaterial; import org.bukkit.Material; import java.util.HashSet; public class AntiCopyBlockManager { - private HashSet antiCopy = new HashSet<>(); + private static final HashSet antiCopy = new HashSet<>(); - public AntiCopyBlockManager() { + static { //TODO Add more anti copy materials //TODO Add to config antiCopy.add(XMaterial.REDSTONE_TORCH); @@ -79,7 +79,7 @@ public class AntiCopyBlockManager { antiCopy.add(XMaterial.JUKEBOX); } - public boolean isAntiCopy(Material mat) { + public static boolean isAntiCopy(Material mat) { XMaterial xmat = XMaterial.matchXMaterial(mat); return antiCopy.contains(xmat); } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/managers/DBManager.java b/src/main/lombok/nl/SBDeveloper/V10Lift/managers/DBManager.java index e781dec..a137100 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/managers/DBManager.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/managers/DBManager.java @@ -12,7 +12,6 @@ import java.sql.SQLException; import java.util.Map; public class DBManager { - private static SQLiteDB data; private static Connection con; @@ -121,5 +120,4 @@ public class DBManager { public void closeConnection() { data.closeSource(); } - } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/managers/DataManager.java b/src/main/lombok/nl/SBDeveloper/V10Lift/managers/DataManager.java index 437a9ac..2d42357 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/managers/DataManager.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/managers/DataManager.java @@ -1,5 +1,6 @@ package nl.SBDeveloper.V10Lift.managers; +import lombok.Getter; import nl.SBDeveloper.V10Lift.api.objects.Lift; import nl.SBDeveloper.V10Lift.api.objects.LiftBlock; @@ -7,19 +8,19 @@ import java.util.*; public class DataManager { /* A manager for general HashMaps */ - private static LinkedHashMap lifts = new LinkedHashMap<>(); - private static LinkedHashMap> builds = new LinkedHashMap<>(); - private static LinkedHashMap editors = new LinkedHashMap<>(); - private static LinkedHashMap inputEdits = new LinkedHashMap<>(); - private static ArrayList inputRemoves = new ArrayList<>(); - private static ArrayList offlineEdits = new ArrayList<>(); - private static ArrayList offlineRemoves = new ArrayList<>(); - private static ArrayList builder = new ArrayList<>(); - private static LinkedHashMap ropeEdits = new LinkedHashMap<>(); - private static ArrayList ropeRemoves = new ArrayList<>(); - private static HashMap doorEdits = new HashMap<>(); - private static ArrayList whoisReq = new ArrayList<>(); - private static HashMap movingTasks = new HashMap<>(); + @Getter private static final Map lifts = new LinkedHashMap<>(); + private static final Map> builds = new LinkedHashMap<>(); + @Getter private static final Map editors = new LinkedHashMap<>(); + private static final Map inputEdits = new LinkedHashMap<>(); + private static final List inputRemoves = new ArrayList<>(); + private static final List offlineEdits = new ArrayList<>(); + private static final List offlineRemoves = new ArrayList<>(); + private static final List builder = new ArrayList<>(); + private static final Map ropeEdits = new LinkedHashMap<>(); + private static final List ropeRemoves = new ArrayList<>(); + private static final Map doorEdits = new HashMap<>(); + private static final List whoisReq = new ArrayList<>(); + private static final Map movingTasks = new HashMap<>(); /* HashMap methods */ @@ -40,8 +41,6 @@ public class DataManager { return lifts.get(liftName); } - public static LinkedHashMap getLifts() { return lifts; } - // // public static boolean containsPlayer(UUID player) { return builds.containsKey(player); @@ -114,8 +113,6 @@ public class DataManager { return editors.get(player); } - public static LinkedHashMap getEditors() { return editors; } - // // public static void addMovingTask(String liftName, int taskid) { movingTasks.put(liftName, taskid); diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/managers/ForbiddenBlockManager.java b/src/main/lombok/nl/SBDeveloper/V10Lift/managers/ForbiddenBlockManager.java index 3fe688e..7437e37 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/managers/ForbiddenBlockManager.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/managers/ForbiddenBlockManager.java @@ -1,14 +1,14 @@ package nl.SBDeveloper.V10Lift.managers; -import nl.SBDeveloper.V10Lift.utils.XMaterial; +import com.cryptomorin.xseries.XMaterial; import org.bukkit.Material; import java.util.HashSet; public class ForbiddenBlockManager { - private HashSet forbidden = new HashSet<>(); + private static final HashSet forbidden = new HashSet<>(); - public ForbiddenBlockManager() { + static { //TODO Add more forbidden materials //TODO Add to config forbidden.add(XMaterial.BLACK_BED); @@ -41,7 +41,7 @@ public class ForbiddenBlockManager { forbidden.add(XMaterial.STICKY_PISTON); } - public boolean isForbidden(Material mat) { + public static boolean isForbidden(Material mat) { XMaterial xmat = XMaterial.matchXMaterial(mat); return forbidden.contains(xmat); } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/managers/VaultManager.java b/src/main/lombok/nl/SBDeveloper/V10Lift/managers/VaultManager.java index e7658a1..b354f85 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/managers/VaultManager.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/managers/VaultManager.java @@ -2,10 +2,10 @@ package nl.SBDeveloper.V10Lift.managers; import net.milkbowl.vault.permission.Permission; import nl.SBDeveloper.V10Lift.V10LiftPlugin; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.RegisteredServiceProvider; -import javax.annotation.Nonnull; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -14,12 +14,14 @@ public class VaultManager { private static Permission perms = null; public static boolean setupPermissions() { + if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) { + return false; + } RegisteredServiceProvider rsp = V10LiftPlugin.getInstance().getServer().getServicesManager().getRegistration(Permission.class); perms = rsp.getProvider(); - return perms != null; + return true; } - @Nonnull public static List getGroups() { return Arrays.asList(perms.getGroups()); } @@ -28,7 +30,7 @@ public class VaultManager { return Arrays.asList(perms.getGroups()).contains(groupName); } - public static boolean userHasAnyGroup(Player player, @Nonnull HashSet whitelistSet) { + public static boolean userHasAnyGroup(Player player, HashSet whitelistSet) { boolean found = false; for (String group : whitelistSet) { found = Arrays.asList(perms.getPlayerGroups(player)).contains(group); diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/ConfigUpdater.java b/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/ConfigUpdater.java new file mode 100644 index 0000000..b05b980 --- /dev/null +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/ConfigUpdater.java @@ -0,0 +1,331 @@ +package nl.SBDeveloper.V10Lift.sbutils; + +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.configuration.serialization.ConfigurationSerializable; +import org.bukkit.plugin.Plugin; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.stream.Collectors; + +/** + * A class to update/add new sections/keys to your config while keeping your current values and keeping your comments + * Algorithm: + * Read the new file and scan for comments and ignored sections, if ignored section is found it is treated as a comment. + * Read and write each line of the new config, if the old config has value for the given key it writes that value in the new config. + * If a key has an attached comment above it, it is written first. + * @author tchristofferson + */ +public class ConfigUpdater { + /** + * Update a yaml file from a resource inside your plugin jar + * @param plugin You plugin + * @param resourceName The yaml file name to update from, typically config.yml + * @param toUpdate The yaml file to update + * @param ignoredSections List of sections to ignore and copy from the current config + * @throws IOException If an IOException occurs + */ + public static void update(Plugin plugin, String resourceName, File toUpdate, List ignoredSections) throws IOException { + BufferedReader newReader = new BufferedReader(new InputStreamReader(plugin.getResource(resourceName), StandardCharsets.UTF_8)); + List newLines = newReader.lines().collect(Collectors.toList()); + newReader.close(); + + FileConfiguration oldConfig = YamlConfiguration.loadConfiguration(toUpdate); + FileConfiguration newConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getResource(resourceName))); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(toUpdate), StandardCharsets.UTF_8)); + + List ignoredSectionsArrayList = new ArrayList<>(ignoredSections); + //ignoredSections can ONLY contain configurations sections + ignoredSectionsArrayList.removeIf(ignoredSection -> !newConfig.isConfigurationSection(ignoredSection)); + + DumperOptions options = new DumperOptions(); + + options.setSplitLines(false); + Yaml yaml = new Yaml(options); + Map comments = parseComments(newLines, ignoredSectionsArrayList, oldConfig, yaml); + write(newConfig, oldConfig, comments, ignoredSectionsArrayList, writer, yaml); + } + + //Write method doing the work. + //It checks if key has a comment associated with it and writes comment then the key and value + private static void write(FileConfiguration newConfig, FileConfiguration oldConfig, Map comments, List ignoredSections, BufferedWriter writer, Yaml yaml) throws IOException { + outer: for (String key : newConfig.getKeys(true)) { + String[] keys = key.split("\\."); + String actualKey = keys[keys.length - 1]; + String comment = comments.remove(key); + + StringBuilder prefixBuilder = new StringBuilder(); + int indents = keys.length - 1; + appendPrefixSpaces(prefixBuilder, indents); + String prefixSpaces = prefixBuilder.toString(); + + if (comment != null) { + writer.write(comment);//No \n character necessary, new line is automatically at end of comment + } + + for (String ignoredSection : ignoredSections) { + if (key.startsWith(ignoredSection)) { + continue outer; + } + } + + Object newObj = newConfig.get(key); + Object oldObj = oldConfig.get(key); + + if (newObj instanceof ConfigurationSection && oldObj instanceof ConfigurationSection) { + //write the old section + writeSection(writer, actualKey, prefixSpaces, (ConfigurationSection) oldObj); + } else if (newObj instanceof ConfigurationSection) { + //write the new section, old value is no more + writeSection(writer, actualKey, prefixSpaces, (ConfigurationSection) newObj); + } else if (oldObj != null) { + //write the old object + write(oldObj, actualKey, prefixSpaces, yaml, writer); + } else { + //write new object + write(newObj, actualKey, prefixSpaces, yaml, writer); + } + } + + String danglingComments = comments.get(null); + + if (danglingComments != null) { + writer.write(danglingComments); + } + + writer.close(); + } + + //Doesn't work with configuration sections, must be an actual object + //Auto checks if it is serializable and writes to file + private static void write(Object obj, String actualKey, String prefixSpaces, Yaml yaml, BufferedWriter writer) throws IOException { + if (obj instanceof ConfigurationSerializable) { + writer.write(prefixSpaces + actualKey + ": " + yaml.dump(((ConfigurationSerializable) obj).serialize())); + } else if (obj instanceof String || obj instanceof Character) { + if (obj instanceof String) { + String s = (String) obj; + obj = s.replace("\n", "\\n"); + } + + writer.write(prefixSpaces + actualKey + ": " + yaml.dump(obj)); + } else if (obj instanceof List) { + writeList((List) obj, actualKey, prefixSpaces, yaml, writer); + } else { + writer.write(prefixSpaces + actualKey + ": " + yaml.dump(obj)); + } + } + + //Writes a configuration section + private static void writeSection(BufferedWriter writer, String actualKey, String prefixSpaces, ConfigurationSection section) throws IOException { + if (section.getKeys(false).isEmpty()) { + writer.write(prefixSpaces + actualKey + ": {}"); + } else { + writer.write(prefixSpaces + actualKey + ":"); + } + + writer.write("\n"); + } + + //Writes a list of any object + private static void writeList(List list, String actualKey, String prefixSpaces, Yaml yaml, BufferedWriter writer) throws IOException { + writer.write(getListAsString(list, actualKey, prefixSpaces, yaml)); + } + + private static String getListAsString(List list, String actualKey, String prefixSpaces, Yaml yaml) { + StringBuilder builder = new StringBuilder(prefixSpaces).append(actualKey).append(":"); + + if (list.isEmpty()) { + builder.append(" []\n"); + return builder.toString(); + } + + builder.append("\n"); + + for (int i = 0; i < list.size(); i++) { + Object o = list.get(i); + + if (o instanceof String || o instanceof Character) { + builder.append(prefixSpaces).append("- '").append(o).append("'"); + } else if (o instanceof List) { + builder.append(prefixSpaces).append("- ").append(yaml.dump(o)); + } else { + builder.append(prefixSpaces).append("- ").append(o); + } + + if (i != list.size()) { + builder.append("\n"); + } + } + + return builder.toString(); + } + + //Key is the config key, value = comment and/or ignored sections + //Parses comments, blank lines, and ignored sections + private static Map parseComments(List lines, List ignoredSections, FileConfiguration oldConfig, Yaml yaml) { + Map comments = new HashMap<>(); + StringBuilder builder = new StringBuilder(); + StringBuilder keyBuilder = new StringBuilder(); + int lastLineIndentCount = 0; + + outer: for (int i = 0; i 0) { + comments.put(keyBuilder.toString(), builder.toString()); + builder.setLength(0); + } + } + } + + if (builder.length() > 0) { + comments.put(null, builder.toString()); + } + return comments; + } + + private static void appendSection(StringBuilder builder, ConfigurationSection section, StringBuilder prefixSpaces, Yaml yaml) { + builder.append(prefixSpaces).append(getKeyFromFullKey(section.getCurrentPath())).append(":"); + Set keys = section.getKeys(false); + + if (keys.isEmpty()) { + builder.append(" {}\n"); + return; + } + + builder.append("\n"); + prefixSpaces.append(" "); + + for (String key : keys) { + Object value = section.get(key); + String actualKey = getKeyFromFullKey(key); + + if (value instanceof ConfigurationSection) { + appendSection(builder, (ConfigurationSection) value, prefixSpaces, yaml); + prefixSpaces.setLength(prefixSpaces.length() - 2); + } else if (value instanceof List) { + builder.append(getListAsString((List) value, actualKey, prefixSpaces.toString(), yaml)); + } else { + builder.append(prefixSpaces.toString()).append(actualKey).append(": ").append(yaml.dump(value)); + } + } + } + + //Check how many times spaces make a jump of at least two + private static int countIndents(int index, List lines) { + + int currentSpaces = getSpaces(lines.get(index)); + int indents = 0; + + for (int i = index-1; i >= 0; i--){ + String line = lines.get(i); + if (line == null || line.trim().equals("")) continue; + int newSpaces = getSpaces(lines.get(i)); + // differs at least two + if (newSpaces < currentSpaces - 1){ + indents++; + currentSpaces = newSpaces; + } + if (currentSpaces <= 1) break; + } + return indents; + } + + private static int getSpaces(String line){ + int spaces = 0; + for (char c : line.toCharArray()) { + if (c == ' ') { + spaces += 1; + } else { + break; + } + } + return spaces; + } + + //Ex. keyBuilder = key1.key2.key3 --> key1.key2 + private static void removeLastKey(StringBuilder keyBuilder) { + String temp = keyBuilder.toString(); + String[] keys = temp.split("\\."); + + if (keys.length == 1) { + keyBuilder.setLength(0); + return; + } + + temp = temp.substring(0, temp.length() - keys[keys.length - 1].length() - 1); + keyBuilder.setLength(temp.length()); + } + + private static String getKeyFromFullKey(String fullKey) { + String[] keys = fullKey.split("\\."); + return keys[keys.length - 1]; + } + + //Updates the keyBuilder and returns configLines number of indents + private static int setFullKey(StringBuilder keyBuilder, int index, List configLines, int lastLineIndentCount) { + + int currentIndents = countIndents(index, configLines); + String key = configLines.get(index).trim().split(":")[0]; + + if (keyBuilder.length() == 0) { + keyBuilder.append(key); + } else if (currentIndents == lastLineIndentCount) { + //Replace the last part of the key with current key + removeLastKey(keyBuilder); + + if (keyBuilder.length() > 0) { + keyBuilder.append("."); + } + + keyBuilder.append(key); + } else if (currentIndents > lastLineIndentCount) { + //Append current key to the keyBuilder + keyBuilder.append(".").append(key); + } else { + int difference = lastLineIndentCount - currentIndents; + + for (int i = 0; i < difference + 1; i++) { + removeLastKey(keyBuilder); + } + + if (keyBuilder.length() > 0) { + keyBuilder.append("."); + } + + keyBuilder.append(key); + } + + return currentIndents; + } + + private static String getPrefixSpaces(int indents) { + return new String(new char[Math.max(0, indents)]).replace("\0", " "); + } + + private static void appendPrefixSpaces(StringBuilder builder, int indents) { + builder.append(getPrefixSpaces(indents)); + } +} \ No newline at end of file diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/LocationSerializer.java b/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/LocationSerializer.java index 7a188ad..888e84b 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/LocationSerializer.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/LocationSerializer.java @@ -7,7 +7,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; public class LocationSerializer { - /** * Deserialize a serialized location, without {@link Location#getYaw()} and {@link Location#getPitch()} * @@ -77,5 +76,4 @@ public class LocationSerializer { if (loc.getWorld() == null) return null; return loc.getWorld().getName() + "_" + loc.getX() + "_" + loc.getY() + "_" + loc.getZ() + "_" + loc.getYaw() + "_" + loc.getPitch(); } - } \ No newline at end of file diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/SQLiteDB.java b/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/SQLiteDB.java index 9781d31..31a8d02 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/SQLiteDB.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/SQLiteDB.java @@ -12,8 +12,7 @@ import java.sql.SQLException; import java.util.Properties; public class SQLiteDB { - - private String dbName; + private final String dbName; private HikariDataSource source; private Connection con; diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/UpdateManager.java b/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/UpdateManager.java index 8445778..811acef 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/UpdateManager.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/UpdateManager.java @@ -1,59 +1,75 @@ package nl.SBDeveloper.V10Lift.sbutils; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import javax.net.ssl.HttpsURLConnection; import java.io.*; import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.URL; import java.nio.channels.Channels; +import java.nio.channels.FileChannel; import java.nio.channels.ReadableByteChannel; +import java.nio.charset.StandardCharsets; import java.util.function.BiConsumer; /** * Update class for SBDevelopment * @author Stijn [SBDeveloper] * @since 05-03-2020 - * @version 1.4 + * @version 2.0 [26-12-2020] - This class supports the v2 Update API * - * © Stijn Bannink - All rights reserved. + *

© Stijn Bannink [stijnbannink23@gmail.com] - All rights reserved.

*/ public class UpdateManager { private static final String SPIGOT_API = "https://api.spigotmc.org/legacy/update.php?resource=%d"; + private static final String SPIGOT_DOWNLOAD = "http://api.spiget.org/v2/resources/%s/download"; - /* Port 4000 is now legacy, 4443 has a SSL cert */ - /* As of 24-05-2020, using the legacy port because of SSL errors */ - private static final String SBDPLUGINS_API = "http://updates.sbdplugins.nl:4000/api/resources/%d"; + private static final String SBDPLUGINS_API = "https://updates.sbdplugins.nl/api/v2/plugins/%d"; + private static final String SBDPLUGINS_DOWNLOAD = "https://updates.sbdplugins.nl/api/v2/download/%d"; - private static final String RESOURCE_DOWNLOAD = "http://api.spiget.org/v2/resources/%s/download"; + private final Plugin plugin; + private final Version currentVersion; + private final int resourceID; + private final CheckType type; + private final String license; - private Plugin plugin; - private Version currentVersion; - private int resourceID; - private CheckType type; private BiConsumer versionResponse; private BiConsumer downloadResponse; /** - * Construct a new UpdateManager + * Construct a new UpdateManager for Spigot * * @param plugin The javaplugin (Main class) * @param resourceID The resourceID on spigot/sbdplugins - * @param type The check type */ - public UpdateManager(@Nonnull Plugin plugin, int resourceID, CheckType type) { + public UpdateManager(Plugin plugin, int resourceID) { this.plugin = plugin; this.currentVersion = new Version(plugin.getDescription().getVersion()); this.resourceID = resourceID; - this.type = type; + this.type = CheckType.SPIGOT; + this.license = null; + } + + /** + * Construct a new UpdateManager for SBDPlugins + * + * @param plugin The javaplugin (Main class) + * @param resourceID The resourceID on spigot/sbdplugins + * @param license The license for the download + */ + public UpdateManager(Plugin plugin, int resourceID, String license) { + this.plugin = plugin; + this.currentVersion = new Version(plugin.getDescription().getVersion()); + this.resourceID = resourceID; + this.type = CheckType.SBDPLUGINS; + this.license = license; } /** @@ -85,7 +101,7 @@ public class UpdateManager { in = new BufferedReader(new InputStreamReader(con.getInputStream())); } else if (type == CheckType.SBDPLUGINS) { - HttpURLConnection con = (HttpURLConnection) new URL(String.format(SBDPLUGINS_API, this.resourceID)).openConnection(); + HttpsURLConnection con = (HttpsURLConnection) new URL(String.format(SBDPLUGINS_API, this.resourceID)).openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("User-Agent", "Mozilla/5.0"); @@ -94,7 +110,7 @@ public class UpdateManager { if (in == null) return; - String version = null; + String version; String inputLine; StringBuilder response = new StringBuilder(); @@ -103,22 +119,25 @@ public class UpdateManager { } in.close(); + JsonParser parser = new JsonParser(); + if (type == CheckType.SPIGOT) { - version = response.toString(); - } else if (type == CheckType.SBDPLUGINS) { - JsonParser parser = new JsonParser(); + JsonArray array = parser.parse(response.toString()).getAsJsonArray(); + + version = array.get(0).getAsJsonObject().get("name").getAsString(); + } else { JsonObject object = parser.parse(response.toString()).getAsJsonObject(); - version = object.get("data").getAsJsonObject().get("version").getAsString(); + version = object.get("version").getAsString(); } if (version == null) return; Version onlineVersion = new Version(version); - boolean latestVersion = this.currentVersion.compareTo(onlineVersion) < 0; + VersionResponse verRes = this.currentVersion.check(onlineVersion); - Bukkit.getScheduler().runTask(this.plugin, () -> this.versionResponse.accept(latestVersion ? VersionResponse.LATEST : VersionResponse.FOUND_NEW, latestVersion ? this.currentVersion : onlineVersion)); + Bukkit.getScheduler().runTask(this.plugin, () -> this.versionResponse.accept(verRes, onlineVersion)); } catch (IOException | NullPointerException e) { e.printStackTrace(); Bukkit.getScheduler().runTask(this.plugin, () -> this.versionResponse.accept(VersionResponse.UNAVAILABLE, null)); @@ -127,54 +146,108 @@ public class UpdateManager { } public void runUpdate() { - File pluginFile = getPluginFile();// /plugins/XXX.jar + File pluginFile = getPluginFile(); // /plugins/XXX.jar if (pluginFile == null) { this.downloadResponse.accept(DownloadResponse.ERROR, null); + Bukkit.getLogger().info("Pluginfile is null"); return; } File updateFolder = Bukkit.getUpdateFolderFile(); if (!updateFolder.exists()) { if (!updateFolder.mkdirs()) { this.downloadResponse.accept(DownloadResponse.ERROR, null); + Bukkit.getLogger().info("Updatefolder doesn't exists, and can't be made"); return; } } final File updateFile = new File(updateFolder, pluginFile.getName()); Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> { - if (this.type == CheckType.SBDPLUGINS) { - Bukkit.getScheduler().runTask(this.plugin, () -> this.downloadResponse.accept(DownloadResponse.UNAVAILABLE, null)); - return; - } - ReadableByteChannel channel; try { //https://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java - HttpURLConnection connection = (HttpURLConnection) new URL(String.format(RESOURCE_DOWNLOAD, this.resourceID)).openConnection(); - connection.setRequestProperty("User-Agent", "Mozilla/5.0"); - if (connection.getResponseCode() != 200) { - throw new RuntimeException("Download returned status #" + connection.getResponseCode()); + int response; + InputStream stream; + if (type == CheckType.SBDPLUGINS) { + HttpURLConnection connection = (HttpURLConnection) new URL(String.format(SBDPLUGINS_DOWNLOAD, this.resourceID)).openConnection(); + + String urlParameters = "license=" + license + "&port=" + Bukkit.getPort(); + byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8); + int postDataLength = postData.length; + + connection.setRequestMethod("GET"); + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + connection.setRequestProperty("charset", "utf-8"); + connection.setRequestProperty("Content-Length", Integer.toString(postDataLength)); + connection.setRequestProperty("User-Agent", "Mozilla/5.0"); + connection.setDoOutput(true); + + DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); + wr.write(postData); + wr.close(); + + response = connection.getResponseCode(); + stream = connection.getInputStream(); + } else { + HttpsURLConnection connection = (HttpsURLConnection) new URL(String.format(SPIGOT_DOWNLOAD, this.resourceID)).openConnection(); + connection.setRequestProperty("User-Agent", "Mozilla/5.0"); + + response = connection.getResponseCode(); + stream = connection.getInputStream(); } - channel = Channels.newChannel(connection.getInputStream()); + + if (response != 200) { + BufferedReader in = new BufferedReader(new InputStreamReader(stream)); + + String inputLine; + StringBuilder responsestr = new StringBuilder(); + while ((inputLine = in.readLine()) != null) { + responsestr.append(inputLine); + } + in.close(); + + throw new RuntimeException("Download returned status #" + response, new Throwable(responsestr.toString())); + } + + channel = Channels.newChannel(stream); } catch (IOException e) { Bukkit.getScheduler().runTask(this.plugin, () -> this.downloadResponse.accept(DownloadResponse.ERROR, null)); + e.printStackTrace(); return; } + + FileChannel fileChannel = null; try { - FileOutputStream output = new FileOutputStream(updateFile); - output.getChannel().transferFrom(channel, 0, Long.MAX_VALUE); - output.flush(); - output.close(); + FileOutputStream fosForDownloadedFile = new FileOutputStream(updateFile); + fileChannel = fosForDownloadedFile.getChannel(); + + fileChannel.transferFrom(channel, 0, Long.MAX_VALUE); } catch (IOException e) { Bukkit.getScheduler().runTask(this.plugin, () -> this.downloadResponse.accept(DownloadResponse.ERROR, null)); + e.printStackTrace(); return; + } finally { + if (channel != null) { + try { + channel.close(); + } catch (IOException ioe) { + System.out.println("Error while closing response body channel"); + } + } + + if (fileChannel != null) { + try { + fileChannel.close(); + } catch (IOException ioe) { + System.out.println("Error while closing file channel for downloaded file"); + } + } } Bukkit.getScheduler().runTask(this.plugin, () -> this.downloadResponse.accept(DownloadResponse.DONE, updateFile.getPath())); }); } - @Nullable private File getPluginFile() { if (!(this.plugin instanceof JavaPlugin)) { return null; } try { @@ -186,27 +259,30 @@ public class UpdateManager { } } - public enum CheckType { + private enum CheckType { SPIGOT, SBDPLUGINS } public enum VersionResponse { - LATEST, FOUND_NEW, UNAVAILABLE + LATEST, //Latest version + FOUND_NEW, //Newer available + THIS_NEWER, //Local version is newer? + UNAVAILABLE //Error } public enum DownloadResponse { DONE, ERROR, UNAVAILABLE } - public static class Version implements Comparable { + public static class Version { - private String version; + private final String version; public final String get() { return this.version; } - public Version(String version) { + private Version(String version) { if(version == null) throw new IllegalArgumentException("Version can not be null"); if(!version.matches("[0-9]+(\\.[0-9]+)*")) @@ -214,8 +290,7 @@ public class UpdateManager { this.version = version; } - @Override - public int compareTo(@Nonnull Version that) { + private VersionResponse check(Version that) { String[] thisParts = this.get().split("\\."); String[] thatParts = that.get().split("\\."); @@ -224,19 +299,11 @@ public class UpdateManager { int thisPart = i < thisParts.length ? Integer.parseInt(thisParts[i]) : 0; int thatPart = i < thatParts.length ? Integer.parseInt(thatParts[i]) : 0; if(thisPart < thatPart) - return -1; + return VersionResponse.FOUND_NEW; if(thisPart > thatPart) - return 1; + return VersionResponse.THIS_NEWER; } - return 0; - } - - @Override - public boolean equals(Object that) { - if (this == that) return true; - if (that == null) return false; - if (this.getClass() != that.getClass()) return false; - return this.compareTo((UpdateManager.Version) that) == 0; + return VersionResponse.LATEST; } } } \ No newline at end of file diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/YamlFile.java b/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/YamlFile.java index 9b008e1..927b880 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/YamlFile.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/sbutils/YamlFile.java @@ -13,11 +13,9 @@ import java.nio.charset.StandardCharsets; import java.util.Objects; public class YamlFile { - //SBYamlFile file = new SBYamlFile(this, "data"); - + private final String name; private FileConfiguration fileConfiguration; private File file; - private String name; public YamlFile(String name) { this.name = name; @@ -53,6 +51,10 @@ public class YamlFile { saveFile(); } + public File getJavaFile() { + return this.file; + } + public FileConfiguration getFile() { return this.fileConfiguration; } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/utils/XMaterial.java b/src/main/lombok/nl/SBDeveloper/V10Lift/utils/XMaterial.java deleted file mode 100644 index 381312a..0000000 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/utils/XMaterial.java +++ /dev/null @@ -1,2130 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Hex_27 - * Copyright (c) 2020 Crypto Morin - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package nl.SBDeveloper.V10Lift.utils; - -import com.google.common.base.Enums; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.Validate; -import org.apache.commons.lang.WordUtils; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -/** - * XMaterial - Data Values/Pre-flattening
- * 1.13 and above as priority. - *

- * This class is mainly designed to support ItemStacks. If you want to use it on blocks, you'll have to use - * XBlock - *

- * Pre-flattening: https://minecraft.gamepedia.com/Java_Edition_data_values/Pre-flattening - * Materials: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html - * Materials (1.12): https://helpch.at/docs/1.12.2/index.html?org/bukkit/Material.html - * Material IDs: https://minecraft-ids.grahamedgecombe.com/ - * Material Source Code: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/Material.java - * XMaterial v1: https://www.spigotmc.org/threads/329630/ - *

- * This class will throw a "unsupported material" error if someone tries to use an item with an invalid data value which can only happen in 1.12 servers and below. - * To get an invalid item, (aka Missing Texture Block) you can use the command - * /give @p minecraft:dirt 1 10 where 1 is the item amount, and 10 is the data value. The material {@link #DIRT} with a data value of {@code 10} doesn't exist. - * - * @author Crypto Morin - * @version 7.0.0 - * @see Material - * @see ItemStack - */ -public enum XMaterial { - ACACIA_BOAT("BOAT_ACACIA"), - ACACIA_BUTTON("WOOD_BUTTON"), - ACACIA_DOOR("ACACIA_DOOR", "ACACIA_DOOR_ITEM"), - ACACIA_FENCE, - ACACIA_FENCE_GATE, - ACACIA_LEAVES("LEAVES_2"), - ACACIA_LOG("LOG_2"), - ACACIA_PLANKS(4, "WOOD"), - ACACIA_PRESSURE_PLATE("WOOD_PLATE"), - ACACIA_SAPLING(4, "SAPLING"), - ACACIA_SIGN("SIGN_POST", "SIGN"), - ACACIA_SLAB(4, "WOOD_DOUBLE_STEP", "WOOD_STEP", "WOODEN_SLAB"), - ACACIA_STAIRS, - ACACIA_TRAPDOOR("TRAP_DOOR"), - ACACIA_WALL_SIGN("WALL_SIGN"), - ACACIA_WOOD("LOG_2"), - ACTIVATOR_RAIL, - /** - * https://minecraft.gamepedia.com/Air - * {@link Material#isAir()} - * - * @see #VOID_AIR - * @see #CAVE_AIR - */ - AIR, - ALLIUM(2, "RED_ROSE"), - ANCIENT_DEBRIS(16), - ANDESITE(5, "STONE"), - ANDESITE_SLAB, - ANDESITE_STAIRS, - ANDESITE_WALL, - ANVIL, - APPLE, - ARMOR_STAND, - ARROW, - ATTACHED_MELON_STEM(7, "MELON_STEM"), - ATTACHED_PUMPKIN_STEM(7, "PUMPKIN_STEM"), - AZURE_BLUET(3, "RED_ROSE"), - BAKED_POTATO, - BAMBOO(0, 14, "SUGAR_CANE", ""), - BAMBOO_SAPLING(14), - BARREL(0, 14, "CHEST", ""), - BARRIER, - BASALT(16), - BAT_SPAWN_EGG(65, "MONSTER_EGG"), - BEACON, - BEDROCK, - BEEF("RAW_BEEF"), - BEEHIVE(15), - /** - * Beetroot is a known material in pre-1.13 - * Use XBlock when comparing block types. - */ - BEETROOT("BEETROOT_BLOCK"), - BEETROOTS("BEETROOT"), - BEETROOT_SEEDS, - BEETROOT_SOUP, - BEE_NEST(15), - BEE_SPAWN_EGG(15), - BELL(14), - BIRCH_BOAT("BOAT_BIRCH"), - BIRCH_BUTTON("WOOD_BUTTON"), - BIRCH_DOOR("BIRCH_DOOR", "BIRCH_DOOR_ITEM"), - BIRCH_FENCE, - BIRCH_FENCE_GATE, - BIRCH_LEAVES(2, "LEAVES"), - BIRCH_LOG(2, "LOG"), - BIRCH_PLANKS(2, "WOOD"), - BIRCH_PRESSURE_PLATE("WOOD_PLATE"), - BIRCH_SAPLING(2, "SAPLING"), - BIRCH_SIGN("SIGN_POST", "SIGN"), - BIRCH_SLAB(2, "WOOD_DOUBLE_STEP", "WOOD_STEP", "WOODEN_SLAB"), - BIRCH_STAIRS("BIRCH_WOOD_STAIRS"), - BIRCH_TRAPDOOR("TRAP_DOOR"), - BIRCH_WALL_SIGN("WALL_SIGN"), - BIRCH_WOOD(2, "LOG"), - BLACKSTONE(16), - BLACKSTONE_SLAB(16), - BLACKSTONE_STAIRS(16), - BLACKSTONE_WALL(16), - BLACK_BANNER("STANDING_BANNER", "BANNER"), - BLACK_BED(15, "BED_BLOCK", "BED"), - BLACK_CARPET(15, "CARPET"), - BLACK_CONCRETE(15, "CONCRETE"), - BLACK_CONCRETE_POWDER(15, "CONCRETE_POWDER"), - BLACK_DYE(0, 14, "INK_SACK", "INK_SAC"), - BLACK_GLAZED_TERRACOTTA(15, 12, "HARD_CLAY", "STAINED_CLAY", "BLACK_TERRACOTTA"), - BLACK_SHULKER_BOX, - BLACK_STAINED_GLASS(15, "STAINED_GLASS"), - BLACK_STAINED_GLASS_PANE(15, "STAINED_GLASS_PANE"), - BLACK_TERRACOTTA(15, "HARD_CLAY", "STAINED_CLAY"), - BLACK_WALL_BANNER("WALL_BANNER"), - BLACK_WOOL(15, "WOOL"), - BLAST_FURNACE(0, 14, "FURNACE", ""), - BLAZE_POWDER, - BLAZE_ROD, - BLAZE_SPAWN_EGG(61, "MONSTER_EGG"), - BLUE_BANNER(4, "STANDING_BANNER", "BANNER"), - BLUE_BED(11, "BED_BLOCK", "BED"), - BLUE_CARPET(11, "CARPET"), - BLUE_CONCRETE(11, "CONCRETE"), - BLUE_CONCRETE_POWDER(11, "CONCRETE_POWDER"), - BLUE_DYE(4, "INK_SACK", "LAPIS_LAZULI"), - BLUE_GLAZED_TERRACOTTA(11, 12, "HARD_CLAY", "STAINED_CLAY", "BLUE_TERRACOTTA"), - BLUE_ICE(0, 13, "PACKED_ICE", ""), - BLUE_ORCHID(1, "RED_ROSE"), - BLUE_SHULKER_BOX, - BLUE_STAINED_GLASS(11, "STAINED_GLASS"), - BLUE_STAINED_GLASS_PANE(11, "THIN_GLASS", "STAINED_GLASS_PANE"), - BLUE_TERRACOTTA(11, "HARD_CLAY", "STAINED_CLAY"), - BLUE_WALL_BANNER(4, "WALL_BANNER"), - BLUE_WOOL(11, "WOOL"), - BONE, - BONE_BLOCK, - BONE_MEAL(15, "INK_SACK"), - BOOK, - BOOKSHELF, - BOW, - BOWL, - BRAIN_CORAL(13), - BRAIN_CORAL_BLOCK(13), - BRAIN_CORAL_FAN(13), - BRAIN_CORAL_WALL_FAN, - BREAD, - BREWING_STAND("BREWING_STAND", "BREWING_STAND_ITEM"), - BRICK("CLAY_BRICK"), - BRICKS("BRICK"), - BRICK_SLAB(4, "STEP"), - BRICK_STAIRS, - BRICK_WALL, - BROWN_BANNER(3, "STANDING_BANNER", "BANNER"), - BROWN_BED(12, "BED_BLOCK", "BED"), - BROWN_CARPET(12, "CARPET"), - BROWN_CONCRETE(12, "CONCRETE"), - BROWN_CONCRETE_POWDER(12, "CONCRETE_POWDER"), - BROWN_DYE(3, "INK_SACK", "DYE", "COCOA_BEANS"), - BROWN_GLAZED_TERRACOTTA(12, 12, "HARD_CLAY", "STAINED_CLAY", "BROWN_TERRACOTTA"), - BROWN_MUSHROOM, - BROWN_MUSHROOM_BLOCK("BROWN_MUSHROOM", "HUGE_MUSHROOM_1"), - BROWN_SHULKER_BOX, - BROWN_STAINED_GLASS(12, "STAINED_GLASS"), - BROWN_STAINED_GLASS_PANE(12, "THIN_GLASS", "STAINED_GLASS_PANE"), - BROWN_TERRACOTTA(12, "STAINED_CLAY"), - BROWN_WALL_BANNER(3, "WALL_BANNER"), - BROWN_WOOL(12, "WOOL"), - BUBBLE_COLUMN(13), - BUBBLE_CORAL(13), - BUBBLE_CORAL_BLOCK(13), - BUBBLE_CORAL_FAN(13), - BUBBLE_CORAL_WALL_FAN, - BUCKET, - CACTUS, - CAKE("CAKE_BLOCK"), - CAMPFIRE(14), - CARROT("CARROT_ITEM"), - CARROTS("CARROT"), - CARROT_ON_A_STICK("CARROT_STICK"), - CARTOGRAPHY_TABLE(0, 14, "CRAFTING_TABLE", ""), - CARVED_PUMPKIN(1, 13, "PUMPKIN", ""), - CAT_SPAWN_EGG, - CAULDRON("CAULDRON", "CAULDRON_ITEM"), - /** - * 1.13 tag is not added because it's the same thing as {@link #AIR} - * - * @see #VOID_AIR - */ - CAVE_AIR("AIR"), - CAVE_SPIDER_SPAWN_EGG(59, "MONSTER_EGG"), - CHAIN(16), - CHAINMAIL_BOOTS, - CHAINMAIL_CHESTPLATE, - CHAINMAIL_HELMET, - CHAINMAIL_LEGGINGS, - CHAIN_COMMAND_BLOCK("COMMAND", "COMMAND_CHAIN"), - CHARCOAL(1, "COAL"), - CHEST("LOCKED_CHEST"), - CHEST_MINECART("STORAGE_MINECART"), - CHICKEN("RAW_CHICKEN"), - CHICKEN_SPAWN_EGG(93, "MONSTER_EGG"), - CHIPPED_ANVIL(1, "ANVIL"), - CHISELED_NETHER_BRICKS(1, "NETHER_BRICKS"), - CHISELED_POLISHED_BLACKSTONE(0, 16, "POLISHED_BLACKSTONE"), - CHISELED_QUARTZ_BLOCK(1, "QUARTZ_BLOCK"), - CHISELED_RED_SANDSTONE(1, "RED_SANDSTONE"), - CHISELED_SANDSTONE(1, "SANDSTONE"), - CHISELED_STONE_BRICKS(3, "SMOOTH_BRICK"), - CHORUS_FLOWER(0, 9), - CHORUS_FRUIT(0, 9), - CHORUS_PLANT(0, 9), - CLAY, - CLAY_BALL, - CLOCK("WATCH"), - COAL, - COAL_BLOCK, - COAL_ORE, - COARSE_DIRT(1, "DIRT"), - COBBLESTONE, - COBBLESTONE_SLAB(3, "STEP"), - COBBLESTONE_STAIRS, - COBBLESTONE_WALL("COBBLE_WALL"), - COBWEB("WEB"), - COCOA(15), - COCOA_BEANS(3, "INK_SACK"), - COD("RAW_FISH"), - COD_BUCKET(0, 13, "BUCKET", "WATER_BUCKET", ""), - COD_SPAWN_EGG(0, 13, "MONSTER_EGG", ""), - COMMAND_BLOCK("COMMAND"), - COMMAND_BLOCK_MINECART("COMMAND_MINECART"), - /** - * Unlike redstone torch and redstone lamp... neither REDTONE_COMPARATOR_OFF nor REDSTONE_COMPARATOR_ON - * are items. REDSTONE_COMPARATOR is. - * - * @see #REDSTONE_TORCH - * @see #REDSTONE_LAMP - */ - COMPARATOR("REDSTONE_COMPARATOR_OFF", "REDSTONE_COMPARATOR_ON", "REDSTONE_COMPARATOR"), - COMPASS, - COMPOSTER(0, 14, "CAULDRON", ""), - CONDUIT(0, 13, "BEACON"), - COOKED_BEEF, - COOKED_CHICKEN, - COOKED_COD("COOKED_FISH"), - COOKED_MUTTON, - COOKED_PORKCHOP("PORK", "GRILLED_PORK"), - COOKED_RABBIT, - COOKED_SALMON(1, "COOKED_FISH"), - COOKIE, - CORNFLOWER(4, 14, "BLUE_DYE", ""), - COW_SPAWN_EGG(92, "MONSTER_EGG"), - CRACKED_NETHER_BRICKS(2, "NETHER_BRICKS"), - CRACKED_POLISHED_BLACKSTONE_BRICKS(0, 16, "POLISHED_BLACKSTONE_BRICKS"), - CRACKED_STONE_BRICKS(2, "SMOOTH_BRICK"), - CRAFTING_TABLE("WORKBENCH"), - CREEPER_BANNER_PATTERN, - CREEPER_HEAD(4, "SKULL", "SKULL_ITEM"), - CREEPER_SPAWN_EGG(50, "MONSTER_EGG"), - CREEPER_WALL_HEAD(4, "SKULL", "SKULL_ITEM"), - CRIMSON_BUTTON(16), - CRIMSON_DOOR(16), - CRIMSON_FENCE(16), - CRIMSON_FENCE_GATE(16), - CRIMSON_FUNGUS(16), - CRIMSON_HYPHAE(16), - CRIMSON_NYLIUM(16), - CRIMSON_PLANKS(16), - CRIMSON_PRESSURE_PLATE(16), - CRIMSON_ROOTS(16), - CRIMSON_SIGN(0, 16, "SIGN_POST"), - CRIMSON_SLAB(16), - CRIMSON_STAIRS(16), - CRIMSON_STEM(16), - CRIMSON_TRAPDOOR(16), - CRIMSON_WALL_SIGN(0, 16, "WALL_SIGN"), - CROSSBOW, - CRYING_OBSIDIAN(16), - CUT_RED_SANDSTONE(13), - CUT_RED_SANDSTONE_SLAB("STONE_SLAB2"), - CUT_SANDSTONE(13), - CUT_SANDSTONE_SLAB("STEP"), - CYAN_BANNER(6, "STANDING_BANNER", "BANNER"), - CYAN_BED(9, "BED_BLOCK", "BED"), - CYAN_CARPET(9, "CARPET"), - CYAN_CONCRETE(9, "CONCRETE"), - CYAN_CONCRETE_POWDER(9, "CONCRETE_POWDER"), - CYAN_DYE(6, "INK_SACK"), - CYAN_GLAZED_TERRACOTTA(9, 12, "HARD_CLAY", "STAINED_CLAY", "CYAN_TERRACOTTA"), - CYAN_SHULKER_BOX, - CYAN_STAINED_GLASS(9, "STAINED_GLASS"), - CYAN_STAINED_GLASS_PANE(9, "STAINED_GLASS_PANE"), - CYAN_TERRACOTTA(9, "HARD_CLAY", "STAINED_CLAY"), - CYAN_WALL_BANNER(6, "WALL_BANNER"), - CYAN_WOOL(9, "WOOL"), - DAMAGED_ANVIL(2, "ANVIL"), - DANDELION("YELLOW_FLOWER"), - DARK_OAK_BOAT("BOAT_DARK_OAK"), - DARK_OAK_BUTTON("WOOD_BUTTON"), - DARK_OAK_DOOR("DARK_OAK_DOOR", "DARK_OAK_DOOR_ITEM"), - DARK_OAK_FENCE, - DARK_OAK_FENCE_GATE, - DARK_OAK_LEAVES(4, "LEAVES", "LEAVES_2"), - DARK_OAK_LOG(1, "LOG", "LOG_2"), - DARK_OAK_PLANKS(5, "WOOD"), - DARK_OAK_PRESSURE_PLATE("WOOD_PLATE"), - DARK_OAK_SAPLING(5, "SAPLING"), - DARK_OAK_SIGN("SIGN_POST", "SIGN"), - DARK_OAK_SLAB(5, "WOOD_DOUBLE_STEP", "WOOD_STEP", "WOODEN_SLAB"), - DARK_OAK_STAIRS, - DARK_OAK_TRAPDOOR("TRAP_DOOR"), - DARK_OAK_WALL_SIGN("WALL_SIGN"), - DARK_OAK_WOOD(1, "LOG", "LOG_2"), - DARK_PRISMARINE(1, "PRISMARINE"), - DARK_PRISMARINE_SLAB(13), - DARK_PRISMARINE_STAIRS(13), - DAYLIGHT_DETECTOR("DAYLIGHT_DETECTOR_INVERTED"), - DEAD_BRAIN_CORAL(13), - DEAD_BRAIN_CORAL_BLOCK(13), - DEAD_BRAIN_CORAL_FAN(13), - DEAD_BRAIN_CORAL_WALL_FAN(13), - DEAD_BUBBLE_CORAL(13), - DEAD_BUBBLE_CORAL_BLOCK(13), - DEAD_BUBBLE_CORAL_FAN(13), - DEAD_BUBBLE_CORAL_WALL_FAN(13), - DEAD_BUSH, - DEAD_FIRE_CORAL(13), - DEAD_FIRE_CORAL_BLOCK(13), - DEAD_FIRE_CORAL_FAN(13), - DEAD_FIRE_CORAL_WALL_FAN(13), - DEAD_HORN_CORAL(13), - DEAD_HORN_CORAL_BLOCK(13), - DEAD_HORN_CORAL_FAN(13), - DEAD_HORN_CORAL_WALL_FAN(13), - DEAD_TUBE_CORAL(13), - DEAD_TUBE_CORAL_BLOCK(13), - DEAD_TUBE_CORAL_FAN(13), - DEAD_TUBE_CORAL_WALL_FAN(13), - DEBUG_STICK(0, 13, "STICK", ""), - DETECTOR_RAIL, - DIAMOND, - DIAMOND_AXE, - DIAMOND_BLOCK, - DIAMOND_BOOTS, - DIAMOND_CHESTPLATE, - DIAMOND_HELMET, - DIAMOND_HOE, - DIAMOND_HORSE_ARMOR("DIAMOND_BARDING"), - DIAMOND_LEGGINGS, - DIAMOND_ORE, - DIAMOND_PICKAXE, - DIAMOND_SHOVEL("DIAMOND_SPADE"), - DIAMOND_SWORD, - DIORITE(3, "STONE"), - DIORITE_SLAB, - DIORITE_STAIRS, - DIORITE_WALL, - DIRT, - DISPENSER, - DOLPHIN_SPAWN_EGG(0, 13, "MONSTER_EGG", ""), - DONKEY_SPAWN_EGG(32, "MONSTER_EGG"), - DRAGON_BREATH("DRAGONS_BREATH"), - DRAGON_EGG, - DRAGON_HEAD(5, 9, "SKULL", "SKULL_ITEM"), - DRAGON_WALL_HEAD(5, "SKULL", "SKULL_ITEM"), - DRIED_KELP(13), - DRIED_KELP_BLOCK(13), - DROPPER, - DROWNED_SPAWN_EGG(0, 13, "MONSTER_EGG", ""), - EGG, - ELDER_GUARDIAN_SPAWN_EGG(4, "MONSTER_EGG"), - ELYTRA, - EMERALD, - EMERALD_BLOCK, - EMERALD_ORE, - ENCHANTED_BOOK, - ENCHANTED_GOLDEN_APPLE(1, "GOLDEN_APPLE"), - ENCHANTING_TABLE("ENCHANTMENT_TABLE"), - ENDERMAN_SPAWN_EGG(58, "MONSTER_EGG"), - ENDERMITE_SPAWN_EGG(67, "MONSTER_EGG"), - ENDER_CHEST, - ENDER_EYE("EYE_OF_ENDER"), - ENDER_PEARL, - END_CRYSTAL, - END_GATEWAY(0, 9), - END_PORTAL("ENDER_PORTAL"), - END_PORTAL_FRAME("ENDER_PORTAL_FRAME"), - END_ROD(0, 9, "BLAZE_ROD", ""), - END_STONE("ENDER_STONE"), - END_STONE_BRICKS("END_BRICKS"), - END_STONE_BRICK_SLAB(6, "STEP"), - END_STONE_BRICK_STAIRS("SMOOTH_STAIRS"), - END_STONE_BRICK_WALL, - EVOKER_SPAWN_EGG(34, "MONSTER_EGG"), - EXPERIENCE_BOTTLE("EXP_BOTTLE"), - FARMLAND("SOIL"), - FEATHER, - FERMENTED_SPIDER_EYE, - FERN(2, "LONG_GRASS"), - /** - * For some reasons filled map items are really special. - * Their data value starts from 0 and every time a player - * creates a new map that maps data value increases. - */ - FILLED_MAP("MAP"), - FIRE, - FIREWORK_ROCKET("FIREWORK"), - FIREWORK_STAR("FIREWORK_CHARGE"), - FIRE_CHARGE("FIREBALL"), - FIRE_CORAL(13), - FIRE_CORAL_BLOCK(13), - FIRE_CORAL_FAN(13), - FIRE_CORAL_WALL_FAN, - FISHING_ROD, - FLETCHING_TABLE(0, 14, "CRAFTING_TABLE", ""), - FLINT, - FLINT_AND_STEEL, - FLOWER_BANNER_PATTERN, - FLOWER_POT("FLOWER_POT", "FLOWER_POT_ITEM"), - FOX_SPAWN_EGG(14), - /** - * This special material cannot be obtained as an item. - */ - FROSTED_ICE(0, 9, "PACKED_ICE", ""), - FURNACE("BURNING_FURNACE"), - FURNACE_MINECART("POWERED_MINECART"), - GHAST_SPAWN_EGG(56, "MONSTER_EGG"), - GHAST_TEAR, - GILDED_BLACKSTONE(16), - GLASS, - GLASS_BOTTLE, - GLASS_PANE("THIN_GLASS"), - GLISTERING_MELON_SLICE("SPECKLED_MELON"), - GLOBE_BANNER_PATTERN, - GLOWSTONE, - GLOWSTONE_DUST, - GOLDEN_APPLE, - GOLDEN_AXE("GOLD_AXE"), - GOLDEN_BOOTS("GOLD_BOOTS"), - GOLDEN_CARROT, - GOLDEN_CHESTPLATE("GOLD_CHESTPLATE"), - GOLDEN_HELMET("GOLD_HELMET"), - GOLDEN_HOE("GOLD_HOE"), - GOLDEN_HORSE_ARMOR("GOLD_BARDING"), - GOLDEN_LEGGINGS("GOLD_LEGGINGS"), - GOLDEN_PICKAXE("GOLD_PICKAXE"), - GOLDEN_SHOVEL("GOLD_SPADE"), - GOLDEN_SWORD("GOLD_SWORD"), - GOLD_BLOCK, - GOLD_INGOT, - GOLD_NUGGET, - GOLD_ORE, - GRANITE(1, "STONE"), - GRANITE_SLAB, - GRANITE_STAIRS, - GRANITE_WALL, - GRASS(1, "LONG_GRASS"), - GRASS_BLOCK("GRASS"), - GRASS_PATH, - GRAVEL, - GRAY_BANNER(8, "STANDING_BANNER", "BANNER"), - GRAY_BED(7, "BED_BLOCK", "BED"), - GRAY_CARPET(7, "CARPET"), - GRAY_CONCRETE(7, "CONCRETE"), - GRAY_CONCRETE_POWDER(7, "CONCRETE_POWDER"), - GRAY_DYE(8, "INK_SACK"), - GRAY_GLAZED_TERRACOTTA(7, 12, "HARD_CLAY", "STAINED_CLAY", "GRAY_TERRACOTTA"), - GRAY_SHULKER_BOX, - GRAY_STAINED_GLASS(7, "STAINED_GLASS"), - GRAY_STAINED_GLASS_PANE(7, "THIN_GLASS", "STAINED_GLASS_PANE"), - GRAY_TERRACOTTA(7, "HARD_CLAY", "STAINED_CLAY"), - GRAY_WALL_BANNER(8, "WALL_BANNER"), - GRAY_WOOL(7, "WOOL"), - GREEN_BANNER(2, "STANDING_BANNER", "BANNER"), - GREEN_BED(13, "BED_BLOCK", "BED"), - GREEN_CARPET(13, "CARPET"), - GREEN_CONCRETE(13, "CONCRETE"), - GREEN_CONCRETE_POWDER(13, "CONCRETE_POWDER"), - GREEN_DYE(2, "INK_SACK", "CACTUS_GREEN"), - GREEN_GLAZED_TERRACOTTA(13, 12, "HARD_CLAY", "STAINED_CLAY", "GREEN_TERRACOTTA"), - GREEN_SHULKER_BOX, - GREEN_STAINED_GLASS(13, "STAINED_GLASS"), - GREEN_STAINED_GLASS_PANE(13, "THIN_GLASS", "STAINED_GLASS_PANE"), - GREEN_TERRACOTTA(13, "HARD_CLAY", "STAINED_CLAY"), - GREEN_WALL_BANNER(2, "WALL_BANNER"), - GREEN_WOOL(13, "WOOL"), - GRINDSTONE(0, 14, "ANVIL", ""), - GUARDIAN_SPAWN_EGG(68, "MONSTER_EGG"), - GUNPOWDER("SULPHUR"), - HAY_BLOCK, - HEART_OF_THE_SEA(13), - HEAVY_WEIGHTED_PRESSURE_PLATE("IRON_PLATE"), - HOGLIN_SPAWN_EGG(0, 16, "MONSTER_EGG"), - HONEYCOMB(15), - HONEYCOMB_BLOCK(15), - HONEY_BLOCK(0, 15, "SLIME_BLOCK", ""), - HONEY_BOTTLE(0, 15, "GLASS_BOTTLE", ""), - HOPPER, - HOPPER_MINECART, - HORN_CORAL(13), - HORN_CORAL_BLOCK(13), - HORN_CORAL_FAN(13), - HORN_CORAL_WALL_FAN, - HORSE_SPAWN_EGG(100, "MONSTER_EGG"), - HUSK_SPAWN_EGG(23, "MONSTER_EGG"), - ICE, - INFESTED_CHISELED_STONE_BRICKS(5, "MONSTER_EGGS", "SMOOTH_BRICK"), - INFESTED_COBBLESTONE(1, "MONSTER_EGGS"), - INFESTED_CRACKED_STONE_BRICKS(4, "MONSTER_EGGS", "SMOOTH_BRICK"), - INFESTED_MOSSY_STONE_BRICKS(3, "MONSTER_EGGS"), - INFESTED_STONE("MONSTER_EGGS"), - INFESTED_STONE_BRICKS(2, "MONSTER_EGGS", "SMOOTH_BRICK"), - /** - * We will only add "INK_SAC" for {@link #BLACK_DYE} since it's - * the only material (linked with this material) that is added - * after 1.13, which means it can use both INK_SACK and INK_SAC. - */ - INK_SAC("INK_SACK"), - IRON_AXE, - IRON_BARS("IRON_FENCE"), - IRON_BLOCK, - IRON_BOOTS, - IRON_CHESTPLATE, - IRON_DOOR("IRON_DOOR_BLOCK"), - IRON_HELMET, - IRON_HOE, - IRON_HORSE_ARMOR("IRON_BARDING"), - IRON_INGOT, - IRON_LEGGINGS, - IRON_NUGGET, - IRON_ORE, - IRON_PICKAXE, - IRON_SHOVEL("IRON_SPADE"), - IRON_SWORD, - IRON_TRAPDOOR, - ITEM_FRAME, - JACK_O_LANTERN, - JIGSAW(0, 14, "COMMAND_BLOCK", "STRUCTURE_BLOCK", ""), - JUKEBOX, - JUNGLE_BOAT("BOAT_JUNGLE"), - JUNGLE_BUTTON("WOOD_BUTTON"), - JUNGLE_DOOR("JUNGLE_DOOR", "JUNGLE_DOOR_ITEM"), - JUNGLE_FENCE, - JUNGLE_FENCE_GATE, - JUNGLE_LEAVES(3, "LEAVES"), - JUNGLE_LOG(3, "LOG"), - JUNGLE_PLANKS(3, "WOOD"), - JUNGLE_PRESSURE_PLATE("WOOD_PLATE"), - JUNGLE_SAPLING(3, "SAPLING"), - JUNGLE_SIGN("SIGN_POST", "SIGN"), - JUNGLE_SLAB(3, "WOOD_DOUBLE_STEP", "WOOD_STEP", "WOODEN_SLAB"), - JUNGLE_STAIRS("JUNGLE_WOOD_STAIRS"), - JUNGLE_TRAPDOOR("TRAP_DOOR"), - JUNGLE_WALL_SIGN("WALL_SIGN"), - JUNGLE_WOOD(3, "LOG"), - KELP(13), - KELP_PLANT(13), - KNOWLEDGE_BOOK(0, 12, "BOOK"), - LADDER, - LANTERN(0, 14, "SEA_LANTERN", ""), - LAPIS_BLOCK, - LAPIS_LAZULI(4, "INK_SACK"), - LAPIS_ORE, - LARGE_FERN(3, "DOUBLE_PLANT"), - LAVA("STATIONARY_LAVA"), - LAVA_BUCKET, - LEAD("LEASH"), - LEATHER, - LEATHER_BOOTS, - LEATHER_CHESTPLATE, - LEATHER_HELMET, - LEATHER_HORSE_ARMOR(0, 14, "IRON_HORSE_ARMOR", ""), - LEATHER_LEGGINGS, - LECTERN(0, 14, "BOOKSHELF", ""), - LEVER, - LIGHT_BLUE_BANNER(12, "STANDING_BANNER", "BANNER"), - LIGHT_BLUE_BED(3, "BED_BLOCK", "BED"), - LIGHT_BLUE_CARPET(3, "CARPET"), - LIGHT_BLUE_CONCRETE(3, "CONCRETE"), - LIGHT_BLUE_CONCRETE_POWDER(3, "CONCRETE_POWDER"), - LIGHT_BLUE_DYE(12, "INK_SACK"), - LIGHT_BLUE_GLAZED_TERRACOTTA(3, 12, "HARD_CLAY", "STAINED_CLAY", "LIGHT_BLUE_TERRACOTTA"), - LIGHT_BLUE_SHULKER_BOX, - LIGHT_BLUE_STAINED_GLASS(3, "STAINED_GLASS"), - LIGHT_BLUE_STAINED_GLASS_PANE(3, "THIN_GLASS", "STAINED_GLASS_PANE"), - LIGHT_BLUE_TERRACOTTA(3, "STAINED_CLAY"), - LIGHT_BLUE_WALL_BANNER(12, "WALL_BANNER", "STANDING_BANNER", "BANNER"), - LIGHT_BLUE_WOOL(3, "WOOL"), - LIGHT_GRAY_BANNER(7, "STANDING_BANNER", "BANNER"), - LIGHT_GRAY_BED(8, "BED_BLOCK", "BED"), - LIGHT_GRAY_CARPET(8, "CARPET"), - LIGHT_GRAY_CONCRETE(8, "CONCRETE"), - LIGHT_GRAY_CONCRETE_POWDER(8, "CONCRETE_POWDER"), - LIGHT_GRAY_DYE(7, "INK_SACK"), - /** - * Renamed to SILVER_GLAZED_TERRACOTTA in 1.12 - * Renamed to LIGHT_GRAY_GLAZED_TERRACOTTA in 1.14 - */ - LIGHT_GRAY_GLAZED_TERRACOTTA(0, 12, "HARD_CLAY", "STAINED_CLAY", "LIGHT_GRAY_TERRACOTTA", "SILVER_GLAZED_TERRACOTTA"), - LIGHT_GRAY_SHULKER_BOX("SILVER_SHULKER_BOX"), - LIGHT_GRAY_STAINED_GLASS(8, "STAINED_GLASS"), - LIGHT_GRAY_STAINED_GLASS_PANE(8, "THIN_GLASS", "STAINED_GLASS_PANE"), - LIGHT_GRAY_TERRACOTTA(8, "HARD_CLAY", "STAINED_CLAY"), - LIGHT_GRAY_WALL_BANNER(7, "WALL_BANNER"), - LIGHT_GRAY_WOOL(8, "WOOL"), - LIGHT_WEIGHTED_PRESSURE_PLATE("GOLD_PLATE"), - LILAC(1, "DOUBLE_PLANT"), - LILY_OF_THE_VALLEY(15, 14, "WHITE_DYE", ""), - LILY_PAD("WATER_LILY"), - LIME_BANNER(10, "STANDING_BANNER", "BANNER"), - LIME_BED(5, "BED_BLOCK", "BED"), - LIME_CARPET(5, "CARPET"), - LIME_CONCRETE(5, "CONCRETE"), - LIME_CONCRETE_POWDER(5, "CONCRETE_POWDER"), - LIME_DYE(10, "INK_SACK"), - LIME_GLAZED_TERRACOTTA(5, 12, "HARD_CLAY", "STAINED_CLAY", "LIME_TERRACOTTA"), - LIME_SHULKER_BOX, - LIME_STAINED_GLASS(5, "STAINED_GLASS"), - LIME_STAINED_GLASS_PANE(5, "STAINED_GLASS_PANE"), - LIME_TERRACOTTA(5, "HARD_CLAY", "STAINED_CLAY"), - LIME_WALL_BANNER(10, "WALL_BANNER"), - LIME_WOOL(5, "WOOL"), - LINGERING_POTION, - LLAMA_SPAWN_EGG(103, "MONSTER_EGG"), - LODESTONE(16), - LOOM(14), - MAGENTA_BANNER(13, "STANDING_BANNER", "BANNER"), - MAGENTA_BED(2, "BED_BLOCK", "BED"), - MAGENTA_CARPET(2, "CARPET"), - MAGENTA_CONCRETE(2, "CONCRETE"), - MAGENTA_CONCRETE_POWDER(2, "CONCRETE_POWDER"), - MAGENTA_DYE(13, "INK_SACK"), - MAGENTA_GLAZED_TERRACOTTA(2, 12, "HARD_CLAY", "STAINED_CLAY", "MAGENTA_TERRACOTTA"), - MAGENTA_SHULKER_BOX, - MAGENTA_STAINED_GLASS(2, "STAINED_GLASS"), - MAGENTA_STAINED_GLASS_PANE(2, "THIN_GLASS", "STAINED_GLASS_PANE"), - MAGENTA_TERRACOTTA(2, "HARD_CLAY", "STAINED_CLAY"), - MAGENTA_WALL_BANNER(13, "WALL_BANNER"), - MAGENTA_WOOL(2, "WOOL"), - MAGMA_BLOCK(0, 10, "MAGMA"), - MAGMA_CREAM, - MAGMA_CUBE_SPAWN_EGG(62, "MONSTER_EGG"), - /** - * Adding this to the duplicated list will give you a filled map - * for 1.13+ versions and removing it from duplicated list will - * still give you a filled map in -1.12 versions. - * Since higher versions are our priority I'll keep 1.13+ support - * until I can come up with something to fix it. - */ - MAP("EMPTY_MAP"), - MELON("MELON_BLOCK"), - MELON_SEEDS, - MELON_SLICE("MELON"), - MELON_STEM, - MILK_BUCKET, - MINECART, - MOJANG_BANNER_PATTERN, - MOOSHROOM_SPAWN_EGG(96, "MONSTER_EGG"), - MOSSY_COBBLESTONE, - MOSSY_COBBLESTONE_SLAB(3, "STEP"), - MOSSY_COBBLESTONE_STAIRS, - MOSSY_COBBLESTONE_WALL(1, "COBBLE_WALL", "COBBLESTONE_WALL"), - MOSSY_STONE_BRICKS(1, "SMOOTH_BRICK"), - MOSSY_STONE_BRICK_SLAB(5, "STEP"), - MOSSY_STONE_BRICK_STAIRS("SMOOTH_STAIRS"), - MOSSY_STONE_BRICK_WALL, - MOVING_PISTON("PISTON_BASE", "PISTON_MOVING_PIECE"), - MULE_SPAWN_EGG(32, "MONSTER_EGG"), - MUSHROOM_STEM("BROWN_MUSHROOM"), - MUSHROOM_STEW("MUSHROOM_SOUP"), - MUSIC_DISC_11("GOLD_RECORD"), - MUSIC_DISC_13("GREEN_RECORD"), - MUSIC_DISC_BLOCKS("RECORD_3"), - MUSIC_DISC_CAT("RECORD_4"), - MUSIC_DISC_CHIRP("RECORD_5"), - MUSIC_DISC_FAR("RECORD_6"), - MUSIC_DISC_MALL("RECORD_7"), - MUSIC_DISC_MELLOHI("RECORD_8"), - MUSIC_DISC_PIGSTEP(16), - MUSIC_DISC_STAL("RECORD_9"), - MUSIC_DISC_STRAD("RECORD_10"), - MUSIC_DISC_WAIT("RECORD_11"), - MUSIC_DISC_WARD("RECORD_12"), - MUTTON, - MYCELIUM("MYCEL"), - NAME_TAG, - NAUTILUS_SHELL(13), - NETHERITE_AXE(16), - NETHERITE_BLOCK(16), - NETHERITE_BOOTS(16), - NETHERITE_CHESTPLATE(16), - NETHERITE_HELMET(16), - NETHERITE_HOE(16), - NETHERITE_INGOT(16), - NETHERITE_LEGGINGS(16), - NETHERITE_PICKAXE(16), - NETHERITE_SCRAP(16), - NETHERITE_SHOVEL(16), - NETHERITE_SWORD(16), - NETHERRACK, - NETHER_BRICK("NETHER_BRICK_ITEM"), - NETHER_BRICKS("NETHER_BRICK"), - NETHER_BRICK_FENCE("NETHER_FENCE"), - NETHER_BRICK_SLAB(6, "STEP"), - NETHER_BRICK_STAIRS, - NETHER_BRICK_WALL, - NETHER_GOLD_ORE(16), - NETHER_PORTAL("PORTAL"), - NETHER_QUARTZ_ORE("QUARTZ_ORE"), - NETHER_SPROUTS(16), - NETHER_STAR, - /** - * Just like mentioned in https://minecraft.gamepedia.com/Nether_Wart - * Nether wart is also known as nether stalk in the code. - * NETHER_STALK is the planted state of nether warts. - */ - NETHER_WART("NETHER_WARTS", "NETHER_STALK"), - NETHER_WART_BLOCK, - NOTE_BLOCK, - OAK_BOAT("BOAT"), - OAK_BUTTON("WOOD_BUTTON"), - OAK_DOOR("WOODEN_DOOR", "WOOD_DOOR"), - OAK_FENCE("FENCE"), - OAK_FENCE_GATE("FENCE_GATE"), - OAK_LEAVES("LEAVES"), - OAK_LOG("LOG"), - OAK_PLANKS("WOOD"), - OAK_PRESSURE_PLATE("WOOD_PLATE"), - OAK_SAPLING("SAPLING"), - OAK_SIGN("SIGN_POST", "SIGN"), - OAK_SLAB("WOOD_DOUBLE_STEP", "WOOD_STEP", "WOODEN_SLAB"), - OAK_STAIRS("WOOD_STAIRS"), - OAK_TRAPDOOR("TRAP_DOOR"), - OAK_WALL_SIGN("WALL_SIGN"), - OAK_WOOD("LOG"), - OBSERVER, - OBSIDIAN, - OCELOT_SPAWN_EGG(98, "MONSTER_EGG"), - ORANGE_BANNER(14, "STANDING_BANNER", "BANNER"), - ORANGE_BED(1, "BED_BLOCK", "BED"), - ORANGE_CARPET(1, "CARPET"), - ORANGE_CONCRETE(1, "CONCRETE"), - ORANGE_CONCRETE_POWDER(1, "CONCRETE_POWDER"), - ORANGE_DYE(14, "INK_SACK"), - ORANGE_GLAZED_TERRACOTTA(1, 12, "HARD_CLAY", "STAINED_CLAY", "ORANGE_TERRACOTTA"), - ORANGE_SHULKER_BOX, - ORANGE_STAINED_GLASS(1, "STAINED_GLASS"), - ORANGE_STAINED_GLASS_PANE(1, "STAINED_GLASS_PANE"), - ORANGE_TERRACOTTA(1, "HARD_CLAY", "STAINED_CLAY"), - ORANGE_TULIP(5, "RED_ROSE"), - ORANGE_WALL_BANNER(14, "WALL_BANNER"), - ORANGE_WOOL(1, "WOOL"), - OXEYE_DAISY(8, "RED_ROSE"), - PACKED_ICE, - PAINTING, - PANDA_SPAWN_EGG(14), - PAPER, - PARROT_SPAWN_EGG(105, "MONSTER_EGG"), - PEONY(5, "DOUBLE_PLANT"), - PETRIFIED_OAK_SLAB("WOOD_STEP"), - PHANTOM_MEMBRANE(13), - PHANTOM_SPAWN_EGG(0, 13, "MONSTER_EGG", ""), - PIGLIN_BANNER_PATTERN(16), - PIGLIN_BRUTE_SPAWN_EGG(16), - PIGLIN_SPAWN_EGG(57, "MONSTER_EGG"), - PIG_SPAWN_EGG(90, "MONSTER_EGG"), - PILLAGER_SPAWN_EGG(14), - PINK_BANNER(9, "STANDING_BANNER", "BANNER"), - PINK_BED(6, "BED_BLOCK", "BED"), - PINK_CARPET(6, "CARPET"), - PINK_CONCRETE(6, "CONCRETE"), - PINK_CONCRETE_POWDER(6, "CONCRETE_POWDER"), - PINK_DYE(9, "INK_SACK"), - PINK_GLAZED_TERRACOTTA(6, 12, "HARD_CLAY", "STAINED_CLAY", "PINK_TERRACOTTA"), - PINK_SHULKER_BOX, - PINK_STAINED_GLASS(6, "STAINED_GLASS"), - PINK_STAINED_GLASS_PANE(6, "THIN_GLASS", "STAINED_GLASS_PANE"), - PINK_TERRACOTTA(6, "HARD_CLAY", "STAINED_CLAY"), - PINK_TULIP(7, "RED_ROSE"), - PINK_WALL_BANNER(9, "WALL_BANNER"), - PINK_WOOL(6, "WOOL"), - PISTON("PISTON_BASE"), - PISTON_HEAD("PISTON_EXTENSION"), - PLAYER_HEAD(3, "SKULL", "SKULL_ITEM"), - PLAYER_WALL_HEAD(3, "SKULL", "SKULL_ITEM"), - PODZOL(2, "DIRT"), - POISONOUS_POTATO, - POLAR_BEAR_SPAWN_EGG(102, "MONSTER_EGG"), - POLISHED_ANDESITE(6, "STONE"), - POLISHED_ANDESITE_SLAB, - POLISHED_ANDESITE_STAIRS, - POLISHED_BASALT(16), - POLISHED_BLACKSTONE(16), - POLISHED_BLACKSTONE_BRICKS(16), - POLISHED_BLACKSTONE_BRICK_SLAB(16), - POLISHED_BLACKSTONE_BRICK_STAIRS(16), - POLISHED_BLACKSTONE_BRICK_WALL(16), - POLISHED_BLACKSTONE_BUTTON(16), - POLISHED_BLACKSTONE_PRESSURE_PLATE(16), - POLISHED_BLACKSTONE_SLAB(16), - POLISHED_BLACKSTONE_STAIRS(16), - POLISHED_BLACKSTONE_WALL(16), - POLISHED_DIORITE(4, "STONE"), - POLISHED_DIORITE_SLAB, - POLISHED_DIORITE_STAIRS, - POLISHED_GRANITE(2, "STONE"), - POLISHED_GRANITE_SLAB, - POLISHED_GRANITE_STAIRS, - POPPED_CHORUS_FRUIT("CHORUS_FRUIT_POPPED"), - POPPY("RED_ROSE"), - PORKCHOP("PORK"), - POTATO("POTATO_ITEM"), - POTATOES("POTATO"), - POTION, - POTTED_ACACIA_SAPLING(4, "SAPLING", "FLOWER_POT"), - POTTED_ALLIUM(2, "RED_ROSE", "FLOWER_POT"), - POTTED_AZURE_BLUET(3, "RED_ROSE", "FLOWER_POT"), - POTTED_BAMBOO, - POTTED_BIRCH_SAPLING(2, "SAPLING", "FLOWER_POT"), - POTTED_BLUE_ORCHID(1, "RED_ROSE", "FLOWER_POT"), - POTTED_BROWN_MUSHROOM("FLOWER_POT"), - POTTED_CACTUS("FLOWER_POT"), - POTTED_CORNFLOWER, - POTTED_CRIMSON_FUNGUS(16), - POTTED_CRIMSON_ROOTS(16), - POTTED_DANDELION("YELLOW_FLOWER", "FLOWER_POT"), - POTTED_DARK_OAK_SAPLING(5, "SAPLING", "FLOWER_POT"), - POTTED_DEAD_BUSH("FLOWER_POT"), - POTTED_FERN(2, "LONG_GRASS", "FLOWER_POT"), - POTTED_JUNGLE_SAPLING(3, "SAPLING", "FLOWER_POT"), - POTTED_LILY_OF_THE_VALLEY, - POTTED_OAK_SAPLING("SAPLING", "FLOWER_POT"), - POTTED_ORANGE_TULIP(5, "RED_ROSE", "FLOWER_POT"), - POTTED_OXEYE_DAISY(8, "RED_ROSE", "FLOWER_POT"), - POTTED_PINK_TULIP(7, "RED_ROSE", "FLOWER_POT"), - POTTED_POPPY("RED_ROSE", "FLOWER_POT"), - POTTED_RED_MUSHROOM("FLOWER_POT"), - POTTED_RED_TULIP(4, "RED_ROSE", "FLOWER_POT"), - POTTED_SPRUCE_SAPLING(1, "SAPLING", "FLOWER_POT"), - POTTED_WARPED_FUNGUS(16), - POTTED_WARPED_ROOTS(16), - POTTED_WHITE_TULIP(6, "RED_ROSE", "FLOWER_POT"), - POTTED_WITHER_ROSE, - POWERED_RAIL, - PRISMARINE, - PRISMARINE_BRICKS(2, "PRISMARINE"), - PRISMARINE_BRICK_SLAB(4, "STEP"), - PRISMARINE_BRICK_STAIRS(13), - PRISMARINE_CRYSTALS, - PRISMARINE_SHARD, - PRISMARINE_SLAB(13), - PRISMARINE_STAIRS(13), - PRISMARINE_WALL, - PUFFERFISH(3, "RAW_FISH"), - PUFFERFISH_BUCKET(0, 13, "BUCKET", "WATER_BUCKET", ""), - PUFFERFISH_SPAWN_EGG(0, 13, "MONSTER_EGG", ""), - PUMPKIN, - PUMPKIN_PIE, - PUMPKIN_SEEDS, - PUMPKIN_STEM, - PURPLE_BANNER(5, "STANDING_BANNER", "BANNER"), - PURPLE_BED(10, "BED_BLOCK", "BED"), - PURPLE_CARPET(10, "CARPET"), - PURPLE_CONCRETE(10, "CONCRETE"), - PURPLE_CONCRETE_POWDER(10, "CONCRETE_POWDER"), - PURPLE_DYE(5, "INK_SACK"), - PURPLE_GLAZED_TERRACOTTA(10, 12, "HARD_CLAY", "STAINED_CLAY", "PURPLE_TERRACOTTA"), - PURPLE_SHULKER_BOX, - PURPLE_STAINED_GLASS(10, "STAINED_GLASS"), - PURPLE_STAINED_GLASS_PANE(10, "THIN_GLASS", "STAINED_GLASS_PANE"), - PURPLE_TERRACOTTA(10, "HARD_CLAY", "STAINED_CLAY"), - PURPLE_WALL_BANNER(5, "WALL_BANNER"), - PURPLE_WOOL(10, "WOOL"), - PURPUR_BLOCK, - PURPUR_PILLAR, - PURPUR_SLAB("PURPUR_DOUBLE_SLAB"), - PURPUR_STAIRS, - QUARTZ, - QUARTZ_BLOCK, - QUARTZ_BRICKS(16), - QUARTZ_PILLAR(2, "QUARTZ_BLOCK"), - QUARTZ_SLAB(7, "STEP"), - QUARTZ_STAIRS, - RABBIT, - RABBIT_FOOT, - RABBIT_HIDE, - RABBIT_SPAWN_EGG(101, "MONSTER_EGG"), - RABBIT_STEW, - RAIL("RAILS"), - RAVAGER_SPAWN_EGG(14), - REDSTONE, - REDSTONE_BLOCK, - /** - * Unlike redstone torch, REDSTONE_LAMP_ON isn't an item. - * The name is just here on the list for matching. - * - * @see #REDSTONE_TORCH - */ - REDSTONE_LAMP("REDSTONE_LAMP_ON", "REDSTONE_LAMP_OFF"), - REDSTONE_ORE("GLOWING_REDSTONE_ORE"), - /** - * REDSTONE_TORCH_OFF isn't an item, but a block. - * But REDSTONE_TORCH_ON is the item. - * The name is just here on the list for matching. - */ - REDSTONE_TORCH("REDSTONE_TORCH_OFF", "REDSTONE_TORCH_ON"), - REDSTONE_WALL_TORCH, - REDSTONE_WIRE, - RED_BANNER(1, "STANDING_BANNER", "BANNER"), - /** - * Data value 14 or 0 - */ - RED_BED(0, "BED_BLOCK", "BED"), - RED_CARPET(14, "CARPET"), - RED_CONCRETE(14, "CONCRETE"), - RED_CONCRETE_POWDER(14, "CONCRETE_POWDER"), - RED_DYE(1, "INK_SACK", "ROSE_RED"), - RED_GLAZED_TERRACOTTA(14, 12, "HARD_CLAY", "STAINED_CLAY", "RED_TERRACOTTA"), - RED_MUSHROOM, - RED_MUSHROOM_BLOCK("RED_MUSHROOM", "HUGE_MUSHROOM_2"), - RED_NETHER_BRICKS("RED_NETHER_BRICK"), - RED_NETHER_BRICK_SLAB(4, "STEP"), - RED_NETHER_BRICK_STAIRS, - RED_NETHER_BRICK_WALL, - RED_SAND(1, "SAND"), - RED_SANDSTONE, - RED_SANDSTONE_SLAB("DOUBLE_STONE_SLAB2", "STONE_SLAB2"), - RED_SANDSTONE_STAIRS, - RED_SANDSTONE_WALL, - RED_SHULKER_BOX, - RED_STAINED_GLASS(14, "STAINED_GLASS"), - RED_STAINED_GLASS_PANE(14, "THIN_GLASS", "STAINED_GLASS_PANE"), - RED_TERRACOTTA(14, "HARD_CLAY", "STAINED_CLAY"), - RED_TULIP(4, "RED_ROSE"), - RED_WALL_BANNER(1, "WALL_BANNER"), - RED_WOOL(14, "WOOL"), - REPEATER("DIODE_BLOCK_ON", "DIODE_BLOCK_OFF", "DIODE"), - REPEATING_COMMAND_BLOCK("COMMAND", "COMMAND_REPEATING"), - RESPAWN_ANCHOR(16), - ROSE_BUSH(4, "DOUBLE_PLANT"), - ROTTEN_FLESH, - SADDLE, - SALMON(1, "RAW_FISH"), - SALMON_BUCKET(0, 13, "BUCKET", "WATER_BUCKET", ""), - SALMON_SPAWN_EGG(0, 13, "MONSTER_EGG", ""), - SAND, - SANDSTONE, - SANDSTONE_SLAB(1, "DOUBLE_STEP", "STEP", "STONE_SLAB"), - SANDSTONE_STAIRS, - SANDSTONE_WALL, - SCAFFOLDING(0, 14, "SLIME_BLOCK", ""), - SCUTE(13), - SEAGRASS(0, 13, "GRASS", ""), - SEA_LANTERN, - SEA_PICKLE(13), - SHEARS, - SHEEP_SPAWN_EGG(91, "MONSTER_EGG"), - SHIELD, - SHROOMLIGHT(16), - SHULKER_BOX("PURPLE_SHULKER_BOX"), - SHULKER_SHELL, - SHULKER_SPAWN_EGG(69, "MONSTER_EGG"), - SILVERFISH_SPAWN_EGG(60, "MONSTER_EGG"), - SKELETON_HORSE_SPAWN_EGG(28, "MONSTER_EGG"), - SKELETON_SKULL("SKULL", "SKULL_ITEM"), - SKELETON_SPAWN_EGG(51, "MONSTER_EGG"), - SKELETON_WALL_SKULL("SKULL", "SKULL_ITEM"), - SKULL_BANNER_PATTERN, - SLIME_BALL, - SLIME_BLOCK, - SLIME_SPAWN_EGG(55, "MONSTER_EGG"), - SMITHING_TABLE, - SMOKER(0, 14, "FURNACE", ""), - SMOOTH_QUARTZ(0, 13, "QUARTZ", ""), - SMOOTH_QUARTZ_SLAB(7, "STEP"), - SMOOTH_QUARTZ_STAIRS, - SMOOTH_RED_SANDSTONE(2, "RED_SANDSTONE"), - SMOOTH_RED_SANDSTONE_SLAB("STONE_SLAB2"), - SMOOTH_RED_SANDSTONE_STAIRS, - SMOOTH_SANDSTONE(2, "SANDSTONE"), - SMOOTH_SANDSTONE_SLAB("STEP"), - SMOOTH_SANDSTONE_STAIRS, - SMOOTH_STONE("STEP"), - SMOOTH_STONE_SLAB("STEP"), - SNOW, - SNOWBALL("SNOW_BALL"), - SNOW_BLOCK, - SOUL_CAMPFIRE(16), - SOUL_FIRE(16), - SOUL_LANTERN(16), - SOUL_SAND, - SOUL_SOIL(16), - SOUL_TORCH(16), - SOUL_WALL_TORCH(16), - SPAWNER("MOB_SPAWNER"), - SPECTRAL_ARROW(0, 9, "ARROW", ""), - SPIDER_EYE, - SPIDER_SPAWN_EGG(52, "MONSTER_EGG"), - SPLASH_POTION, - SPONGE, - SPRUCE_BOAT("BOAT_SPRUCE"), - SPRUCE_BUTTON("WOOD_BUTTON"), - SPRUCE_DOOR("SPRUCE_DOOR", "SPRUCE_DOOR_ITEM"), - SPRUCE_FENCE, - SPRUCE_FENCE_GATE, - SPRUCE_LEAVES(1, "LEAVES", "LEAVES_2"), - SPRUCE_LOG(1, "LOG"), - SPRUCE_PLANKS(1, "WOOD"), - SPRUCE_PRESSURE_PLATE("WOOD_PLATE"), - SPRUCE_SAPLING(1, "SAPLING"), - SPRUCE_SIGN("SIGN_POST", "SIGN"), - SPRUCE_SLAB(1, "WOOD_DOUBLE_STEP", "WOOD_STEP", "WOODEN_SLAB"), - SPRUCE_STAIRS("SPRUCE_WOOD_STAIRS"), - SPRUCE_TRAPDOOR("TRAP_DOOR"), - SPRUCE_WALL_SIGN("WALL_SIGN"), - SPRUCE_WOOD(1, "LOG"), - SQUID_SPAWN_EGG(94, "MONSTER_EGG"), - STICK, - STICKY_PISTON("PISTON_BASE", "PISTON_STICKY_BASE"), - STONE, - STONECUTTER(14), - STONE_AXE, - STONE_BRICKS("SMOOTH_BRICK"), - STONE_BRICK_SLAB(4, "DOUBLE_STEP", "STEP", "STONE_SLAB"), - STONE_BRICK_STAIRS("SMOOTH_STAIRS"), - STONE_BRICK_WALL, - STONE_BUTTON, - STONE_HOE, - STONE_PICKAXE, - STONE_PRESSURE_PLATE("STONE_PLATE"), - STONE_SHOVEL("STONE_SPADE"), - STONE_SLAB("DOUBLE_STEP", "STEP"), - STONE_STAIRS, - STONE_SWORD, - STRAY_SPAWN_EGG(6, "MONSTER_EGG"), - STRIDER_SPAWN_EGG(16), - STRING, - STRIPPED_ACACIA_LOG("LOG_2"), - STRIPPED_ACACIA_WOOD("LOG_2"), - STRIPPED_BIRCH_LOG(2, "LOG"), - STRIPPED_BIRCH_WOOD(2, "LOG"), - STRIPPED_CRIMSON_HYPHAE(16), - STRIPPED_CRIMSON_STEM(16), - STRIPPED_DARK_OAK_LOG("LOG"), - STRIPPED_DARK_OAK_WOOD("LOG"), - STRIPPED_JUNGLE_LOG(3, "LOG"), - STRIPPED_JUNGLE_WOOD(3, "LOG"), - STRIPPED_OAK_LOG("LOG"), - STRIPPED_OAK_WOOD("LOG"), - STRIPPED_SPRUCE_LOG(1, "LOG"), - STRIPPED_SPRUCE_WOOD(1, "LOG"), - STRIPPED_WARPED_HYPHAE(16), - STRIPPED_WARPED_STEM(16), - STRUCTURE_BLOCK, - /** - * Originally developers used barrier blocks for its purpose. - * So technically this isn't really considered as a suggested material. - */ - STRUCTURE_VOID(10, "", "BARRIER"), - SUGAR, - /** - * Sugar Cane is a known material in pre-1.13 - * Use XBlock when comparing block types. - */ - SUGAR_CANE("SUGAR_CANE_BLOCK"), - SUNFLOWER("DOUBLE_PLANT"), - SUSPICIOUS_STEW(0, 14, "MUSHROOM_STEW", ""), - SWEET_BERRIES(14), - SWEET_BERRY_BUSH(0, 14, "GRASS", ""), - TALL_GRASS(2, "DOUBLE_PLANT"), - TALL_SEAGRASS(2, 13, "TALL_GRASS", ""), - TARGET(16), - TERRACOTTA("HARD_CLAY"), - TIPPED_ARROW(0, 9, "ARROW", ""), - TNT, - TNT_MINECART("EXPLOSIVE_MINECART"), - TORCH, - TOTEM_OF_UNDYING("TOTEM"), - TRADER_LLAMA_SPAWN_EGG(103, 14, "MONSTER_EGG", ""), - TRAPPED_CHEST, - TRIDENT(13), - TRIPWIRE, - TRIPWIRE_HOOK, - TROPICAL_FISH(2, "RAW_FISH"), - TROPICAL_FISH_BUCKET(0, 13, "BUCKET", "WATER_BUCKET"), - TROPICAL_FISH_SPAWN_EGG(0, 13, "MONSTER_EGG"), - TUBE_CORAL(13), - TUBE_CORAL_BLOCK(13), - TUBE_CORAL_FAN(13), - TUBE_CORAL_WALL_FAN, - TURTLE_EGG(0, 13, "EGG", ""), - TURTLE_HELMET(0, 13, "IRON_HELMET", ""), - TURTLE_SPAWN_EGG(0, 13, "CHICKEN_SPAWN_EGG", ""), - TWISTING_VINES(16), - TWISTING_VINES_PLANT(16), - VEX_SPAWN_EGG(35, "MONSTER_EGG"), - VILLAGER_SPAWN_EGG(120, "MONSTER_EGG"), - VINDICATOR_SPAWN_EGG(36, "MONSTER_EGG"), - VINE, - /** - * 1.13 tag is not added because it's the same thing as {@link #AIR} - * - * @see #CAVE_AIR - */ - VOID_AIR("AIR"), - WALL_TORCH("TORCH"), - WANDERING_TRADER_SPAWN_EGG(0, 14, "VILLAGER_SPAWN_EGG", ""), - WARPED_BUTTON(16), - WARPED_DOOR(16), - WARPED_FENCE(16), - WARPED_FENCE_GATE(16), - WARPED_FUNGUS(16), - WARPED_FUNGUS_ON_A_STICK(16), - WARPED_HYPHAE(16), - WARPED_NYLIUM(16), - WARPED_PLANKS(16), - WARPED_PRESSURE_PLATE(16), - WARPED_ROOTS(16), - WARPED_SIGN(0, 16, "SIGN_POST"), - WARPED_SLAB(16), - WARPED_STAIRS(16), - WARPED_STEM(16), - WARPED_TRAPDOOR(16), - WARPED_WALL_SIGN(0, 16, "WALL_SIGN"), - WARPED_WART_BLOCK(16), - /** - * This is used for blocks only. - * In 1.13- WATER will turn into STATIONARY_WATER after it finished spreading. - * After 1.13+ this uses - * https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/Levelled.html water flowing system. - * Use XBlock for this instead. - */ - WATER("STATIONARY_WATER"), - WATER_BUCKET, - WEEPING_VINES(16), - WEEPING_VINES_PLANT(16), - WET_SPONGE(1, "SPONGE"), - /** - * Wheat is a known material in pre-1.13 - * Use XBlock when comparing block types. - */ - WHEAT("CROPS"), - WHEAT_SEEDS("SEEDS"), - WHITE_BANNER(15, "STANDING_BANNER", "BANNER"), - WHITE_BED("BED_BLOCK", "BED"), - WHITE_CARPET("CARPET"), - WHITE_CONCRETE("CONCRETE"), - WHITE_CONCRETE_POWDER("CONCRETE_POWDER"), - WHITE_DYE(15, 14, "INK_SACK", "BONE_MEAL"), - WHITE_GLAZED_TERRACOTTA(0, 12, "HARD_CLAY", "STAINED_CLAY"), - WHITE_SHULKER_BOX, - WHITE_STAINED_GLASS("STAINED_GLASS"), - WHITE_STAINED_GLASS_PANE("THIN_GLASS", "STAINED_GLASS_PANE"), - WHITE_TERRACOTTA("HARD_CLAY", "STAINED_CLAY", "TERRACOTTA"), - WHITE_TULIP(6, "RED_ROSE"), - WHITE_WALL_BANNER(15, "WALL_BANNER"), - WHITE_WOOL("WOOL"), - WITCH_SPAWN_EGG(66, "MONSTER_EGG"), - WITHER_ROSE(0, 14, "BLACK_DYE", ""), - WITHER_SKELETON_SKULL(1, "SKULL", "SKULL_ITEM"), - WITHER_SKELETON_SPAWN_EGG(5, "MONSTER_EGG"), - WITHER_SKELETON_WALL_SKULL(1, "SKULL", "SKULL_ITEM"), - WOLF_SPAWN_EGG(95, "MONSTER_EGG"), - WOODEN_AXE("WOOD_AXE"), - WOODEN_HOE("WOOD_HOE"), - WOODEN_PICKAXE("WOOD_PICKAXE"), - WOODEN_SHOVEL("WOOD_SPADE"), - WOODEN_SWORD("WOOD_SWORD"), - WRITABLE_BOOK("BOOK_AND_QUILL"), - WRITTEN_BOOK, - YELLOW_BANNER(11, "STANDING_BANNER", "BANNER"), - YELLOW_BED(4, "BED_BLOCK", "BED"), - YELLOW_CARPET(4, "CARPET"), - YELLOW_CONCRETE(4, "CONCRETE"), - YELLOW_CONCRETE_POWDER(4, "CONCRETE_POWDER"), - YELLOW_DYE(11, "INK_SACK", "DANDELION_YELLOW"), - YELLOW_GLAZED_TERRACOTTA(4, 12, "HARD_CLAY", "STAINED_CLAY", "YELLOW_TERRACOTTA"), - YELLOW_SHULKER_BOX, - YELLOW_STAINED_GLASS(4, "STAINED_GLASS"), - YELLOW_STAINED_GLASS_PANE(4, "THIN_GLASS", "STAINED_GLASS_PANE"), - YELLOW_TERRACOTTA(4, "HARD_CLAY", "STAINED_CLAY"), - YELLOW_WALL_BANNER(11, "WALL_BANNER"), - YELLOW_WOOL(4, "WOOL"), - ZOGLIN_SPAWN_EGG(16), - ZOMBIE_HEAD(2, "SKULL", "SKULL_ITEM"), - ZOMBIE_HORSE_SPAWN_EGG(29, "MONSTER_EGG"), - ZOMBIE_SPAWN_EGG(54, "MONSTER_EGG"), - ZOMBIE_VILLAGER_SPAWN_EGG(27, "MONSTER_EGG"), - ZOMBIE_WALL_HEAD(2, "SKULL", "SKULL_ITEM"), - ZOMBIFIED_PIGLIN_SPAWN_EGG(57, "MONSTER_EGG", "ZOMBIE_PIGMAN_SPAWN_EGG"); - - - /** - * Cached array of {@link XMaterial#values()} to avoid allocating memory for - * calling the method every time. - * This list is unmodifiable. - * - * @since 2.0.0 - */ - public static final XMaterial[] VALUES = values(); - - /** - * We don't want to use {@link Enums#getIfPresent(Class, String)} to avoid a few checks. - * - * @since 5.1.0 - */ - private static final Map NAMES = new HashMap<>(); - - /** - * An array of material names that can be damaged. - *

- * Most of the names are not complete as this list is intended to be - * checked with {@link String#contains} for memory usage and maintainability. - *

- * New items will probably not be added to the list since they're new and it - * doesn't matter what their data value is. - * - * @since 1.0.0 - */ - private static final String[] DAMAGEABLE = { - "HELMET", "CHESTPLATE", "LEGGINGS", "BOOTS", - "SWORD", "AXE", "PICKAXE", "SHOVEL", "HOE", - "ELYTRA", "TRIDENT", "HORSE_ARMOR", "BARDING", - "SHEARS", "FLINT_AND_STEEL", "BOW", "FISHING_ROD", - "CARROT_ON_A_STICK", "CARROT_STICK", "SPADE", "SHIELD" - }; - /** - * XMaterial Paradox (Duplication Check) - *

- * A map of duplicated material names in 1.13 and 1.12 that will conflict with the legacy names. - * Values are the new material names. - *
- * Duplicates are normally only checked by keys, not values. - * - * @since 3.0.0 - */ - private static final EnumMap DUPLICATED = new EnumMap<>(XMaterial.class); - /** - * Guava (Google Core Libraries for Java)'s cache for performance and timed caches. - * For strings that match a certain XMaterial. Mostly cached for configs. - * - * @since 1.0.0 - */ - private static final Cache NAME_CACHE = CacheBuilder.newBuilder() - .expireAfterAccess(30, TimeUnit.MINUTES) - .build(); - /** - * Guava (Google Core Libraries for Java)'s cache for performance and timed caches. - * For XMaterials that are already parsed once. - * - * @since 3.0.0 - */ - private static final Cache> PARSED_CACHE = CacheBuilder.newBuilder() - .expireAfterAccess(10, TimeUnit.MINUTES) - .build(); - /* - * A set of all the legacy names without duplicates. - *

- * It'll help to free up a lot of memory if it's not used. - * Add it back if you need it. - * - * @see #containsLegacy(String) - * @since 2.2.0 - * - private static final ImmutableSet LEGACY_VALUES = VALUES.stream().map(XMaterial::getLegacy) - .flatMap(Arrays::stream) - .filter(m -> m.charAt(1) == '.') - .collect(Collectors.collectingAndThen(Collectors.toSet(), ImmutableSet::copyOf)); - */ - /** - * This is used for {@link #isOneOf(Collection)} - * - * @since 3.4.0 - */ - private static final LoadingCache CACHED_REGEX = CacheBuilder.newBuilder() - .expireAfterAccess(1, TimeUnit.HOURS) - .build(new CacheLoader() { - @Override - public Pattern load(@Nonnull String str) { - try { - return Pattern.compile(str); - } catch (PatternSyntaxException ex) { - ex.printStackTrace(); - return null; - } - } - }); - /** - * The current version of the server in the a form of a major version. - * - * @since 1.0.0 - */ - private static final int VERSION = Integer.parseInt(getMajorVersion(Bukkit.getVersion()).substring(2)); - /** - * Cached result if the server version is after the v1.13 flattening update. - * - * @since 3.0.0 - */ - private static final boolean ISFLAT = supports(13); - - static { - DUPLICATED.put(MELON, MELON_SLICE); - DUPLICATED.put(CARROT, CARROTS); - DUPLICATED.put(POTATO, POTATOES); - DUPLICATED.put(BEETROOT, BEETROOTS); - DUPLICATED.put(BROWN_MUSHROOM, BROWN_MUSHROOM_BLOCK); - DUPLICATED.put(BRICK, BRICKS); - DUPLICATED.put(NETHER_BRICK, NETHER_BRICKS); - - // Illegal Elements - // Since both 1.12 and 1.13 have _DOOR XMaterial will use it - // for 1.12 to parse the material, but it needs _DOOR_ITEM. - // We'll trick XMaterial into thinking this needs to be parsed - // using the old methods. - // Some of these materials have their enum name added to the legacy list as well. - DUPLICATED.put(DARK_OAK_DOOR, DARK_OAK_DOOR); - DUPLICATED.put(ACACIA_DOOR, ACACIA_DOOR); - DUPLICATED.put(BIRCH_DOOR, BIRCH_DOOR); - DUPLICATED.put(JUNGLE_DOOR, JUNGLE_DOOR); - DUPLICATED.put(SPRUCE_DOOR, SPRUCE_DOOR); - DUPLICATED.put(CAULDRON, CAULDRON); - DUPLICATED.put(BREWING_STAND, BREWING_STAND); - DUPLICATED.put(FLOWER_POT, FLOWER_POT); - } - - static { - for (XMaterial material : VALUES) NAMES.put(material.name(), material); - } - - /** - * The data value of this material https://minecraft.gamepedia.com/Java_Edition_data_values/Pre-flattening - * - * @see #getData() - */ - private final byte data; - /** - * The version that this material was added in. - * - * @since 7.0.0 - */ - private final byte version; - /** - * A list of material names that was being used for older verions. - * - * @see #getLegacy() - */ - private final String[] legacy; - - XMaterial(int data, int version, String... legacy) { - this.data = (byte) data; - this.version = (byte) version; - this.legacy = legacy; - } - - XMaterial(int data, String... legacy) { - this(data, 0, legacy); - } - - XMaterial(int version) { - this(0, version); - } - - XMaterial() { - this(0, 0); - } - - XMaterial(String... legacy) { - this(0, 0, legacy); - } - - /** - * Checks if the version is 1.13 Aquatic Update or higher. - * An invocation of this method yields the cached result from the expression: - *

- *

- * {@link #supports(int) 13}} - *
- * - * @return true if 1.13 or higher. - * @see #getVersion() - * @see #supports(int) - * @since 1.0.0 - */ - public static boolean isNewVersion() { - return ISFLAT; - } - - /** - * This is just an extra method that method that can be used for many cases. - * It can be used in {@link org.bukkit.event.player.PlayerInteractEvent} - * or when accessing {@link org.bukkit.entity.Player#getMainHand()}, - * or other compatibility related methods. - *

- * An invocation of this method yields exactly the same result as the expression: - *

- *

- * !{@link #supports(int)} 9 - *
- * - * @since 2.0.0 - */ - public static boolean isOneEight() { - return !supports(9); - } - - /** - * Gets the {@link XMaterial} with this name without throwing an exception. - * - * @param name the name of the material. - * @return an optional that can be empty. - * @since 5.1.0 - */ - @Nonnull - private static Optional getIfPresent(@Nonnull String name) { - return Optional.ofNullable(NAMES.get(name)); - } - - /** - * The current version of the server. - * - * @return the current server version or 0.0 if unknown. - * @see #isNewVersion() - * @since 2.0.0 - */ - public static int getVersion() { - return VERSION; - } - - /** - * When using newer versions of Minecraft ({@link #isNewVersion()}), helps - * to find the old material name with its data value using a cached search for optimization. - * - * @see #matchDefinedXMaterial(String, byte) - * @since 1.0.0 - */ - @Nullable - private static XMaterial requestOldXMaterial(@Nonnull String name, byte data) { - String holder = name + data; - XMaterial cache = NAME_CACHE.getIfPresent(holder); - if (cache != null) return cache; - - for (XMaterial material : VALUES) { - // Not using material.name().equals(name) check is intended. - if ((data == -1 || data == material.data) && material.anyMatchLegacy(name)) { - NAME_CACHE.put(holder, material); - return material; - } - } - - return null; - } - - /** - * Parses the given material name as an XMaterial with unspecified data value. - * - * @see #matchXMaterialWithData(String) - * @since 2.0.0 - */ - @Nonnull - public static Optional matchXMaterial(@Nonnull String name) { - Validate.notEmpty(name, "Cannot match a material with null or empty material name"); - Optional oldMatch = matchXMaterialWithData(name); - if (oldMatch.isPresent()) return oldMatch; - return matchDefinedXMaterial(format(name), (byte) -1); - } - - /** - * Parses material name and data value from the specified string. - * The separator for the material name and its data value is {@code :} - * Spaces are allowed. Mostly used when getting materials from config for old school minecrafters. - *

- * Examples - *

-     *     {@code INK_SACK:1 -> RED_DYE}
-     *     {@code WOOL: 14  -> RED_WOOL}
-     * 
- * - * @param name the material string that consists of the material name, data and separator character. - * @return the parsed XMaterial. - * @see #matchXMaterial(String) - * @since 3.0.0 - */ - @Nonnull - private static Optional matchXMaterialWithData(String name) { - int index = name.indexOf(':'); - if (index != -1) { - String mat = format(name.substring(0, index)); - - try { - byte data = (byte) Byte.parseByte(StringUtils.deleteWhitespace(name.substring(index + 1))); - return matchDefinedXMaterial(mat, data); - } catch (NumberFormatException ignored) { - } - } - - return Optional.empty(); - } - - /** - * Parses the given material as an XMaterial. - * - * @throws IllegalArgumentException may be thrown as an unexpected exception. - * @see #matchDefinedXMaterial(String, byte) - * @see #matchXMaterial(ItemStack) - * @since 2.0.0 - */ - @Nonnull - public static XMaterial matchXMaterial(@Nonnull Material material) { - Objects.requireNonNull(material, "Cannot match null material"); - return matchDefinedXMaterial(material.name(), (byte) -1) - .orElseThrow(() -> new IllegalArgumentException("Unsupported material with no data value: " + material.name())); - } - - /** - * Parses the given item as an XMaterial using its material and data value (durability). - * - * @param item the ItemStack to match. - * @return an XMaterial if matched any. - * @throws IllegalArgumentException may be thrown as an unexpected exception. - * @see #matchDefinedXMaterial(String, byte) - * @since 2.0.0 - */ - @Nonnull - @SuppressWarnings("deprecation") - public static XMaterial matchXMaterial(@Nonnull ItemStack item) { - Objects.requireNonNull(item, "Cannot match null ItemStack"); - String material = item.getType().name(); - byte data = (byte) (ISFLAT || isDamageable(material) ? 0 : item.getDurability()); - - return matchDefinedXMaterial(material, data) - .orElseThrow(() -> new IllegalArgumentException("Unsupported material: " + material + " (" + data + ')')); - } - - /** - * Parses the given material name and data value as an XMaterial. - * All the values passed to this method will not be null or empty and are formatted correctly. - * - * @param name the formatted name of the material. - * @param data the data value of the material. - * @return an XMaterial (with the same data value if specified) - * @see #matchXMaterial(Material) - * @see #matchXMaterial(int, byte) - * @see #matchXMaterial(ItemStack) - * @since 3.0.0 - */ - @SuppressWarnings("OptionalAssignedToNull") - @Nonnull - private static Optional matchDefinedXMaterial(@Nonnull String name, byte data) { - boolean duplicated = isDuplicated(name); - - // Do basic number and boolean checks before accessing more complex enum stuff. - // Maybe we can simplify (ISFLAT || !duplicated) with the (!ISFLAT && duplicated) under it to save a few nanoseconds? - // if (!Boolean.valueOf(Boolean.getBoolean(Boolean.TRUE.toString())).equals(Boolean.FALSE.booleanValue())) return null; - Optional xMaterial = null; - if (data <= 0 && (ISFLAT || !duplicated)) { - // Apparently the transform method is more efficient than toJavaUtil() - // toJavaUtil isn't even supported in older versions. - xMaterial = getIfPresent(name); - if (xMaterial.isPresent()) return xMaterial; - } - - // XMaterial Paradox (Duplication Check) - // I've concluded that this is just an infinite loop that keeps - // going around the Singular Form and the Plural Form materials. A waste of brain cells and a waste of time. - // This solution works just fine anyway. - XMaterial xMat = requestOldXMaterial(name, data); - if (xMat == null) { - // Special case. Refer to FILLED_MAP for more info. - if (data > 0 && name.endsWith("MAP")) return Optional.of(FILLED_MAP); - return Optional.empty(); - } - - if (!ISFLAT && duplicated && xMat.name().charAt(xMat.name().length() - 1) == 'S') { - // A solution for XMaterial Paradox. - // Manually parses the duplicated materials to find the exact material based on the server version. - // If ends with "S" -> Plural Form Material - return xMaterial == null ? getIfPresent(name) : xMaterial; - } - return Optional.ofNullable(xMat); - } - - /** - * XMaterial Paradox (Duplication Check) - * Checks if the material has any duplicates. - *

- * Example: - *

{@code MELON, CARROT, POTATO, BEETROOT -> true} - * - * @param name the name of the material to check. - * @return true if there's a duplicated material for this material, otherwise false. - * @see #isDuplicated() - * @since 2.0.0 - */ - private static boolean isDuplicated(@Nonnull String name) { - // Don't use matchXMaterial() since this method is being called from matchXMaterial() itself and will cause a StackOverflowError. - for (Map.Entry duplicated : DUPLICATED.entrySet()) { - XMaterial material = duplicated.getKey(); - if (material.name().equals(name) || material.anyMatchLegacy(name)) return true; - } - return false; - } - - /** - * Gets the XMaterial based on the material's ID (Magic Value) and data value.
- * You should avoid using this for performance issues. - * - * @param id the ID (Magic value) of the material. - * @param data the data value of the material. - * @return a parsed XMaterial with the same ID and data value. - * @see #matchXMaterial(ItemStack) - * @since 2.0.0 - */ - @Nonnull - public static Optional matchXMaterial(int id, byte data) { - if (id < 0 || data < 0) return Optional.empty(); - - // Looping through Material.values() will take longer. - for (XMaterial materials : VALUES) { - if (materials.data == data && materials.getId() == id) return Optional.of(materials); - } - return Optional.empty(); - } - - /** - * Attempts to build the string like an enum name. - * Removes all the spaces, and extra non-English characters. Also removes some config/in-game based strings. - * While this method is hard to maintain, it's extremely efficient. It's approximately more than x5 times faster than - * the normal RegEx + String Methods approach for both formatted and unformatted material names. - * - * @param name the material name to modify. - * @return a Material enum name. - * @since 2.0.0 - */ - @Nonnull - protected static String format(@Nonnull String name) { - int len = name.length(); - char[] chs = new char[len]; - int count = 0; - boolean appendUnderline = false; - - for (int i = 0; i < len; i++) { - char ch = name.charAt(i); - - if (!appendUnderline && count != 0 && (ch == '-' || ch == ' ' || ch == '_') && chs[count] != '_') appendUnderline = true; - else { - boolean number = false; - // Old materials have numbers in them. - if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (number = (ch >= '0' && ch <= '9'))) { - if (appendUnderline) { - chs[count++] = '_'; - appendUnderline = false; - } - - if (number) chs[count++] = ch; - else chs[count++] = (char) (ch & 0x5f); - } - } - } - - return new String(chs, 0, count); - } - - /** - * Checks if the specified version is the same version or higher than the current server version. - * - * @param version the major version to be checked. "1." is ignored. E.g. 1.12 = 12 | 1.9 = 9 - * @return true of the version is equal or higher than the current version. - * @since 2.0.0 - */ - public static boolean supports(int version) { - return VERSION >= version; - } - - /** - * Converts the enum names to a more friendly and readable string. - * - * @return a formatted string. - * @see #toWord(String) - * @since 2.1.0 - */ - @Nonnull - public static String toWord(@Nonnull Material material) { - Objects.requireNonNull(material, "Cannot translate a null material to a word"); - return toWord(material.name()); - } - - /** - * Parses an enum name to a normal word. - * Normal names have underlines removed and each word capitalized. - *

- * Examples: - *

-     *     EMERALD                 -> Emerald
-     *     EMERALD_BLOCK           -> Emerald Block
-     *     ENCHANTED_GOLDEN_APPLE  -> Enchanted Golden Apple
-     * 
- * - * @param name the name of the enum. - * @return a cleaned more readable enum name. - * @since 2.1.0 - */ - @Nonnull - private static String toWord(@Nonnull String name) { - return WordUtils.capitalize(name.replace('_', ' ').toLowerCase(Locale.ENGLISH)); - } - - /** - * Gets the exact major version (..., 1.9, 1.10, ..., 1.14) - * - * @param version Supports {@link Bukkit#getVersion()}, {@link Bukkit#getBukkitVersion()} and normal formats such as "1.14" - * @return the exact major version. - * @since 2.0.0 - */ - @Nonnull - public static String getMajorVersion(@Nonnull String version) { - Validate.notEmpty(version, "Cannot get major Minecraft version from null or empty string"); - - // getVersion() - int index = version.lastIndexOf("MC:"); - if (index != -1) { - version = version.substring(index + 4, version.length() - 1); - } else if (version.endsWith("SNAPSHOT")) { - // getBukkitVersion() - index = version.indexOf('-'); - version = version.substring(0, index); - } - - // 1.13.2, 1.14.4, etc... - int lastDot = version.lastIndexOf('.'); - if (version.indexOf('.') != lastDot) version = version.substring(0, lastDot); - - return version; - } - - /** - * Checks if the material can be damaged by using it. - * Names going through this method are not formatted. - * - * @param name the name of the material. - * @return true of the material can be damaged. - * @see #isDamageable() - * @since 1.0.0 - */ - public static boolean isDamageable(@Nonnull String name) { - Objects.requireNonNull(name, "Material name cannot be null"); - for (String damageable : DAMAGEABLE) { - if (name.contains(damageable)) return true; - } - return false; - } - - /** - * Checks if the list of given material names matches the given base material. - * Mostly used for configs. - *

- * Supports {@link String#contains} {@code CONTAINS:NAME} and Regular Expression {@code REGEX:PATTERN} formats. - *

- * Example: - *

-     *     XMaterial material = {@link #matchXMaterial(ItemStack)};
-     *     if (material.isOneOf(plugin.getConfig().getStringList("disabled-items")) return;
-     * 
- *
- * {@code CONTAINS} Examples: - *
-     *     {@code "CONTAINS:CHEST" -> CHEST, ENDERCHEST, TRAPPED_CHEST -> true}
-     *     {@code "cOnTaINS:dYe" -> GREEN_DYE, YELLOW_DYE, BLUE_DYE, INK_SACK -> true}
-     * 
- *

- * {@code REGEX} Examples - *

-     *     {@code "REGEX:^.+_.+_.+$" -> Every Material with 3 underlines or more: SHULKER_SPAWN_EGG, SILVERFISH_SPAWN_EGG, SKELETON_HORSE_SPAWN_EGG}
-     *     {@code "REGEX:^.{1,3}$" -> Material names that have 3 letters only: BED, MAP, AIR}
-     * 
- *

- * The reason that there are tags for {@code CONTAINS} and {@code REGEX} - * is for the performance. - * Please avoid using the {@code REGEX} tag if you can use the {@code CONTAINS} tag. - * It'll have a huge impact on performance. - * Please avoid using {@code (capturing groups)} there's no use for them in this case. - * If you want to use groups, use {@code (?: non-capturing groups)}. It's faster. - *

- * You can make a cache for pre-compiled RegEx patterns from your config. - * It's better, but not much faster since these patterns are not that complex. - *

- * Want to learn RegEx? You can mess around in RegExr website. - * - * @param materials the material names to check base material on. - * @return true if one of the given material names is similar to the base material. - * @since 3.1.1 - */ - public boolean isOneOf(@Nullable Collection materials) { - if (materials == null || materials.isEmpty()) return false; - String name = this.name(); - - for (String comp : materials) { - String checker = comp.toUpperCase(Locale.ENGLISH); - if (checker.startsWith("CONTAINS:")) { - comp = format(checker.substring(9)); - if (name.contains(comp)) return true; - continue; - } - if (checker.startsWith("REGEX:")) { - comp = comp.substring(6); - Pattern pattern = CACHED_REGEX.getUnchecked(comp); - if (pattern != null && pattern.matcher(name).matches()) return true; - continue; - } - - // Direct Object Equals - Optional xMat = matchXMaterial(comp); - if (xMat.isPresent() && xMat.get() == this) return true; - } - return false; - } - - /** - * Sets the {@link Material} (and data value on older versions) of an item. - * Damageable materials will not have their durability changed. - *

- * Use {@link #parseItem()} instead when creating new ItemStacks. - * - * @param item the item to change its type. - * @see #parseItem() - * @since 3.0.0 - */ - @Nonnull - @SuppressWarnings("deprecation") - public ItemStack setType(@Nonnull ItemStack item) { - Objects.requireNonNull(item, "Cannot set material for null ItemStack"); - Material material = this.parseMaterial(); - Objects.requireNonNull(material, "Unsupported material: " + this.name()); - - item.setType(material); - if (!ISFLAT && !this.isDamageable()) item.setDurability(this.data); - return item; - } - - /** - * Checks if the given string matches any of this material's legacy material names. - * All the values passed to this method will not be null or empty and are formatted correctly. - * - * @param name the name to check - * @return true if it's one of the legacy names. - * @since 2.0.0 - */ - private boolean anyMatchLegacy(@Nonnull String name) { - for (String legacy : this.legacy) { - if (legacy.isEmpty()) break; // Left-side suggestion list - if (name.equals(legacy)) return true; - } - return false; - } - - /** - * User-friendly readable name for this material - * In most cases you should be using {@link #name()} instead. - * - * @return string of this object. - * @see #toWord(String) - * @since 3.0.0 - */ - @Override - public String toString() { - return toWord(this.name()); - } - - /** - * Gets the ID (Magic value) of the material. - * - * @return the ID of the material or -1 if it's a new block or the material is not supported. - * @see #matchXMaterial(int, byte) - * @since 2.2.0 - */ - @SuppressWarnings("deprecation") - public int getId() { - if (this.data != 0 || (this.version >= 13)) return -1; - Material material = this.parseMaterial(); - return material == null ? -1 : material.getId(); - } - - /** - * Checks if the material has any duplicates. - * - * @return true if there is a duplicated name for this material, otherwise false. - * @see #isDuplicated(String) - * @since 2.0.0 - */ - public boolean isDuplicated() { - return DUPLICATED.containsKey(this); - } - - /** - * Checks if the material can be damaged by using it. - * Names going through this method are not formatted. - * - * @return true if the item can be damaged (have its durability changed), otherwise false. - * @see #isDamageable(String) - * @since 1.0.0 - */ - public boolean isDamageable() { - return isDamageable(this.name()); - } - - /** - * The data value of this material pre-flattening. - *

- * Can be accessed with {@link ItemStack#getData()} then {@code MaterialData#getData()} - * or {@link ItemStack#getDurability()} if not damageable. - * - * @return data of this material, or 0 if none. - * @since 1.0.0 - */ - @SuppressWarnings("deprecation") - public byte getData() { - return data; - } - - /** - * Get a list of materials names that was previously used by older versions. - * If the material was added in a new version {@link #isNewVersion()}, - * then the first element will indicate which version the material was added in. - * - * @return a list of legacy material names and the first element as the version the material was added in if new. - * @since 1.0.0 - */ - @Nonnull - public String[] getLegacy() { - return legacy; - } - - /** - * Parses an item from this XMaterial. - * Uses data values on older versions. - * - * @return an ItemStack with the same material (and data value if in older versions.) - * @see #parseItem(boolean) - * @see #setType(ItemStack) - * @since 1.0.0 - */ - @Nullable - public ItemStack parseItem() { - return parseItem(false); - } - - /** - * Parses an item from this XMaterial. - * Uses data values on older versions. - * - * @param suggest if true {@link #parseMaterial(boolean)} true will be used. - * @return an ItemStack with the same material (and data value if in older versions.) - * @see #setType(ItemStack) - * @since 2.0.0 - */ - @Nullable - @SuppressWarnings("deprecation") - public ItemStack parseItem(boolean suggest) { - Material material = this.parseMaterial(suggest); - if (material == null) return null; - return ISFLAT ? new ItemStack(material) : new ItemStack(material, 1, this.data); - } - - /** - * Parses the material of this XMaterial. - * - * @return the material related to this XMaterial based on the server version. - * @see #parseMaterial(boolean) - * @since 1.0.0 - */ - @Nullable - public Material parseMaterial() { - return parseMaterial(false); - } - - /** - * Parses the material of this XMaterial and accepts suggestions. - * - * @param suggest use a suggested material (from older materials) if the material is added in a later version of Minecraft. - * @return the material related to this XMaterial based on the server version. - * @since 2.0.0 - */ - @SuppressWarnings("OptionalAssignedToNull") - @Nullable - public Material parseMaterial(boolean suggest) { - Optional cache = PARSED_CACHE.getIfPresent(this); - if (cache != null) return cache.orElse(null); - Material mat; - - if (!ISFLAT && this.isDuplicated()) mat = requestOldMaterial(suggest); - else { - mat = Material.getMaterial(this.name()); - if (mat == null) mat = requestOldMaterial(suggest); - } - - Optional opt = Optional.ofNullable(mat); - PARSED_CACHE.put(this, opt); - return mat; - } - - /** - * Parses a material for older versions of Minecraft. - * Accepts suggestions if specified. - * - * @param suggest if true suggested materials will be considered for old versions. - * @return a parsed material suitable for the current Minecraft version. - * @see #parseMaterial(boolean) - * @since 2.0.0 - */ - @Nullable - private Material requestOldMaterial(boolean suggest) { - for (int i = this.legacy.length - 1; i >= 0; i--) { - String legacy = this.legacy[i]; - - // Check if we've reached the end and the last string is our - // material version. - if (i == 0 && legacy.charAt(1) == '.') return null; - - // According to the suggestion list format, all the other names continuing - // from here are considered as a "suggestion" - // The empty string is an indicator for suggestion list on the left side. - if (legacy.isEmpty()) { - if (suggest) continue; - break; - } - - Material material = Material.getMaterial(legacy); - if (material != null) return material; - } - return null; - } - - /** - * Checks if an item has the same material (and data value on older versions). - * - * @param item item to check. - * @return true if the material is the same as the item's material (and data value if on older versions), otherwise false. - * @since 1.0.0 - */ - @SuppressWarnings("deprecation") - public boolean isSimilar(@Nonnull ItemStack item) { - Objects.requireNonNull(item, "Cannot compare with null ItemStack"); - if (item.getType() != this.parseMaterial()) return false; - return ISFLAT || this.isDamageable() || item.getDurability() == this.data; - } - - /** - * Gets the suggested material names that can be used - * if the material is not supported in the current version. - * - * @return a list of suggested material names. - * @see #parseMaterial(boolean) - * @since 2.0.0 - */ - @Nonnull - public List getSuggestions() { - if (this.legacy.length == 0 || this.version == 0) return new ArrayList<>(); - List suggestions = new ArrayList<>(); - for (String legacy : this.legacy) { - if (legacy.isEmpty()) break; - suggestions.add(legacy); - } - return suggestions; - } - - /** - * Checks if this material is supported in the current version. - * Suggested materials will be ignored. - *

- * Note that you should use {@link #parseMaterial()} and check if it's null - * if you're going to parse and use the material later. - * - * @return true if the material exists in {@link Material} list. - * @since 2.0.0 - */ - public boolean isSupported() { - if (this.version != 0) return supports(this.version); - - Material material = Material.getMaterial(this.name()); - if (material != null) return true; - return requestOldMaterial(false) != null; - } - - public byte getMaterialVersion() { - return version; - } -} \ No newline at end of file diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/utils/XSound.java b/src/main/lombok/nl/SBDeveloper/V10Lift/utils/XSound.java deleted file mode 100644 index 9d4839d..0000000 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/utils/XSound.java +++ /dev/null @@ -1,1561 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2020 Crypto Morin - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package nl.SBDeveloper.V10Lift.utils; - -import com.google.common.base.Enums; -import com.google.common.base.Strings; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.Validate; -import org.apache.commons.lang.WordUtils; -import org.bukkit.*; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scheduler.BukkitTask; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; - -/** - * XSound - Universal Minecraft Sound Support
- * 1.13 and above as priority. - *

- * Sounds are thread-safe. But this doesn't mean you should - * use a bukkit async scheduler for every {@link Player#playSound} call. - *

- * Volume: 0.0-∞ - 1.0f (normal) - Using higher values increase the distance from which the sound can be heard.
- * Pitch: 0.5-2.0 - 1.0f (normal) - How fast the sound is play. - *

- * 1.8: http://docs.codelanx.com/Bukkit/1.8/org/bukkit/Sound.html - * Latest: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html - * Basics: https://bukkit.org/threads/151517/ - * play command: https://minecraft.gamepedia.com/Commands/play - * - * @author Crypto Morin - * @version 4.0.0 - * @see Sound - */ -public enum XSound { - AMBIENT_BASALT_DELTAS_ADDITIONS, - AMBIENT_BASALT_DELTAS_LOOP, - AMBIENT_BASALT_DELTAS_MOOD, - AMBIENT_CAVE("AMBIENCE_CAVE"), - AMBIENT_CRIMSON_FOREST_ADDITIONS, - AMBIENT_CRIMSON_FOREST_LOOP, - AMBIENT_CRIMSON_FOREST_MOOD, - AMBIENT_NETHER_WASTES_ADDITIONS, - AMBIENT_NETHER_WASTES_LOOP, - AMBIENT_NETHER_WASTES_MOOD, - AMBIENT_SOUL_SAND_VALLEY_ADDITIONS, - AMBIENT_SOUL_SAND_VALLEY_LOOP, - AMBIENT_SOUL_SAND_VALLEY_MOOD, - AMBIENT_UNDERWATER_ENTER, - AMBIENT_UNDERWATER_EXIT, - AMBIENT_UNDERWATER_LOOP("AMBIENT_UNDERWATER_EXIT"), - AMBIENT_UNDERWATER_LOOP_ADDITIONS("AMBIENT_UNDERWATER_EXIT"), - AMBIENT_UNDERWATER_LOOP_ADDITIONS_RARE("AMBIENT_UNDERWATER_EXIT"), - AMBIENT_UNDERWATER_LOOP_ADDITIONS_ULTRA_RARE("AMBIENT_UNDERWATER_EXIT"), - AMBIENT_WARPED_FOREST_ADDITIONS, - AMBIENT_WARPED_FOREST_LOOP, - AMBIENT_WARPED_FOREST_MOOD, - BLOCK_ANCIENT_DEBRIS_BREAK, - BLOCK_ANCIENT_DEBRIS_FALL, - BLOCK_ANCIENT_DEBRIS_HIT, - BLOCK_ANCIENT_DEBRIS_PLACE, - BLOCK_ANCIENT_DEBRIS_STEP, - BLOCK_ANVIL_BREAK("ANVIL_BREAK"), - BLOCK_ANVIL_DESTROY, - BLOCK_ANVIL_FALL, - BLOCK_ANVIL_HIT("BLOCK_ANVIL_FALL"), - BLOCK_ANVIL_LAND("ANVIL_LAND"), - BLOCK_ANVIL_PLACE("BLOCK_ANVIL_FALL"), - BLOCK_ANVIL_STEP("BLOCK_ANVIL_FALL"), - BLOCK_ANVIL_USE("ANVIL_USE"), - BLOCK_BAMBOO_BREAK, - BLOCK_BAMBOO_FALL, - BLOCK_BAMBOO_HIT, - BLOCK_BAMBOO_PLACE, - BLOCK_BAMBOO_SAPLING_BREAK, - BLOCK_BAMBOO_SAPLING_HIT, - BLOCK_BAMBOO_SAPLING_PLACE, - BLOCK_BAMBOO_STEP, - BLOCK_BARREL_CLOSE, - BLOCK_BARREL_OPEN, - BLOCK_BASALT_BREAK, - BLOCK_BASALT_FALL, - BLOCK_BASALT_HIT, - BLOCK_BASALT_PLACE, - BLOCK_BASALT_STEP, - BLOCK_BEACON_ACTIVATE, - BLOCK_BEACON_AMBIENT, - BLOCK_BEACON_DEACTIVATE("BLOCK_BEACON_AMBIENT"), - BLOCK_BEACON_POWER_SELECT("BLOCK_BEACON_AMBIENT"), - BLOCK_BEEHIVE_DRIP, - BLOCK_BEEHIVE_ENTER, - BLOCK_BEEHIVE_EXIT, - BLOCK_BEEHIVE_SHEAR, - BLOCK_BEEHIVE_WORK, - BLOCK_BELL_RESONATE, - BLOCK_BELL_USE, - BLOCK_BLASTFURNACE_FIRE_CRACKLE, - BLOCK_BONE_BLOCK_BREAK, - BLOCK_BONE_BLOCK_FALL, - BLOCK_BONE_BLOCK_HIT, - BLOCK_BONE_BLOCK_PLACE, - BLOCK_BONE_BLOCK_STEP, - BLOCK_BREWING_STAND_BREW, - BLOCK_BUBBLE_COLUMN_BUBBLE_POP, - BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT, - BLOCK_BUBBLE_COLUMN_UPWARDS_INSIDE, - BLOCK_BUBBLE_COLUMN_WHIRLPOOL_AMBIENT, - BLOCK_BUBBLE_COLUMN_WHIRLPOOL_INSIDE, - BLOCK_CAMPFIRE_CRACKLE, - BLOCK_CHAIN_BREAK, - BLOCK_CHAIN_FALL, - BLOCK_CHAIN_HIT, - BLOCK_CHAIN_PLACE, - BLOCK_CHAIN_STEP, - BLOCK_CHEST_CLOSE("CHEST_CLOSE", "ENTITY_CHEST_CLOSE"), - BLOCK_CHEST_LOCKED, - BLOCK_CHEST_OPEN("CHEST_OPEN", "ENTITY_CHEST_OPEN"), - BLOCK_CHORUS_FLOWER_DEATH, - BLOCK_CHORUS_FLOWER_GROW, - BLOCK_COMPARATOR_CLICK, - BLOCK_COMPOSTER_EMPTY, - BLOCK_COMPOSTER_FILL, - BLOCK_COMPOSTER_FILL_SUCCESS, - BLOCK_COMPOSTER_READY, - BLOCK_CONDUIT_ACTIVATE, - BLOCK_CONDUIT_AMBIENT, - BLOCK_CONDUIT_AMBIENT_SHORT, - BLOCK_CONDUIT_ATTACK_TARGET, - BLOCK_CONDUIT_DEACTIVATE, - BLOCK_CORAL_BLOCK_BREAK, - BLOCK_CORAL_BLOCK_FALL, - BLOCK_CORAL_BLOCK_HIT, - BLOCK_CORAL_BLOCK_PLACE, - BLOCK_CORAL_BLOCK_STEP, - BLOCK_CROP_BREAK, - BLOCK_DISPENSER_DISPENSE, - BLOCK_DISPENSER_FAIL, - BLOCK_DISPENSER_LAUNCH, - BLOCK_ENCHANTMENT_TABLE_USE, - BLOCK_ENDER_CHEST_CLOSE, - BLOCK_ENDER_CHEST_OPEN, - BLOCK_END_GATEWAY_SPAWN, - BLOCK_END_PORTAL_FRAME_FILL, - BLOCK_END_PORTAL_SPAWN, - BLOCK_FENCE_GATE_CLOSE, - BLOCK_FENCE_GATE_OPEN, - BLOCK_FIRE_AMBIENT("FIRE"), - BLOCK_FIRE_EXTINGUISH("FIZZ"), - BLOCK_FUNGUS_BREAK, - BLOCK_FUNGUS_FALL, - BLOCK_FUNGUS_HIT, - BLOCK_FUNGUS_PLACE, - BLOCK_FUNGUS_STEP, - BLOCK_FURNACE_FIRE_CRACKLE, - BLOCK_GILDED_BLACKSTONE_BREAK, - BLOCK_GILDED_BLACKSTONE_FALL, - BLOCK_GILDED_BLACKSTONE_HIT, - BLOCK_GILDED_BLACKSTONE_PLACE, - BLOCK_GILDED_BLACKSTONE_STEP, - BLOCK_GLASS_BREAK("GLASS"), - BLOCK_GLASS_FALL, - BLOCK_GLASS_HIT, - BLOCK_GLASS_PLACE, - BLOCK_GLASS_STEP, - BLOCK_GRASS_BREAK("DIG_GRASS"), - BLOCK_GRASS_FALL, - BLOCK_GRASS_HIT, - BLOCK_GRASS_PLACE, - BLOCK_GRASS_STEP("STEP_GRASS"), - BLOCK_GRAVEL_BREAK("DIG_GRAVEL"), - BLOCK_GRAVEL_FALL, - BLOCK_GRAVEL_HIT, - BLOCK_GRAVEL_PLACE, - BLOCK_GRAVEL_STEP("STEP_GRAVEL"), - BLOCK_GRINDSTONE_USE, - BLOCK_HONEY_BLOCK_BREAK, - BLOCK_HONEY_BLOCK_FALL, - BLOCK_HONEY_BLOCK_HIT, - BLOCK_HONEY_BLOCK_PLACE, - BLOCK_HONEY_BLOCK_SLIDE, - BLOCK_HONEY_BLOCK_STEP, - BLOCK_IRON_DOOR_CLOSE, - BLOCK_IRON_DOOR_OPEN, - BLOCK_IRON_TRAPDOOR_CLOSE, - BLOCK_IRON_TRAPDOOR_OPEN, - BLOCK_LADDER_BREAK, - BLOCK_LADDER_FALL, - BLOCK_LADDER_HIT, - BLOCK_LADDER_PLACE, - BLOCK_LADDER_STEP("STEP_LADDER"), - BLOCK_LANTERN_BREAK, - BLOCK_LANTERN_FALL, - BLOCK_LANTERN_HIT, - BLOCK_LANTERN_PLACE, - BLOCK_LANTERN_STEP, - BLOCK_LAVA_AMBIENT("LAVA"), - BLOCK_LAVA_EXTINGUISH, - BLOCK_LAVA_POP("LAVA_POP"), - BLOCK_LEVER_CLICK, - BLOCK_LILY_PAD_PLACE("BLOCK_WATERLILY_PLACE"), - BLOCK_LODESTONE_BREAK, - BLOCK_LODESTONE_FALL, - BLOCK_LODESTONE_HIT, - BLOCK_LODESTONE_PLACE, - BLOCK_LODESTONE_STEP, - BLOCK_METAL_BREAK, - BLOCK_METAL_FALL, - BLOCK_METAL_HIT, - BLOCK_METAL_PLACE, - BLOCK_METAL_PRESSURE_PLATE_CLICK_OFF("BLOCK_METAL_PRESSUREPLATE_CLICK_OFF"), - BLOCK_METAL_PRESSURE_PLATE_CLICK_ON("BLOCK_METAL_PRESSUREPLATE_CLICK_ON"), - BLOCK_METAL_STEP, - BLOCK_NETHERITE_BLOCK_BREAK, - BLOCK_NETHERITE_BLOCK_FALL, - BLOCK_NETHERITE_BLOCK_HIT, - BLOCK_NETHERITE_BLOCK_PLACE, - BLOCK_NETHERITE_BLOCK_STEP, - BLOCK_NETHERRACK_BREAK, - BLOCK_NETHERRACK_FALL, - BLOCK_NETHERRACK_HIT, - BLOCK_NETHERRACK_PLACE, - BLOCK_NETHERRACK_STEP, - BLOCK_NETHER_BRICKS_BREAK, - BLOCK_NETHER_BRICKS_FALL, - BLOCK_NETHER_BRICKS_HIT, - BLOCK_NETHER_BRICKS_PLACE, - BLOCK_NETHER_BRICKS_STEP, - BLOCK_NETHER_GOLD_ORE_BREAK, - BLOCK_NETHER_GOLD_ORE_FALL, - BLOCK_NETHER_GOLD_ORE_HIT, - BLOCK_NETHER_GOLD_ORE_PLACE, - BLOCK_NETHER_GOLD_ORE_STEP, - BLOCK_NETHER_ORE_BREAK, - BLOCK_NETHER_ORE_FALL, - BLOCK_NETHER_ORE_HIT, - BLOCK_NETHER_ORE_PLACE, - BLOCK_NETHER_ORE_STEP, - BLOCK_NETHER_SPROUTS_BREAK, - BLOCK_NETHER_SPROUTS_FALL, - BLOCK_NETHER_SPROUTS_HIT, - BLOCK_NETHER_SPROUTS_PLACE, - BLOCK_NETHER_SPROUTS_STEP, - BLOCK_NETHER_WART_BREAK, - BLOCK_NOTE_BLOCK_BANJO, - BLOCK_NOTE_BLOCK_BASEDRUM("NOTE_BASS_DRUM", "BLOCK_NOTE_BASEDRUM"), - BLOCK_NOTE_BLOCK_BASS("NOTE_BASS", "BLOCK_NOTE_BASS"), - BLOCK_NOTE_BLOCK_BELL("BLOCK_NOTE_BELL"), - BLOCK_NOTE_BLOCK_BIT, - BLOCK_NOTE_BLOCK_CHIME("BLOCK_NOTE_CHIME"), - BLOCK_NOTE_BLOCK_COW_BELL, - BLOCK_NOTE_BLOCK_DIDGERIDOO, - BLOCK_NOTE_BLOCK_FLUTE("BLOCK_NOTE_FLUTE"), - BLOCK_NOTE_BLOCK_GUITAR("NOTE_BASS_GUITAR", "BLOCK_NOTE_GUITAR"), - BLOCK_NOTE_BLOCK_HARP("NOTE_PIANO", "BLOCK_NOTE_HARP"), - BLOCK_NOTE_BLOCK_HAT("NOTE_STICKS", "BLOCK_NOTE_HAT"), - BLOCK_NOTE_BLOCK_IRON_XYLOPHONE, - BLOCK_NOTE_BLOCK_PLING("NOTE_PLING", "BLOCK_NOTE_PLING"), - BLOCK_NOTE_BLOCK_SNARE("NOTE_SNARE_DRUM", "BLOCK_NOTE_SNARE"), - BLOCK_NOTE_BLOCK_XYLOPHONE("BLOCK_NOTE_XYLOPHONE"), - BLOCK_NYLIUM_BREAK, - BLOCK_NYLIUM_FALL, - BLOCK_NYLIUM_HIT, - BLOCK_NYLIUM_PLACE, - BLOCK_NYLIUM_STEP, - BLOCK_PISTON_CONTRACT("PISTON_RETRACT"), - BLOCK_PISTON_EXTEND("PISTON_EXTEND"), - BLOCK_PORTAL_AMBIENT("PORTAL"), - BLOCK_PORTAL_TRAVEL("PORTAL_TRAVEL"), - BLOCK_PORTAL_TRIGGER("PORTAL_TRIGGER"), - BLOCK_PUMPKIN_CARVE, - BLOCK_REDSTONE_TORCH_BURNOUT, - BLOCK_RESPAWN_ANCHOR_AMBIENT, - BLOCK_RESPAWN_ANCHOR_CHARGE, - BLOCK_RESPAWN_ANCHOR_DEPLETE, - BLOCK_RESPAWN_ANCHOR_SET_SPAWN, - BLOCK_ROOTS_BREAK, - BLOCK_ROOTS_FALL, - BLOCK_ROOTS_HIT, - BLOCK_ROOTS_PLACE, - BLOCK_ROOTS_STEP, - BLOCK_SAND_BREAK("DIG_SAND"), - BLOCK_SAND_FALL, - BLOCK_SAND_HIT, - BLOCK_SAND_PLACE, - BLOCK_SAND_STEP("STEP_SAND"), - BLOCK_SCAFFOLDING_BREAK, - BLOCK_SCAFFOLDING_FALL, - BLOCK_SCAFFOLDING_HIT, - BLOCK_SCAFFOLDING_PLACE, - BLOCK_SCAFFOLDING_STEP, - BLOCK_SHROOMLIGHT_BREAK, - BLOCK_SHROOMLIGHT_FALL, - BLOCK_SHROOMLIGHT_HIT, - BLOCK_SHROOMLIGHT_PLACE, - BLOCK_SHROOMLIGHT_STEP, - BLOCK_SHULKER_BOX_CLOSE, - BLOCK_SHULKER_BOX_OPEN, - BLOCK_SLIME_BLOCK_BREAK("BLOCK_SLIME_BREAK"), - BLOCK_SLIME_BLOCK_FALL("BLOCK_SLIME_FALL"), - BLOCK_SLIME_BLOCK_HIT("BLOCK_SLIME_HIT"), - BLOCK_SLIME_BLOCK_PLACE("BLOCK_SLIME_PLACE"), - BLOCK_SLIME_BLOCK_STEP("BLOCK_SLIME_STEP"), - BLOCK_SMITHING_TABLE_USE, - BLOCK_SMOKER_SMOKE, - BLOCK_SNOW_BREAK("DIG_SNOW"), - BLOCK_SNOW_FALL, - BLOCK_SNOW_HIT, - BLOCK_SNOW_PLACE, - BLOCK_SNOW_STEP("STEP_SNOW"), - BLOCK_SOUL_SAND_BREAK, - BLOCK_SOUL_SAND_FALL, - BLOCK_SOUL_SAND_HIT, - BLOCK_SOUL_SAND_PLACE, - BLOCK_SOUL_SAND_STEP, - BLOCK_SOUL_SOIL_BREAK, - BLOCK_SOUL_SOIL_FALL, - BLOCK_SOUL_SOIL_HIT, - BLOCK_SOUL_SOIL_PLACE, - BLOCK_SOUL_SOIL_STEP, - BLOCK_STEM_BREAK, - BLOCK_STEM_FALL, - BLOCK_STEM_HIT, - BLOCK_STEM_PLACE, - BLOCK_STEM_STEP, - BLOCK_STONE_BREAK("DIG_STONE"), - BLOCK_STONE_BUTTON_CLICK_OFF, - BLOCK_STONE_BUTTON_CLICK_ON, - BLOCK_STONE_FALL, - BLOCK_STONE_HIT, - BLOCK_STONE_PLACE, - BLOCK_STONE_PRESSURE_PLATE_CLICK_OFF("BLOCK_STONE_PRESSUREPLATE_CLICK_OFF"), - BLOCK_STONE_PRESSURE_PLATE_CLICK_ON("BLOCK_STONE_PRESSUREPLATE_CLICK_ON"), - BLOCK_STONE_STEP("STEP_STONE"), - BLOCK_SWEET_BERRY_BUSH_BREAK, - BLOCK_SWEET_BERRY_BUSH_PLACE, - BLOCK_TRIPWIRE_ATTACH, - BLOCK_TRIPWIRE_CLICK_OFF, - BLOCK_TRIPWIRE_CLICK_ON, - BLOCK_TRIPWIRE_DETACH, - BLOCK_VINE_STEP, - BLOCK_WART_BLOCK_BREAK, - BLOCK_WART_BLOCK_FALL, - BLOCK_WART_BLOCK_HIT, - BLOCK_WART_BLOCK_PLACE, - BLOCK_WART_BLOCK_STEP, - BLOCK_WATER_AMBIENT("WATER"), - BLOCK_WEEPING_VINES_BREAK, - BLOCK_WEEPING_VINES_FALL, - BLOCK_WEEPING_VINES_HIT, - BLOCK_WEEPING_VINES_PLACE, - BLOCK_WEEPING_VINES_STEP, - BLOCK_WET_GRASS_BREAK, - BLOCK_WET_GRASS_FALL, - BLOCK_WET_GRASS_HIT, - BLOCK_WET_GRASS_PLACE("BLOCK_WET_GRASS_HIT"), - BLOCK_WET_GRASS_STEP("BLOCK_WET_GRASS_HIT"), - BLOCK_WOODEN_BUTTON_CLICK_OFF("WOOD_CLICK", "BLOCK_WOOD_BUTTON_CLICK_OFF"), - BLOCK_WOODEN_BUTTON_CLICK_ON("WOOD_CLICK", "BLOCK_WOOD_BUTTON_CLICK_ON"), - BLOCK_WOODEN_DOOR_CLOSE("DOOR_CLOSE"), - BLOCK_WOODEN_DOOR_OPEN("DOOR_OPEN"), - BLOCK_WOODEN_PRESSURE_PLATE_CLICK_OFF("BLOCK_WOOD_PRESSUREPLATE_CLICK_OFF"), - BLOCK_WOODEN_PRESSURE_PLATE_CLICK_ON("BLOCK_WOOD_PRESSUREPLATE_CLICK_ON"), - BLOCK_WOODEN_TRAPDOOR_CLOSE, - BLOCK_WOODEN_TRAPDOOR_OPEN, - BLOCK_WOOD_BREAK("DIG_WOOD"), - BLOCK_WOOD_FALL, - BLOCK_WOOD_HIT, - BLOCK_WOOD_PLACE, - BLOCK_WOOD_STEP("STEP_WOOD"), - BLOCK_WOOL_BREAK("DIG_WOOL", "BLOCK_CLOTH_BREAK"), - BLOCK_WOOL_FALL, - BLOCK_WOOL_HIT("BLOCK_WOOL_FALL"), - BLOCK_WOOL_PLACE("BLOCK_WOOL_FALL"), - BLOCK_WOOL_STEP("STEP_WOOL", "BLOCK_CLOTH_STEP"), - ENCHANT_THORNS_HIT, - ENTITY_ARMOR_STAND_BREAK("ENTITY_ARMORSTAND_BREAK"), - ENTITY_ARMOR_STAND_FALL("ENTITY_ARMORSTAND_FALL"), - ENTITY_ARMOR_STAND_HIT("ENTITY_ARMORSTAND_HIT"), - ENTITY_ARMOR_STAND_PLACE("ENTITY_ARMORSTAND_PLACE"), - ENTITY_ARROW_HIT("ARROW_HIT"), - ENTITY_ARROW_HIT_PLAYER("SUCCESSFUL_HIT"), - ENTITY_ARROW_SHOOT("SHOOT_ARROW"), - ENTITY_BAT_AMBIENT("BAT_IDLE"), - ENTITY_BAT_DEATH("BAT_DEATH"), - ENTITY_BAT_HURT("BAT_HURT"), - ENTITY_BAT_LOOP("BAT_LOOP"), - ENTITY_BAT_TAKEOFF("BAT_TAKEOFF"), - ENTITY_BEE_DEATH, - ENTITY_BEE_HURT, - ENTITY_BEE_LOOP, - ENTITY_BEE_LOOP_AGGRESSIVE, - ENTITY_BEE_POLLINATE, - ENTITY_BEE_STING, - ENTITY_BLAZE_AMBIENT("BLAZE_BREATH"), - ENTITY_BLAZE_BURN, - ENTITY_BLAZE_DEATH("BLAZE_DEATH"), - ENTITY_BLAZE_HURT("BLAZE_HIT"), - ENTITY_BLAZE_SHOOT, - ENTITY_BOAT_PADDLE_LAND, - ENTITY_BOAT_PADDLE_WATER, - ENTITY_CAT_AMBIENT("CAT_MEOW"), - ENTITY_CAT_BEG_FOR_FOOD, - ENTITY_CAT_DEATH, - ENTITY_CAT_EAT, - ENTITY_CAT_HISS("CAT_HISS"), - ENTITY_CAT_HURT("CAT_HIT"), - ENTITY_CAT_PURR("CAT_PURR"), - ENTITY_CAT_PURREOW("CAT_PURREOW"), - ENTITY_CAT_STRAY_AMBIENT, - ENTITY_CHICKEN_AMBIENT("CHICKEN_IDLE"), - ENTITY_CHICKEN_DEATH, - ENTITY_CHICKEN_EGG("CHICKEN_EGG_POP"), - ENTITY_CHICKEN_HURT("CHICKEN_HURT"), - ENTITY_CHICKEN_STEP("CHICKEN_WALK"), - ENTITY_COD_AMBIENT, - ENTITY_COD_DEATH, - ENTITY_COD_FLOP, - ENTITY_COD_HURT, - ENTITY_COW_AMBIENT("COW_IDLE"), - ENTITY_COW_DEATH, - ENTITY_COW_HURT("COW_HURT"), - ENTITY_COW_MILK, - ENTITY_COW_STEP("COW_WALK"), - ENTITY_CREEPER_DEATH("CREEPER_DEATH"), - ENTITY_CREEPER_HURT, - ENTITY_CREEPER_PRIMED("CREEPER_HISS"), - ENTITY_DOLPHIN_AMBIENT, - ENTITY_DOLPHIN_AMBIENT_WATER, - ENTITY_DOLPHIN_ATTACK, - ENTITY_DOLPHIN_DEATH, - ENTITY_DOLPHIN_EAT, - ENTITY_DOLPHIN_HURT, - ENTITY_DOLPHIN_JUMP, - ENTITY_DOLPHIN_PLAY, - ENTITY_DOLPHIN_SPLASH, - ENTITY_DOLPHIN_SWIM, - ENTITY_DONKEY_AMBIENT("DONKEY_IDLE"), - ENTITY_DONKEY_ANGRY("DONKEY_ANGRY"), - ENTITY_DONKEY_CHEST, - ENTITY_DONKEY_DEATH("DONKEY_DEATH"), - ENTITY_DONKEY_EAT, - ENTITY_DONKEY_HURT("DONKEY_HIT"), - ENTITY_DRAGON_FIREBALL_EXPLODE("ENTITY_ENDERDRAGON_FIREBALL_EXPLODE"), - ENTITY_DROWNED_AMBIENT, - ENTITY_DROWNED_AMBIENT_WATER, - ENTITY_DROWNED_DEATH, - ENTITY_DROWNED_DEATH_WATER, - ENTITY_DROWNED_HURT, - ENTITY_DROWNED_HURT_WATER, - ENTITY_DROWNED_SHOOT, - ENTITY_DROWNED_STEP, - ENTITY_DROWNED_SWIM, - ENTITY_EGG_THROW, - ENTITY_ELDER_GUARDIAN_AMBIENT, - ENTITY_ELDER_GUARDIAN_AMBIENT_LAND, - ENTITY_ELDER_GUARDIAN_CURSE, - ENTITY_ELDER_GUARDIAN_DEATH, - ENTITY_ELDER_GUARDIAN_DEATH_LAND, - ENTITY_ELDER_GUARDIAN_FLOP, - ENTITY_ELDER_GUARDIAN_HURT, - ENTITY_ELDER_GUARDIAN_HURT_LAND, - ENTITY_ENDERMAN_AMBIENT("ENDERMAN_IDLE", "ENTITY_ENDERMEN_AMBIENT"), - ENTITY_ENDERMAN_DEATH("ENDERMAN_DEATH", "ENTITY_ENDERMEN_DEATH"), - ENTITY_ENDERMAN_HURT("ENDERMAN_HIT", "ENTITY_ENDERMEN_HURT"), - ENTITY_ENDERMAN_SCREAM("ENDERMAN_SCREAM", "ENTITY_ENDERMEN_SCREAM"), - ENTITY_ENDERMAN_STARE("ENDERMAN_STARE", "ENTITY_ENDERMEN_STARE"), - ENTITY_ENDERMAN_TELEPORT("ENDERMAN_TELEPORT", "ENTITY_ENDERMEN_TELEPORT"), - ENTITY_ENDERMITE_AMBIENT, - ENTITY_ENDERMITE_DEATH, - ENTITY_ENDERMITE_HURT, - ENTITY_ENDERMITE_STEP, - ENTITY_ENDER_DRAGON_AMBIENT("ENDERDRAGON_WINGS", "ENTITY_ENDERDRAGON_AMBIENT"), - ENTITY_ENDER_DRAGON_DEATH("ENDERDRAGON_DEATH", "ENTITY_ENDERDRAGON_DEATH"), - ENTITY_ENDER_DRAGON_FLAP("ENDERDRAGON_WINGS", "ENTITY_ENDERDRAGON_FLAP"), - ENTITY_ENDER_DRAGON_GROWL("ENDERDRAGON_GROWL", "ENTITY_ENDERDRAGON_GROWL"), - ENTITY_ENDER_DRAGON_HURT("ENDERDRAGON_HIT", "ENTITY_ENDERDRAGON_HURT"), - ENTITY_ENDER_DRAGON_SHOOT("ENTITY_ENDERDRAGON_SHOOT"), - ENTITY_ENDER_EYE_DEATH, - ENTITY_ENDER_EYE_LAUNCH("ENTITY_ENDER_EYE_DEATH", "ENTITY_ENDEREYE_DEATH"), - ENTITY_ENDER_PEARL_THROW("ENTITY_ENDERPEARL_THROW"), - ENTITY_EVOKER_AMBIENT("ENTITY_EVOCATION_ILLAGER_AMBIENT"), - ENTITY_EVOKER_CAST_SPELL("ENTITY_EVOCATION_ILLAGER_CAST_SPELL"), - ENTITY_EVOKER_CELEBRATE, - ENTITY_EVOKER_DEATH("ENTITY_EVOCATION_ILLAGER_DEATH"), - ENTITY_EVOKER_FANGS_ATTACK("ENTITY_EVOCATION_FANGS_ATTACK"), - ENTITY_EVOKER_HURT("ENTITY_EVOCATION_ILLAGER_HURT"), - ENTITY_EVOKER_PREPARE_ATTACK("ENTITY_EVOCATION_ILLAGER_PREPARE_ATTACK"), - ENTITY_EVOKER_PREPARE_SUMMON("ENTITY_EVOCATION_ILLAGER_PREPARE_SUMMON"), - ENTITY_EVOKER_PREPARE_WOLOLO("ENTITY_EVOCATION_ILLAGER_PREPARE_WOLOLO"), - ENTITY_EXPERIENCE_BOTTLE_THROW, - ENTITY_EXPERIENCE_ORB_PICKUP("ORB_PICKUP"), - ENTITY_FIREWORK_ROCKET_BLAST("FIREWORK_BLAST", "ENTITY_FIREWORK_BLAST"), - ENTITY_FIREWORK_ROCKET_BLAST_FAR("FIREWORK_BLAST2", "ENTITY_FIREWORK_BLAST_FAR"), - ENTITY_FIREWORK_ROCKET_LARGE_BLAST("FIREWORK_LARGE_BLAST", "ENTITY_FIREWORK_LARGE_BLAST"), - ENTITY_FIREWORK_ROCKET_LARGE_BLAST_FAR("FIREWORK_LARGE_BLAST2", "ENTITY_FIREWORK_LARGE_BLAST_FAR"), - ENTITY_FIREWORK_ROCKET_LAUNCH("FIREWORK_LAUNCH", "ENTITY_FIREWORK_LAUNCH"), - ENTITY_FIREWORK_ROCKET_SHOOT, - ENTITY_FIREWORK_ROCKET_TWINKLE("FIREWORK_TWINKLE", "ENTITY_FIREWORK_TWINKLE"), - ENTITY_FIREWORK_ROCKET_TWINKLE_FAR("FIREWORK_TWINKLE2", "ENTITY_FIREWORK_TWINKLE_FAR"), - ENTITY_FISHING_BOBBER_RETRIEVE, - ENTITY_FISHING_BOBBER_SPLASH("SPLASH2", "ENTITY_BOBBER_SPLASH"), - ENTITY_FISHING_BOBBER_THROW("ENTITY_BOBBER_THROW"), - ENTITY_FISH_SWIM, - ENTITY_FOX_AGGRO, - ENTITY_FOX_AMBIENT, - ENTITY_FOX_BITE, - ENTITY_FOX_DEATH, - ENTITY_FOX_EAT, - ENTITY_FOX_HURT, - ENTITY_FOX_SCREECH, - ENTITY_FOX_SLEEP, - ENTITY_FOX_SNIFF, - ENTITY_FOX_SPIT, - ENTITY_FOX_TELEPORT, - ENTITY_GENERIC_BIG_FALL("FALL_BIG"), - ENTITY_GENERIC_BURN, - ENTITY_GENERIC_DEATH, - ENTITY_GENERIC_DRINK("DRINK"), - ENTITY_GENERIC_EAT("EAT"), - ENTITY_GENERIC_EXPLODE("EXPLODE"), - ENTITY_GENERIC_EXTINGUISH_FIRE, - ENTITY_GENERIC_HURT, - ENTITY_GENERIC_SMALL_FALL("FALL_SMALL"), - ENTITY_GENERIC_SPLASH("SPLASH"), - ENTITY_GENERIC_SWIM("SWIM"), - ENTITY_GHAST_AMBIENT("GHAST_MOAN"), - ENTITY_GHAST_DEATH("GHAST_DEATH"), - ENTITY_GHAST_HURT("GHAST_SCREAM2"), - ENTITY_GHAST_SCREAM("GHAST_SCREAM"), - ENTITY_GHAST_SHOOT("GHAST_FIREBALL"), - ENTITY_GHAST_WARN("GHAST_CHARGE"), - ENTITY_GUARDIAN_AMBIENT, - ENTITY_GUARDIAN_AMBIENT_LAND, - ENTITY_GUARDIAN_ATTACK, - ENTITY_GUARDIAN_DEATH, - ENTITY_GUARDIAN_DEATH_LAND, - ENTITY_GUARDIAN_FLOP, - ENTITY_GUARDIAN_HURT, - ENTITY_GUARDIAN_HURT_LAND, - ENTITY_HOGLIN_AMBIENT, - ENTITY_HOGLIN_ANGRY, - ENTITY_HOGLIN_ATTACK, - ENTITY_HOGLIN_CONVERTED_TO_ZOMBIFIED, - ENTITY_HOGLIN_DEATH, - ENTITY_HOGLIN_HURT, - ENTITY_HOGLIN_RETREAT, - ENTITY_HOGLIN_STEP, - ENTITY_HORSE_AMBIENT("HORSE_IDLE"), - ENTITY_HORSE_ANGRY("HORSE_ANGRY"), - ENTITY_HORSE_ARMOR("HORSE_ARMOR"), - ENTITY_HORSE_BREATHE("HORSE_BREATHE"), - ENTITY_HORSE_DEATH("HORSE_DEATH"), - ENTITY_HORSE_EAT, - ENTITY_HORSE_GALLOP("HORSE_GALLOP"), - ENTITY_HORSE_HURT("HORSE_HIT"), - ENTITY_HORSE_JUMP("HORSE_JUMP"), - ENTITY_HORSE_LAND("HORSE_LAND"), - ENTITY_HORSE_SADDLE("HORSE_SADDLE"), - ENTITY_HORSE_STEP("HORSE_SOFT"), - ENTITY_HORSE_STEP_WOOD("HORSE_WOOD"), - ENTITY_HOSTILE_BIG_FALL("FALL_BIG"), - ENTITY_HOSTILE_DEATH, - ENTITY_HOSTILE_HURT, - ENTITY_HOSTILE_SMALL_FALL("FALL_SMALL"), - ENTITY_HOSTILE_SPLASH("SPLASH"), - ENTITY_HOSTILE_SWIM("SWIM"), - ENTITY_HUSK_AMBIENT, - ENTITY_HUSK_CONVERTED_TO_ZOMBIE, - ENTITY_HUSK_DEATH, - ENTITY_HUSK_HURT, - ENTITY_HUSK_STEP, - ENTITY_ILLUSIONER_AMBIENT("ENTITY_ILLUSION_ILLAGER_AMBIENT"), - ENTITY_ILLUSIONER_CAST_SPELL("ENTITY_ILLUSION_ILLAGER_CAST_SPELL"), - ENTITY_ILLUSIONER_DEATH("ENTITY_ILLUSIONER_CAST_DEATH", "ENTITY_ILLUSION_ILLAGER_DEATH"), - ENTITY_ILLUSIONER_HURT("ENTITY_ILLUSION_ILLAGER_HURT"), - ENTITY_ILLUSIONER_MIRROR_MOVE("ENTITY_ILLUSION_ILLAGER_MIRROR_MOVE"), - ENTITY_ILLUSIONER_PREPARE_BLINDNESS("ENTITY_ILLUSION_ILLAGER_PREPARE_BLINDNESS"), - ENTITY_ILLUSIONER_PREPARE_MIRROR("ENTITY_ILLUSION_ILLAGER_PREPARE_MIRROR"), - ENTITY_IRON_GOLEM_ATTACK("IRONGOLEM_THROW", "ENTITY_IRONGOLEM_ATTACK"), - ENTITY_IRON_GOLEM_DAMAGE, - ENTITY_IRON_GOLEM_DEATH("IRONGOLEM_DEATH", "ENTITY_IRONGOLEM_DEATH"), - ENTITY_IRON_GOLEM_HURT("IRONGOLEM_HIT", "ENTITY_IRONGOLEM_HURT"), - ENTITY_IRON_GOLEM_REPAIR, - ENTITY_IRON_GOLEM_STEP("IRONGOLEM_WALK", "ENTITY_IRONGOLEM_STEP"), - ENTITY_ITEM_BREAK("ITEM_BREAK"), - ENTITY_ITEM_FRAME_ADD_ITEM("ENTITY_ITEMFRAME_ADD_ITEM"), - ENTITY_ITEM_FRAME_BREAK("ENTITY_ITEMFRAME_BREAK"), - ENTITY_ITEM_FRAME_PLACE("ENTITY_ITEMFRAME_PLACE"), - ENTITY_ITEM_FRAME_REMOVE_ITEM("ENTITY_ITEMFRAME_REMOVE_ITEM"), - ENTITY_ITEM_FRAME_ROTATE_ITEM("ENTITY_ITEMFRAME_ROTATE_ITEM"), - ENTITY_ITEM_PICKUP("ITEM_PICKUP"), - ENTITY_LEASH_KNOT_BREAK("ENTITY_LEASHKNOT_BREAK"), - ENTITY_LEASH_KNOT_PLACE("ENTITY_LEASHKNOT_PLACE"), - ENTITY_LIGHTNING_BOLT_IMPACT("AMBIENCE_THUNDER", "ENTITY_LIGHTNING_IMPACT"), - ENTITY_LIGHTNING_BOLT_THUNDER("AMBIENCE_THUNDER", "ENTITY_LIGHTNING_THUNDER"), - ENTITY_LINGERING_POTION_THROW, - ENTITY_LLAMA_AMBIENT, - ENTITY_LLAMA_ANGRY, - ENTITY_LLAMA_CHEST, - ENTITY_LLAMA_DEATH, - ENTITY_LLAMA_EAT, - ENTITY_LLAMA_HURT, - ENTITY_LLAMA_SPIT, - ENTITY_LLAMA_STEP, - ENTITY_LLAMA_SWAG, - ENTITY_MAGMA_CUBE_DEATH("ENTITY_MAGMACUBE_DEATH"), - ENTITY_MAGMA_CUBE_DEATH_SMALL("ENTITY_SMALL_MAGMACUBE_DEATH"), - ENTITY_MAGMA_CUBE_HURT("ENTITY_MAGMACUBE_HURT"), - ENTITY_MAGMA_CUBE_HURT_SMALL("ENTITY_SMALL_MAGMACUBE_HURT"), - ENTITY_MAGMA_CUBE_JUMP("MAGMACUBE_JUMP", "ENTITY_MAGMACUBE_JUMP"), - ENTITY_MAGMA_CUBE_SQUISH("MAGMACUBE_WALK", "ENTITY_MAGMACUBE_SQUISH"), - ENTITY_MAGMA_CUBE_SQUISH_SMALL("MAGMACUBE_WALK2", "ENTITY_SMALL_MAGMACUBE_SQUISH"), - ENTITY_MINECART_INSIDE("MINECART_INSIDE"), - ENTITY_MINECART_RIDING("MINECART_BASE"), - ENTITY_MOOSHROOM_CONVERT, - ENTITY_MOOSHROOM_EAT, - ENTITY_MOOSHROOM_MILK, - ENTITY_MOOSHROOM_SHEAR, - ENTITY_MOOSHROOM_SUSPICIOUS_MILK, - ENTITY_MULE_AMBIENT, - ENTITY_MULE_ANGRY, - ENTITY_MULE_CHEST("ENTITY_MULE_AMBIENT"), - ENTITY_MULE_DEATH("ENTITY_MULE_AMBIENT"), - ENTITY_MULE_EAT, - ENTITY_MULE_HURT("ENTITY_MULE_AMBIENT"), - ENTITY_OCELOT_AMBIENT, - ENTITY_OCELOT_DEATH, - ENTITY_OCELOT_HURT, - ENTITY_PAINTING_BREAK, - ENTITY_PAINTING_PLACE, - ENTITY_PANDA_AGGRESSIVE_AMBIENT, - ENTITY_PANDA_AMBIENT, - ENTITY_PANDA_BITE, - ENTITY_PANDA_CANT_BREED, - ENTITY_PANDA_DEATH, - ENTITY_PANDA_EAT, - ENTITY_PANDA_HURT, - ENTITY_PANDA_PRE_SNEEZE, - ENTITY_PANDA_SNEEZE, - ENTITY_PANDA_STEP, - ENTITY_PANDA_WORRIED_AMBIENT, - ENTITY_PARROT_AMBIENT, - ENTITY_PARROT_DEATH, - ENTITY_PARROT_EAT, - ENTITY_PARROT_FLY, - ENTITY_PARROT_HURT, - ENTITY_PARROT_IMITATE_BLAZE, - ENTITY_PARROT_IMITATE_CREEPER, - ENTITY_PARROT_IMITATE_DROWNED, - ENTITY_PARROT_IMITATE_ELDER_GUARDIAN, - /** - * Removed in 1.15 - */ - ENTITY_PARROT_IMITATE_ENDERMAN, - ENTITY_PARROT_IMITATE_ENDERMITE, - ENTITY_PARROT_IMITATE_ENDER_DRAGON, - ENTITY_PARROT_IMITATE_EVOKER, - ENTITY_PARROT_IMITATE_GHAST, - ENTITY_PARROT_IMITATE_GUARDIAN, - ENTITY_PARROT_IMITATE_HOGLIN, - ENTITY_PARROT_IMITATE_HUSK, - ENTITY_PARROT_IMITATE_ILLUSIONER, - ENTITY_PARROT_IMITATE_MAGMA_CUBE, - ENTITY_PARROT_IMITATE_PHANTOM, - ENTITY_PARROT_IMITATE_PIGLIN, - ENTITY_PARROT_IMITATE_PILLAGER, - /** - * Removed in 1.15 - */ - ENTITY_PARROT_IMITATE_POLAR_BEAR, - ENTITY_PARROT_IMITATE_RAVAGER, - ENTITY_PARROT_IMITATE_SHULKER, - ENTITY_PARROT_IMITATE_SILVERFISH, - ENTITY_PARROT_IMITATE_SKELETON, - ENTITY_PARROT_IMITATE_SLIME, - ENTITY_PARROT_IMITATE_SPIDER, - ENTITY_PARROT_IMITATE_STRAY, - ENTITY_PARROT_IMITATE_VEX, - ENTITY_PARROT_IMITATE_VINDICATOR, - ENTITY_PARROT_IMITATE_WITCH, - ENTITY_PARROT_IMITATE_WITHER, - ENTITY_PARROT_IMITATE_WITHER_SKELETON, - /** - * Removed in 1.15 - */ - ENTITY_PARROT_IMITATE_WOLF, - ENTITY_PARROT_IMITATE_ZOGLIN, - ENTITY_PARROT_IMITATE_ZOMBIE, - ENTITY_PARROT_IMITATE_ZOMBIE_VILLAGER, - ENTITY_PARROT_STEP, - ENTITY_PHANTOM_AMBIENT, - ENTITY_PHANTOM_BITE, - ENTITY_PHANTOM_DEATH, - ENTITY_PHANTOM_FLAP, - ENTITY_PHANTOM_HURT, - ENTITY_PHANTOM_SWOOP, - ENTITY_PIGLIN_ADMIRING_ITEM, - ENTITY_PIGLIN_AMBIENT, - ENTITY_PIGLIN_ANGRY, - ENTITY_PIGLIN_CELEBRATE, - ENTITY_PIGLIN_CONVERTED_TO_ZOMBIFIED, - ENTITY_PIGLIN_DEATH, - ENTITY_PIGLIN_HURT, - ENTITY_PIGLIN_JEALOUS, - ENTITY_PIGLIN_RETREAT, - ENTITY_PIGLIN_STEP, - ENTITY_PIG_AMBIENT("PIG_IDLE"), - ENTITY_PIG_DEATH("PIG_DEATH"), - ENTITY_PIG_HURT, - ENTITY_PIG_SADDLE("ENTITY_PIG_HURT"), - ENTITY_PIG_STEP("PIG_WALK"), - ENTITY_PILLAGER_AMBIENT, - ENTITY_PILLAGER_CELEBRATE, - ENTITY_PILLAGER_DEATH, - ENTITY_PILLAGER_HURT, - ENTITY_PLAYER_ATTACK_CRIT, - ENTITY_PLAYER_ATTACK_KNOCKBACK, - ENTITY_PLAYER_ATTACK_NODAMAGE, - ENTITY_PLAYER_ATTACK_STRONG("SUCCESSFUL_HIT"), - ENTITY_PLAYER_ATTACK_SWEEP, - ENTITY_PLAYER_ATTACK_WEAK, - ENTITY_PLAYER_BIG_FALL("FALL_BIG"), - ENTITY_PLAYER_BREATH, - ENTITY_PLAYER_BURP("BURP"), - ENTITY_PLAYER_DEATH, - ENTITY_PLAYER_HURT("HURT_FLESH"), - ENTITY_PLAYER_HURT_DROWN, - ENTITY_PLAYER_HURT_ON_FIRE, - ENTITY_PLAYER_HURT_SWEET_BERRY_BUSH, - ENTITY_PLAYER_LEVELUP("LEVEL_UP"), - ENTITY_PLAYER_SMALL_FALL("FALL_SMALL"), - ENTITY_PLAYER_SPLASH("SLASH"), - ENTITY_PLAYER_SPLASH_HIGH_SPEED("SPLASH"), - ENTITY_PLAYER_SWIM("SWIM"), - ENTITY_POLAR_BEAR_AMBIENT, - ENTITY_POLAR_BEAR_AMBIENT_BABY("ENTITY_POLAR_BEAR_BABY_AMBIENT"), - ENTITY_POLAR_BEAR_DEATH, - ENTITY_POLAR_BEAR_HURT, - ENTITY_POLAR_BEAR_STEP, - ENTITY_POLAR_BEAR_WARNING, - ENTITY_PUFFER_FISH_AMBIENT, - ENTITY_PUFFER_FISH_BLOW_OUT, - ENTITY_PUFFER_FISH_BLOW_UP, - ENTITY_PUFFER_FISH_DEATH, - ENTITY_PUFFER_FISH_FLOP, - ENTITY_PUFFER_FISH_HURT, - ENTITY_PUFFER_FISH_STING, - ENTITY_RABBIT_AMBIENT, - ENTITY_RABBIT_ATTACK, - ENTITY_RABBIT_DEATH, - ENTITY_RABBIT_HURT, - ENTITY_RABBIT_JUMP, - ENTITY_RAVAGER_AMBIENT, - ENTITY_RAVAGER_ATTACK, - ENTITY_RAVAGER_CELEBRATE, - ENTITY_RAVAGER_DEATH, - ENTITY_RAVAGER_HURT, - ENTITY_RAVAGER_ROAR, - ENTITY_RAVAGER_STEP, - ENTITY_RAVAGER_STUNNED, - ENTITY_SALMON_AMBIENT, - ENTITY_SALMON_DEATH, - ENTITY_SALMON_FLOP, - ENTITY_SALMON_HURT("ENTITY_SALMON_FLOP"), - ENTITY_SHEEP_AMBIENT("SHEEP_IDLE"), - ENTITY_SHEEP_DEATH, - ENTITY_SHEEP_HURT, - ENTITY_SHEEP_SHEAR("SHEEP_SHEAR"), - ENTITY_SHEEP_STEP("SHEEP_WALK"), - ENTITY_SHULKER_AMBIENT, - ENTITY_SHULKER_BULLET_HIT, - ENTITY_SHULKER_BULLET_HURT, - ENTITY_SHULKER_CLOSE, - ENTITY_SHULKER_DEATH, - ENTITY_SHULKER_HURT, - ENTITY_SHULKER_HURT_CLOSED, - ENTITY_SHULKER_OPEN, - ENTITY_SHULKER_SHOOT, - ENTITY_SHULKER_TELEPORT, - ENTITY_SILVERFISH_AMBIENT("SILVERFISH_IDLE"), - ENTITY_SILVERFISH_DEATH("SILVERFISH_KILL"), - ENTITY_SILVERFISH_HURT("SILVERFISH_HIT"), - ENTITY_SILVERFISH_STEP("SILVERFISH_WALK"), - ENTITY_SKELETON_AMBIENT("SKELETON_IDLE"), - ENTITY_SKELETON_DEATH("SKELETON_DEATH"), - ENTITY_SKELETON_HORSE_AMBIENT("HORSE_SKELETON_IDLE"), - ENTITY_SKELETON_HORSE_AMBIENT_WATER, - ENTITY_SKELETON_HORSE_DEATH("HORSE_SKELETON_DEATH"), - ENTITY_SKELETON_HORSE_GALLOP_WATER, - ENTITY_SKELETON_HORSE_HURT("HORSE_SKELETON_HIT"), - ENTITY_SKELETON_HORSE_JUMP_WATER, - ENTITY_SKELETON_HORSE_STEP_WATER, - ENTITY_SKELETON_HORSE_SWIM, - ENTITY_SKELETON_HURT("SKELETON_HURT"), - ENTITY_SKELETON_SHOOT, - ENTITY_SKELETON_STEP("SKELETON_WALK"), - ENTITY_SLIME_ATTACK("SLIME_ATTACK"), - ENTITY_SLIME_DEATH, - ENTITY_SLIME_DEATH_SMALL, - ENTITY_SLIME_HURT, - ENTITY_SLIME_HURT_SMALL("ENTITY_SMALL_SLIME_HURT"), - ENTITY_SLIME_JUMP("SLIME_WALK"), - ENTITY_SLIME_JUMP_SMALL("SLIME_WALK2", "ENTITY_SMALL_SLIME_SQUISH"), - ENTITY_SLIME_SQUISH("SLIME_WALK2"), - ENTITY_SLIME_SQUISH_SMALL("ENTITY_SMALL_SLIME_SQUISH"), - ENTITY_SNOWBALL_THROW, - ENTITY_SNOW_GOLEM_AMBIENT("ENTITY_SNOWMAN_AMBIENT"), - ENTITY_SNOW_GOLEM_DEATH("ENTITY_SNOWMAN_DEATH"), - ENTITY_SNOW_GOLEM_HURT("ENTITY_SNOWMAN_HURT"), - ENTITY_SNOW_GOLEM_SHEAR, - ENTITY_SNOW_GOLEM_SHOOT("ENTITY_SNOWMAN_SHOOT"), - ENTITY_SPIDER_AMBIENT("SPIDER_IDLE"), - ENTITY_SPIDER_DEATH("SPIDER_DEATH"), - ENTITY_SPIDER_HURT, - ENTITY_SPIDER_STEP("SPIDER_WALK"), - ENTITY_SPLASH_POTION_BREAK, - ENTITY_SPLASH_POTION_THROW, - ENTITY_SQUID_AMBIENT, - ENTITY_SQUID_DEATH, - ENTITY_SQUID_HURT, - ENTITY_SQUID_SQUIRT, - ENTITY_STRAY_AMBIENT, - ENTITY_STRAY_DEATH, - ENTITY_STRAY_HURT, - ENTITY_STRAY_STEP, - ENTITY_STRIDER_AMBIENT, - ENTITY_STRIDER_DEATH, - ENTITY_STRIDER_EAT, - ENTITY_STRIDER_HAPPY, - ENTITY_STRIDER_HURT, - ENTITY_STRIDER_RETREAT, - ENTITY_STRIDER_SADDLE, - ENTITY_STRIDER_STEP, - ENTITY_STRIDER_STEP_LAVA, - ENTITY_TNT_PRIMED("FUSE"), - ENTITY_TROPICAL_FISH_AMBIENT, - ENTITY_TROPICAL_FISH_DEATH, - ENTITY_TROPICAL_FISH_FLOP("ENTITY_TROPICAL_FISH_DEATH"), - ENTITY_TROPICAL_FISH_HURT, - ENTITY_TURTLE_AMBIENT_LAND, - ENTITY_TURTLE_DEATH, - ENTITY_TURTLE_DEATH_BABY, - ENTITY_TURTLE_EGG_BREAK, - ENTITY_TURTLE_EGG_CRACK, - ENTITY_TURTLE_EGG_HATCH, - ENTITY_TURTLE_HURT, - ENTITY_TURTLE_HURT_BABY, - ENTITY_TURTLE_LAY_EGG, - ENTITY_TURTLE_SHAMBLE, - ENTITY_TURTLE_SHAMBLE_BABY, - ENTITY_TURTLE_SWIM, - ENTITY_VEX_AMBIENT, - ENTITY_VEX_CHARGE, - ENTITY_VEX_DEATH, - ENTITY_VEX_HURT, - ENTITY_VILLAGER_AMBIENT("VILLAGER_IDLE"), - ENTITY_VILLAGER_CELEBRATE, - ENTITY_VILLAGER_DEATH("VILLAGER_DEATH"), - ENTITY_VILLAGER_HURT("VILLAGER_HIT"), - ENTITY_VILLAGER_NO("VILLAGER_NO"), - ENTITY_VILLAGER_TRADE("VILLAGER_HAGGLE", "ENTITY_VILLAGER_TRADING"), - ENTITY_VILLAGER_WORK_ARMORER, - ENTITY_VILLAGER_WORK_BUTCHER, - ENTITY_VILLAGER_WORK_CARTOGRAPHER, - ENTITY_VILLAGER_WORK_CLERIC, - ENTITY_VILLAGER_WORK_FARMER, - ENTITY_VILLAGER_WORK_FISHERMAN, - ENTITY_VILLAGER_WORK_FLETCHER, - ENTITY_VILLAGER_WORK_LEATHERWORKER, - ENTITY_VILLAGER_WORK_LIBRARIAN, - ENTITY_VILLAGER_WORK_MASON, - ENTITY_VILLAGER_WORK_SHEPHERD, - ENTITY_VILLAGER_WORK_TOOLSMITH, - ENTITY_VILLAGER_WORK_WEAPONSMITH, - ENTITY_VILLAGER_YES("VILLAGER_YES"), - ENTITY_VINDICATOR_AMBIENT("ENTITY_VINDICATION_ILLAGER_AMBIENT"), - ENTITY_VINDICATOR_CELEBRATE, - ENTITY_VINDICATOR_DEATH("ENTITY_VINDICATION_ILLAGER_DEATH"), - ENTITY_VINDICATOR_HURT("ENTITY_VINDICATION_ILLAGER_HURT"), - ENTITY_WANDERING_TRADER_AMBIENT, - ENTITY_WANDERING_TRADER_DEATH, - ENTITY_WANDERING_TRADER_DISAPPEARED, - ENTITY_WANDERING_TRADER_DRINK_MILK, - ENTITY_WANDERING_TRADER_DRINK_POTION, - ENTITY_WANDERING_TRADER_HURT, - ENTITY_WANDERING_TRADER_NO, - ENTITY_WANDERING_TRADER_REAPPEARED, - ENTITY_WANDERING_TRADER_TRADE, - ENTITY_WANDERING_TRADER_YES, - ENTITY_WITCH_AMBIENT, - ENTITY_WITCH_CELEBRATE, - ENTITY_WITCH_DEATH, - ENTITY_WITCH_DRINK, - ENTITY_WITCH_HURT, - ENTITY_WITCH_THROW, - ENTITY_WITHER_AMBIENT("WITHER_IDLE"), - ENTITY_WITHER_BREAK_BLOCK, - ENTITY_WITHER_DEATH("WITHER_DEATH"), - ENTITY_WITHER_HURT("WITHER_HURT"), - ENTITY_WITHER_SHOOT("WITHER_SHOOT"), - ENTITY_WITHER_SKELETON_AMBIENT, - ENTITY_WITHER_SKELETON_DEATH, - ENTITY_WITHER_SKELETON_HURT, - ENTITY_WITHER_SKELETON_STEP, - ENTITY_WITHER_SPAWN("WITHER_SPAWN"), - ENTITY_WOLF_AMBIENT("WOLF_BARK"), - ENTITY_WOLF_DEATH("WOLF_DEATH"), - ENTITY_WOLF_GROWL("WOLF_GROWL"), - ENTITY_WOLF_HOWL("WOLF_HOWL"), - ENTITY_WOLF_HURT("WOLF_HURT"), - ENTITY_WOLF_PANT("WOLF_PANT"), - ENTITY_WOLF_SHAKE("WOLF_SHAKE"), - ENTITY_WOLF_STEP("WOLF_WALK"), - ENTITY_WOLF_WHINE("WOLF_WHINE"), - ENTITY_ZOGLIN_AMBIENT, - ENTITY_ZOGLIN_ANGRY, - ENTITY_ZOGLIN_ATTACK, - ENTITY_ZOGLIN_DEATH, - ENTITY_ZOGLIN_HURT, - ENTITY_ZOGLIN_STEP, - ENTITY_ZOMBIE_AMBIENT("ZOMBIE_IDLE"), - ENTITY_ZOMBIE_ATTACK_IRON_DOOR("ZOMBIE_METAL"), - ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR("ZOMBIE_WOOD", "ENTITY_ZOMBIE_ATTACK_DOOR_WOOD"), - ENTITY_ZOMBIE_BREAK_WOODEN_DOOR("ZOMBIE_WOODBREAK", "ENTITY_ZOMBIE_BREAK_DOOR_WOOD"), - ENTITY_ZOMBIE_CONVERTED_TO_DROWNED, - ENTITY_ZOMBIE_DEATH("ZOMBIE_DEATH"), - ENTITY_ZOMBIE_DESTROY_EGG, - ENTITY_ZOMBIE_HORSE_AMBIENT("HORSE_ZOMBIE_IDLE"), - ENTITY_ZOMBIE_HORSE_DEATH("HORSE_ZOMBIE_DEATH"), - ENTITY_ZOMBIE_HORSE_HURT("HORSE_ZOMBIE_HIT"), - ENTITY_ZOMBIE_HURT("ZOMBIE_HURT"), - ENTITY_ZOMBIE_INFECT("ZOMBIE_INFECT"), - ENTITY_ZOMBIE_STEP("ZOMBIE_WALK"), - ENTITY_ZOMBIE_VILLAGER_AMBIENT, - ENTITY_ZOMBIE_VILLAGER_CONVERTED("ZOMBIE_UNFECT"), - - ENTITY_ZOMBIE_VILLAGER_CURE("ZOMBIE_REMEDY"), - ENTITY_ZOMBIE_VILLAGER_DEATH, - ENTITY_ZOMBIE_VILLAGER_HURT, - ENTITY_ZOMBIE_VILLAGER_STEP, - ENTITY_ZOMBIFIED_PIGLIN_AMBIENT("ZOMBE_PIG_IDLE", "ENTITY_ZOMBIE_PIG_AMBIENT", "ENTITY_ZOMBIE_PIGMAN_AMBIENT"), - ENTITY_ZOMBIFIED_PIGLIN_ANGRY("ZOMBIE_PIG_ANGRY", "ENTITY_ZOMBIE_PIG_ANGRY", "ENTITY_ZOMBIE_PIGMAN_ANGRY"), - ENTITY_ZOMBIFIED_PIGLIN_DEATH("ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIGMAN_DEATH"), - ENTITY_ZOMBIFIED_PIGLIN_HURT("ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIGMAN_HURT"), - EVENT_RAID_HORN, - ITEM_ARMOR_EQUIP_CHAIN, - ITEM_ARMOR_EQUIP_DIAMOND, - ITEM_ARMOR_EQUIP_ELYTRA, - ITEM_ARMOR_EQUIP_GENERIC, - ITEM_ARMOR_EQUIP_GOLD, - ITEM_ARMOR_EQUIP_IRON, - ITEM_ARMOR_EQUIP_LEATHER, - ITEM_ARMOR_EQUIP_NETHERITE, - ITEM_ARMOR_EQUIP_TURTLE, - ITEM_AXE_STRIP, - ITEM_BOOK_PAGE_TURN, - ITEM_BOOK_PUT, - ITEM_BOTTLE_EMPTY, - ITEM_BOTTLE_FILL, - ITEM_BOTTLE_FILL_DRAGONBREATH, - ITEM_BUCKET_EMPTY, - ITEM_BUCKET_EMPTY_FISH, - ITEM_BUCKET_EMPTY_LAVA, - ITEM_BUCKET_FILL, - ITEM_BUCKET_FILL_FISH, - ITEM_BUCKET_FILL_LAVA, - ITEM_CHORUS_FRUIT_TELEPORT, - ITEM_CROP_PLANT, - ITEM_CROSSBOW_HIT, - ITEM_CROSSBOW_LOADING_END, - ITEM_CROSSBOW_LOADING_MIDDLE, - ITEM_CROSSBOW_LOADING_START, - ITEM_CROSSBOW_QUICK_CHARGE_1, - ITEM_CROSSBOW_QUICK_CHARGE_2, - ITEM_CROSSBOW_QUICK_CHARGE_3, - ITEM_CROSSBOW_SHOOT, - ITEM_ELYTRA_FLYING, - ITEM_FIRECHARGE_USE, - ITEM_FLINTANDSTEEL_USE("FIRE_IGNITE"), - ITEM_HOE_TILL, - ITEM_HONEY_BOTTLE_DRINK, - ITEM_LODESTONE_COMPASS_LOCK, - ITEM_NETHER_WART_PLANT, - ITEM_SHIELD_BLOCK, - ITEM_SHIELD_BREAK, - ITEM_SHOVEL_FLATTEN, - ITEM_SWEET_BERRIES_PICK_FROM_BUSH, - ITEM_TOTEM_USE, - ITEM_TRIDENT_HIT, - ITEM_TRIDENT_HIT_GROUND, - ITEM_TRIDENT_RETURN, - ITEM_TRIDENT_RIPTIDE_1, - ITEM_TRIDENT_RIPTIDE_2("ITEM_TRIDENT_RIPTIDE_1"), - ITEM_TRIDENT_RIPTIDE_3("ITEM_TRIDENT_RIPTIDE_1"), - ITEM_TRIDENT_THROW, - ITEM_TRIDENT_THUNDER, - MUSIC_CREATIVE, - MUSIC_CREDITS, - MUSIC_DISC_11("RECORD_11"), - MUSIC_DISC_13("RECORD_13"), - MUSIC_DISC_BLOCKS("RECORD_BLOCKS"), - MUSIC_DISC_CAT("RECORD_CAT"), - MUSIC_DISC_CHIRP("RECORD_CHIRP"), - MUSIC_DISC_FAR("RECORD_FAR"), - MUSIC_DISC_MALL("RECORD_MALL"), - MUSIC_DISC_MELLOHI("RECORD_MELLOHI"), - MUSIC_DISC_PIGSTEP, - MUSIC_DISC_STAL("RECORD_STAL"), - MUSIC_DISC_STRAD("RECORD_STRAD"), - MUSIC_DISC_WAIT("RECORD_WAIT"), - MUSIC_DISC_WARD("RECORD_WARD"), - MUSIC_DRAGON, - MUSIC_END, - MUSIC_GAME, - MUSIC_MENU, - MUSIC_NETHER_BASALT_DELTAS("MUSIC_NETHER"), - MUSIC_NETHER_CRIMSON_FOREST, - MUSIC_NETHER_NETHER_WASTES, - MUSIC_NETHER_SOUL_SAND_VALLEY, - MUSIC_NETHER_WARPED_FOREST, - MUSIC_UNDER_WATER, - PARTICLE_SOUL_ESCAPE, - UI_BUTTON_CLICK("CLICK"), - UI_CARTOGRAPHY_TABLE_TAKE_RESULT, - UI_LOOM_SELECT_PATTERN, - UI_LOOM_TAKE_RESULT, - UI_STONECUTTER_SELECT_RECIPE, - UI_STONECUTTER_TAKE_RESULT, - UI_TOAST_CHALLENGE_COMPLETE, - UI_TOAST_IN, - UI_TOAST_OUT, - WEATHER_RAIN("AMBIENCE_RAIN"), - WEATHER_RAIN_ABOVE; - - - /** - * Cached list of {@link XSound#values()} to avoid allocating memory for - * calling the method every time. - * This list is unmodifiable. - * - * @since 2.0.0 - */ - public static final XSound[] VALUES = values(); - - /** - * Guava (Google Core Libraries for Java)'s cache for performance and timed caches. - * Caches the parsed {@link Sound} objects instead of string. Because it has to go through catching exceptions again - * since {@link Sound} class doesn't have a method like {@link Material#getMaterial(String)}. - * So caching these would be more efficient. - * - * @since 2.0.0 - */ - private static final Cache> CACHE = CacheBuilder.newBuilder() - .expireAfterAccess(10, TimeUnit.MINUTES) - .build(); - - /** - * We don't want to use {@link Enums#getIfPresent(Class, String)} to avoid a few checks. - * - * @since 3.1.0 - */ - private static final Map NAMES = new HashMap<>(); - /** - * Since {@link Sound} doesn't provde a method to get a sound from a method like {@link Material#getMaterial(String)} - * - * @since 3.1.0 - */ - private static final Map BUKKIT_NAMES = new HashMap<>(); - - static { - for (Sound sound : Sound.values()) BUKKIT_NAMES.put(sound.name(), sound); - for (XSound sound : VALUES) { - NAMES.put(sound.name(), sound); - for (String legacy : sound.getLegacy()) { - NAMES.putIfAbsent(legacy, sound); - } - } - } - - private final String[] legacy; - - XSound(String... legacy) { - this.legacy = legacy; - } - - /** - * Attempts to build the string like an enum name.
- * Removes all the spaces, numbers and extra non-English characters. Also removes some config/in-game based strings. - * While this method is hard to maintain, it's extremely efficient. It's approximately more than x5 times faster than - * the normal RegEx + String Methods approach for both formatted and unformatted material names. - * - * @param name the sound name to modify. - * @return a Sound enum name. - * @since 1.0.0 - */ - @Nonnull - private static String format(@Nonnull String name) { - int len = name.length(); - char[] chs = new char[len]; - int count = 0; - boolean appendUnderline = false; - - for (int i = 0; i < len; i++) { - char ch = name.charAt(i); - - if (!appendUnderline && count != 0 && (ch == '-' || ch == ' ' || ch == '_') && chs[count] != '_') appendUnderline = true; - else { - boolean number = false; - if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) { - if (appendUnderline) { - chs[count++] = '_'; - appendUnderline = false; - } - - if (number) chs[count++] = ch; - else chs[count++] = (char) (ch & 0x5f); - } - } - } - - return new String(chs, 0, count); - } - - /** - * Parses the XSound with the given name. - * - * @param sound the name of the sound. - * @return a matched XSound. - * @since 1.0.0 - */ - @Nonnull - public static Optional matchXSound(@Nonnull String sound) { - Validate.notEmpty(sound, "Cannot match XSound of a null or empty sound name"); - return getIfPresent(format(sound)); - } - - /** - * Parses the XSound with the given bukkit sound. - * - * @param sound the Bukkit sound. - * @return a matched sound. - * @throws IllegalArgumentException may be thrown as an unexpected exception. - * @since 2.0.0 - */ - @Nonnull - public static XSound matchXSound(@Nonnull Sound sound) { - Objects.requireNonNull(sound, "Cannot match XSound of a null sound"); - return matchXSound(sound.name()) - .orElseThrow(() -> new IllegalArgumentException("Unsupported Sound: " + sound.name())); - } - - /** - * @see #play(Location, String) - * @since 1.0.0 - */ - @Nullable - public static CompletableFuture play(@Nonnull Player player, @Nullable String sound) { - Objects.requireNonNull(player, "Cannot play sound to null player"); - return parse(player, player.getLocation(), sound, true); - } - - /** - * @see #play(Location, String) - * @since 3.0.0 - */ - @Nullable - public static CompletableFuture play(@Nonnull Location location, @Nullable String sound) { - return parse(null, location, sound, true); - } - - /** - * Just an extra feature that loads sounds from strings. - * Useful for getting sounds from config files. - * Sounds are thread safe. - *

- * It's strongly recommended to use this method while using it inside a loop. - * This can help to avoid parsing the sound properties multiple times. - * A simple usage of using it in a loop is: - *

-     *     Record record = XSound.parse(player, location, sound, false).join();
-     *     // Loop:
-     *     if (record != null) record.play();
-     * 
- *

- * This will also ignore {@code none} and {@code null} strings. - *

- * Format: [LOC:]Sound, [Volume], [Pitch]
- * Where {@code LOC:} will play the sound at the location if a player is specified. - * A sound played at a location will be heard by everyone around. - * Comma separators are optional. - *

- * Examples: - *

- *

-     *     LOC:ENTITY_PLAYER_BURP, 2.5f, 0.5
-     *     ENTITY_PLAYER_BURP, 0.5, 1f
-     *     BURP 0.5f 1
-     *     MUSIC_END, 10f
-     *     none
-     *     null
-     * 
- * - * @param player the only player to play the sound to if requested to do so. - * @param location the location to play the sound to. - * @param sound the string of the sound with volume and pitch (if needed). - * @param play if the sound should be played right away. - * @since 3.0.0 - */ - @Nullable - public static CompletableFuture parse(@Nullable Player player, @Nonnull Location location, @Nullable String sound, boolean play) { - Objects.requireNonNull(location, "Cannot play sound to null location"); - if (Strings.isNullOrEmpty(sound) || sound.equalsIgnoreCase("none")) return null; - - return CompletableFuture.supplyAsync(() -> { - String[] split = StringUtils.split(StringUtils.deleteWhitespace(sound), ','); - if (split.length == 0) split = StringUtils.split(sound, ' '); - - String name = split[0]; - boolean playAtLocation = player == null; - if (!playAtLocation && StringUtils.startsWithIgnoreCase(name, "loc:")) { - name = name.substring(4); - playAtLocation = true; - } - Optional typeOpt = matchXSound(name); - if (!typeOpt.isPresent()) return null; - Sound type = typeOpt.get().parseSound(); - if (type == null) return null; - - float volume = 1.0f; - float pitch = 1.0f; - - try { - if (split.length > 1) { - volume = Float.parseFloat(split[1]); - if (split.length > 2) pitch = Float.parseFloat(split[2]); - } - } catch (NumberFormatException ignored) { - } - - Record record = new Record(type, player, location, volume, pitch, playAtLocation); - if (play) record.play(); - return record; - }).exceptionally((ex) -> { - System.err.println("Could not play sound for string: " + sound); - ex.printStackTrace(); - return null; - }); - } - - /** - * Stops all the playing musics (not all the sounds) - *

- * Note that this method will only work for the sound - * that are sent from {@link Player#playSound} and - * the sounds played from the client will not be - * affected by this. - * - * @param player the player to stop all the sounds from. - * @see #stopSound(Player) - * @since 2.0.0 - */ - @Nonnull - public static CompletableFuture stopMusic(@Nonnull Player player) { - Objects.requireNonNull(player, "Cannot stop playing musics from null player"); - - return CompletableFuture.runAsync(() -> { - // We don't need to cache because it's rarely used. - XSound[] musics = {MUSIC_CREATIVE, MUSIC_CREDITS, - MUSIC_DISC_11, MUSIC_DISC_13, MUSIC_DISC_BLOCKS, MUSIC_DISC_CAT, MUSIC_DISC_CHIRP, - MUSIC_DISC_FAR, MUSIC_DISC_MALL, MUSIC_DISC_MELLOHI, MUSIC_DISC_STAL, - MUSIC_DISC_STRAD, MUSIC_DISC_WAIT, MUSIC_DISC_WARD, - MUSIC_DRAGON, MUSIC_END, MUSIC_GAME, MUSIC_MENU, MUSIC_NETHER_BASALT_DELTAS, MUSIC_UNDER_WATER, - MUSIC_NETHER_CRIMSON_FOREST, MUSIC_NETHER_WARPED_FOREST}; - - for (XSound music : musics) { - Sound sound = music.parseSound(); - if (sound != null) player.stopSound(sound); - } - }); - } - - /** - * Gets the {@link XSound} with this name without throwing an exception. - * - * @param name the name of the sound. - * @return an optional that can be empty. - * @since 5.1.0 - */ - @Nonnull - private static Optional getIfPresent(@Nonnull String name) { - return Optional.ofNullable(NAMES.get(name)); - } - - /** - * In most cases your should be using {@link #name()} instead. - * - * @return a friendly readable string name. - */ - @Override - public String toString() { - return WordUtils.capitalize(this.name().replace('_', ' ').toLowerCase(Locale.ENGLISH)); - } - - /** - * Gets all the previous sound names used for this sound. - * - * @return a list of legacy sound names. - * @since 1.0.0 - */ - @Nonnull - public String[] getLegacy() { - return legacy; - } - - /** - * Parses the XSound as a {@link Sound} based on the server version. - * - * @return the vanilla sound. - * @since 1.0.0 - */ - @Nullable - @SuppressWarnings("OptionalAssignedToNull") - public Sound parseSound() { - Optional cachedSound = CACHE.getIfPresent(this); - if (cachedSound != null) return cachedSound.orElse(null); - Sound sound; - - // Since Sound class doesn't have a getSound() method we'll use Guava so - // it can cache it for us. - sound = BUKKIT_NAMES.get(this.name()); - - if (sound == null) { - for (String legacy : this.legacy) { - sound = BUKKIT_NAMES.get(legacy); - if (sound != null) break; - } - } - - // Put nulls too, because there's no point of parsing them again if it's going to give us null again. - CACHE.put(this, Optional.ofNullable(sound)); - return sound; - } - - /** - * Checks if this sound is supported in the current Minecraft version. - *

- * An invocation of this method yields exactly the same result as the expression: - *

- *

- * {@link #parseSound()} != null - *
- * - * @return true if the current version has this sound, otherwise false. - * @since 1.0.0 - */ - public boolean isSupported() { - return this.parseSound() != null; - } - - /** - * Plays a sound repeatedly with the given delay at a moving target's location. - * - * @param plugin the plugin handling schedulers. (You can replace this with a static instance) - * @param entity the entity to play the sound to. We exactly need an entity to keep the track of location changes. - * @param volume the volume of the sound. - * @param pitch the pitch of the sound. - * @param repeat the amount of times to repeat playing. - * @param delay the delay between each repeat. - * @see #play(Location, float, float) - * @since 2.0.0 - */ - @Nonnull - public BukkitTask playRepeatedly(@Nonnull JavaPlugin plugin, @Nonnull Entity entity, float volume, float pitch, int repeat, int delay) { - Objects.requireNonNull(plugin, "Cannot play repeating sound from null plugin"); - Objects.requireNonNull(entity, "Cannot play repeating sound at null location"); - - Validate.isTrue(repeat > 0, "Cannot repeat playing sound " + repeat + " times"); - Validate.isTrue(delay > 0, "Delay ticks must be at least 1"); - - return new BukkitRunnable() { - int repeating = repeat; - - @Override - public void run() { - play(entity.getLocation(), volume, pitch); - if (repeating-- == 0) cancel(); - } - }.runTaskTimer(plugin, 0, delay); - } - - /** - * Plays an instrument's notes in an ascending form. - * This method is not really relevant to this utility class, but a nice feature. - * - * @param plugin the plugin handling schedulers. - * @param player the player to play the note from. - * @param playTo the entity to play the note to. - * @param instrument the instrument. - * @param ascendLevel the ascend level of notes. Can only be positive and not higher than 7 - * @param delay the delay between each play. - * @since 2.0.0 - */ - @Nonnull - public BukkitTask playAscendingNote(@Nonnull JavaPlugin plugin, @Nonnull Player player, @Nonnull Entity playTo, @Nonnull Instrument instrument, int ascendLevel, int delay) { - Objects.requireNonNull(player, "Cannot play note from null player"); - Objects.requireNonNull(playTo, "Cannot play note to null entity"); - - Validate.isTrue(ascendLevel > 0, "Note ascend level cannot be lower than 1"); - Validate.isTrue(ascendLevel <= 7, "Note ascend level cannot be greater than 7"); - Validate.isTrue(delay > 0, "Delay ticks must be at least 1"); - - return new BukkitRunnable() { - int repeating = ascendLevel; - - @Override - public void run() { - player.playNote(playTo.getLocation(), instrument, Note.natural(1, Note.Tone.values()[ascendLevel - repeating])); - if (repeating-- == 0) cancel(); - } - }.runTaskTimerAsynchronously(plugin, 0, delay); - } - - /** - * Stops playing the specified sound from the player. - * - * @param player the player to stop playing the sound to. - * @see #stopMusic(Player) - * @since 2.0.0 - */ - public void stopSound(@Nonnull Player player) { - Objects.requireNonNull(player, "Cannot stop playing sound from null player"); - - Sound sound = this.parseSound(); - if (sound != null) player.stopSound(sound); - } - - /** - * Plays a normal sound to an entity. - * - * @param entity the entity to play the sound to. - * @since 1.0.0 - */ - public void play(@Nonnull Entity entity) { - play(entity, 1.0f, 1.0f); - } - - /** - * Plays a sound to an entity with the given volume and pitch. - * - * @param entity the entity to play the sound to. - * @param volume the volume of the sound, 1 is normal. - * @param pitch the pitch of the sound, 0 is normal. - * @since 1.0.0 - */ - public void play(@Nonnull Entity entity, float volume, float pitch) { - Objects.requireNonNull(entity, "Cannot play sound to a null entity"); - if (entity instanceof Player) { - Sound sound = this.parseSound(); - if (sound == null) return; - ((Player) entity).playSound(entity.getLocation(), sound, volume, pitch); - } else { - play(entity.getLocation(), volume, pitch); - } - } - - /** - * Plays a normal sound in a location. - * - * @param location the location to play the sound in. - * @since 2.0.0 - */ - public void play(@Nonnull Location location) { - play(location, 1.0f, 1.0f); - } - - /** - * Plays a sound in a location with the given volume and pitch. - * - * @param location the location to play this sound. - * @param volume the volume of the sound, 1 is normal. - * @param pitch the pitch of the sound, 0 is normal. - * @since 2.0.0 - */ - public void play(@Nonnull Location location, float volume, float pitch) { - Objects.requireNonNull(location, "Cannot play sound to null location"); - Sound sound = this.parseSound(); - if (sound == null) return; - location.getWorld().playSound(location, sound, volume, pitch); - } - - /** - * A class to help caching sound properties parsed from config. - * - * @since 3.0.0 - */ - public static class Record { - public final Sound sound; - public final Player player; - public final Location location; - public final float volume; - public final float pitch; - public final boolean playAtLocation; - - public Record(@Nonnull Sound sound, @Nullable Player player, @Nonnull Location location, float volume, float pitch, boolean playAtLocation) { - this.sound = sound; - this.player = player; - this.location = location; - this.volume = volume; - this.pitch = pitch; - this.playAtLocation = playAtLocation; - } - - /** - * Plays the sound with the given options and updating the players location. - * - * @since 3.0.0 - */ - public void play() { - play(player == null ? location : player.getLocation()); - } - - /** - * Plays the sound with the updated location. - * - * @param updatedLocation the upated location. - * @since 3.0.0 - */ - public void play(Location updatedLocation) { - if (playAtLocation) location.getWorld().playSound(updatedLocation, sound, volume, pitch); - else if (player.isOnline()) player.playSound(updatedLocation, sound, volume, pitch); - } - } -} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index fa3ddc9..e214814 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,16 +1,35 @@ +#General sign texts SignText: "[v10lift]" DefectText: "&kDefect!" DisabledText: "&cDisabled" MaintenanceText: "&cMaintenance" UpText: "&aup" DownText: "&adown" + +#The change for a lift to get defective. Disabled by default. DefectRate: 0.0 + +#The repair item and amount required RepairItem: REDSTONE RepairAmount: 5 + +#The master repair item and amount required MasterRepairItem: DIAMOND MasterRepairAmount: 10 + +#The default speed of a lift DefaultSpeed: 16 + +#Create lifts with realistic mode enabled default? DefaultRealistic: true + +#The time for the door to close, in ticks. 20 ticks = 1 sec DoorCloseTime: 100 -CheckUpdates: true -PacketTeleport: false \ No newline at end of file + +#Teleport with packets (no Bukkit events will be fired then) +PacketTeleport: false + +#The updater checker - It will check for new versions, and install automatically if found. +UpdateChecker: + Enabled: true + DownloadOnUpdate: true \ No newline at end of file diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 8d151ca..a8ece23 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -1,22 +1,18 @@ General: - #General NoPermission: '&cYou don''t have the permission to do this.' PlayerOnly: '&cOnly players can do this.' IncorrectUsage: '&cPlease use %Command% instead' InternalError: '&cSomething went wrong internally.' - #Lift general DoesntExists: '&cThere are no lifts with that name.' AlreadyExists: '&cA lift with that name already exists.' SwitchOnEdit: '&cEnable editor mode before doing this.' DetectionFailed: '&cAutomatic floor detection failed!' FloorDoesntExists: '&cThe floor %Name% doesn''t exists!' - #Lift control NoWhitelistPermission: '&cYou can''t go to that floor!' NoFloors: '&cThis elevator has no floors!' - #Protection RemoveLiftFirst: '&cYou can''t do this! Remove the lift first.' RemoveRopeFirst: '&cYou can''t do this! Remove the rope first.' RemoveDoorFirst: '&cYou can''t do this! Remove the door first.'