From fc98cf4f6c2fb7912bbdd4470b964440630720c9 Mon Sep 17 00:00:00 2001 From: MrTwiggy Date: Thu, 25 Sep 2014 17:17:38 -0400 Subject: [PATCH 1/7] Add callback feature set for cross-server command system to reduce dependencies, clean up old constant references and add in ability to initialize server name on ServerData. Clean up old 'this' references to '_' prefixed variables and standardize field naming. --- .../src/mineplex/core/portal/Portal.java | 4 +- .../mineplex/core/portal/TransferHandler.java | 29 ++++++++++ .../core/status/ServerStatusManager.java | 4 ++ Plugins/Mineplex.Queuer/.classpath | 1 - .../src/mineplex/queuer/QueueRepository.java | 9 ++- .../mineplex/serverdata/CommandCallback.java | 7 +++ .../src/mineplex/serverdata/CommandType.java | 17 ++++++ .../serverdata/RedisDataRepository.java | 16 +++--- .../mineplex/serverdata/ServerCommand.java | 15 +++-- .../serverdata/ServerCommandManager.java | 57 ++++++++++++++----- .../serverdata/transfers}/ServerTransfer.java | 14 ++--- .../transfers}/TransferCommand.java | 17 ++---- 12 files changed, 139 insertions(+), 51 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/portal/TransferHandler.java create mode 100644 Plugins/Mineplex.ServerData/src/mineplex/serverdata/CommandCallback.java create mode 100644 Plugins/Mineplex.ServerData/src/mineplex/serverdata/CommandType.java rename Plugins/{Mineplex.Core/src/mineplex/core/portal => Mineplex.ServerData/src/mineplex/serverdata/transfers}/ServerTransfer.java (60%) rename Plugins/{Mineplex.Core/src/mineplex/core/portal => Mineplex.ServerData/src/mineplex/serverdata/transfers}/TransferCommand.java (59%) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java index 0da30b552..654568d21 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java @@ -27,6 +27,8 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.serverdata.Region; import mineplex.serverdata.ServerCommandManager; import mineplex.serverdata.ServerManager; +import mineplex.serverdata.transfers.ServerTransfer; +import mineplex.serverdata.transfers.TransferCommand; public class Portal extends MiniPlugin { @@ -53,7 +55,7 @@ public class Portal extends MiniPlugin Bukkit.getMessenger().registerOutgoingPluginChannel(GetPlugin(), "BungeeCord"); // Register the server command type for future use - ServerCommandManager.getInstance().registerCommandType(TransferCommand.class); + ServerCommandManager.getInstance().registerCommandType(TransferCommand.class, new TransferHandler()); } public void SendAllPlayers(String serverName) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/TransferHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/TransferHandler.java new file mode 100644 index 000000000..725f8ee15 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/TransferHandler.java @@ -0,0 +1,29 @@ +package mineplex.core.portal; + +import mineplex.serverdata.CommandCallback; +import mineplex.serverdata.ServerCommand; +import mineplex.serverdata.transfers.ServerTransfer; +import mineplex.serverdata.transfers.TransferCommand; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class TransferHandler implements CommandCallback +{ + + public void run(ServerCommand command) + { + if (command instanceof TransferCommand) + { + TransferCommand transferCommand = (TransferCommand) command; + ServerTransfer transfer = transferCommand.getTransfer(); + + Player player = Bukkit.getPlayer(transfer.getPlayerName()); + + if (player != null && player.isOnline()) + { + Portal.getInstance().SendPlayerToServer(player, transfer.getServerName()); + } + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java index 0d45941b0..d4f12aafb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java @@ -15,6 +15,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.serverdata.MinecraftServer; import mineplex.serverdata.Region; +import mineplex.serverdata.ServerCommandManager; import mineplex.serverdata.ServerManager; import mineplex.serverdata.ServerRepository; import mineplex.serverdata.Utility; @@ -47,6 +48,9 @@ public class ServerStatusManager extends MiniPlugin setupConfigValues(); _name = plugin.getConfig().getString("serverstatus.name"); + + ServerCommandManager.getInstance().initializeServer(_name); + _us = plugin.getConfig().getBoolean("serverstatus.us"); Region region = _us ? Region.US : Region.EU; diff --git a/Plugins/Mineplex.Queuer/.classpath b/Plugins/Mineplex.Queuer/.classpath index aedde4fb1..567d1286d 100644 --- a/Plugins/Mineplex.Queuer/.classpath +++ b/Plugins/Mineplex.Queuer/.classpath @@ -8,6 +8,5 @@ - diff --git a/Plugins/Mineplex.Queuer/src/mineplex/queuer/QueueRepository.java b/Plugins/Mineplex.Queuer/src/mineplex/queuer/QueueRepository.java index 6be115ca6..212ea83a5 100644 --- a/Plugins/Mineplex.Queuer/src/mineplex/queuer/QueueRepository.java +++ b/Plugins/Mineplex.Queuer/src/mineplex/queuer/QueueRepository.java @@ -9,14 +9,14 @@ import java.util.Set; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; -import mineplex.core.portal.Portal; -import mineplex.core.portal.ServerTransfer; import mineplex.serverdata.DataRepository; import mineplex.serverdata.MinecraftServer; import mineplex.serverdata.RedisDataRepository; import mineplex.serverdata.Region; import mineplex.serverdata.ServerManager; import mineplex.serverdata.ServerRepository; +import mineplex.serverdata.transfers.ServerTransfer; +import mineplex.serverdata.transfers.TransferCommand; public class QueueRepository { @@ -130,7 +130,10 @@ public class QueueRepository { for (String playerName : queueParty.getPlayers()) { - Portal.transferPlayer(playerName, emptyServer.getName()); + // Execute a transfer command + ServerTransfer serverTransfer = new ServerTransfer(playerName, emptyServer.getName()); + TransferCommand transferCommand = new TransferCommand(serverTransfer); + transferCommand.publish(); } } } diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/CommandCallback.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/CommandCallback.java new file mode 100644 index 000000000..0e0c86cf3 --- /dev/null +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/CommandCallback.java @@ -0,0 +1,7 @@ +package mineplex.serverdata; + +public interface CommandCallback +{ + + public void run(ServerCommand command); +} diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/CommandType.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/CommandType.java new file mode 100644 index 000000000..9e0b34edb --- /dev/null +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/CommandType.java @@ -0,0 +1,17 @@ +package mineplex.serverdata; + +public class CommandType +{ + + private Class _commandClazz; + public Class getCommandType() { return _commandClazz; } + + private CommandCallback _commandCallback; + public CommandCallback getCallback() { return _commandCallback; } + + public CommandType(Class commandClazz, CommandCallback commandCallback) + { + _commandClazz = commandClazz; + _commandCallback = commandCallback; + } +} diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisDataRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisDataRepository.java index ed9221b0b..8ae8bf002 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisDataRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisDataRepository.java @@ -29,9 +29,9 @@ public class RedisDataRepository implements DataRepository // The geographical region of the servers stored by this ServerRepository private Region _region; - private Class elementType; + private Class _elementType; - private String elementLabel; + private String _elementLabel; /** * Class constructor @@ -42,10 +42,10 @@ public class RedisDataRepository implements DataRepository public RedisDataRepository(String host, int port, Region region, Class elementType, String elementLabel) { - this._jedisPool = new JedisPool(new JedisPoolConfig(), host, port); - this._region = region; - this.elementType = elementType; - this.elementLabel = elementLabel; + _jedisPool = new JedisPool(new JedisPoolConfig(), host, port); + _region = region; + _elementType = elementType; + _elementLabel = elementLabel; } public RedisDataRepository(Region region, Class elementType, String elementLabel) @@ -56,7 +56,7 @@ public class RedisDataRepository implements DataRepository public String getElementSetKey() { - return concatenate("data", elementLabel, _region.toString()); + return concatenate("data", _elementLabel, _region.toString()); } public String generateKey(T element) @@ -317,7 +317,7 @@ public class RedisDataRepository implements DataRepository protected T deserialize(String serializedData) { - return Utility.deserialize(serializedData, elementType); + return Utility.deserialize(serializedData, _elementType); } protected String serialize(T element) diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommand.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommand.java index a442a5af6..9535fbb68 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommand.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommand.java @@ -1,10 +1,12 @@ package mineplex.serverdata; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + public abstract class ServerCommand { // The names of servers targetted to receive this ServerCommand. - private String[] targetServers; + private String[] _targetServers; /** * Class constructor @@ -12,13 +14,16 @@ public abstract class ServerCommand */ public ServerCommand(String... targetServers) { - this.targetServers = targetServers; + _targetServers = targetServers; } /** * Run the command on it's destination target server. */ - public abstract void run(); + public void run() + { + // Not yet implemented in base + } /** * @param serverName - the name of the server to be checked for whether they are a target @@ -27,10 +32,10 @@ public abstract class ServerCommand */ public boolean isTargetServer(String serverName) { - if (targetServers == null || targetServers.length == 0) // Targets all online servers + if (_targetServers == null || _targetServers.length == 0) // Targets all online servers return true; - for (String targetServer : targetServers) + for (String targetServer : _targetServers) { if (targetServer.equalsIgnoreCase(serverName)) { diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandManager.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandManager.java index 9f3542113..fc1718ebe 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandManager.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandManager.java @@ -3,6 +3,7 @@ package mineplex.serverdata; import java.util.HashMap; import java.util.Map; +import mineplex.serverdata.transfers.TransferCommand; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; @@ -11,23 +12,30 @@ public class ServerCommandManager { // The singleton instance of ServerCommandManager - private static ServerCommandManager instance; + private static ServerCommandManager _instance; public final String SERVER_COMMANDS_CHANNEL = "commands.server"; private JedisPool _jedisPool; - private Map> commandTypes; + private Map _commandTypes; + + private String _localServerName; + public void initializeServer(String serverName) { _localServerName = serverName; } + public boolean isServerInitialized() { return _localServerName != null; } /** * Private class constructor to prevent non-singleton instances. */ private ServerCommandManager() { - this._jedisPool = new JedisPool(new JedisPoolConfig(), ServerManager.DEFAULT_REDIS_HOST, + _jedisPool = new JedisPool(new JedisPoolConfig(), ServerManager.DEFAULT_REDIS_HOST, ServerManager.DEFAULT_REDIS_PORT); - this.commandTypes = new HashMap>(); + _commandTypes = new HashMap(); initialize(); + + // Register default command types + registerCommandType(TransferCommand.class); } /** @@ -92,14 +100,27 @@ public class ServerCommandManager */ public void handleCommand(String commandType, String serializedCommand) { - if (commandTypes.containsKey(commandType)) + if (!isServerInitialized()) { - ServerCommand serverCommand = Utility.deserialize(serializedCommand, commandTypes.get(commandType)); + // TODO: Log un-initialized server receiving command? + return; + } + + if (_commandTypes.containsKey(commandType)) + { + Class commandClazz = _commandTypes.get(commandType).getCommandType(); + ServerCommand serverCommand = Utility.deserialize(serializedCommand, commandClazz); - if (serverCommand.isTargetServer("THIS SERVER NAME HERE")) // TODO: Find server name ref + if (serverCommand.isTargetServer(_localServerName)) { // TODO: Run synchronously? - serverCommand.run(); // Run the server command + CommandCallback callback = _commandTypes.get(commandType).getCallback(); + serverCommand.run(); // Run server command without callback + + if (callback != null) + { + callback.run(serverCommand); // Run callback + } } } } @@ -108,14 +129,22 @@ public class ServerCommandManager * Register a new type of {@link ServerCommand}. * @param commandType - the {@link ServerCommand} type to register. */ - public void registerCommandType(Class commandType) + public void registerCommandType(Class commandType, CommandCallback callback) { String commandName = commandType.toString(); - if (!commandTypes.containsKey(commandName)) + if (_commandTypes.containsKey(commandName)) { - commandTypes.put(commandName, commandType); + // Log overwriting of command type? } + + CommandType cmdType = new CommandType(commandType, callback); + _commandTypes.put(commandName, cmdType); + } + + public void registerCommandType(Class commandType) + { + registerCommandType(commandType, null); } /** @@ -123,11 +152,11 @@ public class ServerCommandManager */ public static ServerCommandManager getInstance() { - if (instance == null) + if (_instance == null) { - instance = new ServerCommandManager(); + _instance = new ServerCommandManager(); } - return instance; + return _instance; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/ServerTransfer.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/transfers/ServerTransfer.java similarity index 60% rename from Plugins/Mineplex.Core/src/mineplex/core/portal/ServerTransfer.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/transfers/ServerTransfer.java index cdbcd82de..c0893814d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/ServerTransfer.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/transfers/ServerTransfer.java @@ -1,15 +1,15 @@ -package mineplex.core.portal; +package mineplex.serverdata.transfers; public class ServerTransfer { // The name of the player who is being transferred. - private String playerName; - public String getPlayerName() { return playerName; } + private String _playerName; + public String getPlayerName() { return _playerName; } // The name of the destination server in this ServerTransfer. - private String serverName; - public String getServerName() { return serverName; } + private String _serverName; + public String getServerName() { return _serverName; } /** * Class constructor @@ -18,7 +18,7 @@ public class ServerTransfer */ public ServerTransfer(String playerName, String serverName) { - this.playerName = playerName; - this.serverName = serverName; + _playerName = playerName; + _serverName = serverName; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/TransferCommand.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/transfers/TransferCommand.java similarity index 59% rename from Plugins/Mineplex.Core/src/mineplex/core/portal/TransferCommand.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/transfers/TransferCommand.java index 1c1a70ada..de073851c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/TransferCommand.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/transfers/TransferCommand.java @@ -1,7 +1,4 @@ -package mineplex.core.portal; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; +package mineplex.serverdata.transfers; import mineplex.serverdata.ServerCommand; @@ -15,7 +12,8 @@ public class TransferCommand extends ServerCommand { // The ServerTransfer to be sent to another server for enactment - private ServerTransfer transfer; + private ServerTransfer _transfer; + public ServerTransfer getTransfer() { return _transfer; } /** * Class constructor @@ -23,18 +21,13 @@ public class TransferCommand extends ServerCommand */ public TransferCommand(ServerTransfer transfer) { - this.transfer = transfer; + _transfer = transfer; } @Override public void run() { - Player player = Bukkit.getPlayer(transfer.getPlayerName()); - - if (player != null && player.isOnline()) - { - Portal.getInstance().SendPlayerToServer(player, transfer.getServerName()); - } + // Utilitizes a callback functionality to seperate dependencies } } From a3e6613a94c7f6a8d6ad68580c2a337a72667029 Mon Sep 17 00:00:00 2001 From: MrTwiggy Date: Sat, 11 Oct 2014 15:53:43 -0400 Subject: [PATCH 2/7] a --- Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 62055c56c..6d3f2f941 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -31,6 +31,7 @@ import mineplex.core.preferences.PreferencesManager; import mineplex.core.projectile.ProjectileManager; import mineplex.core.punish.Punish; import mineplex.core.recharge.Recharge; +import mineplex.core.report.ReportPlugin; import mineplex.core.spawn.Spawn; import mineplex.core.status.ServerStatusManager; import mineplex.core.task.TaskManager; @@ -94,6 +95,7 @@ public class Hub extends JavaPlugin implements IRelation //new FriendManager(this, packetHandler); PartyManager partyManager = new PartyManager(this, clientManager, preferenceManager); Portal portal = new Portal(this, serverStatusManager.getCurrentServerName()); + ReportPlugin reportPlugin = new ReportPlugin(this, serverStatusManager.getCurrentServerName()); AntiHack.Initialize(this, punish, portal); PacketHandler packetHandler = new PacketHandler(this); DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler); From 0252db5a0586db5d2986f2a0e8b03069f3bac1f2 Mon Sep 17 00:00:00 2001 From: Chiss Date: Mon, 10 Nov 2014 18:40:39 +1100 Subject: [PATCH 3/7] Punish simplification update --- .../src/mineplex/core/punish/Punish.java | 30 +- .../mineplex/core/punish/UI/PunishPage.java | 272 ++++++++++++------ .../game/games/paintball/Paintball.java | 2 + 3 files changed, 214 insertions(+), 90 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/Punish.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/Punish.java index 02c380451..4c53b769f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/Punish.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/Punish.java @@ -13,7 +13,7 @@ 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.punish.Command.*; +import mineplex.core.punish.Command.PunishCommand; import mineplex.core.punish.Tokens.PunishClientToken; import mineplex.core.punish.Tokens.PunishmentToken; @@ -25,9 +25,10 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result; +import org.bukkit.event.player.PlayerChatTabCompleteEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result; import org.bukkit.plugin.java.JavaPlugin; public class Punish extends MiniPlugin @@ -264,4 +265,29 @@ public class Punish extends MiniPlugin { return _clientManager; } + + public int factorial(int n) + { + if (n == 0) + return 1; + + return n * (factorial(n-1)); + } + + @EventHandler + public void tabComplete(PlayerChatTabCompleteEvent event) + { + if (!_clientManager.Get(event.getPlayer()).GetRank().Has(Rank.HELPER)) + return; + + if (!event.getChatMessage().equals(event.getLastToken())) + return; + + Player player = UtilPlayer.searchOnline(event.getPlayer(), event.getLastToken(), true); + if (player != null) + { + event.getTabCompletions().clear(); + event.getTabCompletions().add("/p " + player.getName() + " "); + } + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/UI/PunishPage.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/UI/PunishPage.java index 42afd4aaa..911a8cd7d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/UI/PunishPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/UI/PunishPage.java @@ -3,6 +3,7 @@ package mineplex.core.punish.UI; import java.util.AbstractMap; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map.Entry; @@ -72,32 +73,27 @@ public class PunishPage extends CraftInventoryCustom implements Listener PunishClient client = _plugin.GetClient(_target); - int chatOffenseCount = 0; - int exploitingCount = 0; - int hackingCount = 0; + HashMap> offenseMap = new HashMap>(); List> punishments = new ArrayList>(); for (Category category : client.GetPunishments().keySet()) { + //Initialise Offences + offenseMap.put(category, new HashMap()); + + offenseMap.get(category).put(1, 0); + offenseMap.get(category).put(2, 0); + offenseMap.get(category).put(3, 0); + + for (Punishment punishment : client.GetPunishments().get(category)) { punishments.add(new AbstractMap.SimpleEntry(category, punishment)); - } - - switch (category) - { - case ChatOffense: - chatOffenseCount = client.GetPunishments().get(category).size(); - break; - case Exploiting: - exploitingCount = client.GetPunishments().get(category).size(); - break; - case Hacking: - hackingCount = client.GetPunishments().get(category).size(); - break; - default: - break; + + //Count by Severity + if (!punishment.GetRemoved() && punishment.GetSeverity() > 0 && punishment.GetSeverity() < 4) + offenseMap.get(category).put(punishment.GetSeverity(), 1 + offenseMap.get(category).get(punishment.GetSeverity())); } } @@ -105,9 +101,9 @@ public class PunishPage extends CraftInventoryCustom implements Listener String examplePrefixEx = ChatColor.RESET + "" + ChatColor.WHITE; String examplePrefixNote = ChatColor.RESET + "" + ChatColor.DARK_GREEN; - _chatOffenseButton = new ShopItem(Material.BOOK_AND_QUILL, (byte)0, "Chat Offense", new String[] { ChatColor.RESET + "Past offenses : " + ChatColor.YELLOW + chatOffenseCount, examplePrefix + "Verbal Abuse, Spam, Harassment, Trolling, etc" }, 1, false, true); - _exploitingButton = new ShopItem(Material.HOPPER, (byte)0, "General Offense", new String[] { ChatColor.RESET + "Past offenses : " + ChatColor.YELLOW + exploitingCount, examplePrefix + "Commmand/Map/Class/Skill exploits, etc" }, 1, false, true); - _hackingButton = new ShopItem(Material.IRON_SWORD, (byte)0, "Client Mod", new String[] { ChatColor.RESET + "Past offenses : " + ChatColor.YELLOW + hackingCount, examplePrefix + "X-ray, Forcefield, Speed, Fly, Inventory Hacks, etc" }, 1, false, true); + _chatOffenseButton = new ShopItem(Material.BOOK_AND_QUILL, (byte)0, "Chat Offense", new String[] { examplePrefix + "Verbal Abuse, Spam, Harassment, Trolling, etc" }, 1, false, true); + _exploitingButton = new ShopItem(Material.HOPPER, (byte)0, "General Offense", new String[] { examplePrefix + "Command/Map/Class/Skill exploits, etc" }, 1, false, true); + _hackingButton = new ShopItem(Material.IRON_SWORD, (byte)0, "Client Mod", new String[] { examplePrefix + "X-ray, Forcefield, Speed, Fly, Inventory Hacks, etc" }, 1, false, true); _warningButton = new ShopItem(Material.PAPER, (byte)0, "Warning", new String[] { }, 1, false, true); _permMuteButton = new ShopItem(Material.EMERALD_BLOCK, (byte)0, "Permanent Mute", new String[] { }, 1, false, true); _permBanButton = new ShopItem(Material.REDSTONE_BLOCK, (byte)0, "Permanent Ban", new String[] { }, 1, false, true); @@ -116,66 +112,67 @@ public class PunishPage extends CraftInventoryCustom implements Listener getInventory().setItem(12, _exploitingButton.getHandle()); getInventory().setItem(14, _hackingButton.getHandle()); - //Mute + //XXX Mute { AddButton(19, new ShopItem(Material.INK_SACK, (byte)2, "Severity 1", new String[] { - ChatColor.RESET + "Mute Duration: " + ChatColor.YELLOW + "2 Hours", + ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.ChatOffense).get(1), + ChatColor.RESET + "Mute Duration: " + ChatColor.YELLOW + getDurationString(Category.ChatOffense, 1, offenseMap), " ", - examplePrefixNote + "Issue a Warning for first offence!", - " ", - examplePrefix + "Spamming same thing in chat (2-5 times)", + examplePrefix + "Light Spam", + examplePrefixEx + " Sending the same message 2-5 times", " ", examplePrefix + "Light Advertising;", examplePrefixEx + " 'anyone want to play on minecade?'", " ", + examplePrefix + "Light Abuse/Harassment", + examplePrefixEx + " 'you suck a this game'", + " ", + examplePrefix + "Hackusations", + examplePrefixEx + " 'you're such a hacker!'", + " ", examplePrefix + "Trolling", - " ", - examplePrefix + "General Rudeness", - " ", - examplePrefix + "Pestering staff in admin chat", - " ", - examplePrefix + "Accusing a player of hacks in chat", - " ", - examplePrefixNote + "Use Severity 2 if two past Severity 1 past", - }, 1, false, true), new PunishButton(this, Category.ChatOffense, 1, false, 2)); + }, 1, false, true), new PunishButton(this, Category.ChatOffense, 1, false, getDuration(Category.ChatOffense, 1, offenseMap))); if (_plugin.GetClients().Get(_player).GetRank().Has(Rank.MODERATOR)) { AddButton(28, new ShopItem(Material.INK_SACK, (byte)11, "Severity 2", new String[] { - ChatColor.RESET + "Mute Duration: " + ChatColor.YELLOW + "24 Hours", + ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.ChatOffense).get(2), + ChatColor.RESET + "Mute Duration: " + ChatColor.YELLOW + getDurationString(Category.ChatOffense, 2, offenseMap), " ", - examplePrefix + "Spamming same thing in chat (6-14 times)", + examplePrefix + "Medium Spam", + examplePrefixEx + " Sending the same message 6-20 times", " ", examplePrefix + "Medium Advertising;", examplePrefixEx + " 'join crap.server.net' - posted once", " ", - examplePrefix + "Abusive Behavior;", - examplePrefixEx + " 'go fucking cry, you baby'.", + examplePrefix + "Medium Abuse/Harassment", + examplePrefixEx + " 'piss off you stupid newb'", examplePrefixEx + " 'SHIT ADMINS ARE SHIT!!!'", - examplePrefixEx + " 'youre terrible, learn to play'", + examplePrefixEx + " 'you're terrible, learn to play'", " ", - examplePrefixNote + "Use Severity 3 if two past Severity 2 offences", - }, 1, false, true), new PunishButton(this, Category.ChatOffense, 2, false, 24)); + examplePrefix + "Avoiding Chat Filter", + examplePrefixEx + " 'F|_|> pastOffences) + { + int hours = getDuration(category, severity, pastOffences); + + if (hours == -1) + return "Permanent"; + + return UtilTime.MakeStr((long)hours * 3600000L); + } + + public int getDuration(Category category, int severity, HashMap> pastOffences) + { + if (category == Category.ChatOffense) + { + int hours = 0; + + if (severity >= 1) + { + hours += calculateTime(2, 2, 48, pastOffences.get(category).get(1), severity != 1); + } + if (severity >= 2) + { + hours += calculateTime(24, 24, 168, pastOffences.get(category).get(2), severity != 2); + } + if (severity >= 3) + { + hours += calculateTime(720, 720, 720, pastOffences.get(category).get(3), severity != 3); + } + + return hours; + } + + if (category == Category.Exploiting) + { + int hours = 0; + + if (severity >= 1) + { + hours += calculateTime(4, 4, 96, pastOffences.get(category).get(1), severity != 1); + } + if (severity >= 2) + { + hours += calculateTime(48, 48, 336, pastOffences.get(category).get(2), severity != 2); + } + if (severity >= 3) + { + return -1; + } + + return hours; + } + + if (category == Category.Hacking) + { + int hours = 0; + + if (severity >= 1) + { + hours += calculateTime(24, 24, 168, pastOffences.get(category).get(1), severity != 1); + } + if (severity >= 2) + { + //Permanent! + if (pastOffences.get(category).get(2) > 0) + return -1; + + hours = 720; + } + if (severity >= 3) + { + return -1; + } + + return hours; + } + + return 0; + } + + private int calculateTime(int baseAmount, int addAmount, int pastLimit, int offenses, boolean zeroBase) + { + int amount = 0; + + if (zeroBase) + baseAmount = 0; + + // At what point does Bonus > pastLimit + int breakLimitCount = 0; + while (baseAmount + addAmount * breakLimitCount * breakLimitCount < pastLimit) + breakLimitCount++; + + amount += Math.min(baseAmount + addAmount * offenses * offenses, pastLimit); + amount += Math.max(0, (offenses - breakLimitCount) * pastLimit); + + return amount; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/paintball/Paintball.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/paintball/Paintball.java index 87ce74376..29356c629 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/paintball/Paintball.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/paintball/Paintball.java @@ -119,6 +119,8 @@ public class Paintball extends TeamGame "Last team alive wins!" }); + this.StrictAntiHack = true; + this.HungerSet = 20; registerStatTrackers( From d362fb3b1c899822330eae430dbc9d419a712d56 Mon Sep 17 00:00:00 2001 From: Chiss Date: Mon, 10 Nov 2014 19:15:56 +1100 Subject: [PATCH 4/7] fixed punish error --- .../mineplex/core/punish/UI/PunishPage.java | 53 ++++++++++--------- .../arcade/game/games/sheep/SheepGame.java | 2 + 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/UI/PunishPage.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/UI/PunishPage.java index 911a8cd7d..3df200b7d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/UI/PunishPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/UI/PunishPage.java @@ -74,10 +74,7 @@ public class PunishPage extends CraftInventoryCustom implements Listener PunishClient client = _plugin.GetClient(_target); HashMap> offenseMap = new HashMap>(); - - List> punishments = new ArrayList>(); - - for (Category category : client.GetPunishments().keySet()) + for (Category category : Category.values()) { //Initialise Offences offenseMap.put(category, new HashMap()); @@ -85,8 +82,12 @@ public class PunishPage extends CraftInventoryCustom implements Listener offenseMap.get(category).put(1, 0); offenseMap.get(category).put(2, 0); offenseMap.get(category).put(3, 0); - - + } + + List> punishments = new ArrayList>(); + + for (Category category : client.GetPunishments().keySet()) + { for (Punishment punishment : client.GetPunishments().get(category)) { punishments.add(new AbstractMap.SimpleEntry(category, punishment)); @@ -184,26 +185,26 @@ public class PunishPage extends CraftInventoryCustom implements Listener examplePrefixEx + " Abusing an exploit to gain an advantage", }, 1, false, true), new PunishButton(this, Category.Exploiting, 1, true, getDuration(Category.Exploiting, 1, offenseMap))); - if (_plugin.GetClients().Get(_player).GetRank().Has(Rank.MODERATOR)) - { - - AddButton(30, new ShopItem(Material.INK_SACK, (byte)11, "Severity 2", new String[] { - ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Exploiting).get(2), - ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Exploiting, 2, offenseMap), - " ", - examplePrefix + "Empty", - examplePrefixEx + " Currently no reason to use this :)", - }, 1, false, true), new PunishButton(this, Category.Exploiting, 2, true, getDuration(Category.Exploiting, 2, offenseMap))); - - AddButton(39, new ShopItem(Material.INK_SACK, (byte)1, "Severity 3", new String[] { - ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Exploiting).get(3), - ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Exploiting, 3, offenseMap), - " ", - examplePrefix + "Server Lag/Crash", - examplePrefixEx + " Abusing a bug to lag or crash a server", - " ", - }, 1, false, true), new PunishButton(this, Category.Exploiting, 3, true, getDuration(Category.Exploiting, 3, offenseMap))); - } +// if (_plugin.GetClients().Get(_player).GetRank().Has(Rank.MODERATOR)) +// { +// +// AddButton(30, new ShopItem(Material.INK_SACK, (byte)11, "Severity 2", new String[] { +// ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Exploiting).get(2), +// ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Exploiting, 2, offenseMap), +// " ", +// examplePrefix + "Empty", +// examplePrefixEx + " Currently no reason to use this :)", +// }, 1, false, true), new PunishButton(this, Category.Exploiting, 2, true, getDuration(Category.Exploiting, 2, offenseMap))); +// +// AddButton(39, new ShopItem(Material.INK_SACK, (byte)1, "Severity 3", new String[] { +// ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Exploiting).get(3), +// ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Exploiting, 3, offenseMap), +// " ", +// examplePrefix + "Server Lag/Crash", +// examplePrefixEx + " Abusing a bug to lag or crash a server", +// " ", +// }, 1, false, true), new PunishButton(this, Category.Exploiting, 3, true, getDuration(Category.Exploiting, 3, offenseMap))); +// } } //XXX Hacks diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/SheepGame.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/SheepGame.java index d3a8da38f..097d7136e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/SheepGame.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sheep/SheepGame.java @@ -397,6 +397,8 @@ public class SheepGame extends TeamGame public void DeathDrop(PlayerDeathEvent event) { DropSheep(event.getEntity(), 0); + + event.getEntity().eject(); } @EventHandler From d2301337d23eaa0ba45e3227409f652192abfd14 Mon Sep 17 00:00:00 2001 From: Chiss Date: Mon, 10 Nov 2014 19:28:36 +1100 Subject: [PATCH 5/7] fixed non-charged block toss not having any velocity. --- .../src/nautilus/game/arcade/kit/perks/PerkBlockToss.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBlockToss.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBlockToss.java index e3ec4b5c7..3a36d7f99 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBlockToss.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBlockToss.java @@ -135,7 +135,7 @@ public class PerkBlockToss extends Perk implements IThrown //Throw double mult = 1.4; if (charge < 1000) - mult = mult * (charge/1000); + mult = mult * ((double)charge/1000d); //Action UtilAction.velocity(block, cur.getLocation().getDirection(), mult, false, 0.2, 0, 1, true); From 920bdad64c64a4734e8feb23efc3be86d81d2d03 Mon Sep 17 00:00:00 2001 From: MrTwiggy Date: Mon, 10 Nov 2014 18:44:46 -0500 Subject: [PATCH 6/7] Player report system commit, including functionality for long-form MySQL storage of report logs as well as real-time redis based report sessions. --- .../src/mineplex/core/report/Report.java | 44 +++ .../mineplex/core/report/ReportManager.java | 318 ++++++++++++++++++ .../mineplex/core/report/ReportPlugin.java | 32 ++ .../mineplex/core/report/ReportProfile.java | 61 ++++ .../core/report/ReportRepository.java | 78 +++++ .../mineplex/core/report/ReportResult.java | 25 ++ .../report/command/ReportCloseCommand.java | 39 +++ .../core/report/command/ReportCommand.java | 48 +++ .../report/command/ReportHandleCommand.java | 38 +++ .../report/command/ReportNotification.java | 31 ++ .../mineplex/serverdata/ServerCommand.java | 2 - 11 files changed, 714 insertions(+), 2 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/Report.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/ReportProfile.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/ReportResult.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java b/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java new file mode 100644 index 000000000..5e7ab4592 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java @@ -0,0 +1,44 @@ +package mineplex.core.report; + +import java.util.HashSet; +import java.util.Set; + +import mineplex.serverdata.Data; + +public class Report implements Data +{ + + private int _reportId; + public int getReportId() { return _reportId; } + + private String _serverName; + public String getServerName() { return _serverName; } + + private String _playerName; + public String getPlayerName() { return _playerName; } + + // Set of account ids of players who contributed to reporting this player + private Set _reporters; + public Set getReporters() { return _reporters; } + public void addReporter(String reporter) { _reporters.add(reporter); } + + /** + * Class constructor + * @param reportId + * @param playerName + * @param serverName + */ + public Report(int reportId, String playerName, String serverName) + { + _reportId = reportId; + _playerName = playerName; + _serverName = serverName; + _reporters = new HashSet(); + } + + @Override + public String getDataId() + { + return String.valueOf(_reportId); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java new file mode 100644 index 000000000..63479b604 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -0,0 +1,318 @@ +package mineplex.core.report; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import mineplex.core.account.CoreClient; +import mineplex.core.command.CommandCenter; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.portal.Portal; +import mineplex.core.report.command.ReportNotification; +import mineplex.serverdata.DataRepository; +import mineplex.serverdata.RedisDataRepository; +import mineplex.serverdata.Region; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.exceptions.JedisConnectionException; + +/** + * ReportManager hooks into a synchronized network-wide report system + * with methods for updating/fetching/closing reports in real time. + * @author Ty + * + */ +public class ReportManager { + + private static ReportManager instance; + + // Holds active/open reports in a synchronized database. + private DataRepository reportRepository; + + private DataRepository reportProfiles; + + // Stores/logs closed tickets, and various reporter/staff actions. + private ReportRepository reportSqlRepository; + + // A mapping of PlayerName(String) to the ReportId(Integer) for all active reports on this server. + private Map activeReports; + + /** + * Private constructor to prevent non-singleton instances. + */ + private ReportManager() + { + this.reportRepository = new RedisDataRepository(Region.ALL, Report.class, "reports"); + this.reportProfiles = new RedisDataRepository(Region.ALL, ReportProfile.class, "reportprofiles"); + this.activeReports = new HashMap(); + + // TODO: Get JavaPlugin instance and locate ConnectionString from config? + this.reportSqlRepository = new ReportRepository(ReportPlugin.getPlugin(), "CONNECTION STRING HERE"); + reportSqlRepository.initialize(); + } + + public void retrieveReportResult(int reportId, Player reportCloser, String reason) + { + // Prompt the report closer with a menu of options to determine the result + // of the report. When confirmation is received, THEN close report. + } + + public void closeReport(int reportId, Player reportCloser, String reason) + { + retrieveReportResult(reportId, reportCloser, reason); + } + + public void closeReport(int reportId, Player reportCloser, String reason, + ReportResult result) + { + if (isActiveReport(reportId)) + { + Report report = getReport(reportId); + reportRepository.removeElement(String.valueOf(reportId)); // Remove report from redis database + removeActiveReport(reportId); + + int closerId = getPlayerAccount(reportCloser).GetAccountId(); + String playerName = getReport(reportId).getPlayerName(); + int playerId = getPlayerAccount(playerName).GetAccountId(); + String server = null; // TODO: Get current server name + reportSqlRepository.logReport(reportId, playerId, server, closerId, result, reason); + + // Update the reputation/profiles of all reporters on this closing report. + for (String reporterName : report.getReporters()) + { + CoreClient reporterAccount = getPlayerAccount(reporterName); + ReportProfile reportProfile = getReportProfile(String.valueOf(reporterAccount.GetAccountId())); + reportProfile.onReportClose(result); + reportProfiles.addElement(reportProfile); + } + + if (reportCloser != null) + { + // Notify staff that the report was closed. + sendReportNotification(String.format("[Report %d] %s closed this report. (%s).", reportId, + reportCloser.getName(), result.toDisplayMessage())); + } + } + + } + + public void handleReport(int reportId, Player reportHandler) + { + if (reportRepository.elementExists(String.valueOf(reportId))) + { + Report report = getReport(reportId); + Portal.transferPlayer(reportHandler.getName(), report.getServerName()); + String handlerName = reportHandler.getName(); + sendReportNotification(String.format("[Report %d] %s is handling this report.", reportId, handlerName)); + + // TODO: Send display message to handler when they arrive on the server + // with info about the case/report. + + int handlerId = getPlayerAccount(reportHandler).GetAccountId(); + reportSqlRepository.logReportHandling(reportId, handlerId); // Log handling into sql database + } + } + + public void reportPlayer(Player reporter, Player reportedPlayer, String reason) + { + int reporterId = getPlayerAccount(reporter).GetAccountId(); + ReportProfile reportProfile = getReportProfile(String.valueOf(reporterId)); + + if (reportProfile.canReport()) + { + Report report = null; + + if (hasActiveReport(reportedPlayer)) + { + int reportId = getActiveReport(reportedPlayer.getName()); + report = getReport(reportId); + report.addReporter(reporter.getName()); + } + else + { + String serverName = null; // TODO: Fetch name of current server + int reportId = generateReportId(); + report = new Report(reportId, reportedPlayer.getName(), serverName); + report.addReporter(reporter.getName()); + activeReports.put(reportedPlayer.getName().toLowerCase(), report.getReportId()); + reportRepository.addElement(report); + } + + if (report != null) + { + // [Report 42] [MrTwiggy +7] [Cheater102 - 5 - Speed hacking] + String message = String.format("[Report %d] [%s %d] [%s - %d - %s]", report.getReportId(), + reporter.getName(), reportProfile.getReputation(), + reportedPlayer.getName(), report.getReporters().size(), reason); + sendReportNotification(message); + reportSqlRepository.logReportSending(report.getReportId(), reporterId, reason); + } + } + } + + public void onPlayerQuit(Player player) + { + if (hasActiveReport(player)) + { + int reportId = getActiveReport(player.getName()); + this.closeReport(reportId, null, "Player Quit", ReportResult.UNDETERMINED); + // TODO: Handle 'null' report closer in closeReport metohd for NPEs. + + sendReportNotification(String.format("[Report %d] %s has left the game.", reportId, player.getName())); + } + } + + public ReportProfile getReportProfile(String playerName) + { + ReportProfile profile = reportProfiles.getElement(playerName); + + if (profile == null) + { + profile = new ReportProfile(playerName, getAccountId(playerName)); + saveReportProfile(profile); + } + + return profile; + } + + private void saveReportProfile(ReportProfile profile) + { + reportProfiles.addElement(profile); + } + + /** + * @return a uniquely generated report id. + */ + public int generateReportId() + { + JedisPool pool = ((RedisDataRepository) reportRepository).getJedisPool(); + Jedis jedis = pool.getResource(); + long uniqueReportId = -1; + + try + { + uniqueReportId = jedis.incr("reports.unique-id"); + } + catch (JedisConnectionException exception) + { + exception.printStackTrace(); + pool.returnBrokenResource(jedis); + jedis = null; + } + finally + { + if (jedis != null) + { + pool.returnResource(jedis); + } + } + + return (int) uniqueReportId; + } + + public Report getReport(int reportId) + { + return reportRepository.getElement(String.valueOf(reportId)); + } + + private CoreClient getPlayerAccount(Player player) + { + return getPlayerAccount(player.getName()); + } + + private CoreClient getPlayerAccount(String playerName) + { + return CommandCenter.Instance.GetClientManager().Get(playerName); + } + + private int getAccountId(String playerName) + { + return getPlayerAccount(playerName).GetAccountId(); + } + + /** + * @param player - the player whose report notification settings are to be checked + * @return true, if the player should receive report notifications, false otherwise. + */ + public boolean hasReportNotifications(Player player) + { + // If player is not staff, return false. + // If player is staff but has report notifications pref disabled, return false; + // Else return true. + return false; + } + + /** + * Send a network-wide {@link ReportNotification} to all online staff. + * @param message - the report notification message to send. + */ + public void sendReportNotification(String message) + { + ReportNotification reportNotification = new ReportNotification(message); + reportNotification.publish(); + } + + /** + * @param playerName - the name of the player whose active report id is being fetched + * @return the report id for the active report corresponding with playerName, if one + * currently exists, -1 otherwise. + */ + public int getActiveReport(String playerName) + { + if (activeReports.containsKey(playerName.toLowerCase())) + { + return activeReports.get(playerName.toLowerCase()); + } + + return -1; + } + + public boolean hasActiveReport(Player player) + { + return getActiveReport(player.getName()) != -1; + } + + public boolean isActiveReport(int reportId) + { + for (Entry activeReport : activeReports.entrySet()) + { + if (activeReport.getValue() == reportId) + { + return true; + } + } + + return false; + } + + public boolean removeActiveReport(int reportId) + { + for (Entry activeReport : activeReports.entrySet()) + { + if (activeReport.getValue() == reportId) + { + activeReports.remove(activeReport.getKey()); + return true; + } + } + + return false; + } + + /** + * @return the singleton instance of {@link ReportManager}. + */ + public static ReportManager getInstance() + { + if (instance == null) + { + instance = new ReportManager(); + } + + return instance; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java new file mode 100644 index 000000000..5293cf78b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java @@ -0,0 +1,32 @@ +package mineplex.core.report; + +import mineplex.core.MiniPlugin; +import mineplex.core.report.command.ReportCloseCommand; +import mineplex.core.report.command.ReportCommand; +import mineplex.core.report.command.ReportDebugCommand; +import mineplex.core.report.command.ReportHandleCommand; + +import org.bukkit.plugin.java.JavaPlugin; + +public class ReportPlugin extends MiniPlugin +{ + + private static JavaPlugin instance; + public static JavaPlugin getPlugin() { return instance; } + + public ReportPlugin(JavaPlugin plugin, String serverName) + { + super("ReportPlugin", plugin); + + instance = plugin; + } + + @Override + public void AddCommands() + { + AddCommand(new ReportCommand(this)); + AddCommand(new ReportHandleCommand(this)); + AddCommand(new ReportCloseCommand(this)); + AddCommand(new ReportDebugCommand(this)); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportProfile.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportProfile.java new file mode 100644 index 000000000..2192676d4 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportProfile.java @@ -0,0 +1,61 @@ +package mineplex.core.report; + +import mineplex.serverdata.Data; + +public class ReportProfile implements Data +{ + + private String _playerName; + + private int _playerId; + + private int _totalReports; + + private int _successfulReports; + + private int _reputation; + public int getReputation() { return _reputation; } + + private boolean _banned; + + public ReportProfile(String playerName, int playerId) + { + _playerName = playerName; + _playerId = playerId; + _totalReports = 0; + _successfulReports = 0; + _reputation = 0; + _banned = false; + } + + @Override + public String getDataId() + { + return String.valueOf(_playerId); + } + + public boolean canReport() + { + return !_banned; + } + + /** + * Called when a report made by this player is closed. + * @param result - the result of the closed report. + */ + public void onReportClose(ReportResult result) + { + _totalReports++; + + if (result == ReportResult.MUTED || result == ReportResult.BANNED) + { + _successfulReports++; + _reputation++; + } + else if (result == ReportResult.ABUSE) + { + _reputation = -1; + _banned = true; + } + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java new file mode 100644 index 000000000..968010e9c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -0,0 +1,78 @@ +package mineplex.core.report; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.UUID; +import java.util.Map.Entry; + +import mineplex.core.common.util.NautHashMap; +import mineplex.core.database.RepositoryBase; +import mineplex.core.database.ResultSetCallable; +import mineplex.core.database.column.ColumnInt; +import mineplex.core.database.column.ColumnVarChar; +import mineplex.core.preferences.UserPreferences; + +import org.bukkit.plugin.java.JavaPlugin; + +public class ReportRepository extends RepositoryBase +{ + /* + * *ReportTicket +id, date, accountId reported player, server, accountId of staff who closed, result, reason + +ReportSenders +id, date, reportId, accountId of Reporter, Reason for report + +ReportHandlers +id, date, reportId, accountId of Staff + +This will be used to determine if staff are handling + */ + + private static String CREATE_TICKET_TABLE = "CREATE TABLE IF NOT EXISTS reportTickets (reportId INT NOT NULL, date LONG, eventDate LONG, playerId INT NOT NULL, server VARCHAR(50), closerId INT NOT NULL, result VARCHAR(25), reason VARCHAR(100), PRIMARY KEY (reportId), INDEX playerIdIndex (playerId), INDEX closerIdIndex (closerId));"; + private static String CREATE_HANDLER_TABLE = "CREATE TABLE IF NOT EXISTS reportHandlers (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, handlerId INT NOT NULL, PRIMARY KEY (id), INDEX handlerIdIndex (handlerId) );"; + private static String CREATE_REPORTERS_TABLE = "CREATE TABLE IF NOT EXISTS reportSenders (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, reporterId INT NOT NULL, reason VARCHAR(100), PRIMARY KEY (id), INDEX reporterIdIndex (reporterId));"; + + private static String INSERT_TICKET = "INSERT INTO reportTickets (reportId, eventDate, playerId, server, closerId, result, reason) VALUES (?, now(), ?, ?, ?, ?, ?);"; + private static String INSERT_HANDLER = "INSERT INTO reportHandlers (eventDate, reportId, handlerId) VALUES(now(), ?, ?);"; + private static String INSERT_SENDER = "INSERT INTO reportSenders (eventDate, reportId, reporterId, reason) VALUES(now(), ?, ?, ?);"; + + public ReportRepository(JavaPlugin plugin, String connectionString) + { + super(plugin, connectionString, "root", "tAbechAk3wR7tuTh"); // TODO: Config file for host/pass? + } + + @Override + protected void initialize() + { + executeUpdate(CREATE_TICKET_TABLE); + executeUpdate(CREATE_HANDLER_TABLE); + executeUpdate(CREATE_REPORTERS_TABLE); + } + + @Override + protected void update() + { + + } + + public void logReportHandling(int reportId, int handlerId) + { + executeUpdate(INSERT_HANDLER, new ColumnInt("reportId", reportId), new ColumnInt("handlerId", handlerId)); + } + + public void logReportSending(int reportId, int reporterId, String reason) + { + executeUpdate(INSERT_SENDER, new ColumnInt("reportId", reportId), new ColumnInt("reporterId", reporterId), + new ColumnVarChar("reason", 100, reason)); + } + + public void logReport(int reportId, int playerId, String server, int closerId, ReportResult result, String reason) + { + executeUpdate(INSERT_TICKET, new ColumnInt("reportId", reportId), new ColumnInt("playerId", playerId), + new ColumnVarChar("server", 50, server), new ColumnInt("closerId", closerId), + new ColumnVarChar("result", 25, result.toString()), new ColumnVarChar("reason", 100, reason)); + } + +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportResult.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportResult.java new file mode 100644 index 000000000..fc2f3abcf --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportResult.java @@ -0,0 +1,25 @@ +package mineplex.core.report; + +import org.bukkit.ChatColor; + +public enum ReportResult +{ + UNDETERMINED(ChatColor.WHITE, "Could not determine"), + MUTED(ChatColor.YELLOW, "Muted"), + BANNED(ChatColor.RED, "Banned"), + ABUSE(ChatColor.DARK_RED, "Abuse of report system"); + + private ChatColor color; + private String displayMessage; + + private ReportResult(ChatColor color, String displayMessage) + { + this.color = color; + this.displayMessage = displayMessage; + } + + public String toDisplayMessage() + { + return color + displayMessage; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java new file mode 100644 index 000000000..49e232446 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java @@ -0,0 +1,39 @@ +package mineplex.core.report.command; + +import mineplex.core.command.CommandBase; +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.UtilPlayer; +import mineplex.core.portal.Portal; +import mineplex.core.report.ReportManager; +import mineplex.core.report.ReportPlugin; + +import org.bukkit.entity.Player; + +public class ReportCloseCommand extends CommandBase +{ + + public ReportCloseCommand(ReportPlugin plugin) + { + super(plugin, Rank.ADMIN, "reportclose", "rc"); + } + + @Override + public void Execute(final Player player, final String[] args) + { + if(args == null || args.length < 2) + { + UtilPlayer.message(player, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!")); + return; + } + else + { + int reportId = Integer.parseInt(args[0]); + String reason = F.combine(args, 1, null, false); + + ReportManager.getInstance().closeReport(reportId, player, reason); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java new file mode 100644 index 000000000..f9cebd2aa --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java @@ -0,0 +1,48 @@ +package mineplex.core.report.command; + +import mineplex.core.command.CommandBase; +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.UtilPlayer; +import mineplex.core.portal.Portal; +import mineplex.core.report.ReportManager; +import mineplex.core.report.ReportPlugin; + +import org.bukkit.entity.Player; + +public class ReportCommand extends CommandBase +{ + + public ReportCommand(ReportPlugin plugin) + { + super(plugin, Rank.ALL, "report"); + } + + @Override + public void Execute(final Player player, final String[] args) + { + if(args == null || args.length < 2) + { + UtilPlayer.message(player, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!")); + return; + } + else + { + String playerName = args[0]; + Player reportedPlayer = UtilPlayer.searchOnline(player, playerName, false); + String reason = F.combine(args, 1, null, false); + + if (reportedPlayer != null) + { + ReportManager.getInstance().reportPlayer(player, reportedPlayer, reason); + } + else + { + UtilPlayer.message(player, F.main(Plugin.GetName(), C.cRed + "Unable to find player '" + + playerName + "'!")); + } + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java new file mode 100644 index 000000000..099bbe14b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java @@ -0,0 +1,38 @@ +package mineplex.core.report.command; + +import mineplex.core.command.CommandBase; +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.UtilPlayer; +import mineplex.core.portal.Portal; +import mineplex.core.report.ReportManager; +import mineplex.core.report.ReportPlugin; + +import org.bukkit.entity.Player; + +public class ReportHandleCommand extends CommandBase +{ + + public ReportHandleCommand(ReportPlugin plugin) + { + super(plugin, Rank.ADMIN, "reporthandle", "rh"); + } + + @Override + public void Execute(final Player player, final String[] args) + { + if(args == null || args.length < 1) + { + UtilPlayer.message(player, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!")); + return; + } + else + { + int reportId = Integer.parseInt(args[0]); + + ReportManager.getInstance().handleReport(reportId, player); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java new file mode 100644 index 000000000..3b670328d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java @@ -0,0 +1,31 @@ +package mineplex.core.report.command; + +import org.bukkit.entity.Player; + +import mineplex.core.common.util.UtilServer; +import mineplex.core.report.ReportManager; +import mineplex.serverdata.ServerCommand; + +public class ReportNotification extends ServerCommand +{ + + // TODO: Encode in JSON-interactive chat message + private String notification; + + public ReportNotification(String notification) + { + super(); // Send to all servers + } + + public void run() + { + // Message all players that can receive report notifications. + for (Player player : UtilServer.getPlayers()) + { + if (ReportManager.getInstance().hasReportNotifications(player)) + { + player.sendMessage(notification); + } + } + } +} diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommand.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommand.java index 9535fbb68..f31752243 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommand.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommand.java @@ -1,7 +1,5 @@ package mineplex.serverdata; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; - public abstract class ServerCommand { From a1eff92bbb7dbfba44ce89d8bad744ed195b8f6e Mon Sep 17 00:00:00 2001 From: Chiss Date: Tue, 11 Nov 2014 12:25:36 +1100 Subject: [PATCH 7/7] fixed achievement kit for sneaky not being accessible --- .../game/games/sneakyassassins/kits/KitBriber.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/kits/KitBriber.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/kits/KitBriber.java index 79fa73015..aad17b7d1 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/kits/KitBriber.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/sneakyassassins/kits/KitBriber.java @@ -1,5 +1,6 @@ package nautilus.game.arcade.game.games.sneakyassassins.kits; +import mineplex.core.achievement.Achievement; import mineplex.core.common.util.*; import mineplex.core.itemstack.*; import nautilus.game.arcade.*; @@ -22,10 +23,18 @@ public class KitBriber extends SneakyAssassinKit new Perk[] { new PerkSmokebomb(Material.INK_SACK, 3, true), - //new PerkBriber(), }, new ItemStack(Material.EMERALD), disguiseType); + + this.setAchievementRequirements(new Achievement[] + { + Achievement.SNEAK_ASSASSINS_I_SEE_YOU, + Achievement.SNEAK_ASSASSINS_INCOMPETENCE, + Achievement.SNEAK_ASSASSINS_MASTER_ASSASSIN, + Achievement.SNEAK_ASSASSINS_THE_MASTERS_MASTER, + Achievement.SNEAKY_ASSASSINS_WINS, + }); } @Override