mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 06:36:44 +01:00
Finished setup command.
This commit is contained in:
parent
a6375796c0
commit
6c1527f41c
@ -40,9 +40,11 @@ public enum C {
|
||||
"&cStep &6%s&c: %s &c<Expecting: &6%s&c, Default: &6%s&c>"), 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.\n&4If you are using MULTIVERSE or MULTIWORLD you will need to import this world. Otherwise you will need to add this world to the 'bukkit.yml' file (See installation tutorial for more info)"), SETUP_WORLD_TAKEN(
|
||||
"&cFinished setup for world &c%s.\n&4If you are using MULTIVERSE or MULTIWORLD the world should have just been created. Otherwise you will need to add the world manually through the bukkit.yml"), 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)\n&6Additional commands:\n&c - &6/p setup <value>\n&c - &6/p setup back\n&c - &6/p setup cancel"),
|
||||
"&cYou need to specify a world name (&6/p setup &l{world}&6 {generator}&c)\n&6Additional commands:\n&c - &6/p setup <value>\n&c - &6/p setup back\n&c - &6/p setup cancel"), SETUP_MISSING_GENERATOR(
|
||||
"&cYou need to specify a generator (&6/p setup {world} &l{generator}&r&c)\n&6Additional commands:\n&c - &6/p setup <value>\n&c - &6/p setup back\n&c - &6/p setup cancel"), SETUP_INVALID_GENERATOR(
|
||||
"&cIncalid generator. Possible options: %generators%"),
|
||||
/*
|
||||
* Schematic Stuff
|
||||
*/
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
package com.intellectualcrafters.plot.api;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
@ -26,7 +27,9 @@ import com.intellectualcrafters.plot.Plot;
|
||||
import com.intellectualcrafters.plot.PlotHelper;
|
||||
import com.intellectualcrafters.plot.PlotId;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.PlotManager;
|
||||
import com.intellectualcrafters.plot.PlotWorld;
|
||||
import com.intellectualcrafters.plot.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||
import com.intellectualcrafters.plot.commands.SubCommand;
|
||||
|
||||
@ -38,6 +41,34 @@ import com.intellectualcrafters.plot.commands.SubCommand;
|
||||
@SuppressWarnings({ "unused", "javadoc" })
|
||||
public class PlotAPI {
|
||||
|
||||
private static PlotHelper plotHelper;
|
||||
private static PlayerFunctions playerFunctions;
|
||||
private static FlagManager flagManager;
|
||||
private static SchematicHandler schematicHandler;
|
||||
private static C c;
|
||||
|
||||
// Methods/fields in PlotMain class
|
||||
|
||||
// PlotMain.config;
|
||||
// PlotMain.storage
|
||||
// PlotMain.translations
|
||||
// PlotMain.addPlotWorld(world, plotworld, manager);
|
||||
//
|
||||
// PlotMain.checkForExpiredPlots();
|
||||
// PlotMain.killAllEntities();
|
||||
//
|
||||
// PlotMain.createConfiguration(plotworld);
|
||||
// PlotMain.getPlots()
|
||||
// PlotMain.getPlots(player)
|
||||
// PlotMain.getPlots(world)
|
||||
// PlotMain.getPlots(world, player)
|
||||
// PlotMain.getWorldPlots(world)
|
||||
// PlotMain.getPlotWorlds()
|
||||
// PlotMain.isPlotWorld(world)
|
||||
// PlotMain.removePlot(world, id, callEvent)
|
||||
// PlotMain.teleportPlayer(player, from, plot)
|
||||
// PlotMain.updatePlot(plot);
|
||||
|
||||
// To access plotMain stuff.
|
||||
private PlotMain plotMain;
|
||||
// Reference
|
||||
@ -52,6 +83,111 @@ public class PlotAPI {
|
||||
this.plotMain = JavaPlugin.getPlugin(PlotMain.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the main class for this plugin <br>
|
||||
* - Contains a lot of fields and methods
|
||||
* - not very well organized
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public PlotMain getMain() {
|
||||
return plotMain;
|
||||
}
|
||||
|
||||
/**
|
||||
* PlotHelper class contains useful methods relating to plots.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public PlotHelper getPlotHelper() {
|
||||
return plotHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* PlayerFunctions class contains useful methods relating to players
|
||||
* - Some player/plot methods are here as well
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public PlayerFunctions getPlayerFunctions() {
|
||||
return playerFunctions;
|
||||
}
|
||||
|
||||
/**
|
||||
* FlagManager class contains methods relating to plot flags
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public FlagManager getFlagManager() {
|
||||
return flagManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* SchematicHandler class contains methods related to pasting schematics
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SchematicHandler getSchematicHandler() {
|
||||
return schematicHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* C class contains all the captions from the translations.yml file.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public C getCaptions() {
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot manager for a world.
|
||||
* - Most of these methods can be accessed through the PlotHelper
|
||||
*
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
public PlotManager getPlotManager(World world) {
|
||||
return PlotMain.getPlotManager(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot manager for a world.
|
||||
* - Contains useful low level methods for plot merging, clearing, and tessellation
|
||||
*
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
public PlotManager getPlotManager(String world) {
|
||||
return PlotMain.getPlotManager(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings for a world (settings bundled in PlotWorld class)
|
||||
* - You will need to downcast for the specific settings a Generator has.
|
||||
* e.g. DefaultPlotWorld class implements PlotWorld
|
||||
*
|
||||
* @param world
|
||||
* (to get settings of)
|
||||
* @return PlotWorld class for that world ! will return null if not a plot world
|
||||
* world
|
||||
*/
|
||||
public PlotWorld getWorldSettings(World world) {
|
||||
return PlotMain.getWorldSettings(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings for a world (settings bundled in PlotWorld class)
|
||||
*
|
||||
* @param world
|
||||
* (to get settings of)
|
||||
* @return PlotWorld class for that world ! will return null if not a plot world
|
||||
* world
|
||||
*/
|
||||
public PlotWorld getWorldSettings(String world) {
|
||||
return PlotMain.getWorldSettings(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a player.
|
||||
*
|
||||
@ -65,6 +201,7 @@ public class PlotAPI {
|
||||
|
||||
/**
|
||||
* Send a message to a player.
|
||||
* - Supports color codes
|
||||
*
|
||||
* @param player
|
||||
* @param string
|
||||
@ -75,6 +212,7 @@ public class PlotAPI {
|
||||
|
||||
/**
|
||||
* Send a message to the console.
|
||||
* - Supports color codes
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
@ -208,18 +346,6 @@ public class PlotAPI {
|
||||
return PlotMain.isPlotWorld(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings for a world (settings bundled in PlotWorld class)
|
||||
*
|
||||
* @param world
|
||||
* (to get settings of)
|
||||
* @return PlotWorld class for ther world ! will return null if not a plot
|
||||
* world
|
||||
*/
|
||||
public PlotWorld getWorldSettings(World world) {
|
||||
return PlotMain.getWorldSettings(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plot locations
|
||||
*
|
||||
|
@ -1,18 +1,24 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.intellectualcrafters.plot.C;
|
||||
import com.intellectualcrafters.plot.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.PlotGenerator;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.PlotWorld;
|
||||
import com.intellectualcrafters.plot.generator.DefaultPlotWorld;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-09-26.
|
||||
@ -23,13 +29,19 @@ public class Setup extends SubCommand implements Listener {
|
||||
|
||||
private class SetupObject {
|
||||
String world;
|
||||
String plugin;
|
||||
int current = 0;
|
||||
|
||||
ConfigurationNode[] step;
|
||||
|
||||
public SetupObject(String world, PlotWorld plotworld) {
|
||||
public SetupObject(String world, PlotWorld plotworld, String plugin) {
|
||||
this.world = world;
|
||||
this.step = plotworld.getSettingNodes();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public String getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
public int getCurrent() {
|
||||
@ -50,19 +62,9 @@ public class Setup extends SubCommand implements Listener {
|
||||
public boolean execute(Player plr, String... args) {
|
||||
boolean finished = false;
|
||||
|
||||
if (!finished) {
|
||||
// TODO recode this to work with the multiple generators
|
||||
PlayerFunctions
|
||||
.sendMessage(plr, "&4CURRENTLY NOT IMPLEMENTED YET!");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (setupMap.containsKey(plr.getName())) {
|
||||
SetupObject object = setupMap.get(plr.getName());
|
||||
if (object.getCurrent() == object.getMax()) {
|
||||
sendMessage(plr, C.SETUP_FINISHED, object.world);
|
||||
|
||||
ConfigurationNode[] steps = object.step;
|
||||
String world = object.world;
|
||||
for (ConfigurationNode step : steps) {
|
||||
@ -76,9 +78,14 @@ public class Setup extends SubCommand implements Listener {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// World newWorld = WorldCreator.name(world).generator(new
|
||||
// WorldGenerator(world)).createWorld();
|
||||
// plr.teleport(newWorld.getSpawnLocation());
|
||||
// Creating the worlds
|
||||
if (object.getPlugin().equals("Multiverse-Core")) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create "+world+" normal -g "+object.plugin);
|
||||
}
|
||||
else if (object.getPlugin().equals("MultiWorld")) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create "+world+" plugin:"+object.plugin);
|
||||
}
|
||||
sendMessage(plr, C.SETUP_FINISHED, object.world);
|
||||
|
||||
setupMap.remove(plr.getName());
|
||||
|
||||
@ -140,19 +147,52 @@ public class Setup extends SubCommand implements Listener {
|
||||
sendMessage(plr, C.SETUP_MISSING_WORLD);
|
||||
return true;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
sendMessage(plr, C.SETUP_MISSING_GENERATOR);
|
||||
return true;
|
||||
}
|
||||
String world = args[0];
|
||||
if (StringUtils.isNumeric(args[0])) {
|
||||
sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PlotMain.getWorldSettings(world) != null) {
|
||||
sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
|
||||
return true;
|
||||
}
|
||||
|
||||
PlotWorld plotworld = PlotMain.getWorldSettings("//TODO"); // TODO
|
||||
ArrayList<String> generators = new ArrayList<String>();
|
||||
|
||||
setupMap.put(plr.getName(), new SetupObject(world, plotworld));
|
||||
ChunkGenerator generator = null;
|
||||
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
if (plugin.isEnabled()) {
|
||||
ChunkGenerator currentGen = plugin.getDefaultWorldGenerator("world", "");
|
||||
if (currentGen != null) {
|
||||
String name = plugin.getDescription().getName();
|
||||
generators.add(name);
|
||||
if (args[1].equals(name)) {
|
||||
generator = currentGen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (generator == null) {
|
||||
sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringUtils.join(generators,C.BLOCK_LIST_SEPARATER.s()));
|
||||
return true;
|
||||
}
|
||||
PlotWorld plotworld;
|
||||
if (generator instanceof PlotGenerator) {
|
||||
plotworld = ((PlotGenerator) generator).getPlotWorld();
|
||||
}
|
||||
else {
|
||||
plotworld = new DefaultPlotWorld(world);
|
||||
}
|
||||
|
||||
setupMap.put(plr.getName(), new SetupObject(world, plotworld, args[1]));
|
||||
sendMessage(plr, C.SETUP_INIT);
|
||||
SetupObject object = setupMap.get(plr.getName());
|
||||
ConfigurationNode step = object.step[object.current];
|
||||
|
@ -25,6 +25,7 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -523,16 +524,19 @@ public class PlayerEvents implements Listener {
|
||||
}
|
||||
if (isInPlot(event.getClickedBlock().getLocation())) {
|
||||
Plot plot = getCurrentPlot(event.getClickedBlock().getLocation());
|
||||
if (new ArrayList<>(Arrays.asList(new Material[] {
|
||||
Material.STONE_BUTTON, Material.WOOD_BUTTON,
|
||||
Material.LEVER, Material.STONE_PLATE, Material.WOOD_PLATE,
|
||||
Material.CHEST, Material.TRAPPED_CHEST, Material.TRAP_DOOR,
|
||||
Material.WOOD_DOOR, Material.WOODEN_DOOR,
|
||||
Material.DISPENSER, Material.DROPPER
|
||||
|
||||
})).contains(event.getClickedBlock().getType())) {
|
||||
return;
|
||||
}
|
||||
// They shouldn't be allowed to access other people's chests
|
||||
|
||||
// if (new ArrayList<>(Arrays.asList(new Material[] {
|
||||
// Material.STONE_BUTTON, Material.WOOD_BUTTON,
|
||||
// Material.LEVER, Material.STONE_PLATE, Material.WOOD_PLATE,
|
||||
// Material.CHEST, Material.TRAPPED_CHEST, Material.TRAP_DOOR,
|
||||
// Material.WOOD_DOOR, Material.WOODEN_DOOR,
|
||||
// Material.DISPENSER, Material.DROPPER
|
||||
//
|
||||
// })).contains(event.getClickedBlock().getType())) {
|
||||
// return;
|
||||
// }
|
||||
if (!plot.hasRights(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@ -548,7 +552,7 @@ public class PlayerEvents implements Listener {
|
||||
if (!isPlotWorld(world)) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntity() instanceof Player) {
|
||||
if (event.getEntity().getType() == EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
if (!isInPlot(event.getLocation())) {
|
||||
|
Loading…
Reference in New Issue
Block a user