2014-09-26 22:53:42 +02:00
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2014-10-02 18:21:34 +10:00
|
|
|
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;
|
|
|
|
|
2014-09-26 22:53:42 +02:00
|
|
|
import com.intellectualcrafters.plot.C;
|
2014-10-02 18:21:34 +10:00
|
|
|
import com.intellectualcrafters.plot.PlayerFunctions;
|
2014-09-26 22:53:42 +02:00
|
|
|
import com.intellectualcrafters.plot.PlotMain;
|
|
|
|
import com.intellectualcrafters.plot.PlotWorld;
|
2014-10-02 14:35:20 +10:00
|
|
|
import com.intellectualcrafters.plot.WorldGenerator;
|
2014-10-02 18:21:34 +10:00
|
|
|
import com.intellectualcrafters.plot.listeners.PlayerEvents;
|
2014-10-02 14:35:20 +10:00
|
|
|
|
2014-10-02 18:21:34 +10:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2014-09-26 22:53:42 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2014-10-02 14:35:20 +10:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.WorldCreator;
|
2014-10-02 18:21:34 +10:00
|
|
|
import org.bukkit.block.Biome;
|
2014-10-02 14:35:20 +10:00
|
|
|
import org.bukkit.block.Block;
|
2014-09-26 22:53:42 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2014-10-02 18:21:34 +10:00
|
|
|
import org.bukkit.event.EventHandler;
|
2014-09-26 22:53:42 +02:00
|
|
|
import org.bukkit.event.Listener;
|
2014-10-02 18:21:34 +10:00
|
|
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
|
|
|
|
|
|
import sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType;
|
2014-09-26 22:53:42 +02:00
|
|
|
|
2014-10-02 18:21:34 +10:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Arrays;
|
2014-09-26 22:53:42 +02:00
|
|
|
import java.util.HashMap;
|
2014-10-02 22:30:25 +10:00
|
|
|
import java.util.List;
|
2014-09-26 22:53:42 +02:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Citymonstret on 2014-09-26.
|
|
|
|
*/
|
|
|
|
public class Setup extends SubCommand implements Listener {
|
|
|
|
|
|
|
|
public static Map<String, SetupObject> setupMap = new HashMap<>();
|
|
|
|
|
|
|
|
private static class SetupStep {
|
|
|
|
private String constant;
|
|
|
|
private Object default_value;
|
|
|
|
private String description;
|
|
|
|
private Object value = 0;
|
2014-10-02 18:21:34 +10:00
|
|
|
private String type;
|
|
|
|
private boolean require_previous;
|
|
|
|
public SetupStep(String constant, Object default_value, String description, String type, boolean require_previous) {
|
2014-09-26 22:53:42 +02:00
|
|
|
this.constant = constant;
|
|
|
|
this.default_value = default_value;
|
|
|
|
this.description = description;
|
2014-09-28 10:21:18 +02:00
|
|
|
this.type = type;
|
2014-10-02 18:21:34 +10:00
|
|
|
this.require_previous = require_previous;
|
|
|
|
}
|
|
|
|
public boolean getRequire() {
|
|
|
|
return this.require_previous;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getType() {
|
|
|
|
return this.type;
|
2014-09-28 10:21:18 +02:00
|
|
|
}
|
|
|
|
|
2014-10-02 18:21:34 +10:00
|
|
|
public boolean setValue(String string) {
|
|
|
|
if (!validValue(string)) {
|
|
|
|
return false;
|
2014-10-02 14:35:20 +10:00
|
|
|
}
|
2014-10-02 18:21:34 +10:00
|
|
|
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":
|
2014-10-02 22:30:25 +10:00
|
|
|
value = (string.toUpperCase());
|
2014-10-02 18:21:34 +10:00
|
|
|
break;
|
|
|
|
case "block":
|
|
|
|
value = string;
|
|
|
|
break;
|
|
|
|
case "blocklist":
|
|
|
|
value = string.split(",");
|
|
|
|
break;
|
|
|
|
case "string":
|
|
|
|
value = string;
|
|
|
|
break;
|
2014-10-02 14:35:20 +10:00
|
|
|
}
|
2014-09-28 10:21:18 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
public boolean validValue(String string) {
|
2014-10-02 14:35:20 +10:00
|
|
|
try {
|
2014-10-02 18:21:34 +10:00
|
|
|
if (this.type.equals("integer")) {
|
2014-10-02 14:35:20 +10:00
|
|
|
Integer.parseInt(string);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-02 18:21:34 +10:00
|
|
|
if (this.type.equals("boolean")) {
|
2014-10-02 14:35:20 +10:00
|
|
|
Boolean.parseBoolean(string);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-02 18:21:34 +10:00
|
|
|
if (this.type.equals("double")) {
|
2014-10-02 14:35:20 +10:00
|
|
|
Double.parseDouble(string);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-02 18:21:34 +10:00
|
|
|
if (this.type.equals("float")) {
|
2014-10-02 14:35:20 +10:00
|
|
|
Float.parseFloat(string);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-02 18:21:34 +10:00
|
|
|
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")) {
|
2014-10-02 14:35:20 +10:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e) {}
|
|
|
|
return false;
|
2014-09-26 22:53:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Object getValue() {
|
2014-10-02 22:30:25 +10:00
|
|
|
if (this.value instanceof String[]) {
|
|
|
|
return (List<String>)(List<?>) Arrays.asList((String[]) this.value);
|
|
|
|
}
|
2014-09-26 22:53:42 +02:00
|
|
|
return this.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getConstant() {
|
|
|
|
return this.constant;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object getDefaultValue() {
|
2014-10-02 22:30:25 +10:00
|
|
|
if (this.default_value instanceof String[]) {
|
|
|
|
return StringUtils.join((String[]) this.default_value,",");
|
|
|
|
}
|
2014-09-26 22:53:42 +02:00
|
|
|
return this.default_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDescription() {
|
|
|
|
return this.description;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-28 10:21:18 +02:00
|
|
|
private class SetupObject {
|
|
|
|
String world;
|
|
|
|
int current = 0;
|
2014-10-02 18:21:34 +10:00
|
|
|
|
|
|
|
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),
|
|
|
|
};
|
2014-09-26 22:53:42 +02:00
|
|
|
public SetupObject(String world) {
|
|
|
|
this.world = world;
|
|
|
|
}
|
2014-10-02 18:21:34 +10:00
|
|
|
|
2014-09-26 22:53:42 +02:00
|
|
|
public SetupStep getNextStep() {
|
|
|
|
return this.step[current++];
|
|
|
|
}
|
|
|
|
|
2014-09-28 10:21:18 +02:00
|
|
|
public int getCurrent() {
|
|
|
|
return this.current;
|
|
|
|
}
|
2014-10-02 18:21:34 +10:00
|
|
|
|
|
|
|
public void setCurrent(String string) {
|
|
|
|
this.step[current].setValue(string);
|
|
|
|
}
|
2014-09-26 22:53:42 +02:00
|
|
|
|
|
|
|
public int getMax() {
|
|
|
|
return this.step.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Setup() {
|
|
|
|
super("setup", "plots.admin", "Setup a PlotWorld", "/plot setup {world}", "setup", CommandCategory.ACTIONS);
|
|
|
|
}
|
2014-10-02 14:35:20 +10:00
|
|
|
|
2014-09-26 22:53:42 +02:00
|
|
|
@Override
|
|
|
|
public boolean execute(Player plr, String... args) {
|
2014-09-28 10:21:18 +02:00
|
|
|
if(setupMap.containsKey(plr.getName())) {
|
|
|
|
SetupObject object = setupMap.get(plr.getName());
|
|
|
|
if(object.getCurrent() == object.getMax()) {
|
|
|
|
sendMessage(plr, C.SETUP_FINISHED, object.world);
|
2014-10-02 14:35:20 +10:00
|
|
|
|
2014-10-02 18:21:34 +10:00
|
|
|
SetupStep[] steps = object.step;
|
|
|
|
String world = object.world;
|
|
|
|
for (SetupStep step:steps) {
|
2014-10-02 22:30:25 +10:00
|
|
|
PlotMain.config.set("worlds."+world+"."+step.constant, step.getValue());
|
2014-10-02 18:21:34 +10:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
PlotMain.config.save(PlotMain.configFile);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2014-10-02 14:35:20 +10:00
|
|
|
|
2014-10-02 22:30:25 +10:00
|
|
|
// World newWorld = WorldCreator.name(world).generator(new WorldGenerator(world)).createWorld();
|
|
|
|
// plr.teleport(newWorld.getSpawnLocation());
|
2014-10-02 18:21:34 +10:00
|
|
|
|
|
|
|
setupMap.remove(plr.getName());
|
2014-10-02 14:35:20 +10:00
|
|
|
|
2014-09-28 10:21:18 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
SetupStep step = object.step[object.current];
|
|
|
|
if(args.length < 1) {
|
2014-10-02 18:21:34 +10:00
|
|
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + "");
|
2014-09-28 10:21:18 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
2014-10-02 18:21:34 +10:00
|
|
|
if (args[0].equalsIgnoreCase("cancel")) {
|
|
|
|
setupMap.remove(plr.getName());
|
|
|
|
PlayerFunctions.sendMessage(plr, "&cCancelled setup.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (args[0].equalsIgnoreCase("back")) {
|
|
|
|
if (object.current>0) {
|
|
|
|
object.current--;
|
|
|
|
step = object.step[object.current];
|
|
|
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + "");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + "");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-09-28 10:21:18 +02:00
|
|
|
boolean valid = step.validValue(args[0]);
|
|
|
|
if(valid) {
|
2014-10-02 18:21:34 +10:00
|
|
|
sendMessage(plr, C.SETUP_VALID_ARG, step.getConstant(), args[0]);
|
|
|
|
step.setValue(args[0]);
|
2014-09-28 10:21:18 +02:00
|
|
|
object.current++;
|
2014-10-02 22:30:25 +10:00
|
|
|
if(object.getCurrent() == object.getMax()) {
|
|
|
|
execute(plr, args);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-02 18:21:34 +10:00
|
|
|
step = object.step[object.current];
|
|
|
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + "");
|
2014-10-02 22:30:25 +10:00
|
|
|
return true;
|
2014-09-28 10:21:18 +02:00
|
|
|
} else {
|
2014-10-02 18:21:34 +10:00
|
|
|
sendMessage(plr, C.SETUP_INVALID_ARG, args[0], step.getConstant());
|
|
|
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + "");
|
2014-10-02 22:30:25 +10:00
|
|
|
return true;
|
2014-09-28 10:21:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (args.length < 1) {
|
|
|
|
sendMessage(plr, C.SETUP_MISSING_WORLD);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
String world = args[0];
|
2014-10-02 18:21:34 +10:00
|
|
|
if (StringUtils.isNumeric(args[0])) {
|
|
|
|
sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (PlotMain.getWorldSettings(world)!=null) {
|
2014-09-28 10:21:18 +02:00
|
|
|
sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
setupMap.put(plr.getName(), new SetupObject(world));
|
|
|
|
sendMessage(plr, C.SETUP_INIT);
|
2014-10-02 18:21:34 +10:00
|
|
|
SetupObject object = setupMap.get(plr.getName());
|
|
|
|
SetupStep step = object.step[object.current];
|
|
|
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + "");
|
2014-09-26 22:53:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|