Merge branch 'master' of git@github.com:graywolf336/Jail.git

This commit is contained in:
graywolf336 2014-01-01 16:19:18 -06:00
commit b22fad16c4
4 changed files with 52 additions and 40 deletions

View File

@ -29,6 +29,7 @@ Done
* Config value ``jailing.during.maxFoodLevel`` is now used in one part
* Config value ``jailing.during.minFoodLevel`` is now used in one part
* Config value ``jailing.release.teleport`` is used in unjailing
* Config value ``jailing.release.commands`` is now used
[Jail 3.0 JavaDoc](http://ci.graywolf336.com/job/Jail/javadoc)
====
====

View File

@ -1,7 +1,5 @@
package com.graywolf336.jail;
import java.io.IOException;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -348,51 +346,25 @@ public class PrisonerManager {
chest.clear();
}else {
restoreInventory(player, prisoner);
Util.restoreInventory(player, prisoner);
}
pl.getJailIO().removePrisoner(jail, cell, prisoner);
cell.removePrisoner();
}else {
restoreInventory(player, prisoner);
Util.restoreInventory(player, prisoner);
pl.getJailIO().removePrisoner(jail, prisoner);
jail.removePrisoner(prisoner);
}
}
private void restoreInventory(Player player, Prisoner prisoner) {
try {
Inventory content = Util.fromBase64(prisoner.getInventory());
ItemStack[] armor = Util.itemStackArrayFromBase64(prisoner.getArmor());
for(ItemStack item : armor) {
if(item == null)
continue;
else if(item.getType().toString().toLowerCase().contains("helmet"))
player.getInventory().setHelmet(item);
else if(item.getType().toString().toLowerCase().contains("chestplate"))
player.getInventory().setChestplate(item);
else if(item.getType().toString().toLowerCase().contains("leg"))
player.getInventory().setLeggings(item);
else if(item.getType().toString().toLowerCase().contains("boots"))
player.getInventory().setBoots(item);
else if (player.getInventory().firstEmpty() == -1)
player.getWorld().dropItem(player.getLocation(), item);
else
player.getInventory().addItem(item);
}
for(ItemStack item : content.getContents()) {
if(item == null) continue;
else if(player.getInventory().firstEmpty() == -1)
player.getWorld().dropItem(player.getLocation(), item);
else
player.getInventory().addItem(item);
}
} catch (IOException e) {
e.printStackTrace();
pl.getLogger().severe("Unable to restore " + player.getName() + "'s inventory.");
}
//Get the commands to execute prisoners are unjailed
//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())) {
command = command.replaceAll("%p%", player.getName());
pl.getServer().dispatchCommand(pl.getServer().getConsoleSender(), command);
}
player.sendMessage(pl.getJailIO().getLanguageString(LangString.UNJAILED));
}
}

View File

@ -11,6 +11,7 @@ import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
@ -20,6 +21,8 @@ import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
import com.graywolf336.jail.beans.Prisoner;
/**
* Provides a variety of methods, static, that are used throughout the plugin.
*
@ -265,4 +268,39 @@ public class Util {
throw new IOException("Unable to decode class type.", e);
}
}
public static void restoreInventory(Player player, Prisoner prisoner) {
try {
Inventory content = Util.fromBase64(prisoner.getInventory());
ItemStack[] armor = Util.itemStackArrayFromBase64(prisoner.getArmor());
for(ItemStack item : armor) {
if(item == null)
continue;
else if(item.getType().toString().toLowerCase().contains("helmet"))
player.getInventory().setHelmet(item);
else if(item.getType().toString().toLowerCase().contains("chestplate"))
player.getInventory().setChestplate(item);
else if(item.getType().toString().toLowerCase().contains("leg"))
player.getInventory().setLeggings(item);
else if(item.getType().toString().toLowerCase().contains("boots"))
player.getInventory().setBoots(item);
else if (player.getInventory().firstEmpty() == -1)
player.getWorld().dropItem(player.getLocation(), item);
else
player.getInventory().addItem(item);
}
for(ItemStack item : content.getContents()) {
if(item == null) continue;
else if(player.getInventory().firstEmpty() == -1)
player.getWorld().dropItem(player.getLocation(), item);
else
player.getInventory().addItem(item);
}
} catch (IOException e) {
e.printStackTrace();
Bukkit.getLogger().severe("Unable to restore " + player.getName() + "'s inventory.");
}
}
}

View File

@ -3,6 +3,7 @@ package com.graywolf336.jail.enums;
public enum Settings {
BROADCASTJAILING("jailing.jail.broadcastJailing"),
COMMANDSONJAIL("jailing.jail.commands"),
COMMANDSONRELEASE("jailing.release.commands"),
DEBUG("system.debug"),
DEFAULTJAIL("jailing.jail.defaultJail"),
DELETEINVENTORY("jailing.jail.deleteInventory"),