From 1726aa253063ba2bd863f5e0630041f5cb1ccfdc Mon Sep 17 00:00:00 2001 From: Morten Date: Mon, 21 Dec 2015 12:58:19 +0100 Subject: [PATCH 1/4] Added a feature to unban clients across the network But there still a bug when you type a username of a none registered member. Will fix ASAP - likely after Mineware --- .../src/mineplex/core/stats/StatsManager.java | 90 ++++++++++++++++++- .../mineplex/core/stats/StatsRepository.java | 27 +++++- .../stats/command/MasterBuilderUnban.java | 58 ++++++++++++ 3 files changed, 168 insertions(+), 7 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/stats/command/MasterBuilderUnban.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java index 1aa921c2d..ae88b6cb1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java @@ -15,6 +15,7 @@ import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilServer; import mineplex.core.stats.command.GiveStatCommand; +import mineplex.core.stats.command.MasterBuilderUnban; import mineplex.core.stats.command.TimeCommand; import mineplex.core.stats.event.StatChangeEvent; @@ -26,6 +27,8 @@ public class StatsManager extends MiniDbClientPlugin private NautHashMap _stats = new NautHashMap(); private NautHashMap> _statUploadQueue = new NautHashMap>(); + private NautHashMap> _statUploadQueueOverRidable = new NautHashMap>(); + private Runnable _saveRunnable; public StatsManager(JavaPlugin plugin, CoreClientManager clientManager) @@ -41,6 +44,7 @@ public class StatsManager extends MiniDbClientPlugin public void run() { saveStats(); + overRidableSaveStats(); } }; @@ -81,6 +85,11 @@ public class StatsManager extends MiniDbClientPlugin } public void incrementStat(final Player player, final String statName, final long value) + { + incrementStat(player, statName, value, false); + } + + public void incrementStat(final Player player, final String statName, final long value, boolean overRide) { if (value <= 0) return; @@ -96,11 +105,80 @@ public class StatsManager extends MiniDbClientPlugin @Override public void run() { - addToQueue(statName, player, value); + if(overRide) + { + addToOverRidableQueue(statName, player, value); + } + else + { + addToQueue(statName, player, value); + } } }); } + private void addToOverRidableQueue(String statName, Player player, long value) + { + synchronized (_statSync) + { + if (!_statUploadQueueOverRidable.containsKey(player)) + _statUploadQueueOverRidable.put(player, new NautHashMap()); + + if (!_statUploadQueueOverRidable.get(player).containsKey(statName)) + _statUploadQueueOverRidable.get(player).put(statName, 0L); + + _statUploadQueueOverRidable.get(player).put(statName, _statUploadQueueOverRidable.get(player).get(statName) + value); + } + } + + protected void overRidableSaveStats() + { + if (_statUploadQueueOverRidable.isEmpty()) + return; + + try + { + NautHashMap> uploadQueue = new NautHashMap>(); + + synchronized (_statSync) + { + for (Iterator statIterator = _statUploadQueueOverRidable.keySet().iterator(); statIterator.hasNext();) + { + Player player = statIterator.next(); + + if (player.isOnline()) + continue; + + try + { + int uploadKey = PlayerCache.getInstance().getPlayer(player.getUniqueId()).getAccountId(); + + uploadQueue.put(uploadKey, new NautHashMap()); + + for (String statName : _statUploadQueueOverRidable.get(player).keySet()) + { + int statId = _stats.get(statName); + uploadQueue.get(uploadKey).put(statId, _statUploadQueueOverRidable.get(player).get(statName)); + System.out.println(player.getName() + " saving stat : " + statName + " overriding " + _statUploadQueueOverRidable.get(player).get(statName)); + } + + statIterator.remove(); + } + catch (Exception e) + { + //System.out.println("[StatsManager] AccountId was not set for " + player.getName()); + } + } + } + + _repository.saveStats(uploadQueue, true); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + } + private void addToQueue(String statName, Player player, long value) { synchronized (_statSync) @@ -162,8 +240,13 @@ public class StatsManager extends MiniDbClientPlugin exception.printStackTrace(); } } - + public boolean incrementStat(final int accountId, final String statName, final long value) + { + return incrementStat(accountId, statName, value, false); + } + + public boolean incrementStat(final int accountId, final String statName, final long value, boolean overRide) { // This will register a new stat if we don't have one, otherwise it will just run the callback registerNewStat(statName, new Runnable() @@ -175,7 +258,7 @@ public class StatsManager extends MiniDbClientPlugin uploadQueue.put(accountId, new NautHashMap()); uploadQueue.get(accountId).put(_stats.get(statName), value); - _repository.saveStats(uploadQueue); + _repository.saveStats(uploadQueue, overRide); } }); @@ -237,6 +320,7 @@ public class StatsManager extends MiniDbClientPlugin { addCommand(new TimeCommand(this)); addCommand(new GiveStatCommand(this)); + addCommand(new MasterBuilderUnban(this)); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java index 12deca990..726f75a99 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java @@ -29,6 +29,8 @@ public class StatsRepository extends RepositoryBase { private static String RETRIEVE_STATS = "SELECT id, name FROM stats;"; private static String INSERT_STAT = "INSERT INTO stats (name) VALUES (?);"; + private static String UPDATE_ACCOUNT_STAT_VALUE= "UPDATE accounts SET rank=?, rankPerm=true WHERE uuid = ?;"; + public StatsRepository(JavaPlugin plugin) { @@ -68,9 +70,15 @@ public class StatsRepository extends RepositoryBase { executeUpdate(INSERT_STAT, new ColumnVarChar("name", 100, name)); } + + public void saveStats(NautHashMap> uploadQueue) + { + saveStats(uploadQueue, false); + } + @SuppressWarnings("rawtypes") - public void saveStats(NautHashMap> uploadQueue) + public void saveStats(NautHashMap> uploadQueue, boolean overRideStat) { try { @@ -83,13 +91,24 @@ public class StatsRepository extends RepositoryBase { for (Integer statId : uploadQueue.get(accountId).keySet()) { - Update update = context + if(overRideStat) + { + Update update = context + .update(Tables.accountStat) + .set(Tables.accountStat.value, ULong.valueOf(uploadQueue.get(accountId).get(statId))) + .where(Tables.accountStat.accountId.eq(accountId)) + .and(Tables.accountStat.statId.eq(statId)); + updates.add(update); + } + else + { + Update update = context .update(Tables.accountStat) .set(Tables.accountStat.value, Tables.accountStat.value.plus(uploadQueue.get(accountId).get(statId))) .where(Tables.accountStat.accountId.eq(accountId)) .and(Tables.accountStat.statId.eq(statId)); - - updates.add(update); + updates.add(update); + } Insert insert = context .insertInto(Tables.accountStat) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/command/MasterBuilderUnban.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/command/MasterBuilderUnban.java new file mode 100644 index 000000000..9ec2656c0 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/command/MasterBuilderUnban.java @@ -0,0 +1,58 @@ +package mineplex.core.stats.command; + +import mineplex.core.account.CoreClient; +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.stats.StatsManager; + +import org.bukkit.entity.Player; + +public class MasterBuilderUnban extends CommandBase +{ + + public MasterBuilderUnban(StatsManager plugin) + { + super(plugin, Rank.ADMIN, "buildunban"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if(args.length != 1) + { + UtilPlayer.message(caller, F.main("MasterBuilder Unban", "/buildunban ")); + return; + } + + try + { + Plugin.getClientManager().loadClientByName(args[0], new Runnable() + { + + @Override + public void run() + { + CoreClient theClient = Plugin.getClientManager().Get(args[0]); + + if(theClient != null) + { + Plugin.incrementStat(theClient.getAccountId(), "Global.Build Draw Abuse", 0, true); + caller.sendMessage(F.main("MasterBuilder Unban", "The user " + args[0] + " has been unbanned for Master Builders")); + } + else + { + caller.sendMessage(F.main("MasterBuilder Unban", "Couldn't find " + args[0] + "'s account!")); + return; + } + } + }); + } + catch(Exception e) + { + caller.sendMessage(F.main("MasterBuilder Unban", "Exception caught! Please contact Morten and explain what happened.")); + } + } + +} From 9336eb19fa5fcf450c1831300d816a0ee57e60bf Mon Sep 17 00:00:00 2001 From: Morten Date: Tue, 22 Dec 2015 21:31:57 +0100 Subject: [PATCH 2/4] Finished up the Unban feature... --- .../stats/command/MasterBuilderUnban.java | 70 +++++++++++++++---- .../password/PasswordRepository.java | 2 +- 2 files changed, 59 insertions(+), 13 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/command/MasterBuilderUnban.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/command/MasterBuilderUnban.java index 9ec2656c0..a8075985a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/command/MasterBuilderUnban.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/command/MasterBuilderUnban.java @@ -1,8 +1,12 @@ package mineplex.core.stats.command; +import java.util.Iterator; +import java.util.List; + import mineplex.core.account.CoreClient; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; +import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.stats.StatsManager; @@ -28,29 +32,71 @@ public class MasterBuilderUnban extends CommandBase try { - Plugin.getClientManager().loadClientByName(args[0], new Runnable() + Plugin.getClientManager().getRepository().matchPlayerName(new Callback>() { - + @Override - public void run() + public void run(List matches) { - CoreClient theClient = Plugin.getClientManager().Get(args[0]); - - if(theClient != null) + boolean matchedExact = false; + + for (String match : matches) { - Plugin.incrementStat(theClient.getAccountId(), "Global.Build Draw Abuse", 0, true); - caller.sendMessage(F.main("MasterBuilder Unban", "The user " + args[0] + " has been unbanned for Master Builders")); + if (match.equalsIgnoreCase(args[0])) + { + matchedExact = true; + } } - else + + if (matchedExact) { - caller.sendMessage(F.main("MasterBuilder Unban", "Couldn't find " + args[0] + "'s account!")); - return; + for (Iterator matchIterator = matches.iterator(); matchIterator.hasNext();) + { + if (!matchIterator.next().equalsIgnoreCase(args[0])) + { + matchIterator.remove(); + } + } } + UtilPlayer.searchOffline(matches, new Callback() + { + @Override + public void run(String target) + { + if(target == null) + { + caller.sendMessage(F.main("MasterBuilder Unban", "Couldn't find " + args[0] + "'s account!")); + return; + } + Plugin.getClientManager().loadClientByName(target, new Runnable() + { + @Override + public void run() + { + CoreClient theClient = Plugin.getClientManager().Get(target); + + if(theClient != null) + { + Plugin.incrementStat(theClient.getAccountId(), "Global.Build Draw Abuse", 0, true); // True = Resets the stat + caller.sendMessage(F.main("MasterBuilder Unban", "The user " + target + " has been unbanned from Master Builders")); + } + else + { + caller.sendMessage(F.main("MasterBuilder Unban", "Couldn't find " + target + "'s client!")); + return; + } + } + }); + } + }, caller, args[0], false); } - }); + + }, args[0]); + } catch(Exception e) { + e.printStackTrace(); caller.sendMessage(F.main("MasterBuilder Unban", "Exception caught! Please contact Morten and explain what happened.")); } } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/password/PasswordRepository.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/password/PasswordRepository.java index f0cf867d4..33b63e8a5 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/password/PasswordRepository.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/password/PasswordRepository.java @@ -24,7 +24,7 @@ public class PasswordRepository extends RepositoryBase public PasswordRepository(JavaPlugin plugin, String serverName) { - super(plugin, DBPool.ACCOUNT); + super(plugin, DBPool.getAccount()); _serverName = serverName; } From 8c399f03da46a923ff0819b62656452628163374 Mon Sep 17 00:00:00 2001 From: Morten Date: Tue, 22 Dec 2015 21:36:19 +0100 Subject: [PATCH 3/4] Removed a weird query :/ Status: Finished --- .../src/mineplex/core/stats/StatsRepository.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java index 726f75a99..e8ac03479 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java @@ -6,16 +6,14 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.bukkit.plugin.java.JavaPlugin; - import mineplex.core.common.util.NautHashMap; import mineplex.core.database.DBPool; import mineplex.core.database.RepositoryBase; import mineplex.core.database.ResultSetCallable; import mineplex.core.database.column.ColumnVarChar; import mineplex.database.Tables; -import net.md_5.bungee.chat.TranslatableComponentSerializer; +import org.bukkit.plugin.java.JavaPlugin; import org.jooq.DSLContext; import org.jooq.Insert; import org.jooq.Record2; @@ -29,7 +27,6 @@ public class StatsRepository extends RepositoryBase { private static String RETRIEVE_STATS = "SELECT id, name FROM stats;"; private static String INSERT_STAT = "INSERT INTO stats (name) VALUES (?);"; - private static String UPDATE_ACCOUNT_STAT_VALUE= "UPDATE accounts SET rank=?, rankPerm=true WHERE uuid = ?;"; public StatsRepository(JavaPlugin plugin) From f83016e0074ce810f727276a0feb127ecd69098f Mon Sep 17 00:00:00 2001 From: Morten Date: Wed, 23 Dec 2015 00:39:16 +0100 Subject: [PATCH 4/4] Also really quickly fixed the Invisibility in lobby bug (hopefully) --- .../src/mineplex/hub/modules/HubVisibilityManager.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/HubVisibilityManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/HubVisibilityManager.java index 1733a2fcc..b7167cf07 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/HubVisibilityManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/HubVisibilityManager.java @@ -70,13 +70,14 @@ public class HubVisibilityManager extends MiniPlugin for (Player other : UtilServer.getPlayers()) { + boolean localHideMe = hideMe; if (player.equals(other)) continue; if(Manager.GetClients().Get(other).GetRank().has(Rank.MODERATOR)) - hideMe = false; + localHideMe = false; - if (hideMe || + if (localHideMe || !Manager.getPreferences().Get(other).ShowPlayers || Manager.GetTutorial().InTutorial(other)) {