Skip to content

Commit

Permalink
punishment handling
Browse files Browse the repository at this point in the history
  • Loading branch information
quiquelhappy committed Mar 12, 2021
1 parent 1a01269 commit 1175b2c
Show file tree
Hide file tree
Showing 32 changed files with 395 additions and 30 deletions.
28 changes: 15 additions & 13 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions module/universal/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ main: io.purecore.mcplugin.spigot.Instance
author: quiquelhappy
version: 1.0.0
description: All-in-one server managment tool
softdepend:
- Essentials
- AdvancedBan
- LiteBans
- Votifier
commands:
key:
description: Saves the key and reloads the plugin
Expand Down
2 changes: 1 addition & 1 deletion module/universal/src/io/purecore/mcplugin/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class API {

protected static String currentRelease = "b8c0e54231910b24";
protected static String currentRelease = "567fc1a44c687470";
public static String getCurrentRelease(){
return API.currentRelease;
}
Expand Down
27 changes: 21 additions & 6 deletions module/universal/src/io/purecore/mcplugin/spigot/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,29 @@ public class Instance extends JavaPlugin {
private static Cache cache;
private static File cacheFile;

private boolean hasLiteBansHandler;

public static io.purecore.mcplugin.spigot.Cache getCache(){
return Instance.cache;
}
public static File getCacheFile(){
return Instance.cacheFile;
}

private static boolean essentials = false;
private static boolean litebans = false;
private static boolean advancedban = false;

public static boolean isEssentialsEnabled(){
return Instance.essentials;
}

public static boolean isLiteBansEnabled(){
return Instance.litebans;
}

public static boolean isAdvancedbanEnabled(){
return Instance.advancedban;
}

@Override
public void onDisable() {
super.onDisable();
Expand All @@ -59,21 +73,22 @@ public void onEnable() {
// integration handlers

if(this.getServer().getPluginManager().isPluginEnabled("AdvancedBan")){
if(!hasLiteBansHandler){
hasLiteBansHandler=true;
if(!Instance.isLiteBansEnabled()){
new LiteBansHandler(this);
Instance.advancedban = true;
}
}

if(this.getServer().getPluginManager().isPluginEnabled("LiteBans")){
if(!hasLiteBansHandler){
hasLiteBansHandler=true;
if(!Instance.isLiteBansEnabled()){
new LiteBansHandler(this);
Instance.litebans = true;
}
}

if(this.getServer().getPluginManager().isPluginEnabled("Essentials")){
this.getServer().getPluginManager().registerEvents(new EssentialsHandler(this), this);
Instance.essentials = true;
}

if(this.getServer().getPluginManager().isPluginEnabled("Votifier")){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package io.purecore.mcplugin.spigot.events;

import io.purecore.api.call.ApiException;
import io.purecore.api.punishment.PunishmentType;
import io.purecore.mcplugin.API;
import me.leoko.advancedban.bukkit.event.PunishmentEvent;
import me.leoko.advancedban.bukkit.event.RevokePunishmentEvent;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
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 AdvancedBanHandler implements Listener {
Expand All @@ -19,12 +27,111 @@ 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());
}
}
});
}
}

@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());
}
}
});
}
}

}
Loading

0 comments on commit 1175b2c

Please sign in to comment.