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; }
// -------------------------------------------- //
// 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 boolean versionSynchronizationEnabled = true;
public int tabCompletionLimit = 100;
public boolean recipientChatEventEnabled = true;
public boolean checkVersionSynchronization = true;
public int maxTabCompletions = 100;
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;
// -------------------------------------------- //
// PERMISSIONS FORMATS
// -------------------------------------------- //
// Permission denied formatting.
public Map<String, String> permissionDeniedFormats = MUtil.map(
"some.awesome.permission.node", "<b>You must be awesome to %s<b>.",
@ -57,6 +65,11 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
return ret;
}
// -------------------------------------------- //
// TP DELAY
// -------------------------------------------- //
// Teleportation delay permissions.
public Map<String, Integer> permissionToTpdelay = MUtil.map(
"massivecore.notpdelay", 0,
"default", 10
@ -69,45 +82,35 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
return ret;
}
// -------------------------------------------- //
// DELETE FILES
// -------------------------------------------- //
// Delete certain files for system cleanliness.
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
// -------------------------------------------- //
// 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<MassiveCoreMConf>
@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;
}

View File

@ -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("<b>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("<b>Metrics Initialization Failed :'(");
log(message);
}
}
long ms = System.currentTimeMillis() - enableTime;
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;
// ... and checking is enabled ...
if ( ! MassiveCoreMConf.get().checkVersionSynchronization) return;
if ( ! MassiveCoreMConf.get().versionSynchronizationEnabled) return;
// ... get the version numbers ...
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);
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);

View File

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

View File

@ -13,7 +13,7 @@ public class CmdMassiveCoreBuffer extends MassiveCommand
// 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; }
// -------------------------------------------- //

View File

@ -24,7 +24,7 @@ public class CmdMassiveCoreCmdurl extends MassiveCommand
// 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; }
// -------------------------------------------- //

View File

@ -13,7 +13,7 @@ public class CmdMassiveCoreStore extends MassiveCommand
// 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; }
// -------------------------------------------- //

View File

@ -13,7 +13,7 @@ public class CmdMassiveCoreUsys extends MassiveCommand
// 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; }
// -------------------------------------------- //

View File

@ -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;

View File

@ -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();
}

View File

@ -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<String> 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);
}
}