/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java
Java | 812 lines | 601 code | 125 blank | 86 comment | 75 complexity | 2cfef57ae14d2cd226f5ecf73b2293a3 MD5 | raw file
- /*
- GriefPrevention Server Plugin for Minecraft
- Copyright (C) 2012 Ryan Hamshire
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package me.ryanhamshire.GriefPrevention;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map.Entry;
- import java.util.UUID;
- import java.util.Vector;
- import java.util.concurrent.ConcurrentHashMap;
- import java.util.logging.Logger;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException;
- import net.milkbowl.vault.economy.Economy;
- import org.bukkit.Achievement;
- import org.bukkit.BanList;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Chunk;
- import org.bukkit.ChunkSnapshot;
- import org.bukkit.GameMode;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.World;
- import org.bukkit.BanList.Type;
- import org.bukkit.World.Environment;
- import org.bukkit.block.Block;
- import org.bukkit.block.BlockFace;
- import org.bukkit.command.*;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.PlayerInventory;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.RegisteredServiceProvider;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.util.BlockIterator;
- public class GriefPrevention extends JavaPlugin
- {
- //for convenience, a reference to the instance of this plugin
- public static GriefPrevention instance;
-
- //for logging to the console and log file
- private static Logger log = Logger.getLogger("Minecraft");
-
- //this handles data storage, like player and region data
- public DataStore dataStore;
-
- //this tracks item stacks expected to drop which will need protection
- ArrayList<PendingItemProtection> pendingItemWatchList = new ArrayList<PendingItemProtection>();
-
- //log entry manager for GP's custom log files
- CustomLogger customLogger;
-
- //configuration variables, loaded/saved from a config.yml
-
- //claim mode for each world
- 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
- public boolean config_claims_protectFires; //whether open flint+steel flames should be protected - optional because it's expensive
- public boolean config_claims_protectHorses; //whether horses on a claim should be protected by that claim's rules
- public boolean config_claims_preventButtonsSwitches; //whether buttons and switches are protectable
- public boolean config_claims_lockWoodenDoors; //whether wooden doors should be locked by default (require /accesstrust)
- public boolean config_claims_lockTrapDoors; //whether trap doors should be locked by default (require /accesstrust)
- public boolean config_claims_lockFenceGates; //whether fence gates should be locked by default (require /accesstrust)
- public boolean config_claims_enderPearlsRequireAccessTrust; //whether teleporting into a claim with a pearl requires access trust
- public int config_claims_maxClaimsPerPlayer; //maximum number of claims per player
- public boolean config_claims_respectWorldGuard; //whether claim creations requires WG build permission in creation area
- public boolean config_claims_portalsRequirePermission; //whether nether portals require permission to generate. defaults to off for performance reasons
- public boolean config_claims_villagerTradingRequiresTrust; //whether trading with a claimed villager requires permission
-
- public int config_claims_initialBlocks; //the number of claim blocks a new player starts with
- public double config_claims_abandonReturnRatio; //the portion of claim blocks returned to a player when a claim is abandoned
- public int config_claims_blocksAccruedPerHour; //how many additional blocks players get each hour of play (can be zero)
- public int config_claims_maxAccruedBlocks; //the limit on accrued blocks (over time). doesn't limit purchased or admin-gifted blocks
- public int config_claims_maxDepth; //limit on how deep claims can go
- public int config_claims_expirationDays; //how many days of inactivity before a player loses his claims
- public int config_claims_expirationExemptionTotalBlocks; //total claim blocks amount which will exempt a player from claim expiration
- public int config_claims_expirationExemptionBonusBlocks; //bonus claim blocks amount which will exempt a player from claim expiration
-
- public int config_claims_automaticClaimsForNewPlayersRadius; //how big automatic new player claims (when they place a chest) should be. 0 to disable
- public int config_claims_claimsExtendIntoGroundDistance; //how far below the shoveled block a new claim will reach
- public int config_claims_minWidth; //minimum width for non-admin claims
- public int config_claims_minArea; //minimum area for non-admin claims
-
- public int config_claims_chestClaimExpirationDays; //number of days of inactivity before an automatic chest claim will be deleted
- public int config_claims_unusedClaimExpirationDays; //number of days of inactivity before an unused (nothing build) claim will be deleted
- public boolean config_claims_survivalAutoNatureRestoration; //whether survival claims will be automatically restored to nature when auto-deleted
-
- public Material config_claims_investigationTool; //which material will be used to investigate claims with a right click
- public Material config_claims_modificationTool; //which material will be used to create/resize claims with a right click
-
- public ArrayList<String> config_claims_commandsRequiringAccessTrust; //the list of slash commands requiring access trust when in a claim
- public boolean config_claims_supplyPlayerManual; //whether to give new players a book with land claim help in it
- public int config_claims_manualDeliveryDelaySeconds; //how long to wait before giving a book to a new player
-
- public ArrayList<World> config_siege_enabledWorlds; //whether or not /siege is enabled on this server
- public ArrayList<Material> config_siege_blocks; //which blocks will be breakable in siege mode
-
- public boolean config_spam_enabled; //whether or not to monitor for spam
- public int config_spam_loginCooldownSeconds; //how long players must wait between logins. combats login spam.
- public ArrayList<String> config_spam_monitorSlashCommands; //the list of slash commands monitored for spam
- public boolean config_spam_banOffenders; //whether or not to ban spammers automatically
- public String config_spam_banMessage; //message to show an automatically banned player
- public String config_spam_warningMessage; //message to show a player who is close to spam level
- public String config_spam_allowedIpAddresses; //IP addresses which will not be censored
- public int config_spam_deathMessageCooldownSeconds; //cooldown period for death messages (per player) in seconds
-
- HashMap<World, Boolean> config_pvp_specifiedWorlds; //list of worlds where pvp anti-grief rules apply, according to the config file
- public boolean config_pvp_protectFreshSpawns; //whether to make newly spawned players immune until they pick up an item
- public boolean config_pvp_punishLogout; //whether to kill players who log out during PvP combat
- public int config_pvp_combatTimeoutSeconds; //how long combat is considered to continue after the most recent damage
- public boolean config_pvp_allowCombatItemDrop; //whether a player can drop items during combat to hide them
- public ArrayList<String> config_pvp_blockedCommands; //list of commands which may not be used during pvp combat
- public boolean config_pvp_noCombatInPlayerLandClaims; //whether players may fight in player-owned land claims
- public boolean config_pvp_noCombatInAdminLandClaims; //whether players may fight in admin-owned land claims
- public boolean config_pvp_noCombatInAdminSubdivisions; //whether players may fight in subdivisions of admin-owned land claims
- public boolean config_pvp_allowLavaNearPlayers; //whether players may dump lava near other players in pvp worlds
- public boolean config_pvp_allowFireNearPlayers; //whether players may start flint/steel fires near other players in pvp worlds
- public boolean config_pvp_protectPets; //whether players may damage pets outside of land claims in pvp worlds
-
- public boolean config_lockDeathDropsInPvpWorlds; //whether players' dropped on death items are protected in pvp worlds
- public boolean config_lockDeathDropsInNonPvpWorlds; //whether players' dropped on death items are protected in non-pvp worlds
-
- public double config_economy_claimBlocksPurchaseCost; //cost to purchase a claim block. set to zero to disable purchase.
- public double config_economy_claimBlocksSellValue; //return on a sold claim block. set to zero to disable sale.
-
- public boolean config_blockClaimExplosions; //whether explosions may destroy claimed blocks
- public boolean config_blockSurfaceCreeperExplosions; //whether creeper explosions near or above the surface destroy blocks
- public boolean config_blockSurfaceOtherExplosions; //whether non-creeper explosions near or above the surface destroy blocks
- public boolean config_blockSkyTrees; //whether players can build trees on platforms in the sky
-
- public boolean config_fireSpreads; //whether fire spreads outside of claims
- public boolean config_fireDestroys; //whether fire destroys blocks outside of claims
-
- public boolean config_whisperNotifications; //whether whispered messages will broadcast to administrators in game
- public boolean config_signNotifications; //whether sign content will broadcast to administrators in game
- public ArrayList<String> config_eavesdrop_whisperCommands; //list of whisper commands to eavesdrop on
-
- public boolean config_smartBan; //whether to ban accounts which very likely owned by a banned player
-
- public boolean config_endermenMoveBlocks; //whether or not endermen may move blocks around
- public boolean config_silverfishBreakBlocks; //whether silverfish may break blocks
- public boolean config_creaturesTrampleCrops; //whether or not non-player entities may trample crops
- public boolean config_rabbitsEatCrops; //whether or not rabbits may eat crops
- public boolean config_zombiesBreakDoors; //whether or not hard-mode zombies may break down wooden doors
-
- public int config_ipLimit; //how many players can share an IP address
-
- public MaterialCollection config_mods_accessTrustIds; //list of block IDs which should require /accesstrust for player interaction
- public MaterialCollection config_mods_containerTrustIds; //list of block IDs which should require /containertrust for player interaction
- public List<String> config_mods_ignoreClaimsAccounts; //list of player names which ALWAYS ignore claims
- public MaterialCollection config_mods_explodableIds; //list of block IDs which can be destroyed by explosions, even in claimed areas
- public HashMap<String, Integer> config_seaLevelOverride; //override for sea level, because bukkit doesn't report the right value for all situations
-
- 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
-
- //custom log settings
- public int config_logs_daysToKeep;
- public boolean config_logs_socialEnabled;
- public boolean config_logs_suspiciousEnabled;
- public boolean config_logs_adminEnabled;
- public boolean config_logs_debugEnabled;
- public boolean config_logs_mutedChatEnabled;
-
- //ban management plugin interop settings
- public boolean config_ban_useCommand;
- public String config_ban_commandFormat;
-
- private String databaseUrl;
- private String databaseUserName;
- private String databasePassword;
-
- //reference to the economy plugin, if economy integration is enabled
- public static Economy economy = null;
-
- //how far away to search from a tree trunk for its branch blocks
- public static final int TREE_RADIUS = 5;
-
- //how long to wait before deciding a player is staying online or staying offline, for notication messages
- public static final int NOTIFICATION_SECONDS = 20;
-
- //adds a server log entry
- public static synchronized void AddLogEntry(String entry, CustomLogEntryTypes customLogType, boolean excludeFromServerLogs)
- {
- if(customLogType != null && GriefPrevention.instance.customLogger != null)
- {
- GriefPrevention.instance.customLogger.AddEntry(entry, customLogType);
- }
- if(!excludeFromServerLogs) log.info("GriefPrevention: " + entry);
- }
-
- public static synchronized void AddLogEntry(String entry, CustomLogEntryTypes customLogType)
- {
- AddLogEntry(entry, customLogType, false);
- }
-
- public static synchronized void AddLogEntry(String entry)
- {
- AddLogEntry(entry, CustomLogEntryTypes.Debug);
- }
-
- //initializes well... everything
- public void onEnable()
- {
- instance = this;
-
- AddLogEntry("Grief Prevention boot start.");
-
- this.loadConfig();
-
- this.customLogger = new CustomLogger();
-
- 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();
- this.dataStore = flatFileStore;
- 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.");
- 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());
- e.printStackTrace();
- }
- }
-
- 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 10 minute event to give claim blocks to online players
- //20L ~ 1 second
- if(this.config_claims_blocksAccruedPerHour > 0)
- {
- DeliverClaimBlocksTask task = new DeliverClaimBlocksTask(null);
- this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task, 20L * 60 * 10, 20L * 60 * 10);
- }
-
- //start the recurring cleanup event for entities in creative worlds
- EntityCleanupTask task = new EntityCleanupTask(0);
- this.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, task, 20L * 60 * 2);
-
- //start recurring cleanup scan for unused claims belonging to inactive players
- FindUnusedClaimsTask task2 = new FindUnusedClaimsTask();
- this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task2, 20L * 60, 20L * 60);
-
- //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.");
- }
- }
-
- //cache offline players
- OfflinePlayer [] offlinePlayers = this.getServer().getOfflinePlayers();
- CacheOfflinePlayerNamesThread namesThread = new CacheOfflinePlayerNamesThread(offlinePlayers, this.playerNameToIDMap);
- namesThread.setPriority(Thread.MIN_PRIORITY);
- namesThread.start();
-
- //load ignore lists for any already-online players
- @SuppressWarnings("unchecked")
- Collection<Player> players = (Collection<Player>)GriefPrevention.instance.getServer().getOnlinePlayers();
- for(Player player : players)
- {
- new IgnoreLoaderThread(player.getUniqueId(), this.dataStore.getPlayerData(player.getUniqueId()).ignoredPlayers).start();
- }
-
- AddLogEntry("Boot finished.");
- }
-
- private void loadConfig()
- {
- //load the config if it exists
- FileConfiguration config = YamlConfiguration.loadConfiguration(new File(DataStore.configFilePath));
- FileConfiguration outConfig = new YamlConfiguration();
- outConfig.options().header("Default values are perfect for most servers. If you want to customize and have a question, look for the answer here first: http://dev.bukkit.org/bukkit-plugins/grief-prevention/pages/setup-and-configuration/");
-
- //read configuration settings (note defaults)
-
- //get (deprecated node) claims world names from the config file
- List<World> worlds = this.getServer().getWorlds();
- List<String> deprecated_claimsEnabledWorldNames = config.getStringList("GriefPrevention.Claims.Worlds");
-
- //validate that list
- for(int i = 0; i < deprecated_claimsEnabledWorldNames.size(); i++)
- {
- String worldName = deprecated_claimsEnabledWorldNames.get(i);
- World world = this.getServer().getWorld(worldName);
- if(world == null)
- {
- deprecated_claimsEnabledWorldNames.remove(i--);
- }
- }
-
- //get (deprecated node) creative world names from the config file
- List<String> deprecated_creativeClaimsEnabledWorldNames = config.getStringList("GriefPrevention.Claims.CreativeRulesWorlds");
-
- //validate that list
- for(int i = 0; i < deprecated_creativeClaimsEnabledWorldNames.size(); i++)
- {
- String worldName = deprecated_creativeClaimsEnabledWorldNames.get(i);
- World world = this.getServer().getWorld(worldName);
- if(world == null)
- {
- deprecated_claimsEnabledWorldNames.remove(i--);
- }
- }
-
- //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?
- String configSetting = config.getString("GriefPrevention.Claims.Mode." + world.getName());
- if(configSetting != null)
- {
- ClaimsMode claimsMode = this.configStringToClaimsMode(configSetting);
- if(claimsMode != null)
- {
- this.config_claims_worldModes.put(world, claimsMode);
- continue;
- }
- else
- {
- GriefPrevention.AddLogEntry("Error: Invalid claim mode \"" + configSetting + "\". Options are Survival, Creative, and Disabled.");
- this.config_claims_worldModes.put(world, ClaimsMode.Creative);
- }
- }
-
- //was it specified in a deprecated config node?
- if(deprecated_creativeClaimsEnabledWorldNames.contains(world.getName()))
- {
- this.config_claims_worldModes.put(world, ClaimsMode.Creative);
- }
-
- else if(deprecated_claimsEnabledWorldNames.contains(world.getName()))
- {
- this.config_claims_worldModes.put(world, ClaimsMode.Survival);
- }
-
- //does the world's name indicate its purpose?
- else if(world.getName().toLowerCase().contains("survival"))
- {
- this.config_claims_worldModes.put(world, ClaimsMode.Survival);
- }
-
- else if(world.getName().toLowerCase().contains("creative"))
- {
- this.config_claims_worldModes.put(world, ClaimsMode.Creative);
- }
-
- //decide a default based on server type and world type
- else if(this.getServer().getDefaultGameMode() == GameMode.CREATIVE)
- {
- this.config_claims_worldModes.put(world, ClaimsMode.Creative);
- }
-
- else if(world.getEnvironment() == Environment.NORMAL)
- {
- this.config_claims_worldModes.put(world, ClaimsMode.Survival);
- }
-
- else
- {
- this.config_claims_worldModes.put(world, ClaimsMode.Disabled);
- }
-
- //if the setting WOULD be disabled but this is a server upgrading from the old config format,
- //then default to survival mode for safety's sake (to protect any admin claims which may
- //have been created there)
- if(this.config_claims_worldModes.get(world) == ClaimsMode.Disabled &&
- deprecated_claimsEnabledWorldNames.size() > 0)
- {
- this.config_claims_worldModes.put(world, ClaimsMode.Survival);
- }
- }
-
- //pvp worlds list
- this.config_pvp_specifiedWorlds = new HashMap<World, Boolean>();
- for(World world : worlds)
- {
- boolean pvpWorld = config.getBoolean("GriefPrevention.PvP.RulesEnabledInWorld." + world.getName(), world.getPVP());
- this.config_pvp_specifiedWorlds.put(world, pvpWorld);
- }
-
- //sea level
- this.config_seaLevelOverride = new HashMap<String, Integer>();
- for(int i = 0; i < worlds.size(); i++)
- {
- int seaLevelOverride = config.getInt("GriefPrevention.SeaLevelOverrides." + worlds.get(i).getName(), -1);
- outConfig.set("GriefPrevention.SeaLevelOverrides." + worlds.get(i).getName(), seaLevelOverride);
- this.config_seaLevelOverride.put(worlds.get(i).getName(), seaLevelOverride);
- }
-
- this.config_claims_preventTheft = config.getBoolean("GriefPrevention.Claims.PreventTheft", true);
- this.config_claims_protectCreatures = config.getBoolean("GriefPrevention.Claims.ProtectCreatures", true);
- this.config_claims_protectFires = config.getBoolean("GriefPrevention.Claims.ProtectFires", false);
- this.config_claims_protectHorses = config.getBoolean("GriefPrevention.Claims.ProtectHorses", true);
- this.config_claims_preventButtonsSwitches = config.getBoolean("GriefPrevention.Claims.PreventButtonsSwitches", true);
- this.config_claims_lockWoodenDoors = config.getBoolean("GriefPrevention.Claims.LockWoodenDoors", false);
- this.config_claims_lockTrapDoors = config.getBoolean("GriefPrevention.Claims.LockTrapDoors", false);
- this.config_claims_lockFenceGates = config.getBoolean("GriefPrevention.Claims.LockFenceGates", true);
- this.config_claims_enderPearlsRequireAccessTrust = config.getBoolean("GriefPrevention.Claims.EnderPearlsRequireAccessTrust", true);
- this.config_claims_initialBlocks = config.getInt("GriefPrevention.Claims.InitialBlocks", 100);
- this.config_claims_blocksAccruedPerHour = config.getInt("GriefPrevention.Claims.BlocksAccruedPerHour", 100);
- this.config_claims_maxAccruedBlocks = config.getInt("GriefPrevention.Claims.MaxAccruedBlocks", 80000);
- this.config_claims_abandonReturnRatio = config.getDouble("GriefPrevention.Claims.AbandonReturnRatio", 1);
- this.config_claims_automaticClaimsForNewPlayersRadius = config.getInt("GriefPrevention.Claims.AutomaticNewPlayerClaimsRadius", 4);
- this.config_claims_claimsExtendIntoGroundDistance = Math.abs(config.getInt("GriefPrevention.Claims.ExtendIntoGroundDistance", 5));
- this.config_claims_minWidth = config.getInt("GriefPrevention.Claims.MinimumWidth", 5);
- this.config_claims_minArea = config.getInt("GriefPrevention.Claims.MinimumArea", 100);
- this.config_claims_maxDepth = config.getInt("GriefPrevention.Claims.MaximumDepth", 0);
- this.config_claims_chestClaimExpirationDays = config.getInt("GriefPrevention.Claims.Expiration.ChestClaimDays", 7);
- this.config_claims_unusedClaimExpirationDays = config.getInt("GriefPrevention.Claims.Expiration.UnusedClaimDays", 14);
- this.config_claims_expirationDays = config.getInt("GriefPrevention.Claims.Expiration.AllClaims.DaysInactive", 60);
- this.config_claims_expirationExemptionTotalBlocks = config.getInt("GriefPrevention.Claims.Expiration.AllClaims.ExceptWhenOwnerHasTotalClaimBlocks", 10000);
- this.config_claims_expirationExemptionBonusBlocks = config.getInt("GriefPrevention.Claims.Expiration.AllClaims.ExceptWhenOwnerHasBonusClaimBlocks", 5000);
- this.config_claims_survivalAutoNatureRestoration = config.getBoolean("GriefPrevention.Claims.Expiration.AutomaticNatureRestoration.SurvivalWorlds", false);
- this.config_claims_maxClaimsPerPlayer = config.getInt("GriefPrevention.Claims.MaximumNumberOfClaimsPerPlayer", 0);
- this.config_claims_respectWorldGuard = config.getBoolean("GriefPrevention.Claims.CreationRequiresWorldGuardBuildPermission", true);
- this.config_claims_portalsRequirePermission = config.getBoolean("GriefPrevention.Claims.PortalGenerationRequiresPermission", false);
- this.config_claims_villagerTradingRequiresTrust = config.getBoolean("GriefPrevention.Claims.VillagerTradingRequiresPermission", true);
- String accessTrustSlashCommands = config.getString("GriefPrevention.Claims.CommandsRequiringAccessTrust", "/sethome");
- this.config_claims_supplyPlayerManual = config.getBoolean("GriefPrevention.Claims.DeliverManuals", true);
- this.config_claims_manualDeliveryDelaySeconds = config.getInt("GriefPrevention.Claims.ManualDeliveryDelaySeconds", 30);
-
- this.config_spam_enabled = config.getBoolean("GriefPrevention.Spam.Enabled", true);
- this.config_spam_loginCooldownSeconds = config.getInt("GriefPrevention.Spam.LoginCooldownSeconds", 60);
- this.config_spam_warningMessage = config.getString("GriefPrevention.Spam.WarningMessage", "Please reduce your noise level. Spammers will be banned.");
- this.config_spam_allowedIpAddresses = config.getString("GriefPrevention.Spam.AllowedIpAddresses", "1.2.3.4; 5.6.7.8");
- this.config_spam_banOffenders = config.getBoolean("GriefPrevention.Spam.BanOffenders", true);
- this.config_spam_banMessage = config.getString("GriefPrevention.Spam.BanMessage", "Banned for spam.");
- String slashCommandsToMonitor = config.getString("GriefPrevention.Spam.MonitorSlashCommands", "/me;/global;/local");
- slashCommandsToMonitor = config.getString("GriefPrevention.Spam.ChatSlashCommands", slashCommandsToMonitor);
- this.config_spam_deathMessageCooldownSeconds = config.getInt("GriefPrevention.Spam.DeathMessageCooldownSeconds", 60);
-
- this.config_pvp_protectFreshSpawns = config.getBoolean("GriefPrevention.PvP.ProtectFreshSpawns", true);
- this.config_pvp_punishLogout = config.getBoolean("GriefPrevention.PvP.PunishLogout", true);
- this.config_pvp_combatTimeoutSeconds = config.getInt("GriefPrevention.PvP.CombatTimeoutSeconds", 15);
- this.config_pvp_allowCombatItemDrop = config.getBoolean("GriefPrevention.PvP.AllowCombatItemDrop", false);
- String bannedPvPCommandsList = config.getString("GriefPrevention.PvP.BlockedSlashCommands", "/home;/vanish;/spawn;/tpa");
-
- this.config_economy_claimBlocksPurchaseCost = config.getDouble("GriefPrevention.Economy.ClaimBlocksPurchaseCost", 0);
- this.config_economy_claimBlocksSellValue = config.getDouble("GriefPrevention.Economy.ClaimBlocksSellValue", 0);
-
- this.config_lockDeathDropsInPvpWorlds = config.getBoolean("GriefPrevention.ProtectItemsDroppedOnDeath.PvPWorlds", false);
- this.config_lockDeathDropsInNonPvpWorlds = config.getBoolean("GriefPrevention.ProtectItemsDroppedOnDeath.NonPvPWorlds", true);
-
- this.config_blockClaimExplosions = config.getBoolean("GriefPrevention.BlockLandClaimExplosions", true);
- this.config_blockSurfaceCreeperExplosions = config.getBoolean("GriefPrevention.BlockSurfaceCreeperExplosions", true);
- this.config_blockSurfaceOtherExplosions = config.getBoolean("GriefPrevention.BlockSurfaceOtherExplosions", true);
- this.config_blockSkyTrees = config.getBoolean("GriefPrevention.LimitSkyTrees", true);
- this.config_limitTreeGrowth = config.getBoolean("GriefPrevention.LimitTreeGrowth", false);
- this.config_pistonsInClaimsOnly = config.getBoolean("GriefPrevention.LimitPistonsToLandClaims", true);
-
- this.config_fireSpreads = config.getBoolean("GriefPrevention.FireSpreads", false);
- this.config_fireDestroys = config.getBoolean("GriefPrevention.FireDestroys", false);
-
- this.config_whisperNotifications = config.getBoolean("GriefPrevention.AdminsGetWhispers", true);
- this.config_signNotifications = config.getBoolean("GriefPrevention.AdminsGetSignNotifications", true);
- String whisperCommandsToMonitor = config.getString("GriefPrevention.WhisperCommands", "/tell;/pm;/r;/whisper;/msg");
- whisperCommandsToMonitor = config.getString("GriefPrevention.Spam.WhisperSlashCommands", whisperCommandsToMonitor);
-
- this.config_smartBan = config.getBoolean("GriefPrevention.SmartBan", true);
- this.config_ipLimit = config.getInt("GriefPrevention.MaxPlayersPerIpAddress", 3);
-
- this.config_endermenMoveBlocks = config.getBoolean("GriefPrevention.EndermenMoveBlocks", false);
- this.config_silverfishBreakBlocks = config.getBoolean("GriefPrevention.SilverfishBreakBlocks", false);
- this.config_creaturesTrampleCrops = config.getBoolean("GriefPrevention.CreaturesTrampleCrops", false);
- this.config_rabbitsEatCrops = config.getBoolean("GriefPrevention.RabbitsEatCrops", true);
- this.config_zombiesBreakDoors = config.getBoolean("GriefPrevention.HardModeZombiesBreakDoors", false);
- this.config_ban_useCommand = config.getBoolean("GriefPrevention.UseBanCommand", false);
- this.config_ban_commandFormat = config.getString("GriefPrevention.BanCommandPattern", "ban %name% %reason%");
-
- this.config_mods_ignoreClaimsAccounts = config.getStringList("GriefPrevention.Mods.PlayersIgnoringAllClaims");
-
- if(this.config_mods_ignoreClaimsAccounts == null) this.config_mods_ignoreClaimsAccounts = new ArrayList<String>();
-
- this.config_mods_accessTrustIds = new MaterialCollection();
- List<String> accessTrustStrings = config.getStringList("GriefPrevention.Mods.BlockIdsRequiringAccessTrust");
-
- this.parseMaterialListFromConfig(accessTrustStrings, this.config_mods_accessTrustIds);
-
- this.config_mods_containerTrustIds = new MaterialCollection();
- List<String> containerTrustStrings = config.getStringList("GriefPrevention.Mods.BlockIdsRequiringContainerTrust");
-
- //default values for container trust mod blocks
- if(containerTrustStrings == null || containerTrustStrings.size() == 0)
- {
- containerTrustStrings.add(new MaterialInfo(99999, "Example - ID 99999, all data values.").toString());
- }
-
- //parse the strings from the config file
- this.parseMaterialListFromConfig(containerTrustStrings, this.config_mods_containerTrustIds);
-
- this.config_mods_explodableIds = new MaterialCollection();
- List<String> explodableStrings = config.getStringList("GriefPrevention.Mods.BlockIdsExplodable");
-
- //parse the strings from the config file
- this.parseMaterialListFromConfig(explodableStrings, this.config_mods_explodableIds);
-
- //default for claim investigation tool
- String investigationToolMaterialName = Material.STICK.name();
-
- //get investigation tool from config
- investigationToolMaterialName = config.getString("GriefPrevention.Claims.InvestigationTool", investigationToolMaterialName);
-
- //validate investigation tool
- this.config_claims_investigationTool = Material.getMaterial(investigationToolMaterialName);
- if(this.config_claims_investigationTool == null)
- {
- GriefPrevention.AddLogEntry("ERROR: Material " + investigationToolMaterialName + " not found. Defaulting to the stick. Please update your config.yml.");
- this.config_claims_investigationTool = Material.STICK;
- }
-
- //default for claim creation/modification tool
- String modificationToolMaterialName = Material.GOLD_SPADE.name();
-
- //get modification tool from config
- modificationToolMaterialName = config.getString("GriefPrevention.Claims.ModificationTool", modificationToolMaterialName);
-
- //validate modification tool
- this.config_claims_modificationTool = Material.getMaterial(modificationToolMaterialName);
- if(this.config_claims_modificationTool == null)
- {
- GriefPrevention.AddLogEntry("ERROR: Material " + modificationToolMaterialName + " not found. Defaulting to the golden shovel. Please update your config.yml.");
- this.config_claims_modificationTool = Material.GOLD_SPADE;
- }
-
- //default for siege worlds list
- ArrayList<String> defaultSiegeWorldNames = new ArrayList<String>();
-
- //get siege world names from the config file
- List<String> siegeEnabledWorldNames = config.getStringList("GriefPrevention.Siege.Worlds");
- if(siegeEnabledWorldNames == null)
- {
- siegeEnabledWorldNames = defaultSiegeWorldNames;
- }
-
- //validate that list
- this.config_siege_enabledWorlds = new ArrayList<World>();
- for(int i = 0; i < siegeEnabledWorldNames.size(); i++)
- {
- String worldName = siegeEnabledWorldNames.get(i);
- World world = this.getServer().getWorld(worldName);
- if(world == null)
- {
- AddLogEntry("Error: Siege Configuration: There's no world named \"" + worldName + "\". Please update your config.yml.");
- }
- else
- {
- this.config_siege_enabledWorlds.add(world);
- }
- }
-
- //default siege blocks
- this.config_siege_blocks = new ArrayList<Material>();
- this.config_siege_blocks.add(Material.DIRT);
- this.config_siege_blocks.add(Material.GRASS);
- this.config_siege_blocks.add(Material.LONG_GRASS);
- this.config_siege_blocks.add(Material.COBBLESTONE);
- this.config_siege_blocks.add(Material.GRAVEL);
- this.config_siege_blocks.add(Material.SAND);
- this.config_siege_blocks.add(Material.GLASS);
- this.config_siege_blocks.add(Material.THIN_GLASS);
- this.config_siege_blocks.add(Material.WOOD);
- this.config_siege_blocks.add(Material.WOOL);
- this.config_siege_blocks.add(Material.SNOW);
-
- //build a default config entry
- ArrayList<String> defaultBreakableBlocksList = new ArrayList<String>();
- for(int i = 0; i < this.config_siege_blocks.size(); i++)
- {
- defaultBreakableBlocksList.add(this.config_siege_blocks.get(i).name());
- }
-
- //try to load the list from the config file
- List<String> breakableBlocksList = config.getStringList("GriefPrevention.Siege.BreakableBlocks");
-
- //if it fails, use default list instead
- if(breakableBlocksList == null || breakableBlocksList.size() == 0)
- {
- breakableBlocksList = defaultBreakableBlocksList;
- }
-
- //parse the list of siege-breakable blocks
- this.config_siege_blocks = new ArrayList<Material>();
- for(int i = 0; i < breakableBlocksList.size(); i++)
- {
- String blockName = breakableBlocksList.get(i);
- Material material = Material.getMaterial(blockName);
- if(material == null)
- {
- GriefPrevention.AddLogEntry("Siege Configuration: Material not found: " + blockName + ".");
- }
- else
- {
- this.config_siege_blocks.add(material);
- }
- }
-
- this.config_pvp_noCombatInPlayerLandClaims = config.getBoolean("GriefPrevention.PvP.ProtectPlayersInLandClaims.PlayerOwnedClaims", this.config_siege_enabledWorlds.size() == 0);
- this.config_pvp_noCombatInAdminLandClaims = config.getBoolean("GriefPrevention.PvP.ProtectPlayersInLandClaims.AdministrativeClaims", this.config_siege_enabledWorlds.size() == 0);
- this.config_pvp_noCombatInAdminSubdivisions = config.getBoolean("GriefPrevention.PvP.ProtectPlayersInLandClaims.AdministrativeSubdivisions", this.config_siege_enabledWorlds.size() == 0);
- this.config_pvp_allowLavaNearPlayers = config.getBoolean("GriefPrevention.PvP.AllowLavaDumpingNearOtherPlayers", true);
- this.config_pvp_allowFireNearPlayers = config.getBoolean("GriefPrevention.PvP.AllowFlintAndSteelNearOtherPlayers", true);
- this.config_pvp_protectPets = config.getBoolean("GriefPrevention.PvP.ProtectPetsOutsideLandClaims", false);
-
- //optional database settings
- this.databaseUrl = config.getString("GriefPrevention.Database.URL", "");
- this.databaseUserName = config.getString("GriefPrevention.Database.UserName", "");
- this.databasePassword = config.getString("GriefPrevention.Database.Password", "");
-
- //custom logger settings
- this.config_logs_daysToKeep = config.getInt("GriefPrevention.Abridged Logs.Days To Keep", 7);
- this.config_logs_socialEnabled = config.getBoolean("GriefPrevention.Abridged Logs.Included Entry Types.Social Activity", true);
- this.config_logs_suspiciousEnabled = config.getBoolean("GriefPrevention.Abridged Logs.Included Entry Types.Suspicious Activity", true);
- this.config_logs_adminEnabled = config.getBoolean("GriefPrevention.Abridged Logs.Included Entry Types.Administrative Activity", false);
- this.config_logs_debugEnabled = config.getBoolean("GriefPrevention.Abridged Logs.Included Entry Types.Debug", false);
- this.config_logs_mutedChatEnabled = config.getBoolean("GriefPrevention.Abridged Logs.Included Entry Types.Muted Chat Messages", false);
-
- //claims mode by world
- for(World world : this.config_claims_worldModes.keySet())
- {
- outConfig.set(
- "GriefPrevention.Claims.Mode." + world.getName(),
- this.config_claims_worldModes.get(world).name());
- }
-
- outConfig.set("GriefPrevention.Claims.PreventTheft", this.config_claims_preventTheft);
- outConfig.set("GriefPrevention.Claims.ProtectCreatures", this.config_claims_protectCreatures);
- outConfig.set("GriefPrevention.Claims.PreventButtonsSwitches", this.config_claims_preventButtonsSwitches);
- outConfig.set("GriefPrevention.Claims.LockWoodenDoors", this.config_claims_lockWoodenDoors);
- outConfig.set("GriefPrevention.Claims.LockTrapDoors", this.config_claims_lockTrapDoors);
- outConfig.set("GriefPrevention.Claims.LockFenceGates", this.config_claims_lockFenceGates);
- outConfig.set("GriefPrevention.Claims.EnderPearlsRequireAccessTrust", this.config_claims_enderPearlsRequireAccessTrust);
- outConfig.set("GriefPrevention.Claims.ProtectFires", this.config_claims_protectFires);
- outConfig.set("GriefPrevention.Claims.ProtectHorses", this.config_claims_protectHorses);
- outConfig.set("GriefPrevention.Claims.InitialBlocks", this.config_claims_initialBlocks);
- outConfig.set("GriefPrevention.Claims.BlocksAccruedPerHour", this.config_claims_blocksAccruedPerHour);
- outConfig.set("GriefPrevention.Claims.MaxAccruedBlocks", this.config_claims_maxAccruedBlocks);
- outConfig.set("GriefPrevention.Claims.AbandonReturnRatio", this.config_claims_abandonReturnRatio);
- outConfig.set("GriefPrevention.Claims.AutomaticNewPlayerClaimsRadius", this.config_claims_automaticClaimsForNewPlayersRadius);
- outConfig.set("GriefPrevention.Claims.ExtendIntoGroundDistance", this.config_claims_claimsExtendIntoGroundDistance);
- outConfig.set("GriefPrevention.Claims.MinimumWidth", this.config_claims_minWidth);
- outConfig.set("GriefPrevention.Claims.MinimumArea", this.config_claims_minArea);
- outConfig.set("GriefPrevention.Claims.MaximumDepth", this.config_claims_maxDepth);
- outConfig.set("GriefPrevention.Claims.InvestigationTool", this.config_claims_investigationTool.name());
- outConfig.set("GriefPrevention.Claims.ModificationTool", this.config_claims_modificationTool.name());
- outConfig.set("GriefPrevention.Claims.Expiration.ChestClaimDays", this.config_claims_chestClaimExpirationDays);
- outConfig.set("GriefPrevention.Claims.Expiration.UnusedClaimDays", this.config_claims_unusedClaimExpirationDays);
- outConfig.set("GriefPrevention.Claims.Expiration.AllClaims.DaysInactive", this.config_claims_expirationDays);
- outConfig.set("GriefPrevention.Claims.Expiration.AllClaims.ExceptWhenOwnerHasTotalClaimBlocks", this.config_claims_expirationExemptionTotalBlocks);
- outConfig.set("GriefPrevention.Claims.Expiration.AllClaims.ExceptWhenOwnerHasBonusClaimBlocks", this.config_claims_expirationExemptionBonusBlocks);
- outConfig.set("GriefPrevention.Claims.Expiration.AutomaticNatureRestoration.SurvivalWorlds", this.config_claims_survivalAutoNatureRestoration);
- outConfig.set("GriefPrevention.Claims.MaximumNumberOfClaimsPerPlayer", this.config_claims_maxClaimsPerPlayer);
- outConfig.set("GriefPrevention.Claims.CreationRequiresWorldGuardBuildPermission", this.config_claims_respectWorldGuard);
- outConfig.set("GriefPrevention.Claims.PortalGenerationRequiresPermission", this.config_claims_portalsRequirePermission);
- outConfig.set("GriefPrevention.Claims.VillagerTradingRequiresPermission", this.config_claims_villagerTradingRequiresTrust);
- outConfig.set("GriefPrevention.Claims.CommandsRequiringAccessTrust", accessTrustSlashCommands);
- outConfig.set("GriefPrevention.Claims.DeliverManuals", config_claims_supplyPlayerManual);
- outConfig.set("GriefPrevention.Claims.ManualDeliveryDelaySeconds", config_claims_manualDeliveryDelaySeconds);
-
- outConfig.set("GriefPrevention.Spam.Enabled", this.config_spam_enabled);
- outConfig.set("GriefPrevention.Spam.LoginCooldownSeconds", this.config_spam_loginCooldownSeconds);
- outConfig.set("GriefPrevention.Spam.ChatSlashCommands", slashCommandsToMonitor);
- outConfig.set("GriefPrevention.Spam.WhisperSlashCommands", whisperCommandsToMonitor);
- outConfig.set("GriefPrevention.Spam.WarningMessage", this.config_spam_warningMessage);
- outConfig.set("GriefPrevention.Spam.BanOffenders", this.config_spam_banOffenders);
- outConfig.set("GriefPrevention.Spam.BanMessage", this.config_spam_banMessage);
- outConfig.set("GriefPrevention.Spam.AllowedIpAddresses", this.config_spam_allowedIpAddresses);
- outConfig.set("GriefPrevention.Spam.DeathMessageCooldownSeconds", this.config_spam_deathMessageCooldownSeconds);
-
- for(World world : worlds)
- {
- outConfig.set("GriefPrevention.PvP.RulesEnabledInWorld." + world.getName(), this.pvpRulesApply(world));
- }
- outConfig.set("GriefPrevention.PvP.ProtectFreshSpawns", this.config_pvp_protectFreshSpawns);
- outConfig.set("GriefPrevention.PvP.PunishLogout", this.config_pvp_punishLogout);
- outConfig.set("GriefPrevention.PvP.CombatTimeoutSeconds", this.config_pvp_combatTimeoutSeconds);
- outConfig.set("GriefPrevention.PvP.AllowCombatItemDrop", this.config_pvp_allowCombatItemDrop);
- outConfig.set("GriefPrevention.PvP.BlockedSlashCommands", bannedPvPCommandsList);
- outConfig.set("GriefPrevention.PvP.ProtectPlayersInLandClaims.PlayerOwnedClaims", this.config_pvp_noCombatInPlayerLandClaims);
- outConfig.set("GriefPrevention.PvP.ProtectPlayersInLandClaims.AdministrativeClaims", this.config_pvp_noCombatInAdminLandClaims);
- outConfig.set("GriefPrevention.PvP.ProtectPlayersInLandClaims.AdministrativeSubdivisions", this.config_pvp_noCombatInAdminSubdivisions);
- outConfig.set("GriefPrevention.PvP.AllowLavaDumpingNearOtherPlayers", this.config_pvp_allowLavaNearPlayers);
- outConfig.set("GriefPrevention.PvP.AllowFlintAndSteelNearOtherPlayers", this.config_pvp_allowFireNearPlayers);
- outConfig.set("GriefPrevention.PvP.ProtectPetsOutsideLandClaims", this.config_pvp_protectPets);
-
- outConfig.set("GriefPrevention.Economy.ClaimBlocksPurchaseCost", this.config_economy_claimBlocksPurchaseCost);
- outConfig.set("GriefPrevention.Economy.ClaimBlocksSellValue", this.config_economy_claimBlocksSellValue);
-
- outConfig.set("GriefPrevention.ProtectItemsDroppedOnDeath.PvPWorlds", this.config_lockDeathDropsInPvpWorlds);
- outConfig.set("GriefPrevention.ProtectItemsDroppedOnDeath.NonPvPWorlds", this.config_lockDeathDropsInNonPvpWorlds);
-
- outConfig.set("GriefPrevention.BlockLandClaimExplo