Improve configuration file. Added support for fully disabling URL connections using the configuration file.

This commit is contained in:
Olof Larsson 2016-04-19 08:33:00 +02:00
parent 6ba1342408
commit 48d9c866e2
No known key found for this signature in database
GPG Key ID: BBEF14F97DA52474
11 changed files with 98 additions and 83 deletions

View File

@ -23,22 +23,30 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
public static MassiveCoreMConf get() { return i; } public static MassiveCoreMConf get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // ALIASES
// -------------------------------------------- // // -------------------------------------------- //
// Base command aliases.
public List<String> aliasesMcore = MUtil.list("massivecore", "mcore");
public List<String> aliasesUsys = MUtil.list("usys");
public List<String> aliasesMstore = MUtil.list("massivestore", "mstore");
public List<String> aliasesBuffer = MUtil.list("buffer");
public List<String> aliasesCmdurl = MUtil.list("cmdurl");
// -------------------------------------------- //
// GENERAL
// -------------------------------------------- //
// General configuration options.
public String taskServerId = null; public String taskServerId = null;
public boolean versionSynchronizationEnabled = true;
public int tabCompletionLimit = 100;
public boolean recipientChatEventEnabled = true;
public boolean checkVersionSynchronization = true; // -------------------------------------------- //
// PERMISSIONS FORMATS
public int maxTabCompletions = 100; // -------------------------------------------- //
// Permission denied formatting.
public List<String> aliasesOuterMassiveCore = MUtil.list("massivecore", "mcore");
public List<String> aliasesOuterMassiveCoreUsys = MUtil.list("usys");
public List<String> aliasesOuterMassiveCoreStore = MUtil.list("massivestore", "mstore");
public List<String> aliasesOuterMassiveCoreBuffer = MUtil.list("buffer");
public List<String> aliasesOuterMassiveCoreCmdurl = MUtil.list("cmdurl");
public boolean usingRecipientChatEvent = true;
public Map<String, String> permissionDeniedFormats = MUtil.map( public Map<String, String> permissionDeniedFormats = MUtil.map(
"some.awesome.permission.node", "<b>You must be awesome to %s<b>.", "some.awesome.permission.node", "<b>You must be awesome to %s<b>.",
@ -57,6 +65,11 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
return ret; return ret;
} }
// -------------------------------------------- //
// TP DELAY
// -------------------------------------------- //
// Teleportation delay permissions.
public Map<String, Integer> permissionToTpdelay = MUtil.map( public Map<String, Integer> permissionToTpdelay = MUtil.map(
"massivecore.notpdelay", 0, "massivecore.notpdelay", 0,
"default", 10 "default", 10
@ -69,45 +82,35 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
return ret; return ret;
} }
// -------------------------------------------- //
// DELETE FILES
// -------------------------------------------- //
// Delete certain files for system cleanliness.
public List<String> deleteFiles = new ArrayList<String>(); public List<String> deleteFiles = new ArrayList<String>();
// 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 // VARIABLES
// -------------------------------------------- // // -------------------------------------------- //
// Chat and command variables.
public String variableBook = "***book***"; public String variableBookName = "***book***";
public boolean usingVariableBook = true; public boolean variableBookEnabled = true;
public String variableBuffer = "***buffer***"; public String variableBufferName = "***buffer***";
public boolean usingVariableBuffer = true; public boolean variableBufferEnabled = true;
// -------------------------------------------- // // -------------------------------------------- //
// CLICK // CLICK
// -------------------------------------------- // // -------------------------------------------- //
// Button click sound configuration.
public SoundEffect clickSound = SoundEffect.valueOf("UI_BUTTON_CLICK", 0.75f, 1.0f); 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 millisBetweenLocalPoll = TimeUnit.MILLIS_PER_MINUTE * 5;
public volatile long millisBetweenRemotePollWithoutPusher = TimeUnit.MILLIS_PER_SECOND * 10; public volatile long millisBetweenRemotePollWithoutPusher = TimeUnit.MILLIS_PER_SECOND * 10;
@ -116,11 +119,31 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
@EditorType(fieldName = "iOn") @EditorType(fieldName = "iOn")
public boolean warnOnLocalAlter = false; 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 // SPONSOR
// -------------------------------------------- // // -------------------------------------------- //
// URL connections to http://sponsorinfo.massivecraft.com/
public boolean sponsorEnabled = true; public boolean sponsorEnabled = true;
public long sponsorUpdateMillis = 0; public long sponsorUpdateMillis = 0;
// -------------------------------------------- //
// MCSTATS
// -------------------------------------------- //
// URL connections to http://mcstats.org/
public boolean mcstatsEnabled = true;
} }

