From 5615fa7f325bb45762d13a704a9ffddda3efbfbb Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sun, 20 Nov 2022 23:39:55 -0500 Subject: 1.7.0 beta 5 --- lib/ProtocolLib.jar | Bin 0 -> 4977063 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/ProtocolLib.jar (limited to 'lib') diff --git a/lib/ProtocolLib.jar b/lib/ProtocolLib.jar new file mode 100644 index 0000000..daa31c7 Binary files /dev/null and b/lib/ProtocolLib.jar differ -- cgit v1.2.3-freya From fcc3764a14d76fa24cddb75fe338a3ee36dec3fa Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Mon, 21 Nov 2022 23:47:04 -0500 Subject: 1.7.0 beta 9 --- lib/ProtocolLib.jar | Bin 4977063 -> 0 bytes pom.xml | 22 ++++++------- .../hideAndSeek/command/location/Locations.java | 17 +++------- .../hideAndSeek/command/util/CommandGroup.java | 2 +- .../hideAndSeek/command/world/Create.java | 36 ++++++++++++++------- .../hideAndSeek/command/world/Delete.java | 2 ++ .../hideAndSeek/command/world/List.java | 15 +++++++-- .../hideAndSeek/configuration/ConfigManager.java | 5 +-- .../net/tylermurphy/hideAndSeek/game/Board.java | 2 +- .../net/tylermurphy/hideAndSeek/game/Game.java | 6 ++-- .../hideAndSeek/game/listener/PlayerHandler.java | 1 - .../net/tylermurphy/hideAndSeek/util/Location.java | 7 ++-- .../tylermurphy/hideAndSeek/world/WorldLoader.java | 16 +++++---- 13 files changed, 75 insertions(+), 56 deletions(-) delete mode 100644 lib/ProtocolLib.jar (limited to 'lib') diff --git a/lib/ProtocolLib.jar b/lib/ProtocolLib.jar deleted file mode 100644 index daa31c7..0000000 Binary files a/lib/ProtocolLib.jar and /dev/null differ diff --git a/pom.xml b/pom.xml index 974cdc8..8b2a39d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,10 +4,13 @@ 1.7.0 Hide and Seek Plugin + + UTF-8 + + clean install src/main/java - org.apache.maven.plugins @@ -30,10 +33,6 @@ com.zaxxer.hikari net.tylermurphy.dependencies.hikari - - org.ibex.nestedvm - net.tylermurphy.dependencies.nestedvm - @@ -58,7 +57,6 @@ META-INF/services/java.sql.Driver - true @@ -82,10 +80,10 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/public/ - - - - + + dmulloy2-repo + https://repo.dmulloy2.net/repository/public/ + placeholderapi https://repo.extendedclip.com/content/repositories/placeholderapi/ @@ -109,8 +107,8 @@ com.comphenix.protocol ProtocolLib 4.4.0 - system - ${project.basedir}/lib/ProtocolLib.jar + + org.xerial diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java index dd73dac..c1316f8 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java @@ -5,22 +5,13 @@ package net.tylermurphy.hideAndSeek.command.location; */ public enum Locations { - GAME("spawns.game"), - LOBBY("spawns.lobby"), - EXIT("spawns.exit"), - SEEKER("spawns.seeker"); - - private final String path; - Locations(String path) { - this.path = path; - } + GAME, + LOBBY, + EXIT, + SEEKER; public String message() { return this + "_SPAWN"; } - public String path(String additive) { - return path + "." + additive; - } - } \ No newline at end of file diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java index e9ed90c..b366b9a 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/util/CommandGroup.java @@ -70,7 +70,7 @@ public class CommandGroup { if (data == null) { player.sendMessage( - String.format("%s%sKenshin's Hide and Seek %s(%s1.7.0 BETA%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY, ChatColor.WHITE, ChatColor.GRAY) + + String.format("%s%sKenshin's Hide and Seek %s(%s1.7.0%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY, ChatColor.WHITE, ChatColor.GRAY) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) ); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java index 20ffd5a..e399993 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java @@ -3,10 +3,9 @@ package net.tylermurphy.hideAndSeek.command.world; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.ICommand; import net.tylermurphy.hideAndSeek.util.Location; -import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.WorldType; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import java.util.Arrays; @@ -23,20 +22,35 @@ public class Create implements ICommand { List worlds = Main.getInstance().getWorlds(); if(worlds.contains(args[0])) { sender.sendMessage(errorPrefix + message("WORLD_EXISTS").addAmount(args[0])); + return; } WorldType type; - if(args[1].equals("normal")) { - type = WorldType.NORMAL; - } else if(args[1].equals("flat")) { - type = WorldType.FLAT; - } else { - sender.sendMessage(errorPrefix + message("INVALID_WORLD_TYPE").addAmount(args[1])); - return; + World.Environment environment; + switch (args[1]) { + case "normal": + type = WorldType.NORMAL; + environment = World.Environment.NORMAL; + break; + case "flat": + type = WorldType.FLAT; + environment = World.Environment.NORMAL; + break; + case "nether": + type = WorldType.NORMAL; + environment = World.Environment.NETHER; + break; + case "end": + type = WorldType.NORMAL; + environment = World.Environment.THE_END; + break; + default: + sender.sendMessage(errorPrefix + message("INVALID_WORLD_TYPE").addAmount(args[1])); + return; } Location temp = new Location(args[0], 0, 0, 0); - if (temp.load(type) == null) { + if (temp.load(type, environment) == null) { sender.sendMessage(errorPrefix + message("WORLD_ADDED_FAILED")); } else { sender.sendMessage(messagePrefix + message("WORLD_ADDED").addAmount(args[0])); @@ -61,7 +75,7 @@ public class Create implements ICommand { return Collections.singletonList("name"); } if(parameter.equals("type")) { - return Arrays.asList("normal", "flat"); + return Arrays.asList("normal", "flat", "nether", "end"); } return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java index 4800e08..985ccdc 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java @@ -22,12 +22,14 @@ public class Delete implements ICommand { java.util.List worlds = Main.getInstance().getWorlds(); if(!worlds.contains(args[0])) { sender.sendMessage(errorPrefix + message("WORLD_DOESNT_EXIST").addAmount(args[0])); + return; } Confirm.Confirmation confirmation = new Confirm.Confirmation(args[0], world -> { java.util.List worlds_now = Main.getInstance().getWorlds(); if(!worlds_now.contains(world)) { sender.sendMessage(errorPrefix + message("WORLD_DOESNT_EXIST").addAmount(world)); + return; } World bukkit_world = Bukkit.getWorld(world); if(bukkit_world != null && bukkit_world.getPlayers().size() > 0) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java index 2c0f745..bdb98e5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java @@ -4,6 +4,7 @@ import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.ICommand; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.World; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -20,8 +21,18 @@ public class List implements ICommand { } else { StringBuilder response = new StringBuilder(messagePrefix + message("LIST_WORLDS")); for (String world : worlds) { - boolean loaded = Bukkit.getWorld(world) != null; - response.append("\n ").append(world).append(": ").append(loaded ? ChatColor.GREEN + "LOADED" : ChatColor.YELLOW + "NOT LOADED").append(ChatColor.WHITE); + String status = ChatColor.GRAY + "NOT LOADED"; + World bukkit_world = Bukkit.getWorld(world); + if(bukkit_world != null) { + if(bukkit_world.getEnvironment() == World.Environment.NETHER) { + status = ChatColor.RED + "NETHER"; + } else if(bukkit_world.getEnvironment() == World.Environment.THE_END) { + status = ChatColor.YELLOW + "THE END"; + } else { + status = ChatColor.GREEN + bukkit_world.getWorldType().toString(); + } + } + response.append("\n ").append(world).append(": ").append(status).append(ChatColor.WHITE); } sender.sendMessage(response.toString()); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java index be699ec..958d1ca 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java @@ -126,6 +126,7 @@ public class ConfigManager { return config.contains(path); } + @SuppressWarnings("unused") public double getDouble(String path) { if (!config.contains(path)) { return defaultConfig.getDouble(path); @@ -190,10 +191,6 @@ public class ConfigManager { config.set(path, defaultConfig.get(path)); } - public void resetAll() { - config = new YamlConfiguration(); - } - public void resetFile(String newDefaultFilename) { this.defaultFilename = newDefaultFilename; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index 83fc2a6..1873fd4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -268,7 +268,7 @@ public class Board { board.setLine(String.valueOf(i), line.replace("{TEAM}", value)); } else if (line.contains("{BORDER}")) { if (!Main.getInstance().getGame().getCurrentMap().isWorldBorderEnabled()) continue; - if (worldBorder == null || status == Status.STARTING) { + if (status == Status.STARTING) { board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replace("{AMOUNT}", "0"))); } else if (!worldBorder.isRunning()) { board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replaceFirst("\\{AMOUNT}", worldBorder.getDelay()/60+"").replaceFirst("\\{AMOUNT}", worldBorder.getDelay()%60+""))); diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java index e238caf..e18a309 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Game.java @@ -97,13 +97,15 @@ public class Game { } public void start() { + Player seeker; try { int rand = (int) (Math.random() * board.getPlayers().size()); - Player seeker = board.getPlayers().get(rand); - start(seeker); + seeker = board.getPlayers().get(rand); } catch (Exception e){ Main.getInstance().getLogger().warning("Failed to select random seeker."); + return; } + start(seeker); } public void start(Player seeker) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/PlayerHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/PlayerHandler.java index 1e7ba69..d34cb11 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/PlayerHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/PlayerHandler.java @@ -2,7 +2,6 @@ package net.tylermurphy.hideAndSeek.game.listener; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.configuration.Items; -import net.tylermurphy.hideAndSeek.game.Game; import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java index e769b05..10fa783 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java @@ -51,7 +51,7 @@ public class Location { this.z = location.getZ(); } - public World load(WorldType type) { + public World load(WorldType type, World.Environment environment) { boolean mapSave = world.startsWith("hs_"); World bukkitWorld = Bukkit.getWorld(world); if(bukkitWorld != null) return bukkitWorld; @@ -59,6 +59,9 @@ public class Location { if(type != null) { creator.type(type); } + if(environment != null) { + creator.environment(environment); + } if(mapSave) { creator.generator(new VoidGenerator()); } @@ -69,7 +72,7 @@ public class Location { public World load() { if(!exists()) return null; if(!Main.getInstance().isLoaded()) return null; - return load(null); + return load(null, null); } private org.bukkit.Location toBukkit() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java index 864397e..d14f617 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/world/WorldLoader.java @@ -60,13 +60,15 @@ public class WorldLoader { } public void loadMap() { - Bukkit.getServer().createWorld(new WorldCreator(map.getGameSpawnName()).generator(new VoidGenerator())); - World world = Bukkit.getServer().getWorld(map.getGameSpawnName()); - if (world == null) { - Main.getInstance().getLogger().severe("COULD NOT LOAD " + map.getGameSpawnName()); - return; - } - world.setAutoSave(false); + Main.getInstance().scheduleTask(() -> { + Bukkit.getServer().createWorld(new WorldCreator(map.getGameSpawnName()).generator(new VoidGenerator())); + World world = Bukkit.getServer().getWorld(map.getGameSpawnName()); + if (world == null) { + Main.getInstance().getLogger().severe("COULD NOT LOAD " + map.getGameSpawnName()); + return; + } + world.setAutoSave(false); + }); } public void rollback() { -- cgit v1.2.3-freya From 0ea945d84ef519b0676793d60eb4d8b47c788e7c Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Tue, 24 Jan 2023 11:50:01 -0500 Subject: 1.7.0 rc2 (1.19.3 datawater fix) --- .github/ISSUE_TEMPLATE/bug_report.md | 33 ---------- .github/ISSUE_TEMPLATE/feature_request.md | 20 ------ .github/PULL_REQUEST_TEMPLATE.md | 11 ---- .github/workflows/beta.yml | 37 ----------- .github/workflows/release.yml | 37 ----------- lib/ProtocolLib.jar | Bin 0 -> 4875977 bytes pom.xml | 14 ++--- .../tylermurphy/hideAndSeek/game/Disguiser.java | 1 + .../tylermurphy/hideAndSeek/game/EntityHider.java | 6 +- .../tylermurphy/hideAndSeek/game/events/Glow.java | 24 +++---- .../hideAndSeek/util/packet/AbstractPacket.java | 4 +- .../util/packet/EntityMetadataPacket.java | 70 +++++++++++++++++++++ 12 files changed, 88 insertions(+), 169 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/beta.yml delete mode 100644 .github/workflows/release.yml create mode 100644 lib/ProtocolLib.jar create mode 100644 src/main/java/net/tylermurphy/hideAndSeek/util/packet/EntityMetadataPacket.java (limited to 'lib') diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index bf64440..0000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: bug report -assignees: '' - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**System Info (please complete the following information):** - - OS: [e.g. Windows/Linux] - - Server Host [e.g. Apex/Custom] - - MC Version [e.g. 1.17/1.18] - - Plugin Version [e.g. 1.3.0/1.3.1 BETA] - -**Additional context** -Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 4aea407..0000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: new plugin feature -assignees: '' - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 977e3be..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,11 +0,0 @@ -**Describe the change** -A clear and concise description of what the changes are. - -**Expected behavior** -A clear and concise description of what your changes are going to do. - -**Screenshots** -If applicable, add screenshots to help explain your changes. - -**Additional context** -Add any other context about the pull request here. diff --git a/.github/workflows/beta.yml b/.github/workflows/beta.yml deleted file mode 100644 index 7adde3f..0000000 --- a/.github/workflows/beta.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Beta - -on: - push: - branches-ignore: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - name: Checkout branch - uses: actions/checkout@v2 - - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - - name: Build with Maven - run: | - mvn -B package --file pom.xml - mkdir staging && cp target/*.jar staging - - - name: Set up a cache for maven - uses: actions/cache@v2 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - - name: Upload artifacts - uses: actions/upload-artifact@v2 - with: - name: artifacts-beta - path: staging diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 722d1c6..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Release - -on: - push: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - name: Checkout branch - uses: actions/checkout@v2 - - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - - name: Build with Maven - run: | - mvn -B package --file pom.xml - mkdir staging && cp target/*.jar staging - - - name: Set up a cache for maven - uses: actions/cache@v2 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - - name: Upload artificats - uses: actions/upload-artifact@v2 - with: - name: artifacts-release - path: staging diff --git a/lib/ProtocolLib.jar b/lib/ProtocolLib.jar new file mode 100644 index 0000000..47b952f Binary files /dev/null and b/lib/ProtocolLib.jar differ diff --git a/pom.xml b/pom.xml index 8b2a39d..df2ab1b 100644 --- a/pom.xml +++ b/pom.xml @@ -80,10 +80,10 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/public/ - - dmulloy2-repo - https://repo.dmulloy2.net/repository/public/ - + + + + placeholderapi https://repo.extendedclip.com/content/repositories/placeholderapi/ @@ -106,9 +106,9 @@ com.comphenix.protocol ProtocolLib - 4.4.0 - - + 4.8.0 + system + ${project.basedir}/lib/ProtocolLib.jar org.xerial diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java index 5fce7d3..351ba10 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Disguiser.java @@ -17,6 +17,7 @@ public class Disguiser { public Disguiser(){ this.disguises = new HashMap<>(); + } public Disguise getDisguise(Player player){ diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java index 8274655..3892f6f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java @@ -235,11 +235,7 @@ public class EntityHider implements Listener { destroyEntity.getIntegerArrays().write(0, new int[]{entity.getEntityId()}); } catch (Exception e){ return false; } // Make the entity disappear - try { - manager.sendServerPacket(observer, destroyEntity); - } catch (InvocationTargetException e) { - throw new RuntimeException("Cannot send server packet.", e); - } + manager.sendServerPacket(observer, destroyEntity); } return visibleBefore; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/events/Glow.java b/src/main/java/net/tylermurphy/hideAndSeek/game/events/Glow.java index 8631ef5..dec23d7 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/events/Glow.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/events/Glow.java @@ -6,6 +6,7 @@ import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.WrappedDataWatcher; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.util.packet.EntityMetadataPacket; import org.bukkit.entity.Player; import java.lang.reflect.InvocationTargetException; @@ -64,22 +65,13 @@ public class Glow { } public void setGlow(Player player, Player target, boolean glowing) { - PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA); - packet.getIntegers().write(0, target.getEntityId()); - WrappedDataWatcher watcher = new WrappedDataWatcher(); - WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(Byte.class); - watcher.setEntity(target); - if (glowing) { - watcher.setObject(0, serializer, (byte) (0x40)); - } else { - watcher.setObject(0, serializer, (byte) (0x0)); - } - packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects()); - try { - protocolManager.sendServerPacket(player, packet); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } + + EntityMetadataPacket packet = new EntityMetadataPacket(); + packet.setEntity(target); + packet.setGlow(glowing); + packet.writeMetadata(); + packet.send(player); + } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/packet/AbstractPacket.java b/src/main/java/net/tylermurphy/hideAndSeek/util/packet/AbstractPacket.java index 9293beb..4e3fc3b 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/util/packet/AbstractPacket.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/packet/AbstractPacket.java @@ -23,9 +23,7 @@ public class AbstractPacket { } public void send(Player player){ - try { - protocolManager.sendServerPacket(player, packet); - } catch (InvocationTargetException ignored) {} + protocolManager.sendServerPacket(player, packet); } } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/packet/EntityMetadataPacket.java b/src/main/java/net/tylermurphy/hideAndSeek/util/packet/EntityMetadataPacket.java new file mode 100644 index 0000000..d77a227 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/packet/EntityMetadataPacket.java @@ -0,0 +1,70 @@ +package net.tylermurphy.hideAndSeek.util.packet; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.wrappers.WrappedDataValue; +import com.comphenix.protocol.wrappers.WrappedDataWatcher; +import com.comphenix.protocol.wrappers.WrappedWatchableObject; +import org.bukkit.entity.Entity; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public class EntityMetadataPacket extends AbstractPacket { + + private final WrappedDataWatcher watcher; + private final WrappedDataWatcher.Serializer serializer; + + public EntityMetadataPacket(){ + super(PacketType.Play.Server.ENTITY_METADATA); + watcher = new WrappedDataWatcher(); + serializer = WrappedDataWatcher.Registry.get(Byte.class); + } + + public void setEntity(@NotNull Entity target){ + super.packet.getIntegers().write(0, target.getEntityId()); + watcher.setEntity(target); + } + + public void setGlow(boolean glowing){ + if (glowing) { + watcher.setObject(0, serializer, (byte) (0x40)); + } else { + watcher.setObject(0, serializer, (byte) (0x0)); + } + } + + public void writeMetadata() { + + // thank you to + // https://www.spigotmc.org/threads/unable-to-modify-entity-metadata-packet-using-protocollib-1-19-3.582442/ + + try { + // 1.19.3 And Up + Class.forName("com.comphenix.protocol.wrappers.WrappedDataValue"); + + final List wrappedDataValueList = new ArrayList<>(); + + for(final WrappedWatchableObject entry : watcher.getWatchableObjects()) { + if(entry == null) continue; + + final WrappedDataWatcher.WrappedDataWatcherObject watcherObject = entry.getWatcherObject(); + wrappedDataValueList.add( + new WrappedDataValue( + watcherObject.getIndex(), + watcherObject.getSerializer(), + entry.getRawValue() + ) + ); + } + + packet.getDataValueCollectionModifier().write(0, wrappedDataValueList); + + } catch (ClassCastException | ClassNotFoundException ignored) { + // 1.9 to 1.19.2 And Up + packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects()); + } + + } + +} \ No newline at end of file -- cgit v1.2.3-freya