diff --git a/src/main/java/net/cubespace/geSuit/events/BanPlayerEvent.java b/src/main/java/net/cubespace/geSuit/events/BanPlayerEvent.java new file mode 100755 index 00000000..fd1c768d --- /dev/null +++ b/src/main/java/net/cubespace/geSuit/events/BanPlayerEvent.java @@ -0,0 +1,80 @@ +package net.cubespace.geSuit.events; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Date; +import java.util.UUID; + +import com.google.common.base.Strings; + +import net.cubespace.geSuit.Utilities; +import net.cubespace.geSuit.objects.Ban; +import net.md_5.bungee.api.plugin.Event; + +public class BanPlayerEvent extends Event { + private Ban ban; + private boolean isAuto; + + public BanPlayerEvent(Ban ban, boolean isAuto) { + this.ban = ban; + this.isAuto = isAuto; + } + + public String getPlayerName() { + return ban.getPlayer(); + } + + public UUID getPlayerId() { + if (Strings.isNullOrEmpty(ban.getUuid())) + return null; + return Utilities.makeUUID(ban.getUuid()); + } + + public InetAddress getPlayerIP() { + if (ban.getIp() == null) + return null; + try { + return InetAddress.getByName(ban.getIp()); + } catch (UnknownHostException e) { + e.printStackTrace(); + return null; + } + } + + public String getReason() { + return ban.getReason(); + } + + public BanType getType() { + switch (ban.getType()) + { + case "tempban": + return BanType.Temporary; + case "ipban": + return BanType.IP; + default: + return BanType.Name; + } + } + + public String getBannedBy() { + return ban.getBannedBy(); + } + + public Date getUnbanDate() { + if (getType() != BanType.Temporary) { + return new Date(Long.MAX_VALUE); + } + return ban.getBannedUntil(); + } + + public boolean isAutomatic() { + return isAuto; + } + + public enum BanType { + Name, + IP, + Temporary + } +} diff --git a/src/main/java/net/cubespace/geSuit/events/UnbanPlayerEvent.java b/src/main/java/net/cubespace/geSuit/events/UnbanPlayerEvent.java new file mode 100755 index 00000000..ffa415f0 --- /dev/null +++ b/src/main/java/net/cubespace/geSuit/events/UnbanPlayerEvent.java @@ -0,0 +1,54 @@ +package net.cubespace.geSuit.events; + +import java.util.UUID; + +import com.google.common.base.Strings; + +import net.cubespace.geSuit.Utilities; +import net.cubespace.geSuit.events.BanPlayerEvent.BanType; +import net.cubespace.geSuit.objects.Ban; +import net.md_5.bungee.api.plugin.Event; + +public class UnbanPlayerEvent extends Event { + private Ban ban; + private String by; + + public UnbanPlayerEvent(Ban ban, String by) { + this.ban = ban; + this.by = by; + } + + public String getPlayerName() { + return ban.getPlayer(); + } + + public UUID getPlayerId() { + if (Strings.isNullOrEmpty(ban.getUuid())) + return null; + return Utilities.makeUUID(ban.getUuid()); + } + + public String getReason() { + return ban.getReason(); + } + + public BanType getType() { + switch (ban.getType()) + { + case "tempban": + return BanType.Temporary; + case "ipban": + return BanType.IP; + default: + return BanType.Name; + } + } + + public String getBannedBy() { + return ban.getBannedBy(); + } + + public String getUnbannedBy() { + return by; + } +} diff --git a/src/main/java/net/cubespace/geSuit/events/WarnPlayerEvent.java b/src/main/java/net/cubespace/geSuit/events/WarnPlayerEvent.java new file mode 100755 index 00000000..4c59bc39 --- /dev/null +++ b/src/main/java/net/cubespace/geSuit/events/WarnPlayerEvent.java @@ -0,0 +1,62 @@ +package net.cubespace.geSuit.events; + +import java.util.UUID; + +import net.cubespace.geSuit.Utilities; +import net.md_5.bungee.api.plugin.Event; + +public class WarnPlayerEvent extends Event { + + private String player; + private UUID id; + private String by; + private String reason; + private ActionType action; + private String actionExtra; + private int warnCount; + + public WarnPlayerEvent(String player, String uuid, String by, String reason, ActionType type, String actionExtra, int count) { + this.player = player; + this.id = Utilities.makeUUID(uuid); + this.by = by; + this.reason = reason; + this.action = type; + this.actionExtra = actionExtra; + this.warnCount = count; + } + + public String getPlayerName() { + return player; + } + + public UUID getPlayerId() { + return id; + } + + public String getReason() { + return reason; + } + + public String getBy() { + return by; + } + + public ActionType getAction() { + return action; + } + + public String getActionExtra() { + return actionExtra; + } + + public int getWarnCount() { + return warnCount; + } + + public enum ActionType { + None, + Kick, + TempBan, + Ban + } +} diff --git a/src/main/java/net/cubespace/geSuit/listeners/PlayerListener.java b/src/main/java/net/cubespace/geSuit/listeners/PlayerListener.java index 392298e4..fe69f9f9 100644 --- a/src/main/java/net/cubespace/geSuit/listeners/PlayerListener.java +++ b/src/main/java/net/cubespace/geSuit/listeners/PlayerListener.java @@ -52,6 +52,9 @@ public void playerServerConnected(final ServerConnectedEvent e) throws SQLExcept final GSPlayer p = PlayerManager.confirmJoin(e.getPlayer()); p.setServer(e.getServer().getInfo().getName()); + if (ConfigManager.main.BroadcastProxyConnectionMessages) { + PlayerManager.sendBroadcast(ConfigManager.messages.PLAYER_CONNECT_PROXY.replace("{player}", p.getName())); + } final boolean newspawn = p.isNewSpawn(); // Check if an existing player has a "newspawn" flag... send them to new player spawn diff --git a/src/main/java/net/cubespace/geSuit/managers/BansManager.java b/src/main/java/net/cubespace/geSuit/managers/BansManager.java index e0c88cd6..bbced374 100644 --- a/src/main/java/net/cubespace/geSuit/managers/BansManager.java +++ b/src/main/java/net/cubespace/geSuit/managers/BansManager.java @@ -1,5 +1,6 @@ package net.cubespace.geSuit.managers; +import java.sql.Timestamp; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Arrays; @@ -16,6 +17,10 @@ import net.cubespace.geSuit.TimeParser; import net.cubespace.geSuit.Utilities; import net.cubespace.geSuit.geSuit; +import net.cubespace.geSuit.events.BanPlayerEvent; +import net.cubespace.geSuit.events.UnbanPlayerEvent; +import net.cubespace.geSuit.events.WarnPlayerEvent; +import net.cubespace.geSuit.events.WarnPlayerEvent.ActionType; import net.cubespace.geSuit.objects.Ban; import net.cubespace.geSuit.objects.GSPlayer; import net.cubespace.geSuit.objects.TimeRecord; @@ -25,6 +30,7 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.plugin.Event; public class BansManager { @@ -56,6 +62,8 @@ public static void banPlayer(String bannedBy, String player, String reason, Bool } DatabaseManager.bans.banPlayer(t.name, t.uuid, null, bannedBy, reason, "ban"); + + callEvent(new BanPlayerEvent(new Ban(-1, t.name, t.uuid, null, bannedBy, reason, "ban", 1, null, null), auto)); // Player is online so kick them if ((t.gsp != null) && (t.gsp.getProxiedPlayer() != null)) { @@ -87,6 +95,7 @@ public static void unbanPlayer(String sentBy, String player) { Ban b = DatabaseManager.bans.getBanInfo(t.name, t.uuid, player); DatabaseManager.bans.unbanPlayer(b.getId()); + callEvent(new UnbanPlayerEvent(b, sentBy)); if (ConfigManager.bans.BroadcastUnbans) { PlayerManager.sendBroadcast(ConfigManager.messages.PLAYER_UNBANNED.replace("{player}", t.dispname).replace("{sender}", sender.getName())); @@ -126,6 +135,7 @@ public static void banIP(String bannedBy, String target, String reason) { if (!DatabaseManager.bans.isPlayerBanned(ip)) { DatabaseManager.bans.banPlayer(player, uuid, ip, bannedBy, reason, "ipban"); + callEvent(new BanPlayerEvent(new Ban(-1, player, uuid, ip, bannedBy, reason, "ipban", 1, null, null), false)); } for (GSPlayer p : PlayerManager.getPlayersByIP(ip)) { @@ -301,6 +311,7 @@ public static void tempBanPlayer(String bannedBy, String player, int seconds, St String shortTimeDiff = Utilities.buildShortTimeDiffString(seconds * 1000, 10); DatabaseManager.bans.tempBanPlayer(t.name, t.uuid, bannedBy, message, sdf.format(sqlToday)); + callEvent(new BanPlayerEvent(new Ban(-1, t.name, t.uuid, null, bannedBy, message, "tempban", 1, null, new Timestamp(System.currentTimeMillis() + (seconds * 1000))), auto)); if ((t.gsp != null) && (t.gsp.getProxiedPlayer() != null)) { disconnectPlayer(t.gsp.getProxiedPlayer(), ConfigManager.messages.TEMP_BAN_MESSAGE.replace("{sender}", t.dispname).replace("{time}", time).replace("{left}", timeDiff).replace("{shortleft}", shortTimeDiff).replace("{message}", message)); @@ -351,10 +362,13 @@ public static void warnPlayer(String warnedBy, String player, String reason) { PlayerManager.sendMessageToTarget(sender, ConfigManager.messages.WARN_PLAYER_BROADCAST.replace("{player}", t.dispname).replace("{message}", reason).replace("{sender}", warnedBy)); } + int warncount = 0; + ActionType actionType = ActionType.None; + String actionExtra = ""; // Check if we have warning actions defined if (ConfigManager.bans.Actions != null) { List warnings = DatabaseManager.bans.getWarnHistory(t.name, t.uuid); - Integer warncount = 0; + warncount = 0; for (Ban w : warnings) { // Only count warnings that have not expired Date now = new Date(); @@ -370,15 +384,19 @@ public static void warnPlayer(String warnedBy, String player, String reason) { String action = parts[0]; if (action.equals("kick")) { + actionType = ActionType.Kick; if ((t.gsp != null) && (t.gsp.getProxiedPlayer() != null)) { kickPlayer(warnedBy, t.name, reason, true); } } else if (action.equals("tempban")) { + actionType = ActionType.TempBan; int seconds = TimeParser.parseString(parts[1]); tempBanPlayer(warnedBy, t.name, seconds, reason, true); + actionExtra = "for " + parts[1]; } else if (action.equals("ban")) { + actionType = ActionType.Ban; banPlayer(warnedBy, t.name, reason, true); } else { PlayerManager.sendMessageToTarget(sender, ChatColor.RED + "Warning action of \"" + fullaction + "\" is invalid!"); @@ -386,6 +404,8 @@ else if (action.equals("ban")) { } } } + + callEvent(new WarnPlayerEvent(t.name, t.uuid, warnedBy, reason, actionType, actionExtra, warncount)); } public static void displayPlayerWarnHistory(final String sentBy, final String player) { @@ -689,6 +709,15 @@ public void run() { } }); } + + private static void callEvent(final Event event) { + ProxyServer.getInstance().getScheduler().runAsync(geSuit.instance, new Runnable() { + @Override + public void run() { + ProxyServer.getInstance().getPluginManager().callEvent(event); + } + }); + } private static class BanTarget { String name = null;