Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex

This commit is contained in:
Jonathan Williams 2014-11-10 23:31:38 -08:00
commit b08cd54666
28 changed files with 1093 additions and 155 deletions

View File

@ -19,6 +19,8 @@ import mineplex.core.portal.Commands.*;
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
{

View File

@ -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());
}
}
}
}

View File

@ -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() + " ");
}
}
}

View File

@ -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,9 +73,16 @@ public class PunishPage extends CraftInventoryCustom implements Listener
PunishClient client = _plugin.GetClient(_target);
int chatOffenseCount = 0;
int exploitingCount = 0;
int hackingCount = 0;
HashMap<Category, HashMap<Integer, Integer>> offenseMap = new HashMap<Category, HashMap<Integer, Integer>>();
for (Category category : Category.values())
{
//Initialise Offences
offenseMap.put(category, new HashMap<Integer, Integer>());
offenseMap.get(category).put(1, 0);
offenseMap.get(category).put(2, 0);
offenseMap.get(category).put(3, 0);
}
List<Entry<Category, Punishment>> punishments = new ArrayList<Entry<Category, Punishment>>();
@ -83,21 +91,10 @@ public class PunishPage extends CraftInventoryCustom implements Listener
for (Punishment punishment : client.GetPunishments().get(category))
{
punishments.add(new AbstractMap.SimpleEntry<Category, Punishment>(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 +102,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 +113,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|_|<K YOU'",
}, 1, false, true), new PunishButton(this, Category.ChatOffense, 2, false, getDuration(Category.ChatOffense, 2, offenseMap)));
AddButton(37, new ShopItem(Material.INK_SACK, (byte)1, "Severity 3", new String[] {
ChatColor.RESET + "Mute Duration: " + ChatColor.YELLOW + "Permanent",
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.ChatOffense).get(3),
ChatColor.RESET + "Mute Duration: " + ChatColor.YELLOW + getDurationString(Category.ChatOffense, 3, offenseMap),
" ",
examplePrefix + "Spamming same thing in chat (15+ times)",
examplePrefix + "Severe Spam",
examplePrefixEx + " Sending the same message 20+ times",
examplePrefixEx + " Only really used for a spam bot",
" ",
examplePrefix + "Strong Advertising;",
examplePrefixEx + " 'JOIN MINECADE!! MINEPLEX SUCKS'",
examplePrefixEx + " 'join crap.server.net' - posted many times",
" ",
examplePrefix + "Severe abuse towards players/staff",
examplePrefix + "Severe Abuse/Harassment",
examplePrefixEx + " 'go fucking die in a fire you fucking sack of shit'",
}, 1, false, true), new PunishButton(this, Category.ChatOffense, 3, false, -1));
}, 1, false, true), new PunishButton(this, Category.ChatOffense, 3, false, getDuration(Category.ChatOffense, 3, offenseMap)));
}
}
//General
//XXX General
{
AddButton(21, new ShopItem(Material.INK_SACK, (byte)2, "Severity 1", new String[] {
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + "2 Hours",
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Exploiting).get(1),
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Exploiting, 1, offenseMap),
" ",
examplePrefix + "Team Killing",
examplePrefixEx + " Intentionally killing your team mates",
@ -185,48 +183,49 @@ public class PunishPage extends CraftInventoryCustom implements Listener
" ",
examplePrefix + "Map/Bug Exploiting",
examplePrefixEx + " Abusing an exploit to gain an advantage",
" ",
examplePrefixNote + "Use Severity 2 if many Severity 1 past offences",
}, 1, false, true), new PunishButton(this, Category.Exploiting, 1, true, 2));
}, 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 + "Ban Duration: " + ChatColor.YELLOW + "24",
" ",
examplePrefixNote + "Use Severity 3 if two past Severity 2 offences",
}, 1, false, true), new PunishButton(this, Category.Exploiting, 2, true, 24));
AddButton(39, new ShopItem(Material.INK_SACK, (byte)1, "Severity 3", new String[] {
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + "Permanent",
" ",
examplePrefix + "Server Lag/Crash",
examplePrefixEx + " Abusing a bug to lag or crash a server",
" ",
}, 1, false, true), new PunishButton(this, Category.Exploiting, 3, true, -1));
}
// 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)));
// }
}
//Hacks
//XXX Hacks
{
AddButton(23, new ShopItem(Material.INK_SACK, (byte)2, "Severity 1", new String[] {
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + "12 Hours",
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Hacking).get(1),
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Hacking, 1, offenseMap),
" ",
examplePrefix + "Examples;",
examplePrefixEx + " Damage Indicators",
examplePrefixEx + " Better Sprint",
examplePrefixEx + " Player Radar",
" ",
examplePrefixNote + "Use this for 1st Offence"
}, 1, false, true), new PunishButton(this, Category.Hacking, 1, true, 12));
}, 1, false, true), new PunishButton(this, Category.Hacking, 1, true, getDuration(Category.Hacking, 1, offenseMap)));
if (_plugin.GetClients().Get(_player).GetRank().Has(Rank.MODERATOR))
{
//Sev 2
String[] sev2 = new String[]
{
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + "1 Month",
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Hacking).get(2),
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Hacking, 2, offenseMap),
" ",
examplePrefix + "Hacks;",
examplePrefixEx + " Fly Hack",
@ -234,58 +233,55 @@ public class PunishPage extends CraftInventoryCustom implements Listener
examplePrefixEx + " Speed Hack",
examplePrefixEx + " Reach Hack",
" ",
examplePrefixNote + "Use this for 2nd Offence",
" ",
examplePrefixNote + "Use Severity 3 for 3rd Offence",
C.cAqua + "Use this for punishing",
C.cAqua + "Fly Hacks on this server!",
};
String[] sev2Strict = new String[]
{
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + "1 Month",
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Hacking).get(2),
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Hacking, 2, offenseMap),
" ",
examplePrefix + "Hacks;",
examplePrefixEx + " Forcefield",
examplePrefixEx + " Speed Hack",
examplePrefixEx + " Reach Hack",
" ",
examplePrefixNote + "Use this for 2nd Offence",
" ",
examplePrefixNote + "Use Severity 3 for 3rd Offence",
C.cRed + "Do not use this for punishing",
C.cRed + "Fly Hacks on this server!"
};
AddButton(32, new ShopItem(Material.INK_SACK, (byte)11, "Severity 2",
(AntiHack.Instance.isStrict() ? sev2Strict : sev2)
, 1, false, true), new PunishButton(this, Category.Hacking, 2, true, 720));
, 1, false, true), new PunishButton(this, Category.Hacking, 2, true, getDuration(Category.Hacking, 2, offenseMap)));
//Sev 3
String[] sev3 = new String[]
{
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + "Permanent",
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Hacking).get(3),
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Hacking, 3, offenseMap),
" ",
C.cRed + "Do not use this for 1st Offence of",
C.cRed + "Fly Hacks on this server!",
" ",
examplePrefixNote + "Use this for 3rd Offence",
C.cRed + "Do not use this for punishing",
C.cRed + "Fly Hacks on this server!"
};
String[] sev3Strict = new String[]
{
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + "Permanent",
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Hacking).get(3),
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Hacking, 3, offenseMap),
" ",
C.cAqua + "Use this for 1st Offence of",
C.cAqua + "Use this for punishing",
C.cAqua + "Fly Hacks on this server!",
" ",
examplePrefixNote + "Use this for 3rd Offence",
};
AddButton(41, new ShopItem(Material.INK_SACK, (byte)1, "Severity 3",
(AntiHack.Instance.isStrict() ? sev3Strict : sev3)
, 1, false, true), new PunishButton(this, Category.Hacking, 3, true, -1));
, 1, false, true), new PunishButton(this, Category.Hacking, 3, true, getDuration(Category.Hacking, 3, offenseMap)));
}
}
//Other
//XXX Other
AddButton(25, new ShopItem(Material.PAPER, (byte)0, "Warning", new String[] {
" ",
examplePrefix + "Example Warning Input;",
@ -304,11 +300,15 @@ public class PunishPage extends CraftInventoryCustom implements Listener
examplePrefixNote + "Must supply detailed reason for Ban."
}, 1, false, true), new PunishButton(this, Category.Other, 1, true, -1));
AddButton(43, new ShopItem(Material.EMERALD_BLOCK, (byte)0, "Permanent Mute", new String[] {
AddButton(43, new ShopItem(Material.BOOK_AND_QUILL, (byte)0, "Permanent Mute", new String[] {
ChatColor.RESET + "Mute Duration: " + ChatColor.YELLOW + "Permanent",
" ",
examplePrefix + "Severe Advertising;",
examplePrefixEx + " 'JOIN MINECADE! MINEPLEX SUCKS!",
examplePrefixEx + " 'join crap.server.net! FREE ADMIN!",
" ",
examplePrefixNote + "Must supply detailed reason for Mute."
}, 1, false, true), new PunishButton(this, Category.Other, 1, false, -1));
}, 1, false, true), new PunishButton(this, Category.ChatOffense, 4, false, -1));
}
Collections.sort(punishments, new PunishmentSorter());
@ -494,4 +494,101 @@ public class PunishPage extends CraftInventoryCustom implements Listener
}
});
}
public String getDurationString(Category category, int severity, HashMap<Category, HashMap<Integer, Integer>> 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<Category, HashMap<Integer, Integer>> 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;
}
}

