PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java

256 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 /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
2015-04-21 14:48:18 +02:00
import java.util.ArrayList;
2015-02-10 07:14:55 +01:00
import java.util.Arrays;
import java.util.List;
2015-04-21 14:48:18 +02:00
import java.util.Map.Entry;
2015-02-23 01:50:05 +01:00
2014-10-02 10:21:34 +02:00
import org.apache.commons.lang.StringUtils;
2015-04-21 14:48:18 +02:00
import org.bukkit.generator.ChunkGenerator;
2014-10-02 10:21:34 +02:00
2015-01-13 17:38:15 +01:00
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.ConfigurationNode;
2015-02-10 10:50:27 +01:00
import com.intellectualcrafters.plot.config.Settings;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.generator.HybridGen;
import com.plotsquared.bukkit.object.PlotGenerator;
2015-02-21 12:38:44 +01:00
import com.intellectualcrafters.plot.object.PlotPlayer;
2015-02-22 14:12:32 +01:00
import com.intellectualcrafters.plot.object.SetupObject;
2015-02-22 13:40:36 +01:00
import com.intellectualcrafters.plot.util.BlockManager;
2015-02-21 12:38:44 +01:00
import com.intellectualcrafters.plot.util.MainUtil;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.util.SetupUtils;
2015-02-10 07:14:55 +01:00
public class Setup extends SubCommand {
2014-11-05 04:42:08 +01:00
public Setup() {
2015-05-14 19:27:37 +02:00
super("setup", "plots.admin.command.setup", "Plotworld setup command", "setup", "create", CommandCategory.ACTIONS, false);
2015-02-10 07:14:55 +01:00
}
2015-04-21 14:48:18 +02:00
public void displayGenerators(PlotPlayer plr) {
2015-04-30 06:46:24 +02:00
StringBuffer message = new StringBuffer();
message.append("&6What generator do you want?");
2015-04-21 14:48:18 +02:00
for (Entry<String, ChunkGenerator> entry : SetupUtils.generators.entrySet()) {
if (entry.getKey().equals("PlotSquared")) {
2015-05-15 18:23:59 +02:00
message.append("\n&8 - &2" + entry.getKey() + " (Default Generator)");
2015-04-21 14:48:18 +02:00
}
else if (entry.getValue() instanceof HybridGen) {
2015-05-01 14:42:10 +02:00
message.append("\n&8 - &7" + entry.getKey() + " (Hybrid Generator)");
2015-04-21 14:48:18 +02:00
}
else if (entry.getValue() instanceof PlotGenerator) {
2015-05-01 14:42:10 +02:00
message.append("\n&8 - &7" + entry.getKey() + " (Plot Generator)");
2015-04-21 14:48:18 +02:00
}
else {
2015-05-01 14:42:10 +02:00
message.append("\n&8 - &7" + entry.getKey() + " (Unknown structure)");
2015-04-21 14:48:18 +02:00
}
}
2015-04-30 06:46:24 +02:00
MainUtil.sendMessage(plr, message.toString());
2015-04-21 14:48:18 +02:00
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
@Override
2015-02-21 08:30:55 +01:00
public boolean execute(final PlotPlayer plr, final String... args) {
2015-02-10 07:14:55 +01:00
// going through setup
2015-05-14 19:27:37 +02:00
String name;
if (plr == null) {
name = "*";
}
else {
name = plr.getName();
}
2015-02-22 14:12:32 +01:00
if (!SetupUtils.setupMap.containsKey(name)) {
2015-02-20 07:34:19 +01:00
final SetupObject object = new SetupObject();
2015-02-22 14:12:32 +01:00
SetupUtils.setupMap.put(name, object);
SetupUtils.manager.updateGenerators();
2015-02-10 07:14:55 +01:00
sendMessage(plr, C.SETUP_INIT);
2015-04-21 14:48:18 +02:00
displayGenerators(plr);
2015-02-10 07:14:55 +01:00
return false;
2014-11-05 04:42:08 +01:00
}
2015-02-10 07:14:55 +01:00
if (args.length == 1) {
if (args[0].equalsIgnoreCase("cancel")) {
2015-05-14 19:27:37 +02:00
SetupUtils.setupMap.remove(name);
2015-02-21 12:24:46 +01:00
MainUtil.sendMessage(plr, "&aCancelled setup");
2015-02-10 07:14:55 +01:00
return false;
}
if (args[0].equalsIgnoreCase("back")) {
2015-05-14 19:27:37 +02:00
final SetupObject object = SetupUtils.setupMap.get(name);
2015-02-10 07:14:55 +01:00
if (object.setup_index > 0) {
object.setup_index--;
2015-05-15 18:23:59 +02:00
final ConfigurationNode node = object.step[object.setup_index];
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", node.getDescription(), node.getType().getType(), node.getDefaultValue() + "");
2015-02-10 07:14:55 +01:00
return false;
2015-02-20 07:34:19 +01:00
} else if (object.current > 0) {
2015-02-10 07:14:55 +01:00
object.current--;
2014-11-05 04:42:08 +01:00
}
2015-02-10 07:14:55 +01:00
}
}
2015-02-22 14:12:32 +01:00
final SetupObject object = SetupUtils.setupMap.get(name);
2015-02-20 07:34:19 +01:00
final int index = object.current;
switch (index) {
2015-02-10 07:14:55 +01:00
case 0: { // choose generator
2015-02-22 14:12:32 +01:00
if ((args.length != 1) || !SetupUtils.generators.containsKey(args[0])) {
2015-02-20 07:34:19 +01:00
final String prefix = "\n&8 - &7";
2015-02-22 14:12:32 +01:00
MainUtil.sendMessage(plr, "&cYou must choose a generator!" + prefix + StringUtils.join(SetupUtils.generators.keySet(), prefix).replaceAll("PlotSquared", "&2PlotSquared"));
2015-02-10 07:14:55 +01:00
sendMessage(plr, C.SETUP_INIT);
return false;
}
2015-04-21 14:48:18 +02:00
object.setupGenerator = args[0];
2015-02-10 07:14:55 +01:00
object.current++;
2015-02-20 07:34:19 +01:00
final String partial = Settings.ENABLE_CLUSTERS ? "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots" : "";
2015-02-21 12:24:46 +01:00
MainUtil.sendMessage(plr, "&6What world type do you want?" + "\n&8 - &2DEFAULT&8 - &7Standard plot generation" + "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain" + partial);
2015-02-10 07:14:55 +01:00
break;
}
case 1: { // choose world type
2015-04-21 16:03:27 +02:00
List<String> allTypes = Arrays.asList(new String[] { "default", "augmented", "partial"});
List<String> allDesc = Arrays.asList(new String[] { "Standard plot generation", "Plot generation with vanilla terrain", "Vanilla with clusters of plots"});
2015-04-21 14:48:18 +02:00
ArrayList<String> types = new ArrayList<>();
if (SetupUtils.generators.get(object.setupGenerator) instanceof PlotGenerator) {
types.add("default");
}
types.add("augmented");
2015-02-10 10:50:27 +01:00
if (Settings.ENABLE_CLUSTERS) {
2015-04-21 14:48:18 +02:00
types.add("partial");
2015-02-10 10:50:27 +01:00
}
2015-02-20 07:34:19 +01:00
if ((args.length != 1) || !types.contains(args[0].toLowerCase())) {
2015-04-21 16:03:27 +02:00
MainUtil.sendMessage(plr, "&cYou must choose a world type!");
for (String type : types) {
int i = allTypes.indexOf(type);
if (type.equals("default")) {
MainUtil.sendMessage(plr, "&8 - &2" + type + " &8-&7 " + allDesc.get(i));
}
else {
MainUtil.sendMessage(plr, "&8 - &7" + type + " &8-&7 " + allDesc.get(i));
}
}
2015-02-10 07:14:55 +01:00
return false;
}
2015-04-21 14:48:18 +02:00
object.type = allTypes.indexOf(args[0].toLowerCase());
2015-04-21 16:03:27 +02:00
ChunkGenerator gen = SetupUtils.generators.get(object.setupGenerator);
2015-02-10 07:14:55 +01:00
if (object.type == 0) {
object.current++;
if (object.step == null) {
2015-04-21 16:03:27 +02:00
object.plotManager = object.setupGenerator;
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
2015-04-27 16:53:07 +02:00
((PlotGenerator) SetupUtils.generators.get(object.plotManager)).processSetup(object);
2014-11-05 04:42:08 +01:00
}
if (object.step.length == 0) {
object.current = 4;
MainUtil.sendMessage(plr, "&6What do you want your world to be called?");
object.setup_index = 0;
return true;
}
2015-02-20 07:34:19 +01:00
final ConfigurationNode step = object.step[object.setup_index];
2015-02-10 07:14:55 +01:00
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
2015-02-20 07:34:19 +01:00
} else {
2015-04-21 16:03:27 +02:00
if (gen instanceof PlotGenerator) {
object.plotManager = object.setupGenerator;
object.setupGenerator = null;
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
2015-04-27 16:53:07 +02:00
((PlotGenerator) SetupUtils.generators.get(object.plotManager)).processSetup(object);
2015-04-21 16:03:27 +02:00
}
else {
object.plotManager = "PlotSquared";
MainUtil.sendMessage(plr, "&c[WARNING] The specified generator does not identify as PlotGenerator");
MainUtil.sendMessage(plr, "&7 - You may need to manually configure the other plugin");
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
}
2015-05-01 14:42:10 +02:00
MainUtil.sendMessage(plr, "&6What terrain would you like in plots?" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ROAD&8 - &7Terrain seperated by roads" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
2014-12-20 05:44:24 +01:00
}
2015-02-10 07:14:55 +01:00
object.current++;
break;
2014-11-05 04:42:08 +01:00
}
2015-02-10 07:14:55 +01:00
case 2: { // Choose terrain
2015-04-21 16:03:27 +02:00
final List<String> terrain = Arrays.asList(new String[] { "none", "ore", "road", "all" });
2015-02-20 07:34:19 +01:00
if ((args.length != 1) || !terrain.contains(args[0].toLowerCase())) {
2015-05-01 14:42:10 +02:00
MainUtil.sendMessage(plr, "&cYou must choose the terrain!" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ROAD&8 - &7Terrain seperated by roads" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
2015-02-10 07:14:55 +01:00
return false;
}
object.terrain = terrain.indexOf(args[0].toLowerCase());
object.current++;
if (object.step == null) {
2015-04-21 16:03:27 +02:00
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
2015-02-10 07:14:55 +01:00
}
2015-02-20 07:34:19 +01:00
final ConfigurationNode step = object.step[object.setup_index];
2015-02-10 07:14:55 +01:00
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
break;
}
case 3: { // world setup
if (object.setup_index == object.step.length) {
2015-02-21 12:24:46 +01:00
MainUtil.sendMessage(plr, "&6What do you want your world to be called?");
2015-02-10 07:14:55 +01:00
object.setup_index = 0;
object.current++;
2014-11-05 04:42:08 +01:00
return true;
}
2015-02-10 07:14:55 +01:00
ConfigurationNode step = object.step[object.setup_index];
if (args.length < 1) {
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
return false;
2014-11-05 04:42:08 +01:00
}
final boolean valid = step.isValid(args[0]);
if (valid) {
sendMessage(plr, C.SETUP_VALID_ARG, step.getConstant(), args[0]);
step.setValue(args[0]);
2015-02-10 07:14:55 +01:00
object.setup_index++;
if (object.setup_index == object.step.length) {
2014-11-05 04:42:08 +01:00
execute(plr, args);
2015-02-10 07:14:55 +01:00
return false;
2014-11-05 04:42:08 +01:00
}
2015-02-10 07:14:55 +01:00
step = object.step[object.setup_index];
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
return false;
2014-12-18 03:15:11 +01:00
} else {
2014-11-05 04:42:08 +01:00
sendMessage(plr, C.SETUP_INVALID_ARG, args[0], step.getConstant());
2015-02-10 07:14:55 +01:00
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
return false;
2014-11-05 04:42:08 +01:00
}
}
2015-02-10 07:14:55 +01:00
case 4: {
if (args.length != 1) {
2015-02-21 12:24:46 +01:00
MainUtil.sendMessage(plr, "&cYou need to choose a world name!");
2015-02-10 07:14:55 +01:00
return false;
2014-11-05 04:42:08 +01:00
}
2015-02-22 13:40:36 +01:00
if (BlockManager.manager.isWorld(args[0])) {
2015-02-21 12:24:46 +01:00
MainUtil.sendMessage(plr, "&cThat world name is already taken!");
2015-02-10 07:14:55 +01:00
}
object.world = args[0];
2015-05-14 19:27:37 +02:00
SetupUtils.setupMap.remove(name);
2015-04-21 14:48:18 +02:00
final String world;
2015-04-21 16:03:27 +02:00
if (object.setupManager == null) {
2015-04-21 14:48:18 +02:00
world = SetupUtils.manager.setupWorld(object);
}
else {
2015-04-21 16:03:27 +02:00
world = object.setupManager.setupWorld(object);
2015-04-21 14:48:18 +02:00
}
2015-02-10 07:14:55 +01:00
try {
2015-05-14 19:27:37 +02:00
if (plr != null) {
plr.teleport(BlockManager.manager.getSpawn(world));
}
2015-02-20 07:34:19 +01:00
} catch (final Exception e) {
2015-02-10 07:14:55 +01:00
plr.sendMessage("&cAn error occured. See console for more information");
e.printStackTrace();
}
sendMessage(plr, C.SETUP_FINISHED, object.world);
2015-05-14 19:27:37 +02:00
SetupUtils.setupMap.remove(name);
2014-11-05 04:42:08 +01:00
}
}
2015-02-10 07:14:55 +01:00
return false;
2014-11-05 04:42:08 +01:00
}
2015-02-10 07:14:55 +01:00
}