1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-07 23:27:08 +02:00

Merge branch 'refs/heads/master' into release

This commit is contained in:
snowleo
2011-11-29 21:55:09 +01:00
18 changed files with 151 additions and 111 deletions

View File

@@ -1,7 +1,6 @@
package com.earth2me.essentials;
import java.util.*;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.PluginCommandYamlParser;
@@ -11,19 +10,21 @@ import org.bukkit.plugin.Plugin;
public class AlternativeCommandsHandler
{
private final transient Map<String, List<PluginCommand>> altcommands = new HashMap<String, List<PluginCommand>>();
private final transient Map<String, String> executed = new HashMap<String, String>();
private final transient IEssentials ess;
public AlternativeCommandsHandler(final IEssentials ess)
{
this.ess = ess;
for (Plugin plugin : ess.getServer().getPluginManager().getPlugins())
{
if (plugin.isEnabled()) {
if (plugin.isEnabled())
{
addPlugin(plugin);
}
}
}
public final void addPlugin(final Plugin plugin)
{
if (plugin.getDescription().getMain().contains("com.earth2me.essentials"))
@@ -106,12 +107,24 @@ public class AlternativeCommandsHandler
return commands.get(0);
}
// return the first command that is not an alias
for (PluginCommand command : commands) {
if (command.getName().equalsIgnoreCase(label)) {
for (PluginCommand command : commands)
{
if (command.getName().equalsIgnoreCase(label))
{
return command;
}
}
// return the first alias
return commands.get(0);
}
public void executed(final String label, final String otherlabel)
{
executed.put(label, otherlabel);
}
public Map<String, String> disabledCommands()
{
return executed;
}
}

View File

@@ -273,7 +273,8 @@ public class Essentials extends JavaPlugin implements IEssentials
final PluginCommand pc = alternativeCommandsHandler.getAlternative(commandLabel);
if (pc != null)
{
LOGGER.info("Essentials: Alternative command " + commandLabel + " found, using " + pc.getLabel());
alternativeCommandsHandler.executed(commandLabel, pc.getLabel());
LOGGER.log(Level.FINE,"Essentials: Alternative command " + commandLabel + " found, using " + pc.getLabel());
return pc.execute(sender, commandLabel, args);
}
}
@@ -345,7 +346,8 @@ public class Essentials extends JavaPlugin implements IEssentials
{
sender.sendMessage(command.getDescription());
sender.sendMessage(command.getUsage().replaceAll("<command>", commandLabel));
if (!ex.getMessage().isEmpty()) {
if (!ex.getMessage().isEmpty())
{
sender.sendMessage(ex.getMessage());
}
return true;
@@ -420,14 +422,7 @@ public class Essentials extends JavaPlugin implements IEssentials
}
if (base instanceof String)
{
try
{
return userMap.getUser((String)base);
}
catch (NullPointerException ex)
{
return null;
}
return userMap.getUser((String)base);
}
return null;
}
@@ -443,27 +438,21 @@ public class Essentials extends JavaPlugin implements IEssentials
{
return (User)base;
}
try
User user = userMap.getUser(base.getName());
if (user == null)
{
return userMap.getUser(base.getName()).update(base);
}
catch (NullPointerException ex)
{
return new User(base, this);
user = new User(base, this);
} else {
user.update(base);
}
return user;
}
@Override
public User getOfflineUser(final String name)
{
try
{
return userMap.getUser(name);
}
catch (NullPointerException ex)
{
return null;
}
return userMap.getUser(name);
}
@Override

View File

