diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanManager.java index 62e7be42a..2c22de324 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanManager.java @@ -1,23 +1,48 @@ package mineplex.game.clans.clans.ban; +import java.util.HashMap; +import java.util.UUID; + import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.donation.DonationManager; +import mineplex.core.recharge.Recharge; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ban.commands.ClansBanCommand; +import mineplex.game.clans.clans.event.ClansCommandExecutedEvent; +import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityTargetLivingEntityEvent; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; public class ClansBanManager extends MiniPlugin { + private static final long FREEZE_MESSAGE_INTERVAL = 10000; private final CoreClientManager _clientManager; private final DonationManager _donationManager; private final ClansBanRepository _repository; + private final HashMap _frozen = new HashMap<>(); public ClansBanManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager) { @@ -74,6 +99,180 @@ public class ClansBanManager extends MiniPlugin } } catch (Exception ignored) {} } + + @EventHandler(priority = EventPriority.LOWEST) + public void onQuit(PlayerQuitEvent event) + { + Float walkSpeed = _frozen.remove(event.getPlayer().getUniqueId()); + if (walkSpeed != null) + { + event.getPlayer().setWalkSpeed(walkSpeed); + for (Player staff : UtilServer.GetPlayers()) + { + if (_clientManager.hasRank(staff, Rank.HELPER)) + { + UtilPlayer.message(staff, F.main(getName(), F.elem(event.getPlayer().getName()) + " has logged out while frozen!")); + } + } + } + } + + @EventHandler + public void onMove(PlayerMoveEvent event) + { + if (isFrozen(event.getPlayer()) && UtilMath.offset2d(event.getFrom(), event.getTo()) >= 1) + { + event.setCancelled(true); + } + } + + @EventHandler + public void onDisplayFreezeMessage(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST) + { + return; + } + + for (UUID frozenUUID : _frozen.keySet()) + { + Player frozen = Bukkit.getPlayer(frozenUUID); + if (Recharge.Instance.use(frozen, "Freeze Message", FREEZE_MESSAGE_INTERVAL, false, false)) + { + String border = C.cGray + C.Strike + "-----------------------------------------------------"; + String sq = "\u2589"; + + UtilPlayer.message(frozen, border); + UtilPlayer.message(frozen, C.Reset + ""); + UtilPlayer.message(frozen, C.cWhite + sq + sq + sq + sq + C.cRed + sq + C.cWhite + sq + sq + sq + sq); + UtilPlayer.message(frozen, C.cWhite + sq + sq + sq + C.cRed + sq + C.cBlack + sq + C.cRed + sq + C.cWhite + sq + sq + sq); + UtilPlayer.message(frozen, C.cWhite + sq + sq + C.cRed + sq + C.cGold + sq + C.cBlack + sq + C.cGold + sq + C.cRed + sq + C.cWhite + sq + sq); + UtilPlayer.message(frozen, C.cWhite + sq + sq + C.cRed + sq + C.cGold + sq + C.cBlack + sq + C.cGold + sq + C.cRed + sq + C.cWhite + sq + sq); + UtilPlayer.message(frozen, C.cWhite + sq + sq + C.cRed + sq + C.cGold + sq + C.cBlack + sq + C.cGold + sq + C.cRed + sq + C.cWhite + sq + sq); + UtilPlayer.message(frozen, C.cWhite + sq + C.cRed + sq + C.cGold + sq + sq + sq + C.cGold + sq + sq + C.cRed + sq + C.cWhite + sq); + UtilPlayer.message(frozen, C.cRed + sq + C.cGold + sq + sq + sq + C.cBlack + sq + C.cGold + sq + sq + sq + C.cRed + sq); + UtilPlayer.message(frozen, C.cRed + sq + sq + sq + sq + sq + sq + sq + sq + sq); + UtilPlayer.message(frozen, C.Reset + ""); + UtilPlayer.message(frozen, C.cRed + "You have been frozen by a staff member!"); + UtilPlayer.message(frozen, C.cRed + "Do not log out or you will be banned!"); + UtilPlayer.message(frozen, C.Reset + ""); + UtilPlayer.message(frozen, border); + } + } + } + + @EventHandler + public void handleMobs(EntityTargetLivingEntityEvent event) + { + if (event.getTarget() instanceof Player) + { + Player player = (Player) event.getTarget(); + if (!isFrozen(player)) + { + return; + } + + event.setCancelled(true); + } + } + + @EventHandler + public void onDamage(CustomDamageEvent event) + { + Player damager = event.GetDamagerPlayer(event.GetCause() == DamageCause.PROJECTILE); + Player damagee = event.GetDamageePlayer(); + + if (damager != null && isFrozen(damager)) + { + event.SetCancelled("Frozen Attacker"); + UtilPlayer.message(damager, F.main(getName(), "You cannot attack others while frozen!")); + } + if (damagee != null && isFrozen(damagee)) + { + event.SetCancelled("Frozen Damagee"); + if (damager != null) + { + UtilPlayer.message(damager, F.main(getName(), "You cannot attack " + F.elem(damagee.getName()) + " while they are frozen!")); + } + } + } + + @EventHandler + public void onUseSkill(SkillTriggerEvent event) + { + if (isFrozen(event.GetPlayer())) + { + event.SetCancelled(true); + UtilPlayer.message(event.GetPlayer(), "You cannot use " + F.skill(event.GetSkillName()) + " while frozen!"); + } + } + + @EventHandler + public void onBreak(BlockBreakEvent event) + { + if (isFrozen(event.getPlayer())) + { + event.setCancelled(true); + UtilPlayer.message(event.getPlayer(), F.main(getName(), "You cannot break blocks while frozen!")); + } + } + + @EventHandler + public void onPlace(BlockPlaceEvent event) + { + if (isFrozen(event.getPlayer())) + { + event.setCancelled(true); + UtilPlayer.message(event.getPlayer(), F.main(getName(), "You cannot place blocks while frozen!")); + } + } + + @EventHandler + public void onTpHome(ClansCommandExecutedEvent event) + { + if (event.getCommand().equalsIgnoreCase("tphome")) + { + if (isFrozen(event.getPlayer())) + { + event.setCancelled(true); + UtilPlayer.message(event.getPlayer(), F.main(getName(), "You cannot teleport to your Clan home while frozen!")); + } + } + } + + public boolean isFrozen(Player player) + { + return _frozen.containsKey(player.getUniqueId()); + } + + public void freeze(Player player, Player staff) + { + _frozen.put(player.getUniqueId(), player.getWalkSpeed()); + player.setWalkSpeed(0); + for (Player alert : UtilServer.GetPlayers()) + { + if (_clientManager.hasRank(alert, Rank.HELPER)) + { + UtilPlayer.message(alert, F.main(getName(), F.elem(player.getName()) + " has been frozen by " + F.elem(staff.getName()) + "!")); + } + } + } + + public void unfreeze(Player player, Player staff) + { + Float walkSpeed = _frozen.remove(player.getUniqueId()); + if (walkSpeed != null) + { + player.setWalkSpeed(walkSpeed); + for (Player alert : UtilServer.GetPlayers()) + { + if (_clientManager.hasRank(alert, Rank.HELPER)) + { + UtilPlayer.message(alert, F.main(getName(), F.elem(player.getName()) + " has been unfrozen by " + F.elem(staff.getName()) + "!")); + } + } + } + } public void unban(ClansBanClient target, ClansBan ban, Callback callback) { @@ -87,4 +286,4 @@ public class ClansBanManager extends MiniPlugin callback.run(target); } -} +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java index 39923ea27..e43c9f130 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java @@ -22,7 +22,7 @@ public class ClansBanCommand extends CommandBase { if (args == null || args.length < 1) { - UtilPlayer.message(caller, C.cBlue + "/cb " + C.cGray + " - " + C.cYellow + "Displays the \"Clans Punish\" GUI, allowing you to ban the player, and view thier past bans."); + UtilPlayer.message(caller, C.cBlue + "/cb " + C.cGray + " - " + C.cYellow + "Displays the \"Clans Punish\" GUI, allowing you to ban the player, and view their past bans."); } else if (args.length > 1) { @@ -52,7 +52,7 @@ public class ClansBanCommand extends CommandBase } else { - UtilPlayer.message(caller, C.cBlue + "/cb " + C.cGray + " - " + C.cYellow + "Displays the \"Clans Punish\" GUI, allowing you to ban the player, and view thier past bans."); + UtilPlayer.message(caller, C.cBlue + "/cb " + C.cGray + " - " + C.cYellow + "Displays the \"Clans Punish\" GUI, allowing you to ban the player, and view their past bans."); } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/FreezeCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/FreezeCommand.java new file mode 100644 index 000000000..5b6ee7158 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/FreezeCommand.java @@ -0,0 +1,41 @@ +package mineplex.game.clans.clans.ban.commands; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.game.clans.clans.ban.ClansBanManager; + +import org.bukkit.entity.Player; + +public class FreezeCommand extends CommandBase +{ + public FreezeCommand(ClansBanManager plugin) + { + super(plugin, Rank.CMOD, "freeze"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args == null || args.length < 1) + { + UtilPlayer.message(caller, C.cBlue + "/freeze " + C.cGray + " - " + C.cYellow + "Freezes a player, restricting their movement and ability to interact with the game."); + } + else if (args.length > 0) + { + Player target = UtilPlayer.searchOnline(caller, args[0], true); + if (target == null) + { + return; + } + if (Plugin.isFrozen(target)) + { + UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(args[0]) + " is already frozen!")); + return; + } + Plugin.freeze(target, caller); + } + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/UnfreezeCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/UnfreezeCommand.java new file mode 100644 index 000000000..3494ee20c --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/UnfreezeCommand.java @@ -0,0 +1,41 @@ +package mineplex.game.clans.clans.ban.commands; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.game.clans.clans.ban.ClansBanManager; + +import org.bukkit.entity.Player; + +public class UnfreezeCommand extends CommandBase +{ + public UnfreezeCommand(ClansBanManager plugin) + { + super(plugin, Rank.CMOD, "unfreeze"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args == null || args.length < 1) + { + UtilPlayer.message(caller, C.cBlue + "/unfreeze " + C.cGray + " - " + C.cYellow + "Unfreezes a player, restoring their movement and ability to interact with the game."); + } + else if (args.length > 0) + { + Player target = UtilPlayer.searchOnline(caller, args[0], true); + if (target == null) + { + return; + } + if (!Plugin.isFrozen(target)) + { + UtilPlayer.message(caller, F.main(Plugin.getName(), F.elem(args[0]) + " is not frozen!")); + return; + } + Plugin.unfreeze(target, caller); + } + } +} \ No newline at end of file