1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-09-29 15:49:21 +02:00

2.9 to 3.0 merge

This commit is contained in:
ementalo
2012-05-29 22:06:04 +01:00
parent 373a48da54
commit a8af0a9259
48 changed files with 1609 additions and 239 deletions

View File

@@ -17,34 +17,25 @@
*/
package com.earth2me.essentials;
import com.earth2me.essentials.economy.Trade;
import com.earth2me.essentials.commands.EssentialsCommandHandler;
import com.earth2me.essentials.utils.ExecuteTimer;
import com.earth2me.essentials.economy.WorthHolder;
import com.earth2me.essentials.economy.Economy;
import com.earth2me.essentials.backup.Backup;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.*;
import com.earth2me.essentials.listener.*;
import com.earth2me.essentials.backup.Backup;
import com.earth2me.essentials.commands.EssentialsCommandHandler;
import com.earth2me.essentials.economy.Economy;
import com.earth2me.essentials.economy.Trade;
import com.earth2me.essentials.economy.WorthHolder;
import com.earth2me.essentials.economy.register.Methods;
import com.earth2me.essentials.ranks.RanksStorage;
import com.earth2me.essentials.settings.SettingsHolder;
import com.earth2me.essentials.settings.SpawnsHolder;
import com.earth2me.essentials.user.UserMap;
import com.earth2me.essentials.api.Economy;
import com.earth2me.essentials.api.IJails;
import com.earth2me.essentials.commands.EssentialsCommand;
import com.earth2me.essentials.commands.IEssentialsCommand;
import com.earth2me.essentials.commands.NoChargeException;
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
import com.earth2me.essentials.listener.*;
import com.earth2me.essentials.metrics.Metrics;
import com.earth2me.essentials.metrics.MetricsListener;
import com.earth2me.essentials.metrics.MetricsStarter;
import com.earth2me.essentials.perm.PermissionsHandler;
import com.earth2me.essentials.register.payment.Methods;
import com.earth2me.essentials.signs.SignBlockListener;
import com.earth2me.essentials.signs.SignEntityListener;
import com.earth2me.essentials.signs.SignPlayerListener;
import com.earth2me.essentials.ranks.RanksStorage;
import com.earth2me.essentials.settings.SettingsHolder;
import com.earth2me.essentials.settings.SpawnsHolder;
import com.earth2me.essentials.user.IOfflinePlayer;
import com.earth2me.essentials.user.User;
import com.earth2me.essentials.user.UserMap;
import com.earth2me.essentials.utils.ExecuteTimer;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
@@ -54,6 +45,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.Getter;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.command.Command;
@@ -95,7 +87,9 @@ public class Essentials extends JavaPlugin implements IEssentials
private transient Economy economy;
public transient boolean testing;
private transient Metrics metrics;
@Getter
private transient EssentialsTimer timer;
@Getter
private transient List<String> vanishedPlayers = new ArrayList<String>();
@Override
@@ -256,7 +250,7 @@ public class Essentials extends JavaPlugin implements IEssentials
final MetricsStarter metricsStarter = new MetricsStarter(this);
if (metricsStarter.getStart() != null && metricsStarter.getStart() == true)
{
getScheduler().scheduleAsyncDelayedTask(this, metricsStarter, 1);
getServer().getScheduler().scheduleAsyncDelayedTask(this, metricsStarter, 1);
}
else if (metricsStarter.getStart() != null && metricsStarter.getStart() == false)
{
@@ -345,8 +339,52 @@ public class Essentials extends JavaPlugin implements IEssentials
{
this.metrics = metrics;
}
@Override
public IUser getUser(final Object base)
{
if (base instanceof Player)
{
return getUser((Player)base);
}
if (base instanceof String)
{
final IUser user = userMap.getUser((String)base);
if (user != null && user.getBase() instanceof IOfflinePlayer)
{
((IOfflinePlayer)user.getBase()).setName((String)base);
}
return user;
}
return null;
}
private <T extends Player> IUser getUser(final T base)
{
if (base == null)
{
return null;
}
if (base instanceof IUser)
{
return (IUser)base;
}
IUser user = userMap.getUser(base.getName());
if (user == null)
{
user = new User(base, this);
}
else
{
//todo - fix this
user.update(base);
}
return user;
}
/*@Override
public IUser getUser(final Player player)
{
return userMap.getUser(player);
@@ -357,7 +395,7 @@ public class Essentials extends JavaPlugin implements IEssentials
{
return userMap.getUser(playerName);
}
*/
@Override
public World getWorld(final String name)
{

View File

@@ -9,6 +9,7 @@ import com.earth2me.essentials.user.UserData.TimestampType;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import org.bukkit.entity.Player;

View File

@@ -240,112 +240,114 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett
final Entity damager = event.getDamager();
if (damager.getType() == EntityType.PLAYER)
{
final User user = ess.getUser(damager);
if (user != null && user.isJailed())
final IUser user = ess.getUser(damager);
if (user != null && user.getData().isJailed())
{
event.setCancelled(true);
}
}
}
private class JailPlayerListener implements Listener
{
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerInteract(final PlayerInteractEvent event)
private class JailPlayerListener implements Listener
{
@Cleanup
final IUser user = ess.getUser(event.getPlayer());
user.acquireReadLock();
if (user.getData().isJailed())
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerInteract(final PlayerInteractEvent event)
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(final PlayerRespawnEvent event)
{
@Cleanup
final IUser user = ess.getUser(event.getPlayer());
user.acquireReadLock();
if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty())
{
return;
}
try
{
event.setRespawnLocation(getJail(user.getData().getJail()));
}
catch (Exception ex)
{
if (ess.getSettings().isDebug())
@Cleanup
final IUser user = ess.getUser(event.getPlayer());
user.acquireReadLock();
if (user.getData().isJailed())
{
LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex);
}
else
{
LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()));
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(final PlayerTeleportEvent event)
{
@Cleanup
final IUser user = ess.getUser(event.getPlayer());
user.acquireReadLock();
if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty())
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(final PlayerRespawnEvent event)
{
return;
}
try
{
event.setTo(getJail(user.getData().getJail()));
}
catch (Exception ex)
{
if (ess.getSettings().isDebug())
@Cleanup
final IUser user = ess.getUser(event.getPlayer());
user.acquireReadLock();
if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty())
{
LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex);
return;
}
else
try
{
LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()));
event.setRespawnLocation(getJail(user.getData().getJail()));
}
catch (Exception ex)
{
if (ess.getSettings().isDebug())
{
LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex);
}
else
{
LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()));
}
}
}
user.sendMessage(_("jailMessage"));
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(final PlayerJoinEvent event)
{
@Cleanup
final IUser user = ess.getUser(event.getPlayer());
user.acquireReadLock();
if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty())
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(final PlayerTeleportEvent event)
{
return;
@Cleanup
final IUser user = ess.getUser(event.getPlayer());
user.acquireReadLock();
if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty())
{
return;
}
try
{
event.setTo(getJail(user.getData().getJail()));
}
catch (Exception ex)
{
if (ess.getSettings().isDebug())
{
LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex);
}
else
{
LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()));
}
}
user.sendMessage(_("jailMessage"));
}
try
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(final PlayerJoinEvent event)
{
sendToJail(user, user.getData().getJail());
}
catch (Exception ex)
{
if (ess.getSettings().isDebug())
@Cleanup
final IUser user = ess.getUser(event.getPlayer());
user.acquireReadLock();
if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty())
{
LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex);
return;
}
else
try
{
LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()));
sendToJail(user, user.getData().getJail());
}
catch (Exception ex)
{
if (ess.getSettings().isDebug())
{
LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex);
}
else
{
LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()));
}
}
user.sendMessage(_("jailMessage"));
}
user.sendMessage(_("jailMessage"));
}
}
}