@@ -232,21 +232,25 @@ public class EssentialsConf extends Configuration
Material.valueOf(getString(path + ".type", "AIR")),
getInt(path + ".amount", 1),
(short)getInt(path + ".damage", 0));
List<String> enchants = getKeys(path + ".enchant");
for (String enchant : enchants)
final List<String> enchants = getKeys(path + ".enchant");
if (enchants != null)
{
Enchantment enchantment = Enchantment.getByName(enchant.toUpperCase(Locale.ENGLISH));
if (enchantment == null) {
continue;
for (String enchant : enchants)
{
final Enchantment enchantment = Enchantment.getByName(enchant.toUpperCase(Locale.ENGLISH));
if (enchantment == null)
{
continue;
}
final int level = getInt(path + ".enchant." + enchant, enchantment.getStartLevel());
stack.addUnsafeEnchantment(enchantment, level);
}
int level = getInt(path+ ".enchant."+enchant, enchantment.getStartLevel());
stack.addUnsafeEnchantment(enchantment, level);
}
return stack;
/*
* ,
* (byte)getInt(path + ".data", 0)
*/
* ,
* (byte)getInt(path + ".data", 0)
*/
}
public void setProperty(final String path, final ItemStack stack)

View File

@@ -120,33 +120,6 @@ public class EssentialsPlayerListener extends PlayerListener
}
user.updateActivity(false);
user.dispose();
if (!ess.getSettings().getReclaimSetting())
{
return;
}
final Thread thread = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
Thread.sleep(1000);
Runtime rt = Runtime.getRuntime();
double mem = rt.freeMemory();
rt.runFinalization();
rt.gc();
mem = rt.freeMemory() - mem;
mem /= 1024 * 1024;
LOGGER.log(Level.INFO, _("freedMemory", mem));
}
catch (InterruptedException ex)
{
}
}
});
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
@Override

View File

@@ -69,6 +69,9 @@ public class I18n
public static String _(final String string, final Object... objects)
{
if (instance == null) {
return "";
}
if (objects.length == 0)
{
return instance.translate(string);

View File

@@ -59,8 +59,6 @@ public interface ISettings extends IConf
String getProtectString(final String configName);
boolean getReclaimSetting();
boolean getRespawnAtHome();
List getMultipleHomes();

View File

@@ -76,8 +76,7 @@ public enum Mob
public LivingEntity spawn(final Player player, final Server server, final Location loc) throws MobException
{
final LivingEntity entity = player.getWorld().spawnCreature(loc, this.bukkitType);
final LivingEntity entity = player.getWorld().spawn(loc, (Class<? extends LivingEntity>)this.bukkitType.getEntityClass());
if (entity == null)
{
logger.log(Level.WARNING, _("unableToSpawnMob"));

View File

@@ -243,12 +243,6 @@ public class Settings implements ISettings
return ChatColor.getByCode(Integer.parseInt(colorName, 16));
}
@Override
public boolean getReclaimSetting()
{
return config.getBoolean("reclaim-onlogout", false);
}
@Override
public int getSpawnMobLimit()
{

View File

@@ -4,11 +4,14 @@ import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.ConcurrentHashMultiset;
import com.google.common.util.concurrent.UncheckedExecutionException;
import java.io.File;
import java.util.Collections;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.entity.Player;
@@ -57,7 +60,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
return keys.contains(name.toLowerCase(Locale.ENGLISH));
}
public User getUser(final String name) throws NullPointerException
public User getUser(final String name)
{
try
{
@@ -65,7 +68,11 @@ public class UserMap extends CacheLoader<String, User> implements IConf
}
catch (ExecutionException ex)
{
throw new NullPointerException();
return null;
}
catch (UncheckedExecutionException ex)
{
return null;
}
}

View File

@@ -376,9 +376,9 @@ public class Util
buf.append(seperator);
}
if (each instanceof List)
if (each instanceof Collection)
{
buf.append(joinList(seperator, ((List)each).toArray()));
buf.append(joinList(seperator, ((Collection)each).toArray()));
}
else
{

View File

@@ -1,5 +1,6 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util;
import java.util.*;
@@ -15,7 +16,6 @@ public class Commandbalancetop extends EssentialsCommand
{
super("balancetop");
}
private static final int CACHETIME = 5 * 60 * 1000;
public static final int MINUSERS = 50;
private static List<String> cache = new ArrayList<String>();
@@ -107,12 +107,10 @@ public class Commandbalancetop extends EssentialsCommand
final Map<String, Double> balances = new HashMap<String, Double>();
for (String u : ess.getUserMap().getAllUniqueUsers())
{
try
{
balances.put(u, ess.getUserMap().getUser(u).getMoney());
}
catch (NullPointerException ex)
final User user = ess.getUserMap().getUser(u);
if (user != null)
{
balances.put(u, user.getMoney());
}
}

View File

@@ -67,6 +67,8 @@ public class Commandenchant extends EssentialsCommand
super("enchant");
}
//TODO: Implement charge costs: final Trade charge = new Trade("enchant-" + enchantmentName, ess);
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{

View File

@@ -1,6 +1,7 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Location;
@@ -23,12 +24,52 @@ public class Commandessentials extends EssentialsCommand
@Override
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length > 0 && args[0].equalsIgnoreCase("debug"))
{
ess.getSettings().setDebug(!ess.getSettings().isDebug());
sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled"));
return;
if (args.length == 0) {
run_disabled(server, sender, commandLabel, args);
}
else if (args[0].equalsIgnoreCase("debug"))
{
run_debug(server, sender, commandLabel, args);
}
else if (args[0].equalsIgnoreCase("nya"))
{
run_nya(server, sender, commandLabel, args);
}
else {
run_reload(server, sender, commandLabel, args);
}
}
private void run_disabled(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
sender.sendMessage("Essentials " + ess.getDescription().getVersion());
sender.sendMessage("/<command> <reload/debug>");
sender.sendMessage("Essentials blocked the following commands, due to command conflicts:");
final StringBuilder disabledCommands = new StringBuilder();
for (Map.Entry<String, String> entry : ess.getAlternativeCommandsHandler().disabledCommands().entrySet())
{
if (disabledCommands.length() > 0) {
disabledCommands.append(", ");
}
disabledCommands.append(entry.getKey()).append(" => ").append(entry.getValue());
}
sender.sendMessage(disabledCommands.toString());
}
private void run_debug(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
ess.getSettings().setDebug(!ess.getSettings().isDebug());
sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled"));
}
private void run_reload(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
ess.reload();
sender.sendMessage(_("essentialsReload", ess.getDescription().getVersion()));
}
private void run_nya(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
final Map<String, Byte> noteMap = new HashMap<String, Byte>();
noteMap.put("1F#", (byte)0x0);
noteMap.put("1G", (byte)0x1);
@@ -54,8 +95,6 @@ public class Commandessentials extends EssentialsCommand
noteMap.put("2D#", (byte)(0x9 + 0xC));
noteMap.put("2E", (byte)(0xA + 0xC));
noteMap.put("2F", (byte)(0xB + 0xC));
if (args.length > 0 && args[0].equalsIgnoreCase("nya"))
{
if (!noteBlocks.isEmpty())
{
return;
@@ -106,9 +145,6 @@ public class Commandessentials extends EssentialsCommand
}
}, 20, 2);
return;
}
ess.reload();
sender.sendMessage(_("essentialsReload", ess.getDescription().getVersion()));
}
private void stopTune()

