mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-01-07 07:41:03 +00:00
[trunk] Renamed infinite to unlimited
Please change your permissions and config if you have used this. New Command: /unlimited [item] <player> Allows a player to enable unlimited placing for one item. Can be used on other players. The permission essentials.unlimited.placing still enables it for all items. git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1108 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
parent
25f09c792d
commit
9df79032ea
6 changed files with 151 additions and 65 deletions
|
@ -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<Integer> 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<Integer> 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() {
|
||||
|
|
|
@ -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<Integer> whitelist = Essentials.getSettings().getInfiniteWhitelist();
|
||||
boolean unlimitedForUser = user.hasUnlimited(new ItemStack(event.getBucket()));
|
||||
if (user.isAuthorized("essentials.unlimited.buckets") || unlimitedForUser) {
|
||||
List<Integer> 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() {
|
||||
|
|
|
@ -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<Integer> getInfiniteWhitelist()
|
||||
public ArrayList<Integer> getUnlimitedWhitelist()
|
||||
{
|
||||
ArrayList<Integer> infiniteWhitelist = new ArrayList<Integer>();
|
||||
for (String itemName : config.getString("infinite.whitelist", "").split(",")) {
|
||||
ArrayList<Integer> unlimitedWhitelist = new ArrayList<Integer>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<User>
|
|||
{
|
||||
return !Essentials.getSettings().itemSpawnBlacklist().contains(itemId);
|
||||
}
|
||||
|
||||
public boolean hasUnlimited(ItemStack stack) {
|
||||
if (!data.containsKey("unlimited")) {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Integer> items = (List<Integer>)data.get("unlimited");
|
||||
return items.contains(stack.getTypeId());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUnlimited(ItemStack stack, boolean b) {
|
||||
List<Integer> items = new ArrayList<Integer>();
|
||||
if (data.containsKey("unlimited")) {
|
||||
items = (List<Integer>)data.get("unlimited");
|
||||
}
|
||||
items.remove(stack.getTypeId());
|
||||
if (b) {
|
||||
items.add(stack.getTypeId());
|
||||
}
|
||||
data.put("unlimited", items);
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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] <player>");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue