Implement AddPunishCommand and RemovePunishCommand

This commit is contained in:
samczsun 2016-12-06 14:08:50 -05:00 committed by cnr
parent 3af0fe3bee
commit 9234c7a7d5
5 changed files with 83 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package mineplex.core.punish; package mineplex.core.punish;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
@ -35,6 +36,8 @@ import mineplex.core.punish.Tokens.PunishClientToken;
import mineplex.core.punish.Tokens.PunishmentToken; import mineplex.core.punish.Tokens.PunishmentToken;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.commands.AddPunishCommand;
import mineplex.serverdata.commands.RemovePunishCommand;
import mineplex.serverdata.commands.ServerCommandManager; import mineplex.serverdata.commands.ServerCommandManager;
public class Punish extends MiniPlugin public class Punish extends MiniPlugin
@ -233,6 +236,10 @@ public class Punish extends MiniPlugin
} }
else if (banResult == PunishmentResponse.Punished) else if (banResult == PunishmentResponse.Punished)
{ {
runAsync(() ->
{
ServerCommandManager.getInstance().publishCommand(new AddPunishCommand(finalPlayerName, category.name(), sentence.name(), reason, duration, finalCallerName, caller != null ? caller.getUniqueId().toString() : null));
});
final String durationString = UtilTime.convertString(finalDuration < 0 ? -1 : (long)(finalDuration * 3600000), 1, TimeUnit.FIT); final String durationString = UtilTime.convertString(finalDuration < 0 ? -1 : (long)(finalDuration * 3600000), 1, TimeUnit.FIT);
if (sentence == PunishmentSentence.Ban) if (sentence == PunishmentSentence.Ban)
@ -385,7 +392,19 @@ public class Punish extends MiniPlugin
public void RemovePunishment(int punishmentId, String target, final Player admin, String reason, Callback<String> callback) public void RemovePunishment(int punishmentId, String target, final Player admin, String reason, Callback<String> callback)
{ {
CoreClient client = _clientManager.Get(admin); CoreClient client = _clientManager.Get(admin);
_repository.RemovePunishment(callback, punishmentId, target, reason, client.getName()); _repository.RemovePunishment(string ->
{
runAsync(() ->
{
PunishmentResponse punishResponse = PunishmentResponse.valueOf(string);
if (punishResponse == PunishmentResponse.PunishmentRemoved)
{
ServerCommandManager.getInstance().publishCommand(new RemovePunishCommand(punishmentId, target, admin.getName(), admin.getUniqueId(), reason));
}
});
callback.run(string);
}, punishmentId, target, reason, client.getName());
} }
public void RemoveBan(String name, String reason) public void RemoveBan(String name, String reason)

View File

@ -0,0 +1,30 @@
package mineplex.serverdata.commands;
import java.util.UUID;
public class AddPunishCommand extends ServerCommand
{
private final String _target;
private final String _category;
private final String _sentence;
private final String _reason;
private final long _duration;
private final String _admin;
private final String _adminUUID;
public AddPunishCommand(String finalPlayerName, String category, String sentence, String reason, long duration, String finalCallerName, String uuid)
{
this._target = finalPlayerName;
this._category = category;
this._sentence = sentence;
this._reason = reason;
this._duration = duration;
this._admin = finalCallerName;
this._adminUUID = uuid;
}
@Override
public void run()
{
}
}

View File

@ -0,0 +1,26 @@
package mineplex.serverdata.commands;
import java.util.UUID;
public class RemovePunishCommand extends ServerCommand
{
private final int _punishmentId;
private final String _target;
private final String _admin;
private final String _adminUUID;
private final String _reason;
public RemovePunishCommand(int punishmentId, String target, String admin, UUID adminUUID, String reason)
{
_punishmentId = punishmentId;
_target = target;
_admin = admin;
_adminUUID = adminUUID.toString();
_reason = reason;
}
@Override
public void run()
{
}
}

View File

@ -5,6 +5,7 @@ public abstract class ServerCommand
{ {
// The names of servers targetted to receive this ServerCommand. // The names of servers targetted to receive this ServerCommand.
private String _fromServer;
private String[] _targetServers; private String[] _targetServers;
/** /**
@ -14,6 +15,7 @@ public abstract class ServerCommand
public ServerCommand(String... targetServers) public ServerCommand(String... targetServers)
{ {
_targetServers = targetServers; _targetServers = targetServers;
_fromServer = ServerCommandManager.getInstance().getServerName();
} }
public void setTargetServers(String... targetServers) public void setTargetServers(String... targetServers)

View File

@ -25,6 +25,10 @@ public class ServerCommandManager
private String _localServerName; private String _localServerName;
public void initializeServer(String serverName) { _localServerName = serverName; } public void initializeServer(String serverName) { _localServerName = serverName; }
public boolean isServerInitialized() { return _localServerName != null; } public boolean isServerInitialized() { return _localServerName != null; }
public String getServerName()
{
return this._localServerName;
}
/** /**
* Private class constructor to prevent non-singleton instances. * Private class constructor to prevent non-singleton instances.