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:
parent
58a092267a
commit
a33c4d4c51
5 changed files with 40 additions and 21 deletions
|
@ -5,7 +5,6 @@ import java.util.Map;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.entity.Animals;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
@ -86,9 +85,6 @@ public class ModInventories extends CoreModule<LimitedCreative> {
|
||||||
if (plugin.getPermManager().hasPermission(player, InventoryPermissions.KEEP_INVENTORY))
|
if (plugin.getPermManager().hasPermission(player, InventoryPermissions.KEEP_INVENTORY))
|
||||||
return;
|
return;
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
if (player.getVehicle() != null && player.getVehicle() instanceof Animals) {
|
|
||||||
player.leaveVehicle();
|
|
||||||
}
|
|
||||||
|
|
||||||
GameMode cgm = player.getGameMode();
|
GameMode cgm = player.getGameMode();
|
||||||
if (gm == GameMode.ADVENTURE && !config.getSeparateAdventure())
|
if (gm == GameMode.ADVENTURE && !config.getSeparateAdventure())
|
||||||
|
|
|
@ -179,9 +179,6 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
|
||||||
* - LEVER
|
* - LEVER
|
||||||
* - STONE_BUTTON
|
* - STONE_BUTTON
|
||||||
* - WOOD_BUTTON
|
* - WOOD_BUTTON
|
||||||
* - WORKBENCH
|
|
||||||
* - ANVIL
|
|
||||||
* - ENCHANTMENT_TABLE
|
|
||||||
*/
|
*/
|
||||||
@IsConfigurationNode(name = "interact", order = 600)
|
@IsConfigurationNode(name = "interact", order = 600)
|
||||||
public BlackList getBlockInteraction() {
|
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.LEVER));
|
||||||
interactList.add(new BlackList.Blacklisted(Material.STONE_BUTTON));
|
interactList.add(new BlackList.Blacklisted(Material.STONE_BUTTON));
|
||||||
interactList.add(new BlackList.Blacklisted(Material.WOOD_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;
|
return interactList;
|
||||||
|
@ -210,23 +204,14 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
|
||||||
* if you're not sure).
|
* if you're not sure).
|
||||||
*
|
*
|
||||||
* default:
|
* default:
|
||||||
* - MINECART_CHEST
|
|
||||||
* - MINECART_FURNACE
|
|
||||||
* - MINECART_HOPPER
|
|
||||||
* - ITEM_FRAME
|
* - ITEM_FRAME
|
||||||
* - VILLAGER
|
|
||||||
*/
|
*/
|
||||||
@IsConfigurationNode(name = "entityInteract", order = 650)
|
@IsConfigurationNode(name = "entityInteract", order = 650)
|
||||||
public BlackListEntity getBlockEntityInteraction() {
|
public BlackListEntity getBlockEntityInteraction() {
|
||||||
if (interactEntityList == null) {
|
if (interactEntityList == null) {
|
||||||
interactEntityList = new BlackListEntity(config.getList("entityInteract"));
|
interactEntityList = new BlackListEntity(config.getList("entityInteract"));
|
||||||
if (!config.contains("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.VILLAGER));
|
||||||
interactEntityList.add(new BlackListEntity.Blacklisted(EntityType.HORSE));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return interactEntityList;
|
return interactEntityList;
|
||||||
|
|
|
@ -20,6 +20,8 @@ package de.jaschastarke.minecraft.limitedcreative.limits;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
import org.bukkit.permissions.PermissionDefault;
|
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);
|
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
|
@IsChildPermission
|
||||||
public static final IPermission CHEST = new BasicPermission(PARENT, "chest", PermissionDefault.FALSE);
|
public static final IPermission CHEST = new BasicPermission(PARENT, "chest", PermissionDefault.FALSE);
|
||||||
|
@ -108,6 +110,12 @@ public class NoLimitPermissions extends SimplePermissionContainerNode {
|
||||||
@IsChildPermission
|
@IsChildPermission
|
||||||
public static final IPermission STATS_POTION = new BasicPermission(PARENT, "potion", PermissionDefault.FALSE);
|
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) {
|
public static IDynamicPermission INTERACT(Block block) {
|
||||||
return new MaterialPermission(BASE_INTERACT, new MaterialData(block.getType(), block.getData()));
|
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()));
|
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 {
|
public static class MaterialPermission extends DynamicPermission {
|
||||||
private MaterialData md;
|
private MaterialData md;
|
||||||
public MaterialPermission(IAbstractPermission parent, MaterialData m) {
|
public MaterialPermission(IAbstractPermission parent, MaterialData m) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
import org.bukkit.event.player.PlayerExpChangeEvent;
|
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
|
@EventHandler
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
if (event.getEntity() instanceof Player) {
|
if (event.getEntity() instanceof Player) {
|
||||||
|
@ -252,4 +265,7 @@ public class PlayerListener implements Listener {
|
||||||
private boolean checkPermission(PlayerEvent event, IDynamicPermission perm) {
|
private boolean checkPermission(PlayerEvent event, IDynamicPermission perm) {
|
||||||
return mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), perm);
|
return mod.getPlugin().getPermManager().hasPermission(event.getPlayer(), perm);
|
||||||
}
|
}
|
||||||
|
private boolean checkPermission(Player player, IDynamicPermission perm) {
|
||||||
|
return mod.getPlugin().getPermManager().hasPermission(player, perm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.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
|
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.chest: Access to chests is not allowed in creative mode
|
||||||
blocked.survival_flying: You should stay on ground, when leaving a creative-area
|
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
|
blocked.outside_place: You can not place blocks outside of the gamemode-area
|
||||||
|
|
Loading…
Reference in a new issue