From 319a3e4deff05d04a544109dbd8755d43dc7abad Mon Sep 17 00:00:00 2001 From: snowleo Date: Sat, 3 Nov 2012 12:44:38 +0100 Subject: Ess2Compat: Settings part 1 --- Essentials/src/net/ess3/commands/Commandspeed.java | 16 +- Essentials/src/net/ess3/commands/Commandtpa.java | 2 +- .../src/net/ess3/commands/Commandtpaall.java | 2 +- .../src/net/ess3/commands/Commandtpaccept.java | 2 +- .../src/net/ess3/commands/Commandtpahere.java | 2 +- .../ess3/listener/EssentialsPlayerListener.java | 4 +- Essentials/src/net/ess3/settings/Commands.java | 4 +- Essentials/src/net/ess3/settings/General.java | 12 +- .../src/net/ess3/settings/commands/Speed.java | 8 +- .../src/net/ess3/settings/commands/Teleport.java | 32 + Essentials/src/net/ess3/settings/commands/Tpa.java | 21 - Essentials/src/net/ess3/user/User.java | 2 +- .../src/com/earth2me/essentials/Essentials.java | 39 +- .../src/com/earth2me/essentials/ISettings.java | 184 ++++ .../src/com/earth2me/essentials/Settings.java | 927 +++++++++++++++++++++ .../com/earth2me/essentials/UpdateSettings.java | 64 ++ 16 files changed, 1262 insertions(+), 59 deletions(-) create mode 100644 Essentials/src/net/ess3/settings/commands/Teleport.java delete mode 100644 Essentials/src/net/ess3/settings/commands/Tpa.java create mode 100644 Essentials2Compat/src/com/earth2me/essentials/ISettings.java create mode 100644 Essentials2Compat/src/com/earth2me/essentials/Settings.java create mode 100644 Essentials2Compat/src/com/earth2me/essentials/UpdateSettings.java diff --git a/Essentials/src/net/ess3/commands/Commandspeed.java b/Essentials/src/net/ess3/commands/Commandspeed.java index cb20da50b..ea28ee0b9 100644 --- a/Essentials/src/net/ess3/commands/Commandspeed.java +++ b/Essentials/src/net/ess3/commands/Commandspeed.java @@ -32,7 +32,7 @@ public class Commandspeed extends EssentialsCommand } boolean isFly; - float speed; + double speed; boolean isBypass = Permissions.SPEED_BYPASS.isAuthorized(user); if (args.length == 1) { @@ -60,7 +60,7 @@ public class Commandspeed extends EssentialsCommand //if (isFly) //{ - user.getPlayer().setFlySpeed(getRealMoveSpeed(speed, isFly, isBypass)); + user.getPlayer().setFlySpeed((float)getRealMoveSpeed(speed, isFly, isBypass)); user.sendMessage(_("moveSpeed", _("flying"), speed, user.getPlayer().getDisplayName())); //} //else @@ -70,13 +70,13 @@ public class Commandspeed extends EssentialsCommand //} } - private void speedOtherPlayers(final Server server, final CommandSender sender, final boolean isFly, final boolean isBypass, final float speed, final String target) + private void speedOtherPlayers(final Server server, final CommandSender sender, final boolean isFly, final boolean isBypass, final double speed, final String target) { for (Player matchPlayer : server.matchPlayer(target)) { if (isFly) { - matchPlayer.setFlySpeed(getRealMoveSpeed(speed, isFly, isBypass)); + matchPlayer.setFlySpeed((float)getRealMoveSpeed(speed, isFly, isBypass)); sender.sendMessage(_("moveSpeed", _("flying"), speed, matchPlayer.getDisplayName())); } //else @@ -128,10 +128,10 @@ public class Commandspeed extends EssentialsCommand return userSpeed; } - private float getRealMoveSpeed(final float userSpeed, final boolean isFly, final boolean isBypass) + private double getRealMoveSpeed(final double userSpeed, final boolean isFly, final boolean isBypass) { - final float defaultSpeed = isFly ? 0.1f : 0.2f; - float maxSpeed = 1f; + final double defaultSpeed = isFly ? 0.1f : 0.2f; + double maxSpeed = 1f; if (!isBypass) { maxSpeed = ess.getSettings().getData().getCommands().getSpeed().getMaxFlySpeed();// : ess.getSettings().ess.getSettings().getData().getCommands().getSpeed()getMaxWalkSpeed()); @@ -143,7 +143,7 @@ public class Commandspeed extends EssentialsCommand } else { - float ratio = ((userSpeed - 1) / 9) * (maxSpeed - defaultSpeed); + double ratio = ((userSpeed - 1) / 9) * (maxSpeed - defaultSpeed); return ratio + defaultSpeed; } } diff --git a/Essentials/src/net/ess3/commands/Commandtpa.java b/Essentials/src/net/ess3/commands/Commandtpa.java index 9e585abf9..bacb13bb0 100644 --- a/Essentials/src/net/ess3/commands/Commandtpa.java +++ b/Essentials/src/net/ess3/commands/Commandtpa.java @@ -36,7 +36,7 @@ public class Commandtpa extends EssentialsCommand player.sendMessage(_("typeTpaccept")); player.sendMessage(_("typeTpdeny")); int tpaAcceptCancellation = 0; - tpaAcceptCancellation = settings.getData().getCommands().getTpa().getTimeout(); + tpaAcceptCancellation = settings.getData().getCommands().getTeleport().getRequestTimeout(); if (tpaAcceptCancellation != 0) { player.sendMessage(_("teleportRequestTimeoutInfo", tpaAcceptCancellation)); diff --git a/Essentials/src/net/ess3/commands/Commandtpaall.java b/Essentials/src/net/ess3/commands/Commandtpaall.java index 48c774e99..ab3d5a364 100644 --- a/Essentials/src/net/ess3/commands/Commandtpaall.java +++ b/Essentials/src/net/ess3/commands/Commandtpaall.java @@ -55,7 +55,7 @@ public class Commandtpaall extends EssentialsCommand player.sendMessage(_("teleportHereRequest", user.getPlayer().getDisplayName())); player.sendMessage(_("typeTpaccept")); int tpaAcceptCancellation = 0; - tpaAcceptCancellation = settings.getData().getCommands().getTpa().getTimeout(); + tpaAcceptCancellation = settings.getData().getCommands().getTeleport().getRequestTimeout(); if (tpaAcceptCancellation != 0) { player.sendMessage(_("teleportRequestTimeoutInfo", tpaAcceptCancellation)); diff --git a/Essentials/src/net/ess3/commands/Commandtpaccept.java b/Essentials/src/net/ess3/commands/Commandtpaccept.java index 8aed3028e..b8a9ee54f 100644 --- a/Essentials/src/net/ess3/commands/Commandtpaccept.java +++ b/Essentials/src/net/ess3/commands/Commandtpaccept.java @@ -34,7 +34,7 @@ public class Commandtpaccept extends EssentialsCommand ISettings settings = ess.getSettings(); - int tpaAcceptCancellation = settings.getData().getCommands().getTpa().getTimeout(); + int tpaAcceptCancellation = settings.getData().getCommands().getTeleport().getRequestTimeout(); if (tpaAcceptCancellation != 0 && (System.currentTimeMillis() - user.getTeleportRequestTime()) / 1000 > tpaAcceptCancellation) { diff --git a/Essentials/src/net/ess3/commands/Commandtpahere.java b/Essentials/src/net/ess3/commands/Commandtpahere.java index ad876e996..df8a8e679 100644 --- a/Essentials/src/net/ess3/commands/Commandtpahere.java +++ b/Essentials/src/net/ess3/commands/Commandtpahere.java @@ -34,7 +34,7 @@ public class Commandtpahere extends EssentialsCommand player.sendMessage(_("typeTpaccept")); int tpaAcceptCancellation = 0; { - tpaAcceptCancellation = settings.getData().getCommands().getTpa().getTimeout(); + tpaAcceptCancellation = settings.getData().getCommands().getTeleport().getRequestTimeout(); } if (tpaAcceptCancellation != 0) { diff --git a/Essentials/src/net/ess3/listener/EssentialsPlayerListener.java b/Essentials/src/net/ess3/listener/EssentialsPlayerListener.java index c73f9c02a..82e05060a 100644 --- a/Essentials/src/net/ess3/listener/EssentialsPlayerListener.java +++ b/Essentials/src/net/ess3/listener/EssentialsPlayerListener.java @@ -326,7 +326,7 @@ public class EssentialsPlayerListener implements Listener { final IUser user = ess.getUserMap().getUser(event.getPlayer()); final String cmd = spaceSplit.split(event.getMessage().toLowerCase(Locale.ENGLISH))[0].replace("/", "").toLowerCase(Locale.ENGLISH); - if (ess.getSettings().getData().getCommands().getSocalspy().getSocialspyCommands().contains(cmd)) + if (ess.getSettings().getData().getCommands().getSocialspy().getSocialspyCommands().contains(cmd)) { for (Player player : ess.getServer().getOnlinePlayers()) { @@ -360,7 +360,7 @@ public class EssentialsPlayerListener implements Listener user.sendMessage(_("noGodWorldWarning")); } } - if (settings.getData().getCommands().getTpa().isCancelTpRequestsOnWorldChange()) + if (settings.getData().getCommands().getTeleport().isCancelRequestsOnWorldChange()) { if (user.getTeleportRequester() != null) { diff --git a/Essentials/src/net/ess3/settings/Commands.java b/Essentials/src/net/ess3/settings/Commands.java index fa23f6583..da84f725d 100644 --- a/Essentials/src/net/ess3/settings/Commands.java +++ b/Essentials/src/net/ess3/settings/Commands.java @@ -24,9 +24,9 @@ public class Commands implements StorageObject private Lightning lightning = new Lightning(); private net.ess3.settings.commands.List list = new net.ess3.settings.commands.List(); private Near near = new Near(); - private SocialSpy socalspy = new SocialSpy(); + private SocialSpy socialspy = new SocialSpy(); private Spawnmob spawnmob = new Spawnmob(); - private Tpa tpa = new Tpa(); + private Teleport teleport = new Teleport(); private Speed speed = new Speed(); @ListType @Comment( diff --git a/Essentials/src/net/ess3/settings/General.java b/Essentials/src/net/ess3/settings/General.java index a34b5f5cc..170407c55 100644 --- a/Essentials/src/net/ess3/settings/General.java +++ b/Essentials/src/net/ess3/settings/General.java @@ -51,17 +51,7 @@ 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", diff --git a/Essentials/src/net/ess3/settings/commands/Speed.java b/Essentials/src/net/ess3/settings/commands/Speed.java index 61872fa5e..cb9652006 100644 --- a/Essentials/src/net/ess3/settings/commands/Speed.java +++ b/Essentials/src/net/ess3/settings/commands/Speed.java @@ -9,9 +9,9 @@ import net.ess3.storage.StorageObject; @EqualsAndHashCode(callSuper = false) public class Speed implements StorageObject { - @Comment({"#Set the max fly speed, values range from 0.1 to 1.0"}) - private float maxFlySpeed = 1.0f; + @Comment({"Set the max fly speed, values range from 0.2 to 1.0"}) + private double maxFlySpeed = 1.0f; - /*@Comment({"#Set the max walk speed, values range from 0.1 to 1.0"}) - private float maxWalkSpeed = 0.8f;*/ + @Comment({"Set the max walk speed, values range from 0.1 to 1.0"}) + private double maxWalkSpeed = 0.8f; } diff --git a/Essentials/src/net/ess3/settings/commands/Teleport.java b/Essentials/src/net/ess3/settings/commands/Teleport.java new file mode 100644 index 000000000..04be7a24e --- /dev/null +++ b/Essentials/src/net/ess3/settings/commands/Teleport.java @@ -0,0 +1,32 @@ +package net.ess3.settings.commands; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.ess3.storage.Comment; +import net.ess3.storage.StorageObject; + + +@Data +@EqualsAndHashCode(callSuper = false) +public class Teleport implements StorageObject +{ + @Comment( + { + "Set timeout in seconds for players to accept tpa before request is cancelled.", + "Set to 0 for no timeout." + }) + private int requestTimeout = 0; + @Comment({"Cancels a request made by tpa / tphere on world change to prevent cross world tp"}) + private boolean cancelRequestsOnWorldChange = false; + @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 invulnerability = 0; + + public long getInvulnerability() + { + return invulnerability * 1000; + } +} diff --git a/Essentials/src/net/ess3/settings/commands/Tpa.java b/Essentials/src/net/ess3/settings/commands/Tpa.java deleted file mode 100644 index 5b8795266..000000000 --- a/Essentials/src/net/ess3/settings/commands/Tpa.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.ess3.settings.commands; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import net.ess3.storage.Comment; -import net.ess3.storage.StorageObject; - - -@Data -@EqualsAndHashCode(callSuper = false) -public class Tpa implements StorageObject -{ - @Comment( - { - "Set timeout in seconds for players to accept tpa before request is cancelled.", - "Set to 0 for no timeout." - }) - private int timeout = 0; - @Comment({"Cancels a request made by tpa / tphere on world change to prevent cross world tp"}) - private boolean cancelTpRequestsOnWorldChange = false; -} diff --git a/Essentials/src/net/ess3/user/User.java b/Essentials/src/net/ess3/user/User.java index f38d794b8..f33369597 100644 --- a/Essentials/src/net/ess3/user/User.java +++ b/Essentials/src/net/ess3/user/User.java @@ -594,7 +594,7 @@ public class User extends UserBase implements IUser { final ISettings settings = ess.getSettings(); - final long time = settings.getData().getGeneral().getTeleportInvulnerability(); + final long time = settings.getData().getCommands().getTeleport().getInvulnerability(); if (time > 0) { teleportInvulnerabilityTimestamp = System.currentTimeMillis() + time; diff --git a/Essentials2Compat/src/com/earth2me/essentials/Essentials.java b/Essentials2Compat/src/com/earth2me/essentials/Essentials.java index a483fb365..4d61e6b3d 100644 --- a/Essentials2Compat/src/com/earth2me/essentials/Essentials.java +++ b/Essentials2Compat/src/com/earth2me/essentials/Essentials.java @@ -2,6 +2,7 @@ package com.earth2me.essentials; import java.io.File; import net.ess3.api.IEssentials; +import net.ess3.api.IItemDb; import net.ess3.api.IPlugin; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -10,7 +11,7 @@ import org.bukkit.plugin.java.JavaPlugin; public class Essentials extends JavaPlugin { IEssentials ess; - + @Override public void onEnable() { @@ -19,19 +20,45 @@ public class Essentials extends JavaPlugin //TODO: Move Eco Api here IPlugin plugin = (IPlugin)getServer().getPluginManager().getPlugin("Essentials-3"); ess = plugin.getEssentials(); + updateSettings(); updateUserfiles(); } + private void updateSettings() + { + File config = new File(getDataFolder(), "config.yml"); + if (config.isFile()) + { + new UpdateSettings(config, ess); + File fileNew; + do + { + fileNew = new File(getDataFolder(), "config-" + System.currentTimeMillis() + ".yml"); + } + while (fileNew.exists()); + config.renameTo(fileNew); + } + } + private void updateUserfiles() { File folder = new File(getDataFolder(), "userdata"); - - if (folder.isDirectory()) { + + if (folder.isDirectory()) + { new UpdateUserFiles(folder, ess); - File folderNew = new File(getDataFolder(), "userdata-"+System.currentTimeMillis()); - if (!folderNew.exists()) { - folder.renameTo(folderNew); + File folderNew; + do + { + folderNew = new File(getDataFolder(), "userdata-" + System.currentTimeMillis()); } + while (folderNew.exists()); + folder.renameTo(folderNew); } } + + public IItemDb getItemDb() + { + return ess.getItemDb(); + } } diff --git a/Essentials2Compat/src/com/earth2me/essentials/ISettings.java b/Essentials2Compat/src/com/earth2me/essentials/ISettings.java new file mode 100644 index 000000000..268a81ba0 --- /dev/null +++ b/Essentials2Compat/src/com/earth2me/essentials/ISettings.java @@ -0,0 +1,184 @@ +package com.earth2me.essentials; + + +import java.text.MessageFormat; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.bukkit.ChatColor; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.event.EventPriority; + + +public interface ISettings +{ + boolean areSignsDisabled(); + + String getAnnounceNewPlayerFormat(); + + boolean getAnnounceNewPlayers(); + + String getNewPlayerKit(); + + String getBackupCommand(); + + long getBackupInterval(); + + //MessageFormat getChatFormat(String group); + + int getChatRadius(); + + + + double getCommandCost(String label); + + String getCurrencySymbol(); + + int getOversizedStackSize(); + + int getDefaultStackSize(); + + double getHealCooldown(); + + Map getKit(String name); + + ConfigurationSection getKits(); + + String getLocale(); + + String getNewbieSpawn(); + + String getNicknamePrefix(); + + ChatColor getOperatorColor() throws Exception; + + boolean getPerWarpPermission(); + + boolean getProtectBoolean(final String configName, boolean def); + + int getProtectCreeperMaxHeight(); + + List getProtectList(final String configName); + + boolean getProtectPreventSpawn(final String creatureName); + + String getProtectString(final String configName); + + boolean getRespawnAtHome(); + + Set getMultipleHomes(); + + int getHomeLimit(String set); + + + + boolean getSortListByGroups(); + + int getSpawnMobLimit(); + + int getStartingBalance(); + + double getTeleportCooldown(); + + double getTeleportDelay(); + + boolean hidePermissionlessHelp(); + + + + boolean isCommandDisabled(String label); + + boolean isCommandOverridden(String name); + + boolean isDebug(); + + boolean isEcoDisabled(); + + boolean isTradeInStacks(int id); + + List itemSpawnBlacklist(); + + List enabledSigns(); + + boolean permissionBasedItemSpawn(); + + boolean showNonEssCommandsInHelp(); + + boolean warnOnBuildDisallow(); + + boolean warnOnSmite(); + + double getMaxMoney(); + + double getMinMoney(); + + boolean isEcoLogEnabled(); + + boolean isEcoLogUpdateEnabled(); + + boolean removeGodOnDisconnect(); + + boolean changeDisplayName(); + + boolean changePlayerListName(); + + boolean isPlayerCommand(String string); + + boolean useBukkitPermissions(); + + boolean addPrefixSuffix(); + + boolean disablePrefix(); + + boolean disableSuffix(); + + long getAutoAfk(); + + long getAutoAfkKick(); + + boolean getFreezeAfkPlayers(); + + boolean cancelAfkOnMove(); + + boolean areDeathMessagesEnabled(); + + public void setDebug(boolean debug); + + Set getNoGodWorlds(); + + boolean getUpdateBedAtDaytime(); + + boolean getRepairEnchanted(); + + boolean isWorldTeleportPermissions(); + + boolean isWorldHomePermissions(); + + boolean registerBackInListener(); + + boolean getDisableItemPickupWhileAfk(); + + EventPriority getRespawnPriority(); + + long getTpaAcceptCancellation(); + + boolean isMetricsEnabled(); + + void setMetricsEnabled(boolean metricsEnabled); + + long getTeleportInvulnerability(); + + boolean isTeleportInvulnerability(); + + long getLoginAttackDelay(); + + int getSignUsePerSecond(); + + double getMaxFlySpeed(); + + double getMaxWalkSpeed(); + + public int getMailsPerMinute(); + + public void setEssentialsChatActive(boolean b); +} \ No newline at end of file diff --git a/Essentials2Compat/src/com/earth2me/essentials/Settings.java b/Essentials2Compat/src/com/earth2me/essentials/Settings.java new file mode 100644 index 000000000..262dbe140 --- /dev/null +++ b/Essentials2Compat/src/com/earth2me/essentials/Settings.java @@ -0,0 +1,927 @@ +package com.earth2me.essentials; + +import java.io.File; +import java.text.MessageFormat; +import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; +import static net.ess3.I18n._; +import net.ess3.api.IEssentials; +import org.bukkit.ChatColor; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.MemoryConfiguration; +import org.bukkit.event.EventPriority; +import org.bukkit.inventory.ItemStack; + + +public class Settings implements ISettings +{ + private final transient EssentialsConf config; + private final static Logger logger = Logger.getLogger("Minecraft"); + private final transient IEssentials ess; + private boolean metricsEnabled = true; + + public Settings(IEssentials ess, File file) + { + this.ess = ess; + config = new EssentialsConf(file); + //config.setTemplateName("/config.yml"); + reloadConfig(); + } + + @Override + public boolean getRespawnAtHome() + { + return config.getBoolean("respawn-at-home", false); + } + + @Override + public boolean getUpdateBedAtDaytime() + { + return config.getBoolean("update-bed-at-daytime", true); + } + + @Override + public Set getMultipleHomes() + { + return config.getConfigurationSection("sethome-multiple").getKeys(false); + } + + @Override + public int getHomeLimit(final String set) + { + return config.getInt("sethome-multiple." + set, config.getInt("sethome-multiple.default", 3)); + } + private int chatRadius = 0; + + private int _getChatRadius() + { + return config.getInt("chat.radius", config.getInt("chat-radius", 0)); + } + + @Override + public int getChatRadius() + { + return chatRadius; + } + + @Override + public double getTeleportDelay() + { + return config.getDouble("teleport-delay", 0); + } + + @Override + public int getOversizedStackSize() + { + return config.getInt("oversized-stacksize", 64); + } + + @Override + public int getDefaultStackSize() + { + return config.getInt("default-stack-size", -1); + } + + @Override + public int getStartingBalance() + { + return config.getInt("starting-balance", 0); + } + + private Set disabledCommands = new HashSet(); + + @Override + public boolean isCommandDisabled(String label) + { + return disabledCommands.contains(label); + } + + private Set getDisabledCommands() + { + Set disCommands = new HashSet(); + for (String c : config.getStringList("disabled-commands")) + { + disCommands.add(c.toLowerCase(Locale.ENGLISH)); + } + for (String c : config.getKeys(false)) + { + if (c.startsWith("disable-")) + { + disCommands.add(c.substring(8).toLowerCase(Locale.ENGLISH)); + } + } + return disCommands; + } + + @Override + public boolean isPlayerCommand(String label) + { + for (String c : config.getStringList("player-commands")) + { + if (!c.equalsIgnoreCase(label)) + { + continue; + } + return true; + } + return false; + } + + @Override + public boolean isCommandOverridden(String name) + { + for (String c : config.getStringList("overridden-commands")) + { + if (!c.equalsIgnoreCase(name)) + { + continue; + } + return true; + } + return config.getBoolean("override-" + name.toLowerCase(Locale.ENGLISH), false); + } + private ConfigurationSection commandCosts; + + + + public ConfigurationSection _getCommandCosts() + { + if (config.isConfigurationSection("command-costs")) + { + final ConfigurationSection section = config.getConfigurationSection("command-costs"); + final ConfigurationSection newSection = new MemoryConfiguration(); + for (String command : section.getKeys(false)) + { + if (section.isDouble(command)) + { + newSection.set(command.toLowerCase(Locale.ENGLISH), section.getDouble(command)); + } + else if (section.isInt(command)) + { + newSection.set(command.toLowerCase(Locale.ENGLISH), (double)section.getInt(command)); + } + } + return newSection; + } + return null; + } + + @Override + public double getCommandCost(String name) + { + name = name.replace('.', '_').replace('/', '_'); + if (commandCosts != null) + { + return commandCosts.getDouble(name, 0.0); + } + return 0.0; + } + private String nicknamePrefix = "~"; + + private String _getNicknamePrefix() + { + return config.getString("nickname-prefix", "~"); + } + + @Override + public String getNicknamePrefix() + { + return nicknamePrefix; + } + + @Override + public double getTeleportCooldown() + { + return config.getDouble("teleport-cooldown", 0); + } + + @Override + public double getHealCooldown() + { + return config.getDouble("heal-cooldown", 0); + } + private ConfigurationSection kits; + + public ConfigurationSection _getKits() + { + if (config.isConfigurationSection("kits")) + { + final ConfigurationSection section = config.getConfigurationSection("kits"); + final ConfigurationSection newSection = new MemoryConfiguration(); + for (String kitItem : section.getKeys(false)) + { + if (section.isConfigurationSection(kitItem)) + { + newSection.set(kitItem.toLowerCase(Locale.ENGLISH), section.getConfigurationSection(kitItem)); + } + } + return newSection; + } + return null; + } + + @Override + public ConfigurationSection getKits() + { + return kits; + } + + @Override + public Map getKit(String name) + { + name = name.replace('.', '_').replace('/', '_'); + if (getKits() != null) + { + final ConfigurationSection kits = getKits(); + if (kits.isConfigurationSection(name)) + { + return kits.getConfigurationSection(name).getValues(true); + } + } + return null; + } + private ChatColor operatorColor = null; + + @Override + public ChatColor getOperatorColor() + { + return operatorColor; + } + + private ChatColor _getOperatorColor() + { + String colorName = config.getString("ops-name-color", null); + + if (colorName == null) + { + return ChatColor.DARK_RED; + } + if ("none".equalsIgnoreCase(colorName) || colorName.isEmpty()) + { + return null; + } + + try + { + return ChatColor.valueOf(colorName.toUpperCase(Locale.ENGLISH)); + } + catch (IllegalArgumentException ex) + { + } + + return ChatColor.getByChar(colorName); + } + + @Override + public int getSpawnMobLimit() + { + return config.getInt("spawnmob-limit", 10); + } + + @Override + public boolean showNonEssCommandsInHelp() + { + return config.getBoolean("non-ess-in-help", true); + } + + @Override + public boolean hidePermissionlessHelp() + { + return config.getBoolean("hide-permissionless-help", true); + } + + @Override + public int getProtectCreeperMaxHeight() + { + return config.getInt("protect.creeper.max-height", -1); + } + + @Override + public boolean areSignsDisabled() + { + return !signsEnabled; + } + + @Override + public long getBackupInterval() + { + return config.getInt("backup.interval", 1440); // 1440 = 24 * 60 + } + + @Override + public String getBackupCommand() + { + return config.getString("backup.command", null); + } + private Map chatFormats = Collections.synchronizedMap(new HashMap()); + + /*@Override + public MessageFormat getChatFormat(String group) + { + MessageFormat mFormat = chatFormats.get(group); + if (mFormat == null) + { + String format = config.getString("chat.group-formats." + (group == null ? "Default" : group), + config.getString("chat.format", "&7[{GROUP}]&f {DISPLAYNAME}&7:&f {MESSAGE}")); + format = Util.replaceFormat(format); + format = format.replace("{DISPLAYNAME}", "%1$s"); + format = format.replace("{GROUP}", "{0}"); + format = format.replace("{MESSAGE}", "%2$s"); + format = format.replace("{WORLDNAME}", "{1}"); + format = format.replace("{SHORTWORLDNAME}", "{2}"); + format = format.replaceAll("\\{(\\D*?)\\}", "\\[$1\\]"); + format = "§r".concat(format); + mFormat = new MessageFormat(format); + chatFormats.put(group, mFormat); + } + return mFormat; + }*/ + + public String getDefaultChatformat() + { + return config.getString("chat.format", "&7[{GROUP}]&f {DISPLAYNAME}&7:&f {MESSAGE}"); + } + + @Override + public boolean getAnnounceNewPlayers() + { + return !config.getString("newbies.announce-format", "-").isEmpty(); + } + + @Override + public String getAnnounceNewPlayerFormat() + { + return config.getString("newbies.announce-format", "&dWelcome {DISPLAYNAME} to the server!"); + } + + @Override + public String getNewPlayerKit() + { + return config.getString("newbies.kit", ""); + } + + @Override + public String getNewbieSpawn() + { + return config.getString("newbies.spawnpoint", "default"); + } + + @Override + public boolean getPerWarpPermission() + { + return config.getBoolean("per-warp-permission", false); + } + + @Override + public boolean getSortListByGroups() + { + return config.getBoolean("sort-list-by-groups", true); + } + + + public void reloadConfig() + { + config.load(); + noGodWorlds = new HashSet(config.getStringList("no-god-in-worlds")); + enabledSigns = _getEnabledSigns(); + teleportInvulnerability = _isTeleportInvulnerability(); + disableItemPickupWhileAfk = _getDisableItemPickupWhileAfk(); + registerBackInListener = _registerBackInListener(); + cancelAfkOnMove = _cancelAfkOnMove(); + getFreezeAfkPlayers = _getFreezeAfkPlayers(); + itemSpawnBl = _getItemSpawnBlacklist(); + loginAttackDelay = _getLoginAttackDelay(); + signUsePerSecond = _getSignUsePerSecond(); + kits = _getKits(); + chatFormats.clear(); + changeDisplayName = _changeDisplayName(); + disabledCommands = getDisabledCommands(); + nicknamePrefix = _getNicknamePrefix(); + operatorColor = _getOperatorColor(); + changePlayerListName = _changePlayerListName(); + configDebug = _isDebug(); + prefixsuffixconfigured = _isPrefixSuffixConfigured(); + addprefixsuffix = _addPrefixSuffix(); + disablePrefix = _disablePrefix(); + disableSuffix = _disableSuffix(); + chatRadius = _getChatRadius(); + commandCosts = _getCommandCosts(); + warnOnBuildDisallow = _warnOnBuildDisallow(); + mailsPerMinute = _getMailsPerMinute(); + } + private List itemSpawnBl = new ArrayList(); + + @Override + public List itemSpawnBlacklist() + { + return itemSpawnBl; + } + + private List _getItemSpawnBlacklist() + { + final List epItemSpwn = new ArrayList(); + if (ess.getItemDb() == null) + { + logger.log(Level.FINE, "Aborting ItemSpawnBL read, itemDB not yet loaded."); + return epItemSpwn; + } + for (String itemName : config.getString("item-spawn-blacklist", "").split(",")) + { + itemName = itemName.trim(); + if (itemName.isEmpty()) + { + continue; + } + try + { + final ItemStack iStack = ess.getItemDb().get(itemName); + epItemSpwn.add(iStack.getTypeId()); + } + catch (Exception ex) + { + logger.log(Level.SEVERE, _("unknownItemInList", itemName, "item-spawn-blacklist")); + } + } + return epItemSpwn; + } + private List enabledSigns = new ArrayList(); + private boolean signsEnabled = false; + + @Override + public List enabledSigns() + { + return enabledSigns; + } + + private List _getEnabledSigns() + { + List newSigns = new ArrayList(); + + for (String signName : config.getStringList("enabledSigns")) + { + signName = signName.trim().toUpperCase(Locale.ENGLISH); + if (signName.isEmpty()) + { + continue; + } + if (signName.equals("COLOR") || signName.equals("COLOUR")) + { + signsEnabled = true; + continue; + } + try + { + newSigns.add(signName); + } + catch (Exception ex) + { + logger.log(Level.SEVERE, _("unknownItemInList", signName, "enabledSigns")); + continue; + } + signsEnabled = true; + } + return newSigns; + } + private boolean warnOnBuildDisallow; + + private boolean _warnOnBuildDisallow() + { + return config.getBoolean("protect.disable.warn-on-build-disallow", false); + } + + @Override + public boolean warnOnBuildDisallow() + { + return warnOnBuildDisallow; + } + private boolean debug = false; + private boolean configDebug = false; + + private boolean _isDebug() + { + return config.getBoolean("debug", false); + } + + @Override + public boolean isDebug() + { + return debug || configDebug; + } + + @Override + public boolean warnOnSmite() + { + return config.getBoolean("warn-on-smite", true); + } + + @Override + public boolean permissionBasedItemSpawn() + { + return config.getBoolean("permission-based-item-spawn", false); + } + + @Override + public String getLocale() + { + return config.getString("locale", ""); + } + + @Override + public String getCurrencySymbol() + { + return config.getString("currency-symbol", "$").concat("$").substring(0, 1).replaceAll("[0-9]", "$"); + } + + @Override + public boolean isTradeInStacks(int id) + { + return config.getBoolean("trade-in-stacks-" + id, false); + } + + @Override + public boolean isEcoDisabled() + { + return config.getBoolean("disable-eco", false); + } + + @Override + public boolean getProtectPreventSpawn(final String creatureName) + { + return config.getBoolean("protect.prevent.spawn." + creatureName, false); + } + + @Override + public List getProtectList(final String configName) + { + final List list = new ArrayList(); + for (String itemName : config.getString(configName, "").split(",")) + { + itemName = itemName.trim(); + if (itemName.isEmpty()) + { + continue; + } + ItemStack itemStack; + try + { + itemStack = ess.getItemDb().get(itemName); + list.add(itemStack.getTypeId()); + } + catch (Exception ex) + { + logger.log(Level.SEVERE, _("unknownItemInList", itemName, configName)); + } + } + return list; + } + + @Override + public String getProtectString(final String configName) + { + return config.getString(configName, null); + } + + @Override + public boolean getProtectBoolean(final String configName, boolean def) + { + return config.getBoolean(configName, def); + } + private final static double MAXMONEY = 10000000000000.0; + + @Override + public double getMaxMoney() + { + double max = config.getDouble("max-money", MAXMONEY); + if (Math.abs(max) > MAXMONEY) + { + max = max < 0 ? -MAXMONEY : MAXMONEY; + } + return max; + } + private final static double MINMONEY = -10000000000000.0; + + @Override + public double getMinMoney() + { + double min = config.getDouble("min-money", MINMONEY); + if (min > 0) + { + min = -min; + } + if (min < MINMONEY) + { + min = MINMONEY; + } + return min; + } + + @Override + public boolean isEcoLogEnabled() + { + return config.getBoolean("economy-log-enabled", false); + } + + @Override + public boolean isEcoLogUpdateEnabled() + { + return config.getBoolean("economy-log-update-enabled", false); + } + + @Override + public boolean removeGodOnDisconnect() + { + return config.getBoolean("remove-god-on-disconnect", false); + } + private boolean changeDisplayName = true; + + private boolean _changeDisplayName() + { + return config.getBoolean("change-displayname", true); + } + + @Override + public boolean changeDisplayName() + { + return changeDisplayName; + } + private boolean changePlayerListName = false; + + private boolean _changePlayerListName() + { + return config.getBoolean("change-playerlist", false); + } + + @Override + public boolean changePlayerListName() + { + return changePlayerListName; + } + + @Override + public boolean useBukkitPermissions() + { + return config.getBoolean("use-bukkit-permissions", false); + } + private boolean prefixsuffixconfigured = false; + private boolean addprefixsuffix = false; + private boolean essentialsChatActive = false; + + private boolean _addPrefixSuffix() + { + return config.getBoolean("add-prefix-suffix", false); + } + + private boolean _isPrefixSuffixConfigured() + { + return config.hasProperty("add-prefix-suffix"); + } + + @Override + public void setEssentialsChatActive(boolean essentialsChatActive) + { + this.essentialsChatActive = essentialsChatActive; + } + + @Override + public boolean addPrefixSuffix() + { + return prefixsuffixconfigured ? addprefixsuffix : essentialsChatActive; + } + private boolean disablePrefix = false; + + private boolean _disablePrefix() + { + return config.getBoolean("disablePrefix", false); + } + + @Override + public boolean disablePrefix() + { + return disablePrefix; + } + private boolean disableSuffix = false; + + private boolean _disableSuffix() + { + return config.getBoolean("disableSuffix", false); + } + + @Override + public boolean disableSuffix() + { + return disableSuffix; + } + + @Override + public long getAutoAfk() + { + return config.getLong("auto-afk", 300); + } + + @Override + public long getAutoAfkKick() + { + return config.getLong("auto-afk-kick", -1); + } + private boolean getFreezeAfkPlayers; + + @Override + public boolean getFreezeAfkPlayers() + { + return getFreezeAfkPlayers; + } + + private boolean _getFreezeAfkPlayers() + { + return config.getBoolean("freeze-afk-players", false); + } + private boolean cancelAfkOnMove; + + @Override + public boolean cancelAfkOnMove() + { + return cancelAfkOnMove; + } + + private boolean _cancelAfkOnMove() + { + return config.getBoolean("cancel-afk-on-move", true); + } + + @Override + public boolean areDeathMessagesEnabled() + { + return config.getBoolean("death-messages", true); + } + private Set noGodWorlds = new HashSet(); + + @Override + public Set getNoGodWorlds() + { + return noGodWorlds; + } + + @Override + public void setDebug(final boolean debug) + { + this.debug = debug; + } + + @Override + public boolean getRepairEnchanted() + { + return config.getBoolean("repair-enchanted", true); + } + + @Override + public boolean isWorldTeleportPermissions() + { + return config.getBoolean("world-teleport-permissions", false); + } + + @Override + public boolean isWorldHomePermissions() + { + return config.getBoolean("world-home-permissions", false); + } + private boolean registerBackInListener; + + @Override + public boolean registerBackInListener() + { + return registerBackInListener; + } + + private boolean _registerBackInListener() + { + return config.getBoolean("register-back-in-listener", false); + } + private boolean disableItemPickupWhileAfk; + + @Override + public boolean getDisableItemPickupWhileAfk() + { + return disableItemPickupWhileAfk; + } + + private boolean _getDisableItemPickupWhileAfk() + { + return config.getBoolean("disable-item-pickup-while-afk", false); + } + + @Override + public EventPriority getRespawnPriority() + { + String priority = config.getString("respawn-listener-priority", "normal").toLowerCase(Locale.ENGLISH); + if ("lowest".equals(priority)) + { + return EventPriority.LOWEST; + } + if ("low".equals(priority)) + { + return EventPriority.LOW; + } + if ("normal".equals(priority)) + { + return EventPriority.NORMAL; + } + if ("high".equals(priority)) + { + return EventPriority.HIGH; + } + if ("highest".equals(priority)) + { + return EventPriority.HIGHEST; + } + return EventPriority.NORMAL; + } + + @Override + public long getTpaAcceptCancellation() + { + return config.getLong("tpa-accept-cancellation", 0); + } + + @Override + public boolean isMetricsEnabled() + { + return metricsEnabled; + } + + @Override + public void setMetricsEnabled(boolean metricsEnabled) + { + this.metricsEnabled = metricsEnabled; + } + private boolean teleportInvulnerability; + + @Override + public long getTeleportInvulnerability() + { + return config.getLong("teleport-invulnerability", 0) * 1000; + } + + private boolean _isTeleportInvulnerability() + { + return (config.getLong("teleport-invulnerability", 0) > 0); + } + + @Override + public boolean isTeleportInvulnerability() + { + return teleportInvulnerability; + } + private long loginAttackDelay; + + private long _getLoginAttackDelay() + { + return config.getLong("login-attack-delay", 0) * 1000; + } + + @Override + public long getLoginAttackDelay() + { + return loginAttackDelay; + } + private int signUsePerSecond; + + private int _getSignUsePerSecond() + { + final int perSec = config.getInt("sign-use-per-second", 4); + return perSec > 0 ? perSec : 1; + } + + @Override + public int getSignUsePerSecond() + { + return signUsePerSecond; + } + + @Override + public double getMaxFlySpeed() + { + double maxSpeed = config.getDouble("max-fly-speed", 1.0); + return maxSpeed > 1.0 ? 1.0 : Math.abs(maxSpeed); + } + + //This option does not exist in the config.yml because it wasn't yet implemented in bukkit + //The code was commented out in the /speed command + @Override + public double getMaxWalkSpeed() + { + double maxSpeed = config.getDouble("max-walk-speed", 0.8); + return maxSpeed > 1.0 ? 1.0 : Math.abs(maxSpeed); + } + + private int mailsPerMinute; + + private int _getMailsPerMinute() { + return config.getInt("mails-per-minute", 1000); + } + @Override + public int getMailsPerMinute() + { + return mailsPerMinute; + } +} \ No newline at end of file diff --git a/Essentials2Compat/src/com/earth2me/essentials/UpdateSettings.java b/Essentials2Compat/src/com/earth2me/essentials/UpdateSettings.java new file mode 100644 index 000000000..b269f2711 --- /dev/null +++ b/Essentials2Compat/src/com/earth2me/essentials/UpdateSettings.java @@ -0,0 +1,64 @@ +package com.earth2me.essentials; + +import java.io.File; +import net.ess3.api.IEssentials; +import net.ess3.settings.General; + + +public class UpdateSettings +{ + UpdateSettings(File config, IEssentials ess) + { + Settings settings = new Settings(ess, config); + net.ess3.settings.Settings data = ess.getSettings().getData(); + data.getChat().setChangeDisplayname(settings.changeDisplayName()); + data.getChat().setDefaultFormat(settings.getDefaultChatformat()); + data.getChat().setLocalRadius(settings.getChatRadius()); + data.getChat().setNicknamePrefix(settings.getNicknamePrefix()); + data.getCommands().getAfk().setAutoAFK(settings.getAutoAfk()); + data.getCommands().getAfk().setAutoAFKKick(settings.getAutoAfkKick()); + data.getCommands().getAfk().setDisableItemPickupWhileAfk(settings.getDisableItemPickupWhileAfk()); + data.getCommands().getAfk().setFreezeAFKPlayers(settings.getFreezeAfkPlayers()); + data.getCommands().getBack().setRegisterBackInListener(settings.registerBackInListener()); + data.getCommands().getGod().setRemoveOnDisconnect(settings.removeGodOnDisconnect()); + data.getCommands().getHelp().setHidePermissionlessCommands(settings.hidePermissionlessHelp()); + data.getCommands().getHelp().setShowNonEssCommandsInHelp(settings.showNonEssCommandsInHelp()); + data.getCommands().getHome().setBedSetsHome(false); //TODO + data.getCommands().getHome().setRespawnAtHome(settings.getRespawnAtHome()); + data.getCommands().getHome().setSpawnIfNoHome(false); //TODO + data.getCommands().getHome().setUpdateBedAtDaytime(false); //TODO + data.getCommands().getLightning().setWarnPlayer(settings.warnOnSmite()); + data.getCommands().getList().setSortByGroups(settings.getSortListByGroups()); + data.getCommands().getNear().setDefaultRadius(0); //TODO + data.getCommands().getSocialspy().setSocialspyCommands(null); //TODO + data.getCommands().getSpawnmob().setLimit(settings.getSpawnMobLimit()); + data.getCommands().getSpeed().setMaxFlySpeed(settings.getMaxFlySpeed()); + data.getCommands().getSpeed().setMaxWalkSpeed(settings.getMaxWalkSpeed()); + data.getCommands().getTpa().setCancelTpRequestsOnWorldChange(false); //TODO + data.getCommands().getTpa().setTimeout(0); //TODO + data.getEconomy().setCurrencySymbol(settings.getCurrencySymbol()); + data.getEconomy().setLogEnabled(settings.isEcoLogEnabled()); + data.getEconomy().setMaxMoney(settings.getMaxMoney()); + data.getEconomy().setMinMoney(settings.getMinMoney()); + data.getEconomy().setStartingBalance(settings.getStartingBalance()); + data.getEconomy().setTradeInStacks(settings.isTradeInStacks(0)); //TODO + data.getEconomy().getWorth(); //TODO + data.getGeneral().getBackup().setCommand(settings.getBackupCommand()); + data.getGeneral().getBackup().setInterval(settings.getBackupInterval()); + data.getGeneral().setDeathMessages(settings.areDeathMessagesEnabled()); + data.getGeneral().setDebug(settings.isDebug()); + data.getGeneral().setDefaultStacksize(settings.getDefaultStackSize()); + data.getGeneral().setGroupStorage(General.GroupStorage.FILE); //TODO + data.getGeneral().setJoinMessage(null); //TODO + data.getGeneral().setLeaveMessage(null); //TODO + data.getGeneral().setLocale(settings.getLocale()); + data.getGeneral().setLoginAttackDelay(settings.getLoginAttackDelay()); + data.getGeneral().setMetricsEnabled(settings.isMetricsEnabled()); + data.getGeneral().setOversizedStacksize(settings.getOversizedStackSize()); + data.getGeneral().setTeleportInvulnerability(settings.getTeleportInvulnerability()); + data.getGeneral().setWorldHomePermissions(settings.isWorldHomePermissions()); + data.getGeneral().setWorldTeleportPermissions(settings.isWorldTeleportPermissions()); + data.getWorldOptions(null); //TODO + ess.getSettings().queueSave(); + } +} -- cgit v1.2.3