View File

@@ -21,6 +21,10 @@ public class GroupManagerHandler implements IPermissionsHandler
public String getGroup(final Player base)
{
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base);
if (handler == null)
{
return null;
}
return handler.getGroup(base.getName());
}
@@ -28,6 +32,10 @@ public class GroupManagerHandler implements IPermissionsHandler
public List<String> getGroups(final Player base)
{
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base);
if (handler == null)
{
return null;
}
return Arrays.asList(handler.getGroups(base.getName()));
}
@@ -35,6 +43,10 @@ public class GroupManagerHandler implements IPermissionsHandler
public boolean canBuild(final Player base, final String group)
{
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base);
if (handler == null)
{
return false;
}
return handler.canUserBuild(base.getName());
}
@@ -42,6 +54,10 @@ public class GroupManagerHandler implements IPermissionsHandler
public boolean inGroup(final Player base, final String group)
{
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base);
if (handler == null)
{
return false;
}
return handler.inGroup(base.getName(), group);
}
@@ -49,6 +65,10 @@ public class GroupManagerHandler implements IPermissionsHandler
public boolean hasPermission(final Player base, final String node)
{
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base);
if (handler == null)
{
return false;
}
return handler.has(base, node);
}
@@ -56,6 +76,10 @@ public class GroupManagerHandler implements IPermissionsHandler
public String getPrefix(final Player base)
{
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base);
if (handler == null)
{
return null;
}
return handler.getUserPrefix(base.getName());
}
@@ -63,6 +87,10 @@ public class GroupManagerHandler implements IPermissionsHandler
public String getSuffix(final Player base)
{
AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(base);
if (handler == null)
{
return null;
}
return handler.getUserSuffix(base.getName());
}
}

