Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull changes #1

Merged
merged 2 commits into from
Apr 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions src/main/java/net/cubespace/geSuit/events/BanPlayerEvent.java
Original file line number Diff line number Diff line change
@@ -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
}
}
54 changes: 54 additions & 0 deletions src/main/java/net/cubespace/geSuit/events/UnbanPlayerEvent.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
62 changes: 62 additions & 0 deletions src/main/java/net/cubespace/geSuit/events/WarnPlayerEvent.java
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 30 additions & 1 deletion src/main/java/net/cubespace/geSuit/managers/BansManager.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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<Ban> 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();
Expand All @@ -370,22 +384,28 @@ 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!");
LoggingManager.log(ChatColor.RED + "Warning action of \"" + fullaction + "\" is invalid!");
}
}
}

callEvent(new WarnPlayerEvent(t.name, t.uuid, warnedBy, reason, actionType, actionExtra, warncount));
}

public static void displayPlayerWarnHistory(final String sentBy, final String player) {
Expand Down Expand Up @@ -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;
Expand Down