View File

@ -57,23 +57,26 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name
// Listener // Listener
Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(this, this);
// Metrics
try
{
MetricsLite metrics = new MetricsLite(this);
metrics.start();
}
catch (IOException e)
{
String message = Txt.parse("<b>Metrics Initialization Failed :'(");
log(message);
}
return true; return true;
} }
public void postEnable() public void postEnable()
{ {
// Metrics
if (MassiveCoreMConf.get().mcstatsEnabled)
{
try
{
MetricsLite metrics = new MetricsLite(this);
metrics.start();
}
catch (IOException e)
{
String message = Txt.parse("<b>Metrics Initialization Failed :'(");
log(message);
}
}
long ms = System.currentTimeMillis() - enableTime; long ms = System.currentTimeMillis() - enableTime;
log(Txt.parse("=== ENABLE <g>COMPLETE <i>(Took <h>" + ms + "ms<i>) ===")); log(Txt.parse("=== ENABLE <g>COMPLETE <i>(Took <h>" + ms + "ms<i>) ==="));
} }
@ -84,7 +87,7 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name
if ( ! this.isVersionSynchronized()) return; if ( ! this.isVersionSynchronized()) return;
// ... and checking is enabled ... // ... and checking is enabled ...
if ( ! MassiveCoreMConf.get().checkVersionSynchronization) return; if ( ! MassiveCoreMConf.get().versionSynchronizationEnabled) return;
// ... get the version numbers ... // ... get the version numbers ...
String thisVersion = this.getDescription().getVersion(); String thisVersion = this.getDescription().getVersion();

View File

@ -146,7 +146,7 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia
List<String> ret = this.getMassiveCommand().getTabCompletions(args, sender); List<String> ret = this.getMassiveCommand().getTabCompletions(args, sender);
int retSize = ret.size(); int retSize = ret.size();
int maxSize = MassiveCoreMConf.get().maxTabCompletions; int maxSize = MassiveCoreMConf.get().tabCompletionLimit;
if (maxSize > 0 && retSize > maxSize) if (maxSize > 0 && retSize > maxSize)
{ {
Mixin.msgOne(sender, Lang.COMMAND_TOO_MANY_TAB_SUGGESTIONS, retSize); Mixin.msgOne(sender, Lang.COMMAND_TOO_MANY_TAB_SUGGESTIONS, retSize);

View File

@ -69,7 +69,7 @@ public class CmdMassiveCore extends MassiveCommand
@Override @Override
public List<String> getAliases() public List<String> getAliases()
{ {
return MassiveCoreMConf.get().aliasesOuterMassiveCore; return MassiveCoreMConf.get().aliasesMcore;
} }
} }

View File

