From 721e5967d82fb5e8c957d245e27987b504b87009 Mon Sep 17 00:00:00 2001 From: Techcable Date: Tue, 10 Mar 2015 00:35:05 -0700 Subject: [PATCH] Huge Internal Rewrite Update to 1.8.3 Should Help with #35 #31 Fix #29 Should fix anti-safezoning --- pom.xml | 106 +++-- .../java/com/trc202/CombatTag/CombatTag.java | 410 ------------------ .../com/trc202/CombatTagApi/CombatTagApi.java | 46 +- .../com/trc202/Containers/HallOfShame.java | 53 --- .../net/techcable/combattag/CombatPlayer.java | 79 ++++ .../net/techcable/combattag/CombatTag.java | 128 ++++++ .../techcable}/combattag/CombatTagAPI.java | 37 +- .../net/techcable/combattag/NPCManager.java | 87 ++++ .../combattag/PluginCompatibility.java | 45 ++ .../techcable}/combattag/Utils.java | 11 +- .../combattag/event/CombatLogEvent.java | 8 +- .../combattag/event/CombatTagEvent.java | 43 ++ .../combattag/event/CombatUntagEvent.java | 23 + .../combattag/event/package-info.java | 2 +- .../listeners/CompatibilityListener.java | 24 + .../listeners/InstakillListener.java | 21 + .../combattag/listeners/NPCListener.java | 46 ++ .../listeners/PermissionListener.java | 24 + .../combattag/listeners/PlayerListener.java | 93 ++++ .../combattag/listeners/SettingListener.java | 81 ++-- .../combattag/PluginCompatibility.java | 70 --- .../combattag/entity/CombatTagNPC.java | 119 ----- .../combattag/entity/CombatTagPlayer.java | 87 ---- .../combattag/entity/package-info.java | 5 - .../event/CombatTagByPlayerEvent.java | 25 -- .../combattag/event/CombatTagEvent.java | 28 -- .../listeners/CompatibilityListener.java | 29 -- .../listeners/InstakillListener.java | 21 - .../combattag/listeners/NPCListener.java | 39 -- .../listeners/PermissionListener.java | 31 -- .../combattag/listeners/PlayerListener.java | 86 ---- src/main/resources/plugin.yml | 4 +- 32 files changed, 745 insertions(+), 1166 deletions(-) delete mode 100644 src/main/java/com/trc202/CombatTag/CombatTag.java delete mode 100644 src/main/java/com/trc202/Containers/HallOfShame.java create mode 100644 src/main/java/net/techcable/combattag/CombatPlayer.java create mode 100644 src/main/java/net/techcable/combattag/CombatTag.java rename src/main/java/{techcable/minecraft => net/techcable}/combattag/CombatTagAPI.java (74%) create mode 100644 src/main/java/net/techcable/combattag/NPCManager.java create mode 100644 src/main/java/net/techcable/combattag/PluginCompatibility.java rename src/main/java/{techcable/minecraft => net/techcable}/combattag/Utils.java (91%) rename src/main/java/{techcable/minecraft => net/techcable}/combattag/event/CombatLogEvent.java (71%) create mode 100644 src/main/java/net/techcable/combattag/event/CombatTagEvent.java create mode 100644 src/main/java/net/techcable/combattag/event/CombatUntagEvent.java rename src/main/java/{techcable/minecraft => net/techcable}/combattag/event/package-info.java (50%) create mode 100644 src/main/java/net/techcable/combattag/listeners/CompatibilityListener.java create mode 100644 src/main/java/net/techcable/combattag/listeners/InstakillListener.java create mode 100644 src/main/java/net/techcable/combattag/listeners/NPCListener.java create mode 100644 src/main/java/net/techcable/combattag/listeners/PermissionListener.java create mode 100644 src/main/java/net/techcable/combattag/listeners/PlayerListener.java rename src/main/java/{techcable/minecraft => net/techcable}/combattag/listeners/SettingListener.java (61%) delete mode 100644 src/main/java/techcable/minecraft/combattag/PluginCompatibility.java delete mode 100644 src/main/java/techcable/minecraft/combattag/entity/CombatTagNPC.java delete mode 100644 src/main/java/techcable/minecraft/combattag/entity/CombatTagPlayer.java delete mode 100644 src/main/java/techcable/minecraft/combattag/entity/package-info.java delete mode 100644 src/main/java/techcable/minecraft/combattag/event/CombatTagByPlayerEvent.java delete mode 100644 src/main/java/techcable/minecraft/combattag/event/CombatTagEvent.java delete mode 100644 src/main/java/techcable/minecraft/combattag/listeners/CompatibilityListener.java delete mode 100644 src/main/java/techcable/minecraft/combattag/listeners/InstakillListener.java delete mode 100644 src/main/java/techcable/minecraft/combattag/listeners/NPCListener.java delete mode 100644 src/main/java/techcable/minecraft/combattag/listeners/PermissionListener.java delete mode 100644 src/main/java/techcable/minecraft/combattag/listeners/PlayerListener.java diff --git a/pom.xml b/pom.xml index 9c53ef5..c846e80 100644 --- a/pom.xml +++ b/pom.xml @@ -1,88 +1,80 @@ - + 4.0.0 - net.techcable - parent - 1.0.0-SNAPSHOT + net.techcable + parent + 1.0.0 - techcable.minecraft - CombatTag - 1.0.12-SNAPSHOT + combattag + 1.0.13-SNAPSHOT Combat Tag Reloaded UTF-8 - metrics-repo - http://repo.mcstats.org/content/repositories/public + metrics-repo + http://repo.mcstats.org/content/repositories/public - sk89q-repo - http://maven.sk89q.com/repo/ + sk89q-repo + http://maven.sk89q.com/repo/ - - techcable-repo - http://repo.techcable.net/content/groups/public/ + + techcable-repo + http://repo.techcable.net/content/groups/public/ - md5-repo - http://repo.md-5.net/content/groups/public/ + md5-repo + http://repo.md-5.net/content/groups/public/ - - net.gravitydevelopment.updater - updater - 2.3 - - - com.sk89q - worldedit - 5.6.3 - provided - true - + + net.gravitydevelopment.updater + updater + 2.3 + org.bukkit bukkit - 1.8-R0.1-SNAPSHOT + 1.7.9-R0.2 provided - org.mcstats.bukkit - metrics - R7 + org.mcstats.bukkit + metrics + R7 - techcable.minecraft - npclib-base - 1.0.2-SNAPSHOT + net.techcable + npclib + 1.1.1-SNAPSHOT compile - net.techcable.minecraft.techutils - core - 1.0.0-SNAPSHOT + net.techcable + techutils + 1.1.0-SNAPSHOT - com.sk89q - worldguard - 6.0.0-SNAPSHOT - provided - true + LibsDisguises + LibsDisguises + 8.2.6-SNAPSHOT + provided + true - LibsDisguises - LibsDisguises - 8.2.6-SNAPSHOT - provided - true + com.sk89q + worldguard + 6.0.0-SNAPSHOT + provided - CombatTag + CombatTag org.apache.maven.plugins @@ -97,24 +89,24 @@ - techcable.minecaft.techutils - techcable.minecraft.combattag.libs.techcable.minecraft.techutils + net.techcable.techutils + net.techcable.combattag.libs.techutils org.mcstats - techcable.minecraft.combattag.libs.org.mcstats + net.techcable.combattag.libs.mcstats - net.gravitydevelopment.updater - techcable.minecraft.libs.net.gravitydevelopment.updater + net.gravitydevelopment.updater + net.techcable.combattag.libs.updater - techcable.minecraft.npclib - techcable.minecraft.combattag.libs.techcable.minecraft.npclib + net.techcable.npclib + net.techcable.combattag.libs.npclib techcable.minecraft.factionsapi - techcable.minecraft.combattag.libs.techcable.minecraft.factionsapi + net.techcable.combattag.libs.factionsapi diff --git a/src/main/java/com/trc202/CombatTag/CombatTag.java b/src/main/java/com/trc202/CombatTag/CombatTag.java deleted file mode 100644 index b3d4f72..0000000 --- a/src/main/java/com/trc202/CombatTag/CombatTag.java +++ /dev/null @@ -1,410 +0,0 @@ -package com.trc202.CombatTag; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.logging.Logger; - -import net.gravitydevelopment.updater.Updater; -import net.gravitydevelopment.updater.Updater.UpdateType; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.util.StringUtil; -import org.mcstats.Metrics; -import org.mcstats.Metrics.Graph; -import org.mcstats.Metrics.Plotter; - -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableList; -import com.trc202.settings.Settings; -import com.trc202.settings.SettingsHelper; -import com.trc202.settings.SettingsLoader; - -import techcable.minecraft.combattag.Utils; - -import static techcable.minecraft.combattag.Utils.info; -import static techcable.minecraft.combattag.Utils.warning; -import static techcable.minecraft.combattag.Utils.severe; - -import techcable.minecraft.combattag.entity.CombatTagNPC; -import techcable.minecraft.combattag.entity.CombatTagPlayer; -import techcable.minecraft.combattag.listeners.CompatibilityListener; -import techcable.minecraft.combattag.listeners.InstakillListener; -import techcable.minecraft.combattag.listeners.NPCListener; -import techcable.minecraft.combattag.listeners.PermissionListener; -import techcable.minecraft.combattag.listeners.PlayerListener; -import techcable.minecraft.combattag.listeners.SettingListener; -import techcable.minecraft.npclib.NPC; -import techcable.minecraft.npclib.NPCLib; -import techcable.minecraft.techutils.TechPlugin; -import techcable.minecraft.techutils.entity.TechPlayerFactory; - -import lombok.Getter; - -public class CombatTag extends TechPlugin { - - @Override - public TechPlayerFactory getPlayerFactory() { - return new TechPlayerFactory() { - public CombatTagPlayer createPlayer(UUID player, TechPlugin plugin) { - return new CombatTagPlayer(player, (CombatTag)plugin); - } - }; - } - - private final SettingsHelper settingsHelper; - private final File settingsFile; - public Settings settings; - private HashMap tagged; - private static final String mainDirectory = "plugins/CombatTag"; - private static final List SUBCOMMANDS = ImmutableList.of("reload", "wipe", "command"); - private static final List COMMAND_SUBCOMMANDS = ImmutableList.of("add", "remove"); - - //public final CombatTagIncompatibles ctIncompatible = new CombatTagIncompatibles(this); - - private int npcNumber; - public CombatTag() { - settings = new Settings(); - new File(mainDirectory).mkdirs(); - settingsFile = new File(mainDirectory + File.separator + "settings.prop"); - settingsHelper = new SettingsHelper(settingsFile, "CombatTag"); - npcNumber = 0; - } - - /** - * Change SL in NPCManager to: - * - * private class SL implements Listener { - * - * @SuppressWarnings("unused") public void disableNPCLib() { despawnAll(); - * Bukkit.getServer().getScheduler().cancelTask(taskid); } } - */ - /** - * Change NullSocket to: - * - * class NullSocket extends Socket { private final byte[] buffer = new - * byte[50]; - * - * @Override public InputStream getInputStream() { return new - * ByteArrayInputStream(this.buffer); } - * - * @Override public OutputStream getOutputStream() { return new - * ByteArrayOutputStream(10); } } - */ - @Override - public void onDisable() { - for (CombatTagNPC npc : CombatTagNPC.getAllNpcs()) { - npc.despawn(); - } - disableMetrics(); - //Just in case... - info("Disabled"); - } - - @Override - public void onEnable() { - settings = new SettingsLoader().loadSettings(settingsHelper, this.getDescription().getVersion()); - if (!settings.isInstaKill()) { - if (!NPCLib.isSupported() ){ - severe("NPCs are enabled but this version of minecraft isn't supported"); - severe("[CombatTag] Please install citizens or update CombatTag if you want to use npcs"); - setEnabled(false); - return; - } - } - tagged = new HashMap(); - PluginManager pm = getServer().getPluginManager(); - //ctIncompatible.startup(pm); - if (!initMetrics()) { - getLogger().warning("Unable to initialize metrics"); - } else { - if (isDebugEnabled()) getLogger().info("Enabled Metrics"); - } - registerListeners(); - - info("has loaded with a tag time of " + settings.getTagDuration() + " seconds"); - } - - public long getRemainingTagTime(UUID uuid) { - if (tagged.get(uuid) == null) { - return -1; - } - return (tagged.get(uuid) - System.currentTimeMillis()); - } - - public boolean addTagged(Player player) { - if (player.isOnline()) { - tagged.remove(player.getUniqueId()); - tagged.put(player.getUniqueId(), PvPTimeout(getTagDuration())); - return true; - } - return false; - } - - public boolean inTagged(UUID name) { - return tagged.containsKey(name); - } - - public long removeTagged(UUID name) { - if (inTagged(name)) { - return tagged.remove(name); - } - return -1; - } - - public long PvPTimeout(int seconds) { - return System.currentTimeMillis() + (seconds * 1000); - } - - public boolean isInCombat(UUID uuid) { - if (getRemainingTagTime(uuid) < 0) { - tagged.remove(uuid); - return false; - } else { - return true; - } - } - - public String getNpcName(String plr) { - String npcName = settings.getNpcName(); - if (!(npcName.contains("player") || npcName.contains("number"))) { - npcName = npcName + getNpcNumber(); - } - if (npcName.contains("player")) { - npcName = npcName.replace("player", plr); - } - if (npcName.contains("number")) { - npcName = npcName.replace("number", "" + getNpcNumber()); - } - return npcName; - } - /** - * - * @return the system tag duration as set by the user - */ - public int getTagDuration() { - return settings.getTagDuration(); - } - - public boolean isDebugEnabled() { - return settings.isDebugEnabled(); - } - - public int getNpcNumber() { - npcNumber = npcNumber + 1; - return npcNumber; - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { - if (command.getName().equalsIgnoreCase("ct") || (command.getName().equalsIgnoreCase("combattag"))) { - if (args.length == 0) { - if (sender instanceof Player) { - if (isInCombat(((Player) sender).getUniqueId())) { - String message = settings.getCommandMessageTagged(); - message = message.replace("[time]", "" + (getRemainingTagTime(((Player) sender).getUniqueId()) / 1000)); - sender.sendMessage(message); - } else { - tagged.remove(((Player) sender).getUniqueId()); - sender.sendMessage(settings.getCommandMessageNotTagged()); - } - } else { - info("[CombatTag] /ct can only be used by a player!"); - } - return true; - } else if (args[0].equalsIgnoreCase("reload")) { - if (sender.hasPermission("combattag.reload")) { - settings = new SettingsLoader().loadSettings(settingsHelper, this.getDescription().getVersion()); - if (sender instanceof Player) { - sender.sendMessage(ChatColor.RED + "[CombatTag] Settings were reloaded!"); - } else { - info("[CombatTag] Settings were reloaded!"); - } - } else { - if (sender instanceof Player) { - sender.sendMessage(ChatColor.RED + "[CombatTag] You don't have the permission 'combattag.reload'!"); - } - } - return true; - } else if (args[0].equalsIgnoreCase("wipe")) { - if (!NPCLib.isSupported()) { - sender.sendMessage(ChatColor.RED + "[CombatTag] npcs aren't supported"); - } else if (sender.hasPermission("combattag.wipe")) { - int numNPC = 0; - for (CombatTagNPC npc : CombatTagNPC.getAllNpcs()) { - npc.despawn(); - } - sender.sendMessage("[CombatTag] Wiped " + numNPC + " pvploggers!"); - } - return true; - } else if (args[0].equalsIgnoreCase("command")) { - if (sender.hasPermission("combattag.command")) { - if (args.length > 2) { - if (args[1].equalsIgnoreCase("add")) { - if (args[2].length() == 0 || !args[2].startsWith("/")) { - sender.sendMessage(ChatColor.RED + "[CombatTag] Correct Usage: /ct command add /"); - } else { - String disabledCommands = settingsHelper.getProperty("disabledCommands"); - if (!disabledCommands.contains(args[2])) { - disabledCommands = disabledCommands.substring(0, disabledCommands.length() - 1) + "," + args[2] + "]"; - disabledCommands = disabledCommands.replace("[,", "["); - disabledCommands = disabledCommands.replaceAll(",,", ","); - settingsHelper.setProperty("disabledCommands", disabledCommands); - settingsHelper.saveConfig(); - sender.sendMessage(ChatColor.RED + "[CombatTag] Added " + args[2] + " to combat blocked commands."); - settings = new SettingsLoader().loadSettings(settingsHelper, this.getDescription().getVersion()); - } else { - sender.sendMessage(ChatColor.RED + "[CombatTag] That command is already in the blocked commands list."); - } - } - } else if (args[1].equalsIgnoreCase("remove")) { - if (args[2].length() == 0 || !args[2].startsWith("/")) { - sender.sendMessage(ChatColor.RED + "[CombatTag] Correct Usage: /ct command remove /"); - } else { - String disabledCommands = settingsHelper.getProperty("disabledCommands"); - if (disabledCommands.contains(args[2] + ",") || disabledCommands.contains(args[2] + "]")) { - disabledCommands = disabledCommands.replace(args[2] + ",", ""); - disabledCommands = disabledCommands.replace(args[2] + "]", "]"); - disabledCommands = disabledCommands.replace(",]", "]"); - disabledCommands = disabledCommands.replaceAll(",,", ","); - settingsHelper.setProperty("disabledCommands", disabledCommands); - settingsHelper.saveConfig(); - sender.sendMessage(ChatColor.RED + "[CombatTag] Removed " + args[2] + " from combat blocked commands."); - settings = new SettingsLoader().loadSettings(settingsHelper, this.getDescription().getVersion()); - } else { - sender.sendMessage(ChatColor.RED + "[CombatTag] That command is not in the blocked commands list."); - } - } - } - } else { - sender.sendMessage(ChatColor.RED + "[CombatTag] Correct Usage: /ct command /"); - } - } - return true; - } else { - sender.sendMessage(ChatColor.RED + "[CombatTag] That is not a valid command!"); - return true; - } - } - return false; - } - - @Override - public final List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { - if (args.length == 1) { - return StringUtil.copyPartialMatches(args[0], SUBCOMMANDS, new ArrayList(SUBCOMMANDS.size())); - } else if (args.length == 2) { - System.out.println(args[1]); - if (args[0].equalsIgnoreCase("command")) { - return StringUtil.copyPartialMatches(args[1], COMMAND_SUBCOMMANDS, new ArrayList(COMMAND_SUBCOMMANDS.size())); - } - } - return ImmutableList.of(); - } - - public double healthCheck(double health) { - if (health < 0) { - health = 0; - } - if (health > 20) { - health = 20; - } - return health; - } - - public SettingsHelper getSettingsHelper() { - return this.settingsHelper; - } - - private Metrics metrics; - public boolean initMetrics() { - try { - if (metrics == null) { - metrics = new Metrics(this); - } - Graph punishment = metrics.createGraph("Punishment used on Combat Tag"); - - punishment.addPlotter(new Plotter("Instakill") { - - @Override - public int getValue() { - if (settings.isInstaKill()) { - return 1; - } else { - return 0; - } - } - }); - - punishment.addPlotter(new Plotter("NPC") { - @Override - public int getValue() { - if (!settings.isInstaKill()) { - return 1; - } else { - return 0; - } - } - }); - metrics.start(); - return true; - } catch (IOException ex) { - return false; - } - } - - public void disableMetrics() { - - } - - private static final int projectId = 86389; - - public void updateProject() { - if (settings.isUpdateEnabled()) { - Updater updater = new Updater(this, CombatTag.projectId, this.getFile(), UpdateType.DEFAULT, true); - } - } - public void registerListeners() { - PluginManager manager = Bukkit.getPluginManager(); - if (settings.isInstaKill()) { - manager.registerEvents(new InstakillListener(), this); - } else { - manager.registerEvents(new NPCListener(), this); - } - manager.registerEvents(new PermissionListener(), this); - manager.registerEvents(new CompatibilityListener(), this); - manager.registerEvents(new PlayerListener(), this); - manager.registerEvents(new SettingListener(), this); - } - - public void registerTasks() { - new NPCUpdateTask().runTaskTimer(this, 10, 5); - } - - public static class NPCUpdateTask extends BukkitRunnable { - @Override - public void run() { - List npcs = CombatTagNPC.getAllNpcs(); - for (CombatTagNPC npc : npcs) { - npc.getNpc().update(); - } - } - } -} diff --git a/src/main/java/com/trc202/CombatTagApi/CombatTagApi.java b/src/main/java/com/trc202/CombatTagApi/CombatTagApi.java index 254f7b8..3a08633 100644 --- a/src/main/java/com/trc202/CombatTagApi/CombatTagApi.java +++ b/src/main/java/com/trc202/CombatTagApi/CombatTagApi.java @@ -1,25 +1,25 @@ package com.trc202.CombatTagApi; +import net.techcable.combattag.CombatTagAPI; + import org.bukkit.Bukkit; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; - -import com.trc202.CombatTag.CombatTag; - -import techcable.minecraft.combattag.CombatTagAPI; -import techcable.minecraft.combattag.entity.CombatTagNPC; +import org.omg.CosNaming.IstringHelper; /** - * @deprecated see techcable.minecraft.combattag CombatTagAPI + * @deprecated use techcable.minecraft.combattag CombatTagAPI */ @Deprecated public class CombatTagApi { - - private final CombatTag plugin; - - public CombatTagApi(CombatTag plugin) { - this.plugin = plugin; - } + + /** + * + * @deprecated use no-args construcor + * @param plugin ignored + */ + @Deprecated + public CombatTagApi(Object plugin) {} /** * Checks to see if the player is in combat. The combat time can be @@ -31,7 +31,7 @@ public CombatTagApi(CombatTag plugin) { */ @Deprecated public boolean isInCombat(Player player) { - return plugin.isInCombat(player.getUniqueId()); + return CombatTagAPI.isTagged(player.getUniqueId()); } /** @@ -47,7 +47,7 @@ public boolean isInCombat(Player player) { public boolean isInCombat(String name) { Player player = Bukkit.getPlayerExact(name); if (player != null) { - return plugin.isInCombat(player.getUniqueId()); + return CombatTagAPI.isTagged(player); } return false; } @@ -62,8 +62,8 @@ public boolean isInCombat(String name) { @Deprecated public long getRemainingTagTime(Player player) { - if (plugin.isInCombat(player.getUniqueId())) { - return plugin.getRemainingTagTime(player.getUniqueId()); + if (isInCombat(player)) { + return CombatTagAPI.getRemainingTagTime(player); } else { return -1L; } @@ -81,11 +81,7 @@ public long getRemainingTagTime(Player player) { public long getRemainingTagTime(String name) { if (Bukkit.getPlayerExact(name) != null) { Player player = Bukkit.getPlayerExact(name); - if (plugin.isInCombat(player.getUniqueId())) { - return plugin.getRemainingTagTime(player.getUniqueId()); - } else { - return -1L; - } + return getRemainingTagTime(player); } return -2L; } @@ -109,7 +105,9 @@ public boolean isNPC(Entity entity) { */ @Deprecated public boolean tagPlayer(Player player) { - return plugin.addTagged(player); + if (isInCombat(player)) return false; + CombatTagAPI.addTagged(player); + return true; } /** @@ -119,7 +117,7 @@ public boolean tagPlayer(Player player) { */ @Deprecated public void untagPlayer(Player player) { - plugin.removeTagged(player.getUniqueId()); + CombatTagAPI.removeTagged(player); } /** @@ -130,6 +128,6 @@ public void untagPlayer(Player player) { */ @Deprecated public String getConfigOption(String configKey) { - return plugin.getSettingsHelper().getProperty(configKey); + return CombatTagAPI.getPlugin().getSettingsHelper().getProperty(configKey); } } diff --git a/src/main/java/com/trc202/Containers/HallOfShame.java b/src/main/java/com/trc202/Containers/HallOfShame.java deleted file mode 100644 index 4952b24..0000000 --- a/src/main/java/com/trc202/Containers/HallOfShame.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.trc202.Containers; - -import java.io.FileWriter; -import java.io.IOException; - -public class HallOfShame { - - private static final String startRow = " \r\n "; - private static final String endRow = ""; - private static final String startCol = ""; - private static final String endCol = ""; - - public void generateHTMLPage(String file, String table) { - String output = ""; - output = output + " \r\n \r\n"; - output = output + "

