This should work around a lot of the plugins out there which handle inventories per world. I might have missed a few things here and there, but that's what testing by others is for. :)
This commit is contained in:
		@@ -172,7 +172,7 @@ public class PrisonerManager {
 | 
				
			|||||||
     * @param player who is the prisoner
 | 
					     * @param player who is the prisoner
 | 
				
			||||||
     * @param prisoner data containing everything pertaining to them
 | 
					     * @param prisoner data containing everything pertaining to them
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected void jailPrisoner(Jail jail, ICell cell, Player player, Prisoner prisoner) {
 | 
					    protected void jailPrisoner(final Jail jail, ICell cell, final Player player, final Prisoner prisoner) {
 | 
				
			||||||
        if(cell instanceof NoCell)
 | 
					        if(cell instanceof NoCell)
 | 
				
			||||||
            cell = null;
 | 
					            cell = null;
 | 
				
			||||||
        else if(cell instanceof AnyCell)
 | 
					        else if(cell instanceof AnyCell)
 | 
				
			||||||
@@ -256,13 +256,21 @@ public class PrisonerManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        //If the cell doesn't equal null, then let's put them in the jail
 | 
					        //If the cell doesn't equal null, then let's put them in the jail
 | 
				
			||||||
        if(cell != null) {
 | 
					        if(cell != null) {
 | 
				
			||||||
 | 
					            //Teleport them to the cell's teleport location
 | 
				
			||||||
 | 
					            //they will now be placed in jail.
 | 
				
			||||||
 | 
					            pl.debug("Teleporting " + player.getName() + " to " + jail.getName() + " in the cell " + cell.getName() + "'s in: " + jail.getTeleportIn().toString());
 | 
				
			||||||
 | 
					            player.teleport(cell.getTeleport());
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            //check if we store the inventory
 | 
					            //check if we store the inventory
 | 
				
			||||||
            if(pl.getConfig().getBoolean(Settings.JAILEDSTOREINVENTORY.getPath(), true)) {
 | 
					            if(pl.getConfig().getBoolean(Settings.JAILEDSTOREINVENTORY.getPath(), true)) {
 | 
				
			||||||
 | 
					                final ICell theCell = cell;
 | 
				
			||||||
 | 
					                pl.getServer().getScheduler().runTaskLater(pl, new Runnable() {
 | 
				
			||||||
 | 
					                    public void run() {
 | 
				
			||||||
                        List<String> blacklist = pl.getConfig().getStringList(Settings.JAILEDINVENTORYBLACKLIST.getPath());
 | 
					                        List<String> blacklist = pl.getConfig().getStringList(Settings.JAILEDINVENTORYBLACKLIST.getPath());
 | 
				
			||||||
                        //Check if there is a chest to store our items to and if it is a double chest, if not we will then serialize it
 | 
					                        //Check if there is a chest to store our items to and if it is a double chest, if not we will then serialize it
 | 
				
			||||||
                if(cell.hasChest()) {
 | 
					                        if(theCell.hasChest()) {
 | 
				
			||||||
                            //Get the chest's inventory and then clear it
 | 
					                            //Get the chest's inventory and then clear it
 | 
				
			||||||
                    Inventory chest = cell.getChest().getInventory();
 | 
					                            Inventory chest = theCell.getChest().getInventory();
 | 
				
			||||||
                            chest.clear();
 | 
					                            chest.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            //Get the separate inventory, so we can iterate of them
 | 
					                            //Get the separate inventory, so we can iterate of them
 | 
				
			||||||
@@ -311,15 +319,19 @@ public class PrisonerManager {
 | 
				
			|||||||
                            player.getInventory().setArmorContents(null);
 | 
					                            player.getInventory().setArmorContents(null);
 | 
				
			||||||
                            player.getInventory().clear();
 | 
					                            player.getInventory().clear();
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					                    };
 | 
				
			||||||
 | 
					                }, 10);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					 | 
				
			||||||
            //Teleport them to the cell's teleport location
 | 
					 | 
				
			||||||
            //they will now be placed in jail.
 | 
					 | 
				
			||||||
            pl.debug("Teleporting " + player.getName() + " to " + jail.getName() + " in the cell " + cell.getName() + "'s in: " + jail.getTeleportIn().toString());
 | 
					 | 
				
			||||||
            player.teleport(cell.getTeleport());
 | 
					 | 
				
			||||||
        }else {
 | 
					        }else {
 | 
				
			||||||
 | 
					            //Teleport them to the jail's teleport in location
 | 
				
			||||||
 | 
					            //They will now be placed in jail.
 | 
				
			||||||
 | 
					            pl.debug("Teleporting " + player.getName() + " to " + jail.getName() + "'s in: " + jail.getTeleportIn().toString());
 | 
				
			||||||
 | 
					            player.teleport(jail.getTeleportIn());
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            //There is no cell we're jailing them to, so stick them in the jail
 | 
					            //There is no cell we're jailing them to, so stick them in the jail
 | 
				
			||||||
            if(pl.getConfig().getBoolean(Settings.JAILEDSTOREINVENTORY.getPath(), true)) {
 | 
					            if(pl.getConfig().getBoolean(Settings.JAILEDSTOREINVENTORY.getPath(), true)) {
 | 
				
			||||||
 | 
					                pl.getServer().getScheduler().runTaskLater(pl, new Runnable() {
 | 
				
			||||||
 | 
					                    public void run() {
 | 
				
			||||||
                        List<String> blacklist = pl.getConfig().getStringList(Settings.JAILEDINVENTORYBLACKLIST.getPath());
 | 
					                        List<String> blacklist = pl.getConfig().getStringList(Settings.JAILEDINVENTORYBLACKLIST.getPath());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        for(ItemStack item : player.getInventory().getContents())
 | 
					                        for(ItemStack item : player.getInventory().getContents())
 | 
				
			||||||
@@ -338,12 +350,9 @@ public class PrisonerManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                        player.getInventory().setArmorContents(null);
 | 
					                        player.getInventory().setArmorContents(null);
 | 
				
			||||||
                        player.getInventory().clear();
 | 
					                        player.getInventory().clear();
 | 
				
			||||||
 | 
					                    };
 | 
				
			||||||
 | 
					                }, 10);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					 | 
				
			||||||
            //Teleport them to the jail's teleport in location
 | 
					 | 
				
			||||||
            //They will now be placed in jail.
 | 
					 | 
				
			||||||
            pl.debug("Teleporting " + player.getName() + " to " + jail.getName() + "'s in: " + jail.getTeleportIn().toString());
 | 
					 | 
				
			||||||
            player.teleport(jail.getTeleportIn());
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Set them to not allowing teleporting, as we are not going to be moving them anymore
 | 
					        //Set them to not allowing teleporting, as we are not going to be moving them anymore
 | 
				
			||||||
@@ -437,7 +446,7 @@ public class PrisonerManager {
 | 
				
			|||||||
     * @throws PrisonerRequiredException when the provided prisoner data is null.
 | 
					     * @throws PrisonerRequiredException when the provided prisoner data is null.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void unJail(Jail jail, ICell cell, Player player, Prisoner prisoner, CommandSender sender) throws AsyncUnJailingNotSupportedException, JailRequiredException, PrisonerRequiredException  {
 | 
					    public void unJail(final Jail jail, ICell cell, final Player player, final Prisoner prisoner, final CommandSender sender) throws AsyncUnJailingNotSupportedException, JailRequiredException, PrisonerRequiredException  {
 | 
				
			||||||
        if(!pl.getServer().isPrimaryThread()) throw new AsyncUnJailingNotSupportedException();
 | 
					        if(!pl.getServer().isPrimaryThread()) throw new AsyncUnJailingNotSupportedException();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Do some checks of whether the passed params are null.
 | 
					        //Do some checks of whether the passed params are null.
 | 
				
			||||||
@@ -468,30 +477,6 @@ public class PrisonerManager {
 | 
				
			|||||||
            player.eject();
 | 
					            player.eject();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        //In case we had set their sleeping state to be ignored
 | 
					 | 
				
			||||||
        //let's enable their sleeping state taking place again
 | 
					 | 
				
			||||||
        player.setSleepingIgnored(false);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        //If the config has us teleporting them back to their
 | 
					 | 
				
			||||||
        //previous position then let's do that
 | 
					 | 
				
			||||||
        boolean tpd = false;
 | 
					 | 
				
			||||||
        if(pl.getConfig().getBoolean(Settings.RELEASETOPREVIOUSPOSITION.getPath(), false)) {
 | 
					 | 
				
			||||||
            if(prisoner.getPreviousLocation() != null)
 | 
					 | 
				
			||||||
                tpd = player.teleport(prisoner.getPreviousLocation());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        //If they haven't already been teleported and the config has us to teleport on release,
 | 
					 | 
				
			||||||
        //then we teleport players to the jail's free spot
 | 
					 | 
				
			||||||
        if(!tpd && pl.getConfig().getBoolean(Settings.TELEPORTONRELEASE.getPath(), true)) {
 | 
					 | 
				
			||||||
            player.teleport(jail.getTeleportFree());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        //If we are to restore their previous gamemode and we have it stored,
 | 
					 | 
				
			||||||
        //then by all means let's restore it
 | 
					 | 
				
			||||||
        if(pl.getConfig().getBoolean(Settings.RESTOREPREVIOUSGAMEMODE.getPath(), false)) {
 | 
					 | 
				
			||||||
            player.setGameMode(prisoner.getPreviousGameMode());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        //Now, let's restore their inventory if we can store it but
 | 
					        //Now, let's restore their inventory if we can store it but
 | 
				
			||||||
        //first up is clearing their inventory...if we can store it
 | 
					        //first up is clearing their inventory...if we can store it
 | 
				
			||||||
        boolean store = pl.getConfig().getBoolean(Settings.JAILEDSTOREINVENTORY.getPath(), true);
 | 
					        boolean store = pl.getConfig().getBoolean(Settings.JAILEDSTOREINVENTORY.getPath(), true);
 | 
				
			||||||
@@ -545,6 +530,34 @@ public class PrisonerManager {
 | 
				
			|||||||
            jail.removePrisoner(prisoner);
 | 
					            jail.removePrisoner(prisoner);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //In case we had set their sleeping state to be ignored
 | 
				
			||||||
 | 
					        //let's enable their sleeping state taking place again
 | 
				
			||||||
 | 
					        player.setSleepingIgnored(false);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        pl.getServer().getScheduler().runTaskLater(pl, new Runnable() {
 | 
				
			||||||
 | 
					            public void run() {
 | 
				
			||||||
 | 
					                //If the config has us teleporting them back to their
 | 
				
			||||||
 | 
					                //previous position then let's do that
 | 
				
			||||||
 | 
					                boolean tpd = false;
 | 
				
			||||||
 | 
					                if(pl.getConfig().getBoolean(Settings.RELEASETOPREVIOUSPOSITION.getPath(), false)) {
 | 
				
			||||||
 | 
					                    if(prisoner.getPreviousLocation() != null)
 | 
				
			||||||
 | 
					                        tpd = player.teleport(prisoner.getPreviousLocation());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                //If they haven't already been teleported and the config has us to teleport on release,
 | 
				
			||||||
 | 
					                //then we teleport players to the jail's free spot
 | 
				
			||||||
 | 
					                if(!tpd && pl.getConfig().getBoolean(Settings.TELEPORTONRELEASE.getPath(), true)) {
 | 
				
			||||||
 | 
					                    player.teleport(jail.getTeleportFree());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                //If we are to restore their previous gamemode and we have it stored,
 | 
				
			||||||
 | 
					                //then by all means let's restore it
 | 
				
			||||||
 | 
					                if(pl.getConfig().getBoolean(Settings.RESTOREPREVIOUSGAMEMODE.getPath(), false)) {
 | 
				
			||||||
 | 
					                    player.setGameMode(prisoner.getPreviousGameMode());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					        }, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Get the commands to execute prisoners are unjailed
 | 
					        //Get the commands to execute prisoners are unjailed
 | 
				
			||||||
        //replace all of the %p% so that the commands can have a player name in them
 | 
					        //replace all of the %p% so that the commands can have a player name in them
 | 
				
			||||||
        for(String command : pl.getConfig().getStringList(Settings.COMMANDSONRELEASE.getPath())) {
 | 
					        for(String command : pl.getConfig().getStringList(Settings.COMMANDSONRELEASE.getPath())) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,8 +48,10 @@ public class JailingListener implements Listener {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @EventHandler
 | 
					    @EventHandler
 | 
				
			||||||
    public void setInmatesClothing(PrisonerJailedEvent event) {
 | 
					    public void setInmatesClothing(final PrisonerJailedEvent event) {
 | 
				
			||||||
        if(pl.getConfig().getBoolean(Settings.CLOTHINGENABLED.getPath())) {
 | 
					        if(pl.getConfig().getBoolean(Settings.CLOTHINGENABLED.getPath())) {
 | 
				
			||||||
 | 
					            pl.getServer().getScheduler().runTaskLater(pl, new Runnable() {
 | 
				
			||||||
 | 
					                public void run() {
 | 
				
			||||||
                    String[] helmet = pl.getConfig().getString(Settings.CLOTHINGHELMET.getPath()).toUpperCase().split("~");
 | 
					                    String[] helmet = pl.getConfig().getString(Settings.CLOTHINGHELMET.getPath()).toUpperCase().split("~");
 | 
				
			||||||
                    switch(helmet.length) {
 | 
					                    switch(helmet.length) {
 | 
				
			||||||
                        case 1:
 | 
					                        case 1:
 | 
				
			||||||
@@ -113,6 +115,8 @@ public class JailingListener implements Listener {
 | 
				
			|||||||
                        default:
 | 
					                        default:
 | 
				
			||||||
                            break;
 | 
					                            break;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					            }, 20);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user