From 4c438d011b29419e38f67331bdfe6b3c8f87a1d1 Mon Sep 17 00:00:00 2001 From: PauMAVA Date: Sun, 6 Jun 2021 10:48:38 +0200 Subject: [PATCH] Fix #4, #5 and #6. Created ReflectionUtils class to access NMS resources. --- .gitignore | 16 ++-- README.md | 4 +- pom.xml | 52 ++++++++++++ v1_15_2/pom.xml | 41 ++++++--- .../src/main/java/me/PauMAVA/TTR/TTRCore.java | 10 +-- .../me/PauMAVA/TTR/chat/TTRChatManager.java | 12 +-- .../TTR/commands/EnableDisableCommand.java | 2 +- .../TTR/commands/StartMatchCommand.java | 10 +-- .../PauMAVA/TTR/config/TTRConfigManager.java | 17 ++-- .../me/PauMAVA/TTR/match/AutoStarter.java | 4 +- .../main/java/me/PauMAVA/TTR/match/Cage.java | 4 +- .../me/PauMAVA/TTR/match/CageChecker.java | 19 ++--- .../me/PauMAVA/TTR/match/LootSpawner.java | 12 +-- .../me/PauMAVA/TTR/match/MatchStatus.java | 2 +- .../java/me/PauMAVA/TTR/match/TTRMatch.java | 24 +++--- .../java/me/PauMAVA/TTR/teams/TTRTeam.java | 2 +- .../me/PauMAVA/TTR/teams/TTRTeamHandler.java | 17 ++-- .../main/java/me/PauMAVA/TTR/ui/CustomUI.java | 8 +- .../java/me/PauMAVA/TTR/ui/TTRCustomTab.java | 6 +- .../java/me/PauMAVA/TTR/ui/TTRScoreboard.java | 15 ++-- .../java/me/PauMAVA/TTR/ui/TeamSelector.java | 19 ++--- .../me/PauMAVA/TTR/util/EventListener.java | 29 +++---- .../PauMAVA/TTR/util/PacketIntercepter.java | 11 +-- .../java/me/PauMAVA/TTR/util/TTRPrefix.java | 2 +- .../java/me/PauMAVA/TTR/util/XPBarTimer.java | 12 +-- .../me/PauMAVA/TTR/world/TTRWorldHandler.java | 2 +- v1_15_2/src/plugin.yml | 22 ++--- v1_16_1/pom.xml | 40 ++++++--- .../src/main/java/me/PauMAVA/TTR/TTRCore.java | 10 +-- .../me/PauMAVA/TTR/chat/TTRChatManager.java | 12 +-- .../TTR/commands/EnableDisableCommand.java | 2 +- .../TTR/commands/StartMatchCommand.java | 10 +-- .../PauMAVA/TTR/config/TTRConfigManager.java | 17 ++-- .../me/PauMAVA/TTR/match/AutoStarter.java | 4 +- .../main/java/me/PauMAVA/TTR/match/Cage.java | 4 +- .../me/PauMAVA/TTR/match/CageChecker.java | 19 ++--- .../me/PauMAVA/TTR/match/LootSpawner.java | 12 +-- .../me/PauMAVA/TTR/match/MatchStatus.java | 2 +- .../java/me/PauMAVA/TTR/match/TTRMatch.java | 59 +++++++------ .../java/me/PauMAVA/TTR/teams/TTRTeam.java | 2 +- .../me/PauMAVA/TTR/teams/TTRTeamHandler.java | 17 ++-- .../main/java/me/PauMAVA/TTR/ui/CustomUI.java | 8 +- .../java/me/PauMAVA/TTR/ui/TTRCustomTab.java | 24 +++--- .../java/me/PauMAVA/TTR/ui/TTRScoreboard.java | 15 ++-- .../java/me/PauMAVA/TTR/ui/TeamSelector.java | 19 ++--- .../me/PauMAVA/TTR/util/EventListener.java | 24 +++--- .../PauMAVA/TTR/util/PacketIntercepter.java | 11 +-- .../me/PauMAVA/TTR/util/ReflectionUtils.java | 83 +++++++++++++++++++ .../java/me/PauMAVA/TTR/util/TTRPrefix.java | 2 +- .../java/me/PauMAVA/TTR/util/XPBarTimer.java | 12 +-- .../me/PauMAVA/TTR/world/TTRWorldHandler.java | 2 +- v1_16_1/src/plugin.yml | 22 ++--- 52 files changed, 485 insertions(+), 321 deletions(-) create mode 100644 pom.xml create mode 100644 v1_16_1/src/main/java/me/PauMAVA/TTR/util/ReflectionUtils.java diff --git a/.gitignore b/.gitignore index d9faff4..3660266 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ - -.idea/ - -*.iml - -v1_15_2/target/ - -v1_16_1/target/ + +.idea/ + +*.iml + +v1_15_2/target/ + +v1_16_1/target/ diff --git a/README.md b/README.md index 76715e5..466ac47 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # TheTowersRemastered -A remsatered version of The Towers for 1.15.X +A remastered version of The Towers for 1.15.X - 1.16.X ## License (GNU v3) ```` TheTowersRemastered (TTR) - Copyright (c) 2019-2020 Pau Machetti Vallverdú + Copyright (c) 2019-2021 Pau Machetti VallverdĂș This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..37d5d4e --- /dev/null +++ b/pom.xml @@ -0,0 +1,52 @@ + + + + + 4.0.0 + + me.PauMAVA + TheTowersRemastered + 1.2.1 + + pom + + + v1_15_2 + v1_16_1 + + + TheTowersRemastered [Parent] + https://github.com/PauMAVA/TheTowersRemastered + + + UTF-8 + 11 + 11 + + + + + PauMAVen + https://raw.githubusercontent.com/PauMAVA/PauMAVen/master + + + + \ No newline at end of file diff --git a/v1_15_2/pom.xml b/v1_15_2/pom.xml index df5b243..1042bcc 100644 --- a/v1_15_2/pom.xml +++ b/v1_15_2/pom.xml @@ -1,12 +1,37 @@ + + 4.0.0 - me.PauMAVA - TheTowersRemastered - 1.1 + TheTowersRemastered.15 + + + me.PauMAVA + TheTowersRemastered + 1.2.1 + + + TheTowersRemastered [1.15.2] + src @@ -53,7 +78,7 @@ Copying .jar to Development Server.... - + @@ -65,12 +90,7 @@ - - - PauMAVen - https://raw.githubusercontent.com/PauMAVA/PauMAVen/master - - + me.PauMAVA @@ -79,4 +99,5 @@ provided + \ No newline at end of file diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/TTRCore.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/TTRCore.java index 775e81b..3c7e603 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/TTRCore.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/TTRCore.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,7 +21,6 @@ import me.PauMAVA.TTR.commands.StartMatchCommand; import me.PauMAVA.TTR.config.TTRConfigManager; import me.PauMAVA.TTR.match.AutoStarter; -import me.PauMAVA.TTR.match.LootSpawner; import me.PauMAVA.TTR.match.MatchStatus; import me.PauMAVA.TTR.match.TTRMatch; import me.PauMAVA.TTR.teams.TTRTeamHandler; @@ -29,8 +28,6 @@ import me.PauMAVA.TTR.ui.TTRScoreboard; import me.PauMAVA.TTR.util.EventListener; import me.PauMAVA.TTR.world.TTRWorldHandler; -import org.bukkit.ChatColor; -import org.bukkit.World; import org.bukkit.plugin.java.JavaPlugin; public class TTRCore extends JavaPlugin { @@ -56,7 +53,7 @@ public void onEnable() { getLogger().warning("TTR is disabled on server start. Use /ttrenable to enable it on start. Make sure to be using the desired map."); } this.configManager = new TTRConfigManager(this.getConfig()); - if(enabled) { + if (enabled) { this.customTab = new TTRCustomTab(); this.scoreboard = new TTRScoreboard(); this.match = new TTRMatch(MatchStatus.PREGAME); @@ -82,7 +79,8 @@ public void onDisable() { try { this.customTab.cancel(); this.scoreboard.removeScoreboard(); - } catch (NullPointerException ignored) {} + } catch (NullPointerException ignored) { + } } public static TTRCore getInstance() { diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/chat/TTRChatManager.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/chat/TTRChatManager.java index 381d6e9..f7c93f7 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/chat/TTRChatManager.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/chat/TTRChatManager.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ public class TTRChatManager { public static void sendMessage(Player sender, String originalMessage) { - if(originalMessage.startsWith("!")) { + if (originalMessage.startsWith("!")) { dispatchGlobalMessage(originalMessage); } else { dispatchTeamMessage(originalMessage, sender); @@ -37,18 +37,18 @@ public static void sendMessage(Player sender, String originalMessage) { } private static void dispatchGlobalMessage(String string) { - for(Player p: Bukkit.getServer().getOnlinePlayers()) { + for (Player p : Bukkit.getServer().getOnlinePlayers()) { p.sendMessage(TTRPrefix.TTR_GLOBAL + "" + ChatColor.GRAY + string); } } private static void dispatchTeamMessage(String string, Player sender) { TTRTeam playerTeam = TTRCore.getInstance().getTeamHandler().getPlayerTeam(sender); - if(playerTeam == null) { + if (playerTeam == null) { return; } - for(Player p: playerTeam.getPlayers()) { - p.sendMessage(TTRPrefix.TTR_TEAM + "" + ChatColor.GRAY + string); + for (Player p : playerTeam.getPlayers()) { + p.sendMessage(TTRPrefix.TTR_TEAM + "" + ChatColor.GRAY + string); } } diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/commands/EnableDisableCommand.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/commands/EnableDisableCommand.java index 1cfd174..49c655f 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/commands/EnableDisableCommand.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/commands/EnableDisableCommand.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/commands/StartMatchCommand.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/commands/StartMatchCommand.java index 455d216..76cc520 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/commands/StartMatchCommand.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/commands/StartMatchCommand.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,17 +26,13 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - public class StartMatchCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender theSender, Command command, String label, String[] args) { - if(TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { + if (TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { int timer; if (args == null || args.length == 0) { - timer = 10; + timer = 10; } else { try { timer = Integer.parseInt(args[0]); diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/config/TTRConfigManager.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/config/TTRConfigManager.java index e24f572..c7f1bef 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/config/TTRConfigManager.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/config/TTRConfigManager.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,10 +20,11 @@ import me.PauMAVA.TTR.TTRCore; import me.PauMAVA.TTR.teams.TTRTeam; -import org.bukkit.*; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.Hash; import java.io.File; import java.util.*; @@ -40,7 +41,7 @@ public class TTRConfigManager { public TTRConfigManager(FileConfiguration configuration) { this.configuration = configuration; this.world = TTRCore.getInstance().getServer().getWorlds().get(0); - if(!new File(TTRCore.getInstance().getDataFolder() + "/config.yml").exists()) { + if (!new File(TTRCore.getInstance().getDataFolder() + "/config.yml").exists()) { setUpFile(); saveConfig(); } else { @@ -88,8 +89,8 @@ public Set getTeamNames() { } private ConfigurationSection getTeam(String teamName) { - for(String key: this.teamsSection.getKeys(false)) { - if(key.equalsIgnoreCase(teamName)) { + for (String key : this.teamsSection.getKeys(false)) { + if (key.equalsIgnoreCase(teamName)) { return this.teamsSection.getConfigurationSection(key); } } @@ -110,8 +111,8 @@ public Location getTeamCage(String teamName) { public HashMap getTeamCages() { HashMap cages = new HashMap(); - for(String teamName: getTeamNames()) { - cages.put(getTeamCage(teamName), TTRCore.getInstance().getTeamHandler().getTeam(teamName )); + for (String teamName : getTeamNames()) { + cages.put(getTeamCage(teamName), TTRCore.getInstance().getTeamHandler().getTeam(teamName)); } return cages; } diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/match/AutoStarter.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/match/AutoStarter.java index eb7ba4f..8bf37df 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/match/AutoStarter.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/match/AutoStarter.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -72,7 +72,7 @@ private void removePlayerFromList(Player player) { } private boolean isPlayerInQueue(Player player) { - for (Player p: queue) { + for (Player p : queue) { if (player.getUniqueId().equals(p.getUniqueId())) { return true; } diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/match/Cage.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/match/Cage.java index 293c211..2939554 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/match/Cage.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/match/Cage.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,8 +22,6 @@ import org.bukkit.Location; import org.bukkit.entity.Player; -import java.util.List; - public class Cage { private Location location; diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/match/CageChecker.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/match/CageChecker.java index f2c2fc9..29d2552 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/match/CageChecker.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/match/CageChecker.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,6 @@ import me.PauMAVA.TTR.TTRCore; import me.PauMAVA.TTR.teams.TTRTeam; -import me.PauMAVA.TTR.ui.TTRScoreboard; import me.PauMAVA.TTR.util.TTRPrefix; import org.bukkit.*; import org.bukkit.entity.Player; @@ -37,16 +36,16 @@ public class CageChecker { public void startChecking() { - this.checkerTaskPID = new BukkitRunnable(){ + this.checkerTaskPID = new BukkitRunnable() { @Override public void run() { - for(Player p: Bukkit.getServer().getOnlinePlayers()) { - for(Cage cage: cages) { + for (Player p : Bukkit.getServer().getOnlinePlayers()) { + for (Cage cage : cages) { Location particleLocation = new Location(cage.getLocation().getWorld(), cage.getLocation().getBlockX(), cage.getLocation().getBlockY() + 1, cage.getLocation().getBlockZ()); particleLocation.add(particleLocation.getX() > 0 ? 0.5 : -0.5, 0.0, particleLocation.getZ() > 0 ? 0.5 : -0.5); cage.getLocation().getWorld().spawnParticle(Particle.SPELL, particleLocation, 100); - if(cage.isInCage(p) && TTRCore.getInstance().getTeamHandler().getPlayerTeam(p) != null) { - if(cage.getOwner().equals(TTRCore.getInstance().getTeamHandler().getPlayerTeam(p))) { + if (cage.isInCage(p) && TTRCore.getInstance().getTeamHandler().getPlayerTeam(p) != null) { + if (cage.getOwner().equals(TTRCore.getInstance().getTeamHandler().getPlayerTeam(p))) { p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 10, 1); p.sendMessage(TTRPrefix.TTR_GAME + "" + ChatColor.RED + "You can't do that!"); p.teleport(TTRCore.getInstance().getConfigManager().getTeamSpawn(TTRCore.getInstance().getTeamHandler().getPlayerTeam(p).getIdentifier())); @@ -71,16 +70,16 @@ private void playerOnCage(Player player) { playersTeam.addPoints(1); TTRCore.getInstance().getScoreboard().refreshScoreboard(); Bukkit.broadcastMessage(TTRPrefix.TTR_GAME + "" + ChatColor.GRAY + player.getName() + " has scored a point!"); - for(Player p: Bukkit.getServer().getOnlinePlayers()) { + for (Player p : Bukkit.getServer().getOnlinePlayers()) { p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 10, 1); } - if(playersTeam.getPoints() >= TTRCore.getInstance().getConfigManager().getMaxPoints()) { + if (playersTeam.getPoints() >= TTRCore.getInstance().getConfigManager().getMaxPoints()) { TTRCore.getInstance().getCurrentMatch().endMatch(playersTeam); } } public void setCages(HashMap cages, int effectiveRadius) { - for(Location cage: cages.keySet()) { + for (Location cage : cages.keySet()) { this.cages.add(new Cage(cage, effectiveRadius, cages.get(cage))); } } diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/match/LootSpawner.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/match/LootSpawner.java index 2768b1f..943d5b7 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/match/LootSpawner.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/match/LootSpawner.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,10 +21,10 @@ import me.PauMAVA.TTR.TTRCore; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.Material; import java.util.List; @@ -53,10 +53,10 @@ public void stopSpawning() { } private void setIronTask() { - this.ironTaskPID = new BukkitRunnable(){ + this.ironTaskPID = new BukkitRunnable() { @Override public void run() { - for(Location location: ironLocations) { + for (Location location : ironLocations) { Location copy = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()); copy.add(location.getX() > 0 ? 0.5 : 0.5, 0.0, location.getZ() > 0 ? 0.5 : -0.5); location.getWorld().dropItem(copy, new ItemStack(Material.IRON_INGOT, 1)); @@ -66,10 +66,10 @@ public void run() { } private void setXpTask() { - this.xpTaskPID = new BukkitRunnable(){ + this.xpTaskPID = new BukkitRunnable() { @Override public void run() { - for(Location location: xpLocations) { + for (Location location : xpLocations) { Location copy = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()); copy.add(location.getX() > 0 ? 0.5 : 0.5, 0.0, location.getZ() > 0 ? 0.5 : -0.5); location.getWorld().spawnEntity(copy, EntityType.THROWN_EXP_BOTTLE); diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/match/MatchStatus.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/match/MatchStatus.java index 69b9db2..00d5e0b 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/match/MatchStatus.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/match/MatchStatus.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/match/TTRMatch.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/match/TTRMatch.java index 69e2fd7..10c5aa2 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/match/TTRMatch.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/match/TTRMatch.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,6 @@ import me.PauMAVA.TTR.TTRCore; import me.PauMAVA.TTR.teams.TTRTeam; -import net.minecraft.server.v1_15_R1.Items; import net.minecraft.server.v1_15_R1.PacketPlayInClientCommand; import net.minecraft.server.v1_15_R1.PacketPlayInClientCommand.EnumClientCommand; import org.bukkit.*; @@ -30,7 +29,6 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.scheduler.BukkitRunnable; @@ -63,9 +61,9 @@ public void startMatch() { TTRCore.getInstance().getWorldHandler().configureWeather(); TTRCore.getInstance().getWorldHandler().setWorldDifficulty(Difficulty.PEACEFUL); TTRCore.getInstance().getScoreboard().startScoreboardTask(); - for(Player player: Bukkit.getServer().getOnlinePlayers()) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { TTRTeam playerTeam = TTRCore.getInstance().getTeamHandler().getPlayerTeam(player); - if(playerTeam == null) { + if (playerTeam == null) { continue; } player.teleport(TTRCore.getInstance().getConfigManager().getTeamSpawn(playerTeam.getIdentifier())); @@ -88,7 +86,7 @@ public void endMatch(TTRTeam team) { this.status = MatchStatus.ENDED; this.lootSpawner.stopSpawning(); TTRCore.getInstance().getScoreboard().stopScoreboardTask(); - for(Player player: Bukkit.getServer().getOnlinePlayers()) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { player.setGameMode(GameMode.SPECTATOR); ChatColor teamColor = TTRCore.getInstance().getConfigManager().getTeamColor(team.getIdentifier()); player.sendTitle(teamColor + "" + ChatColor.BOLD + team.getIdentifier(), ChatColor.AQUA + "WINS!", 10, 100, 20); @@ -100,7 +98,7 @@ public void endMatch(TTRTeam team) { } public void playerDeath(Player player, Player killer) { - new BukkitRunnable(){ + new BukkitRunnable() { @Override public void run() { PacketPlayInClientCommand packet = new PacketPlayInClientCommand(); @@ -114,12 +112,12 @@ public void run() { e.printStackTrace(); } TTRTeam team = TTRCore.getInstance().getTeamHandler().getPlayerTeam(player); - if(team != null) { + if (team != null) { player.teleport(TTRCore.getInstance().getConfigManager().getTeamSpawn(team.getIdentifier())); } setPlayerArmor(player); - player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 10 ,1); - player.playSound(player.getLocation(), Sound.BLOCK_GLASS_BREAK, 10 ,1); + player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 10, 1); + player.playSound(player.getLocation(), Sound.BLOCK_GLASS_BREAK, 10, 1); this.cancel(); kills.put(killer, getKills(killer) + 1); } @@ -129,15 +127,15 @@ public void run() { private void setPlayerArmor(Player player) { TTRTeam team = TTRCore.getInstance().getTeamHandler().getPlayerTeam(player); ChatColor color; - if(team != null) { + if (team != null) { color = TTRCore.getInstance().getConfigManager().getTeamColor(team.getIdentifier()); } else { return; } ItemStack[] armor = new ItemStack[]{new ItemStack(Material.LEATHER_BOOTS, 1), new ItemStack(Material.LEATHER_LEGGINGS, 1), new ItemStack(Material.LEATHER_CHESTPLATE, 1), new ItemStack(Material.LEATHER_HELMET, 1)}; - for(ItemStack itemStack: armor) { + for (ItemStack itemStack : armor) { LeatherArmorMeta meta = (LeatherArmorMeta) itemStack.getItemMeta(); - Color armorColor = Color.fromRGB(0,0,0); + Color armorColor = Color.fromRGB(0, 0, 0); try { meta.setColor((Color) armorColor.getClass().getDeclaredField(color.name()).get(armorColor)); } catch (NoSuchFieldException | IllegalAccessException e) { diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/teams/TTRTeam.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/teams/TTRTeam.java index 4daea6c..7242292 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/teams/TTRTeam.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/teams/TTRTeam.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/teams/TTRTeamHandler.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/teams/TTRTeamHandler.java index 5aa3484..ef54c58 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/teams/TTRTeamHandler.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/teams/TTRTeamHandler.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,6 @@ import me.PauMAVA.TTR.TTRCore; import me.PauMAVA.TTR.match.TTRMatch; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -33,14 +32,14 @@ public class TTRTeamHandler { private List teams = new ArrayList(); public void setUpDefaultTeams() { - for(String team: TTRCore.getInstance().getConfigManager().getTeamNames()) { + for (String team : TTRCore.getInstance().getConfigManager().getTeamNames()) { this.teams.add(new TTRTeam(team)); } } public boolean addPlayerToTeam(Player player, String teamIdentifier) { TTRTeam team = getTeam(teamIdentifier); - if(team == null) { + if (team == null) { return false; } team.addPlayer(player); @@ -49,7 +48,7 @@ public boolean addPlayerToTeam(Player player, String teamIdentifier) { public boolean removePlayerFromTeam(Player player, String teamIdentifier) { TTRTeam team = getTeam(teamIdentifier); - if(team == null) { + if (team == null) { return false; } team.removePlayer(player); @@ -57,8 +56,8 @@ public boolean removePlayerFromTeam(Player player, String teamIdentifier) { } public TTRTeam getPlayerTeam(Player player) { - for(TTRTeam team: this.teams) { - if(team.getPlayers().contains(player)) { + for (TTRTeam team : this.teams) { + if (team.getPlayers().contains(player)) { return team; } } @@ -66,9 +65,9 @@ public TTRTeam getPlayerTeam(Player player) { } public TTRTeam getTeam(String teamIdentifier) { - for(TTRTeam team: this.teams) { + for (TTRTeam team : this.teams) { teamIdentifier = ChatColor.stripColor(teamIdentifier); - if(teamIdentifier.contentEquals(team.getIdentifier())) { + if (teamIdentifier.contentEquals(team.getIdentifier())) { return team; } } diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/CustomUI.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/CustomUI.java index 571317b..25026fc 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/CustomUI.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/CustomUI.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,19 +45,19 @@ void openUI(Player player) { } void closeUI(Player player) { - if(player.getOpenInventory().equals(this.inventory)) { + if (player.getOpenInventory().equals(this.inventory)) { player.closeInventory(); } } public void setSlot(int id, ItemStack item, @Nullable String title, @Nullable String lore) { - if(title == null) { + if (title == null) { this.inventory.setItem(id, item); return; } ItemMeta meta = item.getItemMeta(); meta.setDisplayName(title); - if(lore != null) { + if (lore != null) { meta.setLore(new ArrayList(Arrays.asList(lore))); } item.setItemMeta(meta); diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/TTRCustomTab.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/TTRCustomTab.java index 4333d59..e1722f3 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/TTRCustomTab.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/TTRCustomTab.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,7 +33,7 @@ public class TTRCustomTab extends BukkitRunnable { private String prefix = ""; - private String suffix = ChatColor.AQUA + "(c) 2019-2020" + ChatColor.BOLD + " PauMAVA" + ChatColor.RESET + "\n" + ChatColor.GREEN + "The Towers Remastered (TTR)"; + private String suffix = ChatColor.AQUA + "(c) 2019-2021" + ChatColor.BOLD + " PauMAVA" + ChatColor.RESET + "\n" + ChatColor.GREEN + "The Towers Remastered (TTR)"; private int i = 1; @Override @@ -67,7 +67,7 @@ private void sendPacket() { footer.setAccessible(true); header.set(packet, new ChatComponentText(this.prefix)); footer.set(packet, new ChatComponentText(this.suffix)); - for(Player player: Bukkit.getServer().getOnlinePlayers()) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); } } catch (IllegalAccessException | NoSuchFieldException | DecoderException e) { diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/TTRScoreboard.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/TTRScoreboard.java index 011e464..9b6cbeb 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/TTRScoreboard.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/TTRScoreboard.java @@ -30,26 +30,27 @@ public TTRScoreboard() { public void refreshScoreboard() { updatePoints(); - for(Player player: Bukkit.getServer().getOnlinePlayers()) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { player.setScoreboard(this.ttrScoreboard); this.kills.getScore(player.getName()).setScore(TTRCore.getInstance().getCurrentMatch().getKills(player)); } } public void removeScoreboard() { - for(Player player: Bukkit.getServer().getOnlinePlayers()) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { player.setScoreboard(this.scoreboardManager.getMainScoreboard()); } } public void startScoreboardTask() { - this.taskPID = new BukkitRunnable(){ + this.taskPID = new BukkitRunnable() { private int i = 0; + @Override public void run() { updatePoints(); points.getScore(ChatColor.DARK_GRAY + "§m ").setScore(-1); - if(totalTime != null) { + if (totalTime != null) { ttrScoreboard.resetScores(totalTime.getEntry()); } totalTime = points.getScore(ChatColor.GREEN + "" + ChatColor.BOLD + "Total time: " + ChatColor.GRAY + prettyTime(i)); @@ -60,12 +61,12 @@ public void run() { private String prettyTime(int i) { String elapsedMinutes, elapsedSeconds; - if((((i % 86400) % 3600) / 60) < 10) { + if ((((i % 86400) % 3600) / 60) < 10) { elapsedMinutes = "0" + ((i % 86400) % 3600) / 60; } else { elapsedMinutes = "" + ((i % 86400) % 3600) / 60; } - if((((i % 86400) % 3600) % 60) < 10) { + if ((((i % 86400) % 3600) % 60) < 10) { elapsedSeconds = "0" + ((i % 86400) % 3600) % 60; } else { elapsedSeconds = "" + ((i % 86400) % 3600) % 60; @@ -77,7 +78,7 @@ private String prettyTime(int i) { } private void updatePoints() { - for(TTRTeam team: TTRCore.getInstance().getTeamHandler().getTeams()) { + for (TTRTeam team : TTRCore.getInstance().getTeamHandler().getTeams()) { ChatColor teamColor = TTRCore.getInstance().getConfigManager().getTeamColor(team.getIdentifier()); points.getScore(teamColor + "" + ChatColor.BOLD + team.getIdentifier()).setScore(team.getPoints()); } diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/TeamSelector.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/TeamSelector.java index 442a142..a458d11 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/TeamSelector.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/ui/TeamSelector.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,6 @@ import me.PauMAVA.TTR.TTRCore; import me.PauMAVA.TTR.teams.TTRTeam; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -44,12 +43,12 @@ public TeamSelector(Player player) { setUp(); TTRCore.getInstance().getServer().getPluginManager().registerEvents(this, TTRCore.getInstance()); TTRTeam possibleTeam = TTRCore.getInstance().getTeamHandler().getPlayerTeam(this.owner); - if(possibleTeam != null) { - for(int i = 0; i < super.getInventory().getSize(); i++) { + if (possibleTeam != null) { + for (int i = 0; i < super.getInventory().getSize(); i++) { ItemStack stack = super.getInventory().getItem(i); - if(stack != null) { + if (stack != null) { String cleanName = ChatColor.stripColor(stack.getItemMeta().getDisplayName()); - if(possibleTeam.getIdentifier().equalsIgnoreCase(cleanName)) { + if (possibleTeam.getIdentifier().equalsIgnoreCase(cleanName)) { this.selected = i; addEnchantment(i); break; @@ -69,7 +68,7 @@ public void closeSelector() { public void setUp() { int i = 0; - for(String teamName: TTRCore.getInstance().getConfigManager().getTeamNames()) { + for (String teamName : TTRCore.getInstance().getConfigManager().getTeamNames()) { setSlot(i, new ItemStack(Material.valueOf(TTRCore.getInstance().getConfigManager().getTeamColor(teamName).name() + "_WOOL"), 1), TTRCore.getInstance().getConfigManager().getTeamColor(teamName) + teamName, null); i++; } @@ -77,18 +76,18 @@ public void setUp() { @EventHandler public void onInventoryClick(InventoryClickEvent event) { - if(event.getClickedInventory() == super.getInventory() && event.getClickedInventory().getItem(event.getSlot()) != null) { + if (event.getClickedInventory() == super.getInventory() && event.getClickedInventory().getItem(event.getSlot()) != null) { this.selected = event.getSlot(); setUp(); addEnchantment(this.selected); String teamName = super.getInventory().getItem(this.selected).getItemMeta().getDisplayName(); TTRCore.getInstance().getTeamHandler().addPlayer(teamName, this.owner); - if(lastTeam != null) { + if (lastTeam != null) { TTRCore.getInstance().getTeamHandler().removePlayer(teamName, this.owner); } this.lastTeam = teamName; } - if(TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { + if (TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { event.setCancelled(true); } } diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/util/EventListener.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/util/EventListener.java index ed33322..215fad2 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/util/EventListener.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/util/EventListener.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +21,6 @@ import me.PauMAVA.TTR.TTRCore; import me.PauMAVA.TTR.match.MatchStatus; import me.PauMAVA.TTR.ui.TeamSelector; -import net.minecraft.server.v1_15_R1.PacketPlayInClientCommand; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -34,7 +32,6 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; @@ -42,15 +39,13 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import java.lang.reflect.Field; - public class EventListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - if(TTRCore.getInstance().enabled()) { + if (TTRCore.getInstance().enabled()) { event.setJoinMessage(TTRPrefix.TTR_GAME + "" + ChatColor.GREEN + "+ " + ChatColor.GRAY + event.getPlayer().getName() + " has joined the game"); - if(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.PREGAME) { + if (TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.PREGAME) { Inventory playerInventory = event.getPlayer().getInventory(); playerInventory.clear(); playerInventory.setItem(0, new ItemStack(Material.BLACK_BANNER)); @@ -65,7 +60,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { - if(TTRCore.getInstance().enabled()) { + if (TTRCore.getInstance().enabled()) { event.setQuitMessage(TTRPrefix.TTR_GAME + "" + ChatColor.RED + "- " + ChatColor.GRAY + event.getPlayer().getName() + " has left the game"); TTRCore.getInstance().getAutoStarter().removePlayerFromQueue(event.getPlayer()); } @@ -73,19 +68,19 @@ public void onPlayerLeave(PlayerQuitEvent event) { @EventHandler public void onPlayerDropEvent(PlayerDropItemEvent event) { - if(TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { + if (TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { event.setCancelled(true); } } @EventHandler public void playerClickEvent(PlayerInteractEvent event) { - if(TTRCore.getInstance().enabled() && !(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.INGAME)) { - if(event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (TTRCore.getInstance().enabled() && !(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.INGAME)) { + if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) { return; } event.setCancelled(true); - if(event.getItem() != null && event.getItem().getType() == Material.BLACK_BANNER) { + if (event.getItem() != null && event.getItem().getType() == Material.BLACK_BANNER) { new TeamSelector(event.getPlayer()).openSelector(); } } @@ -93,7 +88,7 @@ public void playerClickEvent(PlayerInteractEvent event) { @EventHandler public void placeBlockEvent(BlockPlaceEvent event) { - if(TTRCore.getInstance().enabled() && !(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.INGAME)) { + if (TTRCore.getInstance().enabled() && !(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.INGAME)) { event.getPlayer().sendMessage(TTRPrefix.TTR_GAME + "" + ChatColor.RED + "You cannot place a block there!"); event.setCancelled(true); } @@ -101,7 +96,7 @@ public void placeBlockEvent(BlockPlaceEvent event) { @EventHandler public void breakBlockEvent(BlockBreakEvent event) { - if(TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { + if (TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { event.getPlayer().sendMessage(TTRPrefix.TTR_GAME + "" + ChatColor.RED + "You cannot break that block!"); event.setCancelled(true); } @@ -109,14 +104,14 @@ public void breakBlockEvent(BlockBreakEvent event) { @EventHandler public void onPlayerDeath(PlayerDeathEvent event) { - if(TTRCore.getInstance().enabled() && TTRCore.getInstance().getCurrentMatch().isOnCourse()) { + if (TTRCore.getInstance().enabled() && TTRCore.getInstance().getCurrentMatch().isOnCourse()) { TTRCore.getInstance().getCurrentMatch().playerDeath(event.getEntity(), event.getEntity().getKiller()); } } @EventHandler public void onPlayerDamage(EntityDamageEvent event) { - if(event.getEntity() instanceof Player && !(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.INGAME)) { + if (event.getEntity() instanceof Player && !(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.INGAME)) { event.setCancelled(true); } } diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/util/PacketIntercepter.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/util/PacketIntercepter.java index 8728312..e1c8044 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/util/PacketIntercepter.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/util/PacketIntercepter.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,13 +31,13 @@ public class PacketIntercepter { public void addPlayer(Player player) { - ChannelDuplexHandler channelDuplexHandler = new ChannelDuplexHandler(){ + ChannelDuplexHandler channelDuplexHandler = new ChannelDuplexHandler() { @Override public void channelRead(ChannelHandlerContext context, Object packet) { - if(TTRCore.getInstance().enabled() && TTRCore.getInstance().getCurrentMatch().isOnCourse() && packet instanceof PacketPlayInChat && !((PacketPlayInChat) packet).b().startsWith("/")) { + if (TTRCore.getInstance().enabled() && TTRCore.getInstance().getCurrentMatch().isOnCourse() && packet instanceof PacketPlayInChat && !((PacketPlayInChat) packet).b().startsWith("/")) { TTRChatManager.sendMessage(player, ((PacketPlayInChat) packet).b()); } - try{ + try { super.channelRead(context, packet); } catch (Exception e) { TTRCore.getInstance().getLogger().warning("An error occurred on packet reading process!"); @@ -53,7 +53,8 @@ public void write(ChannelHandlerContext context, Object packet, ChannelPromise p ChannelPipeline pipeline = ((CraftPlayer) player).getHandle().playerConnection.networkManager.channel.pipeline(); try { pipeline.addBefore("packet_handler", player.getName(), channelDuplexHandler); - } catch (IllegalArgumentException ignored) {} + } catch (IllegalArgumentException ignored) { + } } diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/util/TTRPrefix.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/util/TTRPrefix.java index 97f4cf4..d03f29e 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/util/TTRPrefix.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/util/TTRPrefix.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/util/XPBarTimer.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/util/XPBarTimer.java index b30b14a..1af9c92 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/util/XPBarTimer.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/util/XPBarTimer.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,16 +43,16 @@ public XPBarTimer(int time, Method execute) { @Override public void run() { - for(Player player: Bukkit.getServer().getOnlinePlayers()) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { player.setLevel(i); } - if(i <= 5) { - for(Player player: Bukkit.getServer().getOnlinePlayers()) { + if (i <= 5) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 10, 1); } } - if(i <= 0) { - if(this.execute != null) { + if (i <= 0) { + if (this.execute != null) { try { this.execute.invoke(TTRCore.getInstance().getCurrentMatch()); } catch (IllegalAccessException | InvocationTargetException e) { diff --git a/v1_15_2/src/main/java/me/PauMAVA/TTR/world/TTRWorldHandler.java b/v1_15_2/src/main/java/me/PauMAVA/TTR/world/TTRWorldHandler.java index b4f5481..cafb65c 100644 --- a/v1_15_2/src/main/java/me/PauMAVA/TTR/world/TTRWorldHandler.java +++ b/v1_15_2/src/main/java/me/PauMAVA/TTR/world/TTRWorldHandler.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/v1_15_2/src/plugin.yml b/v1_15_2/src/plugin.yml index 46c993a..7c559f2 100644 --- a/v1_15_2/src/plugin.yml +++ b/v1_15_2/src/plugin.yml @@ -1,12 +1,12 @@ -name: TheTowersRemastered -version: 1.1 -api-version: 1.15 -main: me.PauMAVA.TTR.TTRCore - -commands: - ttrstart: - description: Start the match - ttrenable: - description: Enbles the plugin on server start. - ttrdisable: +name: TheTowersRemastered +version: 1.2.1 +api-version: 1.15 +main: me.PauMAVA.TTR.TTRCore + +commands: + ttrstart: + description: Start the match + ttrenable: + description: Enbles the plugin on server start. + ttrdisable: description: Disables the plugin on server start. \ No newline at end of file diff --git a/v1_16_1/pom.xml b/v1_16_1/pom.xml index d4f0dbd..42c1efc 100644 --- a/v1_16_1/pom.xml +++ b/v1_16_1/pom.xml @@ -1,12 +1,37 @@ + + 4.0.0 - me.PauMAVA - TheTowersRemastered - 1.2 + TheTowersRemastered.16 + + + me.PauMAVA + TheTowersRemastered + 1.2.1 + + + TheTowersRemastered [1.16.1] + src @@ -53,7 +78,7 @@ Copying .jar to Development Server.... - + @@ -65,12 +90,7 @@ - - - PauMAVen - https://raw.githubusercontent.com/PauMAVA/PauMAVen/master - - + me.PauMAVA diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/TTRCore.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/TTRCore.java index 775e81b..3c7e603 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/TTRCore.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/TTRCore.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,7 +21,6 @@ import me.PauMAVA.TTR.commands.StartMatchCommand; import me.PauMAVA.TTR.config.TTRConfigManager; import me.PauMAVA.TTR.match.AutoStarter; -import me.PauMAVA.TTR.match.LootSpawner; import me.PauMAVA.TTR.match.MatchStatus; import me.PauMAVA.TTR.match.TTRMatch; import me.PauMAVA.TTR.teams.TTRTeamHandler; @@ -29,8 +28,6 @@ import me.PauMAVA.TTR.ui.TTRScoreboard; import me.PauMAVA.TTR.util.EventListener; import me.PauMAVA.TTR.world.TTRWorldHandler; -import org.bukkit.ChatColor; -import org.bukkit.World; import org.bukkit.plugin.java.JavaPlugin; public class TTRCore extends JavaPlugin { @@ -56,7 +53,7 @@ public void onEnable() { getLogger().warning("TTR is disabled on server start. Use /ttrenable to enable it on start. Make sure to be using the desired map."); } this.configManager = new TTRConfigManager(this.getConfig()); - if(enabled) { + if (enabled) { this.customTab = new TTRCustomTab(); this.scoreboard = new TTRScoreboard(); this.match = new TTRMatch(MatchStatus.PREGAME); @@ -82,7 +79,8 @@ public void onDisable() { try { this.customTab.cancel(); this.scoreboard.removeScoreboard(); - } catch (NullPointerException ignored) {} + } catch (NullPointerException ignored) { + } } public static TTRCore getInstance() { diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/chat/TTRChatManager.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/chat/TTRChatManager.java index 381d6e9..f7c93f7 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/chat/TTRChatManager.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/chat/TTRChatManager.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ public class TTRChatManager { public static void sendMessage(Player sender, String originalMessage) { - if(originalMessage.startsWith("!")) { + if (originalMessage.startsWith("!")) { dispatchGlobalMessage(originalMessage); } else { dispatchTeamMessage(originalMessage, sender); @@ -37,18 +37,18 @@ public static void sendMessage(Player sender, String originalMessage) { } private static void dispatchGlobalMessage(String string) { - for(Player p: Bukkit.getServer().getOnlinePlayers()) { + for (Player p : Bukkit.getServer().getOnlinePlayers()) { p.sendMessage(TTRPrefix.TTR_GLOBAL + "" + ChatColor.GRAY + string); } } private static void dispatchTeamMessage(String string, Player sender) { TTRTeam playerTeam = TTRCore.getInstance().getTeamHandler().getPlayerTeam(sender); - if(playerTeam == null) { + if (playerTeam == null) { return; } - for(Player p: playerTeam.getPlayers()) { - p.sendMessage(TTRPrefix.TTR_TEAM + "" + ChatColor.GRAY + string); + for (Player p : playerTeam.getPlayers()) { + p.sendMessage(TTRPrefix.TTR_TEAM + "" + ChatColor.GRAY + string); } } diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/commands/EnableDisableCommand.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/commands/EnableDisableCommand.java index 1cfd174..49c655f 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/commands/EnableDisableCommand.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/commands/EnableDisableCommand.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/commands/StartMatchCommand.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/commands/StartMatchCommand.java index 455d216..76cc520 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/commands/StartMatchCommand.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/commands/StartMatchCommand.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,17 +26,13 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - public class StartMatchCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender theSender, Command command, String label, String[] args) { - if(TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { + if (TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { int timer; if (args == null || args.length == 0) { - timer = 10; + timer = 10; } else { try { timer = Integer.parseInt(args[0]); diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/config/TTRConfigManager.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/config/TTRConfigManager.java index e24f572..c7f1bef 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/config/TTRConfigManager.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/config/TTRConfigManager.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,10 +20,11 @@ import me.PauMAVA.TTR.TTRCore; import me.PauMAVA.TTR.teams.TTRTeam; -import org.bukkit.*; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.Hash; import java.io.File; import java.util.*; @@ -40,7 +41,7 @@ public class TTRConfigManager { public TTRConfigManager(FileConfiguration configuration) { this.configuration = configuration; this.world = TTRCore.getInstance().getServer().getWorlds().get(0); - if(!new File(TTRCore.getInstance().getDataFolder() + "/config.yml").exists()) { + if (!new File(TTRCore.getInstance().getDataFolder() + "/config.yml").exists()) { setUpFile(); saveConfig(); } else { @@ -88,8 +89,8 @@ public Set getTeamNames() { } private ConfigurationSection getTeam(String teamName) { - for(String key: this.teamsSection.getKeys(false)) { - if(key.equalsIgnoreCase(teamName)) { + for (String key : this.teamsSection.getKeys(false)) { + if (key.equalsIgnoreCase(teamName)) { return this.teamsSection.getConfigurationSection(key); } } @@ -110,8 +111,8 @@ public Location getTeamCage(String teamName) { public HashMap getTeamCages() { HashMap cages = new HashMap(); - for(String teamName: getTeamNames()) { - cages.put(getTeamCage(teamName), TTRCore.getInstance().getTeamHandler().getTeam(teamName )); + for (String teamName : getTeamNames()) { + cages.put(getTeamCage(teamName), TTRCore.getInstance().getTeamHandler().getTeam(teamName)); } return cages; } diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/match/AutoStarter.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/match/AutoStarter.java index eb7ba4f..8bf37df 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/match/AutoStarter.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/match/AutoStarter.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -72,7 +72,7 @@ private void removePlayerFromList(Player player) { } private boolean isPlayerInQueue(Player player) { - for (Player p: queue) { + for (Player p : queue) { if (player.getUniqueId().equals(p.getUniqueId())) { return true; } diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/match/Cage.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/match/Cage.java index 293c211..2939554 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/match/Cage.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/match/Cage.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,8 +22,6 @@ import org.bukkit.Location; import org.bukkit.entity.Player; -import java.util.List; - public class Cage { private Location location; diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/match/CageChecker.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/match/CageChecker.java index f2c2fc9..29d2552 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/match/CageChecker.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/match/CageChecker.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,6 @@ import me.PauMAVA.TTR.TTRCore; import me.PauMAVA.TTR.teams.TTRTeam; -import me.PauMAVA.TTR.ui.TTRScoreboard; import me.PauMAVA.TTR.util.TTRPrefix; import org.bukkit.*; import org.bukkit.entity.Player; @@ -37,16 +36,16 @@ public class CageChecker { public void startChecking() { - this.checkerTaskPID = new BukkitRunnable(){ + this.checkerTaskPID = new BukkitRunnable() { @Override public void run() { - for(Player p: Bukkit.getServer().getOnlinePlayers()) { - for(Cage cage: cages) { + for (Player p : Bukkit.getServer().getOnlinePlayers()) { + for (Cage cage : cages) { Location particleLocation = new Location(cage.getLocation().getWorld(), cage.getLocation().getBlockX(), cage.getLocation().getBlockY() + 1, cage.getLocation().getBlockZ()); particleLocation.add(particleLocation.getX() > 0 ? 0.5 : -0.5, 0.0, particleLocation.getZ() > 0 ? 0.5 : -0.5); cage.getLocation().getWorld().spawnParticle(Particle.SPELL, particleLocation, 100); - if(cage.isInCage(p) && TTRCore.getInstance().getTeamHandler().getPlayerTeam(p) != null) { - if(cage.getOwner().equals(TTRCore.getInstance().getTeamHandler().getPlayerTeam(p))) { + if (cage.isInCage(p) && TTRCore.getInstance().getTeamHandler().getPlayerTeam(p) != null) { + if (cage.getOwner().equals(TTRCore.getInstance().getTeamHandler().getPlayerTeam(p))) { p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 10, 1); p.sendMessage(TTRPrefix.TTR_GAME + "" + ChatColor.RED + "You can't do that!"); p.teleport(TTRCore.getInstance().getConfigManager().getTeamSpawn(TTRCore.getInstance().getTeamHandler().getPlayerTeam(p).getIdentifier())); @@ -71,16 +70,16 @@ private void playerOnCage(Player player) { playersTeam.addPoints(1); TTRCore.getInstance().getScoreboard().refreshScoreboard(); Bukkit.broadcastMessage(TTRPrefix.TTR_GAME + "" + ChatColor.GRAY + player.getName() + " has scored a point!"); - for(Player p: Bukkit.getServer().getOnlinePlayers()) { + for (Player p : Bukkit.getServer().getOnlinePlayers()) { p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 10, 1); } - if(playersTeam.getPoints() >= TTRCore.getInstance().getConfigManager().getMaxPoints()) { + if (playersTeam.getPoints() >= TTRCore.getInstance().getConfigManager().getMaxPoints()) { TTRCore.getInstance().getCurrentMatch().endMatch(playersTeam); } } public void setCages(HashMap cages, int effectiveRadius) { - for(Location cage: cages.keySet()) { + for (Location cage : cages.keySet()) { this.cages.add(new Cage(cage, effectiveRadius, cages.get(cage))); } } diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/match/LootSpawner.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/match/LootSpawner.java index 2768b1f..943d5b7 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/match/LootSpawner.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/match/LootSpawner.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,10 +21,10 @@ import me.PauMAVA.TTR.TTRCore; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.Material; import java.util.List; @@ -53,10 +53,10 @@ public void stopSpawning() { } private void setIronTask() { - this.ironTaskPID = new BukkitRunnable(){ + this.ironTaskPID = new BukkitRunnable() { @Override public void run() { - for(Location location: ironLocations) { + for (Location location : ironLocations) { Location copy = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()); copy.add(location.getX() > 0 ? 0.5 : 0.5, 0.0, location.getZ() > 0 ? 0.5 : -0.5); location.getWorld().dropItem(copy, new ItemStack(Material.IRON_INGOT, 1)); @@ -66,10 +66,10 @@ public void run() { } private void setXpTask() { - this.xpTaskPID = new BukkitRunnable(){ + this.xpTaskPID = new BukkitRunnable() { @Override public void run() { - for(Location location: xpLocations) { + for (Location location : xpLocations) { Location copy = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()); copy.add(location.getX() > 0 ? 0.5 : 0.5, 0.0, location.getZ() > 0 ? 0.5 : -0.5); location.getWorld().spawnEntity(copy, EntityType.THROWN_EXP_BOTTLE); diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/match/MatchStatus.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/match/MatchStatus.java index 69b9db2..00d5e0b 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/match/MatchStatus.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/match/MatchStatus.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/match/TTRMatch.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/match/TTRMatch.java index 06074ae..a05f563 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/match/TTRMatch.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/match/TTRMatch.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,18 +20,10 @@ import me.PauMAVA.TTR.TTRCore; import me.PauMAVA.TTR.teams.TTRTeam; -import net.minecraft.server.v1_16_R1.PacketPlayInClientCommand; -import net.minecraft.server.v1_16_R1.PacketPlayInClientCommand.EnumClientCommand; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Difficulty; -import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.Color; -import org.bukkit.Sound; +import me.PauMAVA.TTR.util.ReflectionUtils; +import org.bukkit.*; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -39,7 +31,9 @@ import org.bukkit.scheduler.BukkitRunnable; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.util.HashMap; +import java.util.List; public class TTRMatch { @@ -67,9 +61,9 @@ public void startMatch() { TTRCore.getInstance().getWorldHandler().configureWeather(); TTRCore.getInstance().getWorldHandler().setWorldDifficulty(Difficulty.PEACEFUL); TTRCore.getInstance().getScoreboard().startScoreboardTask(); - for(Player player: Bukkit.getServer().getOnlinePlayers()) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { TTRTeam playerTeam = TTRCore.getInstance().getTeamHandler().getPlayerTeam(player); - if(playerTeam == null) { + if (playerTeam == null) { continue; } player.teleport(TTRCore.getInstance().getConfigManager().getTeamSpawn(playerTeam.getIdentifier())); @@ -92,7 +86,7 @@ public void endMatch(TTRTeam team) { this.status = MatchStatus.ENDED; this.lootSpawner.stopSpawning(); TTRCore.getInstance().getScoreboard().stopScoreboardTask(); - for(Player player: Bukkit.getServer().getOnlinePlayers()) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { player.setGameMode(GameMode.SPECTATOR); ChatColor teamColor = TTRCore.getInstance().getConfigManager().getTeamColor(team.getIdentifier()); player.sendTitle(teamColor + "" + ChatColor.BOLD + team.getIdentifier(), ChatColor.AQUA + "WINS!", 10, 100, 20); @@ -104,26 +98,41 @@ public void endMatch(TTRTeam team) { } public void playerDeath(Player player, Player killer) { - new BukkitRunnable(){ + new BukkitRunnable() { @Override public void run() { - PacketPlayInClientCommand packet = new PacketPlayInClientCommand(); - Field a; try { + Object packet = ReflectionUtils.createNMSInstance("PacketPlayInClientCommand", List.of(), List.of()); + Class enumClientCommand = ReflectionUtils.getNMSClass("PacketPlayInClientCommand$EnumClientCommand"); + // TODO Test if enumClientCommand.getEnumConstants())[0] works. + Object performRespawnConstant = null; + for (Object constant: enumClientCommand.getEnumConstants()) { + if (constant.toString().equalsIgnoreCase("PERFORM_RESPAWN")) { + performRespawnConstant = constant; + break; + } + } + if (performRespawnConstant == null) { + throw new IllegalStateException("Class PacketPlayInClientCommand.EnumClientCommand does not contain a PERFORM_RESPAWN constant..."); + } + Field a; a = packet.getClass().getDeclaredField("a"); a.setAccessible(true); - a.set(packet, EnumClientCommand.PERFORM_RESPAWN); - ((CraftPlayer) player).getHandle().playerConnection.a(packet); + a.set(packet, performRespawnConstant); + Object playerConnection = ReflectionUtils.getPlayerConnection(player); + Class packetClass = ReflectionUtils.getNMSClass("PacketPlayInClientCommand"); + Method aMethod = playerConnection.getClass().getMethod("a", packetClass); + aMethod.invoke(playerConnection, packetClass.cast(packet)); } catch (Exception e) { e.printStackTrace(); } TTRTeam team = TTRCore.getInstance().getTeamHandler().getPlayerTeam(player); - if(team != null) { + if (team != null) { player.teleport(TTRCore.getInstance().getConfigManager().getTeamSpawn(team.getIdentifier())); } setPlayerArmor(player); - player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 10 ,1); - player.playSound(player.getLocation(), Sound.BLOCK_GLASS_BREAK, 10 ,1); + player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 10, 1); + player.playSound(player.getLocation(), Sound.BLOCK_GLASS_BREAK, 10, 1); this.cancel(); kills.put(killer, getKills(killer) + 1); } @@ -133,15 +142,15 @@ public void run() { private void setPlayerArmor(Player player) { TTRTeam team = TTRCore.getInstance().getTeamHandler().getPlayerTeam(player); ChatColor color; - if(team != null) { + if (team != null) { color = TTRCore.getInstance().getConfigManager().getTeamColor(team.getIdentifier()); } else { return; } ItemStack[] armor = new ItemStack[]{new ItemStack(Material.LEATHER_BOOTS, 1), new ItemStack(Material.LEATHER_LEGGINGS, 1), new ItemStack(Material.LEATHER_CHESTPLATE, 1), new ItemStack(Material.LEATHER_HELMET, 1)}; - for(ItemStack itemStack: armor) { + for (ItemStack itemStack : armor) { LeatherArmorMeta meta = (LeatherArmorMeta) itemStack.getItemMeta(); - Color armorColor = Color.fromRGB(0,0,0); + Color armorColor = Color.fromRGB(0, 0, 0); try { meta.setColor((Color) armorColor.getClass().getDeclaredField(color.name()).get(armorColor)); } catch (NoSuchFieldException | IllegalAccessException e) { diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/teams/TTRTeam.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/teams/TTRTeam.java index 4daea6c..7242292 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/teams/TTRTeam.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/teams/TTRTeam.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/teams/TTRTeamHandler.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/teams/TTRTeamHandler.java index 5aa3484..ef54c58 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/teams/TTRTeamHandler.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/teams/TTRTeamHandler.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,6 @@ import me.PauMAVA.TTR.TTRCore; import me.PauMAVA.TTR.match.TTRMatch; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -33,14 +32,14 @@ public class TTRTeamHandler { private List teams = new ArrayList(); public void setUpDefaultTeams() { - for(String team: TTRCore.getInstance().getConfigManager().getTeamNames()) { + for (String team : TTRCore.getInstance().getConfigManager().getTeamNames()) { this.teams.add(new TTRTeam(team)); } } public boolean addPlayerToTeam(Player player, String teamIdentifier) { TTRTeam team = getTeam(teamIdentifier); - if(team == null) { + if (team == null) { return false; } team.addPlayer(player); @@ -49,7 +48,7 @@ public boolean addPlayerToTeam(Player player, String teamIdentifier) { public boolean removePlayerFromTeam(Player player, String teamIdentifier) { TTRTeam team = getTeam(teamIdentifier); - if(team == null) { + if (team == null) { return false; } team.removePlayer(player); @@ -57,8 +56,8 @@ public boolean removePlayerFromTeam(Player player, String teamIdentifier) { } public TTRTeam getPlayerTeam(Player player) { - for(TTRTeam team: this.teams) { - if(team.getPlayers().contains(player)) { + for (TTRTeam team : this.teams) { + if (team.getPlayers().contains(player)) { return team; } } @@ -66,9 +65,9 @@ public TTRTeam getPlayerTeam(Player player) { } public TTRTeam getTeam(String teamIdentifier) { - for(TTRTeam team: this.teams) { + for (TTRTeam team : this.teams) { teamIdentifier = ChatColor.stripColor(teamIdentifier); - if(teamIdentifier.contentEquals(team.getIdentifier())) { + if (teamIdentifier.contentEquals(team.getIdentifier())) { return team; } } diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/CustomUI.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/CustomUI.java index 571317b..25026fc 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/CustomUI.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/CustomUI.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,19 +45,19 @@ void openUI(Player player) { } void closeUI(Player player) { - if(player.getOpenInventory().equals(this.inventory)) { + if (player.getOpenInventory().equals(this.inventory)) { player.closeInventory(); } } public void setSlot(int id, ItemStack item, @Nullable String title, @Nullable String lore) { - if(title == null) { + if (title == null) { this.inventory.setItem(id, item); return; } ItemMeta meta = item.getItemMeta(); meta.setDisplayName(title); - if(lore != null) { + if (lore != null) { meta.setLore(new ArrayList(Arrays.asList(lore))); } item.setItemMeta(meta); diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/TTRCustomTab.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/TTRCustomTab.java index abc5f4e..5ee0810 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/TTRCustomTab.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/TTRCustomTab.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,21 +19,21 @@ package me.PauMAVA.TTR.ui; import io.netty.handler.codec.DecoderException; +import me.PauMAVA.TTR.util.ReflectionUtils; import me.PauMAVA.TTR.util.TTRPrefix; -import net.minecraft.server.v1_16_R1.ChatComponentText; -import net.minecraft.server.v1_16_R1.PacketPlayOutPlayerListHeaderFooter; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.util.List; public class TTRCustomTab extends BukkitRunnable { private String prefix = ""; - private String suffix = ChatColor.AQUA + "(c) 2019-2020" + ChatColor.BOLD + " PauMAVA" + ChatColor.RESET + "\n" + ChatColor.GREEN + "The Towers Remastered (TTR)"; + private String suffix = ChatColor.AQUA + "(c) 2019-2021" + ChatColor.BOLD + " PauMAVA" + ChatColor.RESET + "\n" + ChatColor.GREEN + "The Towers Remastered (TTR)"; private int i = 1; @Override @@ -59,18 +59,20 @@ public void run() { } private void sendPacket() { - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); try { + Object packet = ReflectionUtils.createNMSInstance("PacketPlayOutPlayerListHeaderFooter", List.of(), List.of()); Field header = packet.getClass().getDeclaredField("header"); Field footer = packet.getClass().getDeclaredField("footer"); header.setAccessible(true); footer.setAccessible(true); - header.set(packet, new ChatComponentText(this.prefix)); - footer.set(packet, new ChatComponentText(this.suffix)); - for(Player player: Bukkit.getServer().getOnlinePlayers()) { - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + Object headerChatComponentText = ReflectionUtils.createNMSInstance("ChatComponentText", List.of(String.class), List.of(this.prefix)); + Object footerChatComponentText = ReflectionUtils.createNMSInstance("ChatComponentText", List.of(String.class), List.of(this.suffix)); + header.set(packet, headerChatComponentText); + footer.set(packet, footerChatComponentText); + for (Player player : Bukkit.getServer().getOnlinePlayers()) { + ReflectionUtils.sendNMSPacketToPlayer(player, packet); } - } catch (IllegalAccessException | NoSuchFieldException | DecoderException e) { + } catch (IllegalAccessException | NoSuchFieldException | DecoderException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException e) { e.printStackTrace(); } } diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/TTRScoreboard.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/TTRScoreboard.java index 011e464..9b6cbeb 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/TTRScoreboard.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/TTRScoreboard.java @@ -30,26 +30,27 @@ public TTRScoreboard() { public void refreshScoreboard() { updatePoints(); - for(Player player: Bukkit.getServer().getOnlinePlayers()) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { player.setScoreboard(this.ttrScoreboard); this.kills.getScore(player.getName()).setScore(TTRCore.getInstance().getCurrentMatch().getKills(player)); } } public void removeScoreboard() { - for(Player player: Bukkit.getServer().getOnlinePlayers()) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { player.setScoreboard(this.scoreboardManager.getMainScoreboard()); } } public void startScoreboardTask() { - this.taskPID = new BukkitRunnable(){ + this.taskPID = new BukkitRunnable() { private int i = 0; + @Override public void run() { updatePoints(); points.getScore(ChatColor.DARK_GRAY + "§m ").setScore(-1); - if(totalTime != null) { + if (totalTime != null) { ttrScoreboard.resetScores(totalTime.getEntry()); } totalTime = points.getScore(ChatColor.GREEN + "" + ChatColor.BOLD + "Total time: " + ChatColor.GRAY + prettyTime(i)); @@ -60,12 +61,12 @@ public void run() { private String prettyTime(int i) { String elapsedMinutes, elapsedSeconds; - if((((i % 86400) % 3600) / 60) < 10) { + if ((((i % 86400) % 3600) / 60) < 10) { elapsedMinutes = "0" + ((i % 86400) % 3600) / 60; } else { elapsedMinutes = "" + ((i % 86400) % 3600) / 60; } - if((((i % 86400) % 3600) % 60) < 10) { + if ((((i % 86400) % 3600) % 60) < 10) { elapsedSeconds = "0" + ((i % 86400) % 3600) % 60; } else { elapsedSeconds = "" + ((i % 86400) % 3600) % 60; @@ -77,7 +78,7 @@ private String prettyTime(int i) { } private void updatePoints() { - for(TTRTeam team: TTRCore.getInstance().getTeamHandler().getTeams()) { + for (TTRTeam team : TTRCore.getInstance().getTeamHandler().getTeams()) { ChatColor teamColor = TTRCore.getInstance().getConfigManager().getTeamColor(team.getIdentifier()); points.getScore(teamColor + "" + ChatColor.BOLD + team.getIdentifier()).setScore(team.getPoints()); } diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/TeamSelector.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/TeamSelector.java index 442a142..a458d11 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/TeamSelector.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/ui/TeamSelector.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,6 @@ import me.PauMAVA.TTR.TTRCore; import me.PauMAVA.TTR.teams.TTRTeam; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -44,12 +43,12 @@ public TeamSelector(Player player) { setUp(); TTRCore.getInstance().getServer().getPluginManager().registerEvents(this, TTRCore.getInstance()); TTRTeam possibleTeam = TTRCore.getInstance().getTeamHandler().getPlayerTeam(this.owner); - if(possibleTeam != null) { - for(int i = 0; i < super.getInventory().getSize(); i++) { + if (possibleTeam != null) { + for (int i = 0; i < super.getInventory().getSize(); i++) { ItemStack stack = super.getInventory().getItem(i); - if(stack != null) { + if (stack != null) { String cleanName = ChatColor.stripColor(stack.getItemMeta().getDisplayName()); - if(possibleTeam.getIdentifier().equalsIgnoreCase(cleanName)) { + if (possibleTeam.getIdentifier().equalsIgnoreCase(cleanName)) { this.selected = i; addEnchantment(i); break; @@ -69,7 +68,7 @@ public void closeSelector() { public void setUp() { int i = 0; - for(String teamName: TTRCore.getInstance().getConfigManager().getTeamNames()) { + for (String teamName : TTRCore.getInstance().getConfigManager().getTeamNames()) { setSlot(i, new ItemStack(Material.valueOf(TTRCore.getInstance().getConfigManager().getTeamColor(teamName).name() + "_WOOL"), 1), TTRCore.getInstance().getConfigManager().getTeamColor(teamName) + teamName, null); i++; } @@ -77,18 +76,18 @@ public void setUp() { @EventHandler public void onInventoryClick(InventoryClickEvent event) { - if(event.getClickedInventory() == super.getInventory() && event.getClickedInventory().getItem(event.getSlot()) != null) { + if (event.getClickedInventory() == super.getInventory() && event.getClickedInventory().getItem(event.getSlot()) != null) { this.selected = event.getSlot(); setUp(); addEnchantment(this.selected); String teamName = super.getInventory().getItem(this.selected).getItemMeta().getDisplayName(); TTRCore.getInstance().getTeamHandler().addPlayer(teamName, this.owner); - if(lastTeam != null) { + if (lastTeam != null) { TTRCore.getInstance().getTeamHandler().removePlayer(teamName, this.owner); } this.lastTeam = teamName; } - if(TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { + if (TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { event.setCancelled(true); } } diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/util/EventListener.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/util/EventListener.java index 72a4ff2..215fad2 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/util/EventListener.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/util/EventListener.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,9 +43,9 @@ public class EventListener implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - if(TTRCore.getInstance().enabled()) { + if (TTRCore.getInstance().enabled()) { event.setJoinMessage(TTRPrefix.TTR_GAME + "" + ChatColor.GREEN + "+ " + ChatColor.GRAY + event.getPlayer().getName() + " has joined the game"); - if(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.PREGAME) { + if (TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.PREGAME) { Inventory playerInventory = event.getPlayer().getInventory(); playerInventory.clear(); playerInventory.setItem(0, new ItemStack(Material.BLACK_BANNER)); @@ -60,7 +60,7 @@ public void onPlayerJoin(PlayerJoinEvent event) { @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { - if(TTRCore.getInstance().enabled()) { + if (TTRCore.getInstance().enabled()) { event.setQuitMessage(TTRPrefix.TTR_GAME + "" + ChatColor.RED + "- " + ChatColor.GRAY + event.getPlayer().getName() + " has left the game"); TTRCore.getInstance().getAutoStarter().removePlayerFromQueue(event.getPlayer()); } @@ -68,19 +68,19 @@ public void onPlayerLeave(PlayerQuitEvent event) { @EventHandler public void onPlayerDropEvent(PlayerDropItemEvent event) { - if(TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { + if (TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { event.setCancelled(true); } } @EventHandler public void playerClickEvent(PlayerInteractEvent event) { - if(TTRCore.getInstance().enabled() && !(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.INGAME)) { - if(event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (TTRCore.getInstance().enabled() && !(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.INGAME)) { + if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) { return; } event.setCancelled(true); - if(event.getItem() != null && event.getItem().getType() == Material.BLACK_BANNER) { + if (event.getItem() != null && event.getItem().getType() == Material.BLACK_BANNER) { new TeamSelector(event.getPlayer()).openSelector(); } } @@ -88,7 +88,7 @@ public void playerClickEvent(PlayerInteractEvent event) { @EventHandler public void placeBlockEvent(BlockPlaceEvent event) { - if(TTRCore.getInstance().enabled() && !(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.INGAME)) { + if (TTRCore.getInstance().enabled() && !(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.INGAME)) { event.getPlayer().sendMessage(TTRPrefix.TTR_GAME + "" + ChatColor.RED + "You cannot place a block there!"); event.setCancelled(true); } @@ -96,7 +96,7 @@ public void placeBlockEvent(BlockPlaceEvent event) { @EventHandler public void breakBlockEvent(BlockBreakEvent event) { - if(TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { + if (TTRCore.getInstance().enabled() && !TTRCore.getInstance().getCurrentMatch().isOnCourse()) { event.getPlayer().sendMessage(TTRPrefix.TTR_GAME + "" + ChatColor.RED + "You cannot break that block!"); event.setCancelled(true); } @@ -104,14 +104,14 @@ public void breakBlockEvent(BlockBreakEvent event) { @EventHandler public void onPlayerDeath(PlayerDeathEvent event) { - if(TTRCore.getInstance().enabled() && TTRCore.getInstance().getCurrentMatch().isOnCourse()) { + if (TTRCore.getInstance().enabled() && TTRCore.getInstance().getCurrentMatch().isOnCourse()) { TTRCore.getInstance().getCurrentMatch().playerDeath(event.getEntity(), event.getEntity().getKiller()); } } @EventHandler public void onPlayerDamage(EntityDamageEvent event) { - if(event.getEntity() instanceof Player && !(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.INGAME)) { + if (event.getEntity() instanceof Player && !(TTRCore.getInstance().getCurrentMatch().getStatus() == MatchStatus.INGAME)) { event.setCancelled(true); } } diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/util/PacketIntercepter.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/util/PacketIntercepter.java index 0f0246d..55fc974 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/util/PacketIntercepter.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/util/PacketIntercepter.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,13 +31,13 @@ public class PacketIntercepter { public void addPlayer(Player player) { - ChannelDuplexHandler channelDuplexHandler = new ChannelDuplexHandler(){ + ChannelDuplexHandler channelDuplexHandler = new ChannelDuplexHandler() { @Override public void channelRead(ChannelHandlerContext context, Object packet) { - if(TTRCore.getInstance().enabled() && TTRCore.getInstance().getCurrentMatch().isOnCourse() && packet instanceof PacketPlayInChat && !((PacketPlayInChat) packet).b().startsWith("/")) { + if (TTRCore.getInstance().enabled() && TTRCore.getInstance().getCurrentMatch().isOnCourse() && packet instanceof PacketPlayInChat && !((PacketPlayInChat) packet).b().startsWith("/")) { TTRChatManager.sendMessage(player, ((PacketPlayInChat) packet).b()); } - try{ + try { super.channelRead(context, packet); } catch (Exception e) { TTRCore.getInstance().getLogger().warning("An error occurred on packet reading process!"); @@ -53,7 +53,8 @@ public void write(ChannelHandlerContext context, Object packet, ChannelPromise p ChannelPipeline pipeline = ((CraftPlayer) player).getHandle().playerConnection.networkManager.channel.pipeline(); try { pipeline.addBefore("packet_handler", player.getName(), channelDuplexHandler); - } catch (IllegalArgumentException ignored) {} + } catch (IllegalArgumentException ignored) { + } } diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/util/ReflectionUtils.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/util/ReflectionUtils.java new file mode 100644 index 0000000..10674af --- /dev/null +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/util/ReflectionUtils.java @@ -0,0 +1,83 @@ +/* + * TheTowersRemastered (TTR) + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package me.PauMAVA.TTR.util; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; + +public class ReflectionUtils { + + private static String version = null; + + static { + try { + Class.forName("org.bukkit.Bukkit"); + String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; + setField(ReflectionUtils.class, null, "version", version); + } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException e) { + e.printStackTrace(); + } + } + + public static Object getPlayerConnection(Player player) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException { + Class CraftPlayer = getCraftbukkitClass("entity.CraftPlayer"); + Object asCraftPlayer = CraftPlayer.cast(player); + Method getHandle = CraftPlayer.getMethod("getHandle"); + Object playerHandle = getHandle.invoke(asCraftPlayer); + Field playerConnectionField = playerHandle.getClass().getDeclaredField("playerConnection"); + return playerConnectionField.get(playerHandle); + } + + public static void sendNMSPacketToPlayer(Player player, Object packet) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException { + Object playerConnection = getPlayerConnection(player); + Class nmsPacket = getNMSClass("Packet"); + Method sendPacket = playerConnection.getClass().getDeclaredMethod("sendPacket", nmsPacket); + sendPacket.invoke(playerConnection, packet); + } + + public static Class getNMSClass(String clazz) throws ClassNotFoundException { + return Class.forName("net.minecraft.server." + version + "." + clazz); + } + + public static Class getCraftbukkitClass(String clazz) throws ClassNotFoundException { + return Class.forName("org.bukkit.craftbukkit." + version + "." + clazz); + } + + public static Object createNMSInstance(String clazz, List> paramTypes, List params) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { + Class theClazz = getNMSClass(clazz); + Constructor constructor = theClazz.getDeclaredConstructor(paramTypes.toArray(new Class[0])); + constructor.setAccessible(true); + return constructor.newInstance(params.toArray()); + } + + public static void setField(Class clazz, Object instance, String fieldName, Object value) throws IllegalAccessException, NoSuchFieldException { + Field field = clazz.getDeclaredField(fieldName); + boolean accessible = field.canAccess(instance); + field.setAccessible(true); + field.set(instance, value); + field.setAccessible(accessible); + } + +} diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/util/TTRPrefix.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/util/TTRPrefix.java index 97f4cf4..d03f29e 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/util/TTRPrefix.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/util/TTRPrefix.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/util/XPBarTimer.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/util/XPBarTimer.java index b30b14a..1af9c92 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/util/XPBarTimer.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/util/XPBarTimer.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,16 +43,16 @@ public XPBarTimer(int time, Method execute) { @Override public void run() { - for(Player player: Bukkit.getServer().getOnlinePlayers()) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { player.setLevel(i); } - if(i <= 5) { - for(Player player: Bukkit.getServer().getOnlinePlayers()) { + if (i <= 5) { + for (Player player : Bukkit.getServer().getOnlinePlayers()) { player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 10, 1); } } - if(i <= 0) { - if(this.execute != null) { + if (i <= 0) { + if (this.execute != null) { try { this.execute.invoke(TTRCore.getInstance().getCurrentMatch()); } catch (IllegalAccessException | InvocationTargetException e) { diff --git a/v1_16_1/src/main/java/me/PauMAVA/TTR/world/TTRWorldHandler.java b/v1_16_1/src/main/java/me/PauMAVA/TTR/world/TTRWorldHandler.java index b4f5481..cafb65c 100644 --- a/v1_16_1/src/main/java/me/PauMAVA/TTR/world/TTRWorldHandler.java +++ b/v1_16_1/src/main/java/me/PauMAVA/TTR/world/TTRWorldHandler.java @@ -1,6 +1,6 @@ /* * TheTowersRemastered (TTR) - * Copyright (c) 2019-2020 Pau Machetti Vallverdu + * Copyright (c) 2019-2021 Pau Machetti VallverdĂș * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/v1_16_1/src/plugin.yml b/v1_16_1/src/plugin.yml index 46c993a..f263e3c 100644 --- a/v1_16_1/src/plugin.yml +++ b/v1_16_1/src/plugin.yml @@ -1,12 +1,12 @@ -name: TheTowersRemastered -version: 1.1 -api-version: 1.15 -main: me.PauMAVA.TTR.TTRCore - -commands: - ttrstart: - description: Start the match - ttrenable: - description: Enbles the plugin on server start. - ttrdisable: +name: TheTowersRemastered +version: 1.2.1 +api-version: 1.16 +main: me.PauMAVA.TTR.TTRCore + +commands: + ttrstart: + description: Start the match + ttrenable: + description: Enbles the plugin on server start. + ttrdisable: description: Disables the plugin on server start. \ No newline at end of file