View File

@@ -68,11 +68,6 @@ item-spawn-blacklist:
# - essentials.give.item-[itemid]
permission-based-item-spawn: false
# Whether or not to reclaim memory on player logout; this is technical, and should only be changed under special circumstances.
# This generally increases server stability unless very specific runtime configurations are used.
# HOWEVER, it is known to cause lag upon users logging OUT, so beware!
reclaim-onlogout: false
# Mob limit on spawnmob
spawnmob-limit: 10

View File

@@ -31,6 +31,7 @@ settings:
# user/groups permissions as the parent.
world:
- world_nether
- world_the_end
- world2
- world3
# world4:

View File

@@ -294,7 +294,7 @@ public class GlobalGroups {
*/
public boolean hasPermission(String groupName, String permissionNode) {
if (!hasGroup(groupName.toLowerCase()))
if (!hasGroup(groupName))
return false;
return groups.get(groupName.toLowerCase()).hasSamePermissionNode(permissionNode);
@@ -315,7 +315,7 @@ public class GlobalGroups {
result.askedPermission = permissionNode;
result.resultType = PermissionCheckResult.Type.NOTFOUND;
if (!hasGroup(groupName.toLowerCase()))
if (!hasGroup(groupName))
return result;
Group tempGroup = groups.get(groupName.toLowerCase());
@@ -337,7 +337,7 @@ public class GlobalGroups {
* @return List of all group names
*/
public List<String> getGroupsPermissions(String groupName) {
if (!hasGroup(groupName.toLowerCase()))
if (!hasGroup(groupName))
return null;
return groups.get(groupName.toLowerCase()).getPermissionList();
@@ -374,7 +374,7 @@ public class GlobalGroups {
* @return Group object
*/
public Group getGroup(String groupName) {
if (!hasGroup(groupName.toLowerCase()))
if (!hasGroup(groupName))
return null;
return groups.get(groupName.toLowerCase());

View File

@@ -195,7 +195,7 @@ public class WorldDataHolder {
* @return a group if it is found. null if not found.
*/
public Group getGroup(String groupName) {
if (groupName.startsWith("g:"))
if (groupName.toLowerCase().startsWith("g:"))
return GroupManager.getGlobalGroups().getGroup(groupName);
else
return groups.get(groupName.toLowerCase());
@@ -208,7 +208,7 @@ public class WorldDataHolder {
* @return true if exists. false if not.
*/
public boolean groupExists(String groupName) {
if (groupName.startsWith("g:"))
if (groupName.toLowerCase().startsWith("g:"))
return GroupManager.getGlobalGroups().hasGroup(groupName);
else
return groups.containsKey(groupName.toLowerCase());
@@ -219,7 +219,7 @@ public class WorldDataHolder {
* @param groupToAdd
*/
public void addGroup(Group groupToAdd) {
if (groupToAdd.getName().startsWith("g:")) {
if (groupToAdd.getName().toLowerCase().startsWith("g:")) {
GroupManager.getGlobalGroups().addGroup(groupToAdd);
return;
}
@@ -238,7 +238,7 @@ public class WorldDataHolder {
* @return true if had something to remove. false the group was default or non-existant
*/
public boolean removeGroup(String groupName) {
if (groupName.startsWith("g:")) {
if (groupName.toLowerCase().startsWith("g:")) {
return GroupManager.getGlobalGroups().removeGroup(groupName);
}
@@ -278,7 +278,7 @@ public class WorldDataHolder {
* @return null if group already exists. or new Group
*/
public Group createGroup(String groupName) {
if (groupName.startsWith("g:")) {
if (groupName.toLowerCase().startsWith("g:")) {
Group newGroup = new Group(groupName);
return GroupManager.getGlobalGroups().newGroup(newGroup);
}