From 76782fd4207b36821d732977367207ff5a32f5d1 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Thu, 10 Mar 2016 15:07:22 -0600 Subject: [PATCH] Fix issues --- .../core/incognito/IncognitoManager.java | 149 ++++++++++++++++++ .../clans/core/repository/ClanRepository.java | 2 +- .../repository/SiegeWeaponRepository.java | 1 - .../clans/staff/SilentChestInventory.java | 68 ++++++++ .../clans/clans/staff/SilentChestOpen.java | 49 ++++++ 5 files changed, 267 insertions(+), 2 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/staff/SilentChestInventory.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/staff/SilentChestOpen.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java b/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java new file mode 100644 index 000000000..e70469aa1 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java @@ -0,0 +1,149 @@ +package mineplex.core.incognito; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniClientPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.incognito.commands.IncognitoToggleCommand; +import mineplex.core.incognito.events.IncognitoStatusChangeEvent; +import mineplex.core.incognito.repository.IncognitoClient; +import mineplex.core.incognito.repository.IncognitoRepository; +import mineplex.core.packethandler.PacketHandler; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class IncognitoManager extends MiniClientPlugin +{ + private CoreClientManager _clientManager; + private IncognitoRepository _repository; + + public static IncognitoManager Instance; + + public IncognitoManager(JavaPlugin plugin, CoreClientManager clientManager, PacketHandler packetHandler) + { + super("Incognito", plugin); + + _repository = new IncognitoRepository(this, clientManager); + _clientManager = clientManager; + + Instance = this; + } + + public void addCommands() + { + addCommand(new IncognitoToggleCommand(this)); + } + + public boolean toggle(Player caller) + { + boolean enabled = !Get(caller).Status; + + IncognitoStatusChangeEvent event = UtilServer.CallEvent(new IncognitoStatusChangeEvent(caller, enabled)); + + if (event.isCancelled()) + { + return false; + } + + Get(caller).Status = enabled; + + runAsync(() -> _repository.SetStatus(_clientManager.getAccountId(caller), enabled)); + + return enabled; + } + + @EventHandler(priority = EventPriority.LOWEST) + public void Update(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST) + { + UtilServer.getPlayersCollection().forEach(player -> { + UtilServer.getPlayersCollection().forEach(other -> { + if (Get(other).Status && !_clientManager.hasRank(player, _clientManager.Get(other).GetRank())) + player.hidePlayer(other); + + if (Get(player).Status) + { + if (!_clientManager.hasRank(other, _clientManager.Get(player).GetRank())) + other.hidePlayer(player); + } + }); + }); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void ClientLoad(AsyncPlayerPreLoginEvent event) + { + _clientManager.getRepository().getAccountId(event.getUniqueId(), accountId -> { + Get(event.getName()).Status = _repository.GetStatus(accountId.intValue()); + }); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void Join(PlayerJoinEvent event) + { + if (Get(event.getPlayer()).Status) + { + event.setJoinMessage(null); + informIncognito(event.getPlayer()); + } + + UtilServer.getPlayersCollection().forEach(player -> { + if (Get(event.getPlayer()).Status && !_clientManager.hasRank(player, _clientManager.Get(event.getPlayer()).GetRank())) + player.hidePlayer(event.getPlayer()); + + if (Get(player).Status) + { + if (!_clientManager.hasRank(event.getPlayer(), _clientManager.Get(player).GetRank())) + event.getPlayer().hidePlayer(player); + } + }); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void Quit(PlayerQuitEvent event) + { + if (Get(event.getPlayer()).Status) + { + event.setQuitMessage(null); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void Kick(PlayerKickEvent event) + { + if (Get(event.getPlayer()).Status) + { + event.setLeaveMessage(null); + } + } + + private void informIncognito(Player player) + { + UtilPlayer.message(player, " "); + UtilPlayer.message(player, C.cGoldB + "You are currently incognito."); + UtilPlayer.message(player, C.cYellow + "This means you are invisible to all except for those who are " + _clientManager.Get(player).GetRank().getTag(true, false) + C.mBody + "+"); + UtilPlayer.message(player, " "); + } + + protected IncognitoClient AddPlayer(String player) + { + return new IncognitoClient(); + } + + public IncognitoRepository getRepository() + { + return _repository; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java index 8e1d03737..3c61794b0 100644 --- a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java @@ -46,7 +46,7 @@ public class ClanRepository extends MinecraftRepository private static String RETRIEVE_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.kills, c.murder, c.deaths, c.warWins, c.warLosses, c.generator, c.generatorStock, c.dateCreated, c.lastOnline, c.eloRating FROM clans AS c WHERE lower(c.name) = ?;"; private static String RETRIEVE_PLAYER_CLAN_INFO = "SELECT clans.name, accountClan.clanRole, clanServer.serverName, clans.id FROM accountClan INNER JOIN clans ON clans.id = accountClan.clanId INNER JOIN clanServer ON clans.serverId = clanServer.id WHERE accountClan.accountId = ?;"; - private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.kills, c.murder, c.deaths, c.warWins, c.warLosses, c.generator, c.generatorStock, c.dateCreated, c.lastOnline, c.eloRating ct.chunk, ct.safe FROM clans AS c LEFT JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE c.serverId = ? OR c.admin = 1;"; + private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.kills, c.murder, c.deaths, c.warWins, c.warLosses, c.generator, c.generatorStock, c.dateCreated, c.lastOnline, c.eloRating, ct.chunk, ct.safe FROM clans AS c LEFT JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE c.serverId = ? OR c.admin = 1;"; private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT c.name, a.name, a.uuid, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE c.serverId = ?;"; private static String RETRIEVE_CLAN_MEMBERS = "SELECT c.name, a.name, a.uuid, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE lower(c.name) = ?;"; private static String RETRIEVE_CLAN_ALLIANCE_INFO = "SELECT c.name, cOther.name, ca.trusted FROM clanAlliances AS ca INNER JOIN clans AS c ON c.id = ca.clanId INNER JOIN clans as cOther ON cOther.id = ca.otherClanId WHERE c.serverId = ?;"; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java index 5e568fdaa..a7d0ab3cb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java @@ -140,7 +140,6 @@ public class SiegeWeaponRepository extends MinecraftRepository protected void initialize() { executeUpdate(CREATE); - executeUpdate("ALTER TABLE `Account`.`clans` ADD COLUMN `eloRating` INT(11) NOT NULL DEFAULT '1200' AFTER `generatorStock`;"); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/staff/SilentChestInventory.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/staff/SilentChestInventory.java new file mode 100644 index 000000000..b669e7b96 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/staff/SilentChestInventory.java @@ -0,0 +1,68 @@ +package mineplex.game.clans.clans.staff; + +import org.bukkit.Bukkit; +import org.bukkit.block.Chest; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.UtilCollections; +import mineplex.core.common.util.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class SilentChestInventory implements Listener +{ + private Chest _chest; + private Inventory _inventory; + + private Player _viewer; + + public SilentChestInventory(Chest chest, Player viewer) + { + _chest = chest; + + _inventory = Bukkit.createInventory(null, 54, "Chest"); + + viewer.openInventory(_inventory); + + UtilServer.RegisterEvents(this); + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + if (!UtilCollections.equal(_chest.getBlockInventory().getContents(), _inventory.getContents())) + { + _inventory.setContents(_chest.getBlockInventory().getContents()); + } + } + + @EventHandler + public void inventoryClick(InventoryClickEvent event) + { + if (event.getClickedInventory().equals(_inventory) && event.getWhoClicked().equals(_viewer)) + { + _chest.getBlockInventory().setContents(_inventory.getContents()); + } + } + + @EventHandler + public void closeInventory(InventoryCloseEvent event) + { + if (event.getInventory().equals(_inventory) && event.getPlayer().equals(_viewer)) + { + UtilServer.Unregister(this); + } + } + +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/staff/SilentChestOpen.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/staff/SilentChestOpen.java new file mode 100644 index 000000000..c3fe7119d --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/staff/SilentChestOpen.java @@ -0,0 +1,49 @@ +package mineplex.game.clans.clans.staff; + +import org.bukkit.block.BlockState; +import org.bukkit.block.Chest; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEvent; + +import mineplex.core.MiniPlugin; +import mineplex.core.common.Rank; +import mineplex.core.common.util.UtilServer; +import mineplex.core.incognito.IncognitoManager; +import mineplex.game.clans.clans.ClansManager; + +public class SilentChestOpen extends MiniPlugin +{ + private ClansManager _clansManager; + + public SilentChestOpen(ClansManager clansManager) + { + super("Silent Chest", clansManager.getPlugin()); + + _clansManager = clansManager; + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) + { + if (!IncognitoManager.Instance.Get(event.getPlayer()).Status) + return; + + if (!ClansManager.getInstance().getClientManager().hasRank(event.getPlayer(), Rank.CMOD)) + return; + + if (event.getClickedBlock() == null) + return; + + BlockState block = event.getClickedBlock().getState(); + + if (!(block instanceof Chest)) + return; + + Chest chest = (Chest) block; + + UtilServer.RegisterEvents(new SilentChestInventory(chest, event.getPlayer())); + + event.setCancelled(true); + + } +} \ No newline at end of file