diff --git a/README.md b/README.md index 5fd9a66d..32cc6e4d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ gonalez/ZNetwork. This fork was made because the original maintainer of the plug in the original project's [official discord server](https://discord.com/invite/RhNMH4T). ### Dependencies -- Java 17 +- Java 8 - Spigot 1.8 - 1.19.4 - PlaceholderAPI (OPTIONAL) diff --git a/build.gradle b/build.gradle index b8953cab..6c18367a 100644 --- a/build.gradle +++ b/build.gradle @@ -28,8 +28,8 @@ dependencies { compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT" compileOnly "me.clip:placeholderapi:2.11.1" - compileOnly "com.mojang:authlib:3.4.40" - compileOnly "com.mojang:datafixerupper:6.0.8" + compileOnly "com.mojang:authlib:2.1.28" + compileOnly "com.mojang:datafixerupper:3.0.25" implementation "commons-io:commons-io:2.11.0" implementation "com.google.code.gson:gson:2.10.1" @@ -41,10 +41,8 @@ dependencies { group "lol.pyr" version "1.0.6" - -compileJava { - options.release.set(17) -} +sourceCompatibility 1.8 +targetCompatibility 1.8 shadowJar { archiveClassifier.set "" @@ -93,4 +91,4 @@ publishing { url = uri("https://repo.pyr.lol/releases/") } } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/znetworkw/znpcservers/commands/Command.java b/src/main/java/io/github/znetworkw/znpcservers/commands/Command.java index 41512d73..c67df919 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/commands/Command.java +++ b/src/main/java/io/github/znetworkw/znpcservers/commands/Command.java @@ -70,7 +70,7 @@ public Set getCommandsTab() { public boolean execute(CommandSender sender, String commandLabel, String[] args) { Optional> subCommandOptional = this.subCommands.entrySet().stream().filter(command -> command.getKey().name().contentEquals((args.length > 0) ? args[0] : "")).findFirst(); - if (subCommandOptional.isEmpty()) { + if (!subCommandOptional.isPresent()) { sender.sendMessage(ChatColor.RED + "Unable to locate the following command: " + commandLabel + "."); return false; } @@ -90,7 +90,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args) public @NotNull List tabComplete(CommandSender sender, String commandLabel, String[] args) { Optional> subCommandOptional = this.subCommandsTab.entrySet().stream().filter(command -> command.getKey().name().contentEquals((args.length > 0) ? args[0] : "")).findFirst(); - if (subCommandOptional.isEmpty()) { + if (!subCommandOptional.isPresent()) { List collect = getCommands().stream().map(CommandInformation::name).collect(Collectors.toList()); if (args.length == 0) { return collect; @@ -104,7 +104,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args) } return subCommand.getValue().tabComplete(new io.github.znetworkw.znpcservers.commands.CommandSender(sender), Arrays.copyOfRange(args, 1, args.length)); } catch (CommandException e) { - return List.of(); + return Collections.emptyList(); } } } diff --git a/src/main/java/io/github/znetworkw/znpcservers/commands/CommandInvoker.java b/src/main/java/io/github/znetworkw/znpcservers/commands/CommandInvoker.java index b3f583cc..f062e499 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/commands/CommandInvoker.java +++ b/src/main/java/io/github/znetworkw/znpcservers/commands/CommandInvoker.java @@ -20,9 +20,11 @@ public CommandInvoker(Command command, Method commandMethod, String permission) public void execute(CommandSender sender, Object command) throws CommandException { // Check if the sender is not a player - if (!(sender.getCommandSender() instanceof Player player)) + if (!(sender.getCommandSender() instanceof Player)) throw new CommandException("Only players may execute this command."); + final Player player = (Player)sender.getCommandSender(); + // Check if the permission is not empty and the player does not have the permission if (this.permission.length() > 0 && !player.hasPermission(this.permission)) throw new CommandPermissionException("You cannot execute this command."); diff --git a/src/main/java/io/github/znetworkw/znpcservers/commands/CommandTabInvoker.java b/src/main/java/io/github/znetworkw/znpcservers/commands/CommandTabInvoker.java index 1439076d..76759062 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/commands/CommandTabInvoker.java +++ b/src/main/java/io/github/znetworkw/znpcservers/commands/CommandTabInvoker.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; import java.lang.reflect.Method; +import java.util.Collections; import java.util.List; public class CommandTabInvoker { @@ -21,9 +22,11 @@ public CommandTabInvoker(Command command, Method commandMethod, String permissio public List tabComplete(CommandSender sender, Object command) throws CommandException { // Check if the sender is not a player - if (!(sender.getCommandSender() instanceof Player player)) + if (!(sender.getCommandSender() instanceof Player)) throw new CommandException("Only players may execute this command."); + final Player player = (Player)sender.getCommandSender(); + // Check if the permission is not empty and the player does not have the permission if (this.permission.length() > 0 && !player.hasPermission(this.permission)) throw new CommandPermissionException("You cannot execute this command."); @@ -31,11 +34,12 @@ public List tabComplete(CommandSender sender, Object command) throws Com try { // Command Tab execution Object invoke = this.commandTabMethod.invoke(this.command, sender, command); - if (invoke instanceof List list) return ((List) list); + if (invoke instanceof List) + return ((List) invoke); } catch (IllegalAccessException | ClassCastException | java.lang.reflect.InvocationTargetException e) { throw new CommandExecuteException(e.getMessage(), e.getCause()); } - return List.of(); + return Collections.emptyList(); } } diff --git a/src/main/java/io/github/znetworkw/znpcservers/commands/list/DefaultCommand.java b/src/main/java/io/github/znetworkw/znpcservers/commands/list/DefaultCommand.java index ffdfd357..be06a2b4 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/commands/list/DefaultCommand.java +++ b/src/main/java/io/github/znetworkw/znpcservers/commands/list/DefaultCommand.java @@ -430,10 +430,9 @@ public List actionTabComplete(CommandSender sender, String[] args) { } switch (args[0].toLowerCase()) { - default -> { + default: return Lists.newArrayList(); - } - case "add" -> { + case "add": if (args.length == 2) { return Lists.newArrayList(""); } @@ -443,36 +442,28 @@ public List actionTabComplete(CommandSender sender, String[] args) { if (args.length == 4) { NPCAction.ActionType actionType = NPCAction.ActionType.valueOf(args[2].toUpperCase()); switch (actionType) { - default -> { + default: return Lists.newArrayList(); - } - case MESSAGE -> { + case MESSAGE: return Lists.newArrayList(""); - } - case CMD -> { + case CMD: return Lists.newArrayList(""); - } - case CONSOLE -> { + case CONSOLE: return Lists.newArrayList(""); - } - case CHAT -> { + case CHAT: return Lists.newArrayList(""); - } - case SERVER -> { + case SERVER: return Lists.newArrayList(""); - } } } - } - case "remove" -> { + case "remove": if (args.length == 2) { return Lists.newArrayList(""); } if (args.length == 3) { return Lists.newArrayList(""); } - } - case "cooldown" -> { + case "cooldown": if (args.length == 2) { return Lists.newArrayList(""); } @@ -482,12 +473,10 @@ public List actionTabComplete(CommandSender sender, String[] args) { if (args.length == 4) { return Lists.newArrayList(""); } - } - case "list" -> { + case "list": if (args.length == 2) { return Lists.newArrayList(""); } - } } return Lists.newArrayList(); } @@ -594,7 +583,7 @@ public List customizeTabComplete(CommandSender sender, String[] args) { if (foundNPC == null) return Lists.newArrayList(); NPCType npcType = foundNPC.getNpcPojo().getNpcType(); - return partialTabCompleteOptions(args[1], npcType.getCustomizationLoader().getMethods().keySet().stream().toList()); + return partialTabCompleteOptions(args[1], new ArrayList<>(npcType.getCustomizationLoader().getMethods().keySet())); } if (args.length == 3) { NPC foundNPC = NPC.find(Integer.parseInt(args[1])); @@ -819,11 +808,11 @@ public List conversationTabComplete(CommandSender sender, String[] args) if (args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("set")) { Integer id = Ints.tryParse(args[1]); if (id == null) { - return List.of(); + return Collections.emptyList(); } NPC npc = NPC.find(id); if (npc == null) { - return List.of(); + return Collections.emptyList(); } return Lists.newArrayList(npc.getNpcPojo().getConversation() == null ? "null" : npc.getNpcPojo().getConversation().getConversationName()); diff --git a/src/main/java/io/github/znetworkw/znpcservers/exception/CommandException.java b/src/main/java/io/github/znetworkw/znpcservers/exception/CommandException.java index ffc7fb85..e0cf4c5a 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/exception/CommandException.java +++ b/src/main/java/io/github/znetworkw/znpcservers/exception/CommandException.java @@ -1,12 +1,10 @@ package io.github.znetworkw.znpcservers.exception; -import java.io.Serial; - /** * @author xCodiq - 20/04/2023 */ public class CommandException extends Exception { - @Serial private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; public CommandException(String message) { super(message); diff --git a/src/main/java/io/github/znetworkw/znpcservers/listeners/InventoryListener.java b/src/main/java/io/github/znetworkw/znpcservers/listeners/InventoryListener.java index bb39d20a..ab062847 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/listeners/InventoryListener.java +++ b/src/main/java/io/github/znetworkw/znpcservers/listeners/InventoryListener.java @@ -15,9 +15,11 @@ public InventoryListener(Plugin serversNPC) { @EventHandler public void onClick(InventoryClickEvent event) { - if (!(event.getWhoClicked() instanceof Player player)) return; + if (!(event.getWhoClicked() instanceof Player)) return; + final Player player = (Player) event.getWhoClicked(); if (event.getCurrentItem() == null) return; - if (!(event.getInventory().getHolder() instanceof ZInventoryHolder holder)) return; + if (!(event.getInventory().getHolder() instanceof ZInventoryHolder)) return; + final ZInventoryHolder holder = (ZInventoryHolder) event.getInventory().getHolder(); event.setCancelled(true); ZInventoryPage page = holder.getzInventory().getPage(); diff --git a/src/main/java/io/github/znetworkw/znpcservers/npc/NPC.java b/src/main/java/io/github/znetworkw/znpcservers/npc/NPC.java index f57b5056..08587798 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/npc/NPC.java +++ b/src/main/java/io/github/znetworkw/znpcservers/npc/NPC.java @@ -31,6 +31,7 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.stream.Collectors; public class NPC { private static final ConcurrentMap NPC_MAP = new ConcurrentHashMap<>(); @@ -231,7 +232,7 @@ public synchronized void spawn(ZUser user) { PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerSpawnPlayer(entityID, this.gameProfile.getId(), SpigotConversionUtil.fromBukkitLocation(location.toBukkitLocation()))); PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerEntityMetadata(entityID, - List.of(new EntityData(NPCSkin.SkinLayerValues.findLayerByVersion(), EntityDataTypes.BYTE, Byte.MAX_VALUE)))); + Collections.singletonList(new EntityData(NPCSkin.SkinLayerValues.findLayerByVersion(), EntityDataTypes.BYTE, Byte.MAX_VALUE)))); PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerEntityHeadLook(entityID, location.getYaw())); }); } @@ -243,7 +244,7 @@ player, new WrapperPlayServerSpawnEntity(entityID, Optional.ofNullable(uuid), ty location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.empty())); else PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerSpawnLivingEntity( entityID, uuid, type, location.toVector3d(), location.getYaw(), location.getPitch(), - location.getPitch(), new Vector3d(), List.of())); + location.getPitch(), new Vector3d(), Collections.emptyList())); } if (FunctionFactory.isTrue(this, "holo")) this.hologram.spawn(user); @@ -327,10 +328,10 @@ public void sendEquipPackets(ZUser zUser) { .filter(entry -> Objects.nonNull(entry.getKey())) .filter(entry -> Objects.nonNull(entry.getValue())) .map(entry -> new Equipment(entry.getKey(), SpigotConversionUtil.fromBukkitItemStack(entry.getValue()))) - .toList(); + .collect(Collectors.toList()); if (equipment.size() == 0) return; if (Utils.versionNewer(16)) PacketEvents.getAPI().getPlayerManager().sendPacket(zUser.toPlayer(), new WrapperPlayServerEntityEquipment(entityID, equipment)); - else for (Equipment e : equipment) PacketEvents.getAPI().getPlayerManager().sendPacket(zUser.toPlayer(), new WrapperPlayServerEntityEquipment(entityID, List.of(e))); + else for (Equipment e : equipment) PacketEvents.getAPI().getPlayerManager().sendPacket(zUser.toPlayer(), new WrapperPlayServerEntityEquipment(entityID, Collections.singletonList(e))); } public void setPath(NPCPath.AbstractTypeWriter typeWriter) { diff --git a/src/main/java/io/github/znetworkw/znpcservers/skin/SkinFetcher.java b/src/main/java/io/github/znetworkw/znpcservers/skin/SkinFetcher.java index 096ede89..d139c346 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/skin/SkinFetcher.java +++ b/src/main/java/io/github/znetworkw/znpcservers/skin/SkinFetcher.java @@ -31,7 +31,7 @@ public CompletableFuture doReadSkin(SkinFetcherResult skinFetcherRes if (this.builder.isUrlType()) { connection.setDoOutput(true); try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { - outputStream.writeBytes("url=" + URLEncoder.encode(this.builder.getData(), StandardCharsets.UTF_8)); + outputStream.writeBytes("url=" + URLEncoder.encode(this.builder.getData(), "UTF-8")); } } try (Reader reader = new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)) {