diff --git a/.gitignore b/.gitignore index 35ffb80a..f40fb31c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ target/ qodana.yaml .paper-nms/ *.tiny +.idea/material_theme_project_new.xml ### Eclipse ### .apt_generated diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..95c08b38 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/TheAPI__package_.xml b/.idea/runConfigurations/TheAPI__package_.xml new file mode 100644 index 00000000..5cf45081 --- /dev/null +++ b/.idea/runConfigurations/TheAPI__package_.xml @@ -0,0 +1,34 @@ + + + + + + + + \ No newline at end of file diff --git a/Loader - Bukkit/dependency-reduced-pom.xml b/Loader - Bukkit/dependency-reduced-pom.xml index b7e67ea3..86972096 100644 --- a/Loader - Bukkit/dependency-reduced-pom.xml +++ b/Loader - Bukkit/dependency-reduced-pom.xml @@ -45,6 +45,12 @@ 12.9.7 provided + + org.projectlombok + lombok + 1.18.34 + provided + UTF-8 diff --git a/Loader - Bukkit/pom.xml b/Loader - Bukkit/pom.xml index 62d26b35..8431ef38 100644 --- a/Loader - Bukkit/pom.xml +++ b/Loader - Bukkit/pom.xml @@ -59,6 +59,12 @@ 33.2.1-jre provided + + org.projectlombok + lombok + 1.18.34 + provided + \ No newline at end of file diff --git a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/BukkitLibInit.java b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/BukkitLibInit.java index 322d5cce..18de756f 100644 --- a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/BukkitLibInit.java +++ b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/BukkitLibInit.java @@ -30,6 +30,7 @@ import org.bukkit.World; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; @@ -71,7 +72,7 @@ public ImplementableJar(File file) throws IOException { } @Override - public Enumeration entries() { + public @NotNull Enumeration entries() { List> totalEntries = new ArrayList<>(); totalEntries.add(super.entries()); for (JarFile search : file) @@ -512,8 +513,8 @@ public Object read(Map map) { public Map write(Object object) { Map map = new HashMap<>(); Position pos = (Position) object; - map.put("classType", "Position"); - map.put("world", pos.getWorldName()); + map.put("classType", "org.bukkit.Location"); + map.put("world", pos.getWorld().getName()); map.put("x", pos.getX()); map.put("y", pos.getY()); map.put("z", pos.getZ()); diff --git a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/BukkitLoader.java b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/BukkitLoader.java index 26c1d79b..f3e00a31 100644 --- a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/BukkitLoader.java +++ b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/BukkitLoader.java @@ -43,6 +43,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; import javax.tools.ToolProvider; import java.io.File; @@ -400,60 +401,33 @@ public String apply(String text, UUID player) { return me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player == null ? null : Bukkit.getOfflinePlayer(player), "%" + text + "%"); } }; - for (PlaceholderExpansion exp : PlaceholderAPI.getPlaceholders()) - ((me.clip.placeholderapi.expansion.PlaceholderExpansion) exp.setPapiInstance(new me.clip.placeholderapi.expansion.PlaceholderExpansion() { - @Override - public String onRequest(OfflinePlayer player, String params) { - return exp.apply(params, player == null ? null : player.getUniqueId()); - } - - @Override - public String getName() { - return exp.getName(); - } - - @Override - public String getIdentifier() { - return exp.getName().toLowerCase(); - } - - @Override - public String getAuthor() { - return "(Unknown) TheAPI Provided Placeholder"; - } - - @Override - public String getVersion() { - return BukkitLoader.this.getDescription().getVersion(); - } - }).getPapiInstance()).register(); + PlaceholderAPI.unregisterConsumer = exp -> ((me.clip.placeholderapi.expansion.PlaceholderExpansion) exp.getPapiInstance()).unregister(); PlaceholderAPI.registerConsumer = exp -> ((me.clip.placeholderapi.expansion.PlaceholderExpansion) exp.setPapiInstance(new me.clip.placeholderapi.expansion.PlaceholderExpansion() { @Override - public String onRequest(OfflinePlayer player, String params) { + public String onRequest(OfflinePlayer player, @NotNull String params) { return exp.apply(params, player == null ? null : player.getUniqueId()); } @Override - public String getName() { + public @NotNull String getName() { return exp.getName(); } @Override - public String getIdentifier() { + public @NotNull String getIdentifier() { return exp.getName().toLowerCase(); } @Override - public String getAuthor() { + public @NotNull String getAuthor() { return "(Unknown) TheAPI Provided Placeholder"; } @Override - public String getVersion() { + public @NotNull String getVersion() { return BukkitLoader.this.getDescription().getVersion(); } }).getPapiInstance()).register(); - PlaceholderAPI.unregisterConsumer = exp -> ((me.clip.placeholderapi.expansion.PlaceholderExpansion) exp.getPapiInstance()).unregister(); } // Command to reload NmsProvider @@ -517,13 +491,8 @@ private void checkForUpdateAndDownloadCompiled() { serverVersion = 'v' + serverVersion; try { Config gitVersion = Config.loadFromInput(new URL("https://raw.githubusercontent.com/TheDevTec/TheAPI/main/version.yml").openStream()); - Config localVersion = new Config("plugins/TheAPI/version.yml"); - - localVersion.setIfAbsent("build", 1); - localVersion.setComments("build", Arrays.asList("# DO NOT MODIFY THIS VALUE")); - - Version ver = VersionUtils.getVersion(gitVersion.getString("release"), "" + release); + Version ver = getGitVersion(localVersion, gitVersion); if (ver != Version.OLDER_VERSION && ver != Version.SAME_VERSION && new File("plugins/TheAPI/NmsProviders/" + serverVersion + ".jar").exists()) { Bukkit.getConsoleSender().sendMessage("[TheAPI NmsProvider Updater] §cERROR! Can't download new NmsProvider, please update TheAPI."); @@ -544,19 +513,20 @@ private void checkForUpdateAndDownloadCompiled() { } } + private Version getGitVersion(Config localVersion, Config gitVersion) { + localVersion.setIfAbsent("build", 1); + localVersion.setComments("build", Collections.singletonList("# DO NOT MODIFY THIS VALUE")); + return VersionUtils.getVersion(gitVersion.getString("release"), "" + release); + } + private void checkForUpdateAndDownload() { String serverVersion = Ref.serverVersion().replace('.', '_'); if (!serverVersion.startsWith("v")) serverVersion = 'v' + serverVersion; try { Config gitVersion = Config.loadFromInput(new URL("https://raw.githubusercontent.com/TheDevTec/TheAPI/main/version.yml").openStream()); - Config localVersion = new Config("plugins/TheAPI/version.yml"); - - localVersion.setIfAbsent("build", 1); - localVersion.setComments("build", Arrays.asList("# DO NOT MODIFY THIS VALUE")); - - Version ver = VersionUtils.getVersion(gitVersion.getString("release"), "" + release); + Version ver = getGitVersion(localVersion, gitVersion); if (ver != Version.OLDER_VERSION && ver != Version.SAME_VERSION && new File("plugins/TheAPI/NmsProviders/" + serverVersion + ".java").exists()) { Bukkit.getConsoleSender().sendMessage("[TheAPI NmsProvider Updater] §cERROR! Can't download new NmsProvider, please update TheAPI."); diff --git a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/bossbar/BossBar.java b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/bossbar/BossBar.java index 7577a336..d669595b 100644 --- a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/bossbar/BossBar.java +++ b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/bossbar/BossBar.java @@ -1,5 +1,6 @@ package me.devtec.theapi.bukkit.bossbar; +import lombok.Getter; import me.devtec.shared.Ref; import me.devtec.shared.scheduler.Tasker; import me.devtec.shared.utility.ColorUtils; @@ -29,9 +30,12 @@ public class BossBar { private final Player holder; private World before; + @Getter private boolean hidden; + @Getter private String title; + @Getter private double progress; private Object entityBar; @@ -85,18 +89,6 @@ public void move() { BukkitLoader.getPacketHandler().send(holder, packet); } - public boolean isHidden() { - return hidden; - } - - public double getProgress() { - return progress; - } - - public String getTitle() { - return title; - } - public void hide() { if (hidden) return; diff --git a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/commands/hooker/CustomPluginCommand.java b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/commands/hooker/CustomPluginCommand.java index bc3148da..6a89d44b 100644 --- a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/commands/hooker/CustomPluginCommand.java +++ b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/commands/hooker/CustomPluginCommand.java @@ -1,17 +1,19 @@ package me.devtec.theapi.bukkit.commands.hooker; +import lombok.Getter; import me.devtec.shared.commands.holder.CommandHolder; import org.bukkit.command.*; import org.bukkit.plugin.Plugin; -import javax.annotation.CheckForNull; import java.util.List; public class CustomPluginCommand extends Command implements PluginIdentifiableCommand { private final Plugin owningPlugin; + @Getter private CommandExecutor executor; private TabCompleter completer; + @Getter private final CommandHolder commandHolder; protected CustomPluginCommand(String name, Plugin owner, CommandHolder commandHolder) { @@ -48,10 +50,6 @@ public void setExecutor(CommandExecutor executor) { this.executor = executor == null ? owningPlugin : executor; } - public CommandExecutor getExecutor() { - return executor; - } - public void setTabCompleter(TabCompleter completer) { this.completer = completer; } @@ -65,10 +63,6 @@ public Plugin getPlugin() { return owningPlugin; } - public CommandHolder getCommandHolder() { - return commandHolder; - } - @Override public boolean testPermissionSilent(CommandSender target) { if (commandHolder != null && !commandHolder.getStructure().getSenderClass().isAssignableFrom(target.getClass())) diff --git a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/events/ServerListPingEvent.java b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/events/ServerListPingEvent.java index ab1182d6..dbec951c 100644 --- a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/events/ServerListPingEvent.java +++ b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/events/ServerListPingEvent.java @@ -1,5 +1,7 @@ package me.devtec.theapi.bukkit.events; +import lombok.Getter; +import lombok.Setter; import me.devtec.shared.events.Cancellable; import me.devtec.shared.events.Event; import me.devtec.shared.events.ListenerHolder; @@ -15,11 +17,21 @@ public class ServerListPingEvent extends Event implements Cancellable { private boolean cancel; private int online; private int max; + @Setter + @Getter private int protocol; + @Getter private List slots; + @Setter + @Getter private String motd; + @Setter + @Getter private String favicon; + @Setter + @Getter private String version; + @Getter private final InetAddress address; public ServerListPingEvent(int online, int max, List slots, String motd, String favicon, InetAddress inetAddress, String ver, int protocol) { @@ -33,26 +45,6 @@ public ServerListPingEvent(int online, int max, List slots, version = ver; } - public String getVersion() { - return version; - } - - public void setVersion(String ver) { - version = ver; - } - - public int getProtocol() { - return protocol; - } - - public void setProtocol(int protocol) { - this.protocol = protocol; - } - - public InetAddress getAddress() { - return address; - } - public int getOnlinePlayers() { return online; } @@ -69,30 +61,10 @@ public void setMaxPlayers(int max) { this.max = max; } - public List getSlots() { - return slots; - } - public void setPlayersText(List slots) { this.slots = slots; } - public String getMotd() { - return motd; - } - - public void setMotd(String motd) { - this.motd = motd; - } - - public String getFavicon() { - return favicon; - } - - public void setFavicon(String falvicon) { - favicon = falvicon; - } - @Override public boolean isCancelled() { return cancel; diff --git a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/EnchantmentAPI.java b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/EnchantmentAPI.java index 9ec6cc91..bd3ddbe5 100644 --- a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/EnchantmentAPI.java +++ b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/EnchantmentAPI.java @@ -209,7 +209,7 @@ public static boolean unregisterEnchantment(Enchantment enchantment) { if (Ref.isNewerThan(12)) unregistered = ((Map) Ref.get(null, byKey)).remove(Ref.get(enchantment, key)) != null; else - unregistered = ((Map) Ref.get(null, byId)).remove(Ref.get(enchantment, id)) != null; + unregistered = ((Map) Ref.get(null, byId)).remove((Integer)Ref.get(enchantment, id)) != null; } catch (Exception ignored) { } return unregistered; diff --git a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/Position.java b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/Position.java index 56f59575..75570562 100644 --- a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/Position.java +++ b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/Position.java @@ -157,7 +157,7 @@ public Position setWorld(World world) { } public Position setWorld(String worldName) { - if (worldName == null ? world != null : !worldName.equals(world)) { + if (!Objects.equals(worldName, world)) { world = worldName; cachedChunk = null; } @@ -412,9 +412,7 @@ public boolean equals(Object a) { public static void updateBlockAt(Position pos) { Object packet = BukkitLoader.getNmsProvider().packetBlockChange(pos, pos.getIBlockData(), pos.getData()); List players = new ArrayList<>(); - Iterator itr = BukkitLoader.getOnlinePlayers().iterator(); - while (itr.hasNext()) { - Player player = itr.next(); + for (Player player : BukkitLoader.getOnlinePlayers()) { if (player.getWorld().getName().equals(pos.getWorldName())) players.add(player); } @@ -424,9 +422,7 @@ public static void updateBlockAt(Position pos) { public static void updateBlockAt(Position pos, BlockDataStorage blockData) { Object packet = BukkitLoader.getNmsProvider().packetBlockChange(pos, blockData.getIBlockData(), blockData.getItemData()); List players = new ArrayList<>(); - Iterator itr = BukkitLoader.getOnlinePlayers().iterator(); - while (itr.hasNext()) { - Player player = itr.next(); + for (Player player : BukkitLoader.getOnlinePlayers()) { if (player.getWorld().getName().equals(pos.getWorldName())) players.add(player); } @@ -460,9 +456,7 @@ public void setAirAndUpdate(boolean updatePhysics) { setAir(); Object packet = BukkitLoader.getNmsProvider().packetBlockChange(this, null, 0); List players = new ArrayList<>(); - Iterator itr = BukkitLoader.getOnlinePlayers().iterator(); - while (itr.hasNext()) { - Player player = itr.next(); + for (Player player : BukkitLoader.getOnlinePlayers()) { if (player.getWorld().getName().equals(getWorldName())) players.add(player); } diff --git a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/itemmakers/BundleItemMaker.java b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/itemmakers/BundleItemMaker.java index 1f1eae53..c8a13b6e 100644 --- a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/itemmakers/BundleItemMaker.java +++ b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/itemmakers/BundleItemMaker.java @@ -1,6 +1,5 @@ package me.devtec.theapi.bukkit.game.itemmakers; -import me.devtec.shared.Ref; import me.devtec.shared.annotations.Nullable; import me.devtec.theapi.bukkit.game.ItemMaker; import org.bukkit.Material; @@ -8,7 +7,6 @@ import org.bukkit.inventory.meta.BundleMeta; import org.bukkit.inventory.meta.ItemMeta; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; diff --git a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/particles/ParticleData.java b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/particles/ParticleData.java index 7522d41e..c56a472f 100644 --- a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/particles/ParticleData.java +++ b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/particles/ParticleData.java @@ -1,5 +1,6 @@ package me.devtec.theapi.bukkit.game.particles; +import lombok.Getter; import me.devtec.shared.Ref; import me.devtec.theapi.bukkit.game.BlockDataStorage; import me.devtec.theapi.bukkit.xseries.XMaterial; @@ -60,6 +61,7 @@ public int hashCode() { } } + @Getter public static class RedstoneOptions extends ParticleData { private final float red; private final float green; @@ -93,18 +95,6 @@ public RedstoneOptions(float red, float green, float blue) { this(1, red, green, blue); } - public float getRed() { - return red; - } - - public float getGreen() { - return green; - } - - public float getBlue() { - return blue; - } - @Override public float getValueX() { return red / 255.0F; @@ -120,10 +110,6 @@ public float getValueZ() { return blue / 255.0F; } - public float getSize() { - return size; - } - @Override public int hashCode() { int hash = 1; @@ -135,6 +121,7 @@ public int hashCode() { } public static class ItemOptions extends ParticleData { + @Getter private final ItemStack item; private int[] packetData; @@ -166,15 +153,11 @@ public ItemOptions(BlockDataStorage material) { } } - public ItemStack getItem() { - return item; - } - @Deprecated /** * @apiNote 1.12.2 and older only. * @return packedData of item - */ + **/ public int[] getPacketData() { return packetData; } diff --git a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/resourcepack/ResourcePackOffer.java b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/resourcepack/ResourcePackOffer.java index 080fc38b..c3b76e0b 100644 --- a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/resourcepack/ResourcePackOffer.java +++ b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/game/resourcepack/ResourcePackOffer.java @@ -1,5 +1,6 @@ package me.devtec.theapi.bukkit.game.resourcepack; +import lombok.Getter; import me.devtec.shared.components.Component; import java.io.InputStream; @@ -18,8 +19,10 @@ public class ResourcePackOffer { } } + @Getter private String url; private String sha1; + @Getter private Optional prompt; private boolean force; @@ -32,10 +35,6 @@ private ResourcePackOffer(String url) { prompt = Optional.empty(); } - public String getUrl() { - return url; - } - public ResourcePackOffer setHash​(String sha1) { this.sha1 = sha1; return this; @@ -79,10 +78,6 @@ public ResourcePackOffer setPrompt(Component prompt) { return this; } - public Optional getPrompt() { - return prompt; - } - public ResourcePackOffer setShouldForce​(boolean force) { this.force = force; return this; diff --git a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/nms/GameProfileHandler.java b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/nms/GameProfileHandler.java index 37789f27..efaa8219 100644 --- a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/nms/GameProfileHandler.java +++ b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/nms/GameProfileHandler.java @@ -1,5 +1,6 @@ package me.devtec.theapi.bukkit.nms; +import lombok.Getter; import me.devtec.theapi.bukkit.BukkitLoader; import java.util.HashMap; @@ -7,8 +8,11 @@ import java.util.UUID; public class GameProfileHandler { + @Getter private String username; private UUID uuid; + + @Getter private final Map properties = new HashMap<>(); public static GameProfileHandler of(String username, UUID uuid) { @@ -24,14 +28,6 @@ public static GameProfileHandler of(String username, UUID uuid, PropertyHandler return profile; } - /** - * @return GameProfile's Username - * @apiNote Get username of GameProfile - */ - public String getUsername() { - return username; - } - /** * @apiNote Change username of GameProfile */ @@ -56,13 +52,6 @@ public GameProfileHandler setUUID(UUID uuid) { return this; } - /** - * @apiNote Get skin properties - */ - public Map getProperties() { - return properties; - } - /** * @apiNote Set skin textures properties */ @@ -78,6 +67,7 @@ public Object getGameProfile() { return BukkitLoader.getNmsProvider().toGameProfile(this); } + @Getter public static class PropertyHandler { private String name; private String values; @@ -95,20 +85,6 @@ public static PropertyHandler of(String name, String values, String signature) { return property; } - /** - * @apiNote Get property name - */ - public String getName() { - return name; - } - - /** - * @apiNote Get property values - */ - public String getValues() { - return values; - } - /** * @apiNote Set property values */ @@ -117,13 +93,6 @@ public PropertyHandler setValues(String value) { return this; } - /** - * @apiNote Get property signature - */ - public String getSignature() { - return signature; - } - /** * @apiNote Set property signature */ diff --git a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/scoreboard/SimpleScore.java b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/scoreboard/SimpleScore.java index 36a9e294..8441cafd 100644 --- a/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/scoreboard/SimpleScore.java +++ b/Loader - Bukkit/src/main/java/me/devtec/theapi/bukkit/scoreboard/SimpleScore.java @@ -32,9 +32,9 @@ public void send(Player... players) { sb.setTitle(name); if (!Ref.isNewerThan(7)) { Collections.reverse(lines); - if (lines.size() > 15) - for (int i = 15; i < lines.size(); ++i) - lines.remove(i); + if (lines.size() > 15){ + lines.subList(15,lines.size()).clear(); + } } if (sb.getLines().size() > lines.size()) sb.removeUpperLines(lines.size() - 1); diff --git a/NmsProvider - 1.20.6/src/main/java/v1_20_6.java b/NmsProvider - 1.20.6/src/main/java/v1_20_6.java index e71fad79..786cb679 100644 --- a/NmsProvider - 1.20.6/src/main/java/v1_20_6.java +++ b/NmsProvider - 1.20.6/src/main/java/v1_20_6.java @@ -209,7 +209,7 @@ public int getContainerId(Object container) { @Override public Object packetResourcePackSend(String url, String hash, boolean requireRP, Component prompt) { return new ClientboundResourcePackPushPacket(UUID.randomUUID(), url, hash, requireRP, - prompt == null ? null : prompt == null ? Optional.empty() : Optional.of((net.minecraft.network.chat.Component) this.toIChatBaseComponent(prompt))); + prompt == null ? Optional.empty() : Optional.of((net.minecraft.network.chat.Component) this.toIChatBaseComponent(prompt))); } @Override diff --git a/NmsProvider - 1.20.R4/src/main/java/v1_20_R4.java b/NmsProvider - 1.20.R4/src/main/java/v1_20_R4.java index 71eaf7b7..c904df8c 100644 --- a/NmsProvider - 1.20.R4/src/main/java/v1_20_R4.java +++ b/NmsProvider - 1.20.R4/src/main/java/v1_20_R4.java @@ -270,7 +270,7 @@ public int getContainerId(Object container) { @Override public Object packetResourcePackSend(String url, String hash, boolean requireRP, Component prompt) { return new ClientboundResourcePackPushPacket(UUID.randomUUID(), url, hash, requireRP, - prompt == null ? null : prompt == null ? Optional.empty() : Optional.of((IChatBaseComponent) this.toIChatBaseComponent(prompt))); + prompt == null ? Optional.empty() : Optional.of((IChatBaseComponent) this.toIChatBaseComponent(prompt))); } @Override diff --git a/NmsProvider - 1.21.R1/src/main/java/v1_21_R1.java b/NmsProvider - 1.21.R1/src/main/java/v1_21_R1.java index a142a810..59d2871f 100644 --- a/NmsProvider - 1.21.R1/src/main/java/v1_21_R1.java +++ b/NmsProvider - 1.21.R1/src/main/java/v1_21_R1.java @@ -2,22 +2,11 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; import java.util.function.BiFunction; import java.util.stream.Collectors; @@ -270,7 +259,7 @@ public int getContainerId(Object container) { @Override public Object packetResourcePackSend(String url, String hash, boolean requireRP, Component prompt) { return new ClientboundResourcePackPushPacket(UUID.randomUUID(), url, hash, requireRP, - prompt == null ? null : prompt == null ? Optional.empty() : Optional.of((IChatBaseComponent) this.toIChatBaseComponent(prompt))); + prompt == null ? null : Optional.of((IChatBaseComponent) this.toIChatBaseComponent(prompt))); } @Override @@ -339,20 +328,20 @@ public Object packetScoreboardScore(Action action, String player, String line, i @Override public Object packetTitle(TitleAction action, Component text, int fadeIn, int stay, int fadeOut) { switch (action) { - case ACTIONBAR: - return new ClientboundSetActionBarTextPacket((IChatBaseComponent) this.toIChatBaseComponent(text)); - case TITLE: - return new ClientboundSetTitleTextPacket((IChatBaseComponent) this.toIChatBaseComponent(text)); - case SUBTITLE: - return new ClientboundSetSubtitleTextPacket((IChatBaseComponent) this.toIChatBaseComponent(text)); - case TIMES: - return new ClientboundSetTitlesAnimationPacket(fadeIn, stay, fadeOut); - case CLEAR: - case RESET: - return new ClientboundClearTitlesPacket(true); + case ACTIONBAR: + return new ClientboundSetActionBarTextPacket((IChatBaseComponent) this.toIChatBaseComponent(text)); + case TITLE: + return new ClientboundSetTitleTextPacket((IChatBaseComponent) this.toIChatBaseComponent(text)); + case SUBTITLE: + return new ClientboundSetSubtitleTextPacket((IChatBaseComponent) this.toIChatBaseComponent(text)); + case TIMES: + return new ClientboundSetTitlesAnimationPacket(fadeIn, stay, fadeOut); + case CLEAR: + case RESET: + return new ClientboundClearTitlesPacket(true); } return null; - } + } @Override public Object packetChat(ChatType type, Object chatBase, UUID uuid) { @@ -442,20 +431,15 @@ private IChatBaseComponent convert(Component c) { public Object[] toIChatBaseComponents(List components) { List chat = new ArrayList<>(); chat.add(IChatBaseComponent.b("")); - for (Component c : components) { - if (c.getText() == null || c.getText().isEmpty()) { - if (c.getExtra() != null) - addConverted(chat, c.getExtra()); - continue; - } - chat.add(convert(c)); - if (c.getExtra() != null) - addConverted(chat, c.getExtra()); - } + convertComponents(chat, components); return chat.toArray(new IChatBaseComponent[0]); } private void addConverted(List chat, List extra) { + convertComponents(chat, extra); + } + + private void convertComponents(List chat, List extra) { for (Component c : extra) { if (c.getText() == null || c.getText().isEmpty()) { if (c.getExtra() != null) @@ -549,8 +533,7 @@ public Component fromIChatBaseComponent(Object componentObject) { case SHOW_ENTITY: { net.minecraft.network.chat.ChatHoverable.b hover = modif.i().a(EnumHoverAction.c); ComponentEntity compEntity = new ComponentEntity(hover.b.toString(), hover.c); - if (hover.d.isPresent()) - compEntity.setName(fromIChatBaseComponent(hover.d.get())); + hover.d.ifPresent(iChatBaseComponent -> compEntity.setName(fromIChatBaseComponent(iChatBaseComponent))); comp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ENTITY, compEntity)); break; } @@ -702,7 +685,7 @@ public void setBlock(Object objChunk, int x, int y, int z, Object IblockData, in boolean shouldSkip = true; if (!onlyModifyState) shouldSkip = false; - else if (onlyModifyState && !ent.r().a(iblock)) { + else if (!ent.r().a(iblock)) { shouldSkip = false; onlyModifyState = false; } @@ -839,7 +822,7 @@ public Object getPlayerConnection(Player player) { return ((EntityPlayer) getPlayer(player)).c; } - private static Field networkManagerField = Ref.field(ServerCommonPacketListenerImpl.class, NetworkManager.class); + private static final Field networkManagerField = Ref.field(ServerCommonPacketListenerImpl.class, NetworkManager.class); @Override public Object getConnectionNetwork(Object playercon) { @@ -1101,55 +1084,52 @@ public boolean processInvClickPacket(Player player, HolderGUI gui, Object provPa private void processEvent(Container c, InventoryClickType type, HolderGUI gui, Player player, int slot, int gameSlot, ItemStack newItem, ItemStack oldItem, PacketPlayInWindowClick packet, int mouseClick, ClickType clickType, EntityHuman nPlayer) { c.h(); - switch (type) { - case b: { - ItemStack[] contents = slot < gui.size() ? player.getInventory().getStorageContents() : gui.getInventory().getStorageContents(); - boolean interactWithResultSlot = false; - if (gui instanceof AnvilGUI && slot < gui.size() && slot == 2) - if (c.b(2).a(nPlayer)) - interactWithResultSlot = true; - else - return; - Pair result = slot < gui.size() - ? InventoryUtils.shift(slot, player, gui, clickType, gui instanceof AnvilGUI && slot != 2 ? DestinationType.PLAYER_FROM_ANVIL : DestinationType.PLAYER, null, contents, oldItem) - : InventoryUtils.shift(slot, player, gui, clickType, DestinationType.GUI, gui.getNotInterableSlots(player), contents, oldItem); - @SuppressWarnings("unchecked") - Map modified = (Map) result.getValue(); - int remaining = (int) result.getKey(); - - if (!modified.isEmpty()) - if (slot < gui.size()) { - for (Entry modif : modified.entrySet()) - nPlayer.fY().a(modif.getKey(), (net.minecraft.world.item.ItemStack) asNMSItem(modif.getValue())); - if (remaining == 0) { - c.b(gameSlot).d((net.minecraft.world.item.ItemStack) asNMSItem(null)); - if (interactWithResultSlot) { - c.b(0).d((net.minecraft.world.item.ItemStack) asNMSItem(null)); - c.b(1).d((net.minecraft.world.item.ItemStack) asNMSItem(null)); - } - } else { - newItem.setAmount(remaining); - c.b(gameSlot).d((net.minecraft.world.item.ItemStack) asNMSItem(newItem)); - } - } else { - for (Entry modif : modified.entrySet()) - c.b(modif.getKey()).d((net.minecraft.world.item.ItemStack) asNMSItem(modif.getValue())); // Visual & Nms side - // Plugin & Bukkit side - gui.getInventory().setStorageContents(contents); - if (remaining == 0) - nPlayer.fY().a(gameSlot, (net.minecraft.world.item.ItemStack) asNMSItem(null)); - else { - newItem.setAmount(remaining); - nPlayer.fY().a(gameSlot, (net.minecraft.world.item.ItemStack) asNMSItem(newItem)); - } - } - c.i(); - return; - } - default: - processClick(gui, gui.getNotInterableSlots(player), c, slot, mouseClick, type, nPlayer); - break; - } + if (Objects.requireNonNull(type) == InventoryClickType.b) { + ItemStack[] contents = slot < gui.size() ? player.getInventory().getStorageContents() : gui.getInventory().getStorageContents(); + boolean interactWithResultSlot = false; + if (gui instanceof AnvilGUI && slot < gui.size() && slot == 2) + if (c.b(2).a(nPlayer)) + interactWithResultSlot = true; + else + return; + Pair result = slot < gui.size() + ? InventoryUtils.shift(slot, player, gui, clickType, gui instanceof AnvilGUI && slot != 2 ? DestinationType.PLAYER_FROM_ANVIL : DestinationType.PLAYER, null, contents, oldItem) + : InventoryUtils.shift(slot, player, gui, clickType, DestinationType.GUI, gui.getNotInterableSlots(player), contents, oldItem); + @SuppressWarnings("unchecked") + Map modified = (Map) result.getValue(); + int remaining = (int) result.getKey(); + + if (!modified.isEmpty()) + if (slot < gui.size()) { + for (Entry modif : modified.entrySet()) + nPlayer.fY().a(modif.getKey(), (net.minecraft.world.item.ItemStack) asNMSItem(modif.getValue())); + if (remaining == 0) { + c.b(gameSlot).d((net.minecraft.world.item.ItemStack) asNMSItem(null)); + if (interactWithResultSlot) { + c.b(0).d((net.minecraft.world.item.ItemStack) asNMSItem(null)); + c.b(1).d((net.minecraft.world.item.ItemStack) asNMSItem(null)); + } + } else { + newItem.setAmount(remaining); + c.b(gameSlot).d((net.minecraft.world.item.ItemStack) asNMSItem(newItem)); + } + } else { + for (Entry modif : modified.entrySet()) + c.b(modif.getKey()).d((net.minecraft.world.item.ItemStack) asNMSItem(modif.getValue())); // Visual & Nms side + // Plugin & Bukkit side + gui.getInventory().setStorageContents(contents); + if (remaining == 0) + nPlayer.fY().a(gameSlot, (net.minecraft.world.item.ItemStack) asNMSItem(null)); + else { + newItem.setAmount(remaining); + nPlayer.fY().a(gameSlot, (net.minecraft.world.item.ItemStack) asNMSItem(newItem)); + } + } + c.i(); + return; + } else { + processClick(gui, gui.getNotInterableSlots(player), c, slot, mouseClick, type, nPlayer); + } postToMainThread(() -> { if (type != InventoryClickType.f && (c.a().equals(Containers.i) || c.a().equals(Containers.v))) c.b(); @@ -1164,8 +1144,8 @@ private void processEvent(Container c, InventoryClickType type, HolderGUI gui, P }); } - private Method addAmount = Ref.method(Slot.class, "b", int.class); - private Method checkItem = Ref.method(Container.class, "a", EntityHuman.class, ClickAction.class, Slot.class, net.minecraft.world.item.ItemStack.class, net.minecraft.world.item.ItemStack.class); + private final Method addAmount = Ref.method(Slot.class, "b", int.class); + private final Method checkItem = Ref.method(Container.class, "a", EntityHuman.class, ClickAction.class, Slot.class, net.minecraft.world.item.ItemStack.class, net.minecraft.world.item.ItemStack.class); @SuppressWarnings("unchecked") private void processClick(HolderGUI gui, List ignoredSlots, Container container, int slotIndex, int button, InventoryClickType actionType, EntityHuman player) { @@ -1326,7 +1306,7 @@ private void processClick(HolderGUI gui, List ignoredSlots, Container c } } - private Field containerU = Ref.field(Container.class, "u"), containerV = Ref.field(Container.class, "v"), containerT = Ref.field(Container.class, "t"); + private final Field containerU = Ref.field(Container.class, "u"), containerV = Ref.field(Container.class, "v"), containerT = Ref.field(Container.class, "t"); @SuppressWarnings("unchecked") private void processDragMove(HolderGUI gui, Container container, EntityHuman player, int slot, int mouseClick) { @@ -1668,7 +1648,6 @@ public Object packetPlayerInfo(PlayerInfoType type, Player player) { } static Field setField, listField; - static Constructor clientboundConstructor; static { setField = Ref.field(ClientboundPlayerInfoUpdatePacket.class, "b"); @@ -1740,7 +1719,7 @@ public Object toGameProfile(GameProfileHandler gameProfileHandler) { return profile; } - private Field name = Ref.field(Property.class, "name"), value = Ref.field(Property.class, "value"), signature = Ref.field(Property.class, "signature"); + private final Field name = Ref.field(Property.class, "name"), value = Ref.field(Property.class, "value"), signature = Ref.field(Property.class, "signature"); @Override public GameProfileHandler fromGameProfile(Object gameProfile) { diff --git a/NmsProvider - 1.21/src/main/java/v1_21.java b/NmsProvider - 1.21/src/main/java/v1_21.java index 392fa1f9..ac748b95 100644 --- a/NmsProvider - 1.21/src/main/java/v1_21.java +++ b/NmsProvider - 1.21/src/main/java/v1_21.java @@ -208,7 +208,7 @@ public int getContainerId(Object container) { @Override public Object packetResourcePackSend(String url, String hash, boolean requireRP, Component prompt) { return new ClientboundResourcePackPushPacket(UUID.randomUUID(), url, hash, requireRP, - prompt == null ? null : prompt == null ? Optional.empty() : Optional.of((net.minecraft.network.chat.Component) this.toIChatBaseComponent(prompt))); + prompt == null ? Optional.empty() : Optional.of((net.minecraft.network.chat.Component) this.toIChatBaseComponent(prompt))); } @Override diff --git a/NmsProvider - 1.7.R4/src/main/java/v1_7_R4.java b/NmsProvider - 1.7.R4/src/main/java/v1_7_R4.java index 7c764c1c..e325fd40 100644 --- a/NmsProvider - 1.7.R4/src/main/java/v1_7_R4.java +++ b/NmsProvider - 1.7.R4/src/main/java/v1_7_R4.java @@ -287,13 +287,10 @@ private IChatBaseComponent convert(Component c) { if (c.getClickEvent() != null) modif.setChatClickable(new ChatClickable(EnumClickAction.valueOf(c.getClickEvent().getAction().name()), c.getClickEvent().getValue())); if (c.getHoverEvent() != null) - switch (c.getHoverEvent().getAction()) { - case SHOW_ITEM: - modif = modif.a(new ChatHoverable(EnumHoverAction.SHOW_ITEM, ChatSerializer.a(Json.writer().simpleWrite(c.getHoverEvent().getValue().toJsonMap())))); - break; - default: - modif = modif.a(new ChatHoverable(EnumHoverAction.SHOW_TEXT, (IChatBaseComponent) this.toIChatBaseComponent(c.getHoverEvent().getValue()))); - break; + if (Objects.requireNonNull(c.getHoverEvent().getAction()) == HoverEvent.Action.SHOW_ITEM) { + modif = modif.a(new ChatHoverable(EnumHoverAction.SHOW_ITEM, ChatSerializer.a(Json.writer().simpleWrite(c.getHoverEvent().getValue().toJsonMap())))); + } else { + modif = modif.a(new ChatHoverable(EnumHoverAction.SHOW_TEXT, (IChatBaseComponent) this.toIChatBaseComponent(c.getHoverEvent().getValue()))); } modif.setBold(c.isBold()); modif.setItalic(c.isItalic()); @@ -415,15 +412,12 @@ public Component fromIChatBaseComponent(Object componentObject) { comp.setClickEvent(new ClickEvent(ClickEvent.Action.valueOf(modif.h().a().name()), modif.h().b())); if (modif.i() != null) - switch (HoverEvent.Action.valueOf(modif.i().a().b().toUpperCase())) { - case SHOW_ITEM: - ComponentItem compEntity = ComponentItem.fromJson(modif.i().b().e()); - if (compEntity != null) - comp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, ComponentItem.fromJson(modif.i().b().e()))); - break; - default: - comp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, fromIChatBaseComponent(modif.i().b()))); - break; + if (HoverEvent.Action.valueOf(modif.i().a().b().toUpperCase()) == HoverEvent.Action.SHOW_ITEM) { + ComponentItem compEntity = ComponentItem.fromJson(modif.i().b().e()); + if (compEntity != null) + comp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, ComponentItem.fromJson(modif.i().b().e()))); + } else { + comp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, fromIChatBaseComponent(modif.i().b()))); } comp.setBold(modif.b()); comp.setItalic(modif.c()); @@ -469,7 +463,7 @@ public ItemStack toItemStack(BlockDataStorage material) { return itemStack; } - private static Field chunkLoader = Ref.field(ChunkProviderServer.class, "f"); + private static final Field chunkLoader = Ref.field(ChunkProviderServer.class, "f"); @Override public Object getChunk(World world, int x, int z) { @@ -486,16 +480,14 @@ public Object getChunk(World world, int x, int z) { } if (chunk != null) { ((ChunkProviderServer) sworld.L()).chunks.put(ChunkCoordIntPair.a(x, z), chunk); - postToMainThread(() -> { - chunk.addEntities(); - }); + postToMainThread(chunk::addEntities); loaded = chunk; } } catch (Exception e) { } if (loaded == null) { // generate new chunk ChunkRegionLoader loader = null; - if ((IChunkLoader) Ref.get(sworld.L(), chunkLoader) instanceof ChunkRegionLoader) + if (Ref.get(sworld.L(), chunkLoader) instanceof ChunkRegionLoader) loader = (ChunkRegionLoader) Ref.get(sworld.L(), chunkLoader); if (loader != null && loader.chunkExists(sworld, x, z)) @@ -508,9 +500,9 @@ public Object getChunk(World world, int x, int z) { return loaded; } - private static Field tileEntityBlock = Ref.field(TileEntity.class, "h"); - private static Field isCachedInWorld = Ref.field(net.minecraft.server.v1_7_R4.World.class, "M"); - private static Field tileEntityWorld = Ref.field(net.minecraft.server.v1_7_R4.World.class, "a"); + private static final Field tileEntityBlock = Ref.field(TileEntity.class, "h"); + private static final Field isCachedInWorld = Ref.field(net.minecraft.server.v1_7_R4.World.class, "M"); + private static final Field tileEntityWorld = Ref.field(net.minecraft.server.v1_7_R4.World.class, "a"); @SuppressWarnings("unchecked") @Override