From e0c5c285bbdb885445e9057574084efa0e02a5f7 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 2 Oct 2014 18:21:34 +1000 Subject: [PATCH] Finished setup command --- .../src/com/intellectualcrafters/plot/C.java | 6 +- .../intellectualcrafters/plot/PlotHelper.java | 47 ++-- .../intellectualcrafters/plot/PlotMain.java | 11 + .../plot/WorldGenerator.java | 8 +- .../plot/commands/MainCommand.java | 2 +- .../plot/commands/Setup.java | 251 ++++++++++++------ 6 files changed, 218 insertions(+), 107 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/C.java b/PlotSquared/src/com/intellectualcrafters/plot/C.java index 24cec7376..941c68604 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/C.java @@ -29,11 +29,11 @@ public enum C { */ SETUP_INIT("&6PlotSquared Setup -> Setup a new plotworld"), SETUP_STEP("&cStep &6%s&c: %s &c"), - SETUP_INVALID_ARG("&c%s is not a valid argument for step %s"), + SETUP_INVALID_ARG("&c%s is not a valid argument for step %s. To cancel setup use: /plot setup cancel"), SETUP_VALID_ARG("&cValue &6%s &cset for step %s"), - SETUP_FINISHED("&cFinished setup for world &c%s"), + SETUP_FINISHED("&cFinished setup for world &c%s. To create it, type &6/plots setup create"), SETUP_WORLD_TAKEN("&c%s is already a registered plotworld"), - SETUP_MISSING_WORLD("&cYou need to specify a world name (&6/p setup {world}&c)"), + SETUP_MISSING_WORLD("&cYou need to specify a world name (&6/p setup {world}&c)\n&6Additional commands:\n&c - &6/p setup \n&c - &6/p setup back\n&c - &6/p setup cancel"), /* * Schematic Stuff */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java index d8bc45812..f64b6acb0 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java @@ -16,8 +16,11 @@ import com.sk89q.worldedit.blocks.ClothColor.ID; import org.bukkit.*; import org.bukkit.block.Biome; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.Sign; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.material.MaterialData; import java.util.*; @@ -31,21 +34,6 @@ public class PlotHelper { public static boolean canSetFast = false; static long state = 1; - /** - * - * @param blocks - * @param blocks_per_second - * @return - */ - public PlotHelper() { - try { - new SetBlockFast(); - canSetFast = true; - } catch (Exception e) { - canSetFast = false; - } - } - private static double calculateNeededTime(double blocks, double blocks_per_second) { return (blocks / blocks_per_second); } @@ -740,6 +728,27 @@ public class PlotHelper { return new short[] { Short.parseShort(block), 0 }; } + public static void clearAllEntities(World world, Plot plot, boolean tile) { + final Location pos1 = getPlotBottomLoc(world, plot.id).add(1, 0, 1); + final Location pos2 = getPlotTopLoc(world, plot.id); + for (int i = (pos1.getBlockX() / 16) * 16; i < 16+(pos2.getBlockX() / 16) * 16; i += 16) { + for (int j = (pos1.getBlockZ() / 16) * 16; j < 16+(pos2.getBlockZ() / 16) * 16; j += 16) { + Chunk chunk = world.getChunkAt(i, j); + for (Entity entity:chunk.getEntities()) { + PlotId id = PlayerFunctions.getPlot(entity.getLocation()); + if (id!=null && id.equals(plot.id)) { + entity.remove(); + } + } + if (tile) { + for (BlockState entity:chunk.getTileEntities()) { + entity.setRawData((byte) 0); + } + } + } + } + } + /** * Clear a plot * @param requester @@ -750,10 +759,14 @@ public class PlotHelper { // TODO teleport any players underground to the surface final long start = System.nanoTime(); - final PlotWorld plotworld = PlotMain.getWorldSettings(Bukkit.getWorld(plot.world)); + final World world = requester.getWorld(); + + // clear entities: + clearAllEntities(world, plot, false); + + final PlotWorld plotworld = PlotMain.getWorldSettings(world); PlotHelper.setBiome(requester.getWorld(), plot, Biome.FOREST); PlayerFunctions.sendMessage(requester, C.CLEARING_PLOT); - final World world = requester.getWorld(); final Location pos1 = getPlotBottomLoc(world, plot.id).add(1, 0, 1); final Location pos2 = getPlotTopLoc(world, plot.id); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index d59165a0c..b77766482 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -10,6 +10,7 @@ package com.intellectualcrafters.plot; import ca.mera.CameraAPI; + import com.intellectualcrafters.plot.Logger.LogLevel; import com.intellectualcrafters.plot.Settings.Web; import com.intellectualcrafters.plot.commands.Camera; @@ -25,8 +26,10 @@ import com.intellectualcrafters.plot.listeners.WorldEditListener; import com.intellectualcrafters.plot.listeners.WorldGuardListener; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; + import me.confuser.barapi.BarAPI; import net.milkbowl.vault.economy.Economy; + import org.bukkit.*; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Entity; @@ -603,6 +606,14 @@ public class PlotMain extends JavaPlugin { if (Web.ENABLED) { sendConsoleSenderMessage(C.PREFIX.s() + "Web Is not implemented yet. Please bear with us."); } + + try { + new SetBlockFast(); + PlotHelper.canSetFast = true; + } catch (Exception e) { + PlotHelper.canSetFast = false; + } + } /** diff --git a/PlotSquared/src/com/intellectualcrafters/plot/WorldGenerator.java b/PlotSquared/src/com/intellectualcrafters/plot/WorldGenerator.java index 97b283a90..803d4046d 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/WorldGenerator.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/WorldGenerator.java @@ -92,9 +92,10 @@ public class WorldGenerator extends ChunkGenerator { options.put("worlds." + world + ".flags.default", DEFAULT_FLAGS_DEFAULT); options.put("worlds." + world + ".schematic.schematics", plotworld.SCHEMATICS); options.put("worlds." + world + ".schematic.specify_on_claim", plotworld.SCHEMATIC_CLAIM_SPECIFY); - options.put("worlds." + world + ".economy.use", plotworld.USE_ECONOMY); - options.put("worlds." + world + ".economy.prices.claim", plotworld.PLOT_PRICE); - options.put("worlds." + world + ".economy.prices.merge", plotworld.MERGE_PRICE); + options.put("worlds." + world + ".economy.use", plotworld.USE_ECONOMY); // Access should be static + options.put("worlds." + world + ".economy.prices.claim", plotworld.PLOT_PRICE); // Access should be static + options.put("worlds." + world + ".economy.prices.merge", plotworld.MERGE_PRICE); // Access should be static + options.put("worlds." + world + ".chat.enabled", PLOT_CHAT_DEFAULT); for (Entry node : options.entrySet()) { if (!config.contains(node.getKey())) { config.set(node.getKey(), node.getValue()); @@ -127,6 +128,7 @@ public class WorldGenerator extends ChunkGenerator { this.plotworld.USE_ECONOMY = config.getBoolean("worlds." + world + ".economy.use"); this.plotworld.PLOT_PRICE = config.getDouble("worlds." + world + ".economy.prices.claim"); this.plotworld.MERGE_PRICE = config.getDouble("worlds." + world + ".economy.prices.merge"); + this.plotworld.PLOT_CHAT = config.getBoolean("worlds." + world + ".chat.enabled"); String[] default_flags_string = config.getStringList("worlds." + world + ".flags.default").toArray(new String[0]); Flag[] default_flags = new Flag[default_flags_string.length]; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java index 180202a3b..ce9d70571 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/MainCommand.java @@ -30,7 +30,7 @@ import com.intellectualcrafters.plot.PlotMain; */ public class MainCommand implements CommandExecutor { - private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Reload(), new Merge(), new Unlink(), new Kick() }; + private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Reload(), new Merge(), new Unlink(), new Kick(), new Setup() }; public static ArrayList subCommands = new ArrayList() { { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java index e3f13ef2f..45329c38a 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Setup.java @@ -1,18 +1,46 @@ package com.intellectualcrafters.plot.commands; +import static com.intellectualcrafters.plot.PlotWorld.AUTO_MERGE_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.DEFAULT_FLAGS_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.MAIN_BLOCK_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.PLOT_BIOME_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.PLOT_HEIGHT_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.PLOT_WIDTH_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.ROAD_BLOCK_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.ROAD_HEIGHT_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.ROAD_STRIPES_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.ROAD_STRIPES_ENABLED_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.ROAD_WIDTH_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.SCHEMATIC_FILE_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.SCHEMATIC_ON_CLAIM_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.TOP_BLOCK_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.WALL_BLOCK_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.WALL_FILLING_DEFAULT; +import static com.intellectualcrafters.plot.PlotWorld.WALL_HEIGHT_DEFAULT; + import com.intellectualcrafters.plot.C; +import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotWorld; import com.intellectualcrafters.plot.WorldGenerator; +import com.intellectualcrafters.plot.listeners.PlayerEvents; +import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.WorldCreator; +import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType; + +import java.io.IOException; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -28,56 +56,102 @@ public class Setup extends SubCommand implements Listener { private Object default_value; private String description; private Object value = 0; - private Class type; - public SetupStep(String constant, Object default_value, String description, Class type) { + private String type; + private boolean require_previous; + public SetupStep(String constant, Object default_value, String description, String type, boolean require_previous) { this.constant = constant; this.default_value = default_value; this.description = description; this.type = type; + this.require_previous = require_previous; + } + public boolean getRequire() { + return this.require_previous; + } + + public String getType() { + return this.type; } - public Class getType() { - if (this.type == Integer.class) { - return Integer.class; + public boolean setValue(String string) { + if (!validValue(string)) { + return false; } - if (this.type == Boolean.class) { - return Boolean.class; + switch (this.type) { + case "integer": + value = Integer.parseInt(string); + break; + case "boolean": + value = Boolean.parseBoolean(string); + break; + case "double": + value = Double.parseDouble(string); + break; + case "float": + value = Float.parseFloat(string); + break; + case "biome": + value = Biome.valueOf(string.toUpperCase()); + break; + case "block": + value = string; + break; + case "blocklist": + value = string.split(","); + break; + case "string": + value = string; + break; } - if (this.type == Double.class) { - return Double.class; - } - if (this.type == Float.class) { - return Float.class; - } - if (this.type == String.class) { - return String.class; - } - return Object.class; - } - - public boolean setValue(Object o) { return true; } - public boolean validValue(String string) { try { - if (this.type == Integer.class) { + if (this.type.equals("integer")) { Integer.parseInt(string); return true; } - if (this.type == Boolean.class) { + if (this.type.equals("boolean")) { Boolean.parseBoolean(string); return true; } - if (this.type == Double.class) { + if (this.type.equals("double")) { Double.parseDouble(string); return true; } - if (this.type == Float.class) { + if (this.type.equals("float")) { Float.parseFloat(string); return true; } - if (this.type == String.class) { + if (this.type.equals("biome")) { + Biome.valueOf(string.toUpperCase()); + return true; + } + if (this.type.equals("block")) { + if (string.contains(":")) { + String[] split = string.split(":"); + Short.parseShort(split[0]); + Short.parseShort(split[1]); + } + else { + Short.parseShort(string); + } + return true; + } + if (this.type.equals("blocklist")) { + for (String block:string.split(",")) { + if (block.contains(":")) { + String[] split = block.split(":"); + Short.parseShort(split[0]); + Short.parseShort(split[1]); + } + else { + Short.parseShort(block); + } + } + return true; + } + if (this.type.equals("string")) { return true; } } @@ -105,34 +179,26 @@ public class Setup extends SubCommand implements Listener { private class SetupObject { String world; int current = 0; - PlotWorld p; - /* - ROAD_HEIGHT - Integer - PLOT_HEIGHT - Integer - WALL_HEIGHT - Integer - PLOT_WIDTH - Integer - ROAD_WIDTH - Integer - PLOT_BIOME - BIOME - MAIN_BLOCK - Block[] (as you can have several blocks, with IDS) - TOP_BLOCK - Block[] (as you can have several blocks, with IDS) - WALL_BLOCK - Block - WALL_FILLING - Block - ROAD_STRIPES - Block - ROAD_STRIPES_ENABLED - Boolean - ROAD_BLOCK - Block - PLOT_CHAT - Boolean - BLOCKS - wtf is this? - SCHEMATIC_ON_CLAIM - Boolean - SCHEMATIC_FILE - String - DEFAULT_FLAGS - String[] - */ - SetupStep[] step = new SetupStep[] { new SetupStep("road_height", 64, "Height of road", Integer.class) }; - + + SetupStep[] step = new SetupStep[] { + new SetupStep("road.height", PlotWorld.ROAD_HEIGHT_DEFAULT, "Height of road", "integer", false), + new SetupStep("plot.height", PlotWorld.PLOT_HEIGHT_DEFAULT, "Height of plot", "integer", false), + new SetupStep("wall.height", PlotWorld.WALL_HEIGHT_DEFAULT, "Height of wall", "integer", false), + new SetupStep("plot.size", PlotWorld.PLOT_WIDTH_DEFAULT, "Size of plot", "integer", false), + new SetupStep("road.width", PlotWorld.ROAD_WIDTH_DEFAULT, "Width of road", "integer", false), + new SetupStep("plot.biome", PlotWorld.PLOT_BIOME_DEFAULT, "Plot biome", "biome", false), + new SetupStep("plot.filling", PlotWorld.MAIN_BLOCK_DEFAULT, "Plot filling", "blocklist", false), + new SetupStep("plot.floor", PlotWorld.TOP_BLOCK_DEFAULT, "Plot floor", "blocklist", false), + new SetupStep("wall.block", PlotWorld.WALL_BLOCK_DEFAULT, "Wall block", "block", false), + new SetupStep("wall.filling", PlotWorld.WALL_FILLING_DEFAULT, "Wall filling", "block", false), + new SetupStep("road.enable_stripes", PlotWorld.ROAD_STRIPES_ENABLED_DEFAULT, "Enable road stripes", "boolean", false), + new SetupStep("road.stripes", PlotWorld.ROAD_STRIPES_DEFAULT, "Road stripes block", "block", true), + new SetupStep("road.block", PlotWorld.ROAD_BLOCK_DEFAULT, "Road block", "block", false), + }; public SetupObject(String world) { this.world = world; - this.p = new PlotWorld(); } - + public SetupStep getNextStep() { return this.step[current++]; } @@ -140,6 +206,10 @@ public class Setup extends SubCommand implements Listener { public int getCurrent() { return this.current; } + + public void setCurrent(String string) { + this.step[current].setValue(string); + } public int getMax() { return this.step.length; @@ -150,55 +220,63 @@ public class Setup extends SubCommand implements Listener { super("setup", "plots.admin", "Setup a PlotWorld", "/plot setup {world}", "setup", CommandCategory.ACTIONS); } - /* - * /plot setup {world} - setup a world using default values - * (display current default settings) - * (use ordinary chat to get/set) - *