diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java b/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java index 25d209ec6..aaa88cfc6 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java @@ -94,7 +94,12 @@ public class Configuration { @Override public Object parseString(String string) { - return Biome.valueOf(string.toUpperCase()); + for (Biome biome:Biome.values()) { + if (biome.name().equals(string.toUpperCase())) { + return biome; + } + } + return Biome.FOREST; } @Override diff --git a/PlotSquared/src/com/intellectualcrafters/plot/ConfigurationNode.java b/PlotSquared/src/com/intellectualcrafters/plot/ConfigurationNode.java index e803d68ad..f84d80ff0 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/ConfigurationNode.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/ConfigurationNode.java @@ -10,7 +10,7 @@ public class ConfigurationNode { private String constant; private Object default_value; private String description; - private Object value = 0; + private Object value; private SettingValue type; public ConfigurationNode(String constant, Object default_value, @@ -22,8 +22,8 @@ public class ConfigurationNode { this.type = type; } - public String getType() { - return this.type.getType(); + public SettingValue getType() { + return this.type; } public boolean isValid(String string) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/ConsoleColors.java b/PlotSquared/src/com/intellectualcrafters/plot/ConsoleColors.java index 02cf3738a..a14759fc1 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/ConsoleColors.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/ConsoleColors.java @@ -66,7 +66,7 @@ public class ConsoleColors { .replaceAll("&n", fromChatColor(ChatColor.UNDERLINE)) .replaceAll("&o", fromChatColor(ChatColor.ITALIC)) .replaceAll("&r", fromChatColor(ChatColor.RESET)); - return input + ConsoleColor.RESET.toString(); + return input + "\u001B[0m"; } public static String fromChatColor(ChatColor color) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotGenerator.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotGenerator.java index d8fab8b27..1ccf2dd76 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotGenerator.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotGenerator.java @@ -3,8 +3,12 @@ package com.intellectualcrafters.plot; import org.bukkit.generator.ChunkGenerator; public abstract class PlotGenerator extends ChunkGenerator { + + public PlotGenerator(String world) { + PlotMain.loadWorld(world, this); + } - public abstract PlotWorld getPlotWorld(); + public abstract PlotWorld getNewPlotWorld(String world); public abstract PlotManager getPlotManager(); } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java index 1b7bbb21b..768d1d4b8 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java @@ -118,7 +118,7 @@ public class PlotHelper { if (ly) { if (!plot.settings.getMerged(1) || !plot.settings.getMerged(2)) { - manager.createRoadSouthEast(plotworld, plot); + manager.removeRoadSouthEast(plotworld, plot); } } if (!plot.settings.getMerged(1)) { @@ -165,13 +165,13 @@ public class PlotHelper { if (!lesserPlot.settings.getMerged(2)) { lesserPlot.settings.setMerged(2, true); greaterPlot.settings.setMerged(0, true); - manager.createRoadSouth(plotworld, lesserPlot); + manager.removeRoadSouth(plotworld, lesserPlot); } } else { if (!lesserPlot.settings.getMerged(1)) { lesserPlot.settings.setMerged(1, true); greaterPlot.settings.setMerged(3, true); - manager.createRoadSouth(plotworld, lesserPlot); + manager.removeRoadEast(plotworld, lesserPlot); } } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index f128dfa8e..4b705580a 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -55,6 +55,8 @@ import com.intellectualcrafters.plot.database.PlotMeConverter; import com.intellectualcrafters.plot.database.SQLite; import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent; import com.intellectualcrafters.plot.events.PlotDeleteEvent; +import com.intellectualcrafters.plot.generator.DefaultPlotManager; +import com.intellectualcrafters.plot.generator.DefaultPlotWorld; import com.intellectualcrafters.plot.generator.WorldGenerator; import com.intellectualcrafters.plot.listeners.PlayerEvents; import com.intellectualcrafters.plot.listeners.WorldEditListener; @@ -1131,6 +1133,65 @@ public class PlotMain extends JavaPlugin { PlotMain.sendConsoleSenderMessage("&c[Warning] PlotSquared failed to save the configuration&7 (settings.yml may differ from the one in memory)\n - To force a save from console use /plots save"); } } + + public static void loadWorld(String world, ChunkGenerator generator) { + if (getWorldSettings(world)!=null) { + return; + } + Set worlds; + if (config.contains("worlds")) { + worlds = config.getConfigurationSection("worlds").getKeys(false); + } else { + worlds = new HashSet(); + } + if (generator!=null && generator instanceof PlotGenerator) { + sendConsoleSenderMessage(C.PREFIX.s() + + "&aDetected world load for '" + world + "'."); + PlotGenerator plotgen = (PlotGenerator) generator; + PlotWorld plotworld = plotgen.getNewPlotWorld(world); + PlotManager manager = plotgen.getPlotManager(); + + if (!config.contains("worlds." + world)) { + config.createSection("worlds." + world); + } + plotworld.saveConfiguration(config.getConfigurationSection("worlds." + world)); + + plotworld.loadDefaultConfiguration(config.getConfigurationSection("worlds." + world)); + + try { + config.save(configFile); + } catch (IOException e) { + e.printStackTrace(); + } + + addPlotWorld(world, plotworld, manager); + + } else { + if (worlds.contains(world)) { + sendConsoleSenderMessage("&cWorld '" + + world + + "' in settings.yml is not using PlotSquared generator!"); + + PlotWorld plotworld = new DefaultPlotWorld(world); + PlotManager manager = new DefaultPlotManager(); + + if (!config.contains("worlds." + world)) { + config.createSection("worlds." + world); + } + plotworld.saveConfiguration(config.getConfigurationSection("worlds." + world)); + + plotworld.loadConfiguration(config.getConfigurationSection("worlds." + world)); + + try { + config.save(configFile); + } catch (IOException e) { + e.printStackTrace(); + } + + addPlotWorld(world, plotworld, manager); + } + } + } /** * Adds an external world as a recognized PlotSquared world - The PlotWorld @@ -1144,39 +1205,8 @@ public class PlotMain extends JavaPlugin { if (world == null) { return; } - Set worlds; - if (config.contains("worlds")) { - worlds = config.getConfigurationSection("worlds").getKeys(false); - } else { - worlds = new HashSet(); - } ChunkGenerator generator = world.getGenerator(); - if (generator instanceof PlotGenerator) { - sendConsoleSenderMessage(C.PREFIX.s() - + "&aDetected world load for '" + world.getName() + "'."); - PlotGenerator plotgen = (PlotGenerator) generator; - - PlotWorld plotworld = plotgen.getPlotWorld(); - - PlotManager manager = plotgen.getPlotManager(); - - config.createSection("worlds." + world.getName()); - - plotworld.saveConfiguration(config - .getConfigurationSection("worlds." + world.getName())); - - plotworld.loadConfiguration(config - .getConfigurationSection("worlds." + world.getName())); - - addPlotWorld(world.getName(), plotworld, manager); - - } else { - if (worlds.contains(world.getName())) { - sendConsoleSenderMessage("&cWorld '" - + world.getName() - + "' in settings.yml is not using PlotSquared generator!"); - } - } + loadWorld(world.getName(), generator); } /** diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotWorld.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotWorld.java index 91c40772d..519e0312c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotWorld.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotWorld.java @@ -86,6 +86,7 @@ import static org.bukkit.Material.getMaterial; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import org.bukkit.Material; @@ -164,13 +165,11 @@ public abstract class PlotWorld { /** * When a world is created, the following method will be called for each - * node set in the configuration - You may ignore this if you generator does - * not support configuration, or if you want to implement your own methods * * @param key * @param value */ - public void loadConfiguration(ConfigurationSection config) { + public void loadDefaultConfiguration(ConfigurationSection config) { this.MOB_SPAWNING = config.getBoolean("natural_mob_spawning"); this.AUTO_MERGE = config.getBoolean("plot.auto_merge"); this.PLOT_BIOME = (Biome) Configuration.BIOME.parseString(config @@ -186,26 +185,32 @@ public abstract class PlotWorld { this.SELL_PRICE = config.getDouble("economy.prices.sell"); this.PLOT_CHAT = config.getBoolean("chat.enabled"); this.DEFAULT_FLAGS = config.getStringList("flags.default"); + loadConfiguration(config); } + + public abstract void loadConfiguration(ConfigurationSection config); public void saveConfiguration(ConfigurationSection config) { /* * Saving core plotworld settings */ - config.set("natural_mob_spawning", this.MOB_SPAWNING); - config.set("plot.auto_merge", this.AUTO_MERGE); - config.set("plot.biome", this.PLOT_BIOME.name()); - config.set("schematic.on_claim", this.SCHEMATIC_ON_CLAIM); - config.set("schematic.file", this.SCHEMATIC_FILE); - config.set("schematic.specify_on_claim", this.SCHEMATIC_CLAIM_SPECIFY); - config.set("schematic.schematics", this.SCHEMATICS); - config.set("economy.use", this.USE_ECONOMY); - config.set("economy.prices.claim", this.PLOT_PRICE); - config.set("economy.prices.merge", this.MERGE_PRICE); - config.set("economy.prices.sell", this.SELL_PRICE); - config.set("chat.enabled", this.PLOT_CHAT); - config.set("flags.default", this.DEFAULT_FLAGS); + + HashMap options = new HashMap(); + + options.put("natural_mob_spawning", PlotWorld.MOB_SPAWNING_DEFAULT); + options.put("plot.auto_merge", PlotWorld.AUTO_MERGE_DEFAULT); + 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); + options.put("flags.default", PlotWorld.DEFAULT_FLAGS_DEFAULT); ConfigurationNode[] settings = getSettingNodes(); @@ -213,7 +218,13 @@ public abstract class PlotWorld { * Saving generator specific settings */ for (ConfigurationNode setting : settings) { - config.set(setting.getConstant(), setting.getValue()); + options.put(setting.getConstant(), setting.getType().parseObject(setting.getValue())); + } + + for (String option:options.keySet()) { + if (!config.contains(option)) { + config.set(option, options.get(option)); + } } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java b/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java index ba0666b9d..8c94c585f 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java @@ -11,12 +11,16 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import com.google.common.base.Charsets; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; import com.intellectualcrafters.plot.uuid.NameFetcher; import com.intellectualcrafters.plot.uuid.UUIDFetcher; public class UUIDHandler { - private static ConcurrentHashMap uuidMap = new ConcurrentHashMap<>(); + private static boolean online = Bukkit.getServer().getOnlineMode(); + + private static BiMap uuidMap = HashBiMap.create(); public static boolean uuidExists(UUID uuid) { return uuidMap.containsValue(uuid); @@ -41,15 +45,15 @@ public class UUIDHandler { public void run() { OfflinePlayer[] offlinePlayers = Bukkit .getOfflinePlayers(); - int lenght = offlinePlayers.length; + int length = offlinePlayers.length; long start = System.currentTimeMillis(); String name; UUID uuid; for (OfflinePlayer player : offlinePlayers) { - name = player.getName(); uuid = player.getUniqueId(); if (!uuidExists(uuid)) { + name = player.getName(); add(name, uuid); } } @@ -58,7 +62,7 @@ public class UUIDHandler { PlotMain.sendConsoleSenderMessage("&cFinished caching of offlineplayers! Took &6" + time + "&cms, &6" - + lenght + + length + " &cUUID's were cached" + " and there is now a grand total of &6" + uuidMap.size() + " &ccached."); @@ -82,7 +86,7 @@ public class UUIDHandler { if ((uuid = getUuidOfflinePlayer(name)) != null) { return uuid; } - if (Bukkit.getOnlineMode()) { + if (online) { try { UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name)); uuid = fetcher.call().get(name); @@ -102,12 +106,7 @@ public class UUIDHandler { * @return */ private static String loopSearch(UUID uuid) { - for (Map.Entry entry : uuidMap.entrySet()) { - if (entry.getValue().equals(uuid)) { - return entry.getKey(); - } - } - return ""; + return uuidMap.inverse().get(uuid); } /** @@ -116,9 +115,9 @@ public class UUIDHandler { * @return */ public static String getName(UUID uuid) { - if (uuidExists(uuid)) { - return loopSearch(uuid); - } + if (uuidExists(uuid)) { + return loopSearch(uuid); + } String name; if ((name = getNameOnlinePlayer(uuid)) != null) { return name; @@ -126,7 +125,7 @@ public class UUIDHandler { if ((name = getNameOfflinePlayer(uuid)) != null) { return name; } - if (Bukkit.getOnlineMode()) { + if (online) { try { NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid)); name = fetcher.call().get(uuid); @@ -204,11 +203,7 @@ public class UUIDHandler { * @return */ private static UUID getUuidOfflinePlayer(String name) { - OfflinePlayer player = Bukkit.getOfflinePlayer(name); - if (player == null || !player.hasPlayedBefore()) { - return null; - } - UUID uuid = player.getUniqueId(); + UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)); add(name, uuid); return uuid; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java index 496728ebd..8b5cbb61d 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java @@ -94,7 +94,7 @@ public class Setup extends SubCommand implements Listener { ConfigurationNode step = object.step[object.current]; if (args.length < 1) { sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", - step.getDescription(), step.getType(), + step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); return true; } else { @@ -108,12 +108,12 @@ public class Setup extends SubCommand implements Listener { object.current--; step = object.step[object.current]; sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", - step.getDescription(), step.getType(), + step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); return true; } else { sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", - step.getDescription(), step.getType(), + step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); return true; } @@ -130,14 +130,14 @@ public class Setup extends SubCommand implements Listener { } step = object.step[object.current]; sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", - step.getDescription(), step.getType(), + step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); return true; } else { sendMessage(plr, C.SETUP_INVALID_ARG, args[0], step.getConstant()); sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", - step.getDescription(), step.getType(), + step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); return true; } @@ -186,7 +186,7 @@ public class Setup extends SubCommand implements Listener { } PlotWorld plotworld; if (generator instanceof PlotGenerator) { - plotworld = ((PlotGenerator) generator).getPlotWorld(); + plotworld = ((PlotGenerator) generator).getNewPlotWorld(world); } else { plotworld = new DefaultPlotWorld(world); @@ -197,7 +197,7 @@ public class Setup extends SubCommand implements Listener { SetupObject object = setupMap.get(plr.getName()); ConfigurationNode step = object.step[object.current]; sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", - step.getDescription(), step.getType(), + step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); return true; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java index 9be96adf7..5afd4ce9f 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Unlink.java @@ -94,16 +94,16 @@ public class Unlink extends SubCommand { new PlotId(x, y); if (lx) { - manager.removeRoadEast(plotworld, plot); + manager.createRoadEast(plotworld, plot); if (ly) { - manager.removeRoadSouthEast(plotworld, plot); + manager.createRoadSouthEast(plotworld, plot); } } if (ly) { - manager.removeRoadSouth(plotworld, plot); + manager.createRoadSouth(plotworld, plot); } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/generator/DefaultPlotManager.java b/PlotSquared/src/com/intellectualcrafters/plot/generator/DefaultPlotManager.java index fc699c820..1095d678b 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/generator/DefaultPlotManager.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/generator/DefaultPlotManager.java @@ -729,8 +729,8 @@ public class DefaultPlotManager extends PlotManager { int sx = pos2.getBlockX(); int ex = (sx + dpw.ROAD_WIDTH); - int sz = pos1.getBlockZ() - 1; - int ez = pos2.getBlockZ() + 2; + int sz = pos1.getBlockZ(); + int ez = pos2.getBlockZ() + 1; PlotHelper.setSimpleCuboid(w, new Location(w, sx, @@ -756,8 +756,8 @@ public class DefaultPlotManager extends PlotManager { int sz = pos2.getBlockZ(); int ez = (sz + dpw.ROAD_WIDTH); - int sx = pos1.getBlockX() - 1; - int ex = pos2.getBlockX() + 2; + int sx = pos1.getBlockX(); + int ex = pos2.getBlockX() + 1; PlotHelper.setSimpleCuboid(w, new Location(w, sx, diff --git a/PlotSquared/src/com/intellectualcrafters/plot/generator/DefaultPlotWorld.java b/PlotSquared/src/com/intellectualcrafters/plot/generator/DefaultPlotWorld.java index 3cf73df15..d2bdbb053 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/generator/DefaultPlotWorld.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/generator/DefaultPlotWorld.java @@ -62,7 +62,7 @@ public class DefaultPlotWorld extends PlotWorld { public static int ROAD_WIDTH_DEFAULT = 7; /** - * Plot biome + * Plot main block */ public PlotBlock[] MAIN_BLOCK; /** @@ -87,7 +87,7 @@ public class DefaultPlotWorld extends PlotWorld { /** * Default wall block: 44 */ - public static String WALL_BLOCK_DEFAULT = "44:0"; + public static PlotBlock WALL_BLOCK_DEFAULT = new PlotBlock((short) 44, (byte) 0); /** * Wall filling @@ -142,32 +142,32 @@ public class DefaultPlotWorld extends PlotWorld { @Override public ConfigurationNode[] getSettingNodes() { // TODO return a set of configuration nodes (used for setup command) - return new ConfigurationNode[] { - new ConfigurationNode("plot.height", this.PLOT_HEIGHT, - "Plot height", Configuration.INTEGER, true), - new ConfigurationNode("plot.width", this.PLOT_WIDTH, - "Plot width", Configuration.INTEGER, true), - new ConfigurationNode("plot.filling", this.MAIN_BLOCK, - "Plot block", Configuration.BLOCKLIST, true), - new ConfigurationNode("plot.floor", this.TOP_BLOCK, - "Plot floor block", Configuration.BLOCKLIST, true), - new ConfigurationNode("wall.block", this.WALL_BLOCK, - "Top wall block", Configuration.BLOCK, true), - new ConfigurationNode("road.width", this.ROAD_WIDTH, - "Road width", Configuration.INTEGER, true), - new ConfigurationNode("road.height", this.ROAD_HEIGHT, - "Road height", Configuration.INTEGER, true), - new ConfigurationNode("road.enable_stripes", - this.ROAD_STRIPES_ENABLED, "Enable road stripes", - Configuration.BOOLEAN, true), - new ConfigurationNode("road.block", this.ROAD_BLOCK, - "Road block", Configuration.BLOCK, true), - new ConfigurationNode("road.stripes", this.ROAD_STRIPES, - "Road stripe block", Configuration.BLOCK, true), - new ConfigurationNode("wall.filling", this.WALL_FILLING, - "Wall filling block", Configuration.BLOCK, true), - new ConfigurationNode("wall.height", this.WALL_HEIGHT, - "Wall height", Configuration.INTEGER, true), }; + return new ConfigurationNode[] { + new ConfigurationNode("plot.height", DefaultPlotWorld.PLOT_HEIGHT_DEFAULT, + "Plot height", Configuration.INTEGER, true), + new ConfigurationNode("plot.width", DefaultPlotWorld.PLOT_WIDTH_DEFAULT, + "Plot width", Configuration.INTEGER, true), + new ConfigurationNode("plot.filling", DefaultPlotWorld.MAIN_BLOCK_DEFAULT, + "Plot block", Configuration.BLOCKLIST, true), + new ConfigurationNode("plot.floor", DefaultPlotWorld.TOP_BLOCK_DEFAULT, + "Plot floor block", Configuration.BLOCKLIST, true), + new ConfigurationNode("wall.block", DefaultPlotWorld.WALL_BLOCK_DEFAULT, + "Top wall block", Configuration.BLOCK, true), + new ConfigurationNode("road.width", DefaultPlotWorld.ROAD_WIDTH_DEFAULT, + "Road width", Configuration.INTEGER, true), + new ConfigurationNode("road.height", DefaultPlotWorld.ROAD_HEIGHT_DEFAULT, + "Road height", Configuration.INTEGER, true), + new ConfigurationNode("road.enable_stripes", + DefaultPlotWorld.ROAD_STRIPES_ENABLED_DEFAULT, "Enable road stripes", + Configuration.BOOLEAN, true), + new ConfigurationNode("road.block", DefaultPlotWorld.ROAD_BLOCK_DEFAULT, + "Road block", Configuration.BLOCK, true), + new ConfigurationNode("road.stripes", DefaultPlotWorld.ROAD_STRIPES_DEFAULT, + "Road stripe block", Configuration.BLOCK, true), + new ConfigurationNode("wall.filling", DefaultPlotWorld.WALL_FILLING_DEFAULT, + "Wall filling block", Configuration.BLOCK, true), + new ConfigurationNode("wall.height", DefaultPlotWorld.WALL_HEIGHT_DEFAULT, + "Wall height", Configuration.INTEGER, true), }; } /* @@ -177,7 +177,6 @@ public class DefaultPlotWorld extends PlotWorld { */ @Override public void loadConfiguration(ConfigurationSection config) { - this.PLOT_HEIGHT = config.getInt("plot.height"); this.PLOT_WIDTH = config.getInt("plot.width"); this.MAIN_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST diff --git a/PlotSquared/src/com/intellectualcrafters/plot/generator/WorldGenerator.java b/PlotSquared/src/com/intellectualcrafters/plot/generator/WorldGenerator.java index f6c6e04d7..1c34af947 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/generator/WorldGenerator.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/generator/WorldGenerator.java @@ -44,19 +44,19 @@ public class WorldGenerator extends PlotGenerator { /* * Some generator specific variables (implementation dependent) */ - int plotsize; - int pathsize; - PlotBlock wall; - PlotBlock wallfilling; - PlotBlock floor1; - PlotBlock floor2; - int size; - Biome biome; - int roadheight; - int wallheight; - int plotheight; - PlotBlock[] plotfloors; - PlotBlock[] filling; + final int plotsize; + final int pathsize; + final PlotBlock wall; + final PlotBlock wallfilling; + final PlotBlock floor1; + final PlotBlock floor2; + final int size; + final Biome biome; + final int roadheight; + final int wallheight; + final int plotheight; + final PlotBlock[] plotfloors; + final PlotBlock[] filling; /* * Return the plot manager for this type of generator, or create one @@ -66,14 +66,15 @@ public class WorldGenerator extends PlotGenerator { if (manager == null) { manager = new DefaultPlotManager(); } - return null; + return manager; } // return the PlotWorld @Override - public PlotWorld getPlotWorld() { - return this.plotworld; + public PlotWorld getNewPlotWorld(String world) { + this.plotworld = new DefaultPlotWorld(world); + return this.plotworld; } /* @@ -104,19 +105,17 @@ public class WorldGenerator extends PlotGenerator { * inside the loop - You don't have to use this this method, but you may * find it useful. */ - public void setCuboidRegion(int x1, int x2, int y1, int y2, int z1, int z2, - PlotBlock block) { + public void setCuboidRegion(int x1, int x2, int y1, int y2, int z1, int z2, PlotBlock block) { for (int x = x1; x < x2; x++) { for (int z = z1; z < z2; z++) { for (int y = y1; y < y2; y++) { - setBlock(this.result, x, y, z, block.data); + setBlock(this.result, x, y, z, block.id); } } } } - private void setCuboidRegion(int x1, int x2, int y1, int y2, int z1, - int z2, PlotBlock[] blocks) { + private void setCuboidRegion(int x1, int x2, int y1, int y2, int z1, int z2, PlotBlock[] blocks) { if (blocks.length == 1) { setCuboidRegion(x1, x2, y1, y2, z1, z2, blocks[0]); } else { @@ -145,9 +144,9 @@ public class WorldGenerator extends PlotGenerator { * Initialize variables, and create plotworld object used in calculations */ public WorldGenerator(String world) { - this.plotworld = new DefaultPlotWorld(world); - + super(world); this.plotsize = this.plotworld.PLOT_WIDTH; + this.pathsize = this.plotworld.ROAD_WIDTH; this.floor1 = this.plotworld.ROAD_BLOCK; @@ -197,25 +196,23 @@ public class WorldGenerator extends PlotGenerator { * like to learn how to make a world generator */ @Override - public short[][] generateExtBlockSections(World world, Random random, - int cx, int cz, BiomeGrid biomes) { - + public short[][] generateExtBlockSections(World world, Random random, int cx, int cz, BiomeGrid biomes) { + + int maxY = world.getMaxHeight(); + this.result = new short[maxY / 16][]; + final int prime = 31; int h = 1; h = (prime * h) + cx; h = (prime * h) + cz; this.state = h; - - int maxY = world.getMaxHeight(); - - this.result = new short[maxY / 16][]; + double pathWidthLower; if ((this.pathsize % 2) == 0) { pathWidthLower = Math.floor(this.pathsize / 2) - 1; } else { pathWidthLower = Math.floor(this.pathsize / 2); } - cx = (cx % this.size) + (8 * this.size); cz = (cz % this.size) + (8 * this.size); int absX = (int) ((((cx * 16) + 16) - pathWidthLower - 1) + (8 * this.size)); @@ -230,7 +227,7 @@ public class WorldGenerator extends PlotGenerator { if (roadStartZ >= this.size) { roadStartZ -= this.size; } - + // BOTTOM (1/1 cuboids) for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { @@ -240,7 +237,6 @@ public class WorldGenerator extends PlotGenerator { } // ROAD (0/24) The following is an inefficient placeholder as it is too // much work to finish it - if ((this.pathsize > 16) && ((plotMinX > roadStartX) || (plotMinZ > roadStartZ)) && !((roadStartX < 16) && (roadStartZ < 16)) @@ -248,7 +244,6 @@ public class WorldGenerator extends PlotGenerator { setCuboidRegion(0, 16, 1, this.roadheight + 1, 0, 16, this.floor1); return this.result; } - if (((plotMinZ + 1) <= 16) || ((roadStartZ <= 16) && (roadStartZ > 0))) { int start = Math.max((16 - plotMinZ - this.pathsize) + 1, (16 - roadStartZ) + 1);