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.MoveProtectionListener;
|
||||||
import com.graywolf336.jail.listeners.PlayerListener;
|
import com.graywolf336.jail.listeners.PlayerListener;
|
||||||
import com.graywolf336.jail.listeners.ProtectionListener;
|
import com.graywolf336.jail.listeners.ProtectionListener;
|
||||||
|
import com.graywolf336.jail.listeners.WorldListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main class for this Jail plugin, holds instances of vital classes.
|
* 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 JailingListener(this), this);
|
||||||
plm.registerEvents(new PlayerListener(this), this);
|
plm.registerEvents(new PlayerListener(this), this);
|
||||||
plm.registerEvents(new ProtectionListener(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
|
//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
|
//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 {
|
public class Jail {
|
||||||
private JailMain plugin;
|
private JailMain plugin;
|
||||||
|
private boolean enabled;
|
||||||
private HashMap<String, Cell> cells;
|
private HashMap<String, Cell> cells;
|
||||||
private HashMap<UUID, Prisoner> nocellPrisoners;//prisoners who aren't in a cell
|
private HashMap<UUID, Prisoner> nocellPrisoners;//prisoners who aren't in a cell
|
||||||
private String name = "", world = "";
|
private String name = "", world = "";
|
||||||
@ -29,6 +30,7 @@ public class Jail {
|
|||||||
|
|
||||||
public Jail(JailMain plugin, String name) {
|
public Jail(JailMain plugin, String name) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.enabled = true;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
cells = new HashMap<String, Cell>();
|
cells = new HashMap<String, Cell>();
|
||||||
nocellPrisoners = new HashMap<UUID, Prisoner>();
|
nocellPrisoners = new HashMap<UUID, Prisoner>();
|
||||||
@ -39,6 +41,16 @@ public class Jail {
|
|||||||
return this.plugin;
|
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. */
|
/** Sets the name of the jail. */
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = 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.
|
//Get the jail instance from the name of jail in the params.
|
||||||
Jail j = jm.getJail(jailName);
|
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());
|
Cell c = j.getCell(params.getCell());
|
||||||
Prisoner pris = new Prisoner(uuid, params.getPlayer(), muted, time, sender.getName(), reason);
|
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) {
|
if(args.length == 1) {
|
||||||
//No jail provided, so give them a list of the jails
|
//No jail provided, so give them a list of the jails
|
||||||
for(Jail j : jm.getJails()) {
|
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 {
|
}else {
|
||||||
Jail j = jm.getJail(args[1]);
|
Jail j = jm.getJail(args[1]);
|
||||||
|
@ -94,6 +94,10 @@ public enum LangString {
|
|||||||
UNJAILSUCCESS ("jailing"),
|
UNJAILSUCCESS ("jailing"),
|
||||||
/** The message went when an offline player is unjailed. */
|
/** The message went when an offline player is unjailed. */
|
||||||
WILLBEUNJAILED ("jailing"),
|
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. */
|
/** The message sent to the sender when they check their jail status and they aren't jailed. */
|
||||||
YOUARENOTJAILED ("jailing"),
|
YOUARENOTJAILED ("jailing"),
|
||||||
|
|
||||||
|
@ -93,6 +93,13 @@ public class PlayerListener implements Listener {
|
|||||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||||
//Get the prisoner object
|
//Get the prisoner object
|
||||||
Jail j = pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getUniqueId());
|
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());
|
Prisoner p = j.getPrisoner(event.getPlayer().getUniqueId());
|
||||||
//update their last known username when they login
|
//update their last known username when they login
|
||||||
p.setLastKnownName(event.getPlayer().getName());
|
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.'
|
unjailed: '&2You have been released! Please respect the server rules.'
|
||||||
unjailsuccess: '&2%0% has been released from jail.'
|
unjailsuccess: '&2%0% has been released from jail.'
|
||||||
willbeunjailed: '&2%0% will be released the next time they log on.'
|
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.'
|
youarenotjailed: '&2You are not jailed.'
|
||||||
jailpay:
|
jailpay:
|
||||||
cantpayforotherswhilejailed: '&cYou are jailed and as a result you can not pay for others.'
|
cantpayforotherswhilejailed: '&cYou are jailed and as a result you can not pay for others.'
|
||||||
|
Loading…
Reference in New Issue
Block a user