diff --git a/README.md b/README.md index 55666c4..235c44e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ With a huge list of features this is the best free among us plugin! ## Dependencies -- [HolographicDisplays](https://dev.bukkit.org/projects/holographic-displays/files) Minimum 3.0.0 **OR** [DecentHolograms](https://www.spigotmc.org/resources/decentholograms-1-8-1-19-4-papi-support-no-dependencies.96927/) Minimum 2.8.6 +- [HolographicDisplays](https://dev.bukkit.org/projects/holographic-displays/files) Minimum 3.0.0 **OR** [DecentHolograms](https://www.spigotmc.org/resources/decentholograms-1-8-1-19-4-papi-support-no-dependencies.96927/) Minimum 2.8.8 - [ProtocolLib](https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/) Must be latest dev version. - [PlayerPoints](https://www.spigotmc.org/resources/playerpoints.80745/) Soft dependency, only needed for cosmetics. - Warning! Using commands such as /say or /tell with the config option "hidePlayersOutSideArena" set to true can kick the players inside the arena. To prevent this, you can use the [NoEncryption](https://github.com/Doclic/NoEncryption) plugin. diff --git a/build.gradle b/build.gradle index 06c2c7e..5545a1f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { id 'java' + id 'com.github.johnrengelman.shadow' version '8.1.1' } group 'spigot.gradle.project' @@ -24,12 +25,18 @@ dependencies { compileOnly 'org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT' compileOnly group: "com.comphenix.protocol", name: "ProtocolLib", version: "5.2.0-SNAPSHOT" compileOnly 'me.filoghost.holographicdisplays:holographicdisplays-api:3.0.0' - compileOnly 'org.black_ixx:playerpoints:3.2.6' - compileOnly 'me.clip:placeholderapi:2.11.5' + compileOnly 'org.black_ixx:playerpoints:3.2.7' + compileOnly 'me.clip:placeholderapi:2.11.6' compileOnly 'com.mojang:authlib:2.1.28' - compileOnly 'com.github.decentsoftware-eu:decentholograms:2.8.6' - compileOnly 'me.neznamy:tab-api:4.0.2' + compileOnly 'com.github.decentsoftware-eu:decentholograms:2.8.8' + compileOnly 'com.github.NEZNAMY:TAB-API:4.1.6' + implementation 'commons-io:commons-io:2.16.1' compileOnly files('libs/VentureChat.jar') // 3.7.1 //compileOnly files('libs/CMI-API.jar') // 9.0.0.0 +} + +shadowJar { + relocate 'org.apache.commons.io', 'com.nktfh100.AmongUs.commons.io' + minimize() } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 20db9ad..2617362 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/nktfh100/AmongUs/commands/AdminCommand.java b/src/main/java/com/nktfh100/AmongUs/commands/AdminCommand.java index 417798f..2aa56ae 100644 --- a/src/main/java/com/nktfh100/AmongUs/commands/AdminCommand.java +++ b/src/main/java/com/nktfh100/AmongUs/commands/AdminCommand.java @@ -78,6 +78,19 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String /* ---------------------------------------------------- */ + else if (args[0].equalsIgnoreCase("test") && sender instanceof Player player && (sender.hasPermission("amongus.admin.test"))) { + PlayerInfo pInfo = Main.getPlayersManager().getPlayerInfo(player); + if (!pInfo.getIsIngame()) { + player.sendMessage(ChatColor.RED + "You are not in an arena!"); + return true; + } + pInfo.getArena()._isTesting = true; + pInfo.getArena().testingPlayer = player; + player.sendMessage(ChatColor.GREEN + "Enabled testing mode!"); + } + + /* ---------------------------------------------------- */ + else if (args[0].equalsIgnoreCase("setup") && sender instanceof Player && (sender.hasPermission("amongus.admin.setup") || sender.hasPermission("amongus.admin"))) { if (args.length == 1) { ArenaSetupGui.openArenaSetupSelector((Player) sender); diff --git a/src/main/java/com/nktfh100/AmongUs/info/Arena.java b/src/main/java/com/nktfh100/AmongUs/info/Arena.java index 87c6778..71d94d4 100644 --- a/src/main/java/com/nktfh100/AmongUs/info/Arena.java +++ b/src/main/java/com/nktfh100/AmongUs/info/Arena.java @@ -77,7 +77,7 @@ public class Arena { private File arenaFile; private FileConfiguration arenaConfig; - private String name; + private final String name; private String displayName; private Integer minPlayers; private Integer maxPlayers; @@ -668,16 +668,14 @@ public void playerJoin(Player player) { AUArenaPlayerJoin ev = new AUArenaPlayerJoin(this, player); Bukkit.getPluginManager().callEvent(ev); - if (ev.isCancelled()) { - return; - } + if (ev.isCancelled()) return; - if (this.playersSpawns.size() == 0) { + if (this.playersSpawns.isEmpty()) { Logger.log(Level.SEVERE, "Arena " + this.getDisplayName() + " has no spawns!"); return; } - if (this.colors_.size() == 0) { + if (this.colors_.isEmpty()) { Logger.log(Level.SEVERE, "There are not enough colors!"); Logger.log(Level.SEVERE, "Number of colors: " + Main.getConfigManager().getAllColors().size() + ", Number of players in '" + this.getDisplayName() + "': " + this.getMaxPlayers()); @@ -1420,11 +1418,8 @@ public void startGame() { PacketContainer packet = Packets.UPDATE_DISPLAY_NAME(player.getUniqueId(), player.getName(), pInfo.getCustomName()); for (PlayerInfo pInfo1 : this.getPlayersInfo()) { - if (pInfo != pInfo1) { - Packets.sendPacket(pInfo1.getPlayer(), packet); - } + Packets.sendPacket(pInfo1.getPlayer(), packet); } - Packets.sendPacket(player, packet); this.vitalsManager.addPlayer(pInfo); si++; } diff --git a/src/main/java/com/nktfh100/AmongUs/inventory/ArenaSetupGui.java b/src/main/java/com/nktfh100/AmongUs/inventory/ArenaSetupGui.java index 2782ee2..7e258f4 100644 --- a/src/main/java/com/nktfh100/AmongUs/inventory/ArenaSetupGui.java +++ b/src/main/java/com/nktfh100/AmongUs/inventory/ArenaSetupGui.java @@ -529,11 +529,11 @@ public void execute(Player player) { player.closeInventory(); arena.endGame(false, GameEndReasons.RELOAD, GameEndWinners.NOBODY); Location loc = player.getLocation(); - String spawnLoc = loc.getWorld().getName() + "," + (loc.getBlockX() + 0.5) + "," + loc.getBlockY() + "," + String spawnLoc = loc.getWorld().getName() + "," + (loc.getBlockX() + 0.5) + "," + loc.getY() + "," + (loc.getBlockZ() + 0.5) + "," + loc.getYaw() + "," + loc.getPitch(); List allSpawns = arena.getArenaConfig().getStringList("spawnpoints"); allSpawns.add(spawnLoc); - arena.addPlayerSpawn(new Location(loc.getWorld(), loc.getBlockX() + 0.5, loc.getBlockY(), + arena.addPlayerSpawn(new Location(loc.getWorld(), loc.getBlockX() + 0.5, loc.getY(), loc.getBlockZ() + 0.5, loc.getYaw(), loc.getPitch())); arena.getArenaConfig().set("spawnpoints", allSpawns); arena.saveConfig(); diff --git a/src/main/java/com/nktfh100/AmongUs/listeners/UseEntityListener.java b/src/main/java/com/nktfh100/AmongUs/listeners/UseEntityListener.java index 7753497..4f4b98e 100644 --- a/src/main/java/com/nktfh100/AmongUs/listeners/UseEntityListener.java +++ b/src/main/java/com/nktfh100/AmongUs/listeners/UseEntityListener.java @@ -5,7 +5,6 @@ import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.wrappers.EnumWrappers; -import com.comphenix.protocol.wrappers.WrappedEnumEntityUseAction; import com.nktfh100.AmongUs.enums.GameState; import com.nktfh100.AmongUs.info.DeadBody; import com.nktfh100.AmongUs.info.FakeArmorStand; @@ -74,8 +73,12 @@ public void run() { victimInfo = Main.getPlayersManager().getPlayerInfo(victim); } - final WrappedEnumEntityUseAction wrappedAction = event.getPacket().getEnumEntityUseActions().read(0); - final EnumWrappers.EntityUseAction action = wrappedAction.getAction(); + final EnumWrappers.EntityUseAction action; + if (Main.getVersion()[0] < 17) { + action = event.getPacket().getEntityUseActions().read(0); + } else { + action = event.getPacket().getEnumEntityUseActions().read(0).getAction(); + } if (action == EnumWrappers.EntityUseAction.ATTACK) { if ((!attackerInfo.getIsIngame() && victimInfo.getIsIngame()) || (attackerInfo.getIsIngame() && !victimInfo.getIsIngame())) { diff --git a/src/main/java/com/nktfh100/AmongUs/managers/ArenaManager.java b/src/main/java/com/nktfh100/AmongUs/managers/ArenaManager.java index 004637f..ded945a 100644 --- a/src/main/java/com/nktfh100/AmongUs/managers/ArenaManager.java +++ b/src/main/java/com/nktfh100/AmongUs/managers/ArenaManager.java @@ -432,7 +432,7 @@ public void loadArena(String key, YamlConfiguration arenaSC, File file) { Logger.log(Level.INFO,"World: " + world + " doesn't exists!"); continue; } - Location loc = new Location(world, Double.valueOf(locs[1]), Double.valueOf(locs[2]), + Location loc = new Location(world, Double.valueOf(locs[1]), Double.valueOf(locs[2]) + 0.25, Double.valueOf(locs[3]), Double.valueOf(locs[4]).floatValue(), Double.valueOf(locs[5]).floatValue()); created.addPlayerSpawn(loc); diff --git a/src/main/java/com/nktfh100/AmongUs/managers/CosmeticsManager.java b/src/main/java/com/nktfh100/AmongUs/managers/CosmeticsManager.java index 879fcda..018e8f1 100644 --- a/src/main/java/com/nktfh100/AmongUs/managers/CosmeticsManager.java +++ b/src/main/java/com/nktfh100/AmongUs/managers/CosmeticsManager.java @@ -36,16 +36,16 @@ public void loadCosmetics() { YamlConfiguration config = YamlConfiguration.loadConfiguration(configFIle); try { - this.cosmetics = new HashMap>(); - for (CosmeticType cosmetic_ : CosmeticType.values()) { - String type = cosmetic_.getName(); - ConfigurationSection typeSec = config.getConfigurationSection(type); + this.cosmetics = new HashMap<>(); + for (CosmeticType cosmetic : CosmeticType.values()) { + String cosmeticName = cosmetic.getName(); + ConfigurationSection typeSec = config.getConfigurationSection(cosmeticName); if (typeSec == null) { continue; } - this.cosmetics.put(CosmeticType.valueOf(type.toUpperCase()), new HashMap()); - this.defaultCosmetics.put(CosmeticType.valueOf(type.toUpperCase()), config.getString("default_" + type)); - this.cosmeticsOrder.put(CosmeticType.valueOf(type.toUpperCase()), new ArrayList()); + this.cosmetics.put(cosmetic, new HashMap<>()); + this.defaultCosmetics.put(cosmetic, config.getString("default_" + cosmeticName)); + this.cosmeticsOrder.put(cosmetic, new ArrayList<>()); for (String itemKey : typeSec.getKeys(false)) { ConfigurationSection itemSec = typeSec.getConfigurationSection(itemKey); Material mat = Material.getMaterial(itemSec.getString("material", "BARRIER")); @@ -58,8 +58,8 @@ public void loadCosmetics() { int price = itemSec.getInt("price", 0); String permission = itemSec.getString("permission", ""); CosmeticItem cosmeticItem = new CosmeticItem(itemKey, mat, displayName, name, slot, lore, lore2, lore3, price, permission); - this.cosmetics.get(CosmeticType.valueOf(type.toUpperCase())).put(itemKey, cosmeticItem); - this.cosmeticsOrder.get(CosmeticType.valueOf(type.toUpperCase())).add(cosmeticItem); + this.cosmetics.get(cosmetic).put(itemKey, cosmeticItem); + this.cosmeticsOrder.get(cosmetic).add(cosmeticItem); } } diff --git a/src/main/java/com/nktfh100/AmongUs/managers/VisibilityManager.java b/src/main/java/com/nktfh100/AmongUs/managers/VisibilityManager.java index 1b4e76a..cb4a060 100644 --- a/src/main/java/com/nktfh100/AmongUs/managers/VisibilityManager.java +++ b/src/main/java/com/nktfh100/AmongUs/managers/VisibilityManager.java @@ -123,46 +123,45 @@ private void updateVisionOf(PlayerInfo pInfo) { // players for (PlayerInfo pInfo1 : this.arena.getPlayersInfo()) { - if(pInfo1 == null) { - continue; - } + if(pInfo1 == null) continue; + Player player1 = pInfo1.getPlayer(); - if (!pInfo1.isGhost() && player1 != player) { - if (!pInfo1.getIsInVent() && !pInfo.getIsInCameras()) { - Location player1Loc = player1.getLocation(); - if (pInfo1.getIsInCameras()) { - player1Loc = pInfo1.getPlayerCamLocTemp(); - } - // if player sees player1 - if (this.arena.getEnableReducedVision()) { - if (Utils.isInsideCircle(player.getLocation(), (double) pInfo.getVision(), player1Loc) == 2) { // if player1 goes outside view range - if (!pInfo.getPlayersHidden().contains(player1)) { - this.hidePlayer(pInfo, pInfo1, true); - } - } else if (pInfo.getPlayersHidden().contains(player1)) { // if player1 goes inside view range - this.showPlayer(pInfo, pInfo1, true); + if (pInfo1.isGhost() || player1 == player) continue; + + if (!pInfo1.getIsInVent() && !pInfo.getIsInCameras()) { + Location player1Loc = player1.getLocation(); + if (pInfo1.getIsInCameras()) { + player1Loc = pInfo1.getPlayerCamLocTemp(); + } + // if player sees player1 + if (this.arena.getEnableReducedVision()) { + if (Utils.isInsideCircle(player.getLocation(), (double) pInfo.getVision(), player1Loc) == 2) { // if player1 goes outside view range + if (!pInfo.getPlayersHidden().contains(player1)) { + this.hidePlayer(pInfo, pInfo1, true); } + } else if (pInfo.getPlayersHidden().contains(player1)) { // if player1 goes inside view range + this.showPlayer(pInfo, pInfo1, true); } } + } - // if player1 sees player - if (!pInfo.getIsInVent() && !pInfo1.getIsInCameras()) { - Location playerLoc = player.getLocation(); - if (pInfo.getIsInCameras()) { - playerLoc = pInfo.getPlayerCamLocTemp(); - } - if (this.arena.getEnableReducedVision()) { - if (Utils.isInsideCircle(player1.getLocation(), (double) pInfo1.getVision(), playerLoc) == 2) { - if (!pInfo1.getPlayersHidden().contains(player)) { - this.hidePlayer(pInfo1, pInfo, true); - } - } else if (pInfo1.getPlayersHidden().contains(player)) { - this.showPlayer(pInfo1, pInfo, true); + // if player1 sees player + if (!pInfo.getIsInVent() && !pInfo1.getIsInCameras()) { + Location playerLoc = player.getLocation(); + if (pInfo.getIsInCameras()) { + playerLoc = pInfo.getPlayerCamLocTemp(); + } + if (this.arena.getEnableReducedVision()) { + if (Utils.isInsideCircle(player1.getLocation(), (double) pInfo1.getVision(), playerLoc) == 2) { + if (!pInfo1.getPlayersHidden().contains(player)) { + this.hidePlayer(pInfo1, pInfo, true); } + } else if (pInfo1.getPlayersHidden().contains(player)) { + this.showPlayer(pInfo1, pInfo, true); } - } else if (!pInfo.getIsInVent() && pInfo1.getIsInCameras() && pInfo1.getPlayersHidden().contains(player) && !pInfo.isGhost()) { - this.showPlayer(pInfo1, pInfo, true); } + } else if (!pInfo.getIsInVent() && pInfo1.getIsInCameras() && pInfo1.getPlayersHidden().contains(player) && !pInfo.isGhost()) { + this.showPlayer(pInfo1, pInfo, true); } } } @@ -185,13 +184,20 @@ public void showPlayer(PlayerInfo pInfoToShowTo, PlayerInfo pInfoToShow, Boolean } Player playerToShow = pInfoToShow.getPlayer(); - PacketContainer spawnPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY); + Location loc = playerToShow.getLocation(); + PacketContainer spawnPacket; + if (Main.getVersion()[0] > 20 || (Main.getVersion()[0] == 20 && Main.getVersion()[1] >= 2)) { + spawnPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY); + spawnPacket.getEntityTypeModifier().write(0, EntityType.PLAYER); + spawnPacket.getIntegers().write(5, Packets.toPacketRotation(loc.getYaw())).write(4, Packets.toPacketRotation(loc.getPitch())); + + } else { + spawnPacket = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN); + spawnPacket.getBytes().write(0, Packets.toPackedByte(loc.getYaw())).write(1, Packets.toPackedByte(loc.getPitch())); + } spawnPacket.getIntegers().write(0, playerToShow.getEntityId()); spawnPacket.getUUIDs().write(0, playerToShow.getUniqueId()); - spawnPacket.getEntityTypeModifier().write(0, EntityType.PLAYER); - Location loc = playerToShow.getLocation(); spawnPacket.getDoubles().write(0, loc.getX()).write(1, loc.getY()).write(2, loc.getZ()); - spawnPacket.getBytes().write(0, Packets.toPackedByte(loc.getYaw())).write(1, Packets.toPackedByte(loc.getPitch())); Packets.sendPacket(pInfoToShowTo.getPlayer(), spawnPacket); // metadata packet diff --git a/src/main/java/com/nktfh100/AmongUs/utils/Packets.java b/src/main/java/com/nktfh100/AmongUs/utils/Packets.java index eb80149..b56eb87 100644 --- a/src/main/java/com/nktfh100/AmongUs/utils/Packets.java +++ b/src/main/java/com/nktfh100/AmongUs/utils/Packets.java @@ -22,11 +22,14 @@ import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; public class Packets { - public static byte toPackedByte(float f) { return (byte) ((int) (f * 256.0F / 360.0F)); } + public static int toPacketRotation(float f) { + return (int) (f * 256.0F / 360.0F); + } + public static void sendPacket(Player p, PacketContainer packet) { if (p.isOnline() && packet != null) { ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet); @@ -138,7 +141,7 @@ public static PacketContainer SPAWN_PLAYER(Location loc, int entityId, UUID uuid packet.getUUIDs().write(0, uuid); packet.getEntityTypeModifier().write(0, EntityType.PLAYER); packet.getDoubles().write(0, loc.getX()).write(1, loc.getY()).write(2, loc.getZ()); - packet.getBytes().write(0, toPackedByte(loc.getYaw())).write(1, toPackedByte(loc.getPitch())); + packet.getIntegers().write(5, toPacketRotation(loc.getYaw())).write(4, toPacketRotation(loc.getPitch())); return packet; } @@ -181,7 +184,7 @@ public static PacketContainer ENTITY_EQUIPMENT_HEAD(int entityId, Material mat) public static PacketContainer DESTROY_ENTITY(int entityId) { PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY); - packet.getIntLists().write(0, Collections.singletonList(entityId)); + packet.getIntegerArrays().write(0, new int[]{entityId}); return packet; } @@ -228,8 +231,8 @@ public static PacketContainer ARMOR_STAND(Location loc, Integer entityId, UUID u packet.getDoubles().write(0, loc.getX()); packet.getDoubles().write(1, loc.getY()); // location packet.getDoubles().write(2, loc.getZ()); - packet.getBytes().write(0, (byte) 0); // yaw & pitch ? - packet.getBytes().write(1, (byte) 0); + packet.getIntegers().write(4, 0); // yaw & pitch ? + packet.getIntegers().write(5, 0); return packet; } diff --git a/src/main/java/com/nktfh100/AmongUs/utils/Utils.java b/src/main/java/com/nktfh100/AmongUs/utils/Utils.java index 7e0c747..704bba0 100644 --- a/src/main/java/com/nktfh100/AmongUs/utils/Utils.java +++ b/src/main/java/com/nktfh100/AmongUs/utils/Utils.java @@ -441,7 +441,7 @@ public static ArrayList generateHollowCircle(Location loc, int radius, } public static boolean hasChangedBlockCoordinates(Location fromLoc, Location toLoc) { - return !(fromLoc.getWorld().equals(toLoc.getWorld()) && fromLoc.getBlockX() == toLoc.getBlockX() && fromLoc.getBlockZ() == toLoc.getBlockZ()); + return !Objects.equals(fromLoc.getWorld(), toLoc.getWorld()) || fromLoc.getBlockX() != toLoc.getBlockX() || fromLoc.getBlockZ() != toLoc.getBlockZ(); } // 0 = inside