Hall Of PvP Shame

\r\n"; - output = output + table; - output = output + " \r\n \r\n "; - try { - FileWriter fileWriter = new FileWriter(file); - fileWriter.write(output); - fileWriter.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public String generateTable(String[][] twoDArray) { - String output = ""; - output = output + " \r\n"; - for (String[] stringArray : twoDArray) { - output = output + startRow; - for (String string : stringArray) { - output = output + startCol + string + endCol; - } - output = output + endRow; - } - output = output + "
"; - return output; - } - /** - * - * - * - * - * - * - * - * - * - *
row 1, cell 1row 1, cell 2
row 2, cell 1row 2, cell 2
- */ -} diff --git a/src/main/java/net/techcable/combattag/CombatPlayer.java b/src/main/java/net/techcable/combattag/CombatPlayer.java new file mode 100644 index 0000000..6ba11eb --- /dev/null +++ b/src/main/java/net/techcable/combattag/CombatPlayer.java @@ -0,0 +1,79 @@ +package net.techcable.combattag; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.locks.ReentrantLock; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import com.google.common.base.Preconditions; + +import net.techcable.npclib.NPC; +import net.techcable.npclib.NPCRegistry; +import net.techcable.techutils.entity.TechPlayer; +import lombok.*; + +public class CombatPlayer extends TechPlayer { + private long tagTime = -1; + + public CombatPlayer(UUID player, CombatTag plugin) { + super(player, plugin); + } + + public CombatTag getPlugin() { + return (CombatTag) super.getPlugin(); + } + + public boolean isTagged() { + return tagTime > System.currentTimeMillis(); + } + + public void untag() { + this.tagTime = -1; + } + + public void tag() { + this.tagTime = System.currentTimeMillis() + (getPlugin().getSettings().getTagDuration() * 1000); + } + + public long getRemainingTagTime() { + if (!isTagged()) return -1; + return tagTime - System.currentTimeMillis(); + } + + public boolean hasNPC() { + return getNpc() != null; + } + + public NPC getNpc() { + return NPCManager.getInstance().getNpc(getId()); + } + + public static CombatPlayer getPlayer(UUID id) { + return Utils.getPlugin().getPlayer(id); + } + public static CombatPlayer getPlayer(Player player) { + return getPlayer(player.getUniqueId()); + } + + public boolean isDisguised() { + return PluginCompatibility.isDisguised(getEntity()); + } + + public void unDisguise() { + PluginCompatibility.unDisguise(getEntity()); + } + + + public String getNpcName() { + String npcName = getPlugin().getSettings().getNpcName(); + if (!npcName.contains("player") && !npcName.contains("number")) { + return npcName + NPCManager.getInstance().getNpcNumber(); + } + return npcName.replace("player", getName()).replace("number", Integer.toString(NPCManager.getInstance().getNpcNumber())); + } +} \ No newline at end of file diff --git a/src/main/java/net/techcable/combattag/CombatTag.java b/src/main/java/net/techcable/combattag/CombatTag.java new file mode 100644 index 0000000..fcf05fb --- /dev/null +++ b/src/main/java/net/techcable/combattag/CombatTag.java @@ -0,0 +1,128 @@ +package net.techcable.combattag; + +import static net.techcable.combattag.Utils.severe; + +import java.io.File; +import java.io.IOException; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.PluginManager; +import org.mcstats.Metrics; +import org.mcstats.Metrics.Graph; +import org.mcstats.Metrics.Plotter; + +import com.trc202.settings.Settings; +import com.trc202.settings.SettingsHelper; +import com.trc202.settings.SettingsLoader; + +import net.gravitydevelopment.updater.Updater; +import net.gravitydevelopment.updater.Updater.UpdateType; +import net.techcable.combattag.listeners.CompatibilityListener; +import net.techcable.combattag.listeners.InstakillListener; +import net.techcable.combattag.listeners.NPCListener; +import net.techcable.combattag.listeners.PermissionListener; +import net.techcable.combattag.listeners.PlayerListener; +import net.techcable.combattag.listeners.SettingListener; +import net.techcable.npclib.NPCLib; +import net.techcable.techutils.TechPlugin; +import lombok.*; + +@Getter +public class CombatTag extends TechPlugin { + private Settings settings; + private final SettingsHelper settingsHelper = new SettingsHelper(new File(getDataFolder().getParent() + File.pathSeparator + "CombatTag" + File.pathSeparator + "settings.prop"), getName()); + private NPCManager npcManager; + + @Override + protected void shutdown() { + Utils.info("Disabled"); + } + + @Override + protected void startup() { + this.settings = new SettingsLoader().loadSettings(getSettingsHelper(), getDescription().getVersion()); + initMetrics(); + tryUpdatePlugin(); + registerListeners(); + if (!getSettings().isInstaKill()) { + if (!NPCLib.isSupported() ){ + severe("NPCs are enabled but this version of minecraft isn't supported"); + severe("[CombatTag] Please install citizens or update CombatTag if you want to use npcs"); + setEnabled(false); + return; + } else { + this.npcManager = new NPCManager(this); + } + } + + if (!initMetrics()) { + getLogger().warning("Unable to initialize metrics"); + } else { + Utils.debug("Enabled Metrics"); + } + } + + @Override + public CombatPlayer createPlayer(UUID id) { + return new CombatPlayer(id, this); + } + + private Metrics metrics; + public boolean initMetrics() { + try { + if (metrics == null) { + metrics = new Metrics(this); + } + Graph punishment = metrics.createGraph("Punishment used on Combat Tag"); + + punishment.addPlotter(new Plotter("Instakill") { + + @Override + public int getValue() { + if (settings.isInstaKill()) { + return 1; + } else { + return 0; + } + } + }); + + punishment.addPlotter(new Plotter("NPC") { + @Override + public int getValue() { + if (!settings.isInstaKill()) { + return 1; + } else { + return 0; + } + } + }); + metrics.start(); + return true; + } catch (IOException ex) { + return false; + } + } + + private static final int projectId = 86389; + + public void tryUpdatePlugin() { + if (getSettings().isUpdateEnabled()) { + @SuppressWarnings("unused") + Updater updater = new Updater(this, CombatTag.projectId, this.getFile(), UpdateType.DEFAULT, true); + } + } + public void registerListeners() { + PluginManager manager = Bukkit.getPluginManager(); + if (settings.isInstaKill()) { + manager.registerEvents(new InstakillListener(), this); + } else { + manager.registerEvents(new NPCListener(), this); + } + manager.registerEvents(new PermissionListener(), this); + manager.registerEvents(new CompatibilityListener(), this); + manager.registerEvents(new PlayerListener(), this); + manager.registerEvents(new SettingListener(), this); + } +} diff --git a/src/main/java/techcable/minecraft/combattag/CombatTagAPI.java b/src/main/java/net/techcable/combattag/CombatTagAPI.java similarity index 74% rename from src/main/java/techcable/minecraft/combattag/CombatTagAPI.java rename to src/main/java/net/techcable/combattag/CombatTagAPI.java index 32bcda1..503f891 100644 --- a/src/main/java/techcable/minecraft/combattag/CombatTagAPI.java +++ b/src/main/java/net/techcable/combattag/CombatTagAPI.java @@ -1,4 +1,4 @@ -package techcable.minecraft.combattag; +package net.techcable.combattag; import java.util.UUID; @@ -6,12 +6,6 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import com.trc202.CombatTag.CombatTag; - -import techcable.minecraft.combattag.entity.CombatTagNPC; -import techcable.minecraft.npclib.NPCLib; -import techcable.minecraft.techutils.entity.TechPlayer; - import lombok.*; /** @@ -40,11 +34,14 @@ public static boolean isTagged(Player player) { * @return true if combat tagged */ public static boolean isTagged(UUID player) { - return getPlugin().inTagged(player); + return CombatPlayer.getPlayer(player).isTagged(); } /** * Returns the time a player has left in combat + * + * Returns -1 if the player isn't in combat + * * @param player the player to check * @return time in milliseconds until the player is no longer in combat */ @@ -54,15 +51,14 @@ public static long getRemainingTagTime(Player player) { /** * Returns the time a player has left in combat + * + * Returns -1 if the player isn't in combat + * * @param player the player to check * @return time in milliseconds until the player is no longer in combat */ public static long getRemainingTagTime(UUID player) { - if (isTagged(player)) { - return getPlugin().getRemainingTagTime(player); - } else { - return -1; - } + return CombatPlayer.getPlayer(player).getRemainingTagTime(); } /** @@ -71,7 +67,7 @@ public static long getRemainingTagTime(UUID player) { * @return true if entity is a NPC */ public static boolean isNPC(Entity entity) { - return CombatTagNPC.isNPC(entity); + return NPCManager.getInstance().isNPC(entity); } /** @@ -80,23 +76,20 @@ public static boolean isNPC(Entity entity) { * @param tagged true if player should be tagged, false if he should be untagged */ public static void setTagged(Player player, boolean tagged) { - if (tagged) { - getPlugin().addTagged(player); - } else { - getPlugin().removeTagged(player.getUniqueId()); - } + setTagged(player.getUniqueId(), tagged); } /** * Set if a player is tagged - * doesn't support tagging an offline player + * doesn't support tagging or untagging an offline player + * * @param player the player to set the tag status off * @param tagged true if player should be tagged, false if he should be untagged */ public static void setTagged(UUID player, boolean tagged) { if (tagged) { - getPlugin().addTagged(Bukkit.getPlayer(player)); //Could be offline + CombatPlayer.getPlayer(player).tag(); } else { - getPlugin().removeTagged(player); + CombatPlayer.getPlayer(player).untag(); } } diff --git a/src/main/java/net/techcable/combattag/NPCManager.java b/src/main/java/net/techcable/combattag/NPCManager.java new file mode 100644 index 0000000..db4d912 --- /dev/null +++ b/src/main/java/net/techcable/combattag/NPCManager.java @@ -0,0 +1,87 @@ +package net.techcable.combattag; + +import java.util.UUID; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import net.techcable.npclib.NPC; +import net.techcable.npclib.NPCLib; +import net.techcable.npclib.NPCRegistry; +import net.techcable.techutils.inventory.InventoryUtils; +import net.techcable.techutils.inventory.PlayerData; +import lombok.*; + +@RequiredArgsConstructor +@Getter +public class NPCManager { + private final CombatTag plugin; + + public NPC spawnNPC(CombatPlayer toSpawnFor) { + NPC npc = getRegistry().createNPC(EntityType.PLAYER, toSpawnFor.getId(), toSpawnFor.getNpcName()); + npc.setSkin(toSpawnFor.getId()); + npc.setProtected(false); + npc.spawn(toSpawnFor.getEntity().getLocation()); + copyFromPlayer(npc, toSpawnFor.getEntity()); + return npc; + } + + public void despawn(NPC npc) { + syncInventory(npc); + npc.despawn(); + getRegistry().deregister(npc); + Utils.debug("Despawned " + npc.getName()); + } + + public NPC getNpc(UUID id) { + return getRegistry().getByUUID(id); + } + + public NPC getNpc(Entity e) { + return getRegistry().getAsNPC(e); + } + + private static void copyFromPlayer(NPC npc, Player source) { + InventoryUtils.copy(InventoryUtils.getData(source), InventoryUtils.getData((Player)npc.getEntity())); + } + + public static void syncInventory(NPC npc) { + PlayerData player = InventoryUtils.getData(npc.getUUID()); + InventoryUtils.copy(InventoryUtils.getData((Player)npc.getEntity()), player); + } + + public NPCRegistry getRegistry() { + return NPCLib.getNPCRegistry("Combat-Tag", getPlugin()); + } + + public boolean isNPC(Entity e) { + return getRegistry().isNPC(e); + } + + public static NPCManager getInstance() { + return Utils.getPlugin().getNpcManager(); + } + + public void delayedDespawn(final NPC npc, int despawnTicks, final boolean kill) { + BukkitRunnable task = new BukkitRunnable() { + + @Override + public void run() { + if (kill) { + ((LivingEntity)npc.getEntity()).damage(1000); + } else { + despawn(npc); + } + } + }; + task.runTaskLater(Utils.getPlugin(), despawnTicks); + } + + private int npcNumber; + public int getNpcNumber() { + return npcNumber++; + } +} \ No newline at end of file diff --git a/src/main/java/net/techcable/combattag/PluginCompatibility.java b/src/main/java/net/techcable/combattag/PluginCompatibility.java new file mode 100644 index 0000000..735e6a3 --- /dev/null +++ b/src/main/java/net/techcable/combattag/PluginCompatibility.java @@ -0,0 +1,45 @@ +package net.techcable.combattag; + +import me.libraryaddict.disguise.DisguiseAPI; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import com.sk89q.worldguard.bukkit.WGBukkit; +import com.sk89q.worldguard.protection.flags.DefaultFlag; + +import lombok.*; + +@Getter +public class PluginCompatibility { + private PluginCompatibility() {} + + public static boolean isPvpDisabled(Location location) { + return !isWGPvPEnabled(location); + } + + public static boolean isWGPvPEnabled(Location location) { + return WGBukkit.getRegionManager(location.getWorld()).getApplicableRegions(location).allows(DefaultFlag.PVP); + } + + public static boolean isDisguised(Player player) { + if (!hasLibsDisguises()) return false; + return DisguiseAPI.isDisguised(player); + } + + public static void unDisguise(Player player) { + if (!hasLibsDisguises()) return; + DisguiseAPI.undisguiseToAll(player); + } + + public static boolean hasLibsDisguises() { + try { + Class.forName("me.libraryaddict.disguise.DisguiseAPI"); + return true; + } catch (ClassNotFoundException ex) { + return false; + } + } +} diff --git a/src/main/java/techcable/minecraft/combattag/Utils.java b/src/main/java/net/techcable/combattag/Utils.java similarity index 91% rename from src/main/java/techcable/minecraft/combattag/Utils.java rename to src/main/java/net/techcable/combattag/Utils.java index ba2f44f..bf3a3bc 100644 --- a/src/main/java/techcable/minecraft/combattag/Utils.java +++ b/src/main/java/net/techcable/combattag/Utils.java @@ -1,10 +1,9 @@ -package techcable.minecraft.combattag; +package net.techcable.combattag; import java.util.logging.Logger; import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; -import org.bukkit.Material; import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.Entity; import org.bukkit.entity.HumanEntity; @@ -13,17 +12,11 @@ import org.bukkit.entity.Projectile; import org.bukkit.entity.Tameable; import org.bukkit.event.Event; -import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.potion.PotionEffectType; import org.bukkit.projectiles.ProjectileSource; -import com.trc202.CombatTag.CombatTag; - -import techcable.minecraft.npclib.NPC; -import techcable.minecraft.techutils.entity.TechPlayer; - import lombok.*; @Getter @@ -38,7 +31,7 @@ public static CombatTag getPlugin() { } } public static boolean isDebug() { - return getPlugin().isDebugEnabled(); + return getPlugin().getSettings().isDebugEnabled(); } public static Logger getLogger() { return Bukkit.getLogger(); diff --git a/src/main/java/techcable/minecraft/combattag/event/CombatLogEvent.java b/src/main/java/net/techcable/combattag/event/CombatLogEvent.java similarity index 71% rename from src/main/java/techcable/minecraft/combattag/event/CombatLogEvent.java rename to src/main/java/net/techcable/combattag/event/CombatLogEvent.java index 124c37b..0b9254c 100644 --- a/src/main/java/techcable/minecraft/combattag/event/CombatLogEvent.java +++ b/src/main/java/net/techcable/combattag/event/CombatLogEvent.java @@ -1,17 +1,17 @@ -package techcable.minecraft.combattag.event; +package net.techcable.combattag.event; + +import net.techcable.combattag.CombatPlayer; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import techcable.minecraft.combattag.entity.CombatTagPlayer; - import lombok.*; @Getter @RequiredArgsConstructor public class CombatLogEvent extends Event implements Cancellable { - private final CombatTagPlayer player; + private final CombatPlayer player; @Setter private boolean cancelled; @Getter diff --git a/src/main/java/net/techcable/combattag/event/CombatTagEvent.java b/src/main/java/net/techcable/combattag/event/CombatTagEvent.java new file mode 100644 index 0000000..5b4abad --- /dev/null +++ b/src/main/java/net/techcable/combattag/event/CombatTagEvent.java @@ -0,0 +1,43 @@ +package net.techcable.combattag.event; + +import net.techcable.combattag.CombatPlayer; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import lombok.*; + +@Getter +@RequiredArgsConstructor +public class CombatTagEvent extends Event implements Cancellable { + private final CombatPlayer player; + private final LivingEntity cause; + @Getter(AccessLevel.NONE) + private final TagCause reason; + + public boolean isBecauseOfAttack() { + return reason == TagCause.ATTACK; + } + + public boolean isBecauseOfDefend() { + return reason == TagCause.DEFEND; + } + + @Getter + private static final HandlerList handlerList = new HandlerList(); + @Setter + private boolean cancelled; + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } + + public static enum TagCause { + ATTACK, + DEFEND; + } +} diff --git a/src/main/java/net/techcable/combattag/event/CombatUntagEvent.java b/src/main/java/net/techcable/combattag/event/CombatUntagEvent.java new file mode 100644 index 0000000..6b8c7eb --- /dev/null +++ b/src/main/java/net/techcable/combattag/event/CombatUntagEvent.java @@ -0,0 +1,23 @@ +package net.techcable.combattag.event; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import net.techcable.combattag.CombatPlayer; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +@RequiredArgsConstructor +@Getter +public class CombatUntagEvent extends Event { + private final CombatPlayer player; + + @Getter + private static final HandlerList handlerList = new HandlerList(); + + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } +} diff --git a/src/main/java/techcable/minecraft/combattag/event/package-info.java b/src/main/java/net/techcable/combattag/event/package-info.java similarity index 50% rename from src/main/java/techcable/minecraft/combattag/event/package-info.java rename to src/main/java/net/techcable/combattag/event/package-info.java index d403c53..bc84a81 100644 --- a/src/main/java/techcable/minecraft/combattag/event/package-info.java +++ b/src/main/java/net/techcable/combattag/event/package-info.java @@ -5,4 +5,4 @@ * @author Nicholas Schlabach * */ -package techcable.minecraft.combattag.event; \ No newline at end of file +package net.techcable.combattag.event; \ No newline at end of file diff --git a/src/main/java/net/techcable/combattag/listeners/CompatibilityListener.java b/src/main/java/net/techcable/combattag/listeners/CompatibilityListener.java new file mode 100644 index 0000000..41126f9 --- /dev/null +++ b/src/main/java/net/techcable/combattag/listeners/CompatibilityListener.java @@ -0,0 +1,24 @@ +package net.techcable.combattag.listeners; + +import com.trc202.settings.Settings; + +import net.techcable.combattag.PluginCompatibility; +import net.techcable.combattag.Utils; +import net.techcable.combattag.event.CombatTagEvent; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.entity.Player; +import org.bukkit.entity.Entity; + +public class CompatibilityListener implements Listener { + @EventHandler + public void onCombatTag(CombatTagEvent event) { + if (event.getPlayer().isDisguised() && getSettings().isDisableDisguisesInCombat()) event.getPlayer().unDisguise(); + } + + public Settings getSettings() { + return Utils.getPlugin().getSettings(); + } +} diff --git a/src/main/java/net/techcable/combattag/listeners/InstakillListener.java b/src/main/java/net/techcable/combattag/listeners/InstakillListener.java new file mode 100644 index 0000000..cb66e5c --- /dev/null +++ b/src/main/java/net/techcable/combattag/listeners/InstakillListener.java @@ -0,0 +1,21 @@ +package net.techcable.combattag.listeners; + +import net.techcable.combattag.CombatPlayer; +import net.techcable.combattag.Utils; +import net.techcable.combattag.event.CombatLogEvent; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; + +import lombok.*; + +public class InstakillListener implements Listener { + @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) + public void onCombatLog(CombatLogEvent event) { + CombatPlayer player = event.getPlayer(); + player.getEntity().damage(1000); + player.untag(); + Utils.debug(player.getName() + " has been instakilled."); + } +} diff --git a/src/main/java/net/techcable/combattag/listeners/NPCListener.java b/src/main/java/net/techcable/combattag/listeners/NPCListener.java new file mode 100644 index 0000000..e52b56c --- /dev/null +++ b/src/main/java/net/techcable/combattag/listeners/NPCListener.java @@ -0,0 +1,46 @@ +package net.techcable.combattag.listeners; + +import net.techcable.combattag.CombatPlayer; +import net.techcable.combattag.NPCManager; +import net.techcable.combattag.Utils; +import net.techcable.combattag.event.CombatLogEvent; +import net.techcable.npclib.NPC; +import net.techcable.techutils.inventory.InventoryUtils; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.player.PlayerJoinEvent; + +import com.trc202.settings.Settings; + +import lombok.*; + +public class NPCListener implements Listener { + @EventHandler + public void onCombatLog(CombatLogEvent event) { + CombatPlayer player = event.getPlayer(); + NPC npc = NPCManager.getInstance().spawnNPC(player); + if (getSettings().getNpcDespawnTime() > 0) { + NPCManager.getInstance().delayedDespawn(npc, getSettings().getNpcDespawnTime() * 20, getSettings().isNpcDieAfterTime()); + } + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + CombatPlayer player = CombatPlayer.getPlayer(event.getPlayer()); + if (!player.hasNPC()) return; //Player didn't combat log + NPCManager.getInstance().despawn(player.getNpc()); + } + + @EventHandler + public void onDeath(EntityDeathEvent event) { + if (!NPCManager.getInstance().isNPC(event.getEntity())) return; + NPC npc = NPCManager.getInstance().getNpc(event.getEntity()); + NPCManager.syncInventory(npc); + } + + public static Settings getSettings() { + return Utils.getPlugin().getSettings(); + } +} diff --git a/src/main/java/net/techcable/combattag/listeners/PermissionListener.java b/src/main/java/net/techcable/combattag/listeners/PermissionListener.java new file mode 100644 index 0000000..e0ecff6 --- /dev/null +++ b/src/main/java/net/techcable/combattag/listeners/PermissionListener.java @@ -0,0 +1,24 @@ +package net.techcable.combattag.listeners; + +import net.techcable.combattag.event.CombatLogEvent; +import net.techcable.combattag.event.CombatTagEvent; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class PermissionListener implements Listener { + public static String DONT_COMBAT_LOG_PERM = "combattag.ignore.pvplog"; + public static String DONT_COMBAT_TAG_PERM = "combattag.ignore"; + @EventHandler + public void onCombatLog(CombatLogEvent event) { + if (event.getPlayer().getEntity().hasPermission(DONT_COMBAT_LOG_PERM)) { + event.setCancelled(true); + } + } + @EventHandler + public void onCombatTag(CombatTagEvent event) { + if (event.getPlayer().getEntity().hasPermission(DONT_COMBAT_TAG_PERM)) { + event.setCancelled(true); + } + } +} diff --git a/src/main/java/net/techcable/combattag/listeners/PlayerListener.java b/src/main/java/net/techcable/combattag/listeners/PlayerListener.java new file mode 100644 index 0000000..e4c8c03 --- /dev/null +++ b/src/main/java/net/techcable/combattag/listeners/PlayerListener.java @@ -0,0 +1,93 @@ +package net.techcable.combattag.listeners; + +import java.util.Set; +import java.util.UUID; + +import javax.persistence.EntityListeners; + +import net.techcable.combattag.CombatPlayer; +import net.techcable.combattag.CombatTagAPI; +import net.techcable.combattag.PluginCompatibility; +import net.techcable.combattag.Utils; +import net.techcable.combattag.event.CombatLogEvent; +import net.techcable.combattag.event.CombatTagEvent; +import net.techcable.combattag.event.CombatTagEvent.TagCause; + +import org.bukkit.Bukkit; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.Vector; + +import com.google.common.collect.Sets; + +import static net.techcable.combattag.Utils.getPlugin; + +public class PlayerListener implements Listener { + public static final double KNOCKBACK_POWER = 1.5; + + @EventHandler + public void onMove(PlayerMoveEvent event) { + if (!Utils.getPlugin().getSettings().isStopCombatSafezoning()) return; + if (event.getPlayer().hasPermission("combattag.safezone.ignore")); + if (!CombatPlayer.getPlayer(event.getPlayer()).isTagged()) return; + if (PluginCompatibility.isPvpDisabled(event.getTo())) { + knockback(event.getPlayer()); + event.getPlayer().sendMessage("[CombatTag] You can't enter a safezone while combat tagged"); + } + } + + public static void knockback(Player player) { + player.setVelocity(player.getVelocity().multiply(-KNOCKBACK_POWER).setY(2)); + } + @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) + public void onDamage(EntityDamageByEntityEvent event) { + LivingEntity attacker = Utils.getRootDamager(event.getDamager()); + LivingEntity defender = (LivingEntity) event.getEntity(); + if (CombatTagAPI.isNPC(defender) || CombatTagAPI.isNPC(attacker)) return; + if (attacker instanceof Player) onAttack(CombatPlayer.getPlayer((Player)attacker), defender); + if (defender instanceof Player) onDefend(CombatPlayer.getPlayer((Player)defender), attacker); + } + + public void onAttack(CombatPlayer attacker, LivingEntity defender) { + if (!(defender instanceof Player) && !Utils.getPlugin().getSettings().mobTag()) return; + if (attacker.isTagged()) return; + CombatTagEvent event = new CombatTagEvent(attacker, defender, TagCause.ATTACK); + Utils.fire(event); + if (event.isCancelled()) return; + attacker.tag(); + } + + public void onDefend(CombatPlayer defender, LivingEntity attacker) { + if (!(attacker instanceof Player) && !Utils.getPlugin().getSettings().mobTag()) return; + if (defender.isTagged()) return; + CombatTagEvent event = new CombatTagEvent(defender, attacker, TagCause.DEFEND); + Utils.fire(event); + if (event.isCancelled()) return; + defender.tag(); + } + + @EventHandler(priority=EventPriority.MONITOR) + public void onQuit(PlayerQuitEvent event) { + if (CombatTagAPI.isNPC(event.getPlayer())) return; //Don't combat log npcs + CombatPlayer player = getPlugin().getPlayer(event.getPlayer().getUniqueId()); + if (player.isTagged()) { + Utils.fire(new CombatLogEvent(player)); + } + } + + @EventHandler(priority=EventPriority.MONITOR) + public void onDeath(PlayerDeathEvent event) { + if (CombatTagAPI.isNPC(event.getEntity())) return; + CombatPlayer player = CombatPlayer.getPlayer(event.getEntity()); + player.untag(); + } +} diff --git a/src/main/java/techcable/minecraft/combattag/listeners/SettingListener.java b/src/main/java/net/techcable/combattag/listeners/SettingListener.java similarity index 61% rename from src/main/java/techcable/minecraft/combattag/listeners/SettingListener.java rename to src/main/java/net/techcable/combattag/listeners/SettingListener.java index a17428a..b313ae4 100644 --- a/src/main/java/techcable/minecraft/combattag/listeners/SettingListener.java +++ b/src/main/java/net/techcable/combattag/listeners/SettingListener.java @@ -1,4 +1,8 @@ -package techcable.minecraft.combattag.listeners; +package net.techcable.combattag.listeners; + +import net.techcable.combattag.CombatPlayer; +import net.techcable.combattag.Utils; +import net.techcable.combattag.event.CombatTagEvent; import org.apache.commons.lang.ArrayUtils; import org.bukkit.ChatColor; @@ -13,77 +17,67 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerToggleFlightEvent; -import com.sk89q.worldguard.blacklist.event.BlockPlaceBlacklistEvent; import com.trc202.settings.Settings; -import static techcable.minecraft.combattag.CombatTagAPI.isNPC; -import techcable.minecraft.combattag.Utils; -import techcable.minecraft.combattag.entity.CombatTagPlayer; -import techcable.minecraft.combattag.event.CombatTagByPlayerEvent; -import techcable.minecraft.combattag.event.CombatTagEvent; - +import static net.techcable.combattag.CombatTagAPI.isNPC; import lombok.*; +import net.techcable.combattag.CombatTagAPI; public class SettingListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onCombatTagMonitor(CombatTagEvent event) { - event.getDefender().getPlayer().sendMessage(getSettings().getTagMessageDamaged().replace("[player]", Utils.getName(event.getAttacker()))); - if (getSettings().blockFly() && event.getDefender().getPlayer().isFlying()) { - event.getDefender().getPlayer().setFlying(false); + if (event.isBecauseOfAttack()) { + event.getPlayer().getEntity().sendMessage(getSettings().getTagMessageDamager().replace("[player]", Utils.getName(event.getCause()))); } - } - - public void onCombatTagByPlayerMonitor(CombatTagByPlayerEvent event) { - if (getSettings().isSendMessageWhenTagged()) { - event.getAttacker().sendMessage(getSettings().getTagMessageDamager().replace("[player]", event.getDefender().getName())); + if (event.isBecauseOfDefend()) { + event.getPlayer().getEntity().sendMessage(getSettings().getTagMessageDamaged().replace("[player]", Utils.getName(event.getCause()))); } } @EventHandler(ignoreCancelled = true) public void onCombatTag(CombatTagEvent event) { - if (getSettings().onlyDamagerTagged()) { - event.setTagDefender(false); + if (getSettings().onlyDamagerTagged() && event.isBecauseOfDefend()) { + event.setCancelled(true); } - if (ArrayUtils.contains(getSettings().getDisallowedWorlds(), event.getDefender().getLocation().getWorld())) { + if (ArrayUtils.contains(getSettings().getDisallowedWorlds(), event.getPlayer().getEntity().getLocation().getWorld())) { event.setCancelled(true); // Block combat tag in disabled worlds } } @EventHandler - public void onCombatTagByPlayer(CombatTagByPlayerEvent event) { - if (getSettings().blockCreativeTagging() && event.getAttacker().getGameMode().equals(GameMode.CREATIVE)) { - event.getAttacker().sendMessage("[CombatTag] You can't combat tag in creative mode"); - event.setCancelled(true); - } + public void onCombatTagByPlayer(CombatTagEvent event) { + if (getSettings().blockCreativeTagging() && event.getPlayer().getEntity().getGameMode().equals(GameMode.CREATIVE) && event.isBecauseOfAttack()) { + event.getPlayer().getEntity().sendMessage("[CombatTag] You can't combat tag in creative mode"); + event.setCancelled(true); + } } public Settings getSettings() { - return Utils.getPlugin().settings; + return Utils.getPlugin().getSettings(); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { if (isNPC(event.getPlayer())) return; - CombatTagPlayer player = CombatTagPlayer.getPlayer(event.getPlayer()); - if (player.isTagged() && !getSettings().isBlockEditWhileTagged()) { - event.getPlayer().sendMessage("[CombatTag] You can't break blocks in combat"); - event.setCancelled(true); - } - } + if (CombatTagAPI.isTagged(event.getPlayer()) && !getSettings().isBlockEditWhileTagged()) { + event.getPlayer().sendMessage("[CombatTag] You can't break blocks in combat"); + event.setCancelled(true); + } + } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { if (isNPC(event.getPlayer())) return; - CombatTagPlayer player = CombatTagPlayer.getPlayer(event.getPlayer()); - if (player.isTagged() && !getSettings().isBlockEditWhileTagged()) { - event.getPlayer().sendMessage("[CombatTag] You can't break blocks in combat"); - event.setCancelled(true); - } + if (CombatTagAPI.isTagged(event.getPlayer()) && !getSettings().isBlockEditWhileTagged()) { + event.getPlayer().sendMessage("[CombatTag] You can't break blocks in combat"); + event.setCancelled(true); + } } + @EventHandler public void onTeleport(PlayerTeleportEvent event) { if (isNPC(event.getPlayer())) return; - CombatTagPlayer player = CombatTagPlayer.getPlayer(event.getPlayer()); + CombatPlayer player = CombatPlayer.getPlayer(event.getPlayer()); if (!player.isTagged()) return; if (event.getCause().equals(TeleportCause.PLUGIN) || event.getCause().equals(TeleportCause.UNKNOWN) && getSettings().blockTeleport()) { event.getPlayer().sendMessage("[CombatTag] You can't teleport in combat"); @@ -97,8 +91,7 @@ public void onTeleport(PlayerTeleportEvent event) { public void onFly(PlayerToggleFlightEvent event) { if (isNPC(event.getPlayer())) return; if (!getSettings().blockFly()) return; - CombatTagPlayer player = CombatTagPlayer.getPlayer(event.getPlayer()); - if (player.isTagged()) { + if (CombatTagAPI.isTagged(event.getPlayer())) { event.getPlayer().sendMessage("[CombatTag] You can't fly in combat"); event.setCancelled(true); } @@ -109,32 +102,32 @@ public void onFly(PlayerToggleFlightEvent event) { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { if (isNPC(event.getPlayer())) return; - CombatTagPlayer player = CombatTagPlayer.getPlayer(event.getPlayer()); + CombatPlayer player = CombatPlayer.getPlayer(event.getPlayer()); if (player.isTagged()) { String command = event.getMessage(); for (String disabledCommand : getSettings().getDisabledCommands()) { if (disabledCommand.equalsIgnoreCase("all") && !command.equalsIgnoreCase("/ct") && !command.equalsIgnoreCase("/combattag")) { - player.getPlayer().sendMessage(ChatColor.RED + "[CombatTag] All commands are disabled while in combat"); + player.getEntity().sendMessage(ChatColor.RED + "[CombatTag] All commands are disabled while in combat"); event.setCancelled(true); return; } if (command.indexOf(" ") == disabledCommand.length()) { if (command.substring(0, command.indexOf(" ")).equalsIgnoreCase(disabledCommand)) { Utils.debug("Combat Tag has blocked the command: " + disabledCommand + " ."); - player.getPlayer().sendMessage(ChatColor.RED + "[CombatTagReloaded] This command is disabled while in combat"); + player.getEntity().sendMessage(ChatColor.RED + "[CombatTagReloaded] This command is disabled while in combat"); event.setCancelled(true); return; } } else if (disabledCommand.indexOf(" ") > 0) { if (command.toLowerCase().startsWith(disabledCommand.toLowerCase())) { Utils.debug("Combat Tag has blocked the command: " + disabledCommand + " ."); - player.getPlayer().sendMessage(ChatColor.RED + "[CombatTagReloaded] This command is disabled while in combat"); + player.getEntity().sendMessage(ChatColor.RED + "[CombatTagReloaded] This command is disabled while in combat"); event.setCancelled(true); return; } } else if (!command.contains(" ") && command.equalsIgnoreCase(disabledCommand)) { Utils.debug("Combat Tag has blocked the command: " + disabledCommand + " ."); - player.getPlayer().sendMessage(ChatColor.RED + "[CombatTagReloaded] This command is disabled while in combat"); + player.getEntity().sendMessage(ChatColor.RED + "[CombatTagReloaded] This command is disabled while in combat"); event.setCancelled(true); return; } diff --git a/src/main/java/techcable/minecraft/combattag/PluginCompatibility.java b/src/main/java/techcable/minecraft/combattag/PluginCompatibility.java deleted file mode 100644 index be9088a..0000000 --- a/src/main/java/techcable/minecraft/combattag/PluginCompatibility.java +++ /dev/null @@ -1,70 +0,0 @@ -package techcable.minecraft.combattag; - -import me.libraryaddict.disguise.DisguiseAPI; - -import com.sk89q.worldguard.bukkit.WGBukkit; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.flags.DefaultFlag; - -import techcable.minecraft.techutils.libs.factionsapi.FactionsAPI; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import lombok.*; - -@Getter -public class PluginCompatibility { - private PluginCompatibility() {} - - public static boolean isPvpDisabled(Location location) { - return !isWGPvPEnabled(location) || isSafezone(location); - } - public static boolean isWGPvPEnabled(Location location) { - if (!hasWG()) return true; - ApplicableRegionSet set = WGBukkit.getRegionManager(location.getWorld()).getApplicableRegions(location); - return set.testState(null, DefaultFlag.PVP); - } - - public static boolean isSafezone(Location location) { - if (!hasFactions()) return false; - return FactionsAPI.getInstance().getOwningFaction(location).isSafezone(); - } - - public static boolean hasWG() { - try { - Class.forName("com.sk89q.worldguard.bukkit.WorldGuardPlugin"); - } catch (ClassNotFoundException ex) { - return false; - } - Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldGuard"); - if (plugin != null && plugin instanceof WorldGuardPlugin) return true; - else return false; - } - - public static boolean isDisguised(Player player) { - if (!hasLibsDisguises()) return false; - return DisguiseAPI.isDisguised(player); - } - - public static void unDisguise(Player player) { - if (!hasLibsDisguises()) return; - DisguiseAPI.undisguiseToAll(player); - } - - public static boolean hasFactions() { - return FactionsAPI.isFactionsInstalled(); - } - - public static boolean hasLibsDisguises() { - try { - Class.forName("me.libraryaddict.disguise.DisguiseAPI"); - return true; - } catch (ClassNotFoundException ex) { - return false; - } - } -} diff --git a/src/main/java/techcable/minecraft/combattag/entity/CombatTagNPC.java b/src/main/java/techcable/minecraft/combattag/entity/CombatTagNPC.java deleted file mode 100644 index 9312cee..0000000 --- a/src/main/java/techcable/minecraft/combattag/entity/CombatTagNPC.java +++ /dev/null @@ -1,119 +0,0 @@ -package techcable.minecraft.combattag.entity; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import net.techcable.minecraft.techutils.offlineplayer.PlayerData; - -import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -import com.google.common.base.Preconditions; - -import techcable.minecraft.combattag.Utils; -import static techcable.minecraft.combattag.Utils.getPlugin; -import techcable.minecraft.npclib.NPC; -import techcable.minecraft.npclib.NPCLib; -import techcable.minecraft.npclib.NPCRegistry; -import techcable.minecraft.techutils.InventoryUtils; -import techcable.minecraft.techutils.UUIDUtils; -import techcable.minecraft.techutils.utils.EasyCache; -import techcable.minecraft.techutils.utils.EasyCache.Loader; -import lombok.*; - -@Getter -@RequiredArgsConstructor -public class CombatTagNPC { - private final UUID npcId; - - private static final NPCRegistry registry = NPCLib.getNPCRegistry("CombatTagReloaded"); - - public Player getAsPlayer() { - return (Player) getNpc().getEntity(); - } - - public CombatTagPlayer getPlayer() { - return CombatTagPlayer.getPlayer(getNpc().getUUID()); - } - - public void despawn() { - syncInventory(); - if (getNpc().isSpawned()) getNpc().despawn(); - Utils.debug("Despawned npc for " + getPlayer().getName()); - } - - public void spawn(Location toSpawn) { - getNpc().spawn(toSpawn); - } - - - public void syncInventory() { - PlayerData player = getPlugin().getPlayerData(getPlayer().getUuid()); - if (getNpc().getEntity().isDead()) { - InventoryUtils.emptyInventory(player); - } else { - PlayerData npcPlayer = getPlugin().getPlayerData(getAsPlayer()); - InventoryUtils.copy(npcPlayer, player); - } - } - - public void scheduleDelayedDespawn(long delay, boolean kill) { - NPCDelayedDespawn task = new NPCDelayedDespawn(this, kill); - task.runTaskLater(Utils.getPlugin(), delay); - } - - public NPC getNpc() { - return registry.getByUUID(getNpcId()); - } - - @RequiredArgsConstructor - @AllArgsConstructor - @Getter - public static class NPCDelayedDespawn extends BukkitRunnable { - private final CombatTagNPC npc; - private boolean kill; - @Override - public void run() { - if (kill) { - getNpc().getAsPlayer().setHealth(0); - getNpc().syncInventory(); - } else { - getNpc().despawn(); - } - } - - } - - - private static EasyCache npcCache = EasyCache.makeCache(new Loader() { - - @Override - public CombatTagNPC load(UUID key) { - return new CombatTagNPC(key); - } - - }); - public static CombatTagNPC getNPC(UUID player) { - return npcCache.get(player); - } - public static CombatTagNPC createNPC(UUID player) { - if (registry.getByUUID(player) == null) { - registry.createNPC(EntityType.PLAYER, player, UUIDUtils.getName(player)); - } - return getNPC(player); - } - public static List getAllNpcs() { - List npcs = new ArrayList<>(); - for (NPC npc : registry.listNpcs()) { - npcs.add(getNPC(npc.getUUID())); - } - return npcs; - } - public static boolean isNPC(Entity entity) { - return registry.isNPC(entity); - } -} diff --git a/src/main/java/techcable/minecraft/combattag/entity/CombatTagPlayer.java b/src/main/java/techcable/minecraft/combattag/entity/CombatTagPlayer.java deleted file mode 100644 index eab6c35..0000000 --- a/src/main/java/techcable/minecraft/combattag/entity/CombatTagPlayer.java +++ /dev/null @@ -1,87 +0,0 @@ -package techcable.minecraft.combattag.entity; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -import com.google.common.base.Preconditions; -import com.trc202.CombatTag.CombatTag; - -import techcable.minecraft.combattag.CombatTagAPI; -import techcable.minecraft.combattag.PluginCompatibility; -import techcable.minecraft.combattag.Utils; -import techcable.minecraft.techutils.entity.TechPlayer; -import techcable.minecraft.techutils.utils.EasyCache; -import techcable.minecraft.techutils.utils.EasyCache.Loader; - -import lombok.*; - -@Getter -public class CombatTagPlayer extends TechPlayer { - private long remainingTagTime; - public CombatTagPlayer(UUID player, CombatTag plugin) { - super(player, plugin); - } - - public CombatTag getPlugin() { - return (CombatTag) super.getPlugin(); - } - - @Setter - private CombatTagNPC npc; - - public boolean isTagged() { - return CombatTagAPI.isTagged(getUuid()); - } - - public void untag() { - CombatTagAPI.setTagged(getUuid(), false); - } - - public void copyToNPC() { - Preconditions.checkState(hasNPC(), "Doesn't have npc"); - copyTo(getNpc().getAsPlayer()); - } - - public void copyFromNPC() { - Preconditions.checkState(hasNPC(), "Doesn't have npc"); - copyFrom(getNpc().getAsPlayer()); - } - - public void tag() { - CombatTagAPI.setTagged(getUuid(), true); - } - - public long getTagTime() { - return CombatTagAPI.getRemainingTagTime(this.getUuid()); - } - - public boolean hasNPC() { - return npc != null; - } - - public static CombatTagPlayer getPlayer(UUID id) { - return Utils.getPlugin().getPlayer(id); - } - public static CombatTagPlayer getPlayer(OfflinePlayer player) { - return getPlayer(player.getUniqueId()); - } - - public void createNPC() { - CombatTagNPC npc = CombatTagNPC.createNPC(getUuid()); - this.npc = npc; - } - - public boolean isDisguised() { - return PluginCompatibility.isDisguised(getPlayer()); - } - - public void unDisguise() { - PluginCompatibility.unDisguise(getPlayer()); - } -} diff --git a/src/main/java/techcable/minecraft/combattag/entity/package-info.java b/src/main/java/techcable/minecraft/combattag/entity/package-info.java deleted file mode 100644 index f5abb52..0000000 --- a/src/main/java/techcable/minecraft/combattag/entity/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * @author Nicholas Schlabach - * - */ -package techcable.minecraft.combattag.entity; \ No newline at end of file diff --git a/src/main/java/techcable/minecraft/combattag/event/CombatTagByPlayerEvent.java b/src/main/java/techcable/minecraft/combattag/event/CombatTagByPlayerEvent.java deleted file mode 100644 index 5a3846a..0000000 --- a/src/main/java/techcable/minecraft/combattag/event/CombatTagByPlayerEvent.java +++ /dev/null @@ -1,25 +0,0 @@ -package techcable.minecraft.combattag.event; - -import org.bukkit.entity.Player; - -import techcable.minecraft.combattag.entity.CombatTagPlayer; - -import lombok.*; - -@Getter -public class CombatTagByPlayerEvent extends CombatTagEvent { - @Setter - private boolean tagAttacker = true; - public CombatTagByPlayerEvent(CombatTagPlayer defender, Player attacker) { - super(defender, attacker); - } - - @Override - public Player getAttacker() { - return (Player) super.getAttacker(); - } - - public CombatTagPlayer getCTAttacker() { - return CombatTagPlayer.getPlayer(getAttacker()); - } -} diff --git a/src/main/java/techcable/minecraft/combattag/event/CombatTagEvent.java b/src/main/java/techcable/minecraft/combattag/event/CombatTagEvent.java deleted file mode 100644 index a7eaa78..0000000 --- a/src/main/java/techcable/minecraft/combattag/event/CombatTagEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package techcable.minecraft.combattag.event; - -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -import techcable.minecraft.combattag.entity.CombatTagPlayer; - -import lombok.*; - -@Getter -@RequiredArgsConstructor -public class CombatTagEvent extends Event implements Cancellable { - private final CombatTagPlayer defender; - private final LivingEntity attacker; - @Setter - private boolean tagDefender = true; - @Getter - private static final HandlerList handlerList = new HandlerList(); - @Setter - private boolean cancelled; - @Override - public HandlerList getHandlers() { - return getHandlerList(); - } -} diff --git a/src/main/java/techcable/minecraft/combattag/listeners/CompatibilityListener.java b/src/main/java/techcable/minecraft/combattag/listeners/CompatibilityListener.java deleted file mode 100644 index 469a516..0000000 --- a/src/main/java/techcable/minecraft/combattag/listeners/CompatibilityListener.java +++ /dev/null @@ -1,29 +0,0 @@ -package techcable.minecraft.combattag.listeners; - -import com.trc202.settings.Settings; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.entity.Player; -import org.bukkit.entity.Entity; - -import techcable.minecraft.combattag.event.CombatTagByPlayerEvent; -import techcable.minecraft.combattag.event.CombatTagEvent; -import techcable.minecraft.combattag.Utils; -import techcable.minecraft.combattag.PluginCompatibility; - -public class CompatibilityListener implements Listener { - @EventHandler - public void onCombatTag(CombatTagEvent event) { - if (event.getDefender().isDisguised() && getSettings().isDisableDisguisesInCombat()) event.getDefender().unDisguise(); - } - @EventHandler - public void onCombatTagByPlayer(CombatTagByPlayerEvent event) { - if (event.getCTAttacker().isDisguised() && getSettings().isDisableDisguisesInCombat()) event.getCTAttacker().unDisguise(); - } - - public Settings getSettings() { - return Utils.getPlugin().settings; - } -} diff --git a/src/main/java/techcable/minecraft/combattag/listeners/InstakillListener.java b/src/main/java/techcable/minecraft/combattag/listeners/InstakillListener.java deleted file mode 100644 index 964c909..0000000 --- a/src/main/java/techcable/minecraft/combattag/listeners/InstakillListener.java +++ /dev/null @@ -1,21 +0,0 @@ -package techcable.minecraft.combattag.listeners; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; - -import techcable.minecraft.combattag.Utils; -import techcable.minecraft.combattag.entity.CombatTagPlayer; -import techcable.minecraft.combattag.event.CombatLogEvent; - -import lombok.*; - -public class InstakillListener implements Listener { - @EventHandler(priority=EventPriority.MONITOR) - public void onCombatLog(CombatLogEvent event) { - CombatTagPlayer player = event.getPlayer(); - player.getPlayer().damage(1000); - player.untag(); - Utils.debug(player.getName() + " has been instakilled."); - } -} diff --git a/src/main/java/techcable/minecraft/combattag/listeners/NPCListener.java b/src/main/java/techcable/minecraft/combattag/listeners/NPCListener.java deleted file mode 100644 index 4de6149..0000000 --- a/src/main/java/techcable/minecraft/combattag/listeners/NPCListener.java +++ /dev/null @@ -1,39 +0,0 @@ -package techcable.minecraft.combattag.listeners; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -import com.trc202.settings.Settings; - -import techcable.minecraft.combattag.Utils; -import techcable.minecraft.combattag.entity.CombatTagNPC; -import techcable.minecraft.combattag.entity.CombatTagPlayer; -import techcable.minecraft.combattag.event.CombatLogEvent; - -import lombok.*; - -public class NPCListener implements Listener { - @EventHandler - public void onCombatLog(CombatLogEvent event) { - CombatTagPlayer player = event.getPlayer(); - player.createNPC(); - player.getNpc().spawn(player.getLocation()); - player.copyToNPC(); - if (getSettings().getNpcDespawnTime() > 0) { - player.getNpc().scheduleDelayedDespawn(getSettings().getNpcDespawnTime() * 1000, getSettings().isNpcDieAfterTime()); - } - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - CombatTagPlayer player = CombatTagPlayer.getPlayer(event.getPlayer()); - if (!player.hasNPC()) return; //Player didn't combat log - player.getNpc().syncInventory(); //Get the npcs stuff - player.getNpc().despawn(); - } - - public static Settings getSettings() { - return Utils.getPlugin().settings; - } -} diff --git a/src/main/java/techcable/minecraft/combattag/listeners/PermissionListener.java b/src/main/java/techcable/minecraft/combattag/listeners/PermissionListener.java deleted file mode 100644 index 6db6e90..0000000 --- a/src/main/java/techcable/minecraft/combattag/listeners/PermissionListener.java +++ /dev/null @@ -1,31 +0,0 @@ -package techcable.minecraft.combattag.listeners; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -import techcable.minecraft.combattag.event.CombatLogEvent; -import techcable.minecraft.combattag.event.CombatTagByPlayerEvent; -import techcable.minecraft.combattag.event.CombatTagEvent; - -public class PermissionListener implements Listener { - public static String DONT_COMBAT_LOG_PERM = "combattag.ignore.pvplog"; - public static String DONT_COMBAT_TAG_PERM = "combattag.ignore"; - @EventHandler - public void onCombatLog(CombatLogEvent event) { - if (event.getPlayer().getPlayer().hasPermission(DONT_COMBAT_LOG_PERM)) { - event.setCancelled(true); - } - } - @EventHandler - public void onCombatTag(CombatTagEvent event) { - if (event.getDefender().getPlayer().hasPermission(DONT_COMBAT_TAG_PERM)) { - event.setTagDefender(false); - } - } - @EventHandler - public void onCombatTagByPlayer(CombatTagByPlayerEvent event) { - if (event.getAttacker().hasPermission(DONT_COMBAT_TAG_PERM)) { - event.setTagAttacker(false); - } - } -} diff --git a/src/main/java/techcable/minecraft/combattag/listeners/PlayerListener.java b/src/main/java/techcable/minecraft/combattag/listeners/PlayerListener.java deleted file mode 100644 index 0e8e949..0000000 --- a/src/main/java/techcable/minecraft/combattag/listeners/PlayerListener.java +++ /dev/null @@ -1,86 +0,0 @@ -package techcable.minecraft.combattag.listeners; - -import java.util.Set; -import java.util.UUID; - -import javax.persistence.EntityListeners; - -import org.bukkit.Bukkit; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.util.Vector; - -import com.google.common.collect.Sets; -import com.trc202.CombatTag.CombatTag; - -import techcable.minecraft.combattag.CombatTagAPI; -import techcable.minecraft.combattag.PluginCompatibility; -import techcable.minecraft.combattag.Utils; -import static techcable.minecraft.combattag.Utils.getPlugin; -import techcable.minecraft.combattag.entity.CombatTagPlayer; -import techcable.minecraft.combattag.event.CombatLogEvent; -import techcable.minecraft.combattag.event.CombatTagByPlayerEvent; -import techcable.minecraft.combattag.event.CombatTagEvent; - -public class PlayerListener implements Listener { - public static final double KNOCKBACK_POWER = 1.5; - - /* - * Highly buggy - * - @EventHandler - public void onMove(PlayerMoveEvent event) { - if (!Utils.getPlugin().settings.isStopCombatSafezoning()) return; - if (event.getPlayer().hasPermission("combattag.safezone.ignore")); - if (!Utils.getPlugin().inTagged(event.getPlayer().getUniqueId())) return; - if (PluginCompatibility.isPvpDisabled(event.getTo())) { - knockback(event.getPlayer()); - event.getPlayer().sendMessage("[CombatTag] You can't enter a safezone while combat tagged"); - } - } - */ - public static void knockback(Player player) { - if (getPlugin().getPlayer(player).isOnline()) { - getPlugin().getPlayer(player).knockback(KNOCKBACK_POWER); - } - } - @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) - public void onDamage(EntityDamageByEntityEvent event) { - if (!(event.getEntity() instanceof Player)) return; //Not a player - if (CombatTagAPI.isNPC(event.getEntity())) return; - CombatTagPlayer defender = getPlugin().getPlayer(((Player)event.getEntity()).getUniqueId()); - LivingEntity attacker = Utils.getRootDamager(event.getDamager()); - if (attacker == null) return; - if (attacker instanceof Player) { - CombatTagByPlayerEvent tagEvent = new CombatTagByPlayerEvent(defender, (Player)attacker); - if (tagEvent.getDefender().isTagged() && tagEvent.getCTAttacker().isTagged()) return; - Utils.fire(tagEvent); - if (tagEvent.isCancelled()) return; - if (tagEvent.isTagDefender()) defender.tag(); - if (tagEvent.isTagAttacker()) tagEvent.getCTAttacker().tag(); - } else { - if (!Utils.getPlugin().settings.mobTag()) return; - CombatTagEvent tagEvent = new CombatTagEvent(defender, attacker); - if (defender.isTagged()) return; - Utils.fire(tagEvent); - if (tagEvent.isCancelled()) return; - if (tagEvent.isTagDefender()) defender.tag(); - } - } - @EventHandler(priority=EventPriority.MONITOR) - public void onQuit(PlayerQuitEvent event) { - if (CombatTagAPI.isNPC(event.getPlayer())) return; //Don't combat log npcs - CombatTagPlayer player = getPlugin().getPlayer(event.getPlayer().getUniqueId()); - if (player.isTagged()) { - Utils.fire(new CombatLogEvent(player)); - } - } -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1abef5f..fea0bdf 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,8 +1,8 @@ name: CombatTagReloaded -version: 1.0.12-SNAPSHOT +version: 1.0.13-SNAPSHOT authors: [cheddar262, Techcable] softdepend: [Citizens, WorldGuard, Factions] -main: com.trc202.CombatTag.CombatTag +main: net.techcable.combattag.CombatTag dev-url: http://dev.bukkit.org/server-mods/combat-tag commands: CombatTag: