From 48d9c866e24666a398414a26124738dfd319a0e9 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 19 Apr 2016 08:33:00 +0200 Subject: [PATCH] Improve configuration file. Added support for fully disabling URL connections using the configuration file. --- .../massivecore/MassiveCoreMConf.java | 93 ++++++++++++------- .../massivecore/MassivePlugin.java | 29 +++--- .../command/MassiveCoreBukkitCommand.java | 2 +- .../command/massivecore/CmdMassiveCore.java | 2 +- .../massivecore/CmdMassiveCoreBuffer.java | 2 +- .../massivecore/CmdMassiveCoreCmdurl.java | 2 +- .../massivecore/CmdMassiveCoreStore.java | 2 +- .../massivecore/CmdMassiveCoreUsys.java | 2 +- .../engine/EngineMassiveCoreMain.java | 2 +- .../engine/EngineMassiveCoreSponsor.java | 4 + .../engine/EngineMassiveCoreVariable.java | 41 +++----- 11 files changed, 98 insertions(+), 83 deletions(-) diff --git a/src/com/massivecraft/massivecore/MassiveCoreMConf.java b/src/com/massivecraft/massivecore/MassiveCoreMConf.java index cae2c655..19045550 100644 --- a/src/com/massivecraft/massivecore/MassiveCoreMConf.java +++ b/src/com/massivecraft/massivecore/MassiveCoreMConf.java @@ -23,22 +23,30 @@ public class MassiveCoreMConf extends Entity public static MassiveCoreMConf get() { return i; } // -------------------------------------------- // - // FIELDS + // ALIASES // -------------------------------------------- // + // Base command aliases. + + public List aliasesMcore = MUtil.list("massivecore", "mcore"); + public List aliasesUsys = MUtil.list("usys"); + public List aliasesMstore = MUtil.list("massivestore", "mstore"); + public List aliasesBuffer = MUtil.list("buffer"); + public List aliasesCmdurl = MUtil.list("cmdurl"); + + // -------------------------------------------- // + // GENERAL + // -------------------------------------------- // + // General configuration options. public String taskServerId = null; + public boolean versionSynchronizationEnabled = true; + public int tabCompletionLimit = 100; + public boolean recipientChatEventEnabled = true; - public boolean checkVersionSynchronization = true; - - public int maxTabCompletions = 100; - - public List aliasesOuterMassiveCore = MUtil.list("massivecore", "mcore"); - public List aliasesOuterMassiveCoreUsys = MUtil.list("usys"); - public List aliasesOuterMassiveCoreStore = MUtil.list("massivestore", "mstore"); - public List aliasesOuterMassiveCoreBuffer = MUtil.list("buffer"); - public List aliasesOuterMassiveCoreCmdurl = MUtil.list("cmdurl"); - - public boolean usingRecipientChatEvent = true; + // -------------------------------------------- // + // PERMISSIONS FORMATS + // -------------------------------------------- // + // Permission denied formatting. public Map permissionDeniedFormats = MUtil.map( "some.awesome.permission.node", "You must be awesome to %s.", @@ -57,6 +65,11 @@ public class MassiveCoreMConf extends Entity return ret; } + // -------------------------------------------- // + // TP DELAY + // -------------------------------------------- // + // Teleportation delay permissions. + public Map permissionToTpdelay = MUtil.map( "massivecore.notpdelay", 0, "default", 10 @@ -69,45 +82,35 @@ public class MassiveCoreMConf extends Entity return ret; } + // -------------------------------------------- // + // DELETE FILES + // -------------------------------------------- // + // Delete certain files for system cleanliness. + public List deleteFiles = new ArrayList(); - // Used in the MongoDB mstore driver. - public boolean catchingMongoDbErrorsOnSave = true; - - public boolean catchingMongoDbErrorsOnDelete = true; - - public static WriteConcern getMongoDbWriteConcern(boolean catchingErrors) - { - return catchingErrors ? WriteConcern.ACKNOWLEDGED : WriteConcern.UNACKNOWLEDGED; - } - public WriteConcern getMongoDbWriteConcernSave() - { - return getMongoDbWriteConcern(this.catchingMongoDbErrorsOnSave); - } - public WriteConcern getMongoDbWriteConcernDelete() - { - return getMongoDbWriteConcern(this.catchingMongoDbErrorsOnDelete); - } - // -------------------------------------------- // // VARIABLES // -------------------------------------------- // + // Chat and command variables. - public String variableBook = "***book***"; - public boolean usingVariableBook = true; + public String variableBookName = "***book***"; + public boolean variableBookEnabled = true; - public String variableBuffer = "***buffer***"; - public boolean usingVariableBuffer = true; + public String variableBufferName = "***buffer***"; + public boolean variableBufferEnabled = true; // -------------------------------------------- // // CLICK // -------------------------------------------- // + // Button click sound configuration. public SoundEffect clickSound = SoundEffect.valueOf("UI_BUTTON_CLICK", 0.75f, 1.0f); // -------------------------------------------- // - // MSTORE CONFIGURATON + // MSTORE // -------------------------------------------- // + // The database system. public volatile long millisBetweenLocalPoll = TimeUnit.MILLIS_PER_MINUTE * 5; public volatile long millisBetweenRemotePollWithoutPusher = TimeUnit.MILLIS_PER_SECOND * 10; @@ -116,11 +119,31 @@ public class MassiveCoreMConf extends Entity @EditorType(fieldName = "iOn") public boolean warnOnLocalAlter = false; + // -------------------------------------------- // + // MONGODB + // -------------------------------------------- // + // The database system MongoDB driver. + + public boolean catchingMongoDbErrorsOnSave = true; + public boolean catchingMongoDbErrorsOnDelete = true; + + public static WriteConcern getMongoDbWriteConcern(boolean catchingErrors) { return catchingErrors ? WriteConcern.ACKNOWLEDGED : WriteConcern.UNACKNOWLEDGED; } + public WriteConcern getMongoDbWriteConcernSave() { return getMongoDbWriteConcern(this.catchingMongoDbErrorsOnSave); } + public WriteConcern getMongoDbWriteConcernDelete() { return getMongoDbWriteConcern(this.catchingMongoDbErrorsOnDelete); } + // -------------------------------------------- // // SPONSOR // -------------------------------------------- // + // URL connections to http://sponsorinfo.massivecraft.com/ public boolean sponsorEnabled = true; public long sponsorUpdateMillis = 0; + + // -------------------------------------------- // + // MCSTATS + // -------------------------------------------- // + // URL connections to http://mcstats.org/ + + public boolean mcstatsEnabled = true; } diff --git a/src/com/massivecraft/massivecore/MassivePlugin.java b/src/com/massivecraft/massivecore/MassivePlugin.java index 3c4f549e..fd920b9d 100644 --- a/src/com/massivecraft/massivecore/MassivePlugin.java +++ b/src/com/massivecraft/massivecore/MassivePlugin.java @@ -57,23 +57,26 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name // Listener Bukkit.getPluginManager().registerEvents(this, this); - // Metrics - try - { - MetricsLite metrics = new MetricsLite(this); - metrics.start(); - } - catch (IOException e) - { - String message = Txt.parse("Metrics Initialization Failed :'("); - log(message); - } - return true; } public void postEnable() { + // Metrics + if (MassiveCoreMConf.get().mcstatsEnabled) + { + try + { + MetricsLite metrics = new MetricsLite(this); + metrics.start(); + } + catch (IOException e) + { + String message = Txt.parse("Metrics Initialization Failed :'("); + log(message); + } + } + long ms = System.currentTimeMillis() - enableTime; log(Txt.parse("=== ENABLE COMPLETE (Took " + ms + "ms) ===")); } @@ -84,7 +87,7 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name if ( ! this.isVersionSynchronized()) return; // ... and checking is enabled ... - if ( ! MassiveCoreMConf.get().checkVersionSynchronization) return; + if ( ! MassiveCoreMConf.get().versionSynchronizationEnabled) return; // ... get the version numbers ... String thisVersion = this.getDescription().getVersion(); diff --git a/src/com/massivecraft/massivecore/command/MassiveCoreBukkitCommand.java b/src/com/massivecraft/massivecore/command/MassiveCoreBukkitCommand.java index 031f0f44..89ec001e 100644 --- a/src/com/massivecraft/massivecore/command/MassiveCoreBukkitCommand.java +++ b/src/com/massivecraft/massivecore/command/MassiveCoreBukkitCommand.java @@ -146,7 +146,7 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia List ret = this.getMassiveCommand().getTabCompletions(args, sender); int retSize = ret.size(); - int maxSize = MassiveCoreMConf.get().maxTabCompletions; + int maxSize = MassiveCoreMConf.get().tabCompletionLimit; if (maxSize > 0 && retSize > maxSize) { Mixin.msgOne(sender, Lang.COMMAND_TOO_MANY_TAB_SUGGESTIONS, retSize); diff --git a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCore.java b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCore.java index ed0dcc05..9d7716b9 100644 --- a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCore.java +++ b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCore.java @@ -69,7 +69,7 @@ public class CmdMassiveCore extends MassiveCommand @Override public List getAliases() { - return MassiveCoreMConf.get().aliasesOuterMassiveCore; + return MassiveCoreMConf.get().aliasesMcore; } } diff --git a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreBuffer.java b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreBuffer.java index 0fbe738e..ad14a17f 100644 --- a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreBuffer.java +++ b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreBuffer.java @@ -13,7 +13,7 @@ public class CmdMassiveCoreBuffer extends MassiveCommand // INSTANCE // -------------------------------------------- // - private static CmdMassiveCoreBuffer i = new CmdMassiveCoreBuffer() { public List getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreBuffer; } }; + private static CmdMassiveCoreBuffer i = new CmdMassiveCoreBuffer() { public List getAliases() { return MassiveCoreMConf.get().aliasesBuffer; } }; public static CmdMassiveCoreBuffer get() { return i; } // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreCmdurl.java b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreCmdurl.java index 18e46327..4b8faa56 100644 --- a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreCmdurl.java +++ b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreCmdurl.java @@ -24,7 +24,7 @@ public class CmdMassiveCoreCmdurl extends MassiveCommand // INSTANCE // -------------------------------------------- // - private static CmdMassiveCoreCmdurl i = new CmdMassiveCoreCmdurl() { public List getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreCmdurl; } }; + private static CmdMassiveCoreCmdurl i = new CmdMassiveCoreCmdurl() { public List getAliases() { return MassiveCoreMConf.get().aliasesCmdurl; } }; public static CmdMassiveCoreCmdurl get() { return i; } // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStore.java b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStore.java index 2d492239..94e1c24e 100644 --- a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStore.java +++ b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStore.java @@ -13,7 +13,7 @@ public class CmdMassiveCoreStore extends MassiveCommand // INSTANCE // -------------------------------------------- // - private static CmdMassiveCoreStore i = new CmdMassiveCoreStore() { public List getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreStore; } }; + private static CmdMassiveCoreStore i = new CmdMassiveCoreStore() { public List getAliases() { return MassiveCoreMConf.get().aliasesMstore; } }; public static CmdMassiveCoreStore get() { return i; } // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreUsys.java b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreUsys.java index a011dcaf..f9c1400c 100644 --- a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreUsys.java +++ b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreUsys.java @@ -13,7 +13,7 @@ public class CmdMassiveCoreUsys extends MassiveCommand // INSTANCE // -------------------------------------------- // - private static CmdMassiveCoreUsys i = new CmdMassiveCoreUsys() { public List getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreUsys; } }; + private static CmdMassiveCoreUsys i = new CmdMassiveCoreUsys() { public List getAliases() { return MassiveCoreMConf.get().aliasesUsys; } }; public static CmdMassiveCoreUsys get() { return i; } // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java index a2863c78..73f716ab 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreMain.java @@ -54,7 +54,7 @@ public class EngineMassiveCoreMain extends Engine public void recipientChat(final AsyncPlayerChatEvent event) { // Return unless we are using the recipient chat event - if (!MassiveCoreMConf.get().usingRecipientChatEvent) return; + if ( ! MassiveCoreMConf.get().recipientChatEventEnabled) return; // Prepare vars EventMassiveCorePlayerToRecipientChat recipientEvent; diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreSponsor.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreSponsor.java index d6ebed0b..da8b12ed 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreSponsor.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreSponsor.java @@ -63,6 +63,10 @@ public class EngineMassiveCoreSponsor extends Engine @Override public void run() { + // If enabled by mconf ... + if ( ! MassiveCoreMConf.get().sponsorEnabled) return; + + // ... update sponsor info. MassiveCoreMSponsorInfo.update(); } diff --git a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreVariable.java b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreVariable.java index 854874a2..53876786 100644 --- a/src/com/massivecraft/massivecore/engine/EngineMassiveCoreVariable.java +++ b/src/com/massivecraft/massivecore/engine/EngineMassiveCoreVariable.java @@ -13,13 +13,13 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.ItemMeta; import com.massivecraft.massivecore.Engine; import com.massivecraft.massivecore.MassiveCoreMConf; import com.massivecraft.massivecore.MassiveCorePerm; import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.InventoryUtil; import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.Txt; @@ -67,35 +67,20 @@ public class EngineMassiveCoreVariable extends Engine public static String getBookText(CommandSender sender) { - if (sender == null) return null; - if (!(sender instanceof HumanEntity)) return null; + if ( ! (sender instanceof HumanEntity)) return null; HumanEntity human = (HumanEntity)sender; - - PlayerInventory inventory = human.getInventory(); - String ret; - - ret = getBookText(inventory.getItemInHand()); - if (ret != null) return ret; - - // TODO: Handle 1.9 API without breaking 1.8 support - - // ret = getBookText(inventory.getItemInMainHand()); - // if (ret != null) return ret; - - // ret = getBookText(inventory.getItemInOffHand()); - // if (ret != null) return ret; - - return null; + ItemStack item = InventoryUtil.getWeapon(human); + return getBookText(item); } public static String getBookText(ItemStack item) { if (item == null) return null; - if (!item.hasItemMeta()) return null; + if ( ! item.hasItemMeta()) return null; ItemMeta itemMeta = item.getItemMeta(); - if (!(itemMeta instanceof BookMeta)) return null; + if ( ! (itemMeta instanceof BookMeta)) return null; BookMeta bookMeta = (BookMeta)itemMeta; - if (!bookMeta.hasPages()) return null; + if ( ! bookMeta.hasPages()) return null; List pages = bookMeta.getPages(); String ret = Txt.implode(pages, " "); ret = ret.replaceAll("\\n+", " "); @@ -105,17 +90,17 @@ public class EngineMassiveCoreVariable extends Engine public static String variableBook(Player player, String message) { // If we are using this variable ... - if (!MassiveCoreMConf.get().usingVariableBook) return message; + if ( ! MassiveCoreMConf.get().variableBookEnabled) return message; // ... get the variable content ... String content = getBookText(player); if (content == null) return message; // ... check use permission ... - if (!MassiveCorePerm.VARIABLE_BOOK.has(player, false)) return message; + if ( ! MassiveCorePerm.VARIABLE_BOOK.has(player, false)) return message; // ... and replace. - return StringUtils.replace(message, MassiveCoreMConf.get().variableBook, content); + return StringUtils.replace(message, MassiveCoreMConf.get().variableBookName, content); } // -------------------------------------------- // @@ -142,16 +127,16 @@ public class EngineMassiveCoreVariable extends Engine public static String variableBuffer(Player player, String message) { // If we are using this variable ... - if (!MassiveCoreMConf.get().usingVariableBuffer) return message; + if ( ! MassiveCoreMConf.get().variableBufferEnabled) return message; // ... get the variable content ... String content = getBuffer(player); if (content == null) return message; // ... check use permission ... - if (!MassiveCorePerm.VARIABLE_BUFFER.has(player, false)) return message; + if ( ! MassiveCorePerm.VARIABLE_BUFFER.has(player, false)) return message; // ... and replace. - return StringUtils.replace(message, MassiveCoreMConf.get().variableBuffer, content); + return StringUtils.replace(message, MassiveCoreMConf.get().variableBufferName, content); } }