Skip to content

Commit

Permalink
improved greatly mute sync for essentials
Browse files Browse the repository at this point in the history
- ignore unmute event if purecore already has the due date (ignore automatic unmutes)
- correct data sent (invalid order was being used)
  • Loading branch information
quiquelhappy committed Mar 13, 2021
1 parent 7e4bcf8 commit dcc078f
Showing 1 changed file with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import io.purecore.api.call.ApiException;
import io.purecore.api.punishment.PunishmentType;
import io.purecore.mcplugin.API;
import net.ess3.api.IUser;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import net.ess3.api.events.MuteStatusChangeEvent;
Expand Down Expand Up @@ -35,7 +37,30 @@ public void onMute(MuteStatusChangeEvent event){
@Override
public void run() {
try {
API.getInstance().getInstance().punish("be70c5573f92a3a9", PunishmentType.Mute, event.getController().getBase().getUniqueId().toString(),event.getAffected().getBase().getUniqueId().toString(),event.getReason(),null, finalUntil);

IUser player = event.getAffected();
String playerID = null;
if(player!= null){
if(player.getBase()!=null){
playerID = player.getBase().getUniqueId().toString();
} else {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.getName());
if(offlinePlayer.hasPlayedBefore()){
playerID = offlinePlayer.getUniqueId().toString();
}
}
}

if(playerID!=null){
IUser controller = event.getController();

String controllerID = null;
if(controller!=null && controller.getBase() != null){
controllerID = controller.getBase().getUniqueId().toString();
}
API.getInstance().getInstance().punish("be70c5573f92a3a9", PunishmentType.Mute, controllerID, playerID, event.getReason(),null,finalUntil);
}

} catch (IOException | ApiException | JSONException e) {
plugin.getLogger().log(Level.WARNING, "There was an error while creating an EssentialsX punishment: " + e.getMessage());
}
Expand All @@ -46,7 +71,40 @@ public void run() {
@Override
public void run() {
try {
API.getInstance().getInstance().unpunish("be70c5573f92a3a9", PunishmentType.Mute, event.getController().getBase().getUniqueId().toString(),event.getAffected().getBase().getUniqueId().toString(),null);
IUser player = event.getAffected();
String playerID = null;
if(player!= null){
if(player.getBase()!=null){
playerID = player.getBase().getUniqueId().toString();
} else {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.getName());
if(offlinePlayer.hasPlayedBefore()){
playerID = offlinePlayer.getUniqueId().toString();
}
}
}

if(playerID!=null){
boolean skip = false;
if(event.getTimestamp().isPresent()){
if(event.getTimestamp().get() < new Date().getTime()){
skip = true;
// this is an unmute event caused by the due date of the mute,
// since this data is already present on the punishment and it
// shouldn't be considered a manual unmute, we just skip it
}
}
if(!skip){
IUser controller = event.getController();

String controllerID = null;
if(controller!=null && controller.getBase() != null){
controllerID = controller.getBase().getUniqueId().toString();
}
API.getInstance().getInstance().unpunish("be70c5573f92a3a9", PunishmentType.Mute, playerID, controllerID,null);
}
}

} catch (IOException | ApiException | JSONException e) {
plugin.getLogger().log(Level.WARNING, "There was an error while removing an EssentialsX punishment: " + e.getMessage());
}
Expand Down

0 comments on commit dcc078f

Please sign in to comment.