View File

@ -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<String> _reporters;
public Set<String> 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<String>();
}
@Override
public String getDataId()
{
return String.valueOf(_reportId);
}
}

View File

@ -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<Report> reportRepository;
private DataRepository<ReportProfile> 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<String, Integer> activeReports;
/**
* Private constructor to prevent non-singleton instances.
*/
private ReportManager()
{
this.reportRepository = new RedisDataRepository<Report>(Region.ALL, Report.class, "reports");
this.reportProfiles = new RedisDataRepository<ReportProfile>(Region.ALL, ReportProfile.class, "reportprofiles");
this.activeReports = new HashMap<String, Integer>();
// 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<Report>) 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<String, Integer> activeReport : activeReports.entrySet())
{
if (activeReport.getValue() == reportId)
{
return true;
}
}
return false;
}
public boolean removeActiveReport(int reportId)
{
for (Entry<String, Integer> 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;
}
}

View File

@ -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));
}
}

View File

@ -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;
}
}
}

View File

@ -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));
}
}

View File

@ -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;
}
}

View File

@ -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<ReportPlugin>
{
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);
}
}
}

View File

@ -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<ReportPlugin>
{
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 + "'!"));
}
}
}
}

View File

@ -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<ReportPlugin>
{
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);
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -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;

View File

