1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-09-30 16:19:11 +02:00

Modified BetterLocation, and new Permission-System

This commit is contained in:
snowleo
2012-02-05 17:19:32 +01:00
parent 8080abacd6
commit 8ab5bad988
98 changed files with 874 additions and 710 deletions

View File

@@ -19,7 +19,6 @@ package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.*; import com.earth2me.essentials.api.*;
import com.earth2me.essentials.craftbukkit.BetterLocation;
import com.earth2me.essentials.listener.*; import com.earth2me.essentials.listener.*;
import com.earth2me.essentials.perm.PermissionsHandler; import com.earth2me.essentials.perm.PermissionsHandler;
import com.earth2me.essentials.register.payment.Methods; import com.earth2me.essentials.register.payment.Methods;
@@ -235,7 +234,6 @@ public class Essentials extends JavaPlugin implements IEssentials
i18n.onDisable(); i18n.onDisable();
Economy.setEss(null); Economy.setEss(null);
Trade.closeLog(); Trade.closeLog();
BetterLocation.cleanup();
} }
@Override @Override

View File

@@ -113,7 +113,7 @@ public class EssentialsCommandHandler implements ICommandHandler
} }
// Check authorization // Check authorization
if (user != null && !user.isAuthorized(cmd)) if (sender != null && cmd.isAuthorized(sender))
{ {
LOGGER.log(Level.WARNING, _("deniedAccessCommand", user.getName())); LOGGER.log(Level.WARNING, _("deniedAccessCommand", user.getName()));
user.sendMessage(_("noAccessCommand")); user.sendMessage(_("noAccessCommand"));

View File

@@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import com.earth2me.essentials.user.UserData.TimestampType; import com.earth2me.essentials.user.UserData.TimestampType;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@@ -42,7 +43,7 @@ public class EssentialsTimer implements Runnable
settings.unlock(); settings.unlock();
} }
// New mail notification // New mail notification
if (user != null && !mailDisabled && user.isAuthorized("essentials.mail") && !user.gotMailInfo()) if (user != null && !mailDisabled && Permissions.MAIL.isAuthorized(user) && !user.gotMailInfo())
{ {
final List<String> mail = user.getMails(); final List<String> mail = user.getMails();
if (mail != null && !mail.isEmpty()) if (mail != null && !mail.isEmpty())

View File

@@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IItemDb; import com.earth2me.essentials.api.IItemDb;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@@ -77,7 +78,7 @@ public class ItemDb implements IItemDb
else else
{ {
final int oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize(); final int oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize();
if (oversizedStackSize > 0 && user.isAuthorized("essentials.oversizedstacks")) if (oversizedStackSize > 0 && Permissions.OVERSIZEDSTACKS.isAuthorized(user))
{ {
stack.setAmount(oversizedStackSize); stack.setAmount(oversizedStackSize);
} }

View File

@@ -65,7 +65,7 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett
{ {
throw new Exception(_("jailNotExist")); throw new Exception(_("jailNotExist"));
} }
Location loc = getData().getJails().get(jailName.toLowerCase(Locale.ENGLISH)); Location loc = getData().getJails().get(jailName.toLowerCase(Locale.ENGLISH)).getBukkitLocation();
if (loc == null || loc.getWorld() == null) if (loc == null || loc.getWorld() == null)
{ {
throw new Exception(_("jailNotExist")); throw new Exception(_("jailNotExist"));
@@ -149,9 +149,9 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett
{ {
if (getData().getJails() == null) if (getData().getJails() == null)
{ {
getData().setJails(new HashMap<String, Location>()); getData().setJails(new HashMap<String, com.earth2me.essentials.storage.Location>());
} }
getData().getJails().put(jailName.toLowerCase(Locale.ENGLISH), loc); getData().getJails().put(jailName.toLowerCase(Locale.ENGLISH), new com.earth2me.essentials.storage.Location(loc));
} }
finally finally
{ {

View File

@@ -5,6 +5,7 @@ import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.ITeleport; import com.earth2me.essentials.api.ITeleport;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.commands.NotEnoughArgumentsException; import com.earth2me.essentials.commands.NotEnoughArgumentsException;
import com.earth2me.essentials.perm.Permissions;
import com.earth2me.essentials.user.CooldownException; import com.earth2me.essentials.user.CooldownException;
import com.earth2me.essentials.user.UserData.TimestampType; import com.earth2me.essentials.user.UserData.TimestampType;
import java.util.Calendar; import java.util.Calendar;
@@ -152,7 +153,7 @@ public class Teleport implements Runnable, ITeleport
{ {
try try
{ {
user.checkCooldown(TimestampType.LASTTELEPORT, ess.getGroups().getTeleportCooldown(user), !check, "essentials.teleport.cooldown.bypass"); user.checkCooldown(TimestampType.LASTTELEPORT, ess.getGroups().getTeleportCooldown(user), !check, Permissions.TELEPORT_COOLDOWN_BYPASS);
} }
catch (CooldownException ex) catch (CooldownException ex)
{ {
@@ -210,7 +211,7 @@ public class Teleport implements Runnable, ITeleport
chargeFor.isAffordableFor(user); chargeFor.isAffordableFor(user);
} }
cooldown(true); cooldown(true);
if (delay <= 0 || user.isAuthorized("essentials.teleport.timer.bypass")) if (delay <= 0 || Permissions.TELEPORT_TIMER_BYPASS.isAuthorized(user))
{ {
cooldown(false); cooldown(false);
now(target, cause); now(target, cause);

View File

@@ -6,6 +6,8 @@ import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import com.earth2me.essentials.craftbukkit.SetExpFix; import com.earth2me.essentials.craftbukkit.SetExpFix;
import com.earth2me.essentials.perm.NoCommandCostPermissions;
import com.earth2me.essentials.perm.Permissions;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
@@ -63,7 +65,7 @@ public class Trade
if (getMoney() != null if (getMoney() != null
&& mon < getMoney() && mon < getMoney()
&& getMoney() > 0 && getMoney() > 0
&& !user.isAuthorized("essentials.eco.loan")) && !Permissions.ECO_LOAN.isAuthorized(user))
{ {
throw new ChargeException(_("notEnoughMoney")); throw new ChargeException(_("notEnoughMoney"));
} }
@@ -79,11 +81,10 @@ public class Trade
settings.acquireReadLock(); settings.acquireReadLock();
if (command != null && !command.isEmpty() if (command != null && !command.isEmpty()
&& !user.isAuthorized("essentials.nocommandcost.all") && !NoCommandCostPermissions.getPermission(command).isAuthorized(user)
&& !user.isAuthorized("essentials.nocommandcost." + command)
&& mon < settings.getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command) && mon < settings.getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command)
&& 0 < settings.getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command) && 0 < settings.getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command)
&& !user.isAuthorized("essentials.eco.loan")) && !Permissions.ECO_LOAN.isAuthorized(user))
{ {
throw new ChargeException(_("notEnoughMoney")); throw new ChargeException(_("notEnoughMoney"));
} }
@@ -135,7 +136,7 @@ public class Trade
if (getMoney() != null) if (getMoney() != null)
{ {
final double mon = user.getMoney(); final double mon = user.getMoney();
if (mon < getMoney() && getMoney() > 0 && !user.isAuthorized("essentials.eco.loan")) if (mon < getMoney() && getMoney() > 0 && !Permissions.ECO_LOAN.isAuthorized(user))
{ {
throw new ChargeException(_("notEnoughMoney")); throw new ChargeException(_("notEnoughMoney"));
} }
@@ -151,15 +152,14 @@ public class Trade
user.updateInventory(); user.updateInventory();
} }
if (command != null && !command.isEmpty() if (command != null && !command.isEmpty()
&& !user.isAuthorized("essentials.nocommandcost.all") && !NoCommandCostPermissions.getPermission(command).isAuthorized(user))
&& !user.isAuthorized("essentials.nocommandcost." + command))
{ {
@Cleanup @Cleanup
final ISettings settings = ess.getSettings(); final ISettings settings = ess.getSettings();
settings.acquireReadLock(); settings.acquireReadLock();
final double mon = user.getMoney(); final double mon = user.getMoney();
final double cost = settings.getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command); final double cost = settings.getData().getEconomy().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command);
if (mon < cost && cost > 0 && !user.isAuthorized("essentials.eco.loan")) if (mon < cost && cost > 0 && !Permissions.ECO_LOAN.isAuthorized(user))
{ {
throw new ChargeException(_("notEnoughMoney")); throw new ChargeException(_("notEnoughMoney"));
} }

View File

@@ -66,7 +66,7 @@ public class Warps extends StorageObjectMap<IWarp> implements IWarps
warp.acquireReadLock(); warp.acquireReadLock();
try try
{ {
return warp.getData().getLocation(); return warp.getData().getLocation().getBukkitLocation();
} }
finally finally
{ {
@@ -76,6 +76,11 @@ public class Warps extends StorageObjectMap<IWarp> implements IWarps
@Override @Override
public void setWarp(final String name, final Location loc) throws Exception public void setWarp(final String name, final Location loc) throws Exception
{
setWarp(name, new com.earth2me.essentials.storage.Location(loc));
}
public void setWarp(final String name, final com.earth2me.essentials.storage.Location loc) throws Exception
{ {
IWarp warp = getObject(name); IWarp warp = getObject(name);
if (warp == null) if (warp == null)

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.api;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.craftbukkit.DummyOfflinePlayer; import com.earth2me.essentials.craftbukkit.DummyOfflinePlayer;
import com.earth2me.essentials.perm.Permissions;
import com.earth2me.essentials.user.User; import com.earth2me.essentials.user.User;
import java.io.File; import java.io.File;
import java.util.logging.Level; import java.util.logging.Level;
@@ -141,7 +142,7 @@ public final class Economy
{ {
throw new UserDoesNotExistException(name); throw new UserDoesNotExistException(name);
} }
if (balance < 0.0 && !user.isAuthorized("essentials.eco.loan")) if (balance < 0.0 && !Permissions.ECO_LOAN.isAuthorized(user))
{ {
throw new NoLoanPermittedException(); throw new NoLoanPermittedException();
} }

View File

@@ -1,5 +1,6 @@
package com.earth2me.essentials.api; package com.earth2me.essentials.api;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
@@ -8,6 +9,8 @@ public interface IPermission
{ {
String getPermission(); String getPermission();
boolean isAuthorized(CommandSender sender);
Permission getBukkitPermission(); Permission getBukkitPermission();
PermissionDefault getPermissionDefault(); PermissionDefault getPermissionDefault();

View File

@@ -13,12 +13,6 @@ import org.bukkit.inventory.ItemStack;
public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload, IReplyTo, Comparable<IUser> public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload, IReplyTo, Comparable<IUser>
{ {
boolean isAuthorized(String node);
boolean isAuthorized(IPermission node);
//boolean isAuthorized(IEssentialsCommand cmd);
//boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix);
Player getBase(); Player getBase();
double getMoney(); double getMoney();
@@ -53,7 +47,7 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload,
ITeleport getTeleport(); ITeleport getTeleport();
void checkCooldown(UserData.TimestampType cooldownType, double cooldown, boolean set, String bypassPermission) throws CooldownException; void checkCooldown(UserData.TimestampType cooldownType, double cooldown, boolean set, IPermission bypassPermission) throws CooldownException;
boolean toggleAfk(); boolean toggleAfk();

View File

@@ -12,7 +12,7 @@ public class Commandafk extends EssentialsCommand
@Override @Override
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{ {
if (args.length > 0 && user.isAuthorized(Permissions.AFK_OTHERS)) if (args.length > 0 && Permissions.AFK_OTHERS.isAuthorized(user))
{ {
IUser afkUser = ess.getUser((Player)ess.getServer().matchPlayer(args[0])); IUser afkUser = ess.getUser((Player)ess.getServer().matchPlayer(args[0]));
if (afkUser != null) if (afkUser != null)

View File

@@ -23,7 +23,7 @@ public class Commandbalance extends EssentialsCommand
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{ {
final double bal = (args.length < 1 final double bal = (args.length < 1
|| !user.isAuthorized(Permissions.BALANCE_OTHERS) || !Permissions.BALANCE_OTHERS.isAuthorized(user)
? user ? user
: getPlayer(args, 0, true)).getMoney(); : getPlayer(args, 0, true)).getMoney();
user.sendMessage(_("balance", Util.formatCurrency(bal, ess))); user.sendMessage(_("balance", Util.formatCurrency(bal, ess)));

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Console; import com.earth2me.essentials.Console;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import com.earth2me.essentials.user.Ban; import com.earth2me.essentials.user.Ban;
import lombok.Cleanup; import lombok.Cleanup;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -22,7 +23,7 @@ public class Commandban extends EssentialsCommand
final IUser user = getPlayer(args, 0, true); final IUser user = getPlayer(args, 0, true);
if (user.isOnline()) if (user.isOnline())
{ {
if (user.isAuthorized("essentials.ban.exempt")) if (Permissions.BAN_EXEMPT.isAuthorized(user))
{ {
sender.sendMessage(_("banExempt")); sender.sendMessage(_("banExempt"));
return; return;
@@ -30,8 +31,7 @@ public class Commandban extends EssentialsCommand
} }
else else
{ {
if (sender instanceof Player if (Permissions.BAN_OFFLINE.isAuthorized(sender))
&& !ess.getUser((Player)sender).isAuthorized("essentials.ban.offline"))
{ {
sender.sendMessage(_("banExempt")); sender.sendMessage(_("banExempt"));
return; return;
@@ -57,7 +57,7 @@ public class Commandban extends EssentialsCommand
for (Player onlinePlayer : server.getOnlinePlayers()) for (Player onlinePlayer : server.getOnlinePlayers())
{ {
final IUser player = ess.getUser(onlinePlayer); final IUser player = ess.getUser(onlinePlayer);
if (player.isAuthorized("essentials.ban.notify")) if (Permissions.BAN_NOTIFY.isAuthorized(player))
{ {
onlinePlayer.sendMessage(_("playerBanned", senderName, user.getName(), banReason)); onlinePlayer.sendMessage(_("playerBanned", senderName, user.getName(), banReason));
} }

View File

@@ -1,6 +1,7 @@
package com.earth2me.essentials.commands; package com.earth2me.essentials.commands;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
@@ -21,7 +22,7 @@ public class Commandbreak extends EssentialsCommand
{ {
throw new NoChargeException(); throw new NoChargeException();
} }
if (block.getType() == Material.BEDROCK && !user.isAuthorized("essentials.break.bedrock")) if (block.getType() == Material.BEDROCK && !Permissions.BREAK_BEDROCK.isAuthorized(user))
{ {
throw new Exception("You are not allowed to destroy bedrock."); //TODO: Translation throw new Exception("You are not allowed to destroy bedrock."); //TODO: Translation
} }

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.List; import java.util.List;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -13,7 +14,7 @@ public class Commandclearinventory extends EssentialsCommand
@Override @Override
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{ {
if (args.length > 0 && user.isAuthorized("essentials.clearinventory.others")) if (args.length > 0 && Permissions.CLEARINVENTORY_OTHERS.isAuthorized(user))
{ {
//TODO: Fix fringe user match case. //TODO: Fix fringe user match case.
if (args[0].length() >= 3) if (args[0].length() >= 3)

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.Locale; import java.util.Locale;
import lombok.Cleanup; import lombok.Cleanup;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -34,7 +35,7 @@ public class Commanddelhome extends EssentialsCommand
expandedArg = args; expandedArg = args;
} }
if (expandedArg.length > 1 && (user == null || user.isAuthorized("essentials.delhome.others"))) if (expandedArg.length > 1 && (user == null || Permissions.DELHOME_OTHERS.isAuthorized(user)))
{ {
user = getPlayer(expandedArg, 0, true); user = getPlayer(expandedArg, 0, true);
name = expandedArg[1]; name = expandedArg[1];

View File

@@ -4,6 +4,7 @@ import com.earth2me.essentials.Enchantments;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.EnchantPermissions;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -29,7 +30,7 @@ public class Commandenchant extends EssentialsCommand
for (Map.Entry<String, Enchantment> entry : Enchantments.entrySet()) for (Map.Entry<String, Enchantment> entry : Enchantments.entrySet())
{ {
final String enchantmentName = entry.getValue().getName().toLowerCase(Locale.ENGLISH); final String enchantmentName = entry.getValue().getName().toLowerCase(Locale.ENGLISH);
if (enchantmentslist.contains(enchantmentName) || user.isAuthorized("essentials.enchant." + enchantmentName)) if (enchantmentslist.contains(enchantmentName) || EnchantPermissions.getPermission(enchantmentName).isAuthorized(user))
{ {
enchantmentslist.add(entry.getKey()); enchantmentslist.add(entry.getKey());
//enchantmentslist.add(enchantmentName); //enchantmentslist.add(enchantmentName);
@@ -84,7 +85,7 @@ public class Commandenchant extends EssentialsCommand
throw new Exception(_("enchantmentNotFound")); throw new Exception(_("enchantmentNotFound"));
} }
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
if (user != null && !user.isAuthorized("essentials.enchant." + enchantmentName)) if (user != null && !EnchantPermissions.getPermission(enchantmentName).isAuthorized(user))
{ {
throw new Exception(_("enchantmentPerm", enchantmentName)); throw new Exception(_("enchantmentPerm", enchantmentName));
} }

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.List; import java.util.List;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -12,7 +13,7 @@ public class Commandfeed extends EssentialsCommand
@Override @Override
protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{ {
if (args.length > 0 && user.isAuthorized("essentials.feed.others")) if (args.length > 0 && Permissions.FEED_OTHERS.isAuthorized(user))
{ {
feedOtherPlayers(user, args[0]); feedOtherPlayers(user, args[0]);
} }

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.Locale; import java.util.Locale;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -24,7 +25,7 @@ public class Commandgamemode extends EssentialsCommand
@Override @Override
protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{ {
if (args.length > 0 && !args[0].trim().isEmpty() && user.isAuthorized("essentials.gamemode.others")) if (args.length > 0 && !args[0].trim().isEmpty() && Permissions.GAMEMODE_OTHERS.isAuthorized(user))
{ {
gamemodeOtherPlayers(user, args[0]); gamemodeOtherPlayers(user, args[0]);
return; return;

View File

@@ -1,6 +1,7 @@
package com.earth2me.essentials.commands; package com.earth2me.essentials.commands;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -10,7 +11,7 @@ public class Commandgetpos extends EssentialsCommand
@Override @Override
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{ {
if (args.length > 0 && user.isAuthorized("essentials.getpos.others")) if (args.length > 0 && Permissions.GETPOS_OTHERS.isAuthorized(user))
{ {
final IUser otherUser = getPlayer(args, 0); final IUser otherUser = getPlayer(args, 0);
outputPosition(user, otherUser.getLocation(), user.getLocation()); outputPosition(user, otherUser.getLocation(), user.getLocation());

View File

@@ -1,6 +1,7 @@
package com.earth2me.essentials.commands; package com.earth2me.essentials.commands;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.GivePermissions;
import java.util.Locale; import java.util.Locale;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@@ -26,9 +27,7 @@ public class Commandgive extends EssentialsCommand
final ItemStack stack = ess.getItemDb().get(args[1], giveTo); final ItemStack stack = ess.getItemDb().get(args[1], giveTo);
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (sender instanceof Player if (!GivePermissions.getPermission(stack.getType()).isAuthorized(sender))
&& (!ess.getUser((Player)sender).isAuthorized("essentials.give.item-" + itemname)
&& !ess.getUser((Player)sender).isAuthorized("essentials.give.item-" + stack.getTypeId())))
{ {
throw new Exception(ChatColor.RED + "You are not allowed to spawn the item " + itemname); throw new Exception(ChatColor.RED + "You are not allowed to spawn the item " + itemname);
} }

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -22,7 +23,7 @@ public class Commandgod extends EssentialsCommand
@Override @Override
protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{ {
if (args.length > 0 && !args[0].trim().isEmpty() && user.isAuthorized("essentials.god.others")) if (args.length > 0 && !args[0].trim().isEmpty() && Permissions.GOD_OTHERS.isAuthorized(user))
{ {
godOtherPlayers(user, args[0]); godOtherPlayers(user, args[0]);
return; return;

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import com.earth2me.essentials.user.UserData.TimestampType; import com.earth2me.essentials.user.UserData.TimestampType;
import java.util.List; import java.util.List;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -14,15 +15,15 @@ public class Commandheal extends EssentialsCommand
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{ {
if (args.length > 0 && user.isAuthorized("essentials.heal.others")) if (args.length > 0 && Permissions.HEAL_OTHERS.isAuthorized(user))
{ {
user.checkCooldown(TimestampType.LASTHEAL, ess.getGroups().getHealCooldown(user), true, "essentials.heal.cooldown.bypass"); user.checkCooldown(TimestampType.LASTHEAL, ess.getGroups().getHealCooldown(user), true, Permissions.HEAL_COOLDOWN_BYPASS);
healOtherPlayers(user, args[0]); healOtherPlayers(user, args[0]);
return; return;
} }
user.checkCooldown(TimestampType.LASTHEAL, ess.getGroups().getHealCooldown(user), true, "essentials.heal.cooldown.bypass"); user.checkCooldown(TimestampType.LASTHEAL, ess.getGroups().getHealCooldown(user), true, Permissions.HEAL_COOLDOWN_BYPASS);
user.setHealth(20); user.setHealth(20);
user.setFoodLevel(20); user.setFoodLevel(20);

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -22,7 +23,7 @@ public class Commandhelpop extends EssentialsCommand
for (Player onlinePlayer : server.getOnlinePlayers()) for (Player onlinePlayer : server.getOnlinePlayers())
{ {
final IUser player = ess.getUser(onlinePlayer); final IUser player = ess.getUser(onlinePlayer);
if (!player.isAuthorized("essentials.helpop.receive")) if (!Permissions.HELPOP_RECEIVE.isAuthorized(player))
{ {
continue; continue;
} }

View File

@@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade; import com.earth2me.essentials.Trade;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.bukkit.Location; import org.bukkit.Location;
@@ -24,7 +25,7 @@ public class Commandhome extends EssentialsCommand
if (args.length > 0) if (args.length > 0)
{ {
nameParts = args[0].split(":"); nameParts = args[0].split(":");
if (nameParts[0].length() == args[0].length() || !user.isAuthorized("essentials.home.others")) if (nameParts[0].length() == args[0].length() || !Permissions.HOME_OTHERS.isAuthorized(user))
{ {
homeName = nameParts[0]; homeName = nameParts[0];
} }

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.ItemPermissions;
import java.util.Locale; import java.util.Locale;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@@ -20,8 +21,7 @@ public class Commanditem extends EssentialsCommand
final ItemStack stack = ess.getItemDb().get(args[0], user); final ItemStack stack = ess.getItemDb().get(args[0], user);
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (!user.isAuthorized("essentials.itemspawn.item-" + itemname) if (!ItemPermissions.getPermission(stack.getType()).isAuthorized(user))
&& !user.isAuthorized("essentials.itemspawn.item-" + stack.getTypeId()))
{ {
throw new Exception(_("cantSpawnItem", itemname)); throw new Exception(_("cantSpawnItem", itemname));
} }

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Console; import com.earth2me.essentials.Console;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -18,7 +19,7 @@ public class Commandkick extends EssentialsCommand
} }
final IUser user = getPlayer(args, 0); final IUser user = getPlayer(args, 0);
if (user.isAuthorized("essentials.kick.exempt")) if (Permissions.KICK_EXEMPT.isAuthorized(user))
{ {
throw new Exception(_("kickExempt")); throw new Exception(_("kickExempt"));
} }
@@ -29,7 +30,7 @@ public class Commandkick extends EssentialsCommand
for (Player onlinePlayer : server.getOnlinePlayers()) for (Player onlinePlayer : server.getOnlinePlayers())
{ {
final IUser player = ess.getUser(onlinePlayer); final IUser player = ess.getUser(onlinePlayer);
if (player.isAuthorized("essentials.kick.notify")) if (Permissions.KICK_NOTIFY.isAuthorized(player))
{ {
onlinePlayer.sendMessage(_("playerKicked", senderName, user.getName(), kickReason)); onlinePlayer.sendMessage(_("playerKicked", senderName, user.getName(), kickReason));
} }

View File

@@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade; import com.earth2me.essentials.Trade;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.KitPermissions;
import com.earth2me.essentials.settings.Kit; import com.earth2me.essentials.settings.Kit;
import java.util.Collection; import java.util.Collection;
import java.util.Locale; import java.util.Locale;
@@ -25,7 +26,7 @@ public class Commandkit extends EssentialsCommand
{ {
for (String kitName : kitList) for (String kitName : kitList)
{ {
if (!user.isAuthorized("essentials.kit." + kitName)) if (!KitPermissions.getPermission(kitName).isAuthorized(user))
{ {
kitList.remove(kitName); kitList.remove(kitName);
} }
@@ -39,7 +40,7 @@ public class Commandkit extends EssentialsCommand
final String kitName = args[0].toLowerCase(Locale.ENGLISH); final String kitName = args[0].toLowerCase(Locale.ENGLISH);
final Kit kit = ess.getKits().getKit(kitName); final Kit kit = ess.getKits().getKit(kitName);
if (!user.isAuthorized("essentials.kit." + kitName)) if (!KitPermissions.getPermission(kitName).isAuthorized(user))
{ {
throw new Exception(_("noKitPermission", "essentials.kit." + kitName)); throw new Exception(_("noKitPermission", "essentials.kit." + kitName));
} }

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.*; import java.util.*;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -14,14 +15,7 @@ public class Commandlist extends EssentialsCommand
public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{ {
boolean showhidden = false; boolean showhidden = false;
if (sender instanceof Player) if (Permissions.LIST_HIDDEN.isAuthorized(sender))
{
if (ess.getUser((Player)sender).isAuthorized("essentials.list.hidden"))
{
showhidden = true;
}
}
else
{ {
showhidden = true; showhidden = true;
} }

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.List; import java.util.List;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -31,7 +32,7 @@ public class Commandmail extends EssentialsCommand
} }
if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) if (args.length >= 3 && "send".equalsIgnoreCase(args[0]))
{ {
if (!user.isAuthorized("essentials.mail.send")) if (!Permissions.MAIL_SEND.isAuthorized(user))
{ {
throw new Exception(_("noPerm", "essentials.mail.send")); throw new Exception(_("noPerm", "essentials.mail.send"));
} }
@@ -59,7 +60,7 @@ public class Commandmail extends EssentialsCommand
} }
if (args.length > 1 && "sendall".equalsIgnoreCase(args[0])) if (args.length > 1 && "sendall".equalsIgnoreCase(args[0]))
{ {
if (!user.isAuthorized("essentials.mail.sendall")) if (!Permissions.MAIL_SENDALL.isAuthorized(user))
{ {
throw new Exception(_("noPerm", "essentials.mail.sendall")); throw new Exception(_("noPerm", "essentials.mail.sendall"));
} }

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
public class Commandme extends EssentialsCommand public class Commandme extends EssentialsCommand
@@ -21,7 +22,7 @@ public class Commandme extends EssentialsCommand
} }
String message = getFinalArg(args, 0); String message = getFinalArg(args, 0);
if (user.isAuthorized("essentials.chat.color")) if (Permissions.CHAT_COLOR.isAuthorized(user))
{ {
message = Util.replaceColor(message); message = Util.replaceColor(message);
} }

View File

@@ -3,7 +3,10 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.ItemPermissions;
import com.earth2me.essentials.perm.Permissions;
import java.util.Locale; import java.util.Locale;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -30,19 +33,18 @@ public class Commandmore extends EssentialsCommand
{ {
settings.unlock(); settings.unlock();
} }
if (stack.getAmount() >= ((user.isAuthorized("essentials.oversizedstacks")) if (stack.getAmount() >= (Permissions.OVERSIZEDSTACKS.isAuthorized(user)
? oversizedStackSize ? oversizedStackSize
: defaultStackSize > 0 ? defaultStackSize : stack.getMaxStackSize())) : defaultStackSize > 0 ? defaultStackSize : stack.getMaxStackSize()))
{ {
throw new NoChargeException(); throw new NoChargeException();
} }
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (!user.isAuthorized("essentials.itemspawn.item-" + itemname) if (!ItemPermissions.getPermission(stack.getType()).isAuthorized(user))
&& !user.isAuthorized("essentials.itemspawn.item-" + stack.getTypeId()))
{ {
throw new Exception(_("cantSpawnItem", itemname)); throw new Exception(_("cantSpawnItem", itemname));
} }
if (user.isAuthorized("essentials.oversizedstacks")) if (Permissions.OVERSIZEDSTACKS.isAuthorized(user))
{ {
stack.setAmount(oversizedStackSize); stack.setAmount(oversizedStackSize);
} }

View File

@@ -5,6 +5,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IReplyTo; import com.earth2me.essentials.api.IReplyTo;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.List; import java.util.List;
import lombok.Cleanup; import lombok.Cleanup;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -31,7 +32,7 @@ public class Commandmsg extends EssentialsCommand
{ {
throw new Exception(_("voiceSilenced")); throw new Exception(_("voiceSilenced"));
} }
if (user.isAuthorized("essentials.msg.color")) if (Permissions.MSG_COLOR.isAuthorized(user))
{ {
message = Util.replaceColor(message); message = Util.replaceColor(message);
} }

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import com.earth2me.essentials.user.UserData.TimestampType; import com.earth2me.essentials.user.UserData.TimestampType;
import lombok.Cleanup; import lombok.Cleanup;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -21,7 +22,7 @@ public class Commandmute extends EssentialsCommand
@Cleanup @Cleanup
final IUser player = getPlayer(args, 0, true); final IUser player = getPlayer(args, 0, true);
player.acquireReadLock(); player.acquireReadLock();
if (!player.getData().isMuted() && player.isAuthorized("essentials.mute.exempt")) if (!player.getData().isMuted() && Permissions.MUTE_EXEMPT.isAuthorized(player))
{ {
throw new Exception(_("muteExempt")); throw new Exception(_("muteExempt"));
} }

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -43,7 +44,7 @@ public class Commandnear extends EssentialsCommand
{ {
} }
} }
if (otherUser == null || user.isAuthorized("essentials.near.others")) if (otherUser == null || Permissions.NEAR_OTHERS.isAuthorized(user))
{ {
user.sendMessage(_("nearbyPlayers", getLocal(otherUser == null ? user : otherUser, radius))); user.sendMessage(_("nearbyPlayers", getLocal(otherUser == null ? user : otherUser, radius)));
} }

View File

@@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.Locale; import java.util.Locale;
import lombok.Cleanup; import lombok.Cleanup;
import org.bukkit.Server; import org.bukkit.Server;
@@ -29,7 +30,7 @@ public class Commandnick extends EssentialsCommand
} }
if (args.length > 1) if (args.length > 1)
{ {
if (!user.isAuthorized("essentials.nick.others")) if (!Permissions.NICK_OTHERS.isAuthorized(user))
{ {
throw new Exception(_("nickOthersPermission")); throw new Exception(_("nickOthersPermission"));
} }
@@ -67,7 +68,7 @@ public class Commandnick extends EssentialsCommand
private String formatNickname(final IUser user, final String nick) private String formatNickname(final IUser user, final String nick)
{ {
if (user == null || user.isAuthorized("essentials.nick.color")) if (user == null || Permissions.NICK_COLOR.isAuthorized(user))
{ {
return nick.replace('&', '\u00a7').replaceAll("\u00a7+k", ""); return nick.replace('&', '\u00a7').replaceAll("\u00a7+k", "");
} else { } else {

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@@ -71,7 +72,7 @@ public class Commandpowertool extends EssentialsCommand
{ {
if (command.startsWith("a:")) if (command.startsWith("a:"))
{ {
if (!user.isAuthorized("essentials.powertool.append")) if (!Permissions.POWERTOOL_APPEND.isAuthorized(user))
{ {
throw new Exception(_("noPerm", "essentials.powertool.append")); throw new Exception(_("noPerm", "essentials.powertool.append"));
} }

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.DescParseTickFormat; import com.earth2me.essentials.DescParseTickFormat;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.*; import java.util.*;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -40,7 +41,7 @@ public class Commandptime extends EssentialsCommand
} }
IUser user = sender instanceof Player ? ess.getUser((Player)sender) : null; IUser user = sender instanceof Player ? ess.getUser((Player)sender) : null;
if ((!users.contains(user) || users.size() > 1) && user != null && !user.isAuthorized("essentials.ptime.others")) if ((!users.contains(user) || users.size() > 1) && user != null && !Permissions.PTIME_OTHERS.isAuthorized(user))
{ {
user.sendMessage(_("pTimeOthersPermission")); user.sendMessage(_("pTimeOthersPermission"));
return; return;

View File

@@ -5,6 +5,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IReplyTo; import com.earth2me.essentials.api.IReplyTo;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -26,7 +27,7 @@ public class Commandr extends EssentialsCommand
if (sender instanceof Player) if (sender instanceof Player)
{ {
IUser user = ess.getUser((Player)sender); IUser user = ess.getUser((Player)sender);
if (user.isAuthorized("essentials.msg.color")) if (Permissions.MSG_COLOR.isAuthorized(user))
{ {
message = Util.replaceColor(message); message = Util.replaceColor(message);
} }

View File

@@ -5,6 +5,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade; import com.earth2me.essentials.Trade;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@@ -31,7 +32,7 @@ public class Commandrepair extends EssentialsCommand
} }
if (!item.getEnchantments().isEmpty() if (!item.getEnchantments().isEmpty()
&& !user.isAuthorized("essentials.repair.enchanted")) && !Permissions.REPAIR_ENCHANTED.isAuthorized(user))
{ {
throw new Exception(_("repairEnchanted")); throw new Exception(_("repairEnchanted"));
} }
@@ -52,7 +53,7 @@ public class Commandrepair extends EssentialsCommand
final List<String> repaired = new ArrayList<String>(); final List<String> repaired = new ArrayList<String>();
repairItems(user.getInventory().getContents(), user, repaired); repairItems(user.getInventory().getContents(), user, repaired);
if (user.isAuthorized("essentials.repair.armor")) if (Permissions.REPAIR_ARMOR.isAuthorized(user))
{ {
repairItems(user.getInventory().getArmorContents(), user, repaired); repairItems(user.getInventory().getArmorContents(), user, repaired);
} }
@@ -109,7 +110,7 @@ public class Commandrepair extends EssentialsCommand
continue; continue;
} }
if (!item.getEnchantments().isEmpty() if (!item.getEnchantments().isEmpty()
&& !user.isAuthorized("essentials.repair.enchanted")) && !Permissions.REPAIR_ENCHANTED.isAuthorized(user))
{ {
continue; continue;
} }

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import lombok.Cleanup; import lombok.Cleanup;
@@ -24,12 +25,12 @@ public class Commandsethome extends EssentialsCommand
if (args.length < 2) if (args.length < 2)
{ {
if (user.isAuthorized("essentials.sethome.multiple")) if (Permissions.SETHOME_MULTIPLE.isAuthorized(user))
{ {
if ("bed".equals(args[0].toLowerCase(Locale.ENGLISH))) { if ("bed".equals(args[0].toLowerCase(Locale.ENGLISH))) {
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
if ((user.isAuthorized("essentials.sethome.multiple.unlimited")) || (user.getHomes().size() < ess.getGroups().getHomeLimit(user)) if ((user.getHomes().size() < ess.getGroups().getHomeLimit(user))
|| (user.getHomes().contains(args[0].toLowerCase(Locale.ENGLISH)))) || (user.getHomes().contains(args[0].toLowerCase(Locale.ENGLISH))))
{ {
user.acquireWriteLock(); user.acquireWriteLock();
@@ -52,7 +53,7 @@ public class Commandsethome extends EssentialsCommand
} }
else else
{ {
if (user.isAuthorized("essentials.sethome.others")) if (Permissions.SETHOME_OTHERS.isAuthorized(user))
{ {
@Cleanup @Cleanup
IUser usersHome = ess.getUser(ess.getServer().getPlayer(args[0])); IUser usersHome = ess.getUser(ess.getServer().getPlayer(args[0]));
@@ -61,7 +62,7 @@ public class Commandsethome extends EssentialsCommand
throw new Exception(_("playerNotFound")); throw new Exception(_("playerNotFound"));
} }
String name = args[1].toLowerCase(Locale.ENGLISH); String name = args[1].toLowerCase(Locale.ENGLISH);
if (!user.isAuthorized("essentials.sethome.multiple")) if (!Permissions.SETHOME_MULTIPLE.isAuthorized(user))
{ {
name = "home"; name = "home";
} }

View File

@@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Mob; import com.earth2me.essentials.Mob;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.SpawnerPermissions;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.CreatureSpawner; import org.bukkit.block.CreatureSpawner;
@@ -36,7 +37,7 @@ public class Commandspawner extends EssentialsCommand
user.sendMessage(_("invalidMob")); user.sendMessage(_("invalidMob"));
return; return;
} }
if (!user.isAuthorized("essentials.spawner." + mob.name.toLowerCase())) if (!SpawnerPermissions.getPermission(mob.name).isAuthorized(user))
{ {
throw new Exception(_("unableToSpawnMob")); throw new Exception(_("unableToSpawnMob"));
} }

View File

@@ -6,6 +6,7 @@ import com.earth2me.essentials.Mob.MobException;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.SpawnmobPermissions;
import java.util.Locale; import java.util.Locale;
import java.util.Random; import java.util.Random;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
@@ -57,7 +58,7 @@ public class Commandspawnmob extends EssentialsCommand
throw new Exception(_("invalidMob")); throw new Exception(_("invalidMob"));
} }
if (!user.isAuthorized("essentials.spawnmob." + mob.name.toLowerCase())) if (!SpawnmobPermissions.getPermission(mob.name).isAuthorized(user))
{ {
throw new Exception(_("noPermToSpawnMob")); throw new Exception(_("noPermToSpawnMob"));
} }
@@ -92,7 +93,7 @@ public class Commandspawnmob extends EssentialsCommand
return; return;
} }
if (!user.isAuthorized("essentials.spawnmob." + mobMount.name.toLowerCase())) if (!SpawnmobPermissions.getPermission(mobMount.name).isAuthorized(user))
{ {
throw new Exception(_("noPermToSpawnMob")); throw new Exception(_("noPermToSpawnMob"));
} }

View File

@@ -4,6 +4,7 @@ import com.earth2me.essentials.Console;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import com.earth2me.essentials.user.Ban; import com.earth2me.essentials.user.Ban;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -22,8 +23,7 @@ public class Commandtempban extends EssentialsCommand
final IUser user = getPlayer(args, 0, true); final IUser user = getPlayer(args, 0, true);
if (user.getBase() instanceof OfflinePlayer) if (user.getBase() instanceof OfflinePlayer)
{ {
if (sender instanceof Player if (Permissions.TEMPBAN_OFFLINE.isAuthorized(sender))
&& !ess.getUser((Player)sender).isAuthorized("essentials.tempban.offline"))
{ {
sender.sendMessage(_("tempbanExempt")); sender.sendMessage(_("tempbanExempt"));
return; return;
@@ -31,7 +31,7 @@ public class Commandtempban extends EssentialsCommand
} }
else else
{ {
if (user.isAuthorized("essentials.tempban.exempt")) if (Permissions.TEMPBAN_EXEMPT.isAuthorized(user))
{ {
sender.sendMessage(_("tempbanExempt")); sender.sendMessage(_("tempbanExempt"));
return; return;
@@ -52,7 +52,7 @@ public class Commandtempban extends EssentialsCommand
for (Player onlinePlayer : server.getOnlinePlayers()) for (Player onlinePlayer : server.getOnlinePlayers())
{ {
final IUser player = ess.getUser(onlinePlayer); final IUser player = ess.getUser(onlinePlayer);
if (player.isAuthorized("essentials.ban.notify")) if (Permissions.BAN_NOTIFY.isAuthorized(player))
{ {
onlinePlayer.sendMessage(_("playerBanned", senderName, user.getName(), banReason)); onlinePlayer.sendMessage(_("playerBanned", senderName, user.getName(), banReason));
} }

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.DescParseTickFormat; import com.earth2me.essentials.DescParseTickFormat;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.*; import java.util.*;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -29,10 +30,9 @@ public class Commandtime extends EssentialsCommand
return; return;
} }
final IUser user = sender instanceof Player ? ess.getUser((Player)sender) : null; if (Permissions.TIME_SET.isAuthorized(sender))
if (user != null && !user.isAuthorized("essentials.time.set"))
{ {
user.sendMessage(_("timeSetPermission")); sender.sendMessage(_("timeSetPermission"));
return; return;
} }

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import com.earth2me.essentials.user.UserData.TimestampType; import com.earth2me.essentials.user.UserData.TimestampType;
import lombok.Cleanup; import lombok.Cleanup;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@@ -28,8 +29,7 @@ public class Commandtogglejail extends EssentialsCommand
{ {
if (player.getBase() instanceof OfflinePlayer) if (player.getBase() instanceof OfflinePlayer)
{ {
if (sender instanceof Player if (Permissions.TOGGLEJAIL_OFFLINE.isAuthorized(sender))
&& !ess.getUser((Player)sender).isAuthorized("essentials.togglejail.offline"))
{ {
sender.sendMessage(_("mayNotJail")); sender.sendMessage(_("mayNotJail"));
return; return;
@@ -37,7 +37,7 @@ public class Commandtogglejail extends EssentialsCommand
} }
else else
{ {
if (player.isAuthorized("essentials.jail.exempt")) if (Permissions.JAIL_EXEMPT.isAuthorized(player))
{ {
sender.sendMessage(_("mayNotJail")); sender.sendMessage(_("mayNotJail"));
return; return;

View File

@@ -4,6 +4,7 @@ import com.earth2me.essentials.Console;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade; import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import lombok.Cleanup; import lombok.Cleanup;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@@ -34,7 +35,7 @@ public class Commandtp extends EssentialsCommand
throw new NoChargeException(); throw new NoChargeException();
default: default:
if (!user.isAuthorized("essentials.tpohere")) if (!Permissions.TPOHERE.isAuthorized(user))
{ {
//TODO: Translate this //TODO: Translate this
throw new Exception("You need access to /tpohere to teleport other players."); throw new Exception("You need access to /tpohere to teleport other players.");

View File

@@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade; import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@@ -20,7 +21,7 @@ public class Commandtpaccept extends EssentialsCommand
final IUser target = user.getTeleportRequester(); final IUser target = user.getTeleportRequester();
if (target.getBase() instanceof OfflinePlayer if (target.getBase() instanceof OfflinePlayer
|| (user.isTeleportRequestHere() && !target.isAuthorized("essentials.tpahere"))) || (user.isTeleportRequestHere() && !Permissions.TPAHERE.isAuthorized(target)))
{ {
throw new Exception(_("noPendingRequest")); throw new Exception(_("noPendingRequest"));
} }

View File

@@ -2,6 +2,8 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import com.earth2me.essentials.perm.Permissions2Handler;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@@ -25,7 +27,7 @@ public class Commandtpo extends EssentialsCommand
} }
// Verify permission // Verify permission
if (!player.isHidden() || user.isAuthorized("essentials.teleport.hidden")) if (!player.isHidden() || Permissions.TELEPORT_HIDDEN.isAuthorized(user))
{ {
user.getTeleport().now(player, false, TeleportCause.COMMAND); user.getTeleport().now(player, false, TeleportCause.COMMAND);
user.sendMessage(_("teleporting")); user.sendMessage(_("teleporting"));

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@@ -26,7 +27,7 @@ public class Commandtpohere extends EssentialsCommand
} }
// Verify permission // Verify permission
if (!player.isHidden() || user.isAuthorized("essentials.teleport.hidden")) if (!player.isHidden() || Permissions.TELEPORT_HIDDEN.isAuthorized(user))
{ {
player.getTeleport().now(user, false, TeleportCause.COMMAND); player.getTeleport().now(user, false, TeleportCause.COMMAND);
user.sendMessage(_("teleporting")); user.sendMessage(_("teleporting"));

View File

@@ -3,6 +3,8 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import com.earth2me.essentials.perm.Permissions;
import com.earth2me.essentials.perm.UnlimitedItemPermissions;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import lombok.Cleanup; import lombok.Cleanup;
@@ -23,7 +25,7 @@ public class Commandunlimited extends EssentialsCommand
@Cleanup @Cleanup
IUser target = user; IUser target = user;
if (args.length > 1 && user.isAuthorized("essentials.unlimited.others")) if (args.length > 1 && Permissions.UNLIMITED_OTHERS.isAuthorized(user))
{ {
target = getPlayer(args, 1); target = getPlayer(args, 1);
target.acquireReadLock(); target.acquireReadLock();
@@ -80,8 +82,7 @@ public class Commandunlimited extends EssentialsCommand
stack.setAmount(Math.min(stack.getType().getMaxStackSize(), 2)); stack.setAmount(Math.min(stack.getType().getMaxStackSize(), 2));
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (!user.isAuthorized("essentials.unlimited.item-" + itemname) if (!UnlimitedItemPermissions.getPermission(stack.getType()).isAuthorized(user))
&& !user.isAuthorized("essentials.unlimited.item-" + stack.getTypeId()))
{ {
throw new Exception(_("unlimitedItemPermission", itemname)); throw new Exception(_("unlimitedItemPermission", itemname));
} }

View File

@@ -5,6 +5,8 @@ import com.earth2me.essentials.Trade;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.api.IWarps; import com.earth2me.essentials.api.IWarps;
import com.earth2me.essentials.perm.Permissions;
import com.earth2me.essentials.perm.WarpPermissions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@@ -21,7 +23,7 @@ public class Commandwarp extends EssentialsCommand
{ {
if (args.length == 0 || args[0].matches("[0-9]+")) if (args.length == 0 || args[0].matches("[0-9]+"))
{ {
if (!user.isAuthorized("essentials.warp.list")) if (!Permissions.WARP_LIST.isAuthorized(user))
{ {
throw new Exception(_("warpListPermission")); throw new Exception(_("warpListPermission"));
} }
@@ -31,7 +33,7 @@ public class Commandwarp extends EssentialsCommand
if (args.length > 0) if (args.length > 0)
{ {
IUser otherUser = null; IUser otherUser = null;
if (args.length == 2 && user.isAuthorized("essentials.warp.otherplayers")) if (args.length == 2 && Permissions.WARP_OTHERS.isAuthorized(user))
{ {
otherUser = ess.getUser(server.getPlayer(args[1])); otherUser = ess.getUser(server.getPlayer(args[1]));
if (otherUser == null) if (otherUser == null)
@@ -80,7 +82,7 @@ public class Commandwarp extends EssentialsCommand
while (iterator.hasNext()) while (iterator.hasNext())
{ {
final String warpName = iterator.next(); final String warpName = iterator.next();
if (!((IUser)sender).isAuthorized("essentials.warp." + warpName)) if (!WarpPermissions.getPermission(warpName).isAuthorized(sender))
{ {
iterator.remove(); iterator.remove();
} }
@@ -111,7 +113,7 @@ public class Commandwarp extends EssentialsCommand
final Trade charge = new Trade(commandName, ess); final Trade charge = new Trade(commandName, ess);
charge.isAffordableFor(user); charge.isAffordableFor(user);
if (user.isAuthorized("essentials.warp." + name)) if (WarpPermissions.getPermission(name).isAuthorized(user))
{ {
user.getTeleport().warp(name, charge, TeleportCause.COMMAND); user.getTeleport().warp(name, charge, TeleportCause.COMMAND);
return; return;

View File

@@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.Locale; import java.util.Locale;
import lombok.Cleanup; import lombok.Cleanup;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -22,7 +23,7 @@ public class Commandwhois extends EssentialsCommand
boolean showhidden = false; boolean showhidden = false;
if (sender instanceof Player) if (sender instanceof Player)
{ {
if (ess.getUser((Player)sender).isAuthorized("essentials.list.hidden")) if (Permissions.LIST_HIDDEN.isAuthorized(sender))
{ {
showhidden = true; showhidden = true;
} }
@@ -67,7 +68,7 @@ public class Commandwhois extends EssentialsCommand
sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString())); sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString()));
final String location = user.getData().getGeolocation(); final String location = user.getData().getGeolocation();
if (location != null if (location != null
&& (sender instanceof Player ? ess.getUser((Player)sender).isAuthorized("essentials.geoip.show") : true)) && Permissions.GEOIP_SHOW.isAuthorized(sender))
{ {
sender.sendMessage(_("whoisGeoLocation", location)); sender.sendMessage(_("whoisGeoLocation", location));
} }

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade; import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.WorldPermissions;
import java.util.List; import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@@ -49,7 +50,7 @@ public class Commandworld extends EssentialsCommand
} }
if (!user.isAuthorized("essentials.world." + world.getName())) if (!WorldPermissions.getPermission(world.getName()).isAuthorized(user))
{ {
user.sendMessage(_("invalidWorld")); //TODO: Make a "world teleport denied" translation user.sendMessage(_("invalidWorld")); //TODO: Make a "world teleport denied" translation
throw new NoChargeException(); throw new NoChargeException();

View File

@@ -21,13 +21,14 @@ public abstract class EssentialsCommand extends AbstractSuperpermsPermission imp
protected transient IEssentials ess; protected transient IEssentials ess;
protected transient IEssentialsModule module; protected transient IEssentialsModule module;
protected transient Server server; protected transient Server server;
protected final static Logger logger = Logger.getLogger("Minecraft"); protected transient Logger logger;
private transient String permission; private transient String permission;
private transient Permission bukkitPerm; private transient Permission bukkitPerm;
public void init(final IEssentials ess, final String commandName) public void init(final IEssentials ess, final String commandName)
{ {
this.ess = ess; this.ess = ess;
this.logger = ess.getLogger();
this.server = ess.getServer(); this.server = ess.getServer();
this.commandName = commandName; this.commandName = commandName;
this.permission = "essentials." + commandName; this.permission = "essentials." + commandName;

View File

@@ -1,254 +0,0 @@
package com.earth2me.essentials.craftbukkit;
import java.lang.ref.WeakReference;
import java.util.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
public class BetterLocation extends Location
{
private transient String worldName;
private static BetterLocationListener listener = new BetterLocationListener();
public static BetterLocationListener getListener()
{
return listener;
}
public static void cleanup()
{
synchronized (listener.locationMap)
{
listener.locationMap.clear();
}
}
public BetterLocation(final String worldName, final double x, final double y, final double z)
{
super(Bukkit.getWorld(worldName), x, y, z);
this.worldName = worldName;
addToMap(this);
}
public BetterLocation(final String worldName, final double x, final double y,
final double z, final float yaw, final float pitch)
{
super(Bukkit.getWorld(worldName), x, y, z, yaw, pitch);
this.worldName = worldName;
addToMap(this);
}
public BetterLocation(final World world, final double x, final double y, final double z)
{
super(world, x, y, z);
if (world == null)
{
throw new WorldNotLoadedException();
}
this.worldName = world.getName();
addToMap(this);
}
public BetterLocation(final World world, final double x, final double y,
final double z, final float yaw, final float pitch)
{
super(world, x, y, z, yaw, pitch);
if (world == null)
{
throw new WorldNotLoadedException();
}
this.worldName = world.getName();
addToMap(this);
}
public BetterLocation(final Location location)
{
super(location.getWorld(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
if (location.getWorld() == null)
{
throw new WorldNotLoadedException();
}
this.worldName = location.getWorld().getName();
addToMap(this);
}
@Override
public World getWorld()
{
World world = super.getWorld();
if (world == null)
{
world = Bukkit.getWorld(worldName);
}
if (world == null)
{
throw new WorldNotLoadedException();
}
else
{
super.setWorld(world);
}
return world;
}
@Override
public void setWorld(final World world)
{
if (world == null)
{
throw new WorldNotLoadedException();
}
if (!world.getName().equals(this.worldName))
{
getListener().removeLocation(this);
this.worldName = world.getName();
addToMap(this);
}
super.setWorld(world);
}
public String getWorldName()
{
return worldName;
}
private void addToMap(final BetterLocation location)
{
synchronized (listener.locationMap)
{
List<WeakReference<Location>> locations = listener.locationMap.get(location.getWorldName());
if (locations == null)
{
locations = new LinkedList<WeakReference<Location>>();
listener.locationMap.put(location.getWorldName(), locations);
}
locations.add(new WeakReference<Location>(location));
}
}
public static class WorldNotLoadedException extends RuntimeException
{
public WorldNotLoadedException()
{
super("World is not loaded.");
}
}
public static class BetterLocationListener extends org.bukkit.event.world.WorldListener implements Runnable
{
private static Random random = new Random();
private final transient Map<String, List<WeakReference<Location>>> locationMap = new HashMap<String, List<WeakReference<Location>>>();
@Override
public void onWorldLoad(final WorldLoadEvent event)
{
final String worldName = event.getWorld().getName();
synchronized (locationMap)
{
final List<WeakReference<Location>> locations = locationMap.get(worldName);
if (locations != null)
{
for (final Iterator<WeakReference<Location>> it = locations.iterator(); it.hasNext();)
{
final WeakReference<Location> weakReference = it.next();
final Location loc = weakReference.get();
if (loc == null)
{
it.remove();
}
else
{
loc.setWorld(event.getWorld());
}
}
}
}
}
@Override
public void onWorldUnload(final WorldUnloadEvent event)
{
final String worldName = event.getWorld().getName();
synchronized (locationMap)
{
final List<WeakReference<Location>> locations = locationMap.get(worldName);
if (locations != null)
{
for (final Iterator<WeakReference<Location>> it = locations.iterator(); it.hasNext();)
{
final WeakReference<Location> weakReference = it.next();
final Location loc = weakReference.get();
if (loc == null)
{
it.remove();
}
else
{
loc.setWorld(null);
}
}
}
}
}
@Override
public void run()
{
synchronized (locationMap)
{
// Pick a world by random
final Collection<List<WeakReference<Location>>> allWorlds = locationMap.values();
final int randomPick = (allWorlds.isEmpty() ? 0 : random.nextInt(allWorlds.size()));
List<WeakReference<Location>> locations = null;
final Iterator<List<WeakReference<Location>>> iterator = allWorlds.iterator();
for (int i = 0; iterator.hasNext() && i < randomPick; i++)
{
iterator.next();
}
if (iterator.hasNext())
{
locations = iterator.next();
}
if (locations != null)
{
for (final Iterator<WeakReference<Location>> it = locations.iterator(); it.hasNext();)
{
final WeakReference<Location> weakReference = it.next();
final Location loc = weakReference.get();
if (loc == null)
{
it.remove();
}
}
}
}
}
private void removeLocation(final BetterLocation location)
{
final String worldName = location.getWorldName();
synchronized (locationMap)
{
final List<WeakReference<Location>> locations = locationMap.get(worldName);
if (locations != null)
{
for (final Iterator<WeakReference<Location>> it = locations.iterator(); it.hasNext();)
{
final WeakReference<Location> weakReference = it.next();
final Location loc = weakReference.get();
if (loc == null || loc == location)
{
it.remove();
}
}
}
}
}
}
}

View File

@@ -1,11 +1,11 @@
package com.earth2me.essentials.craftbukkit; package com.earth2me.essentials.craftbukkit;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.storage.Location;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.minecraft.server.NBTTagCompound; import net.minecraft.server.NBTTagCompound;
import net.minecraft.server.WorldNBTStorage; import net.minecraft.server.WorldNBTStorage;
import org.bukkit.Location;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
@@ -38,7 +38,7 @@ public class OfflineBedLocation
{ {
spawnWorld = cserver.getWorlds().get(0).getName(); spawnWorld = cserver.getWorlds().get(0).getName();
} }
return new BetterLocation(spawnWorld, playerStorage.getInt("SpawnX"), playerStorage.getInt("SpawnY"), playerStorage.getInt("SpawnZ")); return new Location(spawnWorld, playerStorage.getInt("SpawnX"), playerStorage.getInt("SpawnY"), playerStorage.getInt("SpawnZ"));
} }
return null; return null;
} }

View File

@@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.List; import java.util.List;
import lombok.Cleanup; import lombok.Cleanup;
import org.bukkit.Material; import org.bukkit.Material;
@@ -98,7 +99,7 @@ public class EssentialsEntityListener extends EntityListener
@Cleanup @Cleanup
final ISettings settings = ess.getSettings(); final ISettings settings = ess.getSettings();
settings.acquireReadLock(); settings.acquireReadLock();
if (user.isAuthorized("essentials.back.ondeath") && !settings.getData().getCommands().isDisabled("back")) if (Permissions.BACK_ONDEATH.isAuthorized(user) && !settings.getData().getCommands().isDisabled("back"))
{ {
user.setLastLocation(); user.setLastLocation();
user.sendMessage(_("backAfterDeath")); user.sendMessage(_("backAfterDeath"));

View File

@@ -5,6 +5,7 @@ import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.textreader.KeywordReplacer; import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.TextInput; import com.earth2me.essentials.textreader.TextInput;
@@ -150,7 +151,7 @@ public class EssentialsPlayerListener implements Listener
user.updateDisplayName(); user.updateDisplayName();
user.getData().setIpAddress(user.getAddress().getAddress().getHostAddress()); user.getData().setIpAddress(user.getAddress().getAddress().getHostAddress());
user.updateActivity(false); user.updateActivity(false);
if (user.isAuthorized("essentials.sleepingignored")) if (Permissions.SLEEPINGIGNORED.isAuthorized(user))
{ {
user.setSleepingIgnored(true); user.setSleepingIgnored(true);
} }
@@ -159,7 +160,7 @@ public class EssentialsPlayerListener implements Listener
final ISettings settings = ess.getSettings(); final ISettings settings = ess.getSettings();
settings.acquireReadLock(); settings.acquireReadLock();
if (!settings.getData().getCommands().isDisabled("motd") && user.isAuthorized("essentials.motd")) if (!settings.getData().getCommands().isDisabled("motd") && Permissions.MOTD.isAuthorized(user))
{ {
try try
{ {
@@ -181,7 +182,7 @@ public class EssentialsPlayerListener implements Listener
} }
} }
if (!settings.getData().getCommands().isDisabled("mail") && user.isAuthorized("essentials.mail")) if (!settings.getData().getCommands().isDisabled("mail") && Permissions.MAIL.isAuthorized(user))
{ {
final List<String> mail = user.getData().getMails(); final List<String> mail = user.getData().getMails();
if (mail == null || mail.isEmpty()) if (mail == null || mail.isEmpty())
@@ -219,7 +220,7 @@ public class EssentialsPlayerListener implements Listener
return; return;
} }
if (server.getOnlinePlayers().length >= server.getMaxPlayers() && !user.isAuthorized("essentials.joinfullserver")) if (server.getOnlinePlayers().length >= server.getMaxPlayers() && !Permissions.JOINFULLSERVER.isAuthorized(user))
{ {
event.disallow(Result.KICK_FULL, _("serverFull")); event.disallow(Result.KICK_FULL, _("serverFull"));
return; return;
@@ -382,7 +383,7 @@ public class EssentialsPlayerListener implements Listener
@Cleanup @Cleanup
final IUser user = ess.getUser(event.getPlayer()); final IUser user = ess.getUser(event.getPlayer());
user.acquireReadLock(); user.acquireReadLock();
if (!settings.getData().getWorldOptions(event.getPlayer().getLocation().getWorld().getName()).isGodmode() && !user.isAuthorized("essentials.nogod.override")) if (!settings.getData().getWorldOptions(event.getPlayer().getLocation().getWorld().getName()).isGodmode() && !Permissions.NOGOD_OVERRIDE.isAuthorized(user))
{ {
if (user.getData().isGodmode()) if (user.getData().isGodmode())
{ {

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.perm;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IPermission; import com.earth2me.essentials.api.IPermission;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
@@ -23,9 +24,19 @@ public abstract class AbstractSuperpermsPermission implements IPermission
} }
} }
/**
* PermissionDefault is OP, if the method is not overwritten.
* @return
*/
@Override @Override
public PermissionDefault getPermissionDefault() public PermissionDefault getPermissionDefault()
{ {
return PermissionDefault.OP; return PermissionDefault.OP;
} }
@Override
public boolean isAuthorized(CommandSender sender)
{
return sender.hasPermission(getBukkitPermission());
}
} }

View File

@@ -0,0 +1,18 @@
package com.earth2me.essentials.perm;
import com.earth2me.essentials.api.IPermission;
public class BasePermission extends AbstractSuperpermsPermission {
protected String permission;
public BasePermission(String base, String permission)
{
this.permission = base + permission;
}
public String getPermission()
{
return permission;
}
}

View File

@@ -0,0 +1,23 @@
package com.earth2me.essentials.perm;
import com.earth2me.essentials.api.IPermission;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class EnchantPermissions
{
private static Map<String, IPermission> permissions = new HashMap<String, IPermission>();
public static IPermission getPermission(final String enchantName)
{
IPermission perm = permissions.get(enchantName);
if (perm == null)
{
perm = new BasePermission("essentials.enchant.",enchantName.toLowerCase(Locale.ENGLISH));
permissions.put(enchantName, perm);
}
return perm;
}
}

View File

@@ -0,0 +1,30 @@
package com.earth2me.essentials.perm;
import com.earth2me.essentials.api.IPermission;
import java.util.EnumMap;
import java.util.Locale;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.permissions.PermissionDefault;
public class GivePermissions {
private static Map<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class);
public static IPermission getPermission(final Material mat)
{
IPermission perm = permissions.get(mat);
if (perm == null)
{
perm = new BasePermission("essentials.give.item-", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", ""))
{
@Override
public PermissionDefault getPermissionDefault()
{
return PermissionDefault.TRUE;
}
};
permissions.put(mat, perm);
}
return perm;
}
}

View File

@@ -0,0 +1,23 @@
package com.earth2me.essentials.perm;
import com.earth2me.essentials.api.IPermission;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class GroupsPermissions
{
private static Map<String, IPermission> permissions = new HashMap<String, IPermission>();
public static IPermission getPermission(final String groupName)
{
IPermission perm = permissions.get(groupName);
if (perm == null)
{
perm = new BasePermission("essentials.groups.",groupName.toLowerCase(Locale.ENGLISH));
permissions.put(groupName, perm);
}
return perm;
}
}

View File

@@ -0,0 +1,23 @@
package com.earth2me.essentials.perm;
import com.earth2me.essentials.api.IPermission;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class HelpPermissions
{
private static Map<String, IPermission> permissions = new HashMap<String, IPermission>();
public static IPermission getPermission(final String pluginName)
{
IPermission perm = permissions.get(pluginName);
if (perm == null)
{
perm = new BasePermission("essentials.help.", pluginName.toLowerCase(Locale.ENGLISH));
permissions.put(pluginName, perm);
}
return perm;
}
}

View File

@@ -0,0 +1,32 @@
package com.earth2me.essentials.perm;
import com.earth2me.essentials.api.IPermission;
import java.util.EnumMap;
import java.util.Locale;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.permissions.PermissionDefault;
public class ItemPermissions
{
private static Map<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class);
public static IPermission getPermission(final Material mat)
{
IPermission perm = permissions.get(mat);
if (perm == null)
{
perm = new BasePermission("essentials.itemspawn.item-", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", ""))
{
@Override
public PermissionDefault getPermissionDefault()
{
return PermissionDefault.TRUE;
}
};
permissions.put(mat, perm);
}
return perm;
}
}

View File

@@ -0,0 +1,31 @@
package com.earth2me.essentials.perm;
import com.earth2me.essentials.api.IPermission;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.bukkit.permissions.PermissionDefault;
public class KitPermissions
{
private static Map<String, IPermission> permissions = new HashMap<String, IPermission>();
public static IPermission getPermission(final String kitName)
{
IPermission perm = permissions.get(kitName);
if (perm == null)
{
perm = new BasePermission("essentials.kit.", kitName.toLowerCase(Locale.ENGLISH))
{
@Override
public PermissionDefault getPermissionDefault()
{
return PermissionDefault.TRUE;
}
};
permissions.put(kitName, perm);
}
return perm;
}
}

View File

@@ -0,0 +1,23 @@
package com.earth2me.essentials.perm;
import com.earth2me.essentials.api.IPermission;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class NoCommandCostPermissions
{
private static Map<String, IPermission> permissions = new HashMap<String, IPermission>();
public static IPermission getPermission(final String command)
{
IPermission perm = permissions.get(command);
if (perm == null)
{
perm = new BasePermission("essentials.nocommandcost.", command.toLowerCase(Locale.ENGLISH));
permissions.put(command, perm);
}
return perm;
}
}

View File

@@ -3,14 +3,73 @@ package com.earth2me.essentials.perm;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IPermission; import com.earth2me.essentials.api.IPermission;
import java.util.Locale; import java.util.Locale;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
public enum Permissions implements IPermission public enum Permissions implements IPermission
{ {
AFK,
AFK_KICKEXEMPT,
AFK_OTHERS, AFK_OTHERS,
BALANCE_OTHERS; BACK_ONDEATH,
BALANCE_OTHERS,
BAN_EXEMPT,
BAN_NOTIFY,
BAN_OFFLINE,
BREAK_BEDROCK,
CHAT_COLOR,
CHAT_SPY,
CLEARINVENTORY_OTHERS,
DELHOME_OTHERS,
ECO_LOAN(PermissionDefault.FALSE),
FEED_OTHERS,
GAMEMODE_OTHERS,
GEOIP_HIDE(PermissionDefault.FALSE),
GEOIP_SHOW(PermissionDefault.TRUE),
GETPOS_OTHERS,
GOD_OTHERS,
HEAL_COOLDOWN_BYPASS,
HEAL_OTHERS,
HELPOP_RECEIVE,
HOME_OTHERS,
JAIL_EXEMPT,
JOINFULLSERVER,
KICK_EXEMPT,
KICK_NOTIFY,
LIST_HIDDEN,
MAIL,
MAIL_SEND,
MAIL_SENDALL,
MOTD,
MSG_COLOR,
MUTE_EXEMPT,
NEAR_OTHERS,
NICK_COLOR,
NICK_OTHERS,
NOGOD_OVERRIDE,
OVERSIZEDSTACKS(PermissionDefault.FALSE),
POWERTOOL_APPEND,
PTIME_OTHERS,
REPAIR_ARMOR,
REPAIR_ENCHANTED,
SETHOME_MULTIPLE,
SETHOME_OTHERS,
SLEEPINGIGNORED,
SPAWN_OTHERS,
TELEPORT_COOLDOWN_BYPASS,
TELEPORT_HIDDEN,
TELEPORT_TIMER_BYPASS,
TEMPBAN_EXEMPT,
TEMPBAN_OFFLINE,
TIME_SET,
TOGGLEJAIL_OFFLINE,
TPAHERE,
TPOHERE,
UNLIMITED_OTHERS,
WARP_LIST(PermissionDefault.TRUE),
WARP_OTHERS;
private static final String base = "essentials."; private static final String base = "essentials.";
private final String permission; private final String permission;
private final PermissionDefault defaultPerm; private final PermissionDefault defaultPerm;
@@ -51,4 +110,10 @@ public enum Permissions implements IPermission
{ {
return this.defaultPerm; return this.defaultPerm;
} }
@Override
public boolean isAuthorized(CommandSender sender)
{
return sender.hasPermission(getBukkitPermission());
}
} }

View File

@@ -0,0 +1,23 @@
package com.earth2me.essentials.perm;
import com.earth2me.essentials.api.IPermission;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class SpawnerPermissions
{
private static Map<String, IPermission> permissions = new HashMap<String, IPermission>();
public static IPermission getPermission(final String mobName)
{
IPermission perm = permissions.get(mobName);
if (perm == null)
{
perm = new BasePermission("essentials.spawner.", mobName.toLowerCase(Locale.ENGLISH).replace("_", ""));
permissions.put(mobName, perm);
}
return perm;
}
}

View File

@@ -0,0 +1,21 @@
package com.earth2me.essentials.perm;
import com.earth2me.essentials.api.IPermission;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class SpawnmobPermissions {
private static Map<String, IPermission> permissions = new HashMap<String, IPermission>();
public static IPermission getPermission(final String mobName)
{
IPermission perm = permissions.get(mobName);
if (perm == null)
{
perm = new BasePermission("essentials.spawnmob.", mobName.toLowerCase(Locale.ENGLISH).replace("_", ""));
permissions.put(mobName, perm);
}
return perm;
}
}

View File

@@ -0,0 +1,23 @@
package com.earth2me.essentials.perm;
import com.earth2me.essentials.api.IPermission;
import java.util.EnumMap;
import java.util.Locale;
import java.util.Map;
import org.bukkit.Material;
public class UnlimitedItemPermissions
{
private static Map<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class);
public static IPermission getPermission(final Material mat)
{
IPermission perm = permissions.get(mat);
if (perm == null)
{
perm = new BasePermission("essentials.unlimited.item-", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", ""));
permissions.put(mat, perm);
}
return perm;
}
}

View File

@@ -0,0 +1,31 @@
package com.earth2me.essentials.perm;
import com.earth2me.essentials.api.IPermission;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.bukkit.permissions.PermissionDefault;
public class WarpPermissions
{
private static Map<String, IPermission> permissions = new HashMap<String, IPermission>();
public static IPermission getPermission(final String warpName)
{
IPermission perm = permissions.get(warpName);
if (perm == null)
{
perm = new BasePermission("essentials.warp.", warpName.toLowerCase(Locale.ENGLISH))
{
@Override
public PermissionDefault getPermissionDefault()
{
return PermissionDefault.TRUE;
}
};
permissions.put(warpName, perm);
}
return perm;
}
}

View File

@@ -0,0 +1,22 @@
package com.earth2me.essentials.perm;
import com.earth2me.essentials.api.IPermission;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class WorldPermissions
{
private static Map<String, IPermission> permissions = new HashMap<String, IPermission>();
public static IPermission getPermission(final String worldName)
{
IPermission perm = permissions.get(worldName);
if (perm == null)
{
perm = new BasePermission("essentials.world.", worldName.toLowerCase(Locale.ENGLISH));
permissions.put(worldName, perm);
}
return perm;
}
}

View File

@@ -5,6 +5,7 @@ import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IGroups; import com.earth2me.essentials.api.IGroups;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.GroupsPermissions;
import com.earth2me.essentials.storage.AsyncStorageObjectHolder; import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
import java.io.File; import java.io.File;
import java.text.MessageFormat; import java.text.MessageFormat;
@@ -29,24 +30,6 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
return new File(ess.getDataFolder(), "groups.yml"); return new File(ess.getDataFolder(), "groups.yml");
} }
public void registerPermissions()
{
acquireReadLock();
try
{
final Map<String, GroupOptions> groups = getData().getGroups();
if (groups == null || groups.isEmpty())
{
return;
}
Util.registerPermissions("essentials.groups", groups.keySet(), true, ess);
}
finally
{
unlock();
}
}
public Collection<GroupOptions> getGroups(final IUser player) public Collection<GroupOptions> getGroups(final IUser player)
{ {
acquireReadLock(); acquireReadLock();
@@ -60,7 +43,7 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
final ArrayList<GroupOptions> list = new ArrayList(); final ArrayList<GroupOptions> list = new ArrayList();
for (Entry<String, GroupOptions> entry : groups.entrySet()) for (Entry<String, GroupOptions> entry : groups.entrySet())
{ {
if (player.isAuthorized("essentials.groups." + entry.getKey())) if (GroupsPermissions.getPermission(entry.getKey()).isAuthorized(player))
{ {
if(entry.getValue() != null) if(entry.getValue() != null)
{ {

View File

@@ -1,12 +1,12 @@
package com.earth2me.essentials.settings; package com.earth2me.essentials.settings;
import com.earth2me.essentials.storage.Location;
import com.earth2me.essentials.storage.MapValueType; import com.earth2me.essentials.storage.MapValueType;
import com.earth2me.essentials.storage.StorageObject; import com.earth2me.essentials.storage.StorageObject;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.bukkit.Location;
@Data @Data

View File

@@ -1,22 +0,0 @@
package com.earth2me.essentials.settings;
import com.earth2me.essentials.storage.MapValueType;
import com.earth2me.essentials.storage.StorageObject;
import java.util.HashMap;
import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.bukkit.Location;
@Data
@EqualsAndHashCode(callSuper = false)
public class Locations implements StorageObject
{
@MapValueType(Location.class)
Map<String, Location> jails = new HashMap<String, Location>();
@MapValueType(Location.class)
Map<String, Location> warps = new HashMap<String, Location>();
@MapValueType(Location.class)
Map<String, Location> spawns = new HashMap<String, Location>();
}

View File

@@ -1,13 +1,13 @@
package com.earth2me.essentials.settings; package com.earth2me.essentials.settings;
import com.earth2me.essentials.storage.Comment; import com.earth2me.essentials.storage.Comment;
import com.earth2me.essentials.storage.Location;
import com.earth2me.essentials.storage.MapValueType; import com.earth2me.essentials.storage.MapValueType;
import com.earth2me.essentials.storage.StorageObject; import com.earth2me.essentials.storage.StorageObject;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.bukkit.Location;
@Data @Data

View File

@@ -1,9 +1,9 @@
package com.earth2me.essentials.settings; package com.earth2me.essentials.settings;
import com.earth2me.essentials.storage.Location;
import com.earth2me.essentials.storage.StorageObject; import com.earth2me.essentials.storage.StorageObject;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.bukkit.Location;
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)

View File

@@ -1,13 +1,11 @@
package com.earth2me.essentials.storage; package com.earth2me.essentials.storage;
import com.earth2me.essentials.Essentials; import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.craftbukkit.BetterLocation;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -280,11 +278,12 @@ public class BukkitConstructor extends Constructor
{ {
return null; return null;
} }
return new BetterLocation(worldName, x, y, z, yaw, pitch); return new Location(worldName, x, y, z, yaw, pitch);
} }
return super.construct(node); return super.construct(node);
} }
@Override
protected Object constructJavaBean2ndStep(final MappingNode node, final Object object) protected Object constructJavaBean2ndStep(final MappingNode node, final Object object)
{ {
Map<Class<? extends Object>, TypeDescription> typeDefinitions; Map<Class<? extends Object>, TypeDescription> typeDefinitions;

View File

@@ -0,0 +1,111 @@
package com.earth2me.essentials.storage;
import java.lang.ref.WeakReference;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.World;
public class Location
{
private WeakReference<org.bukkit.Location> location;
private final String worldname;
private UUID worldUID = null;
private final double x;
private final double y;
private final double z;
private final float yaw;
private final float pitch;
public Location(org.bukkit.Location loc)
{
location = new WeakReference<org.bukkit.Location>(loc);
worldname = loc.getWorld().getName();
worldUID = loc.getWorld().getUID();
x = loc.getX();
y = loc.getY();
z = loc.getZ();
yaw = loc.getYaw();
pitch = loc.getPitch();
}
public Location(String worldname, double x, double y, double z, float yaw, float pitch)
{
this.worldname = worldname;
this.x = x;
this.y = y;
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
}
public Location(String worldname, double x, double y, double z)
{
this.worldname = worldname;
this.x = x;
this.y = y;
this.z = z;
this.yaw = 0f;
this.pitch = 0f;
}
public org.bukkit.Location getBukkitLocation() throws WorldNotLoadedException
{
org.bukkit.Location loc = location == null ? null : location.get();
if (loc == null)
{
World world = null;
if (worldUID != null) {
world = Bukkit.getWorld(worldUID);
}
if (world == null) {
world = Bukkit.getWorld(worldname);
}
if (world == null) {
throw new WorldNotLoadedException(worldname);
}
loc = new org.bukkit.Location(world, getX(), getY(), getZ(), getYaw(), getPitch());
location = new WeakReference<org.bukkit.Location>(loc);
}
return loc;
}
public String getWorldName()
{
return worldname;
}
public double getX()
{
return x;
}
public double getY()
{
return y;
}
public double getZ()
{
return z;
}
public float getYaw()
{
return yaw;
}
public float getPitch()
{
return pitch;
}
public static class WorldNotLoadedException extends Exception
{
public WorldNotLoadedException(String worldname)
{
super("World "+worldname+" is not loaded.");
}
}
}

View File

@@ -1,6 +1,5 @@
package com.earth2me.essentials.storage; package com.earth2me.essentials.storage;
import com.earth2me.essentials.craftbukkit.BetterLocation;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
@@ -12,7 +11,6 @@ import java.util.Map.Entry;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -330,14 +328,7 @@ public class YamlStorageWriter implements IStorageWriter
writer.println(); writer.println();
writeIndention(depth); writeIndention(depth);
writer.print("world: "); writer.print("world: ");
if (entry instanceof BetterLocation) writeScalar(entry.getWorldName());
{
writeScalar(((BetterLocation)entry).getWorldName());
}
else
{
writeScalar(entry.getWorld().getName());
}
writeIndention(depth); writeIndention(depth);
writer.print("x: "); writer.print("x: ");
writeScalar(entry.getX()); writeScalar(entry.getX());

View File

@@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.HelpPermissions;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
@@ -53,7 +54,7 @@ public class HelpInput implements IText
if (pluginName.contains("essentials")) if (pluginName.contains("essentials"))
{ {
final String node = "essentials." + k.getKey(); final String node = "essentials." + k.getKey();
if (!settings.getData().getCommands().isDisabled(k.getKey()) && user.isAuthorized(node)) if (!settings.getData().getCommands().isDisabled(k.getKey()) && user.hasPermission(node))
{ {
lines.add("§c" + k.getKey() + "§7: " + k.getValue().get(DESCRIPTION)); lines.add("§c" + k.getKey() + "§7: " + k.getValue().get(DESCRIPTION));
} }
@@ -72,7 +73,7 @@ public class HelpInput implements IText
{ {
permissions = value.get(PERMISSIONS); permissions = value.get(PERMISSIONS);
} }
if (user.isAuthorized("essentials.help." + pluginName)) if (HelpPermissions.getPermission(pluginName).isAuthorized(user))
{ {
lines.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION)); lines.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION));
} }
@@ -81,7 +82,7 @@ public class HelpInput implements IText
boolean enabled = false; boolean enabled = false;
for (Object o : (List<Object>)permissions) for (Object o : (List<Object>)permissions)
{ {
if (o instanceof String && user.isAuthorized(o.toString())) if (o instanceof String && user.hasPermission(o.toString()))
{ {
enabled = true; enabled = true;
break; break;
@@ -94,7 +95,7 @@ public class HelpInput implements IText
} }
else if (permissions instanceof String && !"".equals(permissions)) else if (permissions instanceof String && !"".equals(permissions))
{ {
if (user.isAuthorized(permissions.toString())) if (user.hasPermission(permissions.toString()))
{ {
lines.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION)); lines.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION));
} }

View File

@@ -7,6 +7,7 @@ import com.earth2me.essentials.Teleport;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.*; import com.earth2me.essentials.api.*;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import com.earth2me.essentials.perm.Permissions;
import com.earth2me.essentials.register.payment.Method; import com.earth2me.essentials.register.payment.Method;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
@@ -76,41 +77,7 @@ public class User extends UserBase implements IUser
} }
@Override @Override
public boolean isAuthorized(String node) public void checkCooldown(final UserData.TimestampType cooldownType, final double cooldown, final boolean set, final IPermission bypassPermission) throws CooldownException
{
if (!isOnlineUser())
{
return false;
}
if (getData().isJailed())
{
return false;
}
//TODO: switch to Superperms only
return ess.getPermissionsHandler().hasPermission(base, node);
}
@Override
public boolean isAuthorized(IPermission permission)
{
return isAuthorized(permission.getPermission());
}
/*@Override
public boolean isAuthorized(IEssentialsCommand cmd)
{
return isAuthorized(cmd, "essentials.");
}
@Override
public boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix)
{
return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName()));
}*/
@Override
public void checkCooldown(final UserData.TimestampType cooldownType, final double cooldown, final boolean set, final String bypassPermission) throws CooldownException
{ {
final Calendar now = new GregorianCalendar(); final Calendar now = new GregorianCalendar();
if (getTimestamp(cooldownType) > 0) if (getTimestamp(cooldownType) > 0)
@@ -119,7 +86,7 @@ public class User extends UserBase implements IUser
cooldownTime.setTimeInMillis(getTimestamp(cooldownType)); cooldownTime.setTimeInMillis(getTimestamp(cooldownType));
cooldownTime.add(Calendar.SECOND, (int)cooldown); cooldownTime.add(Calendar.SECOND, (int)cooldown);
cooldownTime.add(Calendar.MILLISECOND, (int)((cooldown * 1000.0) % 1000.0)); cooldownTime.add(Calendar.MILLISECOND, (int)((cooldown * 1000.0) % 1000.0));
if (cooldownTime.after(now) && !isAuthorized(bypassPermission)) if (cooldownTime.after(now) && !bypassPermission.isAuthorized(this))
{ {
throw new CooldownException(Util.formatDateDiff(cooldownTime.getTimeInMillis())); throw new CooldownException(Util.formatDateDiff(cooldownTime.getTimeInMillis()));
} }
@@ -204,7 +171,7 @@ public class User extends UserBase implements IUser
public boolean canAfford(final double cost) public boolean canAfford(final double cost)
{ {
final double mon = getMoney(); final double mon = getMoney();
return mon >= cost || isAuthorized("essentials.eco.loan"); return mon >= cost || Permissions.ECO_LOAN.isAuthorized(this);
} }
public void setHome() public void setHome()
@@ -372,7 +339,7 @@ public class User extends UserBase implements IUser
acquireWriteLock(); acquireWriteLock();
try try
{ {
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set); this.setSleepingIgnored(Permissions.SLEEPINGIGNORED.isAuthorized(this) ? true : set);
if (set && !getData().isAfk()) if (set && !getData().isAfk())
{ {
afkPosition = getLocation(); afkPosition = getLocation();
@@ -389,7 +356,7 @@ public class User extends UserBase implements IUser
public boolean toggleAfk() public boolean toggleAfk()
{ {
final boolean now = super.toggleAfk(); final boolean now = super.toggleAfk();
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : now); this.setSleepingIgnored(Permissions.SLEEPINGIGNORED.isAuthorized(this) ? true : now);
return now; return now;
} }
@@ -497,7 +464,9 @@ public class User extends UserBase implements IUser
settings.acquireReadLock(); settings.acquireReadLock();
final long autoafkkick = settings.getData().getCommands().getAfk().getAutoAFKKick(); final long autoafkkick = settings.getData().getCommands().getAfk().getAutoAFKKick();
if (autoafkkick > 0 && lastActivity > 0 && (lastActivity + (autoafkkick * 1000)) < System.currentTimeMillis() if (autoafkkick > 0 && lastActivity > 0 && (lastActivity + (autoafkkick * 1000)) < System.currentTimeMillis()
&& !hidden && !isAuthorized("essentials.kick.exempt") && !isAuthorized("essentials.afk.kickexempt")) && !hidden
&& !Permissions.KICK_EXEMPT.isAuthorized(this)
&& !Permissions.AFK_KICKEXEMPT.isAuthorized(this))
{ {
final String kickReason = _("autoAfkKickReason", autoafkkick / 60.0); final String kickReason = _("autoAfkKickReason", autoafkkick / 60.0);
lastActivity = 0; lastActivity = 0;
@@ -507,7 +476,7 @@ public class User extends UserBase implements IUser
for (Player player : ess.getServer().getOnlinePlayers()) for (Player player : ess.getServer().getOnlinePlayers())
{ {
final IUser user = ess.getUser(player); final IUser user = ess.getUser(player);
if (user.isAuthorized("essentials.kick.notify")) if (Permissions.KICK_NOTIFY.isAuthorized(user))
{ {
player.sendMessage(_("playerKicked", Console.NAME, getName(), kickReason)); player.sendMessage(_("playerKicked", Console.NAME, getName(), kickReason));
} }
@@ -517,7 +486,7 @@ public class User extends UserBase implements IUser
acquireReadLock(); acquireReadLock();
try try
{ {
if (!getData().isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && isAuthorized("essentials.afk")) if (!getData().isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && Permissions.AFK.isAuthorized(this))
{ {
setAfk(true); setAfk(true);
if (!hidden) if (!hidden)
@@ -688,7 +657,7 @@ public class User extends UserBase implements IUser
} }
final Map<Integer, ItemStack> overfilled; final Map<Integer, ItemStack> overfilled;
if (isAuthorized("essentials.oversizedstacks")) if (Permissions.OVERSIZEDSTACKS.isAuthorized(this))
{ {
@Cleanup @Cleanup
final ISettings settings = ess.getSettings(); final ISettings settings = ess.getSettings();

View File

@@ -4,12 +4,14 @@ import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.InvalidNameException; import com.earth2me.essentials.api.InvalidNameException;
import com.earth2me.essentials.craftbukkit.BetterLocation;
import com.earth2me.essentials.craftbukkit.OfflineBedLocation; import com.earth2me.essentials.craftbukkit.OfflineBedLocation;
import com.earth2me.essentials.storage.AsyncStorageObjectHolder; import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
import com.earth2me.essentials.storage.Location.WorldNotLoadedException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import lombok.Cleanup; import lombok.Cleanup;
import lombok.Delegate; import lombok.Delegate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -32,7 +34,7 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
Player.class, Entity.class, CommandSender.class, ServerOperator.class, Player.class, Entity.class, CommandSender.class, ServerOperator.class,
HumanEntity.class, ConfigurationSerializable.class, LivingEntity.class, HumanEntity.class, ConfigurationSerializable.class, LivingEntity.class,
Permissible.class Permissible.class
}, excludes = {IOfflinePlayer.class, OtherExcludes.class}) }, excludes = {IOfflinePlayer.class})
protected Player base; protected Player base;
protected transient OfflinePlayer offlinePlayer; protected transient OfflinePlayer offlinePlayer;
@@ -116,7 +118,14 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
} }
else else
{ {
return OfflineBedLocation.getBedLocation(base.getName(), ess); try
{
return OfflineBedLocation.getBedLocation(base.getName(), ess).getBukkitLocation();
}
catch (WorldNotLoadedException ex)
{
return null;
}
} }
} }
@@ -437,14 +446,4 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
unlock(); unlock();
} }
} }
@Override
public Location getLocation()
{
return new BetterLocation(base.getLocation());
}
public static interface OtherExcludes {
Location getLocation();
}
} }

View File

@@ -2,8 +2,8 @@ package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.craftbukkit.FakeWorld;
import com.earth2me.essentials.settings.Spawns; import com.earth2me.essentials.settings.Spawns;
import com.earth2me.essentials.storage.Location;
import com.earth2me.essentials.storage.YamlStorageWriter; import com.earth2me.essentials.storage.YamlStorageWriter;
import java.io.*; import java.io.*;
import java.math.BigInteger; import java.math.BigInteger;
@@ -13,11 +13,11 @@ import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@Deprecated @Deprecated
public class EssentialsUpgrade public class EssentialsUpgrade
{ {
@@ -211,14 +211,10 @@ public class EssentialsUpgrade
continue; continue;
} }
World world = ess.getServer().getWorlds().get(0); World world = ess.getServer().getWorlds().get(0);
if (vals.size() > 5)
{
world = ess.getServer().getWorld((String)vals.get(5));
}
if (world != null) if (world != null)
{ {
final Location loc = new Location( final Location loc = new Location(
world, (String)vals.get(5),
((Number)vals.get(0)).doubleValue(), ((Number)vals.get(0)).doubleValue(),
((Number)vals.get(1)).doubleValue(), ((Number)vals.get(1)).doubleValue(),
((Number)vals.get(2)).doubleValue(), ((Number)vals.get(2)).doubleValue(),
@@ -352,7 +348,7 @@ public class EssentialsUpgrade
{ {
continue; continue;
} }
worldName = loc.getWorld().getName().toLowerCase(Locale.ENGLISH); worldName = loc.getWorldName().toLowerCase(Locale.ENGLISH);
if (worldName != null && !worldName.isEmpty()) if (worldName != null && !worldName.isEmpty())
{ {
config.setProperty("homes." + worldName, loc); config.setProperty("homes." + worldName, loc);
@@ -373,54 +369,21 @@ public class EssentialsUpgrade
doneFile.save(); doneFile.save();
} }
/*private void moveUsersDataToUserdataFolder() /*
{ * private void moveUsersDataToUserdataFolder() { final File usersFile = new File(ess.getDataFolder(), "users.yml");
final File usersFile = new File(ess.getDataFolder(), "users.yml"); * if (!usersFile.exists()) { return; } final EssentialsConf usersConfig = new EssentialsConf(usersFile);
if (!usersFile.exists()) * usersConfig.load(); for (String username : usersConfig.getKeys(null)) { final User user = new User(new
{ * OfflinePlayer(username, ess), ess); final String nickname = usersConfig.getString(username + ".nickname"); if
return; * (nickname != null && !nickname.isEmpty() && !nickname.equals(username)) { user.setNickname(nickname); } final
} * List<String> mails = usersConfig.getStringList(username + ".mail", null); if (mails != null && !mails.isEmpty())
final EssentialsConf usersConfig = new EssentialsConf(usersFile); * { user.setMails(mails); } if (!user.hasHome()) { @SuppressWarnings("unchecked") final List<Object> vals =
usersConfig.load(); * (List<Object>)usersConfig.getProperty(username + ".home"); if (vals != null) { World world =
for (String username : usersConfig.getKeys(null)) * ess.getServer().getWorlds().get(0); if (vals.size() > 5) { world = getFakeWorld((String)vals.get(5)); } if (world
{ * != null) { user.setHome("home", new Location(world, ((Number)vals.get(0)).doubleValue(),
final User user = new User(new OfflinePlayer(username, ess), ess); * ((Number)vals.get(1)).doubleValue(), ((Number)vals.get(2)).doubleValue(), ((Number)vals.get(3)).floatValue(),
final String nickname = usersConfig.getString(username + ".nickname"); * ((Number)vals.get(4)).floatValue())); } } } } usersFile.renameTo(new File(usersFile.getAbsolutePath() + ".old"));
if (nickname != null && !nickname.isEmpty() && !nickname.equals(username)) * }
{ */
user.setNickname(nickname);
}
final List<String> mails = usersConfig.getStringList(username + ".mail", null);
if (mails != null && !mails.isEmpty())
{
user.setMails(mails);
}
if (!user.hasHome())
{
@SuppressWarnings("unchecked")
final List<Object> vals = (List<Object>)usersConfig.getProperty(username + ".home");
if (vals != null)
{
World world = ess.getServer().getWorlds().get(0);
if (vals.size() > 5)
{
world = getFakeWorld((String)vals.get(5));
}
if (world != null)
{
user.setHome("home", new Location(world,
((Number)vals.get(0)).doubleValue(),
((Number)vals.get(1)).doubleValue(),
((Number)vals.get(2)).doubleValue(),
((Number)vals.get(3)).floatValue(),
((Number)vals.get(4)).floatValue()));
}
}
}
}
usersFile.renameTo(new File(usersFile.getAbsolutePath() + ".old"));
}*/
private void convertWarps() private void convertWarps()
{ {
final File warpsFolder = new File(ess.getDataFolder(), "warps"); final File warpsFolder = new File(ess.getDataFolder(), "warps");
@@ -475,32 +438,17 @@ public class EssentialsUpgrade
{ {
rx.close(); rx.close();
} }
World w = null;
for (World world : ess.getServer().getWorlds())
{
if (world.getEnvironment() != World.Environment.NETHER)
{
w = world;
break;
}
}
if (worldName != null) if (worldName != null)
{ {
worldName = worldName.trim(); final Location loc = new Location(worldName, x, y, z, yaw, pitch);
World w1 = null; ((Warps)ess.getWarps()).setWarp(filename.substring(0, filename.length() - 4), loc);
w1 = getFakeWorld(worldName);
if (w1 != null)
{
w = w1;
}
}
final Location loc = new Location(w, x, y, z, yaw, pitch);
ess.getWarps().setWarp(filename.substring(0, filename.length() - 4), loc);
if (!listOfFiles[i].renameTo(new File(warpsFolder, filename + ".old"))) if (!listOfFiles[i].renameTo(new File(warpsFolder, filename + ".old")))
{ {
throw new Exception(_("fileRenameError", filename)); throw new Exception(_("fileRenameError", filename));
} }
} }
}
catch (Exception ex) catch (Exception ex)
{ {
LOGGER.log(Level.SEVERE, null, ex); LOGGER.log(Level.SEVERE, null, ex);
@@ -509,7 +457,7 @@ public class EssentialsUpgrade
} }
} }
final File warpFile = new File(ess.getDataFolder(), "warps.txt"); /*final File warpFile = new File(ess.getDataFolder(), "warps.txt");
if (warpFile.exists()) if (warpFile.exists())
{ {
try try
@@ -542,7 +490,7 @@ public class EssentialsUpgrade
break; break;
} }
} }
final Location loc = new Location(w, x, y, z, yaw, pitch); final Location loc = new Location(name, x, y, z, yaw, pitch);
ess.getWarps().setWarp(name, loc); ess.getWarps().setWarp(name, loc);
if (!warpFile.renameTo(new File(ess.getDataFolder(), "warps.txt.old"))) if (!warpFile.renameTo(new File(ess.getDataFolder(), "warps.txt.old")))
{ {
@@ -559,65 +507,30 @@ public class EssentialsUpgrade
{ {
LOGGER.log(Level.SEVERE, null, ex); LOGGER.log(Level.SEVERE, null, ex);
} }
}
}
/*private void sanitizeAllUserFilenames()
{
if (doneFile.getBoolean("sanitizeAllUserFilenames", false))
{
return;
}
final File usersFolder = new File(ess.getDataFolder(), "userdata");
if (!usersFolder.exists())
{
return;
}
final File[] listOfFiles = usersFolder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
{
final String filename = listOfFiles[i].getName();
if (!listOfFiles[i].isFile() || !filename.endsWith(".yml"))
{
continue;
}
final String sanitizedFilename = Util.sanitizeFileName(filename.substring(0, filename.length() - 4)) + ".yml";
if (sanitizedFilename.equals(filename))
{
continue;
}
final File tmpFile = new File(listOfFiles[i].getParentFile(), sanitizedFilename + ".tmp");
final File newFile = new File(listOfFiles[i].getParentFile(), sanitizedFilename);
if (!listOfFiles[i].renameTo(tmpFile))
{
LOGGER.log(Level.WARNING, _("userdataMoveError", filename, sanitizedFilename));
continue;
}
if (newFile.exists())
{
LOGGER.log(Level.WARNING, _("duplicatedUserdata", filename, sanitizedFilename));
continue;
}
if (!tmpFile.renameTo(newFile))
{
LOGGER.log(Level.WARNING, _("userdataMoveBackError", sanitizedFilename, sanitizedFilename));
}
}
doneFile.setProperty("sanitizeAllUserFilenames", true);
doneFile.save();
}*/ }*/
private World getFakeWorld(final String name)
{
final File bukkitDirectory = ess.getDataFolder().getParentFile().getParentFile();
final File worldDirectory = new File(bukkitDirectory, name);
if (worldDirectory.exists() && worldDirectory.isDirectory())
{
return new FakeWorld(worldDirectory.getName(), World.Environment.NORMAL);
}
return null;
} }
/*
* private void sanitizeAllUserFilenames() { if (doneFile.getBoolean("sanitizeAllUserFilenames", false)) { return; }
* final File usersFolder = new File(ess.getDataFolder(), "userdata"); if (!usersFolder.exists()) { return; } final
* File[] listOfFiles = usersFolder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { final String
* filename = listOfFiles[i].getName(); if (!listOfFiles[i].isFile() || !filename.endsWith(".yml")) { continue; }
* final String sanitizedFilename = Util.sanitizeFileName(filename.substring(0, filename.length() - 4)) + ".yml"; if
* (sanitizedFilename.equals(filename)) { continue; } final File tmpFile = new File(listOfFiles[i].getParentFile(),
* sanitizedFilename + ".tmp"); final File newFile = new File(listOfFiles[i].getParentFile(), sanitizedFilename); if
* (!listOfFiles[i].renameTo(tmpFile)) { LOGGER.log(Level.WARNING, _("userdataMoveError", filename,
* sanitizedFilename)); continue; } if (newFile.exists()) { LOGGER.log(Level.WARNING, _("duplicatedUserdata",
* filename, sanitizedFilename)); continue; } if (!tmpFile.renameTo(newFile)) { LOGGER.log(Level.WARNING,
* _("userdataMoveBackError", sanitizedFilename, sanitizedFilename)); } }
* doneFile.setProperty("sanitizeAllUserFilenames", true); doneFile.save(); }
*/
/*
* private World getFakeWorld(final String name) { final File bukkitDirectory =
* ess.getDataFolder().getParentFile().getParentFile(); final File worldDirectory = new File(bukkitDirectory, name);
* if (worldDirectory.exists() && worldDirectory.isDirectory()) { return new FakeWorld(worldDirectory.getName(),
* World.Environment.NORMAL); } return null;
}
*/
public Location getFakeLocation(EssentialsConf config, String path) public Location getFakeLocation(EssentialsConf config, String path)
{ {
String worldName = config.getString((path != null ? path + "." : "") + "world"); String worldName = config.getString((path != null ? path + "." : "") + "world");
@@ -625,12 +538,7 @@ public class EssentialsUpgrade
{ {
return null; return null;
} }
World world = getFakeWorld(worldName); return new Location(worldName,
if (world == null)
{
return null;
}
return new Location(world,
config.getDouble((path != null ? path + "." : "") + "x", 0), config.getDouble((path != null ? path + "." : "") + "x", 0),
config.getDouble((path != null ? path + "." : "") + "y", 0), config.getDouble((path != null ? path + "." : "") + "y", 0),
config.getDouble((path != null ? path + "." : "") + "z", 0), config.getDouble((path != null ? path + "." : "") + "z", 0),

View File

@@ -0,0 +1,22 @@
package com.earth2me.essentials.chat;
import com.earth2me.essentials.api.IPermission;
import com.earth2me.essentials.perm.BasePermission;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class ChatPermissions {
private static Map<String, IPermission> permissions = new HashMap<String, IPermission>();
public static IPermission getPermission(final String groupName)
{
IPermission perm = permissions.get(groupName);
if (perm == null)
{
perm = new BasePermission("essentials.chat.",groupName.toLowerCase(Locale.ENGLISH));
permissions.put(groupName, perm);
}
return perm;
}
}

View File

@@ -8,6 +8,7 @@ import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IGroups; import com.earth2me.essentials.api.IGroups;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -77,7 +78,7 @@ public abstract class EssentialsChatPlayer implements Listener
protected void formatChat(final PlayerChatEvent event, final ChatStore chatStore) protected void formatChat(final PlayerChatEvent event, final ChatStore chatStore)
{ {
final IUser user = chatStore.getUser(); final IUser user = chatStore.getUser();
if (user.isAuthorized("essentials.chat.color")) if (Permissions.CHAT_COLOR.isAuthorized(user))
{ {
event.setMessage(Util.stripColor(event.getMessage())); event.setMessage(Util.stripColor(event.getMessage()));
} }
@@ -141,10 +142,7 @@ public abstract class EssentialsChatPlayer implements Listener
if (event.getMessage().length() > 1 && chatStore.getType().length() > 0) if (event.getMessage().length() > 1 && chatStore.getType().length() > 0)
{ {
final StringBuilder permission = new StringBuilder(); if (ChatPermissions.getPermission(chatStore.getType()).isAuthorized(user))
permission.append("essentials.chat.").append(chatStore.getType());
if (user.isAuthorized(permission.toString()))
{ {
final StringBuilder format = new StringBuilder(); final StringBuilder format = new StringBuilder();
format.append(chatStore.getType()).append("Format"); format.append(chatStore.getType()).append("Format");

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.chat;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
@@ -52,7 +53,7 @@ public class EssentialsLocalChatEventListener implements Listener
if (delta > event.getRadius()) if (delta > event.getRadius())
{ {
if (user.isAuthorized("essentials.chat.spy")) if (Permissions.CHAT_SPY.isAuthorized(user))
{ {
type = type.concat(_("chatTypeSpy")); type = type.concat(_("chatTypeSpy"));
} }

View File

@@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IReload; import com.earth2me.essentials.api.IReload;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.perm.Permissions;
import com.maxmind.geoip.Location; import com.maxmind.geoip.Location;
import com.maxmind.geoip.LookupService; import com.maxmind.geoip.LookupService;
import com.maxmind.geoip.regionName; import com.maxmind.geoip.regionName;
@@ -45,7 +46,7 @@ public class EssentialsGeoIPPlayerListener implements Listener, IReload
public void onPlayerJoin(final PlayerJoinEvent event) public void onPlayerJoin(final PlayerJoinEvent event)
{ {
final IUser u = ess.getUser(event.getPlayer()); final IUser u = ess.getUser(event.getPlayer());
if (u.isAuthorized("essentials.geoip.hide")) if (Permissions.GEOIP_HIDE.isAuthorized(u))
{ {
return; return;
} }
@@ -93,7 +94,7 @@ public class EssentialsGeoIPPlayerListener implements Listener, IReload
for (Player player : event.getPlayer().getServer().getOnlinePlayers()) for (Player player : event.getPlayer().getServer().getOnlinePlayers())
{ {
final IUser user = ess.getUser(player); final IUser user = ess.getUser(player);
if (user.isAuthorized("essentials.geoip.show")) if (Permissions.GEOIP_SHOW.isAuthorized(user))
{ {
user.sendMessage(_("geoipJoinFormat", user.getDisplayName(), builder.toString())); user.sendMessage(_("geoipJoinFormat", user.getDisplayName(), builder.toString()));
} }

View File

@@ -43,7 +43,7 @@ public class EssentialsConnect
return ess; return ess;
} }
public void alert(final IUser user, final String item, final String type) public void alert(final Player user, final String item, final String type)
{ {
final Location loc = user.getLocation(); final Location loc = user.getLocation();
final String warnMessage = _("alertFormat", user.getName(), type, item, final String warnMessage = _("alertFormat", user.getName(), type, item,
@@ -53,7 +53,7 @@ public class EssentialsConnect
for (Player p : ess.getServer().getOnlinePlayers()) for (Player p : ess.getServer().getOnlinePlayers())
{ {
final IUser alertUser = ess.getUser(p); final IUser alertUser = ess.getUser(p);
if (alertUser.isAuthorized("essentials.protect.alerts")) if (Permissions.ALERTS.isAuthorized(alertUser))
{ {
alertUser.sendMessage(warnMessage); alertUser.sendMessage(warnMessage);
} }

View File

@@ -2,13 +2,13 @@ package com.earth2me.essentials.protect;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.protect.data.IProtectedBlock; import com.earth2me.essentials.protect.data.IProtectedBlock;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@@ -34,12 +34,12 @@ public class EssentialsProtectBlockListener implements Listener
return; return;
} }
final IUser user = ess.getUser(event.getPlayer()); final Player user = event.getPlayer();
final ProtectHolder settings = prot.getSettings(); final ProtectHolder settings = prot.getSettings();
settings.acquireReadLock(); settings.acquireReadLock();
try try
{ {
if (!user.isAuthorized(Permissions.BUILD)) if (!Permissions.BUILD.isAuthorized(user))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
@@ -48,13 +48,13 @@ public class EssentialsProtectBlockListener implements Listener
final Block blockPlaced = event.getBlockPlaced(); final Block blockPlaced = event.getBlockPlaced();
final int id = blockPlaced.getTypeId(); final int id = blockPlaced.getTypeId();
if (!user.isAuthorized(BlockPlacePermissions.getPermission(blockPlaced.getType()))) if (!BlockPlacePermissions.getPermission(blockPlaced.getType()).isAuthorized(user))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (!user.hasPermission("essentials.protect.alerts.notrigger") && if (!Permissions.ALERTS_NOTRIGGER.isAuthorized(user) &&
settings.getData().getAlertOnPlacement().contains(blockPlaced.getType())) settings.getData().getAlertOnPlacement().contains(blockPlaced.getType()))
{ {
prot.getEssentialsConnect().alert(user, blockPlaced.getType().toString(), _("alertPlaced")); prot.getEssentialsConnect().alert(user, blockPlaced.getType().toString(), _("alertPlaced"));
@@ -72,7 +72,7 @@ public class EssentialsProtectBlockListener implements Listener
final List<Block> protect = new ArrayList<Block>(); final List<Block> protect = new ArrayList<Block>();
if ((blockPlaced.getType() == Material.RAILS || blockPlaced.getType() == Material.POWERED_RAIL || blockPlaced.getType() == Material.DETECTOR_RAIL) if ((blockPlaced.getType() == Material.RAILS || blockPlaced.getType() == Material.POWERED_RAIL || blockPlaced.getType() == Material.DETECTOR_RAIL)
&& settings.getData().getSignsAndRails().isProtectRails() && settings.getData().getSignsAndRails().isProtectRails()
&& user.isAuthorized("essentials.protect")) && Permissions.RAILS.isAuthorized(user))
{ {
protect.add(blockPlaced); protect.add(blockPlaced);
if (settings.getData().getSignsAndRails().isBlockBelow() if (settings.getData().getSignsAndRails().isBlockBelow()
@@ -81,7 +81,7 @@ public class EssentialsProtectBlockListener implements Listener
protect.add(blockPlaced.getRelative(BlockFace.DOWN)); protect.add(blockPlaced.getRelative(BlockFace.DOWN));
} }
} }
if ((blockPlaced.getType() == Material.SIGN_POST || blockPlaced.getType() == Material.WALL_SIGN) /*if ((blockPlaced.getType() == Material.SIGN_POST || blockPlaced.getType() == Material.WALL_SIGN)
&& settings.getData().getSignsAndRails().isProtectSigns() && settings.getData().getSignsAndRails().isProtectSigns()
&& user.isAuthorized("essentials.protect")) && user.isAuthorized("essentials.protect"))
{ {
@@ -93,7 +93,7 @@ public class EssentialsProtectBlockListener implements Listener
{ {
protect.add(event.getBlockAgainst()); protect.add(event.getBlockAgainst());
} }
} }*/
for (Block block : protect) for (Block block : protect)
{ {
prot.getStorage().protectBlock(block, user.getName()); prot.getStorage().protectBlock(block, user.getName());
@@ -144,7 +144,7 @@ public class EssentialsProtectBlockListener implements Listener
if (event.getCause().equals(BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) && event.getPlayer() != null) if (event.getCause().equals(BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) && event.getPlayer() != null)
{ {
event.setCancelled(ess.getUser(event.getPlayer()).isAuthorized(Permissions.USEFLINTSTEEL)); event.setCancelled(Permissions.USEFLINTSTEEL.isAuthorized(event.getPlayer()));
return; return;
} }
@@ -267,9 +267,9 @@ public class EssentialsProtectBlockListener implements Listener
{ {
return; return;
} }
final IUser user = ess.getUser(event.getPlayer()); final Player user = event.getPlayer();
if (!user.isAuthorized(Permissions.BUILD)) if (!Permissions.BUILD.isAuthorized(user))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
@@ -277,7 +277,7 @@ public class EssentialsProtectBlockListener implements Listener
final Block block = event.getBlock(); final Block block = event.getBlock();
final int typeId = block.getTypeId(); final int typeId = block.getTypeId();
if (!user.isAuthorized(BlockBreakPermissions.getPermission(block.getType()))) if (!BlockBreakPermissions.getPermission(block.getType()).isAuthorized(user))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
@@ -288,13 +288,13 @@ public class EssentialsProtectBlockListener implements Listener
{ {
final Material type = block.getType(); final Material type = block.getType();
if (!user.hasPermission("essentials.protect.alerts.notrigger") && settings.getData().getAlertOnBreak().contains(type)) if (!Permissions.ALERTS_NOTRIGGER.isAuthorized(user) && settings.getData().getAlertOnBreak().contains(type))
{ {
prot.getEssentialsConnect().alert(user, type.toString(), _("alertBroke")); prot.getEssentialsConnect().alert(user, type.toString(), _("alertBroke"));
} }
final IProtectedBlock storage = prot.getStorage(); final IProtectedBlock storage = prot.getStorage();
if (user.isAuthorized("essentials.protect.admin")) if (Permissions.ADMIN.isAuthorized(user))
{ {
if (type == Material.WALL_SIGN || type == Material.SIGN_POST || type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL) if (type == Material.WALL_SIGN || type == Material.SIGN_POST || type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
{ {
@@ -489,7 +489,7 @@ public class EssentialsProtectBlockListener implements Listener
} }
} }
private boolean isProtected(final Block block, final IUser user, final ProtectHolder settings) private boolean isProtected(final Block block, final Player user, final ProtectHolder settings)
{ {
final Material type = block.getType(); final Material type = block.getType();
if (settings.getData().getSignsAndRails().isProtectSigns()) if (settings.getData().getSignsAndRails().isProtectSigns())

View File

@@ -1,7 +1,6 @@
package com.earth2me.essentials.protect; package com.earth2me.essentials.protect;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.craftbukkit.FakeExplosion; import com.earth2me.essentials.craftbukkit.FakeExplosion;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@@ -46,28 +45,28 @@ public class EssentialsProtectEntityListener implements Listener
return; return;
} }
final IUser user = target instanceof Player ? ess.getUser((Player)target) : null; final Player user = target instanceof Player ? (Player)target : null;
if (target instanceof Player && event instanceof EntityDamageByBlockEvent) if (target instanceof Player && event instanceof EntityDamageByBlockEvent)
{ {
final DamageCause cause = event.getCause(); final DamageCause cause = event.getCause();
if (cause == DamageCause.CONTACT if (cause == DamageCause.CONTACT
&& (user.isAuthorized(Permissions.PREVENTDAMAGE_CONTACT) && (Permissions.PREVENTDAMAGE_CONTACT.isAuthorized(user)
&& !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (cause == DamageCause.LAVA if (cause == DamageCause.LAVA
&& (user.isAuthorized(Permissions.PREVENTDAMAGE_LAVADAMAGE) && (Permissions.PREVENTDAMAGE_LAVADAMAGE.isAuthorized(user)
&& !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (cause == DamageCause.BLOCK_EXPLOSION if (cause == DamageCause.BLOCK_EXPLOSION
&& (user.isAuthorized(Permissions.PREVENTDAMAGE_TNT) && (Permissions.PREVENTDAMAGE_TNT.isAuthorized(user)
&& !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
@@ -78,11 +77,11 @@ public class EssentialsProtectEntityListener implements Listener
{ {
final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event; final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event;
final Entity eAttack = edEvent.getDamager(); final Entity eAttack = edEvent.getDamager();
final IUser attacker = eAttack instanceof Player ? ess.getUser((Player)eAttack) : null; final Player attacker = eAttack instanceof Player ? (Player)eAttack : null;
// PVP Settings // PVP Settings
if (target instanceof Player && eAttack instanceof Player if (target instanceof Player && eAttack instanceof Player
&& (!user.isAuthorized(Permissions.PVP) || !attacker.isAuthorized(Permissions.PVP))) && (!Permissions.PVP.isAuthorized(user) || !Permissions.PVP.isAuthorized(attacker)))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
@@ -90,35 +89,35 @@ public class EssentialsProtectEntityListener implements Listener
//Creeper explode prevention //Creeper explode prevention
if (eAttack instanceof Creeper && settings.getData().getPrevent().isCreeperExplosion() if (eAttack instanceof Creeper && settings.getData().getPrevent().isCreeperExplosion()
|| (user.isAuthorized(Permissions.PREVENTDAMAGE_CREEPER) || (Permissions.PREVENTDAMAGE_CREEPER.isAuthorized(user)
&& !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball) if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
&& (user.isAuthorized(Permissions.PREVENTDAMAGE_FIREBALL) && (Permissions.PREVENTDAMAGE_FIREBALL.isAuthorized(user)
&& !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (eAttack instanceof TNTPrimed if (eAttack instanceof TNTPrimed
&& (user.isAuthorized(Permissions.PREVENTDAMAGE_TNT) && (Permissions.PREVENTDAMAGE_TNT.isAuthorized(user)
&& !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (edEvent.getDamager() instanceof Projectile if (edEvent.getDamager() instanceof Projectile
&& ((user.isAuthorized(Permissions.PREVENTDAMAGE_PROJECTILES) && ((Permissions.PREVENTDAMAGE_PROJECTILES.isAuthorized(user)
&& !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)) && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user))
|| (((Projectile)edEvent.getDamager()).getShooter() instanceof Player || (((Projectile)edEvent.getDamager()).getShooter() instanceof Player
&& (!user.isAuthorized(Permissions.PVP) && (!Permissions.PVP.isAuthorized(user)
|| !ess.getUser((Player)((Projectile)edEvent.getDamager()).getShooter()).isAuthorized(Permissions.PVP))))) || !Permissions.PVP.isAuthorized((Player)((Projectile)edEvent.getDamager()).getShooter())))))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
@@ -129,38 +128,38 @@ public class EssentialsProtectEntityListener implements Listener
if (target instanceof Player) if (target instanceof Player)
{ {
if (cause == DamageCause.FALL if (cause == DamageCause.FALL
&& (user.isAuthorized(Permissions.PREVENTDAMAGE_FALL) && (Permissions.PREVENTDAMAGE_FALL.isAuthorized(user)
&& !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (cause == DamageCause.SUFFOCATION if (cause == DamageCause.SUFFOCATION
&& (user.isAuthorized(Permissions.PREVENTDAMAGE_SUFFOCATION) && (Permissions.PREVENTDAMAGE_SUFFOCATION.isAuthorized(user)
&& !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if ((cause == DamageCause.FIRE if ((cause == DamageCause.FIRE
|| cause == DamageCause.FIRE_TICK) || cause == DamageCause.FIRE_TICK)
&& (user.isAuthorized(Permissions.PREVENTDAMAGE_FIRE) && (Permissions.PREVENTDAMAGE_FIRE.isAuthorized(user)
&& !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (cause == DamageCause.DROWNING if (cause == DamageCause.DROWNING
&& (user.isAuthorized(Permissions.PREVENTDAMAGE_DROWNING) && (Permissions.PREVENTDAMAGE_DROWNING.isAuthorized(user)
&& !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (cause == DamageCause.LIGHTNING if (cause == DamageCause.LIGHTNING
&& (user.isAuthorized(Permissions.PREVENTDAMAGE_LIGHTNING) && (Permissions.PREVENTDAMAGE_LIGHTNING.isAuthorized(user)
&& !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))) && !Permissions.PREVENTDAMAGE_NONE.isAuthorized(user)))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
@@ -289,14 +288,14 @@ public class EssentialsProtectEntityListener implements Listener
{ {
return; return;
} }
final IUser user = ess.getUser((Player)event.getTarget()); final Player user = (Player)event.getTarget();
if ((event.getReason() == TargetReason.CLOSEST_PLAYER if ((event.getReason() == TargetReason.CLOSEST_PLAYER
|| event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY || event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY
|| event.getReason() == TargetReason.PIG_ZOMBIE_TARGET || event.getReason() == TargetReason.PIG_ZOMBIE_TARGET
|| event.getReason() == TargetReason.RANDOM_TARGET || event.getReason() == TargetReason.RANDOM_TARGET
|| event.getReason() == TargetReason.TARGET_ATTACKED_OWNER || event.getReason() == TargetReason.TARGET_ATTACKED_OWNER
|| event.getReason() == TargetReason.OWNER_ATTACKED_TARGET) || event.getReason() == TargetReason.OWNER_ATTACKED_TARGET)
&& user.isAuthorized(Permissions.ENTITYTARGET)) && Permissions.ENTITYTARGET.isAuthorized(user))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;

View File

@@ -2,9 +2,9 @@ package com.earth2me.essentials.protect;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@@ -28,7 +28,7 @@ public class EssentialsProtectPlayerListener implements Listener
public void onPlayerInteract(final PlayerInteractEvent event) public void onPlayerInteract(final PlayerInteractEvent event)
{ {
// Do not return if cancelled, because the interact event has 2 cancelled states. // Do not return if cancelled, because the interact event has 2 cancelled states.
final IUser user = ess.getUser(event.getPlayer()); final Player user = event.getPlayer();
final ProtectHolder settings = prot.getSettings(); final ProtectHolder settings = prot.getSettings();
settings.acquireReadLock(); settings.acquireReadLock();
@@ -37,7 +37,7 @@ public class EssentialsProtectPlayerListener implements Listener
if (event.hasItem() if (event.hasItem()
&& (event.getItem().getType() == Material.WATER_BUCKET && (event.getItem().getType() == Material.WATER_BUCKET
|| event.getItem().getType() == Material.LAVA_BUCKET) || event.getItem().getType() == Material.LAVA_BUCKET)
&& !user.isAuthorized(Permissions.BUILD)) && !Permissions.BUILD.isAuthorized(user))
{ {
if (settings.getData().isWarnOnBuildDisallow()) if (settings.getData().isWarnOnBuildDisallow())
{ {
@@ -47,7 +47,7 @@ public class EssentialsProtectPlayerListener implements Listener
return; return;
} }
if (!user.isAuthorized(Permissions.INTERACT)) if (!Permissions.INTERACT.isAuthorized(user))
{ {
if (settings.getData().isWarnOnBuildDisallow()) if (settings.getData().isWarnOnBuildDisallow())
{ {
@@ -59,13 +59,13 @@ public class EssentialsProtectPlayerListener implements Listener
final ItemStack item = event.getItem(); final ItemStack item = event.getItem();
if (item != null if (item != null
&& !user.isAuthorized(ItemUsePermissions.getPermission(item.getType()))) && !ItemUsePermissions.getPermission(item.getType()).isAuthorized(user))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (user.isAuthorized("essentials.protect.ownerinfo") && event.getAction() == Action.RIGHT_CLICK_BLOCK) if (Permissions.OWNERINFO.isAuthorized(user) && event.getAction() == Action.RIGHT_CLICK_BLOCK)
{ {
final StringBuilder stringBuilder = new StringBuilder(); final StringBuilder stringBuilder = new StringBuilder();
boolean first = true; boolean first = true;
@@ -86,7 +86,7 @@ public class EssentialsProtectPlayerListener implements Listener
} }
} }
if (item != null if (item != null
&& !user.hasPermission("essentials.protect.alerts.notrigger") && !Permissions.ALERTS_NOTRIGGER.isAuthorized(user)
&& settings.getData().getAlertOnUse().contains(item.getType())) && settings.getData().getAlertOnUse().contains(item.getType()))
{ {
prot.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed")); prot.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed"));

View File

@@ -3,17 +3,21 @@ package com.earth2me.essentials.protect;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IPermission; import com.earth2me.essentials.api.IPermission;
import java.util.Locale; import java.util.Locale;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
public enum Permissions implements IPermission public enum Permissions implements IPermission
{ {
ALERTS,
ALERTS_NOTRIGGER,
ADMIN,
BUILD(PermissionDefault.TRUE), BUILD(PermissionDefault.TRUE),
INTERACT(PermissionDefault.TRUE),
USEFLINTSTEEL(PermissionDefault.TRUE),
PVP(PermissionDefault.TRUE),
ENTITYTARGET(PermissionDefault.TRUE), ENTITYTARGET(PermissionDefault.TRUE),
INTERACT(PermissionDefault.TRUE),
OWNERINFO,
PVP(PermissionDefault.TRUE),
PREVENTDAMAGE_FALL(PermissionDefault.FALSE), PREVENTDAMAGE_FALL(PermissionDefault.FALSE),
PREVENTDAMAGE_CREEPER(PermissionDefault.FALSE), PREVENTDAMAGE_CREEPER(PermissionDefault.FALSE),
PREVENTDAMAGE_CONTACT(PermissionDefault.FALSE), PREVENTDAMAGE_CONTACT(PermissionDefault.FALSE),
@@ -25,7 +29,9 @@ public enum Permissions implements IPermission
PREVENTDAMAGE_FIRE(PermissionDefault.FALSE), PREVENTDAMAGE_FIRE(PermissionDefault.FALSE),
PREVENTDAMAGE_DROWNING(PermissionDefault.FALSE), PREVENTDAMAGE_DROWNING(PermissionDefault.FALSE),
PREVENTDAMAGE_LIGHTNING(PermissionDefault.FALSE), PREVENTDAMAGE_LIGHTNING(PermissionDefault.FALSE),
PREVENTDAMAGE_NONE(PermissionDefault.FALSE); PREVENTDAMAGE_NONE(PermissionDefault.FALSE),
RAILS(PermissionDefault.TRUE),
USEFLINTSTEEL(PermissionDefault.TRUE);
private static final String base = "essentials.protect."; private static final String base = "essentials.protect.";
private final String permission; private final String permission;
private final PermissionDefault defaultPerm; private final PermissionDefault defaultPerm;
@@ -66,4 +72,10 @@ public enum Permissions implements IPermission
{ {
return this.defaultPerm; return this.defaultPerm;
} }
@Override
public boolean isAuthorized(CommandSender sender)
{
return sender.hasPermission(getBukkitPermission());
}
} }

View File

@@ -5,6 +5,7 @@ import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.commands.EssentialsCommand; import com.earth2me.essentials.commands.EssentialsCommand;
import com.earth2me.essentials.commands.NotEnoughArgumentsException; import com.earth2me.essentials.commands.NotEnoughArgumentsException;
import com.earth2me.essentials.perm.Permissions;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@@ -17,7 +18,7 @@ public class Commandspawn extends EssentialsCommand
{ {
final Trade charge = new Trade(commandName, ess); final Trade charge = new Trade(commandName, ess);
charge.isAffordableFor(user); charge.isAffordableFor(user);
if (args.length > 0 && user.isAuthorized("essentials.spawn.others")) if (args.length > 0 && Permissions.SPAWN_OTHERS.isAuthorized(user))
{ {
final IUser otherUser = getPlayer(args, 0); final IUser otherUser = getPlayer(args, 0);
respawn(otherUser, null); respawn(otherUser, null);

View File

@@ -5,6 +5,7 @@ import com.earth2me.essentials.api.IEssentialsModule;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.settings.Spawns; import com.earth2me.essentials.settings.Spawns;
import com.earth2me.essentials.storage.AsyncStorageObjectHolder; import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
import com.earth2me.essentials.storage.Location.WorldNotLoadedException;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
@@ -35,9 +36,9 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE
{ {
if (getData().getSpawns() == null) if (getData().getSpawns() == null)
{ {
getData().setSpawns(new HashMap<String, Location>()); getData().setSpawns(new HashMap<String, com.earth2me.essentials.storage.Location>());
} }
getData().getSpawns().put(group.toLowerCase(Locale.ENGLISH), loc); getData().getSpawns().put(group.toLowerCase(Locale.ENGLISH), new com.earth2me.essentials.storage.Location(loc));
} }
finally finally
{ {
@@ -59,7 +60,7 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE
{ {
return getWorldSpawn(); return getWorldSpawn();
} }
final Map<String, Location> spawnMap = getData().getSpawns(); final Map<String, com.earth2me.essentials.storage.Location> spawnMap = getData().getSpawns();
String groupName = group.toLowerCase(Locale.ENGLISH); String groupName = group.toLowerCase(Locale.ENGLISH);
if (!spawnMap.containsKey(groupName)) if (!spawnMap.containsKey(groupName))
{ {
@@ -69,7 +70,14 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE
{ {
return getWorldSpawn(); return getWorldSpawn();
} }
return spawnMap.get(groupName); try
{
return spawnMap.get(groupName).getBukkitLocation();
}
catch (WorldNotLoadedException ex)
{
return getWorldSpawn();
}
} }
finally finally
{ {