From c42ad5e706b54b7c8d41d1c31080949af3279e3c Mon Sep 17 00:00:00 2001 From: marcocorriero Date: Mon, 13 Nov 2017 18:48:02 +0100 Subject: [PATCH] Adds PVP monitoring Resolves God PVPing Creative PVPing Both PVPing. --- .../totalfreedommod/PvpMonitor.java | 336 ++++++++++++++++++ .../totalfreedommod/TotalFreedomMod.java | 3 + 2 files changed, 339 insertions(+) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/PvpMonitor.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/PvpMonitor.java b/src/main/java/me/totalfreedom/totalfreedommod/PvpMonitor.java new file mode 100644 index 00000000..a0270177 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/PvpMonitor.java @@ -0,0 +1,336 @@ +package me.totalfreedom.totalfreedommod; + +import me.totalfreedom.totalfreedommod.banning.Ban; +import me.totalfreedom.totalfreedommod.command.Command_smite; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.projectiles.ProjectileSource; +import java.util.ArrayList; +import java.util.HashMap; + + +public class PvpMonitor extends FreedomService { + + HashMap Hassmited = new HashMap<>(); + HashMap WarningLevel = new HashMap<>(); + HashMap Hits = new HashMap<>(); // THIS IS THE SAME! + ArrayList First = new ArrayList<>(); + ArrayList Clock = new ArrayList<>(); + ArrayList Clock2 = new ArrayList<>(); + ArrayList hitsclock = new ArrayList<>(); + + public PvpMonitor(TotalFreedomMod plugin) { + super(plugin); + } + + @Override + protected void onStart() { + for (Player p : server.getOnlinePlayers()) { + WarningLevel.put(p, 0); + Hits.put(p, 0); + Hassmited.put(p,false); + } + timer(); + timer2(); + } + + @Override + protected void onStop() { + First.clear(); + WarningLevel.clear(); + hitsclock.clear(); + Clock.clear(); + Clock2.clear(); + Hits.clear(); + Hassmited.clear(); + } + + @EventHandler(priority = EventPriority.LOW) + + + public void hit(final EntityDamageByEntityEvent event) { + Entity damager = event.getDamager(); + Entity entity = event.getEntity(); + + if (damager instanceof Player && entity instanceof Player) { + final Player player = (Player) damager; + + + if (plugin.al.isAdmin((player))) { + return; + } + + if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + Clock.add(player); + Hits.put(player, Hits.get(player) + 1); + event.setCancelled(true); + + } + + + if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + Clock.add(player); + Hits.put(player, Hits.get(player) + 1); + event.setCancelled(true); + } + + + if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + Clock.add(player); + Hits.put(player, Hits.get(player) + 1); + event.setCancelled(true); + } + + if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + Clock.add(player); + Hits.put(player, Hits.get(player) + 1); + event.setCancelled(true); + + } + + + if (Hits.get(player) == 4) { + WarningLevel.put(player, WarningLevel.get(player) + 1); + Hits.put(player, 0); + + } + + + if (WarningLevel.get(player) == 1) { + if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + player.sendMessage(ChatColor.GREEN + "Hey! you need to turn off your god mode and set your gamemode to survival!"); + + } else if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + player.sendMessage(ChatColor.GREEN + "Hey! you need to set your gamemode to survival!"); + + } else if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + player.sendMessage(ChatColor.GREEN + "Hey! you need to set your godmode off!!"); + + } else if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + player.sendMessage(ChatColor.GREEN + "Hey! you need to set your godmode off!!"); + + } + } + + if (WarningLevel.get(player) > 3) { + if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + player.sendMessage(ChatColor.RED + "Hey! you need to turn off your god mode and set your gamemode to survival!"); + + } else if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + player.sendMessage(ChatColor.RED + "Hey! you need to set your gamemode to survival!"); + + } else if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + player.sendMessage(ChatColor.RED + "Hey! you need to set your godmode off!!"); + + } else if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + player.sendMessage(ChatColor.RED + "Hey! you need to set your godmode off!!"); + + } + } + + if (WarningLevel.get(player) == 6 && !(WarningLevel.get(player) == 7)) { + if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + if (Hassmited.get(player) == false) + { + Command_smite.smite(player, "Constantly trying to pvp with creative and god mode."); + Hassmited.put(player, true); + } + } else if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + if (Hassmited.get(player) == false) + { + Command_smite.smite(player, "Constantly trying to pvp with creative!"); + Hassmited.put(player, true); + } + } else if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + if (Hassmited.get(player) == false) + { + Command_smite.smite(player, "Constantly trying to pvp with god mode!"); + Hassmited.put(player, true); + } + } else if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + if (Hassmited.get(player) == false) + { + Command_smite.smite(player, "Constantly trying to pvp with god mode!"); + Hassmited.put(player, true); + } + } + return; + } + + if (WarningLevel.get(player) > 7) { + if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + player.sendMessage(ChatColor.RED + "Hey! you need to turn off your god mode and set your gamemode to survival! , some more warnings and you will get a 5m ban!"); + + } else if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + player.sendMessage(ChatColor.RED + "Hey! you need to set your gamemode to survival! , some more warnings and you will get a 5m ban!"); + + } else if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + player.sendMessage(ChatColor.RED + "Hey! you need to set your godmode off!! , some more warnings and you will get a 5m ban!"); + + } else if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + player.sendMessage(ChatColor.RED + "Hey! you need to set your godmode off!! , some more warnings and you will get a 5m ban!"); + + } + } + + + if (WarningLevel.get(player) > 9) { + if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + plugin.bm.addBan(Ban.forPlayer(player, server.getConsoleSender(), FUtil.parseDateOffset("5m"), "Keeping God and creative PVPing after you got warned multiple times!")); + FUtil.bcastMsg(player.getName() + "has been banned for constantly creative and god pvping (5m ban)", ChatColor.RED); + WarningLevel.put(player, 0); + player.kickPlayer("§cBanned for 5m"); + Hassmited.put(player,false); + } else if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + plugin.bm.addBan(Ban.forPlayer(player, server.getConsoleSender(), FUtil.parseDateOffset("5m"), "Keeping Creative PVPing after you got warned multiple times!")); + FUtil.bcastMsg(player.getName() + "has been banned for constantly creative pvping (5m ban)", ChatColor.RED); + WarningLevel.put(player, 0); + player.kickPlayer("§cBanned for 5m"); + Hassmited.put(player,false); + } else if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + plugin.bm.addBan(Ban.forPlayer(player, server.getConsoleSender(), FUtil.parseDateOffset("5m"), "Keeping God PVPing after you got warned multiple times!")); + FUtil.bcastMsg(player.getName() + "has been banned for constantly god pvping (5m ban)", ChatColor.RED); + WarningLevel.put(player, 0); + Hassmited.put(player,false); + player.kickPlayer("§cBanned for 5m"); + } else if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + plugin.bm.addBan(Ban.forPlayer(player, server.getConsoleSender(), FUtil.parseDateOffset("5m"), "Keeping God PVPing after you got warned multiple times!")); + FUtil.bcastMsg(player.getName() + "has been banned for constantly god pvping (5m ban)", ChatColor.RED); + WarningLevel.put(player, 0); + Hassmited.put(player,false); + player.kickPlayer("§cBanned for 5m"); + } + } + + + if (WarningLevel.get(player) >= 1) { + if (Clock.contains(player)) { + Clock2.add(player); + } + if (Hits.get(player) >= 1) { + if (hitsclock.contains(player)) { + hitsclock.add(player); + } + } + } + } + + + if (damager instanceof Projectile && entity instanceof Player) { + + ProjectileSource ps = ((Projectile) damager).getShooter(); + + Player player = (Player) ps; + + + if (plugin.al.isAdmin((player))) { + return; + } + + if (player.getGameMode() == GameMode.CREATIVE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + Clock.add(player); + Hits.put(player, Hits.get(player) + 1); + event.setCancelled(true); + } + + + if (player.getGameMode() == GameMode.CREATIVE && !plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + Clock.add(player); + Hits.put(player, Hits.get(player) + 1); + event.setCancelled(true); + } + + + if (player.getGameMode() == GameMode.SURVIVAL && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + Clock.add(player); + Hits.put(player, Hits.get(player) + 1); + event.setCancelled(true); + } + + if (player.getGameMode() == GameMode.ADVENTURE && plugin.esb.getEssentialsUser(player.getName()).isGodModeEnabled()) { + Clock.add(player); + Hits.put(player, Hits.get(player) + 1); + event.setCancelled(true); + + } + + + if (Hits.get(player) == 4) { + WarningLevel.put(player, WarningLevel.get(player) + 1); + Hits.put(player, 0); + } + } + } + + + + + + + + + + + + + @EventHandler(priority = EventPriority.LOW) + public void OnjoinFirst(final PlayerJoinEvent event) { + Player p = event.getPlayer(); + if (First.contains(p) == true) { + WarningLevel.put(p, 0); + Hits.put(p, 0); + Hassmited.put(p,false); + } else { + First.add(p); + WarningLevel.put(p, 0); + Hits.put(p, 0); + Hassmited.put(p,false); + } + + } + + public void timer() { + server.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + public void run() { + for (Player player : server.getOnlinePlayers()) { + if (WarningLevel.get(player) >= 2) { + if (Clock2.contains(player)) { + return; + } + WarningLevel.put(player, 0); + Clock.remove(player); + player.sendMessage(ChatColor.GREEN + "Your warning level has been reset!"); + } + } + } + } + , 6000, 6000); + } + + public void timer2() { + server.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + public void run() { + for (Player player : server.getOnlinePlayers()) { + if (Hits.get(player) >= 1) { + if (hitsclock.contains(player)) { + return; + } + Hits.put(player, 0); + hitsclock.remove(player); + } + } + } + } + , 4000, 4000); + } +} + diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 14e9e05a..dd65b9fd 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -75,6 +75,7 @@ public class TotalFreedomMod extends AeroPlugin public AntiNuke nu; public PotionMonitorer pmn; public DropMonitor dmn; + public PvpMonitor pvp; public AntiSpam as; public PlayerList pl; public Announcer an; @@ -198,6 +199,8 @@ public class TotalFreedomMod extends AeroPlugin ae = services.registerService(AutoEject.class); dmn = services.registerService(DropMonitor.class); cmon = services.registerService(ChestMonitor.class); + pvp = services.registerService(PvpMonitor.class); + mv = services.registerService(MovementValidator.class); ew = services.registerService(EntityWiper.class);