1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-10-04 01:51:58 +02:00

Merge pull request #52 from Zenexer/3.0

Misc Cleaning
This commit is contained in:
KHobbits
2012-02-23 11:47:01 -08:00
45 changed files with 106 additions and 100 deletions

1
.gitignore vendored
View File

@@ -44,3 +44,4 @@
/Essentials2Compat/build/
/EssentialsGroupManager/bin
/EssentialsGroupManager/.externalToolBuilders
/EssentialsGeoIP/build

View File

@@ -27,20 +27,15 @@ import com.earth2me.essentials.user.UserMap;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -60,7 +55,7 @@ public class Essentials extends JavaPlugin implements IEssentials
public static final int BUKKIT_VERSION = 1952;
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private transient ISettings settings;
private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this);
private final transient TntExplodeListener tntListener = new TntExplodeListener(this);
private transient IJails jails;
private transient IKits kits;
private transient IWarps warps;
@@ -230,7 +225,7 @@ public class Essentials extends JavaPlugin implements IEssentials
final String timeroutput = execTimer.end();
if (getSettings().isDebug())
{
LOGGER.log(Level.INFO, "Essentials load " + timeroutput);
LOGGER.log(Level.INFO, "Essentials load {0}", timeroutput);
}
}
@@ -380,7 +375,7 @@ public class Essentials extends JavaPlugin implements IEssentials
}
@Override
public TNTExplodeListener getTNTListener()
public TntExplodeListener getTNTListener()
{
return tntListener;
}

View File

