New Inventory-Blocking, that doesn't require horse blocking any longer.

Can be bypassed with a dynamic permission (see http://dev.bukkit.org/bukkit-plugins/limited-creative/pages/permissions/#w-additional-dynamic-permissions)
This commit is contained in:
Jascha Starke 2013-07-29 10:22:39 +02:00
parent 58a092267a
commit a33c4d4c51
5 changed files with 40 additions and 21 deletions

View file

@ -5,7 +5,6 @@ import java.util.Map;
import java.util.WeakHashMap;
import org.bukkit.GameMode;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -86,9 +85,6 @@ public class ModInventories extends CoreModule<LimitedCreative> {
if (plugin.getPermManager().hasPermission(player, InventoryPermissions.KEEP_INVENTORY))
return;
player.closeInventory();
if (player.getVehicle() != null && player.getVehicle() instanceof Animals) {
player.leaveVehicle();
}
GameMode cgm = player.getGameMode();
if (gm == GameMode.ADVENTURE && !config.getSeparateAdventure())

View file

@ -179,9 +179,6 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
* - LEVER
* - STONE_BUTTON
* - WOOD_BUTTON
* - WORKBENCH
* - ANVIL
* - ENCHANTMENT_TABLE
*/
@IsConfigurationNode(name = "interact", order = 600)
public BlackList getBlockInteraction() {
@ -193,9 +190,6 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
interactList.add(new BlackList.Blacklisted(Material.LEVER));
interactList.add(new BlackList.Blacklisted(Material.STONE_BUTTON));
interactList.add(new BlackList.Blacklisted(Material.WOOD_BUTTON));
interactList.add(new BlackList.Blacklisted(Material.WORKBENCH));
interactList.add(new BlackList.Blacklisted(Material.ANVIL));
interactList.add(new BlackList.Blacklisted(Material.ENCHANTMENT_TABLE));
}
}
return interactList;
@ -210,23 +204,14 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
* if you're not sure).
*
* default:
* - MINECART_CHEST
* - MINECART_FURNACE
* - MINECART_HOPPER
* - ITEM_FRAME
* - VILLAGER
*/
@IsConfigurationNode(name = "entityInteract", order = 650)
public BlackListEntity getBlockEntityInteraction() {
if (interactEntityList == null) {
interactEntityList = new BlackListEntity(config.getList("entityInteract"));
if (!config.contains("entityInteract")) {
interactEntityList.add(new BlackListEntity.Blacklisted(EntityType.MINECART_CHEST));
interactEntityList.add(new BlackListEntity.Blacklisted(EntityType.MINECART_FURNACE));
interactEntityList.add(new BlackListEntity.Blacklisted(EntityType.MINECART_HOPPER));
interactEntityList.add(new BlackListEntity.Blacklisted(EntityType.ITEM_FRAME));
interactEntityList.add(new BlackListEntity.Blacklisted(EntityType.VILLAGER));
interactEntityList.add(new BlackListEntity.Blacklisted(EntityType.HORSE));
}
}
return interactEntityList;

View file

@ -20,6 +20,8 @@ package de.jaschastarke.minecraft.limitedcreative.limits;
import java.util.Collection;
import org.bukkit.block.Block;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.material.MaterialData;
import org.bukkit.permissions.PermissionDefault;
@ -50,7 +52,7 @@ public class NoLimitPermissions extends SimplePermissionContainerNode {
public static final IPermission ALL = new ParentPermissionContainerNode(PARENT, "*", PermissionDefault.OP, PARENT);
/**
* Allows bypassing the "do not open a chest"-limitation
* Allows bypassing the "do not open a chest" and "do not open inventory"-limitation
*/
@IsChildPermission
public static final IPermission CHEST = new BasicPermission(PARENT, "chest", PermissionDefault.FALSE);
@ -108,6 +110,12 @@ public class NoLimitPermissions extends SimplePermissionContainerNode {
@IsChildPermission
public static final IPermission STATS_POTION = new BasicPermission(PARENT, "potion", PermissionDefault.FALSE);
public static IDynamicPermission INVENTORY(Inventory inv) {
return new InventoryPermission(CHEST, inv.getType());
}
public static IDynamicPermission INVENTORY(InventoryType invtype) {
return new InventoryPermission(CHEST, invtype);
}
public static IDynamicPermission INTERACT(Block block) {
return new MaterialPermission(BASE_INTERACT, new MaterialData(block.getType(), block.getData()));
}
@ -121,6 +129,19 @@ public class NoLimitPermissions extends SimplePermissionContainerNode {
return new MaterialPermission(BASE_BREAK, new MaterialData(block.getType(), block.getData()));
}
public static class InventoryPermission extends DynamicPermission {
private InventoryType it;
public InventoryPermission(IAbstractPermission parent, InventoryType t) {
super(parent);
it = t;
}
@Override
protected void buildPermissionsToCheck(Collection<IAbstractPermission> perms) {
perms.add(new BasicPermission(parent, it.toString()));
}
}
public static class MaterialPermission extends DynamicPermission {
private MaterialData md;
public MaterialPermission(IAbstractPermission parent, MaterialData m) {

View file

@ -34,6 +34,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerExpChangeEvent;
@ -77,6 +78,18 @@ public class PlayerListener implements Listener {
}
}
@EventHandler
public void onInventoryOpen(InventoryOpenEvent event) {
if (event.getPlayer() instanceof Player) {
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
if (checkPermission((Player) event.getPlayer(), NoLimitPermissions.INVENTORY(event.getInventory())))
return;
event.setCancelled(true);
((Player) event.getPlayer()).sendMessage(mod.getPlugin().getLocale().trans("blocked.inventory"));
}
}
}
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof Player) {
@ -252,4 +265,7 @@ public class PlayerListener implements Listener {
private boolean checkPermission(PlayerEvent event, IDynamicPermission perm) {
return mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), perm);
}
private boolean checkPermission(Player player, IDynamicPermission perm) {
return mod.getPlugin().getPermManager().hasPermission(player, perm);
}
}

View file

@ -36,6 +36,7 @@ cmdblock.blocked.not_console: This command can not be used from console
exception.config.material_not_found: (Config) Material with name/id "{0}" was not found.
exception.region.not_optional: You can not be {0} in that area
blocked.inventory: Opening inventories is not allowed in creative mode
blocked.chest: Access to chests is not allowed in creative mode
blocked.survival_flying: You should stay on ground, when leaving a creative-area
blocked.outside_place: You can not place blocks outside of the gamemode-area