PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java

https://gitlab.com/igserfurtmcschulserver/CustomWorldGuard
Java | 655 lines | 513 code | 91 blank | 51 comment | 80 complexity | 7abd15300d86cc1817dcd6f7075be0f4 MD5 | raw file
  1. /*
  2. * WorldGuard, a suite of tools for Minecraft
  3. * Copyright (C) sk89q <http://www.sk89q.com>
  4. * Copyright (C) WorldGuard team and contributors
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU Lesser General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
  14. * for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.sk89q.worldguard.bukkit;
  20. import com.sk89q.util.yaml.YAMLFormat;
  21. import com.sk89q.util.yaml.YAMLProcessor;
  22. import com.sk89q.worldguard.blacklist.Blacklist;
  23. import com.sk89q.worldguard.blacklist.BlacklistLoggerHandler;
  24. import com.sk89q.worldguard.blacklist.logger.ConsoleHandler;
  25. import com.sk89q.worldguard.blacklist.logger.DatabaseHandler;
  26. import com.sk89q.worldguard.blacklist.logger.FileHandler;
  27. import com.sk89q.worldguard.blacklist.target.TargetMatcherParseException;
  28. import com.sk89q.worldguard.blacklist.target.TargetMatcherParser;
  29. import com.sk89q.worldguard.bukkit.commands.CommandUtils;
  30. import com.sk89q.worldguard.bukkit.internal.BukkitBlacklist;
  31. import com.sk89q.worldguard.bukkit.internal.TargetMatcherSet;
  32. import com.sk89q.worldguard.chest.ChestProtection;
  33. import com.sk89q.worldguard.chest.SignChestProtection;
  34. import com.sk89q.worldguard.util.report.Unreported;
  35. import org.bukkit.block.Block;
  36. import org.bukkit.entity.EntityType;
  37. import org.bukkit.entity.Player;
  38. import org.bukkit.potion.PotionEffectType;
  39. import org.yaml.snakeyaml.parser.ParserException;
  40. import java.io.File;
  41. import java.io.FileNotFoundException;
  42. import java.io.IOException;
  43. import java.util.*;
  44. import java.util.logging.Level;
  45. import java.util.logging.Logger;
  46. /**
  47. * Holds the configuration for individual worlds.
  48. *
  49. * @author sk89q
  50. * @author Michael
  51. */
  52. public class WorldConfiguration {
  53. private static final Logger log = Logger.getLogger(WorldConfiguration.class.getCanonicalName());
  54. private static final TargetMatcherParser matcherParser = new TargetMatcherParser();
  55. public static final String CONFIG_HEADER = "#\r\n" +
  56. "# WorldGuard's world configuration file\r\n" +
  57. "#\r\n" +
  58. "# This is a world configuration file. Anything placed into here will only\r\n" +
  59. "# affect this world. If you don't put anything in this file, then the\r\n" +
  60. "# settings will be inherited from the main configuration file.\r\n" +
  61. "#\r\n" +
  62. "# If you see {} below, that means that there are NO entries in this file.\r\n" +
  63. "# Remove the {} and add your own entries.\r\n" +
  64. "#\r\n";
  65. @Unreported private WorldGuardPlugin plugin;
  66. @Unreported private String worldName;
  67. @Unreported private YAMLProcessor parentConfig;
  68. @Unreported private YAMLProcessor config;
  69. private File blacklistFile;
  70. @Unreported private Blacklist blacklist;
  71. @Unreported private ChestProtection chestProtection = new SignChestProtection();
  72. /* Configuration data start */
  73. public boolean summaryOnStart;
  74. public boolean opPermissions;
  75. public boolean buildPermissions;
  76. public String buildPermissionDenyMessage = "";
  77. public boolean fireSpreadDisableToggle;
  78. public boolean itemDurability;
  79. public boolean simulateSponge;
  80. public int spongeRadius;
  81. public boolean disableExpDrops;
  82. public Set<PotionEffectType> blockPotions;
  83. public boolean blockPotionsAlways;
  84. public boolean pumpkinScuba;
  85. public boolean redstoneSponges;
  86. public boolean noPhysicsGravel;
  87. public boolean noPhysicsSand;
  88. public boolean ropeLadders;
  89. public boolean allowPortalAnywhere;
  90. public Set<Integer> preventWaterDamage;
  91. public boolean blockLighter;
  92. public boolean disableFireSpread;
  93. public Set<Integer> disableFireSpreadBlocks;
  94. public boolean preventLavaFire;
  95. public Set<Integer> allowedLavaSpreadOver;
  96. public boolean blockTNTExplosions;
  97. public boolean blockTNTBlockDamage;
  98. public boolean blockCreeperExplosions;
  99. public boolean blockCreeperBlockDamage;
  100. public boolean blockWitherExplosions;
  101. public boolean blockWitherBlockDamage;
  102. public boolean blockWitherSkullExplosions;
  103. public boolean blockWitherSkullBlockDamage;
  104. public boolean blockEnderDragonBlockDamage;
  105. public boolean blockEnderDragonPortalCreation;
  106. public boolean blockFireballExplosions;
  107. public boolean blockFireballBlockDamage;
  108. public boolean blockOtherExplosions;
  109. public boolean blockEntityPaintingDestroy;
  110. public boolean blockEntityItemFrameDestroy;
  111. public boolean blockPluginSpawning;
  112. public boolean blockGroundSlimes;
  113. public boolean blockZombieDoorDestruction;
  114. public boolean disableContactDamage;
  115. public boolean disableFallDamage;
  116. public boolean disableLavaDamage;
  117. public boolean disableFireDamage;
  118. public boolean disableLightningDamage;
  119. public boolean disableDrowningDamage;
  120. public boolean disableSuffocationDamage;
  121. public boolean teleportOnSuffocation;
  122. public boolean disableVoidDamage;
  123. public boolean teleportOnVoid;
  124. public boolean disableExplosionDamage;
  125. public boolean disableMobDamage;
  126. public boolean useRegions;
  127. public boolean highFreqFlags;
  128. public boolean checkLiquidFlow;
  129. public int regionWand;
  130. public Set<EntityType> blockCreatureSpawn;
  131. public boolean allowTamedSpawns;
  132. // public boolean useiConomy;
  133. // public boolean buyOnClaim;
  134. // public double buyOnClaimPrice;
  135. public int maxClaimVolume;
  136. public boolean claimOnlyInsideExistingRegions;
  137. public int maxRegionCountPerPlayer;
  138. public boolean boundedLocationFlags;
  139. public boolean antiWolfDumbness;
  140. public boolean signChestProtection;
  141. public boolean disableSignChestProtectionCheck;
  142. public boolean removeInfiniteStacks;
  143. public boolean disableCreatureCropTrampling;
  144. public boolean disablePlayerCropTrampling;
  145. public boolean preventLightningFire;
  146. public Set<Integer> disallowedLightningBlocks;
  147. public boolean disableThunder;
  148. public boolean disableWeather;
  149. public boolean alwaysRaining;
  150. public boolean alwaysThundering;
  151. public boolean disablePigZap;
  152. public boolean disableCreeperPower;
  153. public boolean disableHealthRegain;
  154. public boolean disableMushroomSpread;
  155. public boolean disableIceMelting;
  156. public boolean disableSnowMelting;
  157. public boolean disableSnowFormation;
  158. public boolean disableIceFormation;
  159. public boolean disableLeafDecay;
  160. public boolean disableGrassGrowth;
  161. public boolean disableMyceliumSpread;
  162. public boolean disableVineGrowth;
  163. public boolean disableEndermanGriefing;
  164. public boolean disableSnowmanTrails;
  165. public boolean disableSoilDehydration;
  166. public Set<Integer> allowedSnowFallOver;
  167. public boolean regionInvinciblityRemovesMobs;
  168. public boolean regionNetherPortalProtection;
  169. public boolean fakePlayerBuildOverride;
  170. public boolean explosionFlagCancellation;
  171. public boolean disableDeathMessages;
  172. public boolean disableObsidianGenerators;
  173. public boolean strictEntitySpawn;
  174. public TargetMatcherSet allowAllInteract;
  175. public TargetMatcherSet blockUseAtFeet;
  176. private Map<String, Integer> maxRegionCounts;
  177. /* Configuration data end */
  178. /**
  179. * Construct the object.
  180. *
  181. * @param plugin The WorldGuardPlugin instance
  182. * @param worldName The world name that this WorldConfiguration is for.
  183. * @param parentConfig The parent configuration to read defaults from
  184. */
  185. public WorldConfiguration(WorldGuardPlugin plugin, String worldName, YAMLProcessor parentConfig) {
  186. File baseFolder = new File(plugin.getDataFolder(), "worlds/" + worldName);
  187. File configFile = new File(baseFolder, "config.yml");
  188. blacklistFile = new File(baseFolder, "blacklist.txt");
  189. this.plugin = plugin;
  190. this.worldName = worldName;
  191. this.parentConfig = parentConfig;
  192. plugin.createDefaultConfiguration(configFile, "config_world.yml");
  193. plugin.createDefaultConfiguration(blacklistFile, "blacklist.txt");
  194. config = new YAMLProcessor(configFile, true, YAMLFormat.EXTENDED);
  195. loadConfiguration();
  196. if (summaryOnStart) {
  197. log.info("Loaded configuration for world '" + worldName + "'");
  198. }
  199. }
  200. private boolean getBoolean(String node, boolean def) {
  201. boolean val = parentConfig.getBoolean(node, def);
  202. if (config.getProperty(node) != null) {
  203. return config.getBoolean(node, def);
  204. } else {
  205. return val;
  206. }
  207. }
  208. private String getString(String node, String def) {
  209. String val = parentConfig.getString(node, def);
  210. if (config.getProperty(node) != null) {
  211. return config.getString(node, def);
  212. } else {
  213. return val;
  214. }
  215. }
  216. private int getInt(String node, int def) {
  217. int val = parentConfig.getInt(node, def);
  218. if (config.getProperty(node) != null) {
  219. return config.getInt(node, def);
  220. } else {
  221. return val;
  222. }
  223. }
  224. @SuppressWarnings("unused")
  225. private double getDouble(String node, double def) {
  226. double val = parentConfig.getDouble(node, def);
  227. if (config.getProperty(node) != null) {
  228. return config.getDouble(node, def);
  229. } else {
  230. return val;
  231. }
  232. }
  233. private List<Integer> getIntList(String node, List<Integer> def) {
  234. List<Integer> res = parentConfig.getIntList(node, def);
  235. if (res == null || res.size() == 0) {
  236. parentConfig.setProperty(node, new ArrayList<Integer>());
  237. }
  238. if (config.getProperty(node) != null) {
  239. res = config.getIntList(node, def);
  240. }
  241. return res;
  242. }
  243. private TargetMatcherSet getTargetMatchers(String node) {
  244. TargetMatcherSet set = new TargetMatcherSet();
  245. List<String> inputs = parentConfig.getStringList(node, null);
  246. if (inputs == null || inputs.size() == 0) {
  247. parentConfig.setProperty(node, new ArrayList<String>());
  248. return set;
  249. }
  250. for (String input : inputs) {
  251. try {
  252. set.add(matcherParser.fromInput(input));
  253. } catch (TargetMatcherParseException e) {
  254. log.warning("Failed to parse the block / item type specified as '" + input + "'");
  255. }
  256. }
  257. return set;
  258. }
  259. private List<String> getStringList(String node, List<String> def) {
  260. List<String> res = parentConfig.getStringList(node, def);
  261. if (res == null || res.size() == 0) {
  262. parentConfig.setProperty(node, new ArrayList<String>());
  263. }
  264. if (config.getProperty(node) != null) {
  265. res = config.getStringList(node, def);
  266. }
  267. return res;
  268. }
  269. private List<String> getKeys(String node) {
  270. List<String> res = parentConfig.getKeys(node);
  271. if (res == null || res.size() == 0) {
  272. res = config.getKeys(node);
  273. }
  274. if (res == null) {
  275. res = new ArrayList<String>();
  276. }
  277. return res;
  278. }
  279. private Object getProperty(String node) {
  280. Object res = parentConfig.getProperty(node);
  281. if (config.getProperty(node) != null) {
  282. res = config.getProperty(node);
  283. }
  284. return res;
  285. }
  286. /**
  287. * Load the configuration.
  288. */
  289. private void loadConfiguration() {
  290. try {
  291. config.load();
  292. } catch (IOException e) {
  293. log.severe("Error reading configuration for world " + worldName + ": ");
  294. e.printStackTrace();
  295. } catch (ParserException e) {
  296. log.severe("Error parsing configuration for world " + worldName + ". ");
  297. throw e;
  298. }
  299. summaryOnStart = getBoolean("summary-on-start", true);
  300. opPermissions = getBoolean("op-permissions", true);
  301. buildPermissions = getBoolean("build-permission-nodes.enable", false);
  302. buildPermissionDenyMessage = CommandUtils.replaceColorMacros(
  303. getString("build-permission-nodes.deny-message", "&eSorry, but you are not permitted to do that here."));
  304. strictEntitySpawn = getBoolean("event-handling.block-entity-spawns-with-untraceable-cause", false);
  305. allowAllInteract = getTargetMatchers("event-handling.interaction-whitelist");
  306. blockUseAtFeet = getTargetMatchers("event-handling.emit-block-use-at-feet");
  307. itemDurability = getBoolean("protection.item-durability", true);
  308. removeInfiniteStacks = getBoolean("protection.remove-infinite-stacks", false);
  309. disableExpDrops = getBoolean("protection.disable-xp-orb-drops", false);
  310. disableObsidianGenerators = getBoolean("protection.disable-obsidian-generators", false);
  311. blockPotions = new HashSet<PotionEffectType>();
  312. for (String potionName : getStringList("gameplay.block-potions", null)) {
  313. PotionEffectType effect = PotionEffectType.getByName(potionName);
  314. if (effect == null) {
  315. log.warning("Unknown potion effect type '" + potionName + "'");
  316. } else {
  317. blockPotions.add(effect);
  318. }
  319. }
  320. blockPotionsAlways = getBoolean("gameplay.block-potions-overly-reliably", false);
  321. simulateSponge = getBoolean("simulation.sponge.enable", false);
  322. spongeRadius = Math.max(1, getInt("simulation.sponge.radius", 3)) - 1;
  323. redstoneSponges = getBoolean("simulation.sponge.redstone", false);
  324. pumpkinScuba = getBoolean("default.pumpkin-scuba", false);
  325. disableHealthRegain = getBoolean("default.disable-health-regain", false);
  326. noPhysicsGravel = getBoolean("physics.no-physics-gravel", false);
  327. noPhysicsSand = getBoolean("physics.no-physics-sand", false);
  328. ropeLadders = getBoolean("physics.vine-like-rope-ladders", false);
  329. allowPortalAnywhere = getBoolean("physics.allow-portal-anywhere", false);
  330. preventWaterDamage = new HashSet<Integer>(getIntList("physics.disable-water-damage-blocks", null));
  331. blockTNTExplosions = getBoolean("ignition.block-tnt", false);
  332. blockTNTBlockDamage = getBoolean("ignition.block-tnt-block-damage", false);
  333. blockLighter = getBoolean("ignition.block-lighter", false);
  334. preventLavaFire = getBoolean("fire.disable-lava-fire-spread", true);
  335. disableFireSpread = getBoolean("fire.disable-all-fire-spread", false);
  336. disableFireSpreadBlocks = new HashSet<Integer>(getIntList("fire.disable-fire-spread-blocks", null));
  337. allowedLavaSpreadOver = new HashSet<Integer>(getIntList("fire.lava-spread-blocks", null));
  338. blockCreeperExplosions = getBoolean("mobs.block-creeper-explosions", false);
  339. blockCreeperBlockDamage = getBoolean("mobs.block-creeper-block-damage", false);
  340. blockWitherExplosions = getBoolean("mobs.block-wither-explosions", false);
  341. blockWitherBlockDamage = getBoolean("mobs.block-wither-block-damage", false);
  342. blockWitherSkullExplosions = getBoolean("mobs.block-wither-skull-explosions", false);
  343. blockWitherSkullBlockDamage = getBoolean("mobs.block-wither-skull-block-damage", false);
  344. blockEnderDragonBlockDamage = getBoolean("mobs.block-enderdragon-block-damage", false);
  345. blockEnderDragonPortalCreation = getBoolean("mobs.block-enderdragon-portal-creation", false);
  346. blockFireballExplosions = getBoolean("mobs.block-fireball-explosions", false);
  347. blockFireballBlockDamage = getBoolean("mobs.block-fireball-block-damage", false);
  348. antiWolfDumbness = getBoolean("mobs.anti-wolf-dumbness", false);
  349. allowTamedSpawns = getBoolean("mobs.allow-tamed-spawns", true);
  350. disableEndermanGriefing = getBoolean("mobs.disable-enderman-griefing", false);
  351. disableSnowmanTrails = getBoolean("mobs.disable-snowman-trails", false);
  352. blockEntityPaintingDestroy = getBoolean("mobs.block-painting-destroy", false);
  353. blockEntityItemFrameDestroy = getBoolean("mobs.block-item-frame-destroy", false);
  354. blockPluginSpawning = getBoolean("mobs.block-plugin-spawning", true);
  355. blockGroundSlimes = getBoolean("mobs.block-above-ground-slimes", false);
  356. blockOtherExplosions = getBoolean("mobs.block-other-explosions", false);
  357. blockZombieDoorDestruction = getBoolean("mobs.block-zombie-door-destruction", false);
  358. disableFallDamage = getBoolean("player-damage.disable-fall-damage", false);
  359. disableLavaDamage = getBoolean("player-damage.disable-lava-damage", false);
  360. disableFireDamage = getBoolean("player-damage.disable-fire-damage", false);
  361. disableLightningDamage = getBoolean("player-damage.disable-lightning-damage", false);
  362. disableDrowningDamage = getBoolean("player-damage.disable-drowning-damage", false);
  363. disableSuffocationDamage = getBoolean("player-damage.disable-suffocation-damage", false);
  364. disableContactDamage = getBoolean("player-damage.disable-contact-damage", false);
  365. teleportOnSuffocation = getBoolean("player-damage.teleport-on-suffocation", false);
  366. disableVoidDamage = getBoolean("player-damage.disable-void-damage", false);
  367. teleportOnVoid = getBoolean("player-damage.teleport-on-void-falling", false);
  368. disableExplosionDamage = getBoolean("player-damage.disable-explosion-damage", false);
  369. disableMobDamage = getBoolean("player-damage.disable-mob-damage", false);
  370. disableDeathMessages = getBoolean("player-damage.disable-death-messages", false);
  371. signChestProtection = getBoolean("chest-protection.enable", false);
  372. disableSignChestProtectionCheck = getBoolean("chest-protection.disable-off-check", false);
  373. disableCreatureCropTrampling = getBoolean("crops.disable-creature-trampling", false);
  374. disablePlayerCropTrampling = getBoolean("crops.disable-player-trampling", false);
  375. disallowedLightningBlocks = new HashSet<Integer>(getIntList("weather.prevent-lightning-strike-blocks", null));
  376. preventLightningFire = getBoolean("weather.disable-lightning-strike-fire", false);
  377. disableThunder = getBoolean("weather.disable-thunderstorm", false);
  378. disableWeather = getBoolean("weather.disable-weather", false);
  379. disablePigZap = getBoolean("weather.disable-pig-zombification", false);
  380. disableCreeperPower = getBoolean("weather.disable-powered-creepers", false);
  381. alwaysRaining = getBoolean("weather.always-raining", false);
  382. alwaysThundering = getBoolean("weather.always-thundering", false);
  383. disableMushroomSpread = getBoolean("dynamics.disable-mushroom-spread", false);
  384. disableIceMelting = getBoolean("dynamics.disable-ice-melting", false);
  385. disableSnowMelting = getBoolean("dynamics.disable-snow-melting", false);
  386. disableSnowFormation = getBoolean("dynamics.disable-snow-formation", false);
  387. disableIceFormation = getBoolean("dynamics.disable-ice-formation", false);
  388. disableLeafDecay = getBoolean("dynamics.disable-leaf-decay", false);
  389. disableGrassGrowth = getBoolean("dynamics.disable-grass-growth", false);
  390. disableMyceliumSpread = getBoolean("dynamics.disable-mycelium-spread", false);
  391. disableVineGrowth = getBoolean("dynamics.disable-vine-growth", false);
  392. disableSoilDehydration = getBoolean("dynamics.disable-soil-dehydration", false);
  393. allowedSnowFallOver = new HashSet<Integer>(getIntList("dynamics.snow-fall-blocks", null));
  394. useRegions = getBoolean("regions.enable", true);
  395. regionInvinciblityRemovesMobs = getBoolean("regions.invincibility-removes-mobs", false);
  396. regionNetherPortalProtection = getBoolean("regions.nether-portal-protection", false);
  397. fakePlayerBuildOverride = getBoolean("regions.fake-player-build-override", true);
  398. explosionFlagCancellation = getBoolean("regions.explosion-flags-block-entity-damage", true);
  399. highFreqFlags = getBoolean("regions.high-frequency-flags", false);
  400. checkLiquidFlow = getBoolean("regions.protect-against-liquid-flow", false);
  401. regionWand = getInt("regions.wand", 334);
  402. maxClaimVolume = getInt("regions.max-claim-volume", 30000);
  403. claimOnlyInsideExistingRegions = getBoolean("regions.claim-only-inside-existing-regions", false);
  404. boundedLocationFlags = getBoolean("regions.location-flags-only-inside-regions", false);
  405. maxRegionCountPerPlayer = getInt("regions.max-region-count-per-player.default", 7);
  406. maxRegionCounts = new HashMap<String, Integer>();
  407. maxRegionCounts.put(null, maxRegionCountPerPlayer);
  408. for (String key : getKeys("regions.max-region-count-per-player")) {
  409. if (!key.equalsIgnoreCase("default")) {
  410. Object val = getProperty("regions.max-region-count-per-player." + key);
  411. if (val != null && val instanceof Number) {
  412. maxRegionCounts.put(key, ((Number) val).intValue());
  413. }
  414. }
  415. }
  416. // useiConomy = getBoolean("iconomy.enable", false);
  417. // buyOnClaim = getBoolean("iconomy.buy-on-claim", false);
  418. // buyOnClaimPrice = getDouble("iconomy.buy-on-claim-price", 1.0);
  419. blockCreatureSpawn = new HashSet<EntityType>();
  420. for (String creatureName : getStringList("mobs.block-creature-spawn", null)) {
  421. EntityType creature = EntityType.fromName(creatureName);
  422. if (creature == null) {
  423. log.warning("Unknown mob type '" + creatureName + "'");
  424. } else if (!creature.isAlive()) {
  425. log.warning("Entity type '" + creatureName + "' is not a creature");
  426. } else {
  427. blockCreatureSpawn.add(creature);
  428. }
  429. }
  430. boolean useBlacklistAsWhitelist = getBoolean("blacklist.use-as-whitelist", false);
  431. // Console log configuration
  432. boolean logConsole = getBoolean("blacklist.logging.console.enable", true);
  433. // Database log configuration
  434. boolean logDatabase = getBoolean("blacklist.logging.database.enable", false);
  435. String dsn = getString("blacklist.logging.database.dsn", "jdbc:mysql://localhost:3306/minecraft");
  436. String user = getString("blacklist.logging.database.user", "root");
  437. String pass = getString("blacklist.logging.database.pass", "");
  438. String table = getString("blacklist.logging.database.table", "blacklist_events");
  439. // File log configuration
  440. boolean logFile = getBoolean("blacklist.logging.file.enable", false);
  441. String logFilePattern = getString("blacklist.logging.file.path", "worldguard/logs/%Y-%m-%d.log");
  442. int logFileCacheSize = Math.max(1, getInt("blacklist.logging.file.open-files", 10));
  443. // Load the blacklist
  444. try {
  445. // If there was an existing blacklist, close loggers
  446. if (blacklist != null) {
  447. blacklist.getLogger().close();
  448. }
  449. // First load the blacklist data from worldguard-blacklist.txt
  450. Blacklist blist = new BukkitBlacklist(useBlacklistAsWhitelist, plugin);
  451. blist.load(blacklistFile);
  452. // If the blacklist is empty, then set the field to null
  453. // and save some resources
  454. if (blist.isEmpty()) {
  455. this.blacklist = null;
  456. } else {
  457. this.blacklist = blist;
  458. if (summaryOnStart) {
  459. log.log(Level.INFO, "Blacklist loaded.");
  460. }
  461. BlacklistLoggerHandler blacklistLogger = blist.getLogger();
  462. if (logDatabase) {
  463. blacklistLogger.addHandler(new DatabaseHandler(dsn, user, pass, table, worldName, log));
  464. }
  465. if (logConsole) {
  466. blacklistLogger.addHandler(new ConsoleHandler(worldName, log));
  467. }
  468. if (logFile) {
  469. FileHandler handler =
  470. new FileHandler(logFilePattern, logFileCacheSize, worldName, log);
  471. blacklistLogger.addHandler(handler);
  472. }
  473. }
  474. } catch (FileNotFoundException e) {
  475. log.log(Level.WARNING, "WorldGuard blacklist does not exist.");
  476. } catch (IOException e) {
  477. log.log(Level.WARNING, "Could not load WorldGuard blacklist: "
  478. + e.getMessage());
  479. }
  480. // Print an overview of settings
  481. if (summaryOnStart) {
  482. log.log(Level.INFO, blockTNTExplosions
  483. ? "(" + worldName + ") TNT ignition is blocked."
  484. : "(" + worldName + ") TNT ignition is PERMITTED.");
  485. log.log(Level.INFO, blockLighter
  486. ? "(" + worldName + ") Lighters are blocked."
  487. : "(" + worldName + ") Lighters are PERMITTED.");
  488. log.log(Level.INFO, preventLavaFire
  489. ? "(" + worldName + ") Lava fire is blocked."
  490. : "(" + worldName + ") Lava fire is PERMITTED.");
  491. if (disableFireSpread) {
  492. log.log(Level.INFO, "(" + worldName + ") All fire spread is disabled.");
  493. } else {
  494. if (disableFireSpreadBlocks.size() > 0) {
  495. log.log(Level.INFO, "(" + worldName
  496. + ") Fire spread is limited to "
  497. + disableFireSpreadBlocks.size() + " block types.");
  498. } else {
  499. log.log(Level.INFO, "(" + worldName
  500. + ") Fire spread is UNRESTRICTED.");
  501. }
  502. }
  503. }
  504. config.setHeader(CONFIG_HEADER);
  505. config.save();
  506. }
  507. public Blacklist getBlacklist() {
  508. return this.blacklist;
  509. }
  510. public String getWorldName() {
  511. return this.worldName;
  512. }
  513. public boolean isChestProtected(Block block, Player player) {
  514. if (!signChestProtection) {
  515. return false;
  516. }
  517. if (plugin.hasPermission(player, "worldguard.chest-protection.override")
  518. || plugin.hasPermission(player, "worldguard.override.chest-protection")) {
  519. return false;
  520. }
  521. return chestProtection.isProtected(block, player);
  522. }
  523. public boolean isChestProtected(Block block) {
  524. return signChestProtection && chestProtection.isProtected(block, null);
  525. }
  526. public boolean isChestProtectedPlacement(Block block, Player player) {
  527. if (!signChestProtection) {
  528. return false;
  529. }
  530. if (plugin.hasPermission(player, "worldguard.chest-protection.override")
  531. || plugin.hasPermission(player, "worldguard.override.chest-protection")) {
  532. return false;
  533. }
  534. return chestProtection.isProtectedPlacement(block, player);
  535. }
  536. public boolean isAdjacentChestProtected(Block block, Player player) {
  537. if (!signChestProtection) {
  538. return false;
  539. }
  540. if (plugin.hasPermission(player, "worldguard.chest-protection.override")
  541. || plugin.hasPermission(player, "worldguard.override.chest-protection")) {
  542. return false;
  543. }
  544. return chestProtection.isAdjacentChestProtected(block, player);
  545. }
  546. public ChestProtection getChestProtection() {
  547. return chestProtection;
  548. }
  549. public int getMaxRegionCount(Player player) {
  550. int max = -1;
  551. for (String group : plugin.getGroups(player)) {
  552. if (maxRegionCounts.containsKey(group)) {
  553. int groupMax = maxRegionCounts.get(group);
  554. if (max < groupMax) {
  555. max = groupMax;
  556. }
  557. }
  558. }
  559. if (max <= -1) {
  560. max = maxRegionCountPerPlayer;
  561. }
  562. return max;
  563. }
  564. }