@@ -44,6 +44,7 @@ public class I18n implements II18n
instance = null;
}
@Override
public Locale getCurrentLocale()
{
return currentLocale;

View File

@@ -1,5 +1,6 @@
package com.earth2me.essentials;
import com.earth2me.essentials.storage.ManagedFile;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IItemDb;

View File

@@ -1,6 +1,7 @@
package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.ChargeException;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.api.IUser;
@@ -115,21 +116,21 @@ public class Trade
{
final Map<Integer, ItemStack> leftOver = InventoryWorkaround.addItem(user.getInventory(), true, getItemStack());
final Location loc = user.getLocation();
for (ItemStack itemStack : leftOver.values())
for (ItemStack dropStack : leftOver.values())
{
final int maxStackSize = itemStack.getType().getMaxStackSize();
final int stacks = itemStack.getAmount() / maxStackSize;
final int leftover = itemStack.getAmount() % maxStackSize;
final int maxStackSize = dropStack.getType().getMaxStackSize();
final int stacks = dropStack.getAmount() / maxStackSize;
final int leftover = dropStack.getAmount() % maxStackSize;
final Item[] itemStacks = new Item[stacks + (leftover > 0 ? 1 : 0)];
for (int i = 0; i < stacks; i++)
{
final ItemStack stack = itemStack.clone();
final ItemStack stack = dropStack.clone();
stack.setAmount(maxStackSize);
itemStacks[i] = loc.getWorld().dropItem(loc, stack);
}
if (leftover > 0)
{
final ItemStack stack = itemStack.clone();
final ItemStack stack = dropStack.clone();
stack.setAmount(leftover);
itemStacks[stacks] = loc.getWorld().dropItem(loc, stack);
}

View File

@@ -1,4 +1,4 @@
package com.earth2me.essentials;
package com.earth2me.essentials.api;
public class ChargeException extends Exception

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.api;
import com.earth2me.essentials.listener.TNTExplodeListener;
import com.earth2me.essentials.listener.TntExplodeListener;
import com.earth2me.essentials.register.payment.Methods;
import org.bukkit.World;
import org.bukkit.entity.Player;
@@ -12,7 +12,7 @@ public interface IEssentials extends Plugin
void addReloadListener(IReload listener);
IUser getUser(Player player);
IUser getUser(String playerName);
int broadcastMessage(IUser sender, String message);
@@ -24,7 +24,7 @@ public interface IEssentials extends Plugin
IGroups getGroups();
IJails getJails();
IKits getKits();
IWarps getWarps();
@@ -36,7 +36,7 @@ public interface IEssentials extends Plugin
IUserMap getUserMap();
IBackup getBackup();
ICommandHandler getCommandHandler();
World getWorld(String name);
@@ -52,14 +52,13 @@ public interface IEssentials extends Plugin
int scheduleSyncRepeatingTask(Runnable run, long delay, long period);
//IPermissionsHandler getPermissionsHandler();
void reload();
TNTExplodeListener getTNTListener();
TntExplodeListener getTNTListener();
void setGroups(IGroups groups);
void removeReloadListener(IReload groups);
IEconomy getEconomy();
}

View File

@@ -1,5 +1,6 @@
package com.earth2me.essentials.api;
public interface IEssentialsModule
{
}

View File

@@ -6,8 +6,8 @@ import org.bukkit.inventory.ItemStack;
public interface IItemDb extends IReload
{
ItemStack get(final String name, final IUser user) throws Exception;
ItemStack get(final String name, final int quantity) throws Exception;
ItemStack get(final String name) throws Exception;
}

View File

@@ -6,13 +6,13 @@ import java.util.Collection;
public interface IKits extends IReload
{
Kit getKit(String kit)throws Exception;
Kit getKit(String kit) throws Exception;
void sendKit(IUser user, String kit) throws Exception;
void sendKit(IUser user, Kit kit) throws Exception;
Collection<String> getList() throws Exception;
boolean isEmpty();
}

View File

@@ -8,10 +8,10 @@ import org.bukkit.permissions.PermissionDefault;
public interface IPermission
{
String getPermission();
boolean isAuthorized(CommandSender sender);
Permission getBukkitPermission();
PermissionDefault getPermissionDefault();
}

View File

@@ -2,7 +2,9 @@ package com.earth2me.essentials.api;
import org.bukkit.command.CommandSender;
public interface IReplyTo {
public interface IReplyTo
{
void setReplyTo(CommandSender user);
CommandSender getReplyTo();

View File

@@ -9,7 +9,7 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
public interface ITeleport
{
void now(Location loc, boolean cooldown, TeleportCause cause) throws Exception;
void now(Entity entity, boolean cooldown, TeleportCause cause) throws Exception;
void back(Trade chargeFor) throws Exception;

View File

@@ -1,6 +1,5 @@
package com.earth2me.essentials.api;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.storage.IStorageObjectHolder;
import com.earth2me.essentials.user.CooldownException;
import com.earth2me.essentials.user.UserData;
@@ -24,9 +23,9 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload,
void giveMoney(double value);
void giveMoney(double value, CommandSender initiator);
void giveItems(ItemStack itemStack, Boolean canSpew) throws ChargeException;
void giveItems(List<ItemStack> itemStacks, Boolean canSpew) throws ChargeException;
void setMoney(double value);

View File

@@ -10,7 +10,7 @@ public interface IUserMap extends IReload
boolean userExists(final String name);
IUser getUser(final Player player);
IUser getUser(final String playerName);
void removeUser(final String name) throws InvalidNameException;

View File

@@ -6,5 +6,4 @@ import com.earth2me.essentials.storage.IStorageObjectHolder;
public interface IWarp extends IStorageObjectHolder<Warp>
{
}

View File

@@ -3,7 +3,6 @@ package com.earth2me.essentials.api;
public class InvalidNameException extends Exception
{
public InvalidNameException(Throwable thrwbl)
{
super(thrwbl);

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.Util;

View File

@@ -5,6 +5,7 @@ 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.register.payment.Methods;
import com.earth2me.essentials.settings.General;
import com.earth2me.essentials.settings.GroupsHolder;
import java.util.logging.Level;
@@ -32,11 +33,11 @@ public class EssentialsPluginListener implements Listener, IReload
checkGroups();
//ess.getPermissionsHandler().checkPermissions();
ess.getCommandHandler().addPlugin(event.getPlugin());
if (!ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().setMethod(ess.getServer().getPluginManager()))
if (!Methods.hasMethod() && Methods.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()
Methods.getMethod().getName(), Methods.getMethod().getVersion()
});
}
}
@@ -48,9 +49,9 @@ public class EssentialsPluginListener implements Listener, IReload
//ess.getPermissionsHandler().checkPermissions();
ess.getCommandHandler().removePlugin(event.getPlugin());
// 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 (Methods.hasMethod() && Methods.checkDisabled(event.getPlugin()))
{
ess.getPaymentMethod().reset();
Methods.reset();
ess.getLogger().log(Level.INFO, "Payment method was disabled. No longer accepting payments.");
}
}

View File

@@ -10,13 +10,13 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
public class TNTExplodeListener implements Listener, Runnable
public class TntExplodeListener implements Listener, Runnable
{
private final transient IEssentials ess;
private transient AtomicBoolean enabled = new AtomicBoolean(false);
private transient int timer = -1;
public TNTExplodeListener(final IEssentials ess)
public TntExplodeListener(final IEssentials ess)
{
super();
this.ess = ess;

View File

@@ -69,7 +69,7 @@ public abstract class AbstractDelayedYamlFileReader<T extends StorageObject> imp
catch (FileNotFoundException ex)
{
onException(ex);
Bukkit.getLogger().log(Level.INFO, "File not found: " + file.toString());
Bukkit.getLogger().log(Level.INFO, "File not found: {0}", file.toString());
}
catch (ObjectLoadException ex)
{

View File

@@ -210,7 +210,8 @@ public class BukkitConstructor extends Constructor
}
return new EnchantmentLevel(enchant, level);
}
if (node.getType().isEnum()) {
if (node.getType().isEnum())
{
final String val = (String)constructScalar((ScalarNode)node);
if (val.isEmpty())
{
@@ -218,7 +219,8 @@ public class BukkitConstructor extends Constructor
}
for (Object object : node.getType().getEnumConstants())
{
if (object.toString().equalsIgnoreCase(val)) {
if (object.toString().equalsIgnoreCase(val))
{
return object;
}
}
@@ -292,7 +294,8 @@ public class BukkitConstructor extends Constructor
final Field typeDefField = Constructor.class.getDeclaredField("typeDefinitions");
typeDefField.setAccessible(true);
typeDefinitions = (Map<Class<? extends Object>, TypeDescription>)typeDefField.get((Constructor)BukkitConstructor.this);
if (typeDefinitions == null) {
if (typeDefinitions == null)
{
throw new NullPointerException();
}
}

View File

@@ -70,9 +70,9 @@ public class EnchantmentLevel implements Entry<Enchantment, Integer>
if (entry.getKey() instanceof Enchantment
&& entry.getValue() instanceof Integer)
{
final Enchantment enchantment = (Enchantment)entry.getKey();
final Integer level = (Integer)entry.getValue();
return this.enchantment.equals(enchantment) && this.level == level.intValue();
final Enchantment objEnchantment = (Enchantment)entry.getKey();
final Integer objLevel = (Integer)entry.getValue();
return enchantment.equals(objEnchantment) && level == objLevel.intValue();
}
}
return false;

View File

@@ -1,4 +1,3 @@
package com.earth2me.essentials.storage;
import com.earth2me.essentials.api.IReload;
@@ -7,18 +6,17 @@ import java.io.File;
import java.util.Set;
interface IStorageObjectMap<I> extends IReload
{
boolean objectExists(final String name);
I getObject(final String name);
void removeObject(final String name) throws InvalidNameException;
Set<String> getAllKeys();
int getKeySize();
File getStorageFile(final String name) throws InvalidNameException;
}

View File

@@ -3,5 +3,5 @@ package com.earth2me.essentials.storage;
public interface IStorageReader
{
<T extends StorageObject> T load(final Class<? extends T> clazz) throws ObjectLoadException;
<T extends StorageObject> T load(final Class<? extends T> clazz) throws ObjectLoadException;
}

View File

@@ -38,7 +38,7 @@ public class Location
this.yaw = yaw;
this.pitch = pitch;
}
public Location(String worldname, double x, double y, double z)
{
this.worldname = worldname;
@@ -56,13 +56,16 @@ public class Location
if (loc == null)
{
World world = null;
if (worldUID != null) {
if (worldUID != null)
{
world = Bukkit.getWorld(worldUID);
}
if (world == null) {
if (world == null)
{
world = Bukkit.getWorld(worldname);
}
if (world == null) {
if (world == null)
{
throw new WorldNotLoadedException(worldname);
}
loc = new org.bukkit.Location(world, getX(), getY(), getZ(), getYaw(), getPitch());
@@ -100,12 +103,13 @@ public class Location
{
return pitch;
}
public static class WorldNotLoadedException extends Exception
{
public WorldNotLoadedException(String worldname)
{
super("World "+worldname+" is not loaded.");
super("World " + worldname + " is not loaded.");
}
}
}

View File

@@ -1,4 +1,4 @@
package com.earth2me.essentials;
package com.earth2me.essentials.storage;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials;

View File

@@ -45,7 +45,8 @@ public class YamlStorageReader implements IStorageReader
try
{
T object = (T)yaml.load(reader);
if (object == null) {
if (object == null)
{
object = clazz.newInstance();
}
return object;

View File

@@ -23,12 +23,12 @@ public class YamlStorageWriter implements IStorageWriter
private transient static final Pattern NON_WORD_PATTERN = Pattern.compile("\\W");
private transient final PrintWriter writer;
private transient static final Yaml YAML = new Yaml();
public YamlStorageWriter(final PrintWriter writer)
{
this.writer = writer;
}
@Override
public void save(final StorageObject object)
{
@@ -45,7 +45,7 @@ public class YamlStorageWriter implements IStorageWriter
Logger.getLogger(YamlStorageWriter.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void writeToFile(final Object object, final int depth, final Class clazz) throws IllegalAccessException
{
for (Field field : clazz.getDeclaredFields())
@@ -54,7 +54,7 @@ public class YamlStorageWriter implements IStorageWriter
if (Modifier.isPrivate(modifier) && !Modifier.isTransient(modifier) && !Modifier.isStatic(modifier))
{
field.setAccessible(true);
final Object data = field.get(object);
if (writeKey(field, depth, data))
{
@@ -85,7 +85,7 @@ public class YamlStorageWriter implements IStorageWriter
}
}
}
private boolean writeKey(final Field field, final int depth, final Object data)
{
final boolean commentPresent = writeComment(field, depth);
@@ -109,7 +109,7 @@ public class YamlStorageWriter implements IStorageWriter
}
return false;
}
private boolean writeComment(final Field field, final int depth)
{
final boolean commentPresent = field.isAnnotationPresent(Comment.class);
@@ -131,7 +131,7 @@ public class YamlStorageWriter implements IStorageWriter
}
return commentPresent;
}
private void writeCollection(final Collection<Object> data, final int depth) throws IllegalAccessException
{
writer.println();
@@ -162,7 +162,7 @@ public class YamlStorageWriter implements IStorageWriter
}
writer.println();
}
private void writeMap(final Map<Object, Object> data, final int depth) throws IllegalArgumentException, IllegalAccessException
{
writer.println();
@@ -199,7 +199,7 @@ public class YamlStorageWriter implements IStorageWriter
}
}
}
private void writeIndention(final int depth)
{
for (int i = 0; i < depth; i++)
@@ -207,7 +207,7 @@ public class YamlStorageWriter implements IStorageWriter
writer.print(" ");
}
}
private void writeScalar(final Object data)
{
if (data instanceof String || data instanceof Boolean || data instanceof Number)
@@ -247,7 +247,7 @@ public class YamlStorageWriter implements IStorageWriter
throw new UnsupportedOperationException();
}
}
private void writeKey(final Object data)
{
if (data instanceof String || data instanceof Boolean || data instanceof Number)
@@ -285,12 +285,12 @@ public class YamlStorageWriter implements IStorageWriter
throw new UnsupportedOperationException();
}
}
private void writeMaterial(final Object data)
{
writer.print(data.toString().toLowerCase(Locale.ENGLISH));
}
private void writeMaterialData(final Object data)
{
final MaterialData matData = (MaterialData)data;
@@ -301,7 +301,7 @@ public class YamlStorageWriter implements IStorageWriter
writer.print(matData.getData());
}
}
private void writeItemStack(final Object data)
{
final ItemStack itemStack = (ItemStack)data;
@@ -314,7 +314,7 @@ public class YamlStorageWriter implements IStorageWriter
writeEnchantmentLevel(entry);
}
}
private void writeEnchantmentLevel(Object data)
{
final Entry<Enchantment, Integer> enchLevel = (Entry<Enchantment, Integer>)data;
@@ -322,7 +322,7 @@ public class YamlStorageWriter implements IStorageWriter
writer.print(':');
writer.print(enchLevel.getValue());
}
private void writeLocation(final Location entry, final int depth)
{
writer.println();

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.user;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import com.earth2me.essentials.Console;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Teleport;

View File

@@ -1,5 +1,6 @@
package com.earth2me.essentials;
import com.earth2me.essentials.storage.ManagedFile;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.settings.Spawns;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.chat;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.Util;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.Util;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import com.earth2me.essentials.Enchantments;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.IEssentials;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.IEssentials;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.Util;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.IEssentials;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.Util;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.api.ChargeException;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.api.IEssentials;