Don't allow jailing in unloaded worlds and don't allow joining while
jailed in unloaded worlds.
This commit is contained in:
parent
5c4122ee92
commit
a5bf89b07e
@ -19,6 +19,7 @@ import com.graywolf336.jail.listeners.JailingListener;
|
||||
import com.graywolf336.jail.listeners.MoveProtectionListener;
|
||||
import com.graywolf336.jail.listeners.PlayerListener;
|
||||
import com.graywolf336.jail.listeners.ProtectionListener;
|
||||
import com.graywolf336.jail.listeners.WorldListener;
|
||||
|
||||
/**
|
||||
* The main class for this Jail plugin, holds instances of vital classes.
|
||||
@ -87,6 +88,7 @@ public class JailMain extends JavaPlugin {
|
||||
plm.registerEvents(new JailingListener(this), this);
|
||||
plm.registerEvents(new PlayerListener(this), this);
|
||||
plm.registerEvents(new ProtectionListener(this), this);
|
||||
plm.registerEvents(new WorldListener(this), this);
|
||||
|
||||
//Only register the move protection listener if this is enabled in the
|
||||
//config when we first start the plugin. The reason for this change is
|
||||
|
@ -21,6 +21,7 @@ import com.graywolf336.jail.Util;
|
||||
*/
|
||||
public class Jail {
|
||||
private JailMain plugin;
|
||||
private boolean enabled;
|
||||
private HashMap<String, Cell> cells;
|
||||
private HashMap<UUID, Prisoner> nocellPrisoners;//prisoners who aren't in a cell
|
||||
private String name = "", world = "";
|
||||
@ -29,6 +30,7 @@ public class Jail {
|
||||
|
||||
public Jail(JailMain plugin, String name) {
|
||||
this.plugin = plugin;
|
||||
this.enabled = true;
|
||||
this.name = name;
|
||||
cells = new HashMap<String, Cell>();
|
||||
nocellPrisoners = new HashMap<UUID, Prisoner>();
|
||||
@ -39,6 +41,16 @@ public class Jail {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
/** Sets whether this jail can be used or not. */
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
/** Gets whether this jail is enabled or not. */
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
/** Sets the name of the jail. */
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
|
@ -174,6 +174,11 @@ public class JailCommand implements Command {
|
||||
|
||||
//Get the jail instance from the name of jail in the params.
|
||||
Jail j = jm.getJail(jailName);
|
||||
if(!j.isEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.WORLDUNLOADED, j.getName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
Cell c = j.getCell(params.getCell());
|
||||
Prisoner pris = new Prisoner(uuid, params.getPlayer(), muted, time, sender.getName(), reason);
|
||||
|
||||
|
@ -32,7 +32,8 @@ public class JailListCommand implements Command {
|
||||
if(args.length == 1) {
|
||||
//No jail provided, so give them a list of the jails
|
||||
for(Jail j : jm.getJails()) {
|
||||
sender.sendMessage(ChatColor.BLUE + " " + j.getName() + " (" + j.getAllPrisoners().size() + ")");
|
||||
if(j.isEnabled()) sender.sendMessage(ChatColor.BLUE + " " + j.getName() + " (" + j.getAllPrisoners().size() + ")");
|
||||
else sender.sendMessage(ChatColor.RED + " " + j.getName() + " (" + j.getAllPrisoners().size() + ") - WORLD UNLOADED");
|
||||
}
|
||||
}else {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
@ -94,6 +94,10 @@ public enum LangString {
|
||||
UNJAILSUCCESS ("jailing"),
|
||||
/** The message went when an offline player is unjailed. */
|
||||
WILLBEUNJAILED ("jailing"),
|
||||
/** The message sent when trying to jail a player in an unloaded world. */
|
||||
WORLDUNLOADED ("jailing"),
|
||||
/** The message sent when a player joins and is jailed in a world that is unloaded. */
|
||||
WORLDUNLOADEDKICK ("jailing"),
|
||||
/** The message sent to the sender when they check their jail status and they aren't jailed. */
|
||||
YOUARENOTJAILED ("jailing"),
|
||||
|
||||
|
@ -93,6 +93,13 @@ public class PlayerListener implements Listener {
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Get the prisoner object
|
||||
Jail j = pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getUniqueId());
|
||||
|
||||
if(!j.isEnabled()) {
|
||||
event.getPlayer().kickPlayer(pl.getJailIO().getLanguageString(LangString.WORLDUNLOADEDKICK));
|
||||
pl.getLogger().warning(j.getName() + " is located in a world which is unloaded and " + event.getPlayer().getName() + " (" + event.getPlayer().getUniqueId() + ") tried to join while jailed in it.");
|
||||
return;
|
||||
}
|
||||
|
||||
Prisoner p = j.getPrisoner(event.getPlayer().getUniqueId());
|
||||
//update their last known username when they login
|
||||
p.setLastKnownName(event.getPlayer().getName());
|
||||
|
@ -0,0 +1,30 @@
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
|
||||
public class WorldListener implements Listener {
|
||||
private JailMain pl;
|
||||
|
||||
public WorldListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
|
||||
public void worldLoaded(WorldLoadEvent event) {
|
||||
for(Jail j : pl.getJailManager().getJails())
|
||||
if(j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) j.setEnabled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
|
||||
public void worldUnload(WorldUnloadEvent event) {
|
||||
for(Jail j : pl.getJailManager().getJails())
|
||||
if(j.getWorldName().equalsIgnoreCase(event.getWorld().getName())) j.setEnabled(false);
|
||||
}
|
||||
}
|
@ -75,6 +75,8 @@ language:
|
||||
unjailed: '&2You have been released! Please respect the server rules.'
|
||||
unjailsuccess: '&2%0% has been released from jail.'
|
||||
willbeunjailed: '&2%0% will be released the next time they log on.'
|
||||
worldunloaded: '&4%0% is located in a world that is not loaded, jailing to it is disabled.'
|
||||
worldunloadedkick: '&4You are jailed in a jail that is located in a world which is currently unloaded, try again later.'
|
||||
youarenotjailed: '&2You are not jailed.'
|
||||
jailpay:
|
||||
cantpayforotherswhilejailed: '&cYou are jailed and as a result you can not pay for others.'
|
||||
|
Loading…
Reference in New Issue
Block a user