View File

@@ -14,6 +14,8 @@ import org.bukkit.inventory.ItemStack;
public class Kits extends AsyncStorageObjectHolder<com.earth2me.essentials.settings.Kits> implements IKits
{
public Kits(final IEssentials ess)
{
super(ess, com.earth2me.essentials.settings.Kits.class);
@@ -87,4 +89,16 @@ public class Kits extends AsyncStorageObjectHolder<com.earth2me.essentials.setti
{
return getData().getKits().isEmpty();
}
@Override
public void finishRead()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void finishWrite()
{
throw new UnsupportedOperationException("Not supported yet.");
}
}

View File

@@ -23,6 +23,7 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
public class Teleport implements Runnable, ITeleport
{
private static final double MOVE_CONSTANT = 0.3;
@@ -292,7 +293,7 @@ public class Teleport implements Runnable, ITeleport
user.unlock();
}
}
public void home(Location loc, Trade chargeFor) throws Exception
{
teleport(new Target(loc), chargeFor, TeleportCause.COMMAND);

View File

@@ -1,9 +1,10 @@
package com.earth2me.essentials.api;
import com.earth2me.essentials.listener.TntExplodeListener;
import com.earth2me.essentials.EssentialsTimer;
import com.earth2me.essentials.economy.register.Methods;
import com.earth2me.essentials.listener.TntExplodeListener;
import java.util.List;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@@ -11,9 +12,7 @@ public interface IEssentials extends Plugin
{
void addReloadListener(IReload listener);
IUser getUser(Player player);
IUser getUser(String playerName);
IUser getUser(final Object base);
int broadcastMessage(IUser sender, String message);
@@ -61,4 +60,8 @@ public interface IEssentials extends Plugin
void removeReloadListener(IReload groups);
IEconomy getEconomy();
List<String> getVanishedPlayers();
EssentialsTimer getTimer();
}

View File

@@ -18,7 +18,7 @@ public interface ITeleport
void teleport(Entity entity, Trade chargeFor, TeleportCause cause) throws Exception;
void home(IUser player, String toLowerCase, Trade charge) throws Exception;
void home(Location loc, Trade chargeFor) throws Exception;
void respawn(Trade charge, TeleportCause teleportCause) throws Exception;

View File

@@ -49,6 +49,8 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload,
void updateActivity(boolean broadcast);
void updateDisplayName();
void setDisplayNick();
boolean checkJailTimeout(long currentTime);
@@ -107,4 +109,10 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload,
public void updateMoneyCache(double userMoney);
public boolean canAfford(double amount, boolean b);
boolean isVanished();
void resetInvulnerabilityAfterTeleport();
void toggleVanished();
}

