diff --git a/src/org/mcteam/ancientgates/Plugin.java b/src/org/mcteam/ancientgates/Plugin.java index 2947e0a..b5419df 100644 --- a/src/org/mcteam/ancientgates/Plugin.java +++ b/src/org/mcteam/ancientgates/Plugin.java @@ -18,6 +18,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.mcteam.ancientgates.commands.BaseCommand; import org.mcteam.ancientgates.commands.CommandClose; import org.mcteam.ancientgates.commands.CommandCreate; +import org.mcteam.ancientgates.commands.CommandCreateSetFrom; import org.mcteam.ancientgates.commands.CommandDelete; import org.mcteam.ancientgates.commands.CommandHelp; import org.mcteam.ancientgates.commands.CommandList; @@ -64,6 +65,7 @@ public class Plugin extends JavaPlugin { // Add the commands commands.add(new CommandHelp()); commands.add(new CommandCreate()); + commands.add(new CommandCreateSetFrom()); commands.add(new CommandDelete()); commands.add(new CommandSetFrom()); commands.add(new CommandSetTo()); diff --git a/src/org/mcteam/ancientgates/commands/CommandCreateSetFrom.java b/src/org/mcteam/ancientgates/commands/CommandCreateSetFrom.java new file mode 100644 index 0000000..afd3d70 --- /dev/null +++ b/src/org/mcteam/ancientgates/commands/CommandCreateSetFrom.java @@ -0,0 +1,82 @@ +package org.mcteam.ancientgates.commands; + +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.mcteam.ancientgates.Conf; +import org.mcteam.ancientgates.Gate; +import org.mcteam.ancientgates.util.FloodUtil; + +public class CommandCreateSetFrom extends BaseCommand +{ + public CommandCreateSetFrom() + { + aliases.add("createsetfrom"); + aliases.add("newsetfrom"); + aliases.add("csf"); + aliases.add("nsf"); + + requiredParameters.add("id"); + + hasGateParam = false; + + helpDescription = "Create a gate and set \"from\" to your location."; + } + + public void perform() + { + String id = parameters.get(0); + + if (Gate.exists(id)) { + sendMessage("There gate \"" + id + "\" already exists."); + return; + } + + Gate.create(id); + Gate.save(); + sendMessage("Gate with id \"" + id + "\" was created."); + + gate = Gate.get(id); + + // The player might stand in a halfblock or a sign or whatever + // Therefore we load som extra locations and blocks + Block playerBlock = player.getLocation().getBlock(); + Block upBlock = playerBlock.getRelative(BlockFace.UP); + Location playerUpLocation = new Location(player.getLocation().getWorld(), + player.getLocation().getX(), + player.getLocation().getY() + 1, + player.getLocation().getZ(), + player.getLocation().getYaw(), + player.getLocation().getPitch()); + + Set gateBlocks = FloodUtil.getGateFrameBlocks(player.getLocation().getBlock()); + + if (gateBlocks == null) + { + sendMessage("Could not set from! Your portal is too large.\nMax size is: " + Conf.getGateMaxArea() + " Blocks."); + return; + } + + if (playerBlock.getType() == Material.AIR) + { + gate.setFrom(player.getLocation()); + gate.setGateBlocks(gateBlocks); + } + else if (upBlock.getType() == Material.AIR) + { + gate.setFrom(playerUpLocation); + gate.setGateBlocks(gateBlocks); + } + else + { + sendMessage("Could not set from! There is not enough room for a gate to open here"); + return; + } + + sendMessage("From location for gate \""+gate.getId()+"\" is now where you stand."); + sendMessage("Your gate includes " + gateBlocks.size() + " Blocks."); + } +} diff --git a/src/org/mcteam/ancientgates/commands/CommandHelp.java b/src/org/mcteam/ancientgates/commands/CommandHelp.java index 8725847..266fe1d 100644 --- a/src/org/mcteam/ancientgates/commands/CommandHelp.java +++ b/src/org/mcteam/ancientgates/commands/CommandHelp.java @@ -54,6 +54,7 @@ public class CommandHelp extends BaseCommand { pageLines = new ArrayList(); pageLines.add( new CommandHelp().getUseageTemplate(true, true) ); pageLines.add( new CommandCreate().getUseageTemplate(true, true) ); + pageLines.add( new CommandCreateSetFrom().getUseageTemplate(true, true) ); pageLines.add( new CommandDelete().getUseageTemplate(true, true) ); pageLines.add( new CommandSetFrom().getUseageTemplate(true, true) ); pageLines.add( new CommandSetTo().getUseageTemplate(true, true) );