@ -8,6 +8,5 @@
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/jedis-2.4.2.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -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();
}
}
}

View File

@ -0,0 +1,7 @@
package mineplex.serverdata;
public interface CommandCallback
{
public void run(ServerCommand command);
}

View File

@ -0,0 +1,17 @@
package mineplex.serverdata;
public class CommandType
{
private Class<? extends ServerCommand> _commandClazz;
public Class<? extends ServerCommand> getCommandType() { return _commandClazz; }
private CommandCallback _commandCallback;
public CommandCallback getCallback() { return _commandCallback; }
public CommandType(Class<? extends ServerCommand> commandClazz, CommandCallback commandCallback)
{
_commandClazz = commandClazz;
_commandCallback = commandCallback;
}
}

View File

@ -27,9 +27,9 @@ public class RedisDataRepository<T extends Data> implements DataRepository<T>
// The geographical region of the servers stored by this ServerRepository
private Region _region;
private Class<T> elementType;
private Class<T> _elementType;
private String elementLabel;
private String _elementLabel;
/**
* Class constructor
@ -40,10 +40,10 @@ public class RedisDataRepository<T extends Data> implements DataRepository<T>
public RedisDataRepository(String host, int port, Region region,
Class<T> 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<T> elementType, String elementLabel)
@ -54,7 +54,7 @@ public class RedisDataRepository<T extends Data> implements DataRepository<T>
public String getElementSetKey()
{
return concatenate("data", elementLabel, _region.toString());
return concatenate("data", _elementLabel, _region.toString());
}
public String generateKey(T element)
@ -315,7 +315,7 @@ public class RedisDataRepository<T extends Data> implements DataRepository<T>
protected T deserialize(String serializedData)
{
return Utility.deserialize(serializedData, elementType);
return Utility.deserialize(serializedData, _elementType);
}
protected String serialize(T element)

View File

@ -4,7 +4,7 @@ public abstract class ServerCommand
{
// The names of servers targetted to receive this ServerCommand.
private String[] targetServers;
private String[] _targetServers;
/**
* Class constructor
@ -12,13 +12,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 +30,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))
{

View File

@ -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<String, Class<? extends ServerCommand>> _commandTypes;
private Map<String, CommandType> _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<String, Class<? extends ServerCommand>>();
_commandTypes = new HashMap<String, CommandType>();
initialize();
// Register default command types
registerCommandType(TransferCommand.class);
}
/**
@ -92,14 +100,27 @@ public class ServerCommandManager
*/
public void handleCommand(String commandType, String serializedCommand)
{
if (!isServerInitialized())
{
// TODO: Log un-initialized server receiving command?
return;
}
if (_commandTypes.containsKey(commandType))
{
ServerCommand serverCommand = Utility.deserialize(serializedCommand, _commandTypes.get(commandType));
Class<? extends ServerCommand> 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,12 +129,22 @@ public class ServerCommandManager
* Register a new type of {@link ServerCommand}.
* @param commandType - the {@link ServerCommand} type to register.
*/
public void registerCommandType(String commandName, Class<? extends ServerCommand> commandType)
public void registerCommandType(Class<? extends ServerCommand> commandType, CommandCallback callback)
{
if (!_commandTypes.containsKey(commandName))
String commandName = commandType.toString();
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<? extends ServerCommand> commandType)
{
registerCommandType(commandType, null);
}
/**
@ -121,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;
}
}

View File

@ -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;
}
}

View File

@ -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,17 +21,12 @@ 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
}
}

View File

@ -119,6 +119,8 @@ public class Paintball extends TeamGame
"Last team alive wins!"
});
this.StrictAntiHack = true;
this.HungerSet = 20;
registerStatTrackers(

View File

@ -397,6 +397,8 @@ public class SheepGame extends TeamGame
public void DeathDrop(PlayerDeathEvent event)
{
DropSheep(event.getEntity(), 0);
event.getEntity().eject();
}
@EventHandler

View File

@ -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

View File

@ -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);