View File

@@ -1,8 +1,9 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.economy.Trade;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.economy.Trade;
import com.earth2me.essentials.permissions.WorldPermissions;
public class Commandback extends EssentialsCommand
@@ -10,12 +11,14 @@ public class Commandback extends EssentialsCommand
@Override
protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{
if (user.getWorld() != user.getLastLocation().getWorld() && ess.getSettings().isWorldTeleportPermissions()
&& !user.isAuthorized("essentials.world." + user.getLastLocation().getWorld().getName()))
final String worldName = user.getData().getLastLocation().getWorldName();
if (user.getWorld() != user.getData().getLastLocation().getBukkitLocation().getWorld() && ess.getSettings().getData().getGeneral().isWorldTeleportPermissions()
&& WorldPermissions.getPermission(worldName))
{
throw new Exception(_("noPerm", "essentials.world." + user.getLastLocation().getWorld().getName()));
throw new Exception(_("noPerm", "essentials.world." + worldName));
}
final Trade charge = new Trade(this.getName(), ess);
//tod - verify
final Trade charge = new Trade(this.toString(), ess);
charge.isAffordableFor(user);
user.sendMessage(_("backUsageMsg"));
user.getTeleport().back(charge);

View File

@@ -10,12 +10,12 @@ public class Commandbackup extends EssentialsCommand
@Override
protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
final Backup backup = ess.getBackup();
final IBackup backup = ess.getBackup();
if (backup == null)
{
throw new Exception(_("backupDisabled"));
}
final String command = ess.getSettings().getBackupCommand();
final String command = ess.getSettings().getData().getCommands().getBackupCommand();
if (command == null || "".equals(command) || "save-all".equalsIgnoreCase(command))
{
throw new Exception(_("backupDisabled"));

View File

@@ -50,7 +50,7 @@ public class Commandban extends EssentialsCommand
else
{
banReason = _("defaultBanReason");
user.setBanReason("");
user.getData().getBan().setReason("");
}
user.setBanned(true);

View File

@@ -197,5 +197,4 @@ public class Commandessentials extends EssentialsCommand
{
sender.sendMessage("Unable to modify 'plugins/PluginMetrics/config.yml': " + ex.getMessage());
}
}
}

View File

