More on /p setup {world}

Fixed schematic support for claim
This commit is contained in:
Sauilitired 2014-09-28 10:21:18 +02:00
parent 2eb82fe703
commit 7a6d0ef531
3 changed files with 95 additions and 36 deletions

View File

@ -22,7 +22,7 @@ public enum C {
* Setup Stuff
*/
SETUP_INIT("&6PlotSquared Setup -> Setup a new plotworld"),
SETUP_STEP("&cStep &6%s&c: %s"),
SETUP_STEP("&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"),
SETUP_VALID_ARG("&cValue &6%s &cset for step %s"),
SETUP_FINISHED("&cFinished setup for world &c%s"),
@ -63,6 +63,7 @@ public enum C {
/*
* Permission
*/
NO_SCHEMATIC_PERMISSION("&cYou don't have the permission required to use schematic &6%s"),
NO_PERMISSION("&cYou don't have the permissions required to use this command."), NO_PLOT_PERMS("&cYou don't have the permissions to do that in this plot"), CANT_CLAIM_MORE_PLOTS("&cYou can't claim more plots."), YOU_BE_DENIED("&cYou are not allowed to enter this plot"),
NO_PERM_MERGE("&cYou are not the owner of the plot: &6%plot%"), UNLINK_REQUIRED("&cAn unlink is required to do this."), UNLINK_IMPOSSIBLE("&cYou can only unlink a mega-plot"),
NO_MERGE_TO_MEGA("&cMega plots cannot be merged into. Please merge from the desired mega plot."),

View File

@ -34,6 +34,10 @@ public class Claim extends SubCommand {
@Override
public boolean execute(Player plr, String... args) {
String schematic = "";
if(args.length >= 1) {
schematic = args[0];
}
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
@ -47,7 +51,17 @@ public class Claim extends SubCommand {
PlayerFunctions.sendMessage(plr, C.PLOT_IS_CLAIMED);
return false;
}
boolean result = claimPlot(plr, plot, false);
if(!schematic.equals("")) {
if(!plr.hasPermission("plots.claim." + schematic) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
return true;
}
if(new SchematicHandler().getSchematic(schematic) == null) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
return true;
}
}
boolean result = claimPlot(plr, plot, false, schematic);
if (result) {
PlayerFunctions.sendMessage(plr, C.PLOT_NOT_CLAIMED);
return false;
@ -57,7 +71,10 @@ public class Claim extends SubCommand {
}
public static boolean claimPlot(Player player, Plot plot, boolean teleport) {
plot.clear(player);
return claimPlot(player, plot, teleport, "");
}
public static boolean claimPlot(Player player, Plot plot, boolean teleport, String schematic) {
PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
@ -70,8 +87,16 @@ public class Claim extends SubCommand {
PlotWorld world = PlotMain.getWorldSettings(plot.getWorld());
if (world.SCHEMATIC_ON_CLAIM) {
SchematicHandler handler = new SchematicHandler();
SchematicHandler.Schematic schematic = handler.getSchematic(world.SCHEMATIC_FILE);
handler.paste(player.getLocation(), schematic, plot);
SchematicHandler.Schematic sch;
if(schematic.equals("")) {
sch = handler.getSchematic(world.SCHEMATIC_FILE);
} else {
sch = handler.getSchematic(schematic);
if(sch == null) {
sch = handler.getSchematic(world.SCHEMATIC_FILE);
}
}
handler.paste(player.getLocation(), sch, plot);
}
plot.settings.setFlags(PlotMain.getWorldSettings(player.getWorld()).DEFAULT_FLAGS);
}

View File

@ -5,10 +5,7 @@ import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.util.HashMap;
import java.util.Map;
@ -45,15 +42,24 @@ public class Setup extends SubCommand implements Listener {
private Object default_value;
private String description;
private Object value = 0;
public SetupStep(String constant, Object default_value, String description) {
private String type;
public SetupStep(String constant, Object default_value, String description, String type) {
this.constant = constant;
this.default_value = default_value;
this.description = description;
this.type = type;
}
public String getType() {
return this.type;
}
public boolean setValue(Object o) {
return true;
}
public boolean validValue(String string) {
return true;
}
public Object getValue() {
@ -73,23 +79,38 @@ public class Setup extends SubCommand implements Listener {
}
}
private static class SetupObject {
private String world;
private int current = 0;
private class SetupObject {
String world;
int current = 0;
PlotWorld p;
private SetupStep[] step = new SetupStep[] {
new SetupStep("road_height", 64, "Height of road")
SetupStep[] step = new SetupStep[] {
new SetupStep("road_height", 64, "Height of road", "integer") {
@Override
public boolean validValue(String string) {
try {
int t = Integer.parseInt(string);
} catch(Exception e) {
return false;
}
return true;
}
}
};
public SetupObject(String world) {
this.world = world;
PlotWorld p = new PlotWorld();
this.p = new PlotWorld();
}
public SetupStep getNextStep() {
return this.step[current++];
}
public int getCurrent() {
return this.current;
}
public int getMax() {
return this.step.length;
@ -102,12 +123,33 @@ public class Setup extends SubCommand implements Listener {
@Override
public boolean execute(Player plr, String... args) {
if(setupMap.containsKey(plr.getName())) {
SetupObject object = setupMap.get(plr.getName());
if(object.getCurrent() == object.getMax()) {
sendMessage(plr, C.SETUP_FINISHED, object.world);
setupMap.remove(plr.getName());
return true;
}
SetupStep step = object.step[object.current];
if(args.length < 1) {
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + "");
return true;
} else {
boolean valid = step.validValue(args[0]);
if(valid) {
sendMessage(plr, C.SETUP_VALID_ARG);
object.current++;
} else {
sendMessage(plr, C.SETUP_INVALID_ARG);
}
}
} else {
if (args.length < 1) {
sendMessage(plr, C.SETUP_MISSING_WORLD);
return true;
}
String world = args[0];
if(PlotMain.isPlotWorld(Bukkit.getWorld(world))) {
if (PlotMain.isPlotWorld(Bukkit.getWorld(world))) {
sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
return true;
}
@ -115,15 +157,6 @@ public class Setup extends SubCommand implements Listener {
sendMessage(plr, C.SETUP_INIT);
return true;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
if(!setupMap.containsKey(player.getName())) {
return;
}
event.setCancelled(true);
SetupObject object = setupMap.get(player.getName());
}
}