mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-06 04:23:02 +00:00
[Fix] Call JailStatusChangeEvent when jailing and unjailing players. Fixes #161
This commit is contained in:
parent
a134e99c8c
commit
23f3d69d38
2 changed files with 52 additions and 33 deletions
|
@ -11,6 +11,7 @@ import com.earth2me.essentials.utils.NumberUtil;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import net.ess3.api.MaxMoneyException;
|
import net.ess3.api.MaxMoneyException;
|
||||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||||
|
import net.ess3.api.events.JailStatusChangeEvent;
|
||||||
import net.ess3.api.events.UserBalanceUpdateEvent;
|
import net.ess3.api.events.UserBalanceUpdateEvent;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -445,6 +446,10 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||||
//Returns true if status expired during this check
|
//Returns true if status expired during this check
|
||||||
public boolean checkJailTimeout(final long currentTime) {
|
public boolean checkJailTimeout(final long currentTime) {
|
||||||
if (getJailTimeout() > 0 && getJailTimeout() < currentTime && isJailed()) {
|
if (getJailTimeout() > 0 && getJailTimeout() < currentTime && isJailed()) {
|
||||||
|
final JailStatusChangeEvent event = new JailStatusChangeEvent(this, null, false);
|
||||||
|
ess.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if (!event.isCancelled()) {
|
||||||
setJailTimeout(0);
|
setJailTimeout(0);
|
||||||
setJailed(false);
|
setJailed(false);
|
||||||
sendMessage(tl("haveBeenReleased"));
|
sendMessage(tl("haveBeenReleased"));
|
||||||
|
@ -459,6 +464,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
|
||||||
import com.earth2me.essentials.CommandSource;
|
import com.earth2me.essentials.CommandSource;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.utils.DateUtil;
|
import com.earth2me.essentials.utils.DateUtil;
|
||||||
|
import net.ess3.api.events.JailStatusChangeEvent;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n.tl;
|
import static com.earth2me.essentials.I18n.tl;
|
||||||
|
@ -33,6 +34,11 @@ public class Commandtogglejail extends EssentialsCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
final User controller = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null;
|
||||||
|
final JailStatusChangeEvent event = new JailStatusChangeEvent(player, controller, true);
|
||||||
|
ess.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if (!event.isCancelled()) {
|
||||||
if (player.getBase().isOnline()) {
|
if (player.getBase().isOnline()) {
|
||||||
ess.getJails().sendToJail(player, args[1]);
|
ess.getJails().sendToJail(player, args[1]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -50,6 +56,7 @@ public class Commandtogglejail extends EssentialsCommand {
|
||||||
player.setJailTimeout(timeDiff);
|
player.setJailTimeout(timeDiff);
|
||||||
}
|
}
|
||||||
sender.sendMessage((timeDiff > 0 ? tl("playerJailedFor", player.getName(), DateUtil.formatDateDiff(timeDiff)) : tl("playerJailed", player.getName())));
|
sender.sendMessage((timeDiff > 0 ? tl("playerJailedFor", player.getName(), DateUtil.formatDateDiff(timeDiff)) : tl("playerJailed", player.getName())));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +77,11 @@ public class Commandtogglejail extends EssentialsCommand {
|
||||||
if (!player.isJailed()) {
|
if (!player.isJailed()) {
|
||||||
throw new NotEnoughArgumentsException();
|
throw new NotEnoughArgumentsException();
|
||||||
}
|
}
|
||||||
|
final User controller = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null;
|
||||||
|
final JailStatusChangeEvent event = new JailStatusChangeEvent(player, controller, false);
|
||||||
|
ess.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if (!event.isCancelled()) {
|
||||||
player.setJailed(false);
|
player.setJailed(false);
|
||||||
player.setJailTimeout(0);
|
player.setJailTimeout(0);
|
||||||
player.sendMessage(tl("jailReleasedPlayerNotify"));
|
player.sendMessage(tl("jailReleasedPlayerNotify"));
|
||||||
|
@ -80,4 +92,5 @@ public class Commandtogglejail extends EssentialsCommand {
|
||||||
sender.sendMessage(tl("jailReleased", player.getName()));
|
sender.sendMessage(tl("jailReleased", player.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue