Added /gpreload.
Reloads configuration settings, but doesn't totally restart the plugin. If the server owner has updated the JAR, then either /reload or server reboot is still necessary.
This commit is contained in:
parent
4c6b215407
commit
a1dd7a7792
|
|
@ -133,6 +133,10 @@ commands:
|
|||
description: Toggles whether a player's messages will only reach other soft-muted players.
|
||||
usage: /SoftMute <player>
|
||||
permission: griefprevention.softmute
|
||||
gpreload:
|
||||
description: Reloads Grief Prevention's configuration settings. Does NOT totally reload the entire plugin.
|
||||
usage: /gpreload
|
||||
permission: griefprevention.reload
|
||||
permissions:
|
||||
griefprevention.createclaims:
|
||||
description: Grants permission to create claims.
|
||||
|
|
@ -151,6 +155,7 @@ permissions:
|
|||
griefprevention.eavesdrop: true
|
||||
griefprevention.deathblow: true
|
||||
griefprevention.softmute: true
|
||||
griefprevention.reload: true
|
||||
griefprevention.restorenature:
|
||||
description: Grants permission to use /RestoreNature.
|
||||
default: op
|
||||
|
|
@ -181,6 +186,9 @@ permissions:
|
|||
griefprevention.deathblow:
|
||||
description: Grants access to /DeathBlow.
|
||||
default: op
|
||||
griefprevention.reload:
|
||||
description: Grants access to /gpreload.
|
||||
default: op
|
||||
griefprevention.softmute:
|
||||
description: Grants access to /SoftMute.
|
||||
default: op
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class GriefPrevention extends JavaPlugin
|
|||
//configuration variables, loaded/saved from a config.yml
|
||||
|
||||
//claim mode for each world
|
||||
public ConcurrentHashMap<World, ClaimsMode> config_claims_worldModes = new ConcurrentHashMap<World, ClaimsMode>();
|
||||
public ConcurrentHashMap<World, ClaimsMode> config_claims_worldModes;
|
||||
|
||||
public boolean config_claims_preventTheft; //whether containers and crafting blocks are protectable
|
||||
public boolean config_claims_protectCreatures; //whether claimed animals may be injured by players without permission
|
||||
|
|
@ -149,6 +149,10 @@ public class GriefPrevention extends JavaPlugin
|
|||
public boolean config_limitTreeGrowth; //whether trees should be prevented from growing into a claim from outside
|
||||
public boolean config_pistonsInClaimsOnly; //whether pistons are limited to only move blocks located within the piston's land claim
|
||||
|
||||
private String databaseUrl;
|
||||
private String databaseUserName;
|
||||
private String databasePassword;
|
||||
|
||||
//reference to the economy plugin, if economy integration is enabled
|
||||
public static Economy economy = null;
|
||||
|
||||
|
|
@ -171,6 +175,138 @@ public class GriefPrevention extends JavaPlugin
|
|||
|
||||
instance = this;
|
||||
|
||||
this.loadConfig();
|
||||
|
||||
AddLogEntry("Finished loading configuration.");
|
||||
|
||||
//when datastore initializes, it loads player and claim data, and posts some stats to the log
|
||||
if(this.databaseUrl.length() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
DatabaseDataStore databaseStore = new DatabaseDataStore(this.databaseUrl, this.databaseUserName, this.databasePassword);
|
||||
|
||||
if(FlatFileDataStore.hasData())
|
||||
{
|
||||
GriefPrevention.AddLogEntry("There appears to be some data on the hard drive. Migrating those data to the database...");
|
||||
FlatFileDataStore flatFileStore = new FlatFileDataStore();
|
||||
flatFileStore.migrateData(databaseStore);
|
||||
GriefPrevention.AddLogEntry("Data migration process complete. Reloading data from the database...");
|
||||
databaseStore.close();
|
||||
databaseStore = new DatabaseDataStore(this.databaseUrl, this.databaseUserName, this.databasePassword);
|
||||
}
|
||||
|
||||
this.dataStore = databaseStore;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Because there was a problem with the database, GriefPrevention will not function properly. Either update the database config settings resolve the issue, or delete those lines from your config.yml so that GriefPrevention can use the file system to store data.");
|
||||
GriefPrevention.AddLogEntry(e.getMessage());
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//if not using the database because it's not configured or because there was a problem, use the file system to store data
|
||||
//this is the preferred method, as it's simpler than the database scenario
|
||||
if(this.dataStore == null)
|
||||
{
|
||||
File oldclaimdata = new File(getDataFolder(), "ClaimData");
|
||||
if(oldclaimdata.exists()) {
|
||||
if(!FlatFileDataStore.hasData()) {
|
||||
File claimdata = new File("plugins" + File.separator + "GriefPreventionData" + File.separator + "ClaimData");
|
||||
oldclaimdata.renameTo(claimdata);
|
||||
File oldplayerdata = new File(getDataFolder(), "PlayerData");
|
||||
File playerdata = new File("plugins" + File.separator + "GriefPreventionData" + File.separator + "PlayerData");
|
||||
oldplayerdata.renameTo(playerdata);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
this.dataStore = new FlatFileDataStore();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to initialize the file system data store. Details:");
|
||||
GriefPrevention.AddLogEntry(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
String dataMode = (this.dataStore instanceof FlatFileDataStore)?"(File Mode)":"(Database Mode)";
|
||||
AddLogEntry("Finished loading data " + dataMode + ".");
|
||||
|
||||
//unless claim block accrual is disabled, start the recurring per 5 minute event to give claim blocks to online players
|
||||
//20L ~ 1 second
|
||||
if(this.config_claims_blocksAccruedPerHour > 0)
|
||||
{
|
||||
DeliverClaimBlocksTask task = new DeliverClaimBlocksTask();
|
||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task, 20L * 60 * 5, 20L * 60 * 5);
|
||||
}
|
||||
|
||||
//start the recurring cleanup event for entities in creative worlds
|
||||
EntityCleanupTask task = new EntityCleanupTask(0);
|
||||
this.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, task, 20L);
|
||||
|
||||
//start recurring cleanup scan for unused claims belonging to inactive players
|
||||
CleanupUnusedClaimsTask task2 = new CleanupUnusedClaimsTask();
|
||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task2, 20L * 60 * 2, 20L * 60 * 5);
|
||||
|
||||
//register for events
|
||||
PluginManager pluginManager = this.getServer().getPluginManager();
|
||||
|
||||
//player events
|
||||
PlayerEventHandler playerEventHandler = new PlayerEventHandler(this.dataStore, this);
|
||||
pluginManager.registerEvents(playerEventHandler, this);
|
||||
|
||||
//block events
|
||||
BlockEventHandler blockEventHandler = new BlockEventHandler(this.dataStore);
|
||||
pluginManager.registerEvents(blockEventHandler, this);
|
||||
|
||||
//entity events
|
||||
EntityEventHandler entityEventHandler = new EntityEventHandler(this.dataStore);
|
||||
pluginManager.registerEvents(entityEventHandler, this);
|
||||
|
||||
//if economy is enabled
|
||||
if(this.config_economy_claimBlocksPurchaseCost > 0 || this.config_economy_claimBlocksSellValue > 0)
|
||||
{
|
||||
//try to load Vault
|
||||
GriefPrevention.AddLogEntry("GriefPrevention requires Vault for economy integration.");
|
||||
GriefPrevention.AddLogEntry("Attempting to load Vault...");
|
||||
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
GriefPrevention.AddLogEntry("Vault loaded successfully!");
|
||||
|
||||
//ask Vault to hook into an economy plugin
|
||||
GriefPrevention.AddLogEntry("Looking for a Vault-compatible economy plugin...");
|
||||
if (economyProvider != null)
|
||||
{
|
||||
GriefPrevention.economy = economyProvider.getProvider();
|
||||
|
||||
//on success, display success message
|
||||
if(GriefPrevention.economy != null)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Hooked into economy: " + GriefPrevention.economy.getName() + ".");
|
||||
GriefPrevention.AddLogEntry("Ready to buy/sell claim blocks!");
|
||||
}
|
||||
|
||||
//otherwise error message
|
||||
else
|
||||
{
|
||||
GriefPrevention.AddLogEntry("ERROR: Vault was unable to find a supported economy plugin. Either install a Vault-compatible economy plugin, or set both of the economy config variables to zero.");
|
||||
}
|
||||
}
|
||||
|
||||
//another error case
|
||||
else
|
||||
{
|
||||
GriefPrevention.AddLogEntry("ERROR: Vault was unable to find a supported economy plugin. Either install a Vault-compatible economy plugin, or set both of the economy config variables to zero.");
|
||||
}
|
||||
}
|
||||
|
||||
AddLogEntry("Boot finished.");
|
||||
}
|
||||
|
||||
private void loadConfig()
|
||||
{
|
||||
//load the config if it exists
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(DataStore.configFilePath));
|
||||
FileConfiguration outConfig = new YamlConfiguration();
|
||||
|
|
@ -207,6 +343,7 @@ public class GriefPrevention extends JavaPlugin
|
|||
}
|
||||
|
||||
//decide claim mode for each world
|
||||
this.config_claims_worldModes = new ConcurrentHashMap<World, ClaimsMode>();
|
||||
for(World world : worlds)
|
||||
{
|
||||
//is it specified in the config file?
|
||||
|
|
@ -550,9 +687,9 @@ public class GriefPrevention extends JavaPlugin
|
|||
this.config_pvp_noCombatInAdminLandClaims = config.getBoolean("GriefPrevention.PvP.ProtectPlayersInLandClaims.AdministrativeClaims", this.config_siege_enabledWorlds.size() == 0);
|
||||
|
||||
//optional database settings
|
||||
String databaseUrl = config.getString("GriefPrevention.Database.URL", "");
|
||||
String databaseUserName = config.getString("GriefPrevention.Database.UserName", "");
|
||||
String databasePassword = config.getString("GriefPrevention.Database.Password", "");
|
||||
this.databaseUrl = config.getString("GriefPrevention.Database.URL", "");
|
||||
this.databaseUserName = config.getString("GriefPrevention.Database.UserName", "");
|
||||
this.databasePassword = config.getString("GriefPrevention.Database.Password", "");
|
||||
|
||||
//claims mode by world
|
||||
for(World world : this.config_claims_worldModes.keySet())
|
||||
|
|
@ -630,9 +767,9 @@ public class GriefPrevention extends JavaPlugin
|
|||
outConfig.set("GriefPrevention.CreaturesTrampleCrops", this.config_creaturesTrampleCrops);
|
||||
outConfig.set("GriefPrevention.HardModeZombiesBreakDoors", this.config_zombiesBreakDoors);
|
||||
|
||||
outConfig.set("GriefPrevention.Database.URL", databaseUrl);
|
||||
outConfig.set("GriefPrevention.Database.UserName", databaseUserName);
|
||||
outConfig.set("GriefPrevention.Database.Password", databasePassword);
|
||||
outConfig.set("GriefPrevention.Database.URL", this.databaseUrl);
|
||||
outConfig.set("GriefPrevention.Database.UserName", this.databaseUserName);
|
||||
outConfig.set("GriefPrevention.Database.Password", this.databasePassword);
|
||||
|
||||
outConfig.set("GriefPrevention.Mods.BlockIdsRequiringAccessTrust", this.config_mods_accessTrustIds);
|
||||
outConfig.set("GriefPrevention.Mods.BlockIdsRequiringContainerTrust", this.config_mods_containerTrustIds);
|
||||
|
|
@ -674,133 +811,6 @@ public class GriefPrevention extends JavaPlugin
|
|||
{
|
||||
this.config_pvp_blockedCommands.add(commands[i].trim());
|
||||
}
|
||||
|
||||
AddLogEntry("Finished loading configuration.");
|
||||
|
||||
//when datastore initializes, it loads player and claim data, and posts some stats to the log
|
||||
if(databaseUrl.length() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
DatabaseDataStore databaseStore = new DatabaseDataStore(databaseUrl, databaseUserName, databasePassword);
|
||||
|
||||
if(FlatFileDataStore.hasData())
|
||||
{
|
||||
GriefPrevention.AddLogEntry("There appears to be some data on the hard drive. Migrating those data to the database...");
|
||||
FlatFileDataStore flatFileStore = new FlatFileDataStore();
|
||||
flatFileStore.migrateData(databaseStore);
|
||||
GriefPrevention.AddLogEntry("Data migration process complete. Reloading data from the database...");
|
||||
databaseStore.close();
|
||||
databaseStore = new DatabaseDataStore(databaseUrl, databaseUserName, databasePassword);
|
||||
}
|
||||
|
||||
this.dataStore = databaseStore;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Because there was a problem with the database, GriefPrevention will not function properly. Either update the database config settings resolve the issue, or delete those lines from your config.yml so that GriefPrevention can use the file system to store data.");
|
||||
GriefPrevention.AddLogEntry(e.getMessage());
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//if not using the database because it's not configured or because there was a problem, use the file system to store data
|
||||
//this is the preferred method, as it's simpler than the database scenario
|
||||
if(this.dataStore == null)
|
||||
{
|
||||
File oldclaimdata = new File(getDataFolder(), "ClaimData");
|
||||
if(oldclaimdata.exists()) {
|
||||
if(!FlatFileDataStore.hasData()) {
|
||||
File claimdata = new File("plugins" + File.separator + "GriefPreventionData" + File.separator + "ClaimData");
|
||||
oldclaimdata.renameTo(claimdata);
|
||||
File oldplayerdata = new File(getDataFolder(), "PlayerData");
|
||||
File playerdata = new File("plugins" + File.separator + "GriefPreventionData" + File.separator + "PlayerData");
|
||||
oldplayerdata.renameTo(playerdata);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
this.dataStore = new FlatFileDataStore();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to initialize the file system data store. Details:");
|
||||
GriefPrevention.AddLogEntry(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
String dataMode = (this.dataStore instanceof FlatFileDataStore)?"(File Mode)":"(Database Mode)";
|
||||
AddLogEntry("Finished loading data " + dataMode + ".");
|
||||
|
||||
//unless claim block accrual is disabled, start the recurring per 5 minute event to give claim blocks to online players
|
||||
//20L ~ 1 second
|
||||
if(this.config_claims_blocksAccruedPerHour > 0)
|
||||
{
|
||||
DeliverClaimBlocksTask task = new DeliverClaimBlocksTask();
|
||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task, 20L * 60 * 5, 20L * 60 * 5);
|
||||
}
|
||||
|
||||
//start the recurring cleanup event for entities in creative worlds
|
||||
EntityCleanupTask task = new EntityCleanupTask(0);
|
||||
this.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, task, 20L);
|
||||
|
||||
//start recurring cleanup scan for unused claims belonging to inactive players
|
||||
CleanupUnusedClaimsTask task2 = new CleanupUnusedClaimsTask();
|
||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task2, 20L * 60 * 2, 20L * 60 * 5);
|
||||
|
||||
//register for events
|
||||
PluginManager pluginManager = this.getServer().getPluginManager();
|
||||
|
||||
//player events
|
||||
PlayerEventHandler playerEventHandler = new PlayerEventHandler(this.dataStore, this);
|
||||
pluginManager.registerEvents(playerEventHandler, this);
|
||||
|
||||
//block events
|
||||
BlockEventHandler blockEventHandler = new BlockEventHandler(this.dataStore);
|
||||
pluginManager.registerEvents(blockEventHandler, this);
|
||||
|
||||
//entity events
|
||||
EntityEventHandler entityEventHandler = new EntityEventHandler(this.dataStore);
|
||||
pluginManager.registerEvents(entityEventHandler, this);
|
||||
|
||||
//if economy is enabled
|
||||
if(this.config_economy_claimBlocksPurchaseCost > 0 || this.config_economy_claimBlocksSellValue > 0)
|
||||
{
|
||||
//try to load Vault
|
||||
GriefPrevention.AddLogEntry("GriefPrevention requires Vault for economy integration.");
|
||||
GriefPrevention.AddLogEntry("Attempting to load Vault...");
|
||||
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
GriefPrevention.AddLogEntry("Vault loaded successfully!");
|
||||
|
||||
//ask Vault to hook into an economy plugin
|
||||
GriefPrevention.AddLogEntry("Looking for a Vault-compatible economy plugin...");
|
||||
if (economyProvider != null)
|
||||
{
|
||||
GriefPrevention.economy = economyProvider.getProvider();
|
||||
|
||||
//on success, display success message
|
||||
if(GriefPrevention.economy != null)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Hooked into economy: " + GriefPrevention.economy.getName() + ".");
|
||||
GriefPrevention.AddLogEntry("Ready to buy/sell claim blocks!");
|
||||
}
|
||||
|
||||
//otherwise error message
|
||||
else
|
||||
{
|
||||
GriefPrevention.AddLogEntry("ERROR: Vault was unable to find a supported economy plugin. Either install a Vault-compatible economy plugin, or set both of the economy config variables to zero.");
|
||||
}
|
||||
}
|
||||
|
||||
//another error case
|
||||
else
|
||||
{
|
||||
GriefPrevention.AddLogEntry("ERROR: Vault was unable to find a supported economy plugin. Either install a Vault-compatible economy plugin, or set both of the economy config variables to zero.");
|
||||
}
|
||||
}
|
||||
|
||||
AddLogEntry("Boot finished.");
|
||||
}
|
||||
|
||||
private ClaimsMode configStringToClaimsMode(String configSetting)
|
||||
|
|
@ -1937,6 +1947,21 @@ public class GriefPrevention extends JavaPlugin
|
|||
return true;
|
||||
}
|
||||
|
||||
else if(cmd.getName().equalsIgnoreCase("gpreload"))
|
||||
{
|
||||
this.reloadConfig();
|
||||
if(player != null)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Success, "Configuration updated. If you have updated your Grief Prevention JAR, you still need to /reload or reboot your server.");
|
||||
}
|
||||
else
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Configuration updated. If you have updated your Grief Prevention JAR, you still need to /reload or reboot your server.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user