PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java

290 lines
14 KiB
Java
Raw Normal View History

2014-11-08 20:27:09 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// 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, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
2014-11-16 10:48:18 +01:00
package com.intellectualcrafters.plot.object;
2014-09-22 13:02:14 +02:00
2015-07-30 16:25:16 +02:00
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
2015-07-05 17:44:10 +02:00
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS;
2015-01-13 17:38:15 +01:00
import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.ConfigurationNode;
2015-01-27 22:51:56 +01:00
import com.intellectualcrafters.plot.config.Settings;
2015-01-13 17:38:15 +01:00
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
2015-06-05 14:39:48 +02:00
import com.intellectualcrafters.plot.util.EconHandler;
2015-07-30 16:25:16 +02:00
import com.intellectualcrafters.plot.util.PlotGamemode;
2015-07-26 20:38:08 +02:00
import com.intellectualcrafters.plot.util.StringMan;
2014-09-28 10:43:44 +02:00
2014-10-18 12:28:15 +02:00
/**
* @author Jesse Boyd
*/
2014-10-10 09:31:51 +02:00
public abstract class PlotWorld {
2014-12-18 03:15:11 +01:00
public final static boolean AUTO_MERGE_DEFAULT = false;
2015-02-24 08:11:14 +01:00
public final static boolean ALLOW_SIGNS_DEFAULT = true;
2014-12-18 03:15:11 +01:00
public final static boolean MOB_SPAWNING_DEFAULT = false;
2015-02-22 13:24:48 +01:00
public final static String PLOT_BIOME_DEFAULT = "FOREST";
2014-12-18 03:15:11 +01:00
public final static boolean PLOT_CHAT_DEFAULT = false;
public final static boolean SCHEMATIC_CLAIM_SPECIFY_DEFAULT = false;
public final static boolean SCHEMATIC_ON_CLAIM_DEFAULT = false;
public final static String SCHEMATIC_FILE_DEFAULT = "null";
public final static List<String> SCHEMATICS_DEFAULT = null;
public final static boolean USE_ECONOMY_DEFAULT = false;
public final static double PLOT_PRICE_DEFAULT = 100;
public final static double MERGE_PRICE_DEFAULT = 100;
public final static double SELL_PRICE_DEFAULT = 75;
public final static boolean PVP_DEFAULT = false;
public final static boolean PVE_DEFAULT = false;
public final static boolean SPAWN_EGGS_DEFAULT = false;
public final static boolean SPAWN_CUSTOM_DEFAULT = true;
public final static boolean SPAWN_BREEDING_DEFAULT = false;
2015-01-14 14:47:03 +01:00
public final static boolean WORLD_BORDER_DEFAULT = false;
public final static int MAX_PLOT_MEMBERS_DEFAULT = 128;
2015-07-18 10:47:35 +02:00
public final static int MAX_BUILD_HEIGHT_DEFAULT = 256;
2015-07-30 16:25:16 +02:00
public final static PlotGamemode GAMEMODE_DEFAULT = PlotGamemode.CREATIVE;
2015-01-27 22:51:56 +01:00
// are plot clusters enabled
// require claim in cluster
2014-11-21 23:55:30 +01:00
// TODO make this configurable
// make non static and static_default_valu + add config option
2015-02-22 13:24:48 +01:00
public static int[] BLOCKS;
2014-11-21 23:55:30 +01:00
static {
2015-02-23 02:32:27 +01:00
BLOCKS = new int[] { 1, 2, 3, 4, 5, 7, 14, 15, 16, 17, 19, 21, 22, 23, 24, 25, 35, 41, 42, 43, 45, 47, 48, 49, 52, 56, 57, 58, 61, 62, 73, 74, 80, 82, 84, 86, 87, 88, 91, 97, 98, 99, 100, 103, 110, 112, 120, 121, 123, 124, 125, 129, 133, 153, 155, 159, 162, 165, 166, 168, 170, 172, 173, 174, 179, 181 };
2014-11-21 23:55:30 +01:00
}
2014-12-18 03:15:11 +01:00
public final String worldname;
public int MAX_PLOT_MEMBERS;
2014-12-18 03:15:11 +01:00
public boolean AUTO_MERGE;
2015-02-24 08:11:14 +01:00
public boolean ALLOW_SIGNS;
2014-12-18 03:15:11 +01:00
public boolean MOB_SPAWNING;
2015-02-22 13:24:48 +01:00
public String PLOT_BIOME;
2014-12-18 03:15:11 +01:00
public boolean PLOT_CHAT;
public boolean SCHEMATIC_CLAIM_SPECIFY = false;
public boolean SCHEMATIC_ON_CLAIM;
public String SCHEMATIC_FILE;
public List<String> SCHEMATICS;
public HashMap<String, Flag> DEFAULT_FLAGS;
2014-12-18 03:15:11 +01:00
public boolean USE_ECONOMY;
public double PLOT_PRICE;
public double MERGE_PRICE;
public double SELL_PRICE;
public boolean PVP;
public boolean PVE;
public boolean SPAWN_EGGS;
public boolean SPAWN_CUSTOM;
public boolean SPAWN_BREEDING;
2015-01-14 14:47:03 +01:00
public boolean WORLD_BORDER;
2015-02-08 00:44:53 +01:00
public int TYPE = 0;
public int TERRAIN = 0;
2015-04-07 08:19:16 +02:00
public boolean HOME_ALLOW_NONMEMBER;
public PlotLoc DEFAULT_HOME;
2015-07-18 10:47:35 +02:00
public int MAX_BUILD_HEIGHT;
2015-07-30 16:25:16 +02:00
public PlotGamemode GAMEMODE = PlotGamemode.CREATIVE;
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
public PlotWorld(final String worldname) {
this.worldname = worldname;
}
2015-03-23 15:27:42 +01:00
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
PlotWorld plotworld = (PlotWorld) obj;
ConfigurationSection section = PS.get().config.getConfigurationSection("worlds");
for (ConfigurationNode setting : plotworld.getSettingNodes()) {
Object constant = section.get(plotworld.worldname + "." + setting.getConstant());
if (constant == null) {
return false;
}
if (!constant.equals(section.get(this.worldname + "." + setting.getConstant()))) {
return false;
}
}
return true;
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
/**
* When a world is created, the following method will be called for each
*
2014-12-18 03:15:11 +01:00
* @param config Configuration Section
2014-11-05 04:42:08 +01:00
*/
public void loadDefaultConfiguration(final ConfigurationSection config) {
2015-02-20 07:34:19 +01:00
if (config.contains("generator.terrain")) {
this.TERRAIN = config.getInt("generator.terrain");
this.TYPE = config.getInt("generator.type");
}
2014-11-05 04:42:08 +01:00
this.MOB_SPAWNING = config.getBoolean("natural_mob_spawning");
this.AUTO_MERGE = config.getBoolean("plot.auto_merge");
this.MAX_PLOT_MEMBERS = config.getInt("limits.max-members");
2015-02-24 08:11:14 +01:00
this.ALLOW_SIGNS = config.getBoolean("plot.create_signs");
2015-02-22 13:24:48 +01:00
this.PLOT_BIOME = (String) Configuration.BIOME.parseString(config.getString("plot.biome"));
2014-11-05 04:42:08 +01:00
this.SCHEMATIC_ON_CLAIM = config.getBoolean("schematic.on_claim");
this.SCHEMATIC_FILE = config.getString("schematic.file");
this.SCHEMATIC_CLAIM_SPECIFY = config.getBoolean("schematic.specify_on_claim");
this.SCHEMATICS = config.getStringList("schematic.schematics");
2015-06-05 14:39:48 +02:00
this.USE_ECONOMY = config.getBoolean("economy.use") && (EconHandler.manager != null);
2014-11-05 04:42:08 +01:00
this.PLOT_PRICE = config.getDouble("economy.prices.claim");
this.MERGE_PRICE = config.getDouble("economy.prices.merge");
this.SELL_PRICE = config.getDouble("economy.prices.sell");
this.PLOT_CHAT = config.getBoolean("chat.enabled");
2015-01-14 14:47:03 +01:00
this.WORLD_BORDER = config.getBoolean("world.border");
2015-07-18 10:47:35 +02:00
this.MAX_BUILD_HEIGHT = config.getInt("world.max_height");
2015-04-07 08:19:16 +02:00
2015-07-30 16:25:16 +02:00
switch (config.getString("world.gamemode").toLowerCase()) {
case "survival":
case "s":
case "0":
this.GAMEMODE = PlotGamemode.SURVIVAL;
2015-07-31 11:46:07 +02:00
break;
2015-07-30 16:25:16 +02:00
case "creative":
case "c":
case "1":
this.GAMEMODE = PlotGamemode.CREATIVE;
2015-07-31 11:46:07 +02:00
break;
2015-07-30 16:25:16 +02:00
case "adventure":
case "a":
case "2":
this.GAMEMODE = PlotGamemode.ADVENTURE;
2015-07-31 11:46:07 +02:00
break;
2015-07-30 16:25:16 +02:00
case "spectator":
case "3":
this.GAMEMODE = PlotGamemode.SPECTATOR;
2015-07-31 11:46:07 +02:00
break;
2015-07-30 16:25:16 +02:00
default:
PS.debug("&cInvalid gamemode set for: " + worldname);
2015-07-31 11:46:07 +02:00
break;
2015-07-30 16:25:16 +02:00
}
2015-04-07 08:19:16 +02:00
this.HOME_ALLOW_NONMEMBER = config.getBoolean("home.allow-nonmembers");
String homeDefault = config.getString("home.default");
if (homeDefault.equalsIgnoreCase("side")) {
DEFAULT_HOME = null;
}
else if (homeDefault.equalsIgnoreCase("center")) {
DEFAULT_HOME = new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE);
}
else {
try {
String[] split = homeDefault.split(",");
DEFAULT_HOME = new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
}
catch (Exception e) {
DEFAULT_HOME = null;
}
}
2015-03-10 11:48:20 +01:00
List<String> flags = config.getStringList("flags.default");
if (flags == null || flags.size() == 0) {
flags = config.getStringList("flags");
if (flags == null || flags.size() == 0) {
flags = new ArrayList<String>();
ConfigurationSection section = config.getConfigurationSection("flags");
Set<String> keys = section.getKeys(false);
for (String key : keys) {
2015-03-11 12:16:57 +01:00
if (!key.equals("default")) {
flags.add(key + ";" + section.get(key));
}
2015-03-10 11:48:20 +01:00
}
2015-01-10 02:00:26 +01:00
}
2014-12-21 15:59:35 +01:00
}
2015-03-10 11:48:20 +01:00
try {
this.DEFAULT_FLAGS = FlagManager.parseFlags(flags);
} catch (final Exception e) {
e.printStackTrace();
2015-07-30 16:25:16 +02:00
PS.debug("&cInvalid default flags for " + this.worldname + ": " + StringMan.join(flags, ","));
this.DEFAULT_FLAGS = new HashMap<>();
2015-03-10 11:48:20 +01:00
}
2014-11-05 04:42:08 +01:00
this.PVP = config.getBoolean("event.pvp");
2014-10-19 08:19:01 +02:00
this.PVE = config.getBoolean("event.pve");
this.SPAWN_EGGS = config.getBoolean("event.spawn.egg");
this.SPAWN_CUSTOM = config.getBoolean("event.spawn.custom");
this.SPAWN_BREEDING = config.getBoolean("event.spawn.breeding");
2014-10-18 10:24:48 +02:00
loadConfiguration(config);
2014-11-05 04:42:08 +01:00
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
public abstract void loadConfiguration(final ConfigurationSection config);
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
/**
* Saving core plotworld settings
*
2014-12-18 03:15:11 +01:00
* @param config Configuration Section
2014-11-05 04:42:08 +01:00
*/
public void saveConfiguration(final ConfigurationSection config) {
final HashMap<String, Object> options = new HashMap<>();
2014-11-05 04:42:08 +01:00
options.put("natural_mob_spawning", PlotWorld.MOB_SPAWNING_DEFAULT);
options.put("plot.auto_merge", PlotWorld.AUTO_MERGE_DEFAULT);
2015-02-24 08:11:14 +01:00
options.put("plot.create_signs", PlotWorld.ALLOW_SIGNS_DEFAULT);
2014-11-05 04:42:08 +01:00
options.put("plot.biome", PlotWorld.PLOT_BIOME_DEFAULT.toString());
options.put("schematic.on_claim", PlotWorld.SCHEMATIC_ON_CLAIM_DEFAULT);
options.put("schematic.file", PlotWorld.SCHEMATIC_FILE_DEFAULT);
options.put("schematic.specify_on_claim", PlotWorld.SCHEMATIC_CLAIM_SPECIFY_DEFAULT);
options.put("schematic.schematics", PlotWorld.SCHEMATICS_DEFAULT);
options.put("economy.use", PlotWorld.USE_ECONOMY_DEFAULT);
options.put("economy.prices.claim", PlotWorld.PLOT_PRICE_DEFAULT);
options.put("economy.prices.merge", PlotWorld.MERGE_PRICE_DEFAULT);
options.put("economy.prices.sell", PlotWorld.SELL_PRICE_DEFAULT);
options.put("chat.enabled", PlotWorld.PLOT_CHAT_DEFAULT);
2014-12-21 15:59:35 +01:00
options.put("flags.default", null);
2014-10-19 08:19:01 +02:00
options.put("event.pvp", PlotWorld.PVP_DEFAULT);
options.put("event.pve", PlotWorld.PVE_DEFAULT);
options.put("event.spawn.egg", PlotWorld.SPAWN_EGGS_DEFAULT);
2014-10-18 10:24:48 +02:00
options.put("event.spawn.custom", PlotWorld.SPAWN_CUSTOM_DEFAULT);
2014-10-19 08:19:01 +02:00
options.put("event.spawn.breeding", PlotWorld.SPAWN_BREEDING_DEFAULT);
2015-01-14 14:47:03 +01:00
options.put("world.border", PlotWorld.WORLD_BORDER_DEFAULT);
options.put("limits.max-members", PlotWorld.MAX_PLOT_MEMBERS_DEFAULT);
2015-04-07 08:19:16 +02:00
options.put("home.default", "side");
options.put("home.allow-nonmembers", false);
2015-07-18 10:47:35 +02:00
options.put("world.max_height", PlotWorld.MAX_BUILD_HEIGHT_DEFAULT);
2015-07-30 16:25:16 +02:00
options.put("world.gamemode", PlotWorld.GAMEMODE_DEFAULT.name().toLowerCase());
2015-07-18 10:47:35 +02:00
2015-02-20 07:34:19 +01:00
if (Settings.ENABLE_CLUSTERS && (this.TYPE != 0)) {
2015-02-08 00:44:53 +01:00
options.put("generator.terrain", this.TERRAIN);
options.put("generator.type", this.TYPE);
2015-02-20 07:34:19 +01:00
}
2014-11-05 04:42:08 +01:00
final ConfigurationNode[] settings = getSettingNodes();
/*
* Saving generator specific settings
*/
for (final ConfigurationNode setting : settings) {
options.put(setting.getConstant(), setting.getValue());
2014-11-05 04:42:08 +01:00
}
for (final String option : options.keySet()) {
if (!config.contains(option)) {
config.set(option, options.get(option));
}
}
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
/**
2014-12-18 03:15:11 +01:00
* Used for the <b>/plot setup</b> command Return null if you do not want to support this feature
2014-11-05 04:42:08 +01:00
*
* @return ConfigurationNode[]
*/
public abstract ConfigurationNode[] getSettingNodes();
}