diff --git a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java index 6adfa4818..359753733 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java @@ -165,47 +165,48 @@ public class EssentialsBlockListener extends BlockListener return; } } - if (Essentials.getSettings().isInfinitePlacingEnabled()) { + if (Essentials.getSettings().isUnlimitedPlacingEnabled()) { final User user = User.get(event.getPlayer()); - if (user.isAuthorized("essentials.infinite.placing")) { - final ItemStack is = event.getItemInHand(); - if (is.getType() == Material.AIR) { - is.setType(event.getBlockPlaced().getType()); - } - switch(is.getType()) { - case WOODEN_DOOR: - is.setType(Material.WOOD_DOOR); - break; - case IRON_DOOR_BLOCK: - is.setType(Material.IRON_DOOR); - break; - case SIGN_POST: - case WALL_SIGN: - is.setType(Material.SIGN); - break; - case CROPS: - is.setType(Material.SEEDS); - break; - case CAKE_BLOCK: - is.setType(Material.CAKE); - break; - case BED_BLOCK: - is.setType(Material.BED); - break; - case REDSTONE_WIRE: - is.setType(Material.REDSTONE); - break; - case REDSTONE_TORCH_OFF: - is.setType(Material.REDSTONE_TORCH_ON); - break; - case DIODE_BLOCK_OFF: - case DIODE_BLOCK_ON: - is.setType(Material.DIODE); - break; - } - List whitelist = Essentials.getSettings().getInfiniteWhitelist(); + final ItemStack is = event.getItemInHand(); + if (is.getType() == Material.AIR) { + is.setType(event.getBlockPlaced().getType()); + } + switch(is.getType()) { + case WOODEN_DOOR: + is.setType(Material.WOOD_DOOR); + break; + case IRON_DOOR_BLOCK: + is.setType(Material.IRON_DOOR); + break; + case SIGN_POST: + case WALL_SIGN: + is.setType(Material.SIGN); + break; + case CROPS: + is.setType(Material.SEEDS); + break; + case CAKE_BLOCK: + is.setType(Material.CAKE); + break; + case BED_BLOCK: + is.setType(Material.BED); + break; + case REDSTONE_WIRE: + is.setType(Material.REDSTONE); + break; + case REDSTONE_TORCH_OFF: + is.setType(Material.REDSTONE_TORCH_ON); + break; + case DIODE_BLOCK_OFF: + case DIODE_BLOCK_ON: + is.setType(Material.DIODE); + break; + } + boolean unlimitedForUser = user.hasUnlimited(is); + if (user.isAuthorized("essentials.unlimited.placing") || unlimitedForUser) { + List whitelist = Essentials.getSettings().getUnlimitedWhitelist(); if (whitelist.isEmpty() || whitelist.contains(is.getTypeId()) || - user.isAuthorized("essentials.infinite.whitelist.override")) { + user.isAuthorized("essentials.unlimited.whitelist.override") || unlimitedForUser) { is.setAmount(1); Essentials.getStatic().getScheduler().scheduleSyncDelayedTask(Essentials.getStatic(), new Runnable() { diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index ad3dc0aee..731c89d83 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -397,10 +397,11 @@ public class EssentialsPlayerListener extends PlayerListener @Override public void onPlayerEggThrow(PlayerEggThrowEvent event) { - if (Essentials.getSettings().isInfiniteEggThrowEnabled()) { + if (Essentials.getSettings().isUnlimitedEggThrowEnabled()) { User user = User.get(event.getPlayer()); - if (user.isAuthorized("essentials.infinite.eggthrow")) { - user.getInventory().addItem(new ItemStack(Material.EGG, 1)); + ItemStack is = new ItemStack(Material.EGG, 1); + if (user.isAuthorized("essentials.unlimited.eggthrow") || user.hasUnlimited(is)) { + user.getInventory().addItem(is); user.updateInventory(); } } @@ -408,12 +409,14 @@ public class EssentialsPlayerListener extends PlayerListener @Override public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) { - if (Essentials.getSettings().isInfiniteBucketsEnabled()) { + if (Essentials.getSettings().isUnlimitedBucketsEnabled()) { final User user = User.get(event.getPlayer()); - if (user.isAuthorized("essentials.infinite.buckets")) { - List whitelist = Essentials.getSettings().getInfiniteWhitelist(); + boolean unlimitedForUser = user.hasUnlimited(new ItemStack(event.getBucket())); + if (user.isAuthorized("essentials.unlimited.buckets") || unlimitedForUser) { + List whitelist = Essentials.getSettings().getUnlimitedWhitelist(); if (whitelist.isEmpty() || whitelist.contains(event.getBucket().getId()) || - user.isAuthorized("essentials.infinite.whitelist.override")) { + user.isAuthorized("essentials.unlimited.whitelist.override") || + unlimitedForUser) { event.getItemStack().setType(event.getBucket()); Essentials.getStatic().getScheduler().scheduleSyncDelayedTask(Essentials.getStatic(), new Runnable() { diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index a83116e52..3475dcf60 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -434,22 +434,22 @@ public class Settings implements IConf return epBreakList; } - boolean isInfinitePlacingEnabled() { - return config.getBoolean("infinite.placing",false); + boolean isUnlimitedPlacingEnabled() { + return config.getBoolean("unlimited.placing",false); } - boolean isInfiniteEggThrowEnabled() { - return config.getBoolean("infinite.eggthrow",false); + boolean isUnlimitedEggThrowEnabled() { + return config.getBoolean("unlimited.eggthrow",false); } - boolean isInfiniteBucketsEnabled() { - return config.getBoolean("infinite.buckets",false); + boolean isUnlimitedBucketsEnabled() { + return config.getBoolean("unlimited.buckets",false); } - public ArrayList getInfiniteWhitelist() + public ArrayList getUnlimitedWhitelist() { - ArrayList infiniteWhitelist = new ArrayList(); - for (String itemName : config.getString("infinite.whitelist", "").split(",")) { + ArrayList unlimitedWhitelist = new ArrayList(); + for (String itemName : config.getString("unlimited.whitelist", "").split(",")) { itemName = itemName.trim(); if (itemName.isEmpty()) { continue; @@ -457,11 +457,11 @@ public class Settings implements IConf ItemStack is; try { is = ItemDb.get(itemName); - infiniteWhitelist.add(is.getTypeId()); + unlimitedWhitelist.add(is.getTypeId()); } catch (Exception ex) { - logger.log(Level.SEVERE, "Unknown item " + itemName + " in infinite whitelist."); + logger.log(Level.SEVERE, "Unknown item " + itemName + " in unlimited whitelist."); } } - return infiniteWhitelist; + return unlimitedWhitelist; } } diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index 6038e8b1c..d7e3686ea 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -8,6 +8,7 @@ import com.earth2me.essentials.commands.IEssentialsCommand; import net.minecraft.server.EntityHuman; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.*; +import org.bukkit.inventory.ItemStack; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.SafeConstructor; import org.yaml.snakeyaml.reader.UnicodeReader; @@ -696,4 +697,27 @@ public class User extends PlayerExtension implements Comparable { return !Essentials.getSettings().itemSpawnBlacklist().contains(itemId); } + + public boolean hasUnlimited(ItemStack stack) { + if (!data.containsKey("unlimited")) { + return false; + } + @SuppressWarnings("unchecked") + List items = (List)data.get("unlimited"); + return items.contains(stack.getTypeId()); + } + + @SuppressWarnings("unchecked") + public void setUnlimited(ItemStack stack, boolean b) { + List items = new ArrayList(); + if (data.containsKey("unlimited")) { + items = (List)data.get("unlimited"); + } + items.remove(stack.getTypeId()); + if (b) { + items.add(stack.getTypeId()); + } + data.put("unlimited", items); + flush(); + } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java new file mode 100644 index 000000000..28c0a6e7f --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java @@ -0,0 +1,58 @@ +package com.earth2me.essentials.commands; + +import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.ItemDb; +import com.earth2me.essentials.User; +import org.bukkit.ChatColor; +import org.bukkit.Server; +import org.bukkit.inventory.ItemStack; + +public class Commandunlimited extends EssentialsCommand +{ + public Commandunlimited() + { + super("unlimited"); + } + + @Override + public void run(Server server, Essentials parent, User user, String commandLabel, String[] args) throws Exception + { + if (args.length < 1) + { + user.sendMessage("§cUsage: /" + commandLabel + " [item] "); + return; + } + ItemStack stack = ItemDb.get(args[0]); + + if(!user.isAuthorized("essentials.infinite.whitelist.override") && + Essentials.getSettings().getUnlimitedWhitelist().contains(stack.getTypeId())) + { + user.sendMessage(ChatColor.RED + "You are not allowed to spawn that item"); + return; + } + User target = user; + + if (args.length > 1 && user.isAuthorized("essentials.unlimited.others")) { + target = getPlayer(server, args, 1); + } + + String itemName = stack.getType().name().toLowerCase().replace('_', ' '); + + if (target.hasUnlimited(stack)) { + if (user != target) { + user.sendMessage("§7Disable unlimited placing of " + itemName + " for " + user.getDisplayName() + "."); + } + target.sendMessage("§7Disable unlimited placing of " + itemName + " for " + user.getDisplayName() + "."); + target.setUnlimited(stack, false); + return; + } + user.charge(this); + if (user != target) { + user.sendMessage("§7Giving unlimited amount of " + itemName + " to " + user.getDisplayName() + "."); + } + target.sendMessage("§7Giving unlimited amount of " + itemName + " to " + user.getDisplayName() + "."); + target.getInventory().addItem(stack); + target.setUnlimited(stack, true); + } +} + diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index e9bb9a85c..c0913b37a 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -155,16 +155,16 @@ per-warp-permission: false # Sort output of /list command by groups sort-list-by-groups: false -# Infinite placement of blocks, throwing of eggs, using of buckets -infinite: - # Players need also permission essentials.infinite.placing +# Unlimited placement of blocks, throwing of eggs, using of buckets +unlimited: + # Players need also permission essentials.unlimited.placing placing: false - # permission essentials.infinite.eggthrow + # permission essentials.unlimited.eggthrow eggthrow: false - # permission essentials.infinite.buckets + # permission essentials.unlimited.buckets buckets: false - # Use this whitelist to restrict the use of infinite placing and buckets - # Permission essentials.infinite.whitelist.override let players ignore this list + # Use this whitelist to restrict the use of unlimited placing and buckets + # Permission essentials.unlimited.whitelist.override let players ignore this list whitelist: # example: (You can use ids or names from items.csv) # whitelist: cobblestone, dirt, waterbucket