2014-09-26 22:53:42 +02:00
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2014-10-03 12:36:30 +10:00
|
|
|
import java.io.IOException;
|
2014-10-11 12:09:14 -07:00
|
|
|
import java.util.ArrayList;
|
2014-10-03 12:36:30 +10:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2014-10-02 14:35:20 +10:00
|
|
|
|
2014-10-02 18:21:34 +10:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2014-10-11 12:09:14 -07:00
|
|
|
import org.bukkit.Bukkit;
|
2014-09-26 22:53:42 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.Listener;
|
2014-10-11 12:09:14 -07:00
|
|
|
import org.bukkit.generator.ChunkGenerator;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
2014-10-02 18:21:34 +10:00
|
|
|
|
2014-10-03 12:36:30 +10:00
|
|
|
import com.intellectualcrafters.plot.C;
|
2014-10-11 00:33:10 -07:00
|
|
|
import com.intellectualcrafters.plot.ConfigurationNode;
|
2014-10-03 12:36:30 +10:00
|
|
|
import com.intellectualcrafters.plot.PlayerFunctions;
|
2014-10-11 12:09:14 -07:00
|
|
|
import com.intellectualcrafters.plot.PlotGenerator;
|
2014-10-03 12:36:30 +10:00
|
|
|
import com.intellectualcrafters.plot.PlotMain;
|
|
|
|
import com.intellectualcrafters.plot.PlotWorld;
|
2014-10-11 12:09:14 -07:00
|
|
|
import com.intellectualcrafters.plot.generator.DefaultPlotWorld;
|
2014-09-26 22:53:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Citymonstret on 2014-09-26.
|
|
|
|
*/
|
|
|
|
public class Setup extends SubCommand implements Listener {
|
|
|
|
|
2014-10-11 00:33:10 -07:00
|
|
|
public static Map<String, SetupObject> setupMap = new HashMap<>();
|
|
|
|
|
|
|
|
private class SetupObject {
|
|
|
|
String world;
|
2014-10-11 12:09:14 -07:00
|
|
|
String plugin;
|
2014-10-11 00:33:10 -07:00
|
|
|
int current = 0;
|
|
|
|
|
|
|
|
ConfigurationNode[] step;
|
|
|
|
|
2014-10-11 12:09:14 -07:00
|
|
|
public SetupObject(String world, PlotWorld plotworld, String plugin) {
|
2014-10-11 00:33:10 -07:00
|
|
|
this.world = world;
|
|
|
|
this.step = plotworld.getSettingNodes();
|
2014-10-11 12:09:14 -07:00
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
2014-10-12 00:37:36 -07:00
|
|
|
|
2014-10-11 12:09:14 -07:00
|
|
|
public String getPlugin() {
|
|
|
|
return this.plugin;
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getCurrent() {
|
|
|
|
return this.current;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMax() {
|
|
|
|
return this.step.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Setup() {
|
2014-10-19 17:15:13 +11:00
|
|
|
super("setup", "plots.admin", "Setup a PlotWorld", "setup {world} {generator}", "setup", CommandCategory.ACTIONS, false);
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean execute(Player plr, String... args) {
|
2014-10-18 11:06:29 -07:00
|
|
|
String plrname;
|
|
|
|
|
|
|
|
if (plr==null) {
|
|
|
|
plrname = "";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
plrname = plr.getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setupMap.containsKey(plrname)) {
|
|
|
|
SetupObject object = setupMap.get(plrname);
|
2014-10-11 00:33:10 -07:00
|
|
|
if (object.getCurrent() == object.getMax()) {
|
|
|
|
ConfigurationNode[] steps = object.step;
|
|
|
|
String world = object.world;
|
|
|
|
for (ConfigurationNode step : steps) {
|
2014-10-12 00:37:36 -07:00
|
|
|
PlotMain.config.set("worlds." + world + "." + step.getConstant(), step.getValue());
|
2014-10-11 00:33:10 -07:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
PlotMain.config.save(PlotMain.configFile);
|
2014-10-12 00:37:36 -07:00
|
|
|
}
|
|
|
|
catch (IOException e) {
|
2014-10-11 00:33:10 -07:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2014-10-12 00:37:36 -07:00
|
|
|
|
2014-10-11 12:09:14 -07:00
|
|
|
// Creating the worlds
|
|
|
|
if (object.getPlugin().equals("Multiverse-Core")) {
|
2014-10-12 00:37:36 -07:00
|
|
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world
|
|
|
|
+ " normal -g " + object.plugin);
|
2014-10-11 12:09:14 -07:00
|
|
|
}
|
2014-10-12 00:37:36 -07:00
|
|
|
else
|
|
|
|
if (object.getPlugin().equals("MultiWorld")) {
|
|
|
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world
|
|
|
|
+ " plugin:" + object.plugin);
|
|
|
|
}
|
2014-10-11 12:09:14 -07:00
|
|
|
sendMessage(plr, C.SETUP_FINISHED, object.world);
|
2014-10-11 00:33:10 -07:00
|
|
|
|
2014-10-18 11:06:29 -07:00
|
|
|
setupMap.remove(plrname);
|
2014-10-11 00:33:10 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
ConfigurationNode step = object.step[object.current];
|
|
|
|
if (args.length < 1) {
|
2014-10-12 00:37:36 -07:00
|
|
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue()
|
|
|
|
+ "");
|
2014-10-11 00:33:10 -07:00
|
|
|
return true;
|
2014-10-12 00:37:36 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-10-11 00:33:10 -07:00
|
|
|
if (args[0].equalsIgnoreCase("cancel")) {
|
2014-10-18 11:06:29 -07:00
|
|
|
setupMap.remove(plrname);
|
2014-10-11 00:33:10 -07:00
|
|
|
PlayerFunctions.sendMessage(plr, "&cCancelled setup.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (args[0].equalsIgnoreCase("back")) {
|
|
|
|
if (object.current > 0) {
|
|
|
|
object.current--;
|
|
|
|
step = object.step[object.current];
|
2014-10-12 00:37:36 -07:00
|
|
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue()
|
|
|
|
+ "");
|
2014-10-11 00:33:10 -07:00
|
|
|
return true;
|
2014-10-12 00:37:36 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue()
|
|
|
|
+ "");
|
2014-10-11 00:33:10 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean valid = step.isValid(args[0]);
|
|
|
|
if (valid) {
|
2014-10-12 00:37:36 -07:00
|
|
|
sendMessage(plr, C.SETUP_VALID_ARG, step.getConstant(), args[0]);
|
2014-10-11 00:33:10 -07:00
|
|
|
step.setValue(args[0]);
|
|
|
|
object.current++;
|
|
|
|
if (object.getCurrent() == object.getMax()) {
|
|
|
|
execute(plr, args);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
step = object.step[object.current];
|
2014-10-12 00:37:36 -07:00
|
|
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue()
|
|
|
|
+ "");
|
2014-10-11 00:33:10 -07:00
|
|
|
return true;
|
2014-10-12 00:37:36 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
sendMessage(plr, C.SETUP_INVALID_ARG, args[0], step.getConstant());
|
|
|
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue()
|
|
|
|
+ "");
|
2014-10-11 00:33:10 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-10-12 00:37:36 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-10-11 00:33:10 -07:00
|
|
|
if (args.length < 1) {
|
|
|
|
sendMessage(plr, C.SETUP_MISSING_WORLD);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-11 12:09:14 -07:00
|
|
|
if (args.length < 2) {
|
|
|
|
sendMessage(plr, C.SETUP_MISSING_GENERATOR);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-11 00:33:10 -07:00
|
|
|
String world = args[0];
|
|
|
|
if (StringUtils.isNumeric(args[0])) {
|
|
|
|
sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-12 00:37:36 -07:00
|
|
|
|
2014-10-11 00:33:10 -07:00
|
|
|
if (PlotMain.getWorldSettings(world) != null) {
|
|
|
|
sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-12 00:37:36 -07:00
|
|
|
|
2014-10-11 12:09:14 -07:00
|
|
|
ArrayList<String> generators = new ArrayList<String>();
|
2014-10-12 00:37:36 -07:00
|
|
|
|
2014-10-11 12:09:14 -07:00
|
|
|
ChunkGenerator generator = null;
|
2014-10-12 00:37:36 -07:00
|
|
|
|
2014-10-11 12:09:14 -07:00
|
|
|
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
|
|
|
if (plugin.isEnabled()) {
|
2014-10-12 00:37:36 -07:00
|
|
|
if (plugin.getDefaultWorldGenerator("world", "") != null) {
|
2014-10-11 12:09:14 -07:00
|
|
|
String name = plugin.getDescription().getName();
|
|
|
|
generators.add(name);
|
|
|
|
if (args[1].equals(name)) {
|
2014-10-12 00:37:36 -07:00
|
|
|
generator = plugin.getDefaultWorldGenerator(world, "");
|
2014-10-11 12:09:14 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-12 00:37:36 -07:00
|
|
|
|
2014-10-11 12:09:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (generator == null) {
|
2014-10-12 00:37:36 -07:00
|
|
|
sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringUtils.join(generators, C.BLOCK_LIST_SEPARATER.s()));
|
2014-10-11 12:09:14 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
PlotWorld plotworld;
|
|
|
|
if (generator instanceof PlotGenerator) {
|
2014-10-11 19:05:50 +11:00
|
|
|
plotworld = ((PlotGenerator) generator).getNewPlotWorld(world);
|
2014-10-11 12:09:14 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
plotworld = new DefaultPlotWorld(world);
|
|
|
|
}
|
2014-10-11 00:33:10 -07:00
|
|
|
|
2014-10-18 11:06:29 -07:00
|
|
|
setupMap.put(plrname, new SetupObject(world, plotworld, args[1]));
|
2014-10-11 00:33:10 -07:00
|
|
|
sendMessage(plr, C.SETUP_INIT);
|
2014-10-18 11:06:29 -07:00
|
|
|
SetupObject object = setupMap.get(plrname);
|
2014-10-11 00:33:10 -07:00
|
|
|
ConfigurationNode step = object.step[object.current];
|
2014-10-12 00:37:36 -07:00
|
|
|
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue()
|
|
|
|
+ "");
|
2014-10-11 00:33:10 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-09-26 22:53:42 +02:00
|
|
|
|
|
|
|
}
|