mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-21 14:03:54 +02:00
New Groups code, supports groups.yml file, gm and vault, new economy api.
This commit is contained in:
210
Essentials/src/com/earth2me/essentials/Economy.java
Normal file
210
Essentials/src/com/earth2me/essentials/Economy.java
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.api.*;
|
||||||
|
import com.earth2me.essentials.perm.Permissions;
|
||||||
|
import com.earth2me.essentials.settings.MoneyHolder;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import org.bukkit.plugin.ServicePriority;
|
||||||
|
|
||||||
|
|
||||||
|
public class Economy implements IEconomy
|
||||||
|
{
|
||||||
|
private final IEssentials ess;
|
||||||
|
private final MoneyHolder npcs;
|
||||||
|
|
||||||
|
public Economy(IEssentials ess)
|
||||||
|
{
|
||||||
|
this.ess = ess;
|
||||||
|
this.npcs = new MoneyHolder(ess);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getNPCBalance(String name) throws UserDoesNotExistException
|
||||||
|
{
|
||||||
|
npcs.acquireReadLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Map<String, Double> balances = npcs.getData().getBalances();
|
||||||
|
if (balances == null)
|
||||||
|
{
|
||||||
|
throw new UserDoesNotExistException(name);
|
||||||
|
}
|
||||||
|
Double balance = npcs.getData().getBalances().get(name.toLowerCase(Locale.ENGLISH));
|
||||||
|
if (balance == null)
|
||||||
|
{
|
||||||
|
throw new UserDoesNotExistException(name);
|
||||||
|
}
|
||||||
|
return balance;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
npcs.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNPCBalance(String name, double balance, boolean checkExistance) throws UserDoesNotExistException
|
||||||
|
{
|
||||||
|
npcs.acquireWriteLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Map<String, Double> balances = npcs.getData().getBalances();
|
||||||
|
if (balances == null)
|
||||||
|
{
|
||||||
|
balances = new HashMap<String, Double>();
|
||||||
|
npcs.getData().setBalances(balances);
|
||||||
|
}
|
||||||
|
if (checkExistance && !balances.containsKey(name.toLowerCase(Locale.ENGLISH)))
|
||||||
|
{
|
||||||
|
throw new UserDoesNotExistException(name);
|
||||||
|
}
|
||||||
|
balances.put(name.toLowerCase(Locale.ENGLISH), balance);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
npcs.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getStartingBalance()
|
||||||
|
{
|
||||||
|
double startingBalance = 0;
|
||||||
|
ISettings settings = ess.getSettings();
|
||||||
|
settings.acquireReadLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
startingBalance = settings.getData().getEconomy().getStartingBalance();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
settings.unlock();
|
||||||
|
}
|
||||||
|
return startingBalance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReload()
|
||||||
|
{
|
||||||
|
this.npcs.onReload(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getMoney(String name) throws UserDoesNotExistException
|
||||||
|
{
|
||||||
|
IUser user = ess.getUser(name);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return getNPCBalance(name);
|
||||||
|
}
|
||||||
|
return user.getMoney();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMoney(String name, double balance) throws NoLoanPermittedException, UserDoesNotExistException
|
||||||
|
{
|
||||||
|
IUser user = ess.getUser(name);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
setNPCBalance(name, balance, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (balance < 0.0 && !Permissions.ECO_LOAN.isAuthorized(user))
|
||||||
|
{
|
||||||
|
throw new NoLoanPermittedException();
|
||||||
|
}
|
||||||
|
user.setMoney(balance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetBalance(String name) throws NoLoanPermittedException, UserDoesNotExistException
|
||||||
|
{
|
||||||
|
setMoney(name, getStartingBalance());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String format(double amount)
|
||||||
|
{
|
||||||
|
return Util.formatCurrency(amount, ess);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean playerExists(String name)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
getMoney(name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (UserDoesNotExistException ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNPC(String name) throws UserDoesNotExistException
|
||||||
|
{
|
||||||
|
boolean result = ess.getUser(name) == null;
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
getNPCBalance(name);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean createNPC(String name)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (isNPC(name))
|
||||||
|
{
|
||||||
|
|
||||||
|
setNPCBalance(name, getStartingBalance(), false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (UserDoesNotExistException ex)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
setNPCBalance(name, getStartingBalance(), false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (UserDoesNotExistException ex1)
|
||||||
|
{
|
||||||
|
//This should never happen!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeNPC(String name) throws UserDoesNotExistException
|
||||||
|
{
|
||||||
|
npcs.acquireWriteLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Map<String, Double> balances = npcs.getData().getBalances();
|
||||||
|
if (balances == null)
|
||||||
|
{
|
||||||
|
balances = new HashMap<String, Double>();
|
||||||
|
npcs.getData().setBalances(balances);
|
||||||
|
}
|
||||||
|
if (balances.containsKey(name.toLowerCase(Locale.ENGLISH)))
|
||||||
|
{
|
||||||
|
balances.remove(name.toLowerCase(Locale.ENGLISH));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new UserDoesNotExistException(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
npcs.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -66,11 +66,12 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
private transient IItemDb itemDb;
|
private transient IItemDb itemDb;
|
||||||
private transient IGroups groups;
|
private transient IGroups groups;
|
||||||
private transient final Methods paymentMethod = new Methods();
|
private transient final Methods paymentMethod = new Methods();
|
||||||
private transient PermissionsHandler permissionsHandler;
|
//private transient PermissionsHandler permissionsHandler;
|
||||||
private transient IUserMap userMap;
|
private transient IUserMap userMap;
|
||||||
private transient ExecuteTimer execTimer;
|
private transient ExecuteTimer execTimer;
|
||||||
private transient I18n i18n;
|
private transient I18n i18n;
|
||||||
private transient ICommandHandler commandHandler;
|
private transient ICommandHandler commandHandler;
|
||||||
|
private transient Economy economy;
|
||||||
public transient boolean testing;
|
public transient boolean testing;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,8 +100,8 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
settings = new SettingsHolder(this);
|
settings = new SettingsHolder(this);
|
||||||
i18n.updateLocale("en");
|
i18n.updateLocale("en");
|
||||||
userMap = new UserMap(this);
|
userMap = new UserMap(this);
|
||||||
permissionsHandler = new PermissionsHandler(this);
|
//permissionsHandler = new PermissionsHandler(this);
|
||||||
Economy.setEss(this);
|
economy = new Economy(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -155,7 +156,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
reloadList.add(userMap);
|
reloadList.add(userMap);
|
||||||
execTimer.mark("Init(Usermap)");
|
execTimer.mark("Init(Usermap)");
|
||||||
groups = new GroupsHolder(this);
|
groups = new GroupsHolder(this);
|
||||||
reloadList.add(groups);
|
reloadList.add((GroupsHolder)groups);
|
||||||
warps = new Warps(this);
|
warps = new Warps(this);
|
||||||
reloadList.add(warps);
|
reloadList.add(warps);
|
||||||
execTimer.mark("Init(Spawn/Warp)");
|
execTimer.mark("Init(Spawn/Warp)");
|
||||||
@@ -168,6 +169,8 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
reloadList.add(kits);
|
reloadList.add(kits);
|
||||||
commandHandler = new EssentialsCommandHandler(Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command", "essentials.", this);
|
commandHandler = new EssentialsCommandHandler(Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command", "essentials.", this);
|
||||||
reloadList.add(commandHandler);
|
reloadList.add(commandHandler);
|
||||||
|
economy = new Economy(this);
|
||||||
|
reloadList.add(economy);
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
catch (YAMLException exception)
|
catch (YAMLException exception)
|
||||||
@@ -197,7 +200,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
backup = new Backup(this);
|
backup = new Backup(this);
|
||||||
permissionsHandler = new PermissionsHandler(this);
|
//permissionsHandler = new PermissionsHandler(this);
|
||||||
final EssentialsPluginListener serverListener = new EssentialsPluginListener(this);
|
final EssentialsPluginListener serverListener = new EssentialsPluginListener(this);
|
||||||
pm.registerEvents(serverListener, this);
|
pm.registerEvents(serverListener, this);
|
||||||
reloadList.add(serverListener);
|
reloadList.add(serverListener);
|
||||||
@@ -219,7 +222,6 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
|
|
||||||
final EssentialsTimer timer = new EssentialsTimer(this);
|
final EssentialsTimer timer = new EssentialsTimer(this);
|
||||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 100);
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 100);
|
||||||
Economy.setEss(this);
|
|
||||||
execTimer.mark("RegListeners");
|
execTimer.mark("RegListeners");
|
||||||
final String timeroutput = execTimer.end();
|
final String timeroutput = execTimer.end();
|
||||||
if (getSettings().isDebug())
|
if (getSettings().isDebug())
|
||||||
@@ -232,7 +234,6 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
i18n.onDisable();
|
i18n.onDisable();
|
||||||
Economy.setEss(null);
|
|
||||||
Trade.closeLog();
|
Trade.closeLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,18 +375,17 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
return this.getServer().getScheduler().scheduleSyncRepeatingTask(this, run, delay, period);
|
return this.getServer().getScheduler().scheduleSyncRepeatingTask(this, run, delay, period);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TNTExplodeListener getTNTListener()
|
public TNTExplodeListener getTNTListener()
|
||||||
{
|
{
|
||||||
return tntListener;
|
return tntListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*@Override
|
||||||
public PermissionsHandler getPermissionsHandler()
|
public PermissionsHandler getPermissionsHandler()
|
||||||
{
|
{
|
||||||
return permissionsHandler;
|
return permissionsHandler;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IItemDb getItemDb()
|
public IItemDb getItemDb()
|
||||||
@@ -416,4 +416,22 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
{
|
{
|
||||||
return commandHandler;
|
return commandHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setGroups(final IGroups groups)
|
||||||
|
{
|
||||||
|
this.groups = groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeReloadListener(IReload groups)
|
||||||
|
{
|
||||||
|
this.reloadList.remove(groups);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEconomy getEconomy()
|
||||||
|
{
|
||||||
|
return economy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
21
Essentials/src/com/earth2me/essentials/api/IEconomy.java
Normal file
21
Essentials/src/com/earth2me/essentials/api/IEconomy.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package com.earth2me.essentials.api;
|
||||||
|
|
||||||
|
|
||||||
|
public interface IEconomy extends IReload
|
||||||
|
{
|
||||||
|
public double getMoney(String name) throws UserDoesNotExistException;
|
||||||
|
|
||||||
|
public void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException;
|
||||||
|
|
||||||
|
public void resetBalance(String name) throws UserDoesNotExistException, NoLoanPermittedException;
|
||||||
|
|
||||||
|
public String format(double amount);
|
||||||
|
|
||||||
|
public boolean playerExists(String name);
|
||||||
|
|
||||||
|
public boolean isNPC(String name) throws UserDoesNotExistException;
|
||||||
|
|
||||||
|
public boolean createNPC(String name);
|
||||||
|
|
||||||
|
public void removeNPC(String name) throws UserDoesNotExistException;
|
||||||
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
package com.earth2me.essentials.api;
|
package com.earth2me.essentials.api;
|
||||||
|
|
||||||
import com.earth2me.essentials.listener.TNTExplodeListener;
|
import com.earth2me.essentials.listener.TNTExplodeListener;
|
||||||
|
import com.earth2me.essentials.perm.GMGroups;
|
||||||
import com.earth2me.essentials.perm.IPermissionsHandler;
|
import com.earth2me.essentials.perm.IPermissionsHandler;
|
||||||
import com.earth2me.essentials.register.payment.Methods;
|
import com.earth2me.essentials.register.payment.Methods;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@@ -52,9 +53,15 @@ public interface IEssentials extends Plugin
|
|||||||
|
|
||||||
int scheduleSyncRepeatingTask(Runnable run, long delay, long period);
|
int scheduleSyncRepeatingTask(Runnable run, long delay, long period);
|
||||||
|
|
||||||
IPermissionsHandler getPermissionsHandler();
|
//IPermissionsHandler getPermissionsHandler();
|
||||||
|
|
||||||
void reload();
|
void reload();
|
||||||
|
|
||||||
TNTExplodeListener getTNTListener();
|
TNTExplodeListener getTNTListener();
|
||||||
|
|
||||||
|
void setGroups(IGroups groups);
|
||||||
|
|
||||||
|
void removeReloadListener(IReload groups);
|
||||||
|
|
||||||
|
IEconomy getEconomy();
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,14 @@
|
|||||||
package com.earth2me.essentials.api;
|
package com.earth2me.essentials.api;
|
||||||
|
|
||||||
import com.earth2me.essentials.settings.Groups;
|
|
||||||
import com.earth2me.essentials.storage.IStorageObjectHolder;
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
|
||||||
public interface IGroups extends IStorageObjectHolder<Groups>
|
public interface IGroups
|
||||||
{
|
{
|
||||||
|
String getMainGroup(IUser player);
|
||||||
|
|
||||||
|
boolean inGroup(IUser player, String groupname);
|
||||||
|
|
||||||
double getHealCooldown(IUser player);
|
double getHealCooldown(IUser player);
|
||||||
|
|
||||||
double getTeleportCooldown(IUser player);
|
double getTeleportCooldown(IUser player);
|
||||||
|
@@ -33,10 +33,6 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload,
|
|||||||
|
|
||||||
void payUser(final IUser reciever, final double value) throws Exception;
|
void payUser(final IUser reciever, final double value) throws Exception;
|
||||||
|
|
||||||
String getGroup();
|
|
||||||
|
|
||||||
boolean inGroup(String group);
|
|
||||||
|
|
||||||
void setLastLocation();
|
void setLastLocation();
|
||||||
|
|
||||||
Location getHome(String name) throws Exception;
|
Location getHome(String name) throws Exception;
|
||||||
|
@@ -61,7 +61,7 @@ public class Commandlist extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final String group = player.getGroup();
|
final String group = ess.getGroups().getMainGroup(player);
|
||||||
List<IUser> list = sort.get(group);
|
List<IUser> list = sort.get(group);
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
|
@@ -2,12 +2,18 @@ package com.earth2me.essentials.listener;
|
|||||||
|
|
||||||
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.ISettings;
|
||||||
|
import com.earth2me.essentials.perm.GMGroups;
|
||||||
|
import com.earth2me.essentials.perm.VaultGroups;
|
||||||
|
import com.earth2me.essentials.settings.General;
|
||||||
|
import com.earth2me.essentials.settings.GroupsHolder;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
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;
|
||||||
import org.bukkit.event.server.PluginDisableEvent;
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
import org.bukkit.event.server.PluginEnableEvent;
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsPluginListener implements Listener, IReload
|
public class EssentialsPluginListener implements Listener, IReload
|
||||||
@@ -23,18 +29,23 @@ public class EssentialsPluginListener implements Listener, IReload
|
|||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPluginEnable(final PluginEnableEvent event)
|
public void onPluginEnable(final PluginEnableEvent event)
|
||||||
{
|
{
|
||||||
ess.getPermissionsHandler().checkPermissions();
|
checkGroups();
|
||||||
|
//ess.getPermissionsHandler().checkPermissions();
|
||||||
ess.getCommandHandler().addPlugin(event.getPlugin());
|
ess.getCommandHandler().addPlugin(event.getPlugin());
|
||||||
if (!ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().setMethod(ess.getServer().getPluginManager()))
|
if (!ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().setMethod(ess.getServer().getPluginManager()))
|
||||||
{
|
{
|
||||||
ess.getLogger().log(Level.INFO, "Payment method found ({0} version: {1})", new Object[]{ess.getPaymentMethod().getMethod().getName(), ess.getPaymentMethod().getMethod().getVersion()});
|
ess.getLogger().log(Level.INFO, "Payment method found ({0} version: {1})", new Object[]
|
||||||
|
{
|
||||||
|
ess.getPaymentMethod().getMethod().getName(), ess.getPaymentMethod().getMethod().getVersion()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPluginDisable(final PluginDisableEvent event)
|
public void onPluginDisable(final PluginDisableEvent event)
|
||||||
{
|
{
|
||||||
ess.getPermissionsHandler().checkPermissions();
|
checkGroups();
|
||||||
|
//ess.getPermissionsHandler().checkPermissions();
|
||||||
ess.getCommandHandler().removePlugin(event.getPlugin());
|
ess.getCommandHandler().removePlugin(event.getPlugin());
|
||||||
// Check to see if the plugin thats being disabled is the one we are using
|
// Check to see if the plugin thats being disabled is the one we are using
|
||||||
if (ess.getPaymentMethod() != null && ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().checkDisabled(event.getPlugin()))
|
if (ess.getPaymentMethod() != null && ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().checkDisabled(event.getPlugin()))
|
||||||
@@ -49,4 +60,50 @@ public class EssentialsPluginListener implements Listener, IReload
|
|||||||
{
|
{
|
||||||
//ess.getPermissionsHandler().setUseSuperperms(ess.getSettings().useBukkitPermissions());
|
//ess.getPermissionsHandler().setUseSuperperms(ess.getSettings().useBukkitPermissions());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkGroups()
|
||||||
|
{
|
||||||
|
ISettings settings = ess.getSettings();
|
||||||
|
settings.acquireReadLock();
|
||||||
|
General.GroupStorage storage = General.GroupStorage.FILE;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
storage = settings.getData().getGeneral().getGroupStorage();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
settings.unlock();
|
||||||
|
}
|
||||||
|
if (storage == General.GroupStorage.GROUPMANAGER)
|
||||||
|
{
|
||||||
|
Plugin groupManager = ess.getServer().getPluginManager().getPlugin("GroupManager");
|
||||||
|
if (groupManager != null && groupManager.isEnabled() && !(ess.getGroups() instanceof GMGroups))
|
||||||
|
{
|
||||||
|
if (ess.getGroups() instanceof GroupsHolder)
|
||||||
|
{
|
||||||
|
ess.removeReloadListener((GroupsHolder)ess.getGroups());
|
||||||
|
}
|
||||||
|
ess.setGroups(new GMGroups(ess, groupManager));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (storage == General.GroupStorage.VAULT)
|
||||||
|
{
|
||||||
|
Plugin vault = ess.getServer().getPluginManager().getPlugin("Vault");
|
||||||
|
if (vault != null && vault.isEnabled() && !(ess.getGroups() instanceof VaultGroups))
|
||||||
|
{
|
||||||
|
if (ess.getGroups() instanceof GroupsHolder)
|
||||||
|
{
|
||||||
|
ess.removeReloadListener((GroupsHolder)ess.getGroups());
|
||||||
|
}
|
||||||
|
ess.setGroups(new VaultGroups(ess));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!(ess.getGroups() instanceof GroupsHolder))
|
||||||
|
{
|
||||||
|
ess.setGroups(new GroupsHolder(ess));
|
||||||
|
ess.addReloadListener((GroupsHolder)ess.getGroups());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
143
Essentials/src/com/earth2me/essentials/perm/GMGroups.java
Normal file
143
Essentials/src/com/earth2me/essentials/perm/GMGroups.java
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
package com.earth2me.essentials.perm;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.Util;
|
||||||
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
|
import com.earth2me.essentials.api.IGroups;
|
||||||
|
import com.earth2me.essentials.api.ISettings;
|
||||||
|
import com.earth2me.essentials.api.IUser;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import lombok.Cleanup;
|
||||||
|
import org.anjocaido.groupmanager.GroupManager;
|
||||||
|
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class GMGroups implements IGroups {
|
||||||
|
private final transient IEssentials ess;
|
||||||
|
private final transient GroupManager groupManager;
|
||||||
|
|
||||||
|
public GMGroups(final IEssentials ess, final Plugin groupManager)
|
||||||
|
{
|
||||||
|
this.ess = ess;
|
||||||
|
this.groupManager = (GroupManager)groupManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getHealCooldown(IUser player)
|
||||||
|
{
|
||||||
|
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player.getBase());
|
||||||
|
if (handler == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return handler.getPermissionDouble(player.getName(), "healcooldown");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getTeleportCooldown(IUser player)
|
||||||
|
{
|
||||||
|
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player.getBase());
|
||||||
|
if (handler == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return handler.getPermissionDouble(player.getName(), "teleportcooldown");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getTeleportDelay(IUser player)
|
||||||
|
{
|
||||||
|
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player.getBase());
|
||||||
|
if (handler == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return handler.getPermissionDouble(player.getName(), "teleportdelay");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrefix(IUser player)
|
||||||
|
{
|
||||||
|
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player.getBase());
|
||||||
|
if (handler == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return handler.getUserPrefix(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSuffix(IUser player)
|
||||||
|
{
|
||||||
|
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player.getBase());
|
||||||
|
if (handler == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return handler.getUserSuffix(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHomeLimit(IUser player)
|
||||||
|
{
|
||||||
|
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player.getBase());
|
||||||
|
if (handler == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return handler.getPermissionInteger(player.getName(), "homes");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageFormat getChatFormat(final IUser player)
|
||||||
|
{
|
||||||
|
String format = getRawChatFormat(player);
|
||||||
|
format = Util.replaceColor(format);
|
||||||
|
format = format.replace("{DISPLAYNAME}", "%1$s");
|
||||||
|
format = format.replace("{GROUP}", "{0}");
|
||||||
|
format = format.replace("{MESSAGE}", "%2$s");
|
||||||
|
format = format.replace("{WORLDNAME}", "{1}");
|
||||||
|
format = format.replace("{SHORTWORLDNAME}", "{2}");
|
||||||
|
format = format.replaceAll("\\{(\\D*)\\}", "\\[$1\\]");
|
||||||
|
MessageFormat mFormat = new MessageFormat(format);
|
||||||
|
return mFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawChatFormat(final IUser player)
|
||||||
|
{
|
||||||
|
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player.getBase());
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
String chatformat = handler.getPermissionString(player.getName(), "chatformat");
|
||||||
|
if (chatformat != null && !chatformat.isEmpty()) {
|
||||||
|
return chatformat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Cleanup
|
||||||
|
ISettings settings = ess.getSettings();
|
||||||
|
settings.acquireReadLock();
|
||||||
|
return settings.getData().getChat().getDefaultFormat();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMainGroup(IUser player)
|
||||||
|
{
|
||||||
|
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player.getBase());
|
||||||
|
if (handler == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return handler.getGroup(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inGroup(IUser player, String groupname)
|
||||||
|
{
|
||||||
|
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player.getBase());
|
||||||
|
if (handler == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return handler.inGroup(player.getName(), groupname);
|
||||||
|
}
|
||||||
|
}
|
126
Essentials/src/com/earth2me/essentials/perm/VaultGroups.java
Normal file
126
Essentials/src/com/earth2me/essentials/perm/VaultGroups.java
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
package com.earth2me.essentials.perm;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.Util;
|
||||||
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
|
import com.earth2me.essentials.api.IGroups;
|
||||||
|
import com.earth2me.essentials.api.ISettings;
|
||||||
|
import com.earth2me.essentials.api.IUser;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import lombok.Cleanup;
|
||||||
|
import net.milkbowl.vault.chat.Chat;
|
||||||
|
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
|
|
||||||
|
public class VaultGroups implements IGroups
|
||||||
|
{
|
||||||
|
private final IEssentials ess;
|
||||||
|
|
||||||
|
public VaultGroups(final IEssentials ess)
|
||||||
|
{
|
||||||
|
this.ess = ess;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getHealCooldown(IUser player)
|
||||||
|
{
|
||||||
|
RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class);
|
||||||
|
Chat chat = rsp.getProvider();
|
||||||
|
return chat.getPlayerInfoDouble(player.getBase(), "healcooldown", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getTeleportCooldown(IUser player)
|
||||||
|
{
|
||||||
|
RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class);
|
||||||
|
Chat chat = rsp.getProvider();
|
||||||
|
return chat.getPlayerInfoDouble(player.getBase(), "teleportcooldown", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getTeleportDelay(IUser player)
|
||||||
|
{
|
||||||
|
RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class);
|
||||||
|
Chat chat = rsp.getProvider();
|
||||||
|
return chat.getPlayerInfoDouble(player.getBase(), "teleportdelay", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrefix(IUser player)
|
||||||
|
{
|
||||||
|
RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class);
|
||||||
|
Chat chat = rsp.getProvider();
|
||||||
|
return chat.getPlayerPrefix(player.getBase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSuffix(IUser player)
|
||||||
|
{
|
||||||
|
RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class);
|
||||||
|
Chat chat = rsp.getProvider();
|
||||||
|
return chat.getPlayerSuffix(player.getBase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHomeLimit(IUser player)
|
||||||
|
{
|
||||||
|
RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class);
|
||||||
|
Chat chat = rsp.getProvider();
|
||||||
|
return chat.getPlayerInfoInteger(player.getBase(), "teleportdelay", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageFormat getChatFormat(final IUser player)
|
||||||
|
{
|
||||||
|
String format = getRawChatFormat(player);
|
||||||
|
format = Util.replaceColor(format);
|
||||||
|
format = format.replace("{DISPLAYNAME}", "%1$s");
|
||||||
|
format = format.replace("{GROUP}", "{0}");
|
||||||
|
format = format.replace("{MESSAGE}", "%2$s");
|
||||||
|
format = format.replace("{WORLDNAME}", "{1}");
|
||||||
|
format = format.replace("{SHORTWORLDNAME}", "{2}");
|
||||||
|
format = format.replaceAll("\\{(\\D*)\\}", "\\[$1\\]");
|
||||||
|
MessageFormat mFormat = new MessageFormat(format);
|
||||||
|
return mFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawChatFormat(final IUser player)
|
||||||
|
{
|
||||||
|
RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class);
|
||||||
|
Chat chat = rsp.getProvider();
|
||||||
|
String chatformat = chat.getPlayerInfoString(player.getBase(), "chatformat", "");
|
||||||
|
if (chatformat != null && !chatformat.isEmpty())
|
||||||
|
{
|
||||||
|
return chatformat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Cleanup
|
||||||
|
ISettings settings = ess.getSettings();
|
||||||
|
settings.acquireReadLock();
|
||||||
|
return settings.getData().getChat().getDefaultFormat();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMainGroup(IUser player)
|
||||||
|
{
|
||||||
|
RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class);
|
||||||
|
Chat chat = rsp.getProvider();
|
||||||
|
return chat.getPrimaryGroup(player.getBase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inGroup(IUser player, String groupname)
|
||||||
|
{
|
||||||
|
RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class);
|
||||||
|
Chat chat = rsp.getProvider();
|
||||||
|
for (String group : chat.getPlayerGroups(player.getBase()))
|
||||||
|
{
|
||||||
|
if (group.equalsIgnoreCase(groupname))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -37,4 +37,18 @@ public class General implements StorageObject
|
|||||||
"How many items should be in a oversized stack?"
|
"How many items should be in a oversized stack?"
|
||||||
})
|
})
|
||||||
private int oversizedStacksize = 64;
|
private int oversizedStacksize = 64;
|
||||||
|
|
||||||
|
|
||||||
|
public enum GroupStorage
|
||||||
|
{
|
||||||
|
FILE, GROUPMANAGER, VAULT
|
||||||
|
}
|
||||||
|
@Comment(
|
||||||
|
{
|
||||||
|
"Sets the place where group options should be stored:",
|
||||||
|
" FILE: Options are stored inside groups.yml in the Essentials folder",
|
||||||
|
" GROUPMANAGER: Options are stored using the GroupManager groups",
|
||||||
|
" VAULT: Options are stored using a permissions plugin supported by Vault"
|
||||||
|
})
|
||||||
|
private GroupStorage groupStorage = GroupStorage.FILE;
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
|
|||||||
public GroupsHolder(final IEssentials ess)
|
public GroupsHolder(final IEssentials ess)
|
||||||
{
|
{
|
||||||
super(ess, Groups.class);
|
super(ess, Groups.class);
|
||||||
|
onReload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -30,7 +31,7 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
|
|||||||
return new File(ess.getDataFolder(), "groups.yml");
|
return new File(ess.getDataFolder(), "groups.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<GroupOptions> getGroups(final IUser player)
|
public Collection<Entry<String, GroupOptions>> getGroups(final IUser player)
|
||||||
{
|
{
|
||||||
acquireReadLock();
|
acquireReadLock();
|
||||||
try
|
try
|
||||||
@@ -40,14 +41,14 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
|
|||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
final ArrayList<GroupOptions> list = new ArrayList();
|
final ArrayList<Entry<String, GroupOptions>> list = new ArrayList();
|
||||||
for (Entry<String, GroupOptions> entry : groups.entrySet())
|
for (Entry<String, GroupOptions> entry : groups.entrySet())
|
||||||
{
|
{
|
||||||
if (GroupsPermissions.getPermission(entry.getKey()).isAuthorized(player))
|
if (GroupsPermissions.getPermission(entry.getKey()).isAuthorized(player))
|
||||||
{
|
{
|
||||||
if(entry.getValue() != null)
|
if(entry.getValue() != null)
|
||||||
{
|
{
|
||||||
list.add(entry.getValue());
|
list.add(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,11 +63,11 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
|
|||||||
@Override
|
@Override
|
||||||
public double getHealCooldown(final IUser player)
|
public double getHealCooldown(final IUser player)
|
||||||
{
|
{
|
||||||
for (GroupOptions groupOptions : getGroups(player))
|
for (Entry<String, GroupOptions> groupOptions : getGroups(player))
|
||||||
{
|
{
|
||||||
if (groupOptions.getHealCooldown() != null)
|
if (groupOptions.getValue().getHealCooldown() != null)
|
||||||
{
|
{
|
||||||
return groupOptions.getHealCooldown();
|
return groupOptions.getValue().getHealCooldown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -75,11 +76,11 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
|
|||||||
@Override
|
@Override
|
||||||
public double getTeleportCooldown(final IUser player)
|
public double getTeleportCooldown(final IUser player)
|
||||||
{
|
{
|
||||||
for (GroupOptions groupOptions : getGroups(player))
|
for (Entry<String, GroupOptions> groupOptions : getGroups(player))
|
||||||
{
|
{
|
||||||
if (groupOptions.getTeleportCooldown() != null)
|
if (groupOptions.getValue().getTeleportCooldown() != null)
|
||||||
{
|
{
|
||||||
return groupOptions.getTeleportCooldown();
|
return groupOptions.getValue().getTeleportCooldown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -88,11 +89,11 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
|
|||||||
@Override
|
@Override
|
||||||
public double getTeleportDelay(final IUser player)
|
public double getTeleportDelay(final IUser player)
|
||||||
{
|
{
|
||||||
for (GroupOptions groupOptions : getGroups(player))
|
for (Entry<String, GroupOptions> groupOptions : getGroups(player))
|
||||||
{
|
{
|
||||||
if (groupOptions.getTeleportDelay() != null)
|
if (groupOptions.getValue().getTeleportDelay() != null)
|
||||||
{
|
{
|
||||||
return groupOptions.getTeleportDelay();
|
return groupOptions.getValue().getTeleportDelay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -101,11 +102,11 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
|
|||||||
@Override
|
@Override
|
||||||
public String getPrefix(final IUser player)
|
public String getPrefix(final IUser player)
|
||||||
{
|
{
|
||||||
for (GroupOptions groupOptions : getGroups(player))
|
for (Entry<String, GroupOptions> groupOptions : getGroups(player))
|
||||||
{
|
{
|
||||||
if (groupOptions.getPrefix() != null)
|
if (groupOptions.getValue().getPrefix() != null)
|
||||||
{
|
{
|
||||||
return groupOptions.getPrefix();
|
return groupOptions.getValue().getPrefix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
@@ -114,11 +115,11 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
|
|||||||
@Override
|
@Override
|
||||||
public String getSuffix(final IUser player)
|
public String getSuffix(final IUser player)
|
||||||
{
|
{
|
||||||
for (GroupOptions groupOptions : getGroups(player))
|
for (Entry<String, GroupOptions> groupOptions : getGroups(player))
|
||||||
{
|
{
|
||||||
if (groupOptions.getSuffix() != null)
|
if (groupOptions.getValue().getSuffix() != null)
|
||||||
{
|
{
|
||||||
return groupOptions.getSuffix();
|
return groupOptions.getValue().getSuffix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
@@ -127,11 +128,11 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
|
|||||||
@Override
|
@Override
|
||||||
public int getHomeLimit(final IUser player)
|
public int getHomeLimit(final IUser player)
|
||||||
{
|
{
|
||||||
for (GroupOptions groupOptions : getGroups(player))
|
for (Entry<String, GroupOptions> groupOptions : getGroups(player))
|
||||||
{
|
{
|
||||||
if (groupOptions.getHomes() != null)
|
if (groupOptions.getValue().getHomes() != null)
|
||||||
{
|
{
|
||||||
return groupOptions.getHomes();
|
return groupOptions.getValue().getHomes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -155,11 +156,11 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
|
|||||||
|
|
||||||
private String getRawChatFormat(final IUser player)
|
private String getRawChatFormat(final IUser player)
|
||||||
{
|
{
|
||||||
for (GroupOptions groupOptions : getGroups(player))
|
for (Entry<String, GroupOptions> groupOptions : getGroups(player))
|
||||||
{
|
{
|
||||||
if (groupOptions != null && groupOptions.getMessageFormat() != null)
|
if (groupOptions.getValue().getMessageFormat() != null)
|
||||||
{
|
{
|
||||||
return groupOptions.getMessageFormat();
|
return groupOptions.getValue().getMessageFormat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Cleanup
|
@Cleanup
|
||||||
@@ -168,4 +169,27 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
|
|||||||
return settings.getData().getChat().getDefaultFormat();
|
return settings.getData().getChat().getDefaultFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inGroup(IUser player, String groupname)
|
||||||
|
{
|
||||||
|
for (Entry<String, GroupOptions> groupOptions : getGroups(player))
|
||||||
|
{
|
||||||
|
if (groupOptions.getKey().equalsIgnoreCase(groupname))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMainGroup(IUser player)
|
||||||
|
{
|
||||||
|
for (Entry<String, GroupOptions> groupOptions : getGroups(player))
|
||||||
|
{
|
||||||
|
return groupOptions.getKey();
|
||||||
|
}
|
||||||
|
return "default";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
17
Essentials/src/com/earth2me/essentials/settings/Money.java
Normal file
17
Essentials/src/com/earth2me/essentials/settings/Money.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class Money implements StorageObject
|
||||||
|
{
|
||||||
|
@MapValueType(Double.class)
|
||||||
|
private Map<String, Double> balances = new HashMap<String, Double>();
|
||||||
|
}
|
@@ -0,0 +1,22 @@
|
|||||||
|
package com.earth2me.essentials.settings;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
|
import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
|
public class MoneyHolder extends AsyncStorageObjectHolder<Money>
|
||||||
|
{
|
||||||
|
public MoneyHolder(IEssentials ess)
|
||||||
|
{
|
||||||
|
super(ess, Money.class);
|
||||||
|
onReload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getStorageFile() throws IOException
|
||||||
|
{
|
||||||
|
return new File(ess.getDataFolder(), "economy_npcs.yml");
|
||||||
|
}
|
||||||
|
}
|
@@ -33,7 +33,7 @@ public class TextInput implements IText
|
|||||||
file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getName()) + ".txt");
|
file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getName()) + ".txt");
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
{
|
{
|
||||||
file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getGroup()) + ".txt");
|
file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(ess.getGroups().getMainGroup(user)) + ".txt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InvalidNameException ex)
|
catch (InvalidNameException ex)
|
||||||
|
@@ -214,9 +214,7 @@ public class User extends UserBase implements IUser
|
|||||||
@Cleanup
|
@Cleanup
|
||||||
final ISettings settings = ess.getSettings();
|
final ISettings settings = ess.getSettings();
|
||||||
settings.acquireReadLock();
|
settings.acquireReadLock();
|
||||||
@Cleanup
|
|
||||||
final IGroups groups = ess.getGroups();
|
final IGroups groups = ess.getGroups();
|
||||||
groups.acquireReadLock();
|
|
||||||
// default: {PREFIX}{NICKNAMEPREFIX}{NAME}{SUFFIX}
|
// default: {PREFIX}{NICKNAMEPREFIX}{NAME}{SUFFIX}
|
||||||
String displayname = settings.getData().getChat().getDisplaynameFormat();
|
String displayname = settings.getData().getChat().getDisplaynameFormat();
|
||||||
if (settings.getData().getCommands().isDisabled("nick") || nick == null || nick.isEmpty() || nick.equals(getName()))
|
if (settings.getData().getCommands().isDisabled("nick") || nick == null || nick.isEmpty() || nick.equals(getName()))
|
||||||
@@ -533,22 +531,6 @@ public class User extends UserBase implements IUser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroup()
|
|
||||||
{
|
|
||||||
return ess.getPermissionsHandler().getGroup(base);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean inGroup(final String group)
|
|
||||||
{
|
|
||||||
return ess.getPermissionsHandler().inGroup(base, group);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canBuild()
|
|
||||||
{
|
|
||||||
return ess.getPermissionsHandler().canBuild(base, getGroup());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Location getHome(String name) throws Exception
|
public Location getHome(String name) throws Exception
|
||||||
{
|
{
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import com.earth2me.essentials.api.Economy;
|
|
||||||
import com.earth2me.essentials.api.NoLoanPermittedException;
|
import com.earth2me.essentials.api.NoLoanPermittedException;
|
||||||
import com.earth2me.essentials.api.UserDoesNotExistException;
|
import com.earth2me.essentials.api.UserDoesNotExistException;
|
||||||
import com.earth2me.essentials.craftbukkit.DummyOfflinePlayer;
|
import com.earth2me.essentials.craftbukkit.DummyOfflinePlayer;
|
||||||
@@ -44,37 +43,29 @@ public class EconomyTest extends TestCase
|
|||||||
public void testEconomy()
|
public void testEconomy()
|
||||||
{
|
{
|
||||||
// test NPC
|
// test NPC
|
||||||
assertFalse("NPC does not exists", Economy.playerExists(NPCNAME));
|
assertFalse("NPC does not exists", ess.getEconomy().playerExists(NPCNAME));
|
||||||
assertTrue("Create NPC", Economy.createNPC(NPCNAME));
|
assertTrue("Create NPC", ess.getEconomy().createNPC(NPCNAME));
|
||||||
assertTrue("NPC exists", Economy.playerExists(NPCNAME));
|
assertTrue("NPC exists", ess.getEconomy().playerExists(NPCNAME));
|
||||||
assertNotNull("NPC can be accessed", ess.getUser(NPCNAME));
|
assertNull("NPC can not be accessed", ess.getUser(NPCNAME));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Economy.removeNPC(NPCNAME);
|
ess.getEconomy().removeNPC(NPCNAME);
|
||||||
}
|
}
|
||||||
catch (UserDoesNotExistException ex)
|
catch (UserDoesNotExistException ex)
|
||||||
{
|
{
|
||||||
fail(ex.getMessage());
|
fail(ex.getMessage());
|
||||||
}
|
}
|
||||||
assertFalse("NPC can be removed", Economy.playerExists(NPCNAME));
|
assertFalse("NPC can be removed",ess.getEconomy().playerExists(NPCNAME));
|
||||||
|
|
||||||
//test Math
|
//test Math
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
assertTrue("Player exists", Economy.playerExists(PLAYERNAME));
|
assertTrue("Player exists", ess.getEconomy().playerExists(PLAYERNAME));
|
||||||
Economy.resetBalance(PLAYERNAME);
|
ess.getEconomy().resetBalance(PLAYERNAME);
|
||||||
assertEquals("Player has no money", 0.0, Economy.getMoney(PLAYERNAME));
|
assertEquals("Player has no money", 0.0, ess.getEconomy().getMoney(PLAYERNAME));
|
||||||
Economy.add(PLAYERNAME, 10.0);
|
ess.getEconomy().setMoney(PLAYERNAME, 10.0);
|
||||||
assertEquals("Add money", 10.0, Economy.getMoney(PLAYERNAME));
|
assertEquals("Set money", 10.0, ess.getEconomy().getMoney(PLAYERNAME));
|
||||||
Economy.subtract(PLAYERNAME, 5.0);
|
|
||||||
assertEquals("Subtract money", 5.0, Economy.getMoney(PLAYERNAME));
|
|
||||||
Economy.multiply(PLAYERNAME, 2.0);
|
|
||||||
assertEquals("Multiply money", 10.0, Economy.getMoney(PLAYERNAME));
|
|
||||||
Economy.divide(PLAYERNAME, 2.0);
|
|
||||||
assertEquals("Divide money", 5.0, Economy.getMoney(PLAYERNAME));
|
|
||||||
Economy.setMoney(PLAYERNAME, 10.0);
|
|
||||||
assertEquals("Set money", 10.0, Economy.getMoney(PLAYERNAME));
|
|
||||||
}
|
}
|
||||||
catch (NoLoanPermittedException ex)
|
catch (NoLoanPermittedException ex)
|
||||||
{
|
{
|
||||||
@@ -86,20 +77,20 @@ public class EconomyTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
//test Format
|
//test Format
|
||||||
assertEquals("Format $1000", "$1000", Economy.format(1000.0));
|
assertEquals("Format $1000", "$1000", ess.getEconomy().format(1000.0));
|
||||||
assertEquals("Format $10", "$10", Economy.format(10.0));
|
assertEquals("Format $10", "$10", ess.getEconomy().format(10.0));
|
||||||
assertEquals("Format $10.10", "$10.10", Economy.format(10.10));
|
assertEquals("Format $10.10", "$10.10", ess.getEconomy().format(10.10));
|
||||||
assertEquals("Format $10.10", "$10.10", Economy.format(10.102));
|
assertEquals("Format $10.10", "$10.10", ess.getEconomy().format(10.102));
|
||||||
assertEquals("Format $10.11", "$10.11", Economy.format(10.109));
|
assertEquals("Format $10.11", "$10.11", ess.getEconomy().format(10.109));
|
||||||
|
|
||||||
|
|
||||||
//test Exceptions
|
//test Exceptions
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
assertTrue("Player exists", Economy.playerExists(PLAYERNAME));
|
assertTrue("Player exists", ess.getEconomy().playerExists(PLAYERNAME));
|
||||||
Economy.resetBalance(PLAYERNAME);
|
ess.getEconomy().resetBalance(PLAYERNAME);
|
||||||
assertEquals("Reset balance", 0.0, Economy.getMoney(PLAYERNAME));
|
assertEquals("Reset balance", 0.0, ess.getEconomy().getMoney(PLAYERNAME));
|
||||||
Economy.subtract(PLAYERNAME, 5.0);
|
ess.getEconomy().setMoney(PLAYERNAME, -5.0);
|
||||||
fail("Did not throw exception");
|
fail("Did not throw exception");
|
||||||
}
|
}
|
||||||
catch (NoLoanPermittedException ex)
|
catch (NoLoanPermittedException ex)
|
||||||
@@ -112,7 +103,7 @@ public class EconomyTest extends TestCase
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Economy.resetBalance("UnknownPlayer");
|
ess.getEconomy().resetBalance("UnknownPlayer");
|
||||||
fail("Did not throw exception");
|
fail("Did not throw exception");
|
||||||
}
|
}
|
||||||
catch (NoLoanPermittedException ex)
|
catch (NoLoanPermittedException ex)
|
||||||
|
@@ -80,10 +80,15 @@ public class UserTest extends TestCase
|
|||||||
assertEquals(user.getMoney(), i);
|
assertEquals(user.getMoney(), i);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
public void testGetGroup()
|
/*public void testGetGroup()
|
||||||
{
|
{
|
||||||
should("return the default group");
|
should("return the default group");
|
||||||
IUser user = ess.getUser(base1);
|
IUser user = ess.getUser(base1);
|
||||||
assertEquals(user.getGroup(), "default");
|
//assertEquals(user.getGroup(), "default");
|
||||||
|
}*/
|
||||||
|
|
||||||
|
public void testNoop()
|
||||||
|
{
|
||||||
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,6 @@
|
|||||||
package com.earth2me.essentials.api;
|
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.perm.Permissions;
|
|
||||||
import com.earth2me.essentials.user.User;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import lombok.Cleanup;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,97 +12,9 @@ public final class Economy
|
|||||||
private Economy()
|
private Economy()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
|
||||||
private static IEssentials ess;
|
private static IEssentials ess;
|
||||||
private static final String noCallBeforeLoad = "Essentials API is called before Essentials is loaded.";
|
private static final String noCallBeforeLoad = "Essentials API is called before Essentials is loaded.";
|
||||||
|
|
||||||
/**
|
|
||||||
* @param aEss the ess to set
|
|
||||||
*/
|
|
||||||
public static void setEss(IEssentials aEss)
|
|
||||||
{
|
|
||||||
ess = aEss;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void createNPCFile(String name)
|
|
||||||
{
|
|
||||||
File folder = new File(ess.getDataFolder(), "userdata");
|
|
||||||
if (!folder.exists())
|
|
||||||
{
|
|
||||||
folder.mkdirs();
|
|
||||||
}
|
|
||||||
double startingBalance = 0;
|
|
||||||
ISettings settings = ess.getSettings();
|
|
||||||
settings.acquireReadLock();
|
|
||||||
try {
|
|
||||||
startingBalance = settings.getData().getEconomy().getStartingBalance();
|
|
||||||
} finally {
|
|
||||||
settings.unlock();
|
|
||||||
}
|
|
||||||
IUser npc = new User(new DummyOfflinePlayer(name), ess);
|
|
||||||
npc.acquireWriteLock();
|
|
||||||
try {
|
|
||||||
npc.getData().setNpc(true);
|
|
||||||
npc.setMoney(startingBalance);
|
|
||||||
} finally {
|
|
||||||
npc.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*EssentialsConf npcConfig = new EssentialsConf(new File(folder, Util.sanitizeFileName(name) + ".yml"));
|
|
||||||
npcConfig.load();
|
|
||||||
npcConfig.setProperty("npc", true);
|
|
||||||
npcConfig.setProperty("money", ess.getSettings().getStartingBalance());
|
|
||||||
npcConfig.save();*/
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void deleteNPC(final String name)
|
|
||||||
{
|
|
||||||
File folder = new File(ess.getDataFolder(), "userdata");
|
|
||||||
if (!folder.exists())
|
|
||||||
{
|
|
||||||
folder.mkdirs();
|
|
||||||
}
|
|
||||||
IUser user = ess.getUser(name);
|
|
||||||
if (user != null) {
|
|
||||||
boolean npc = false;
|
|
||||||
user.acquireReadLock();
|
|
||||||
try {
|
|
||||||
npc = user.getData().isNpc();
|
|
||||||
} finally {
|
|
||||||
user.unlock();
|
|
||||||
}
|
|
||||||
if (npc) {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ess.getUserMap().removeUser(name);
|
|
||||||
}
|
|
||||||
catch (InvalidNameException ex)
|
|
||||||
{
|
|
||||||
Bukkit.getLogger().log(Level.INFO, name, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IUser getUserByName(String name)
|
|
||||||
{
|
|
||||||
if (ess == null)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(noCallBeforeLoad);
|
|
||||||
}
|
|
||||||
IUser user;
|
|
||||||
Player player = ess.getServer().getPlayer(name);
|
|
||||||
if (player != null)
|
|
||||||
{
|
|
||||||
user = ess.getUser(player);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
user = ess.getUser(name);
|
|
||||||
}
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the balance of a user
|
* Returns the balance of a user
|
||||||
* @param name Name of the user
|
* @param name Name of the user
|
||||||
@@ -120,12 +23,11 @@ public final class Economy
|
|||||||
*/
|
*/
|
||||||
public static double getMoney(String name) throws UserDoesNotExistException
|
public static double getMoney(String name) throws UserDoesNotExistException
|
||||||
{
|
{
|
||||||
IUser user = getUserByName(name);
|
if (ess == null)
|
||||||
if (user == null)
|
|
||||||
{
|
{
|
||||||
throw new UserDoesNotExistException(name);
|
throw new RuntimeException(noCallBeforeLoad);
|
||||||
}
|
}
|
||||||
return user.getMoney();
|
return ess.getEconomy().getMoney(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,16 +39,11 @@ public final class Economy
|
|||||||
*/
|
*/
|
||||||
public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException
|
public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException
|
||||||
{
|
{
|
||||||
IUser user = getUserByName(name);
|
if (ess == null)
|
||||||
if (user == null)
|
|
||||||
{
|
{
|
||||||
throw new UserDoesNotExistException(name);
|
throw new RuntimeException(noCallBeforeLoad);
|
||||||
}
|
}
|
||||||
if (balance < 0.0 && !Permissions.ECO_LOAN.isAuthorized(user))
|
ess.getEconomy().setMoney(name, balance);
|
||||||
{
|
|
||||||
throw new NoLoanPermittedException();
|
|
||||||
}
|
|
||||||
user.setMoney(balance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -213,15 +110,7 @@ public final class Economy
|
|||||||
{
|
{
|
||||||
throw new RuntimeException(noCallBeforeLoad);
|
throw new RuntimeException(noCallBeforeLoad);
|
||||||
}
|
}
|
||||||
double startingBalance = 0;
|
ess.getEconomy().resetBalance(name);
|
||||||
ISettings settings = ess.getSettings();
|
|
||||||
settings.acquireReadLock();
|
|
||||||
try {
|
|
||||||
startingBalance = settings.getData().getEconomy().getStartingBalance();
|
|
||||||
} finally {
|
|
||||||
settings.unlock();
|
|
||||||
}
|
|
||||||
setMoney(name, startingBalance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -290,7 +179,11 @@ public final class Economy
|
|||||||
*/
|
*/
|
||||||
public static boolean playerExists(String name)
|
public static boolean playerExists(String name)
|
||||||
{
|
{
|
||||||
return getUserByName(name) != null;
|
if (ess == null)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(noCallBeforeLoad);
|
||||||
|
}
|
||||||
|
return ess.getEconomy().playerExists(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -301,14 +194,11 @@ public final class Economy
|
|||||||
*/
|
*/
|
||||||
public static boolean isNPC(String name) throws UserDoesNotExistException
|
public static boolean isNPC(String name) throws UserDoesNotExistException
|
||||||
{
|
{
|
||||||
@Cleanup
|
if (ess == null)
|
||||||
IUser user = getUserByName(name);
|
|
||||||
if (user == null)
|
|
||||||
{
|
{
|
||||||
throw new UserDoesNotExistException(name);
|
throw new RuntimeException(noCallBeforeLoad);
|
||||||
}
|
}
|
||||||
user.acquireReadLock();
|
return ess.getEconomy().isNPC(name);
|
||||||
return user.getData().isNpc();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -318,13 +208,11 @@ public final class Economy
|
|||||||
*/
|
*/
|
||||||
public static boolean createNPC(String name)
|
public static boolean createNPC(String name)
|
||||||
{
|
{
|
||||||
IUser user = getUserByName(name);
|
if (ess == null)
|
||||||
if (user == null)
|
|
||||||
{
|
{
|
||||||
createNPCFile(name);
|
throw new RuntimeException(noCallBeforeLoad);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return ess.getEconomy().createNPC(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -334,11 +222,10 @@ public final class Economy
|
|||||||
*/
|
*/
|
||||||
public static void removeNPC(String name) throws UserDoesNotExistException
|
public static void removeNPC(String name) throws UserDoesNotExistException
|
||||||
{
|
{
|
||||||
IUser user = getUserByName(name);
|
if (ess == null)
|
||||||
if (user == null)
|
|
||||||
{
|
{
|
||||||
throw new UserDoesNotExistException(name);
|
throw new RuntimeException(noCallBeforeLoad);
|
||||||
}
|
}
|
||||||
deleteNPC(name);
|
ess.getEconomy().removeNPC(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -82,22 +82,14 @@ public abstract class EssentialsChatPlayer implements Listener
|
|||||||
{
|
{
|
||||||
event.setMessage(Util.stripColor(event.getMessage()));
|
event.setMessage(Util.stripColor(event.getMessage()));
|
||||||
}
|
}
|
||||||
String group = user.getGroup();
|
String group = ess.getGroups().getMainGroup(user);
|
||||||
String world = user.getWorld().getName();
|
String world = user.getWorld().getName();
|
||||||
|
|
||||||
IGroups groupSettings = ess.getGroups();
|
IGroups groupSettings = ess.getGroups();
|
||||||
groupSettings.acquireReadLock();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
event.setFormat(groupSettings.getChatFormat(user).format(new Object[]
|
event.setFormat(groupSettings.getChatFormat(user).format(new Object[]
|
||||||
{
|
{
|
||||||
group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH)
|
group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH)
|
||||||
}));
|
}));
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
groupSettings.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -52,7 +52,7 @@ public class SignKit extends EssentialsSign
|
|||||||
{
|
{
|
||||||
final String kitName = sign.getLine(1).toLowerCase(Locale.ENGLISH);
|
final String kitName = sign.getLine(1).toLowerCase(Locale.ENGLISH);
|
||||||
final String group = sign.getLine(2);
|
final String group = sign.getLine(2);
|
||||||
if ((!group.isEmpty() && ("§2Everyone".equals(group) || player.inGroup(group)))
|
if ((!group.isEmpty() && ("§2Everyone".equals(group) || ess.getGroups().inGroup(player, group)))
|
||||||
|| (group.isEmpty() && KitPermissions.getPermission(kitName).isAuthorized(player)))
|
|| (group.isEmpty() && KitPermissions.getPermission(kitName).isAuthorized(player)))
|
||||||
{
|
{
|
||||||
final Trade charge = getTrade(sign, 3, ess);
|
final Trade charge = getTrade(sign, 3, ess);
|
||||||
|
@@ -34,7 +34,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
sign.setLine(3, "§4" + username);
|
sign.setLine(3, "§4" + username);
|
||||||
if (hasAdjacentBlock(sign.getBlock()))
|
if (hasAdjacentBlock(sign.getBlock()))
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(sign.getBlock(), player, username, true);
|
final SignProtectionState state = isBlockProtected(sign.getBlock(), player, username, true, ess);
|
||||||
if (state == SignProtectionState.NOSIGN || state == SignProtectionState.OWNER
|
if (state == SignProtectionState.NOSIGN || state == SignProtectionState.OWNER
|
||||||
|| SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(player))
|
|| SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(player))
|
||||||
{
|
{
|
||||||
@@ -49,7 +49,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
@Override
|
@Override
|
||||||
protected boolean onSignBreak(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException
|
protected boolean onSignBreak(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException
|
||||||
{
|
{
|
||||||
final SignProtectionState state = checkProtectionSign(sign, player, username);
|
final SignProtectionState state = checkProtectionSign(sign, player, username, ess);
|
||||||
return state == SignProtectionState.OWNER;
|
return state == SignProtectionState.OWNER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
|
|
||||||
private void checkIfSignsAreBroken(final Block block, final IUser player, final String username, final IEssentials ess)
|
private void checkIfSignsAreBroken(final Block block, final IUser player, final String username, final IEssentials ess)
|
||||||
{
|
{
|
||||||
final Map<Location, SignProtectionState> signs = getConnectedSigns(block, player, username, false);
|
final Map<Location, SignProtectionState> signs = getConnectedSigns(block, player, username, false, ess);
|
||||||
for (Map.Entry<Location, SignProtectionState> entry : signs.entrySet())
|
for (Map.Entry<Location, SignProtectionState> entry : signs.entrySet())
|
||||||
{
|
{
|
||||||
if (entry.getValue() != SignProtectionState.NOSIGN)
|
if (entry.getValue() != SignProtectionState.NOSIGN)
|
||||||
@@ -91,14 +91,14 @@ public class SignProtection extends EssentialsSign
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Location, SignProtectionState> getConnectedSigns(final Block block, final IUser user, final String username, boolean secure)
|
private Map<Location, SignProtectionState> getConnectedSigns(final Block block, final IUser user, final String username, boolean secure, final IEssentials ess)
|
||||||
{
|
{
|
||||||
final Map<Location, SignProtectionState> signs = new HashMap<Location, SignProtectionState>();
|
final Map<Location, SignProtectionState> signs = new HashMap<Location, SignProtectionState>();
|
||||||
getConnectedSigns(block, signs, user, username, secure ? 4 : 2);
|
getConnectedSigns(block, signs, user, username, secure ? 4 : 2, ess);
|
||||||
return signs;
|
return signs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getConnectedSigns(final Block block, final Map<Location, SignProtectionState> signs, final IUser user, final String username, final int depth)
|
private void getConnectedSigns(final Block block, final Map<Location, SignProtectionState> signs, final IUser user, final String username, final int depth, final IEssentials ess)
|
||||||
{
|
{
|
||||||
final Block[] faces = getAdjacentBlocks(block);
|
final Block[] faces = getAdjacentBlocks(block);
|
||||||
for (Block b : faces)
|
for (Block b : faces)
|
||||||
@@ -108,12 +108,12 @@ public class SignProtection extends EssentialsSign
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final SignProtectionState check = checkProtectionSign(b, user, username);
|
final SignProtectionState check = checkProtectionSign(b, user, username, ess);
|
||||||
signs.put(loc, check);
|
signs.put(loc, check);
|
||||||
|
|
||||||
if (protectedBlocks.contains(b.getType()) && depth > 0)
|
if (protectedBlocks.contains(b.getType()) && depth > 0)
|
||||||
{
|
{
|
||||||
getConnectedSigns(b, signs, user, username, depth - 1);
|
getConnectedSigns(b, signs, user, username, depth - 1, ess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,20 +124,20 @@ public class SignProtection extends EssentialsSign
|
|||||||
NOT_ALLOWED, ALLOWED, NOSIGN, OWNER
|
NOT_ALLOWED, ALLOWED, NOSIGN, OWNER
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignProtectionState checkProtectionSign(final Block block, final IUser user, final String username)
|
private SignProtectionState checkProtectionSign(final Block block, final IUser user, final String username, final IEssentials ess)
|
||||||
{
|
{
|
||||||
if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)
|
if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)
|
||||||
{
|
{
|
||||||
final BlockSign sign = new BlockSign(block);
|
final BlockSign sign = new BlockSign(block);
|
||||||
if (sign.getLine(0).equalsIgnoreCase(this.getSuccessName()))
|
if (sign.getLine(0).equalsIgnoreCase(this.getSuccessName()))
|
||||||
{
|
{
|
||||||
return checkProtectionSign(sign, user, username);
|
return checkProtectionSign(sign, user, username, ess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return SignProtectionState.NOSIGN;
|
return SignProtectionState.NOSIGN;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignProtectionState checkProtectionSign(final ISign sign, final IUser user, final String username)
|
private SignProtectionState checkProtectionSign(final ISign sign, final IUser user, final String username, final IEssentials ess)
|
||||||
{
|
{
|
||||||
if (user == null || username == null)
|
if (user == null || username == null)
|
||||||
{
|
{
|
||||||
@@ -154,7 +154,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
for (int i = 1; i <= 2; i++)
|
for (int i = 1; i <= 2; i++)
|
||||||
{
|
{
|
||||||
final String line = sign.getLine(i);
|
final String line = sign.getLine(i);
|
||||||
if (line.startsWith("(") && line.endsWith(")") && user.inGroup(line.substring(1, line.length() - 1)))
|
if (line.startsWith("(") && line.endsWith(")") && ess.getGroups().inGroup(user, line.substring(1, line.length() - 1)))
|
||||||
{
|
{
|
||||||
return SignProtectionState.ALLOWED;
|
return SignProtectionState.ALLOWED;
|
||||||
}
|
}
|
||||||
@@ -179,9 +179,9 @@ public class SignProtection extends EssentialsSign
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public SignProtectionState isBlockProtected(final Block block, final IUser user, final String username, boolean secure)
|
public SignProtectionState isBlockProtected(final Block block, final IUser user, final String username, boolean secure, final IEssentials ess)
|
||||||
{
|
{
|
||||||
final Map<Location, SignProtectionState> signs = getConnectedSigns(block, user, username, secure);
|
final Map<Location, SignProtectionState> signs = getConnectedSigns(block, user, username, secure, ess);
|
||||||
SignProtectionState retstate = SignProtectionState.NOSIGN;
|
SignProtectionState retstate = SignProtectionState.NOSIGN;
|
||||||
for (SignProtectionState state : signs.values())
|
for (SignProtectionState state : signs.values())
|
||||||
{
|
{
|
||||||
@@ -251,7 +251,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
{
|
{
|
||||||
for (Block adjBlock : getAdjacentBlocks(block))
|
for (Block adjBlock : getAdjacentBlocks(block))
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(adjBlock, player, username, true);
|
final SignProtectionState state = isBlockProtected(adjBlock, player, username, true, ess);
|
||||||
|
|
||||||
if ((state == SignProtectionState.ALLOWED || state == SignProtectionState.NOT_ALLOWED)
|
if ((state == SignProtectionState.ALLOWED || state == SignProtectionState.NOT_ALLOWED)
|
||||||
&& !SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(player))
|
&& !SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(player))
|
||||||
@@ -267,7 +267,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
@Override
|
@Override
|
||||||
protected boolean onBlockInteract(final Block block, final IUser player, final String username, final IEssentials ess) throws SignException
|
protected boolean onBlockInteract(final Block block, final IUser player, final String username, final IEssentials ess) throws SignException
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(block, player, username, false);
|
final SignProtectionState state = isBlockProtected(block, player, username, false, ess);
|
||||||
|
|
||||||
if (state == SignProtectionState.OWNER || state == SignProtectionState.NOSIGN || state == SignProtectionState.ALLOWED)
|
if (state == SignProtectionState.OWNER || state == SignProtectionState.NOSIGN || state == SignProtectionState.ALLOWED)
|
||||||
{
|
{
|
||||||
@@ -288,7 +288,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
@Override
|
@Override
|
||||||
protected boolean onBlockBreak(final Block block, final IUser player, final String username, final IEssentials ess) throws SignException
|
protected boolean onBlockBreak(final Block block, final IUser player, final String username, final IEssentials ess) throws SignException
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(block, player, username, false);
|
final SignProtectionState state = isBlockProtected(block, player, username, false, ess);
|
||||||
|
|
||||||
if (state == SignProtectionState.OWNER || state == SignProtectionState.NOSIGN)
|
if (state == SignProtectionState.OWNER || state == SignProtectionState.NOSIGN)
|
||||||
{
|
{
|
||||||
@@ -311,7 +311,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
@Override
|
@Override
|
||||||
public boolean onBlockBreak(final Block block, final IEssentials ess)
|
public boolean onBlockBreak(final Block block, final IEssentials ess)
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(block, null, null, false);
|
final SignProtectionState state = isBlockProtected(block, null, null, false, ess);
|
||||||
|
|
||||||
return state == SignProtectionState.NOSIGN;
|
return state == SignProtectionState.NOSIGN;
|
||||||
}
|
}
|
||||||
@@ -319,7 +319,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
@Override
|
@Override
|
||||||
public boolean onBlockExplode(final Block block, final IEssentials ess)
|
public boolean onBlockExplode(final Block block, final IEssentials ess)
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(block, null, null, false);
|
final SignProtectionState state = isBlockProtected(block, null, null, false, ess);
|
||||||
|
|
||||||
return state == SignProtectionState.NOSIGN;
|
return state == SignProtectionState.NOSIGN;
|
||||||
}
|
}
|
||||||
@@ -327,7 +327,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
@Override
|
@Override
|
||||||
public boolean onBlockBurn(final Block block, final IEssentials ess)
|
public boolean onBlockBurn(final Block block, final IEssentials ess)
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(block, null, null, false);
|
final SignProtectionState state = isBlockProtected(block, null, null, false, ess);
|
||||||
|
|
||||||
return state == SignProtectionState.NOSIGN;
|
return state == SignProtectionState.NOSIGN;
|
||||||
}
|
}
|
||||||
@@ -335,7 +335,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
@Override
|
@Override
|
||||||
public boolean onBlockIgnite(final Block block, final IEssentials ess)
|
public boolean onBlockIgnite(final Block block, final IEssentials ess)
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(block, null, null, false);
|
final SignProtectionState state = isBlockProtected(block, null, null, false, ess);
|
||||||
|
|
||||||
return state == SignProtectionState.NOSIGN;
|
return state == SignProtectionState.NOSIGN;
|
||||||
}
|
}
|
||||||
@@ -343,7 +343,7 @@ public class SignProtection extends EssentialsSign
|
|||||||
@Override
|
@Override
|
||||||
public boolean onBlockPush(final Block block, final IEssentials ess)
|
public boolean onBlockPush(final Block block, final IEssentials ess)
|
||||||
{
|
{
|
||||||
final SignProtectionState state = isBlockProtected(block, null, null, false);
|
final SignProtectionState state = isBlockProtected(block, null, null, false, ess);
|
||||||
|
|
||||||
return state == SignProtectionState.NOSIGN;
|
return state == SignProtectionState.NOSIGN;
|
||||||
}
|
}
|
||||||
|
@@ -51,7 +51,7 @@ public class SignWarp extends EssentialsSign
|
|||||||
final String warpName = sign.getLine(1);
|
final String warpName = sign.getLine(1);
|
||||||
final String group = sign.getLine(2);
|
final String group = sign.getLine(2);
|
||||||
|
|
||||||
if ((!group.isEmpty() && ("§2Everyone".equals(group) || player.inGroup(group)))
|
if ((!group.isEmpty() && ("§2Everyone".equals(group) || ess.getGroups().inGroup(player, group)))
|
||||||
|| (group.isEmpty() && WarpPermissions.getPermission(warpName).isAuthorized(player)))
|
|| (group.isEmpty() && WarpPermissions.getPermission(warpName).isAuthorized(player)))
|
||||||
{
|
{
|
||||||
final Trade charge = getTrade(sign, 3, ess);
|
final Trade charge = getTrade(sign, 3, ess);
|
||||||
|
@@ -50,7 +50,7 @@ public class Commandspawn extends EssentialsCommand
|
|||||||
private void respawn(final IUser user, final Trade charge) throws Exception
|
private void respawn(final IUser user, final Trade charge) throws Exception
|
||||||
{
|
{
|
||||||
final SpawnStorage spawns = (SpawnStorage)this.module;
|
final SpawnStorage spawns = (SpawnStorage)this.module;
|
||||||
final Location spawn = spawns.getSpawn(user.getGroup());
|
final Location spawn = spawns.getSpawn(ess.getGroups().getMainGroup(user));
|
||||||
user.getTeleport().teleport(spawn, charge, TeleportCause.COMMAND);
|
user.getTeleport().teleport(spawn, charge, TeleportCause.COMMAND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -60,7 +60,7 @@ public class EssentialsSpawnPlayerListener implements Listener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Location spawn = spawns.getSpawn(user.getGroup());
|
final Location spawn = spawns.getSpawn(ess.getGroups().getMainGroup(user));
|
||||||
if (spawn != null)
|
if (spawn != null)
|
||||||
{
|
{
|
||||||
event.setRespawnLocation(spawn);
|
event.setRespawnLocation(spawn);
|
||||||
|
@@ -154,7 +154,7 @@ public class SpawnStorage extends AsyncStorageObjectHolder<Spawns> implements IE
|
|||||||
acquireReadLock();
|
acquireReadLock();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return getData().getNewPlayerAnnouncement().replace('&', '§').replace("§§", "&").replace("{PLAYER}", user.getDisplayName()).replace("{DISPLAYNAME}", user.getDisplayName()).replace("{GROUP}", user.getGroup()).replace("{USERNAME}", user.getName()).replace("{ADDRESS}", user.getAddress().toString());
|
return getData().getNewPlayerAnnouncement().replace('&', '§').replace("§§", "&").replace("{PLAYER}", user.getDisplayName()).replace("{DISPLAYNAME}", user.getDisplayName()).replace("{GROUP}", ess.getGroups().getMainGroup(user)).replace("{USERNAME}", user.getName()).replace("{ADDRESS}", user.getAddress().toString());
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user