@@ -1,26 +1,22 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import com.earth2me.essentials.user.User;
import com.earth2me.essentials.utils.Util;
import com.earth2me.essentials.craftbukkit.SetExpFix;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commandexp extends EssentialsCommand
{
public Commandexp()
{
super("exp");
}
//todo - fix this
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length == 0)
if (args.length == 0 && sender instanceof Player)
{
showExp(user, user);
showExp((User)sender, (User)sender);
}
else if (args[0].equalsIgnoreCase("set") && user.isAuthorized("essentials.exp.set"))
{

View File

@@ -1,9 +1,7 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import java.util.Locale;
import org.bukkit.GameMode;
import com.earth2me.essentials.api.IUser;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -11,13 +9,8 @@ import org.bukkit.entity.Player;
public class Commandfly extends EssentialsCommand
{
public Commandfly()
{
super("fly");
}
@Override
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
@@ -28,8 +21,9 @@ public class Commandfly extends EssentialsCommand
}
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{
//todo permissions
if (args.length > 0 && args[0].trim().length() > 2 && user.isAuthorized("essentials.fly.others"))
{
flyOtherPlayers(server, user, args[0]);
@@ -47,7 +41,7 @@ public class Commandfly extends EssentialsCommand
{
for (Player matchPlayer : server.matchPlayer(name))
{
final User player = ess.getUser(matchPlayer);
final IUser player = ess.getUser(matchPlayer);
if (player.isHidden())
{
continue;

View File

@@ -19,7 +19,7 @@ public class Commandgamemode extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
gamemodeOtherPlayers(sender, args[0]);
gamemodeOtherPlayers(sender, args);
}
@Override
@@ -27,7 +27,7 @@ public class Commandgamemode extends EssentialsCommand
{
if (args.length > 0 && !args[0].trim().isEmpty() && Permissions.GAMEMODE_OTHERS.isAuthorized(user))
{
gamemodeOtherPlayers(user, args[0]);
gamemodeOtherPlayers(user, args);
return;
}
@@ -35,7 +35,7 @@ public class Commandgamemode extends EssentialsCommand
user.sendMessage(_("gameMode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName()));
}
private void gamemodeOtherPlayers(final CommandSender sender, final String name)
private void gamemodeOtherPlayers(final CommandSender sender, final String args[])
{
for (Player matchPlayer : server.matchPlayer(args[0]))
{

View File

@@ -13,6 +13,7 @@ public class Commandgetpos extends EssentialsCommand
{
if (args.length > 0 && Permissions.GETPOS_OTHERS.isAuthorized(user))
{
//todo permissions
final IUser otherUser = getPlayer(args, 0);
if (!otherUser.isHidden() || user.isAuthorized("essentials.list.hidden"))
{

View File

@@ -1,9 +1,9 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.permissions.GivePermissions;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util;
import com.earth2me.essentials.utils.Util;
import java.util.Locale;
import org.bukkit.ChatColor;
import org.bukkit.Material;

View File

@@ -1,22 +1,16 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.api.IUser;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
public class Commandhat extends EssentialsCommand
{
public Commandhat()
{
super("hat");
}
@Override
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
protected void run(IUser user, String commandLabel, String[] args) throws Exception
{
if (user.getItemInHand().getType() != Material.AIR)
{

View File

@@ -1,16 +1,14 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.utils.textreader.TextInput;
import com.earth2me.essentials.utils.textreader.IText;
import com.earth2me.essentials.utils.textreader.TextPager;
import com.earth2me.essentials.utils.textreader.HelpInput;
import com.earth2me.essentials.utils.textreader.KeywordReplacer;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.utils.Util;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.textreader.*;
import com.earth2me.essentials.utils.Util;
import com.earth2me.essentials.utils.textreader.HelpInput;
import com.earth2me.essentials.utils.textreader.IText;
import com.earth2me.essentials.utils.textreader.KeywordReplacer;
import com.earth2me.essentials.utils.textreader.TextInput;
import com.earth2me.essentials.utils.textreader.TextPager;
import java.util.Locale;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;

View File

@@ -1,10 +1,10 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.economy.Trade;
import com.earth2me.essentials.utils.Util;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.economy.Trade;
import com.earth2me.essentials.permissions.Permissions;
import com.earth2me.essentials.utils.Util;
import java.util.List;
import java.util.Locale;
import org.bukkit.Location;
@@ -89,14 +89,14 @@ public class Commandhome extends EssentialsCommand
throw new NoChargeException();
}
private void goHome(final User user, final User player, final String home, final Trade charge) throws Exception
private void goHome(final IUser user, final IUser player, final String home, final Trade charge) throws Exception
{
final Location loc = player.getHome(home);
if (loc == null)
{
throw new NotEnoughArgumentsException();
}
if (user.getWorld() != loc.getWorld() && ess.getSettings().isWorldHomePermissions()
if (user.getWorld() != loc.getWorld() && ess.getSettings().getData().getGeneral().isWorldHomePermissions()
&& !user.isAuthorized("essentials.world." + loc.getWorld().getName()))
{
throw new Exception(_("noPerm", "essentials.world." + loc.getWorld().getName()));

View File

@@ -1,10 +1,6 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.user.Inventory;
import java.util.Arrays;
import org.bukkit.inventory.ItemStack;
public class Commandinvsee extends EssentialsCommand
@@ -16,7 +12,7 @@ public class Commandinvsee extends EssentialsCommand
{
throw new NotEnoughArgumentsException();
}
final User invUser = getPlayer(server, args, 0);
final IUser invUser = getPlayer(args, 0);
user.setInvSee(true);
user.openInventory(invUser.getInventory());
}

View File

@@ -25,25 +25,21 @@ public class Commanditem extends EssentialsCommand
{
throw new Exception(_("cantSpawnItem", itemname));
}
try
{
stack.setAmount(Integer.parseInt(args[1]));
}
if (args.length > 2)
{
for (int i = 2; i < args.length; i++)
if (args.length > 1 && Integer.parseInt(args[1]) > 0)
{
stack.setAmount(Integer.parseInt(args[1]));
}
else if (ess.getSettings().getDefaultStackSize() > 0)
else if (ess.getSettings().getData().getGeneral().getDefaultStacksize() > 0)
{
stack.setAmount(ess.getSettings().getDefaultStackSize());
stack.setAmount(ess.getSettings().getData().getGeneral().getDefaultStacksize());
}
else if (ess.getSettings().getOversizedStackSize() > 0 && user.isAuthorized("essentials.oversizedstacks"))
else if (ess.getSettings().getData().getGeneral().getOversizedStacksize()> 0 && user.isAuthorized("essentials.oversizedstacks"))
{
stack.setAmount(ess.getSettings().getOversizedStackSize());
}
stack.setAmount(ess.getSettings().getData().getGeneral().getOversizedStacksize());
}
if (args.length > 2)
{
for (int i = 2; i < args.length; i++)

View File

@@ -7,7 +7,9 @@ import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.permissions.KitPermissions;
import com.earth2me.essentials.settings.Kit;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.bukkit.command.CommandSender;
@@ -38,7 +40,7 @@ public class Commandkit extends EssentialsCommand
}
else if (args.length > 1 && user.isAuthorized("essentials.kit.others"))
{
final User userTo = getPlayer(server, args, 1, true);
final IUser userTo = getPlayer(args, 1, true);
final String kitName = Util.sanitizeString(args[0].toLowerCase(Locale.ENGLISH));
giveKit(userTo, user, kitName);
}
@@ -50,7 +52,7 @@ public class Commandkit extends EssentialsCommand
}
@Override
public void run(final Server server, 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
{
if (args.length < 2)
{
@@ -59,14 +61,13 @@ public class Commandkit extends EssentialsCommand
}
else
{
final User userTo = getPlayer(server, args, 1, true);
final IUser userTo = getPlayer(args, 1, true);
final String kitName = args[0].toLowerCase(Locale.ENGLISH);
final Kit kit = ess.getKits().getKit(kitName);
final List<String> items = Kit.getItems(userTo, kit);
Kit.expandItems(ess,userTo,items);
if (!KitPermissions.getPermission(kitName).isAuthorized(user))
{
throw new Exception(_("noKitPermission", "essentials.kit." + kitName));
}
//TODO: Check kit delay
sender.sendMessage(_("kitGive", kitName));
@@ -86,7 +87,7 @@ public class Commandkit extends EssentialsCommand
}
}
private void giveKit(User userTo, User userFrom, String kitName) throws Exception
private void giveKit(IUser userTo, IUser userFrom, String kitName) throws Exception
{
final Map<String, Object> kit = ess.getSettings().getKit(kitName);

View File

@@ -39,7 +39,7 @@ public class Commandspawner extends EssentialsCommand
{
throw new Exception(_("invalidMob"));
}
if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH)))
if (ess.getSettings().getData().getGeneral().getPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH)))
{
throw new Exception(_("disabledToSpawnMob"));
}

View File

@@ -1,10 +1,10 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.utils.DescParseTickFormat;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.permissions.Permissions;
import com.earth2me.essentials.Util;
import com.earth2me.essentials.utils.DescParseTickFormat;
import com.earth2me.essentials.utils.Util;
import java.util.*;
import org.bukkit.World;
import org.bukkit.command.CommandSender;

View File

@@ -17,7 +17,7 @@ public class Commandtpo extends EssentialsCommand
throw new NotEnoughArgumentsException();
case 1:
final User player = getPlayer(server, args, 0, true);
final IUser player = getPlayer(args, 0, true);
if (!player.isOnline() || (player.isHidden() && !user.isAuthorized("essentials.teleport.hidden")))
{
throw new NoSuchFieldException(_("playerNotFound"));
@@ -37,8 +37,8 @@ public class Commandtpo extends EssentialsCommand
throw new Exception(_("noPerm", "essentials.tp.others"));
}
user.sendMessage(_("teleporting"));
final User target = getPlayer(server, args, 0, true);
final User toPlayer = getPlayer(server, args, 1, true);
final IUser target = getPlayer(args, 0, true);
final IUser toPlayer = getPlayer(args, 1, true);
if (!target.isOnline() || !toPlayer.isOnline()
|| ((target.isHidden() || toPlayer.isHidden()) && !user.isAuthorized("essentials.teleport.hidden")))

View File

@@ -38,14 +38,14 @@ public class Commandtppos extends EssentialsCommand
}
@Override
public void run(final Server server, 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
{
if (args.length < 4)
{
throw new NotEnoughArgumentsException();
}
User user = ess.getUser(server.getPlayer(args[0]));
IUser user = ess.getUser(server.getPlayer(args[0]));
final int x = Integer.parseInt(args[1]);
final int y = Integer.parseInt(args[2]);
final int z = Integer.parseInt(args[3]);

View File

@@ -1,21 +1,14 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import com.earth2me.essentials.api.IUser;
import org.bukkit.entity.Player;
public class Commandvanish extends EssentialsCommand
{
public Commandvanish()
{
super("vanish");
}
@Override
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
protected void run(IUser user, String commandLabel, String[] args) throws Exception
{
if (user.isVanished())
{

View File

@@ -1,4 +1,5 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
public class WarpNotFoundException extends Exception

View File

@@ -8,6 +8,20 @@ import java.io.IOException;
public class MoneyHolder extends AsyncStorageObjectHolder<Money>
{
@Override
public void finishRead()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void finishWrite()
{
throw new UnsupportedOperationException("Not supported yet.");
}
public MoneyHolder(IEssentials ess)
{
super(ess, Money.class);

View File

@@ -15,6 +15,20 @@ import org.bukkit.material.MaterialData;
public class WorthHolder extends AsyncStorageObjectHolder<com.earth2me.essentials.economy.Worth> implements IWorth
{
@Override
public void finishRead()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void finishWrite()
{
throw new UnsupportedOperationException("Not supported yet.");
}
public WorthHolder(final IEssentials ess)
{
super(ess, com.earth2me.essentials.economy.Worth.class);

View File

@@ -1,7 +1,6 @@
package com.earth2me.essentials.listener;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.craftbukkit.FakeExplosion;
import java.util.concurrent.atomic.AtomicBoolean;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;

View File

@@ -1,7 +1,7 @@
package com.earth2me.essentials.metrics;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser;
import java.util.logging.Level;
import org.bukkit.Server;
import org.bukkit.entity.Player;
@@ -27,7 +27,7 @@ public class MetricsListener implements Listener
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(final PlayerJoinEvent event)
{
final User player = ess.getUser(event.getPlayer());
final IUser player = ess.getUser(event.getPlayer());
if (ess.getSettings().isMetricsEnabled() == false && (player.isAuthorized("essentials.essentials") || player.isAuthorized("bukkit.broadcast.admin")))
{
player.sendMessage("PluginMetrics collects minimal statistic data, starting in about 5 minutes.");

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.metrics;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.metrics.Metrics.Graph;
import com.earth2me.essentials.metrics.Metrics.Plotter;
import com.earth2me.essentials.register.payment.Method;

View File

@@ -91,7 +91,7 @@ public class GMGroups implements IRanks {
public MessageFormat getChatFormat(final IUser player)
{
String format = getRawChatFormat(player);
format = Util.replaceColor(format);
format = Util.replaceFormat(format);
format = format.replace("{DISPLAYNAME}", "%1$s");
format = format.replace("{GROUP}", "{0}");
format = format.replace("{MESSAGE}", "%2$s");

View File

@@ -19,6 +19,18 @@ import lombok.Cleanup;
public class RanksStorage extends AsyncStorageObjectHolder<Ranks> implements IRanks
{
@Override
public void finishRead()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void finishWrite()
{
throw new UnsupportedOperationException("Not supported yet.");
}
public RanksStorage(final IEssentials ess)
{
super(ess, Ranks.class);
@@ -143,7 +155,7 @@ public class RanksStorage extends AsyncStorageObjectHolder<Ranks> implements IRa
public MessageFormat getChatFormat(final IUser player)
{
String format = getRawChatFormat(player);
format = Util.replaceColor(format);
format = Util.replaceFormat(format);
format = format.replace("{DISPLAYNAME}", "%1$s");
format = format.replace("{GROUP}", "{0}");
format = format.replace("{MESSAGE}", "%2$s");

View File

@@ -72,7 +72,7 @@ public class VaultGroups implements IRanks
public MessageFormat getChatFormat(final IUser player)
{
String format = getRawChatFormat(player);
format = Util.replaceColor(format);
format = Util.replaceFormat(format);
format = format.replace("{DISPLAYNAME}", "%1$s");
format = format.replace("{GROUP}", "{0}");
format = format.replace("{MESSAGE}", "%2$s");

View File

@@ -2,6 +2,8 @@ package com.earth2me.essentials.settings;
import com.earth2me.essentials.storage.Comment;
import com.earth2me.essentials.storage.StorageObject;
import java.util.HashMap;
import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -17,6 +19,8 @@ public class General implements StorageObject
@Comment("Turn this on, if you want to see more error messages, if something goes wrong.")
private boolean debug = false;
@Comment(
{
"Set the locale here, if you want to change the language of Essentials.",
"If this is not set, Essentials will use the language of your computer.",
@@ -24,6 +28,8 @@ public class General implements StorageObject
})
private String locale;
@Comment(
{
"The number of items given, if the quantity parameter is left out in /item or /give.",
"If this number is below 1, the maximum stack size size is given. If oversized stacks",
@@ -31,6 +37,8 @@ public class General implements StorageObject
})
private int defaultStacksize = -1;
@Comment(
{
"Oversized stacks are stacks that ignore the normal max stacksize.",
"They can be obtained using /give and /item, if the player has essentials.oversizedstacks permission.",
@@ -44,6 +52,8 @@ public class General implements StorageObject
FILE, GROUPMANAGER, VAULT
}
@Comment(
{
"Sets the place where group options should be stored:",
" FILE: Options are stored inside groups.yml in the Essentials folder",
@@ -51,4 +61,36 @@ public class General implements StorageObject
" VAULT: Options are stored using a permissions plugin supported by Vault"
})
private GroupStorage groupStorage = GroupStorage.FILE;
@Comment(
{
"The delay, in seconds, a player can't be attacked by other players after he has been teleported by a command",
"This will also prevent that the player can attack other players"
})
private long teleportInvulnerability = 0;
public long getTeleportInvulnerability()
{
return teleportInvulnerability * 1000;
}
@Comment(
{
"Set to true to enable per-world permissions for teleporting between worlds with essentials commands",
"This applies to /world, /back, /tp[a|o][here|all], but not warps.",
"Give someone permission to teleport to a world with essentials.world.<worldname>"
})
private boolean worldTeleportPermissions = false;
@Comment("Prevent creatures spawning")
private Map<String, Boolean> creatureSpawn = new HashMap<String, Boolean>();
public boolean getPreventSpawn(String creatureName)
{
if (creatureSpawn == null)
{
return false;
}
return creatureSpawn.get(creatureName);
}
}

View File

@@ -9,6 +9,18 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class SettingsHolder extends AsyncStorageObjectHolder<Settings> implements ISettings
{
@Override
public void finishRead()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void finishWrite()
{
throw new UnsupportedOperationException("Not supported yet.");
}
private final transient AtomicBoolean debug = new AtomicBoolean(false);
public SettingsHolder(final IEssentials ess)
{

View File

@@ -29,6 +29,19 @@ import org.bukkit.plugin.EventExecutor;
public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IEssentialsModule
{
@Override
public void finishRead()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void finishWrite()
{
throw new UnsupportedOperationException("Not supported yet.");
}
public SpawnsHolder(final IEssentials ess)
{
super(ess, Spawns.class);

View File

@@ -10,6 +10,19 @@ import java.io.IOException;
public class WarpHolder extends AsyncStorageObjectHolder<Warp> implements IWarp
{
@Override
public void finishRead()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void finishWrite()
{
throw new UnsupportedOperationException("Not supported yet.");
}
private final String name;
public WarpHolder(String name, IEssentials ess)

View File

@@ -5,10 +5,12 @@ import com.earth2me.essentials.storage.StorageObject;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public class WorldOptions implements StorageObject
{
@Comment("Disables godmode for all players if they teleport to this world.")
private boolean godmode = true;
private boolean godmode = true;
}

View File

@@ -9,11 +9,11 @@ import java.io.IOException;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
public abstract class AbstractDelayedYamlFileReader<T extends StorageObject> implements Runnable
{
private final transient Class<T> clazz;
protected final transient IEssentials plugin;
private final transient ReentrantLock lock = new ReentrantLock();
@@ -41,10 +41,11 @@ public abstract class AbstractDelayedYamlFileReader<T extends StorageObject> imp
@Override
public void run()
{
File file = null;
lock.lock();
try
{
final File file = onStart();
file = onStart();
try
{
final FileReader reader = new FileReader(file);
@@ -81,7 +82,7 @@ public abstract class AbstractDelayedYamlFileReader<T extends StorageObject> imp
}
catch (IOException ex)
{
onException();
onException(ex);
if (plugin.getSettings() == null || plugin.getSettings().isDebug())
{
Bukkit.getLogger().log(Level.INFO, "File not found: " + file.toString());

View File

@@ -15,4 +15,6 @@ public interface IOfflinePlayer
void setBanned(boolean bln);
boolean hasPermission(Permission perm);
void setName(final String name);
}

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.utils;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.api.InvalidNameException;
import com.earth2me.essentials.utils.gnu.inet.encoding.Punycode;
import com.earth2me.essentials.utils.gnu.inet.encoding.PunycodeException;
@@ -178,7 +179,7 @@ public final class Util
public static String formatAsCurrency(final double value)
{
String str = dFormat.format(value);
if (str.endsWith(".00"))
{
@@ -333,8 +334,95 @@ public final class Util
perm.recalculatePermissibles();
return perm;
}
private static transient final Pattern VANILLA_COLOR_PATTERN = Pattern.compile("\u00A7+[0-9A-FKa-fk]");
private static transient final Pattern EASY_COLOR_PATTERN = Pattern.compile("&([0-9a-fk])");
private static transient final Pattern URL_PATTERN = Pattern.compile("((?:(?:https?)://)?[\\w-_\\.]{2,})\\.([a-z]{2,3}(?:/\\S+)?)");
private static transient final Pattern VANILLA_PATTERN = Pattern.compile("\u00A7+[0-9A-FK-ORa-fk-or]");
private static transient final Pattern REPLACE_PATTERN = Pattern.compile("&([0-9a-fk-or])");
private static transient final Pattern VANILLA_COLOR_PATTERN = Pattern.compile("\u00A7+[0-9A-Fa-f]");
private static transient final Pattern VANILLA_MAGIC_PATTERN = Pattern.compile("\u00A7+[Kk]");
private static transient final Pattern VANILLA_FORMAT_PATTERN = Pattern.compile("\u00A7+[L-ORl-or]");
private static transient final Pattern REPLACE_COLOR_PATTERN = Pattern.compile("&([0-9a-f])");
private static transient final Pattern REPLACE_MAGIC_PATTERN = Pattern.compile("&(k)");
private static transient final Pattern REPLACE_FORMAT_PATTERN = Pattern.compile("&([l-or])");
public static String stripFormat(final String input)
{
if (input == null)
{
return null;
}
return VANILLA_PATTERN.matcher(input).replaceAll("");
}
public static String replaceFormat(final String input)
{
if (input == null)
{
return null;
}
return REPLACE_PATTERN.matcher(input).replaceAll("\u00a7$1");
}
public static String blockURL(final String input)
{
if (input == null)
{
return null;
}
String text = URL_PATTERN.matcher(input).replaceAll("$1 $2");
while (URL_PATTERN.matcher(text).find())
{
text = URL_PATTERN.matcher(text).replaceAll("$1 $2");
}
return text;
}
public static String formatString(final IUser user, final String permBase, final String input)
{
if (input == null)
{
return null;
}
String message;
if (user.isAuthorized(permBase + ".color"))
{
message = Util.replaceColor(input, REPLACE_COLOR_PATTERN);
}
else
{
message = Util.stripColor(input, VANILLA_COLOR_PATTERN);
}
if (user.isAuthorized(permBase + ".magic"))
{
message = Util.replaceColor(message, REPLACE_MAGIC_PATTERN);
}
else
{
message = Util.stripColor(message, VANILLA_MAGIC_PATTERN);
}
if (user.isAuthorized(permBase + ".format"))
{
message = Util.replaceColor(message, REPLACE_FORMAT_PATTERN);
}
else
{
message = Util.stripColor(message, VANILLA_FORMAT_PATTERN);
}
return message;
}
public static String formatMessage(final IUser user, final String permBase, final String input)
{
if (input == null)
{
return null;
}
String message = formatString(user, permBase, input);
if (!user.isAuthorized(permBase + ".url"))
{
message = Util.blockURL(message);
}
return message;
}
public static String stripColor(final String input)
{
@@ -346,13 +434,13 @@ public final class Util
return VANILLA_COLOR_PATTERN.matcher(input).replaceAll("");
}
public static String replaceColor(final String input)
private static String stripColor(final String input, final Pattern pattern)
{
if (input == null)
{
return null;
}
return pattern.matcher(input).replaceAll("");
}
return EASY_COLOR_PATTERN.matcher(input).replaceAll("\u00a7$1");
private static String replaceColor(final String input, final Pattern pattern)
{
return pattern.matcher(input).replaceAll("\u00a7$1");
}
}

View File

@@ -9,6 +9,7 @@ import com.earth2me.essentials.api.IRanks;
import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.permissions.Permissions;
import com.earth2me.essentials.storage.Location;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Logger;

View File

@@ -74,7 +74,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bukkit.version>1.2.5-R1.2-SNAPSHOT</bukkit.version>
<bukkit.version>1.2.5-R3.1-SNAPSHOT</bukkit.version>
<build.number>Unknown</build.number>
<org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs>true</org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs>
<org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width>2</org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width>