@ -13,7 +13,7 @@ public class CmdMassiveCoreBuffer extends MassiveCommand
// INSTANCE // INSTANCE
// -------------------------------------------- // // -------------------------------------------- //
private static CmdMassiveCoreBuffer i = new CmdMassiveCoreBuffer() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreBuffer; } }; private static CmdMassiveCoreBuffer i = new CmdMassiveCoreBuffer() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesBuffer; } };
public static CmdMassiveCoreBuffer get() { return i; } public static CmdMassiveCoreBuffer get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -24,7 +24,7 @@ public class CmdMassiveCoreCmdurl extends MassiveCommand
// INSTANCE // INSTANCE
// -------------------------------------------- // // -------------------------------------------- //
private static CmdMassiveCoreCmdurl i = new CmdMassiveCoreCmdurl() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreCmdurl; } }; private static CmdMassiveCoreCmdurl i = new CmdMassiveCoreCmdurl() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesCmdurl; } };
public static CmdMassiveCoreCmdurl get() { return i; } public static CmdMassiveCoreCmdurl get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -13,7 +13,7 @@ public class CmdMassiveCoreStore extends MassiveCommand
// INSTANCE // INSTANCE
// -------------------------------------------- // // -------------------------------------------- //
private static CmdMassiveCoreStore i = new CmdMassiveCoreStore() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreStore; } }; private static CmdMassiveCoreStore i = new CmdMassiveCoreStore() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesMstore; } };
public static CmdMassiveCoreStore get() { return i; } public static CmdMassiveCoreStore get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -13,7 +13,7 @@ public class CmdMassiveCoreUsys extends MassiveCommand
// INSTANCE // INSTANCE
// -------------------------------------------- // // -------------------------------------------- //
private static CmdMassiveCoreUsys i = new CmdMassiveCoreUsys() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesOuterMassiveCoreUsys; } }; private static CmdMassiveCoreUsys i = new CmdMassiveCoreUsys() { public List<String> getAliases() { return MassiveCoreMConf.get().aliasesUsys; } };
public static CmdMassiveCoreUsys get() { return i; } public static CmdMassiveCoreUsys get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -54,7 +54,7 @@ public class EngineMassiveCoreMain extends Engine
public void recipientChat(final AsyncPlayerChatEvent event) public void recipientChat(final AsyncPlayerChatEvent event)
{ {
// Return unless we are using the recipient chat event // Return unless we are using the recipient chat event
if (!MassiveCoreMConf.get().usingRecipientChatEvent) return; if ( ! MassiveCoreMConf.get().recipientChatEventEnabled) return;
// Prepare vars // Prepare vars
EventMassiveCorePlayerToRecipientChat recipientEvent; EventMassiveCorePlayerToRecipientChat recipientEvent;

View File

@ -63,6 +63,10 @@ public class EngineMassiveCoreSponsor extends Engine
@Override @Override
public void run() public void run()
{ {
// If enabled by mconf ...
if ( ! MassiveCoreMConf.get().sponsorEnabled) return;
// ... update sponsor info.
MassiveCoreMSponsorInfo.update(); MassiveCoreMSponsorInfo.update();
} }

View File

@ -13,13 +13,13 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import com.massivecraft.massivecore.Engine; import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.MassiveCoreMConf; import com.massivecraft.massivecore.MassiveCoreMConf;
import com.massivecraft.massivecore.MassiveCorePerm; import com.massivecraft.massivecore.MassiveCorePerm;
import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.InventoryUtil;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
@ -67,35 +67,20 @@ public class EngineMassiveCoreVariable extends Engine
public static String getBookText(CommandSender sender) 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; HumanEntity human = (HumanEntity)sender;
ItemStack item = InventoryUtil.getWeapon(human);
PlayerInventory inventory = human.getInventory(); return getBookText(item);
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;
} }
public static String getBookText(ItemStack item) public static String getBookText(ItemStack item)
{ {
if (item == null) return null; if (item == null) return null;
if (!item.hasItemMeta()) return null; if ( ! item.hasItemMeta()) return null;
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();
if (!(itemMeta instanceof BookMeta)) return null; if ( ! (itemMeta instanceof BookMeta)) return null;
BookMeta bookMeta = (BookMeta)itemMeta; BookMeta bookMeta = (BookMeta)itemMeta;
if (!bookMeta.hasPages()) return null; if ( ! bookMeta.hasPages()) return null;
List<String> pages = bookMeta.getPages(); List<String> pages = bookMeta.getPages();
String ret = Txt.implode(pages, " "); String ret = Txt.implode(pages, " ");
ret = ret.replaceAll("\\n+", " "); ret = ret.replaceAll("\\n+", " ");
@ -105,17 +90,17 @@ public class EngineMassiveCoreVariable extends Engine
public static String variableBook(Player player, String message) public static String variableBook(Player player, String message)
{ {
// If we are using this variable ... // If we are using this variable ...
if (!MassiveCoreMConf.get().usingVariableBook) return message; if ( ! MassiveCoreMConf.get().variableBookEnabled) return message;
// ... get the variable content ... // ... get the variable content ...
String content = getBookText(player); String content = getBookText(player);
if (content == null) return message; if (content == null) return message;
// ... check use permission ... // ... check use permission ...
if (!MassiveCorePerm.VARIABLE_BOOK.has(player, false)) return message; if ( ! MassiveCorePerm.VARIABLE_BOOK.has(player, false)) return message;
// ... and replace. // ... 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) public static String variableBuffer(Player player, String message)
{ {
// If we are using this variable ... // If we are using this variable ...
if (!MassiveCoreMConf.get().usingVariableBuffer) return message; if ( ! MassiveCoreMConf.get().variableBufferEnabled) return message;
// ... get the variable content ... // ... get the variable content ...
String content = getBuffer(player); String content = getBuffer(player);
if (content == null) return message; if (content == null) return message;
// ... check use permission ... // ... check use permission ...
if (!MassiveCorePerm.VARIABLE_BUFFER.has(player, false)) return message; if ( ! MassiveCorePerm.VARIABLE_BUFFER.has(player, false)) return message;
// ... and replace. // ... and replace.
return StringUtils.replace(message, MassiveCoreMConf.get().variableBuffer, content); return StringUtils.replace(message, MassiveCoreMConf.get().variableBufferName, content);
} }
} }