Skip to content

Commit

Permalink
adapt third party handlers for Spigot to match the new common handler…
Browse files Browse the repository at this point in the history
… method
  • Loading branch information
quiquelhappy committed Mar 13, 2021
1 parent c8668e9 commit 7e4bcf8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.purecore.api.call.ApiException;
import io.purecore.api.punishment.PunishmentType;
import io.purecore.mcplugin.API;
import io.purecore.mcplugin.common.thirdPartyIntegration.AdvancedBan;
import me.leoko.advancedban.bukkit.event.PunishmentEvent;
import me.leoko.advancedban.bukkit.event.RevokePunishmentEvent;
import org.bukkit.Bukkit;
Expand All @@ -12,8 +13,6 @@
import org.json.JSONException;

import java.io.IOException;
import java.util.Date;
import java.util.UUID;
import java.util.logging.Level;

public class AdvancedBanHandler implements Listener {
Expand All @@ -27,111 +26,30 @@ public AdvancedBanHandler(Plugin plugin){

@EventHandler
public void onPunishment(PunishmentEvent event){
PunishmentType type = null;
Date until = null;
String id = event.getPunishment().getHexId();
String reason = event.getPunishment().getReason();
String playerId = event.getPunishment().getUuid();
String operatorIdTemp = event.getPunishment().getOperator();
String operatorId = null;
if(operatorIdTemp!=null&& !operatorIdTemp.toLowerCase().equals("console")){
operatorId = UUID.fromString(me.leoko.advancedban.manager.UUIDManager.get().getUUID(operatorIdTemp)).toString();
}
switch (event.getPunishment().getType()){
case BAN:
type = PunishmentType.Ban;
break;
case IP_BAN:
type = PunishmentType.BanIP;
break;
case KICK:
type = PunishmentType.Kick;
break;
case MUTE:
type = PunishmentType.Mute;
break;
case WARNING:
type = PunishmentType.Warn;
break;
case TEMP_BAN:
type = PunishmentType.Ban;
until = new Date(event.getPunishment().getEnd());
break;
case TEMP_MUTE:
type = PunishmentType.Mute;
until = new Date(event.getPunishment().getEnd());
break;
case TEMP_IP_BAN:
type = PunishmentType.BanIP;
until = new Date(event.getPunishment().getEnd());
break;
case TEMP_WARNING:
type = PunishmentType.Warn;
until = new Date(event.getPunishment().getEnd());
break;
}
if(type!=null){
PunishmentType finalType = type;
String finalOperatorId = operatorId;
Date finalUntil = until;
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, new Runnable() {
@Override
public void run() {
try {
API.getInstance().getInstance().punish("5cd40c80132cd11e", finalType, finalOperatorId, playerId, reason, id, finalUntil);
} catch (IOException | ApiException | JSONException e) {
plugin.getLogger().log(Level.WARNING, "There was an error while creating an AdvancedBan punishment: " + e.getMessage());
}
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, new Runnable() {
@Override
public void run() {
try {
AdvancedBan.handlePunishment(event.getPunishment());
} catch (IOException | ApiException | JSONException e) {
plugin.getLogger().log(Level.WARNING, "There was an error while creating an AdvancedBan punishment: " + e.getMessage());
}
});
}
}
});
}

@EventHandler
public void onRemovePunishment(RevokePunishmentEvent event){
PunishmentType type = null;
String id = event.getPunishment().getHexId();
String playerId = event.getPunishment().getUuid();
String operatorIdTemp = event.getPunishment().getOperator();
String operatorId = null;
if(operatorIdTemp!=null&& !operatorIdTemp.toLowerCase().equals("console")){
operatorId = UUID.fromString(me.leoko.advancedban.manager.UUIDManager.get().getUUID(operatorIdTemp)).toString();
}
switch (event.getPunishment().getType()){
case BAN:
case TEMP_BAN:
type = PunishmentType.Ban;
break;
case IP_BAN:
case TEMP_IP_BAN:
type = PunishmentType.BanIP;
break;
case KICK:
type = PunishmentType.Kick;
break;
case MUTE:
case TEMP_MUTE:
type = PunishmentType.Mute;
break;
case WARNING:
case TEMP_WARNING:
type = PunishmentType.Warn;
break;
}
if(type!=null){
PunishmentType finalType = type;
String finalOperatorId = operatorId;
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, new Runnable() {
@Override
public void run() {
try {
API.getInstance().getInstance().unpunish("5cd40c80132cd11e", finalType, playerId, finalOperatorId, id);
} catch (IOException | ApiException | JSONException e) {
plugin.getLogger().log(Level.WARNING, "There was an error while removing an AdvancedBan punishment: " + e.getMessage());
}
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, new Runnable() {
@Override
public void run() {
try {
AdvancedBan.handleRevokePunishment(event.getPunishment());
} catch (IOException | ApiException | JSONException e) {
plugin.getLogger().log(Level.WARNING, "There was an error while removing an AdvancedBan punishment: " + e.getMessage());
}
});
}
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void pardonEventConsoleRemote(RemoteServerCommandEvent event){
}

private void unbanHandler(Player player, String command){
if((player == null || player.hasPermission(command)) && command.startsWith("minecraft:pardon ") || command.startsWith("pardon ") || (Instance.isEssentialsEnabled() && !Instance.isLiteBansEnabled() && !Instance.isAdvancedbanEnabled() && (command.startsWith("unban"))) || (Instance.isEssentialsEnabled() && command.startsWith("essentials:unban"))){
if((player == null || player.hasPermission(command)) && command.startsWith("minecraft:pardon ") || command.startsWith("pardon ") || (Instance.isEssentialsEnabled() && !Instance.isLiteBansEnabled() && !Instance.isAdvancedbanEnabled() && (command.startsWith("unban "))) || (Instance.isEssentialsEnabled() && command.startsWith("essentials:unban"))){

String moderatorId = null;
if(player!=null) moderatorId = player.getUniqueId().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import io.purecore.api.call.ApiException;
import io.purecore.api.punishment.PunishmentType;
import io.purecore.mcplugin.API;
import io.purecore.mcplugin.common.thirdPartyIntegration.LiteBans;
import litebans.api.Entry;
import litebans.api.Events;
import org.bukkit.plugin.Plugin;
import org.json.JSONException;

import java.io.IOException;
import java.util.Date;
import java.util.UUID;
import java.util.logging.Level;

public class LiteBansHandler extends Events.Listener {
Expand All @@ -25,84 +24,19 @@ public LiteBansHandler(Plugin plugin){
Events.get().register(new Events.Listener() {
@Override
public void entryRemoved(Entry entry){
PunishmentType type = null;
String id = String.valueOf(entry.getId());
if(entry.getUuid()!=null){
String playerId = UUID.fromString(entry.getUuid()).toString();
String operatorId = null;
if(entry.getExecutorUUID()!=null&&!entry.getExecutorUUID().toLowerCase().equals("console")){
operatorId = UUID.fromString(entry.getExecutorUUID()).toString();
}
switch (entry.getType()){
case "ban":
type = PunishmentType.Ban;
break;
case "ipban":
type = PunishmentType.BanIP;
break;
case "kick":
type = PunishmentType.Kick;
break;
case "mute":
type = PunishmentType.Mute;
break;
case "warning":
case "warn":
type = PunishmentType.Warn;
break;
}
if(type!=null){
try {
API.getInstance().getInstance().unpunish("c21f73b997fac4d7", type, operatorId, playerId, id);
} catch (IOException | ApiException | JSONException e) {
plugin.getLogger().log(Level.WARNING, "There was an error while creating a LiteBans punishment: " + e.getMessage());
}
}
try {
LiteBans.handleEntryDelete(entry);
} catch (JSONException | ApiException | IOException e) {
plugin.getLogger().log(Level.WARNING, "There was an error while removing a LiteBans punishment: " + e.getMessage());
}
}

@Override
public void entryAdded(Entry entry) {
PunishmentType type = null;
Date until = null;
String id = String.valueOf(entry.getId());
String reason = entry.getReason();
if(entry.getUuid()!=null){
String playerId = UUID.fromString(entry.getUuid()).toString();
String operatorId = null;
if(entry.getExecutorUUID()!=null&&!entry.getExecutorUUID().toLowerCase().equals("console")){
operatorId = UUID.fromString(entry.getExecutorUUID()).toString();
}
switch (entry.getType()){
case "ban":
type = PunishmentType.Ban;
if(entry.getDateEnd()>0) until = new Date(entry.getDateEnd());
break;
case "ipban":
type = PunishmentType.BanIP;
if(entry.getDateEnd()>0) until = new Date(entry.getDateEnd());
break;
case "kick":
type = PunishmentType.Kick;
if(entry.getDateEnd()>0) until = new Date(entry.getDateEnd());
break;
case "mute":
type = PunishmentType.Mute;
if(entry.getDateEnd()>0) until = new Date(entry.getDateEnd());
break;
case "warning":
case "warn":
type = PunishmentType.Warn;
if(entry.getDateEnd()>0) until = new Date(entry.getDateEnd());
break;
}
if(type!=null){
try {
API.getInstance().getInstance().punish("c21f73b997fac4d7", type, operatorId, playerId, reason, id, until);
} catch (IOException | ApiException | JSONException e) {
plugin.getLogger().log(Level.WARNING, "There was an error while creating a LiteBans punishment: " + e.getMessage());
}
}
try {
LiteBans.handleEntryAdd(entry);
} catch (JSONException | ApiException | IOException e) {
plugin.getLogger().log(Level.WARNING, "There was an error while creating a LiteBans punishment: " + e.getMessage());
}
}
});
Expand Down

0 comments on commit 7e4bcf8

Please sign in to comment.