Added cross-server instant punishments.

[Punish] Banning doesn't kick.
This commit is contained in:
Jonathan Williams 2015-01-23 23:33:24 -08:00
parent b00deb683e
commit 39d1a48bc1
4 changed files with 96 additions and 2 deletions

View File

@ -1,6 +1,5 @@
package mineplex.core.punish.Command;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

View File

@ -16,6 +16,7 @@ import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.punish.Command.PunishCommand;
import mineplex.core.punish.Tokens.PunishClientToken;
import mineplex.core.punish.Tokens.PunishmentToken;
import mineplex.serverdata.ServerCommandManager;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
@ -26,7 +27,6 @@ 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.plugin.java.JavaPlugin;
@ -44,6 +44,8 @@ public class Punish extends MiniPlugin
_punishClients = new HashMap<String, PunishClient>();
_clientManager = clientManager;
_repository = new PunishRepository(webServerAddress);
ServerCommandManager.getInstance().registerCommandType("PunishCommand", mineplex.serverdata.transfers.PunishCommand.class, new PunishmentHandler(this));
}
public PunishRepository GetRepository()
@ -178,6 +180,8 @@ public class Punish extends MiniPlugin
Player target = UtilPlayer.searchOnline(null, playerName, false);
if (target != null)
target.kickPlayer(kickReason);
else
new mineplex.serverdata.transfers.PunishCommand(playerName, true, false, kickReason).publish();
}
});
@ -202,6 +206,8 @@ public class Punish extends MiniPlugin
UtilPlayer.message(target, F.main("Punish", F.elem(C.cGray + C.Bold + "Reason: ") + reason));
target.playSound(target.getLocation(), Sound.CAT_MEOW, 1f, 1f);
}
else
new mineplex.serverdata.transfers.PunishCommand(playerName, false, finalDuration != 0, F.main("Punish", F.elem(C.cGray + C.Bold + (finalDuration != 0 ? "Mute" : "Warning") + " Reason: ") + reason)).publish();
_repository.LoadPunishClient(playerName, new Callback<PunishClientToken>()
{

View File

@ -0,0 +1,59 @@
package mineplex.core.punish;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.punish.Tokens.PunishClientToken;
import mineplex.serverdata.CommandCallback;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.transfers.PunishCommand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class PunishmentHandler implements CommandCallback
{
private Punish _punishManager;
public PunishmentHandler(Punish punishManager)
{
_punishManager = punishManager;
}
public void run(ServerCommand command)
{
if (command instanceof PunishCommand)
{
PunishCommand punishCommand = (PunishCommand)command;
String playerName = punishCommand.getPlayerName();
boolean ban = punishCommand.getBan();
final String reason = punishCommand.getMessage();
final Player player = Bukkit.getPlayer(playerName);
if (player != null && player.isOnline())
{
if (ban)
{
Bukkit.getServer().getScheduler().runTask(_punishManager.GetPlugin(), new Runnable()
{
public void run()
{
player.kickPlayer(reason);
}
});
}
else
{
_punishManager.GetRepository().LoadPunishClient(playerName, new Callback<PunishClientToken>()
{
public void run(PunishClientToken token)
{
_punishManager.LoadClient(token);
UtilPlayer.message(player, reason);
}
});
}
}
}
}
}

View File

@ -0,0 +1,30 @@
package mineplex.serverdata.transfers;
import mineplex.serverdata.ServerCommand;
public class PunishCommand extends ServerCommand
{
private String _playerName;
private boolean _ban;
private boolean _mute;
private String _message;
public String getPlayerName() { return _playerName; }
public boolean getBan() { return _ban; }
public boolean getMute() { return _mute; }
public String getMessage() { return _message; }
public PunishCommand(String playerName, boolean ban, boolean mute, String message)
{
_playerName = playerName;
_ban = ban;
_mute = mute;
_message = message;
}
@Override
public void run()
{
// Utilitizes a callback functionality to seperate dependencies
}
}