merge went odd

This commit is contained in:
ementalo 2011-07-09 12:52:46 +01:00
parent 7ec1ca651f
commit b9b5db8ccd

View File

@ -27,9 +27,13 @@ import org.bukkit.command.CommandSender;
import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.commands.IEssentialsCommand;
import com.earth2me.essentials.commands.NotEnoughArgumentsException; import com.earth2me.essentials.commands.NotEnoughArgumentsException;
import com.earth2me.essentials.register.payment.Methods; 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 java.math.BigInteger; import java.math.BigInteger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.bukkit.command.PluginCommand;
import org.bukkit.craftbukkit.scheduler.CraftScheduler; import org.bukkit.craftbukkit.scheduler.CraftScheduler;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
@ -45,10 +49,8 @@ public class Essentials extends JavaPlugin implements IEssentials
public static final int minBukkitBuildVersion = 974; public static final int minBukkitBuildVersion = 974;
private static final Logger logger = Logger.getLogger("Minecraft"); private static final Logger logger = Logger.getLogger("Minecraft");
private Settings settings; private Settings settings;
private EssentialsPlayerListener playerListener; private TNTExplodeListener tntListener;
private EssentialsBlockListener blockListener; private EssentialsDependancyChecker essDep;
private EssentialsEntityListener entityListener;
private JailPlayerListener jailPlayerListener;
private static Essentials instance = null; private static Essentials instance = null;
private Spawn spawn; private Spawn spawn;
private Jail jail; private Jail jail;
@ -59,12 +61,12 @@ public class Essentials extends JavaPlugin implements IEssentials
public ArrayList bannedIps = new ArrayList(); public ArrayList bannedIps = new ArrayList();
private Backup backup; private Backup backup;
private final Map<String, User> users = new HashMap<String, User>(); private final Map<String, User> users = new HashMap<String, User>();
private EssentialsTimer timer;
private EssentialsUpdateTimer updateTimer; private EssentialsUpdateTimer updateTimer;
private boolean registerFallback = true; private boolean registerFallback = true;
private final Methods paymentMethod = new Methods(); private final Methods paymentMethod = new Methods();
private final static boolean enableErrorLogging = false; private final static boolean enableErrorLogging = false;
private final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler(); private final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
private IPermissionsHandler permissionsHandler;
public static IEssentials getStatic() public static IEssentials getStatic()
{ {
@ -85,6 +87,7 @@ public class Essentials extends JavaPlugin implements IEssentials
logger.log(Level.INFO, dataFolder.toString()); logger.log(Level.INFO, dataFolder.toString());
this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null); this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null);
settings = new Settings(dataFolder); settings = new Settings(dataFolder);
permissionsHandler = new ConfigPermissionsHandler(this);
setStatic(); setStatic();
} }
@ -95,9 +98,10 @@ public class Essentials extends JavaPlugin implements IEssentials
public void onEnable() public void onEnable()
{ {
if (!Thread.currentThread().getStackTrace()[5].getMethodName().equals("loadPlugin")) { final String[] javaversion = System.getProperty("java.version").split("\\.", 3);
logger.log(Level.SEVERE, "Another plugin is trying to enable Essentials manually. Don't do this! It's probably " if (javaversion == null || javaversion.length < 2 || Integer.parseInt(javaversion[1]) < 6)
+ Thread.currentThread().getStackTrace()[5].getClassName()); {
logger.log(Level.SEVERE, "Java version not supported! Please install Java 1.6. You have " + System.getProperty("java.version"));
} }
if (enableErrorLogging) if (enableErrorLogging)
{ {
@ -119,8 +123,9 @@ public class Essentials extends JavaPlugin implements IEssentials
confList.add(worth); confList.add(worth);
reload(); reload();
backup = new Backup(this); backup = new Backup(this);
essDep = new EssentialsDependancyChecker(this);
PluginManager pm = getServer().getPluginManager(); final PluginManager pm = getServer().getPluginManager();
for (Plugin plugin : pm.getPlugins()) for (Plugin plugin : pm.getPlugins())
{ {
if (plugin.getDescription().getName().startsWith("Essentials")) if (plugin.getDescription().getName().startsWith("Essentials"))
@ -145,15 +150,33 @@ public class Essentials extends JavaPlugin implements IEssentials
logger.log(Level.INFO, Util.i18n("bukkitFormatChanged")); logger.log(Level.INFO, Util.i18n("bukkitFormatChanged"));
} }
Plugin permissionsPlugin = pm.getPlugin("Permissions");
ServerListener serverListener = new EssentialsPluginListener(paymentMethod); if (permissionsPlugin != null)
{
if (permissionsPlugin.getDescription().getVersion().charAt(0) == '3')
{
this.permissionsHandler = new Permissions3Handler(permissionsPlugin);
}
else
{
this.permissionsHandler = new Permissions2Handler(permissionsPlugin);
}
}
else
{
this.permissionsHandler = new ConfigPermissionsHandler(this);
}
final ServerListener serverListener = new EssentialsPluginListener(paymentMethod);
pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Low, this); pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Low, this);
pm.registerEvent(Type.PLUGIN_DISABLE, serverListener, Priority.Low, this); pm.registerEvent(Type.PLUGIN_DISABLE, serverListener, Priority.Low, this);
playerListener = new EssentialsPlayerListener(this); final EssentialsPlayerListener playerListener = new EssentialsPlayerListener(this);
pm.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, this); pm.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, this);
pm.registerEvent(Type.PLAYER_QUIT, playerListener, Priority.Monitor, this); pm.registerEvent(Type.PLAYER_QUIT, playerListener, Priority.Monitor, this);
pm.registerEvent(Type.PLAYER_CHAT, playerListener, Priority.Lowest, this); pm.registerEvent(Type.PLAYER_CHAT, playerListener, Priority.Lowest, this);
pm.registerEvent(Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Lowest, this);
if (getSettings().getNetherPortalsEnabled()) if (getSettings().getNetherPortalsEnabled())
{ {
pm.registerEvent(Type.PLAYER_MOVE, playerListener, Priority.High, this); pm.registerEvent(Type.PLAYER_MOVE, playerListener, Priority.High, this);
@ -165,32 +188,47 @@ public class Essentials extends JavaPlugin implements IEssentials
pm.registerEvent(Type.PLAYER_BUCKET_EMPTY, playerListener, Priority.High, this); pm.registerEvent(Type.PLAYER_BUCKET_EMPTY, playerListener, Priority.High, this);
pm.registerEvent(Type.PLAYER_ANIMATION, playerListener, Priority.High, this); pm.registerEvent(Type.PLAYER_ANIMATION, playerListener, Priority.High, this);
blockListener = new EssentialsBlockListener(this); final EssentialsBlockListener blockListener = new EssentialsBlockListener(this);
pm.registerEvent(Type.SIGN_CHANGE, blockListener, Priority.Low, this); //pm.registerEvent(Type.SIGN_CHANGE, blockListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Lowest, this); //pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Lowest, this);
pm.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Lowest, this); pm.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Lowest, this);
final SignBlockListener signBlockListener = new SignBlockListener(this);
pm.registerEvent(Type.SIGN_CHANGE, signBlockListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_PLACE, signBlockListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_BREAK, signBlockListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_IGNITE, signBlockListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_BURN, signBlockListener, Priority.Low, this);
final SignPlayerListener signPlayerListener = new SignPlayerListener(this);
pm.registerEvent(Type.PLAYER_INTERACT, signPlayerListener, Priority.Low, this);
final SignEntityListener signEntityListener = new SignEntityListener(this);
pm.registerEvent(Type.ENTITY_EXPLODE, signEntityListener, Priority.Low, this);
entityListener = new EssentialsEntityListener(this); final EssentialsEntityListener entityListener = new EssentialsEntityListener(this);
pm.registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Lowest, this); pm.registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Lowest, this);
pm.registerEvent(Type.ENTITY_COMBUST, entityListener, Priority.Lowest, this); pm.registerEvent(Type.ENTITY_COMBUST, entityListener, Priority.Lowest, this);
pm.registerEvent(Type.ENTITY_DEATH, entityListener, Priority.Lowest, this); pm.registerEvent(Type.ENTITY_DEATH, entityListener, Priority.Lowest, this);
jail = new Jail(this); jail = new Jail(this);
jailPlayerListener = new JailPlayerListener(this); final JailPlayerListener jailPlayerListener = new JailPlayerListener(this);
confList.add(jail); confList.add(jail);
pm.registerEvent(Type.BLOCK_BREAK, jail, Priority.High, this); pm.registerEvent(Type.BLOCK_BREAK, jail, Priority.High, this);
pm.registerEvent(Type.BLOCK_DAMAGE, jail, Priority.High, this); pm.registerEvent(Type.BLOCK_DAMAGE, jail, Priority.High, this);
pm.registerEvent(Type.BLOCK_PLACE, jail, Priority.High, this); pm.registerEvent(Type.BLOCK_PLACE, jail, Priority.High, this);
pm.registerEvent(Type.PLAYER_INTERACT, jailPlayerListener, Priority.High, this); pm.registerEvent(Type.PLAYER_INTERACT, jailPlayerListener, Priority.High, this);
attachEcoListeners(); //attachEcoListeners();
if (settings.isNetherEnabled() && getServer().getWorlds().size() < 2) if (settings.isNetherEnabled() && getServer().getWorlds().size() < 2)
{ {
logger.log(Level.WARNING, "Old nether is disabled until multiworld support in bukkit is fixed.");
getServer().createWorld(settings.getNetherName(), World.Environment.NETHER); getServer().createWorld(settings.getNetherName(), World.Environment.NETHER);
} }
timer = new EssentialsTimer(this); tntListener = new TNTExplodeListener(this);
pm.registerEvent(Type.ENTITY_EXPLODE, tntListener, Priority.High, this);
final EssentialsTimer timer = new EssentialsTimer(this);
getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 50); getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 50);
if (enableErrorLogging) if (enableErrorLogging)
{ {
@ -203,11 +241,13 @@ public class Essentials extends JavaPlugin implements IEssentials
public void onDisable() public void onDisable()
{ {
instance = null; instance = null;
Trade.closeLog();
logger.removeHandler(errorHandler); logger.removeHandler(errorHandler);
} }
public void reload() public void reload()
{ {
Trade.closeLog();
loadBanList(); loadBanList();
for (IConf iConf : confList) for (IConf iConf : confList)
@ -249,7 +289,7 @@ public class Essentials extends JavaPlugin implements IEssentials
} }
String[] retval = new String[lines.size()]; String[] retval = new String[lines.size()];
if (lines == null || lines.isEmpty() || lines.get(0) == null) if (lines.isEmpty() || lines.get(0) == null)
{ {
try try
{ {
@ -331,39 +371,14 @@ public class Essentials extends JavaPlugin implements IEssentials
return retval; return retval;
} }
@SuppressWarnings("LoggerStringConcat")
public static void previewCommand(CommandSender sender, Command command, String commandLabel, String[] args)
{
if (sender instanceof Player)
{
logger.info(ChatColor.BLUE + "[PLAYER_COMMAND] " + ((Player)sender).getName() + ": /" + commandLabel + " " + EssentialsCommand.getFinalArg(args, 0));
}
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
{ {
return onCommandEssentials(sender, command, commandLabel, args, Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command"); return onCommandEssentials(sender, command, commandLabel, args, Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command", "essentials.");
} }
public boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath) public boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath, String permissionPrefix)
{ {
if (("msg".equals(commandLabel.toLowerCase()) || "r".equals(commandLabel.toLowerCase()) || "mail".equals(commandLabel.toLowerCase())) && sender instanceof Player)
{
StringBuilder str = new StringBuilder();
str.append(commandLabel).append(" ");
for (String a : args)
{
str.append(a).append(" ");
}
for (Player player : getServer().getOnlinePlayers())
{
if (getUser(player).isSocialSpyEnabled())
{
player.sendMessage(getUser(sender).getDisplayName() + " : " + str);
}
}
}
// Allow plugins to override the command via onCommand // Allow plugins to override the command via onCommand
if (!getSettings().isCommandOverridden(command.getName()) && !commandLabel.startsWith("e")) if (!getSettings().isCommandOverridden(command.getName()) && !commandLabel.startsWith("e"))
{ {
@ -385,24 +400,22 @@ public class Essentials extends JavaPlugin implements IEssentials
continue; continue;
} }
if (!(desc.getCommands() instanceof Map)) PluginCommand pc = getServer().getPluginCommand(desc.getName() + ":" + commandLabel);
if (pc != null)
{ {
continue; return pc.execute(sender, commandLabel, args);
} }
Map<String, Object> cmds = (Map<String, Object>)desc.getCommands();
if (!cmds.containsKey(command.getName()))
{
continue;
}
return p.onCommand(sender, command, commandLabel, args);
} }
} }
try try
{ {
previewCommand(sender, command, commandLabel, args); User user = null;
User user = sender instanceof Player ? getUser(sender) : null; if (sender instanceof Player)
{
user = getUser(sender);
logger.log(Level.INFO, String.format("[PLAYER_COMMAND] %s: /%s %s ", ((Player)sender).getName(), commandLabel , EssentialsCommand.getFinalArg(args, 0)));
}
// New mail notification // New mail notification
if (user != null && !getSettings().isCommandDisabled("mail") && !commandLabel.equals("mail") && user.isAuthorized("essentials.mail")) if (user != null && !getSettings().isCommandDisabled("mail") && !commandLabel.equals("mail") && user.isAuthorized("essentials.mail"))
@ -434,7 +447,7 @@ public class Essentials extends JavaPlugin implements IEssentials
} }
// Check authorization // Check authorization
if (user != null && !user.isAuthorized(cmd)) if (user != null && !user.isAuthorized(cmd, permissionPrefix))
{ {
logger.log(Level.WARNING, Util.format("deniedAccessCommand", user.getName())); logger.log(Level.WARNING, Util.format("deniedAccessCommand", user.getName()));
user.sendMessage(Util.i18n("noAccessCommand")); user.sendMessage(Util.i18n("noAccessCommand"));
@ -462,21 +475,7 @@ public class Essentials extends JavaPlugin implements IEssentials
} }
catch (Throwable ex) catch (Throwable ex)
{ {
sender.sendMessage(Util.format("errorWithMessage", ex.getMessage())); showError(sender, ex, commandLabel);
LogRecord lr = new LogRecord(Level.WARNING, Util.format("errorCallingCommand", commandLabel));
lr.setThrown(ex);
if (getSettings().isDebug())
{
logger.log(lr);
}
else
{
if (enableErrorLogging)
{
errorHandler.publish(lr);
errorHandler.flush();
}
}
return true; return true;
} }
} }
@ -487,6 +486,25 @@ public class Essentials extends JavaPlugin implements IEssentials
} }
} }
public void showError(final CommandSender sender, final Throwable exception, final String commandLabel)
{
sender.sendMessage(Util.format("errorWithMessage", exception.getMessage()));
final LogRecord logRecord = new LogRecord(Level.WARNING, Util.format("errorCallingCommand", commandLabel));
logRecord.setThrown(exception);
if (getSettings().isDebug())
{
logger.log(logRecord);
}
else
{
if (enableErrorLogging)
{
errorHandler.publish(logRecord);
errorHandler.flush();
}
}
}
public void loadBanList() public void loadBanList()
{ {
//I don't like this but it needs to be done until CB fixors //I don't like this but it needs to be done until CB fixors
@ -583,12 +601,12 @@ public class Essentials extends JavaPlugin implements IEssentials
private void attachEcoListeners() private void attachEcoListeners()
{ {
PluginManager pm = getServer().getPluginManager(); //PluginManager pm = getServer().getPluginManager();
EssentialsEcoBlockListener ecoBlockListener = new EssentialsEcoBlockListener(this); //EssentialsEcoBlockListener ecoBlockListener = new EssentialsEcoBlockListener(this);
EssentialsEcoPlayerListener ecoPlayerListener = new EssentialsEcoPlayerListener(this); //EssentialsEcoPlayerListener ecoPlayerListener = new EssentialsEcoPlayerListener(this);
pm.registerEvent(Type.PLAYER_INTERACT, ecoPlayerListener, Priority.High, this); //pm.registerEvent(Type.PLAYER_INTERACT, ecoPlayerListener, Priority.High, this);
pm.registerEvent(Type.BLOCK_BREAK, ecoBlockListener, Priority.High, this); //pm.registerEvent(Type.BLOCK_BREAK, ecoBlockListener, Priority.High, this);
pm.registerEvent(Type.SIGN_CHANGE, ecoBlockListener, Priority.Monitor, this); //pm.registerEvent(Type.SIGN_CHANGE, ecoBlockListener, Priority.Monitor, this);
} }
public CraftScheduler getScheduler() public CraftScheduler getScheduler()
@ -733,6 +751,11 @@ public class Essentials extends JavaPlugin implements IEssentials
return this.getScheduler().scheduleSyncDelayedTask(this, run); return this.getScheduler().scheduleSyncDelayedTask(this, run);
} }
public int scheduleSyncDelayedTask(final Runnable run, final long delay)
{
return this.getScheduler().scheduleSyncDelayedTask(this, run, delay);
}
public int scheduleSyncRepeatingTask(final Runnable run, long delay, long period) public int scheduleSyncRepeatingTask(final Runnable run, long delay, long period)
{ {
return this.getScheduler().scheduleSyncRepeatingTask(this, run, delay, period); return this.getScheduler().scheduleSyncRepeatingTask(this, run, delay, period);
@ -747,4 +770,19 @@ public class Essentials extends JavaPlugin implements IEssentials
{ {
return bannedIps; return bannedIps;
} }
public TNTExplodeListener getTNTListener()
{
return tntListener;
}
public EssentialsDependancyChecker getDependancyChecker()
{
return essDep;
}
public IPermissionsHandler getPermissionsHandler()
{
return permissionsHandler;
}
} }