From 723f62b8f9ef4ad54f5d50061117686174fad057 Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 20 Mar 2016 01:06:46 +0000 Subject: [PATCH] incognito fixes and loads of other fixes --- .../game/clans/clans/ClansManager.java | 56 ++++++++++++++++++- .../game/clans/clans/ban/ClansBan.java | 17 +++--- .../game/clans/clans/ban/ClansBanClient.java | 6 +- .../game/clans/clans/ban/ClansBanManager.java | 35 ++++-------- .../clans/clans/ban/ClansBanRepository.java | 51 +++++------------ .../clans/ban/commands/ClansBanCommand.java | 9 +-- .../clans/clans/regions/ClansRegions.java | 1 - .../game/clans/gameplay/safelog/SafeLog.java | 14 +---- .../nautilus/game/arcade/ArcadeManager.java | 12 ++++ 9 files changed, 109 insertions(+), 92 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index eea2823e5..d444e6d3f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -56,6 +56,7 @@ import mineplex.core.energy.Energy; import mineplex.core.explosion.Explosion; import mineplex.core.hologram.Hologram; import mineplex.core.hologram.HologramManager; +import mineplex.core.incognito.IncognitoManager; import mineplex.core.incognito.events.IncognitoStatusChangeEvent; import mineplex.core.movement.Movement; import mineplex.core.npc.NpcManager; @@ -507,7 +508,12 @@ public class ClansManager extends MiniClientPluginimplements IRelati public ClanInfo getClan(Player player) { - return _clanMemberUuidMap.get(player.getUniqueId()); + return getClan(player.getUniqueId()); + } + + public ClanInfo getClan(UUID uuid) + { + return _clanMemberUuidMap.get(uuid); } public boolean isInClan(Player player) @@ -581,6 +587,54 @@ public class ClansManager extends MiniClientPluginimplements IRelati } } + @EventHandler(priority = EventPriority.LOWEST) + public void Join(PlayerJoinEvent event) + { + if (IncognitoManager.Instance.Get(event.getPlayer()).Status) + { + event.setJoinMessage(null); + return; + } + + if (event.getJoinMessage() != null) + { + event.setJoinMessage(null); + UtilServer.broadcast(F.sys("Join", event.getPlayer().getName())); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void Quit(PlayerQuitEvent event) + { + if (IncognitoManager.Instance.Get(event.getPlayer()).Status) + { + event.setQuitMessage(null); + return; + } + + if (event.getQuitMessage() != null) + { + event.setQuitMessage(null); + UtilServer.broadcast(F.sys("Quit", event.getPlayer().getName())); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void Kick(PlayerKickEvent event) + { + if (IncognitoManager.Instance.Get(event.getPlayer()).Status) + { + event.setLeaveMessage(null); + return; + } + + if (event.getLeaveMessage() != null) + { + event.setLeaveMessage(null); + UtilServer.broadcast(F.sys("Quit", event.getPlayer().getName())); + } + } + @EventHandler public void disableEnderpeal(PlayerInteractEvent event) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBan.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBan.java index d8c4d1c1a..80af66e13 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBan.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBan.java @@ -1,6 +1,7 @@ package mineplex.game.clans.clans.ban; import java.sql.Timestamp; +import java.util.UUID; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilTime; @@ -8,18 +9,18 @@ import mineplex.core.common.util.UtilTime; public class ClansBan { private int _id; - private int _accountId; private String _reason; private String _admin; private Timestamp _banTime; private Timestamp _unbanTime; private boolean _permanent; private boolean _removed; + private UUID _uuid; - public ClansBan(int id, int accountId, String admin, String reason, Timestamp banTime, Timestamp unbanTime, boolean permanent, boolean removed) + public ClansBan(int id, UUID uuid, String admin, String reason, Timestamp banTime, Timestamp unbanTime, boolean permanent, boolean removed) { _id = id; - _accountId = accountId; + _uuid = uuid; _reason = reason; _admin = admin; _banTime = banTime; @@ -33,11 +34,6 @@ public class ClansBan return _id; } - public int getAccountId() - { - return _accountId; - } - public String getAdmin() { return _admin; @@ -89,4 +85,9 @@ public class ClansBan { return (isPermanent() || getTimeLeft() > 0) && !isRemoved(); } + + public UUID getUUID() + { + return _uuid; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanClient.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanClient.java index 57565214f..af8e5b888 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanClient.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanClient.java @@ -7,12 +7,12 @@ import mineplex.core.common.util.UtilTime; public class ClansBanClient { - public int AccountId; + public String UUID; public List Bans; - public ClansBanClient(int accountId, List bans) + public ClansBanClient(String uuid, List bans) { - AccountId = accountId; + UUID = uuid; Bans = bans; } 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 f85261d50..0b3c63045 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 @@ -4,12 +4,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result; import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; @@ -21,15 +23,11 @@ import mineplex.core.account.CoreClientManager; import mineplex.core.common.Pair; import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; -import mineplex.core.common.util.F; -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.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.game.clans.clans.ClanInfo; -import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ban.commands.ClansBanCommand; import mineplex.game.clans.clans.ban.ui.ClansBanShop; @@ -83,7 +81,7 @@ public class ClansBanManager extends MiniPlugin public void ban(ClansBanClient client, String name, String admin, long time, String reason, Callback callback) { - _repository.ban(client.AccountId, admin, time, reason, time == -1); + _repository.ban(UUID.fromString(client.UUID), admin, time, reason, time == -1); LoadClient(name, callback); } @@ -99,9 +97,9 @@ public class ClansBanManager extends MiniPlugin } @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) + public void onPlayerJoin(AsyncPlayerPreLoginEvent event) { - LoadClient(event.getPlayer().getName(), client -> { + LoadClient(event.getName(), client -> { if (client.isBanned()) { String time = UtilTime.convertString(client.getLongestBan().getTimeLeft(), 0, TimeUnit.FIT); @@ -112,20 +110,8 @@ public class ClansBanManager extends MiniPlugin String reason = C.cRedB + "You are banned from Clans for " + time + "\n" + C.cWhite + client.getLongestBan().getReason(); - event.getPlayer().kickPlayer(reason); - - ClanInfo clan = ClansManager.getInstance().getClan(event.getPlayer()); - String name = event.getPlayer().getName(); - - if (clan != null) - UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> clan.playerOffline(name), 20L); - } - else - { - if (event.getJoinMessage() == null) - return; - - UtilServer.broadcast(F.sys("Join", event.getPlayer().getName())); + event.disallow(Result.KICK_BANNED, reason); + event.setKickMessage(reason); } }); } @@ -191,6 +177,9 @@ public class ClansBanManager extends MiniPlugin public void LoadClient(final String name, Callback callback) { + if (_clients.containsKey(name)) + _clients.remove(name); + GetRepository().loadBans(name, client -> { synchronized (_lock) { @@ -231,7 +220,7 @@ public class ClansBanManager extends MiniPlugin public void unban(ClansBanClient target, ClansBan ban, String name, Callback callback) { - if (target.AccountId != ban.getAccountId()) + if (!target.UUID.equals(ban.getUUID().toString())) { return; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java index 85eb69bd4..81513e371 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java @@ -3,11 +3,13 @@ package mineplex.game.clans.clans.ban; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.account.CoreClient; import mineplex.core.common.util.Callback; +import mineplex.core.common.util.UUIDFetcher; import mineplex.core.database.MinecraftRepository; import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.column.ColumnBoolean; @@ -19,10 +21,9 @@ public class ClansBanRepository extends MinecraftRepository { private ClansBanManager _manager; - private static final String GET_LONGEST_BAN = "SELECT * FROM clanBans WHERE (NOW() < unbanTime OR permanent=1) AND accountId = ? ORDER BY permanent DESC, unbanTime DESC LIMIT 1;"; - private static final String BAN_PLAYER = "INSERT INTO clanBans (accountId, admin, reason, banTime, unbanTime, permanent, removed) VALUES (?, ?, ?, ?, ?, ?, ?);"; + private static final String BAN_PLAYER = "INSERT INTO clanBans (uuid, admin, reason, banTime, unbanTime, permanent, removed) VALUES (?, ?, ?, ?, ?, ?, ?);"; private static final String REMOVE_BAN = "UPDATE clanBans SET removed = 1 WHERE id = ?;"; - private static final String GET_ALL_BANS = "SELECT * FROM clanBans WHERE accountId = ?;"; + private static final String GET_ALL_BANS = "SELECT * FROM clanBans WHERE uuid = ?;"; public ClansBanRepository(JavaPlugin plugin, ClansBanManager manager) { @@ -31,10 +32,10 @@ public class ClansBanRepository extends MinecraftRepository _manager = manager; } - public void ban(int accountId, String admin, long time, String reason, boolean permanent) + public void ban(UUID uuid, String admin, long time, String reason, boolean permanent) { executeInsert(BAN_PLAYER, null, - new ColumnInt("accountId", accountId), + new ColumnVarChar("uuid", 36, uuid.toString()), new ColumnVarChar("admin", 16, admin), new ColumnVarChar("reason", 128, reason), new ColumnTimestamp("banTime", new Timestamp(System.currentTimeMillis())), @@ -50,6 +51,8 @@ public class ClansBanRepository extends MinecraftRepository loadClientByName(name, client -> { System.out.println("> Successfully loaded CoreClient"); + String uuid = UUIDFetcher.getUUIDOf(client.GetPlayerName()).toString(); + executeQuery(GET_ALL_BANS, resultSet -> { System.out.println("> Successfully executed query, result set object: " + resultSet); @@ -58,7 +61,7 @@ public class ClansBanRepository extends MinecraftRepository while (resultSet.next()) { int id = resultSet.getInt(1); - int accountId = resultSet.getInt(2); + String ruuid = resultSet.getString(2); String admin = resultSet.getString(3); String reason = resultSet.getString(4); Timestamp banTime = resultSet.getTimestamp(5); @@ -66,44 +69,20 @@ public class ClansBanRepository extends MinecraftRepository boolean permanent = resultSet.getBoolean(7); boolean removed = resultSet.getBoolean(8); - list.add(new ClansBan(id, accountId, admin, reason, banTime, unbanTime, permanent, removed)); + list.add(new ClansBan(id, UUID.fromString(ruuid), admin, reason, banTime, unbanTime, permanent, removed)); + + System.out.println("Got ban for " + name); } - callback.run(new ClansBanClient(client.getAccountId(), list)); + callback.run(new ClansBanClient(uuid, list)); System.out.println("> Successfully handled result"); System.out.println(">> FINISH"); - }, new ColumnInt("accountId", client.getAccountId())); + }, new ColumnVarChar("uuid", 36, uuid)); }); } - public void getLongestBan(final String name, final Callback callback) - { - if (callback == null) - { - return; - } - - loadClientByName(name, client -> { - executeQuery(GET_LONGEST_BAN, resultSet -> { - while (resultSet.next()) - { - int id = resultSet.getInt(1); - int accountId = resultSet.getInt(2); - String admin = resultSet.getString(3); - String reason = resultSet.getString(4); - Timestamp banTime = resultSet.getTimestamp(5); - Timestamp unbanTime = resultSet.getTimestamp(6); - boolean permanent = resultSet.getBoolean(7); - boolean removed = resultSet.getBoolean(8); - - callback.run(new ClansBan(id, accountId, admin, reason, banTime, unbanTime, permanent, removed)); - } - }, new ColumnInt("accountId", client.getAccountId())); - }); - } - - public void loadClientByName(String name, Callback client) + private void loadClientByName(String name, Callback client) { if (_manager.getClientManager().Contains(name)) { 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 7dd6578ff..64d766b4a 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 @@ -27,7 +27,7 @@ public class ClansBanCommand extends CommandBase { final String playerName = args[0]; - String reason = args[2]; + String reason = args[1]; for (int i = 2; i < args.length; i++) { @@ -43,10 +43,6 @@ public class ClansBanCommand extends CommandBase Plugin.LoadClient(playerName, client -> { Plugin.cache(caller, playerName, finalReason); Plugin.getShop().attemptShopOpen(caller); -// Plugin.ban(client, target.getName(), caller.getName(), permanent ? -1 : (long) (time * 24.f * 60.f * 60.f * 1000.f), finalReason, c -> { -// UtilPlayer.message(caller, F.main("Clans", F.elem(playerName) + " is now banned " + F.time(c.getBanTimeFormatted()) + ".")); -// Plugin.runSync(() -> target.kickPlayer(C.cRedB + "You have been banned from Clans " + c.getBanTimeFormatted() + ".")); -// }); }); return; @@ -55,9 +51,6 @@ public class ClansBanCommand extends CommandBase Plugin.LoadClient(playerName, client -> { Plugin.cache(caller, playerName, finalReason); Plugin.getShop().attemptShopOpen(caller); -// Plugin.ban(client, playerName, caller.getName(), permanent ? -1 : (long) (time * 24.f * 60.f * 60.f * 1000.f), finalReason, c -> { -// UtilPlayer.message(caller, F.main("Clans", F.elem(playerName) + " is now banned " + c.getBanTimeFormatted() + ".")); -// }); }); } else diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java index db1d1432f..e129da1c8 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java @@ -147,7 +147,6 @@ public class ClansRegions extends MiniPlugin // Only claim if the clan doesn't have claims. Speeds up startup time if (clan == null || clan.getClaimSet().size() == 0) { - if (clan != null) { _manager.getClanDataAccess().delete(clan, status -> { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java index 84f68d50b..8d819ff9b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java @@ -113,10 +113,7 @@ public class SafeLog extends MiniPlugin @EventHandler(priority = EventPriority.LOWEST) public void onPlayerQuit(PlayerQuitEvent event) { - if (event.getQuitMessage() != null) - event.setQuitMessage(F.sys("Quit", event.getPlayer().getName())); - - onPlayerQuit(event.getPlayer()); + onPlayerQuit(event.getPlayer()); } @EventHandler(priority = EventPriority.HIGHEST) @@ -124,9 +121,7 @@ public class SafeLog extends MiniPlugin { if (event.getPlayer().getItemInHand() != null && event.getPlayer().getItemInHand().getItemMeta() != null && (C.cGold + "Wind Blade").equals(event.getPlayer().getItemInHand().getItemMeta().getDisplayName())) if (event.getReason().contains("flying is not enabled")) - return; - - _flying.add(event.getPlayer().getName()); + _flying.add(event.getPlayer().getName()); } @EventHandler(priority = EventPriority.LOWEST) @@ -137,17 +132,12 @@ public class SafeLog extends MiniPlugin if (event.getReason().contains("flying is not enabled")) return; - if (event.getLeaveMessage() != null) - event.setLeaveMessage(F.sys("Quit", event.getPlayer().getName())); - onPlayerQuit(event.getPlayer()); } @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - event.setJoinMessage(null); - onPlayerJoin(event.getPlayer()); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 645539a52..600b7a1dd 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -694,6 +694,12 @@ public class ArcadeManager extends MiniPlugin implements IRelation { String name = event.getPlayer().getName(); + if (IncognitoManager.Instance.Get(event.getPlayer()).Status) + { + event.setJoinMessage(null); + return; + } + if (event.getJoinMessage() == null) return; @@ -707,6 +713,12 @@ public class ArcadeManager extends MiniPlugin implements IRelation @EventHandler public void MessageQuit(PlayerQuitEvent event) { + if (IncognitoManager.Instance.Get(event.getPlayer()).Status) + { + event.setQuitMessage(null); + return; + } + String name = event.getPlayer().getName(); if (event.getQuitMessage() == null)