Fixed enderchests and item dropping. close #57, close #55, close #52

This commit is contained in:
t3hk0d3 2012-10-31 22:18:16 +04:00
parent 13412e58d9
commit 12b19f134c
2 changed files with 17 additions and 6 deletions

View File

@ -24,6 +24,7 @@ import org.bukkit.block.BlockState;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.*;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
@ -60,7 +61,7 @@ public abstract class ModifyworldListener implements Listener {
return getEntityName(((ComplexEntityPart) entity).getParent());
}
String entityName = entity.getType().toString().toLowerCase().replace("_", "");
String entityName = formatEnumString(entity.getType().toString());
if (entity instanceof Item) {
entityName = getItemPermission(((Item) entity).getItemStack());
@ -83,10 +84,14 @@ public abstract class ModifyworldListener implements Listener {
return category.getNameDot() + entityName;
}
private String getInventoryTypePermission(InventoryType type) {
return formatEnumString(type.name());
}
// Functional programming fuck yeah
private String getMaterialPermission(Material type) {
return this.useMaterialNames ? type.name().toLowerCase().replace("_", "") : Integer.toString(type.getId());
return this.useMaterialNames ? formatEnumString(type.name()) : Integer.toString(type.getId());
}
private String getMaterialPermission(Material type, byte metadata) {
@ -162,6 +167,8 @@ public abstract class ModifyworldListener implements Listener {
return (getMaterialPermission((Material) obj));
} else if (obj instanceof Block) {
return (getBlockPermission((Block) obj));
} else if (obj instanceof InventoryType) {
return getInventoryTypePermission((InventoryType)obj);
}
return (obj.toString());
@ -170,4 +177,8 @@ public abstract class ModifyworldListener implements Listener {
private void registerEvents(Plugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
private String formatEnumString(String enumName) {
return enumName.toLowerCase().replace("_", "");
}
}

View File

@ -182,14 +182,14 @@ public class PlayerListener extends ModifyworldListener {
if (holder instanceof Player || // do not track inter-inventory stuff
event.getRawSlot() >= event.getView().getTopInventory().getSize() || // top inventory only
event.getSlotType() == InventoryType.SlotType.OUTSIDE) { // do not track drop
event.getSlotType() == InventoryType.SlotType.OUTSIDE || // do not track drop
event.getSlot() == -999) { // temporary fix for bukkit bug (BUKKIT-2768)
return;
}
ItemStack take = holder.getInventory().getItem(event.getSlot());
ItemStack take = event.getInventory().getItem(event.getSlot());
String action;
String op;
ItemStack item;
if (take == null) {
@ -202,7 +202,7 @@ public class PlayerListener extends ModifyworldListener {
Player player = (Player) event.getWhoClicked();
if (permissionDenied(player, "modifyworld.items", action, item, "of", holder)) {
if (permissionDenied(player, "modifyworld.items", action, item, "of", event.getInventory().getType())) {
event.setCancelled(true);
}
}