Commands refactoring
This commit is contained in:
parent
107de7551c
commit
7be2f02e03
@ -73,15 +73,15 @@ public class Plugin extends JavaPlugin
|
||||
commands.add(new CommandHelp());
|
||||
commands.add(new CommandCreate());
|
||||
commands.add(new CommandDelete());
|
||||
commands.add(new CommandSetFrom());
|
||||
commands.add(new CommandSetTo());
|
||||
commands.add(new CommandSetLocation());
|
||||
commands.add(new CommandSetExit());
|
||||
commands.add(new CommandOpen());
|
||||
commands.add(new CommandRename());
|
||||
commands.add(new CommandClose());
|
||||
commands.add(new CommandList());
|
||||
commands.add(new CommandInfo());
|
||||
commands.add(new CommandHide());
|
||||
commands.add(new CommandUnhide());
|
||||
commands.add(new CommandSetHidden());
|
||||
commands.add(new CommandSetVisible());
|
||||
|
||||
|
||||
// Register events
|
||||
|
@ -8,8 +8,11 @@ public class CommandClose extends BaseCommand
|
||||
public CommandClose()
|
||||
{
|
||||
aliases.add("close");
|
||||
requiredParameters.add("id");
|
||||
helpDescription = "Close that gate";
|
||||
|
||||
requiredParameters.add("id");
|
||||
|
||||
helpDescription = "Closes a gate to prevent players from using it.";
|
||||
|
||||
requiredPermission = Plugin.permissionManage;
|
||||
}
|
||||
|
||||
@ -17,7 +20,12 @@ public class CommandClose extends BaseCommand
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
gate.setOpen(false);
|
||||
try {
|
||||
gate.setOpen(false);
|
||||
}
|
||||
catch(Exception e) {
|
||||
}
|
||||
|
||||
sendMessage("The gate was closed.");
|
||||
}
|
||||
}
|
||||
|
@ -14,10 +14,10 @@ public class CommandCreate extends BaseLocationCommand
|
||||
|
||||
requiredParameters.add("id");
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBePlayer = true;
|
||||
hasGateParam = false;
|
||||
|
||||
helpDescription = "Create a gate";
|
||||
helpDescription = "Create a gate at the current location of the player.";
|
||||
|
||||
requiredPermission = Plugin.permissionManage;
|
||||
}
|
||||
@ -26,24 +26,30 @@ public class CommandCreate extends BaseLocationCommand
|
||||
public void perform()
|
||||
{
|
||||
String id = parameters.get(0);
|
||||
if (Gate.exists(id))
|
||||
{
|
||||
sendMessage("There gate \"" + id + "\" already exists.");
|
||||
return;
|
||||
}
|
||||
|
||||
gate = Gate.create(id);
|
||||
try {
|
||||
gate = Gate.create(id);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
Location playerLocation = getValidPlayerLocation();
|
||||
|
||||
if (playerLocation != null) {
|
||||
gate.setLocation(playerLocation);
|
||||
try {
|
||||
gate.setLocation(playerLocation);
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
|
||||
sendMessage("Gate with id \"" + id + "\" was created.\n The gates location has been set to your current location.");
|
||||
sendMessage("Gate with id \"" + id + "\" was created.");
|
||||
sendMessage("The gates location has been set to your current location.");
|
||||
}
|
||||
else {
|
||||
sendMessage("Gate with id \"" + id + "\" was created.\n Now you should build a frame and:");
|
||||
sendMessage(new CommandSetFrom().getUsageTemplate(true, true));
|
||||
sendMessage("Gate with id \"" + id + "\" was created.");
|
||||
sendMessage("Now you should build a frame and:");
|
||||
sendMessage(new CommandSetLocation().getUsageTemplate(true, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import org.mcteam.ancientgates.Plugin;
|
||||
|
||||
public class CommandDelete extends BaseCommand
|
||||
{
|
||||
|
||||
public CommandDelete()
|
||||
{
|
||||
aliases.add("delete");
|
||||
@ -17,7 +16,7 @@ public class CommandDelete extends BaseCommand
|
||||
requiredParameters.add("id");
|
||||
|
||||
senderMustBePlayer = false;
|
||||
helpDescription = "Delete a gate";
|
||||
helpDescription = "Removes the gate from the game.";
|
||||
|
||||
requiredPermission = Plugin.permissionManage;
|
||||
}
|
||||
@ -25,10 +24,8 @@ public class CommandDelete extends BaseCommand
|
||||
|
||||
public void perform()
|
||||
{
|
||||
gate.setOpen(false);
|
||||
Gate.delete(gate.getId());
|
||||
|
||||
sendMessage("Gate with id \"" + gate.getId() + "\" was deleted.");
|
||||
sendMessage("Gate with id '" + gate.getId() + "' was deleted.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class CommandHelp extends BaseCommand
|
||||
optionalParameters.add("page");
|
||||
hasGateParam = false;
|
||||
|
||||
helpDescription = "Display a help page";
|
||||
helpDescription = "Prints a list of all availible commands.";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,8 +72,8 @@ public class CommandHelp extends BaseCommand
|
||||
pageLines.add( new CommandHelp().getUsageTemplate(true, true) );
|
||||
pageLines.add( new CommandCreate().getUsageTemplate(true, true) );
|
||||
pageLines.add( new CommandDelete().getUsageTemplate(true, true) );
|
||||
pageLines.add( new CommandSetFrom().getUsageTemplate(true, true) );
|
||||
pageLines.add( new CommandSetTo().getUsageTemplate(true, true) );
|
||||
pageLines.add( new CommandSetLocation().getUsageTemplate(true, true) );
|
||||
pageLines.add( new CommandSetExit().getUsageTemplate(true, true) );
|
||||
pageLines.add( new CommandOpen().getUsageTemplate(true, true) );
|
||||
|
||||
helpPages.add(pageLines);
|
||||
@ -83,8 +83,8 @@ public class CommandHelp extends BaseCommand
|
||||
pageLines.add( new CommandClose().getUsageTemplate(true, true) );
|
||||
pageLines.add( new CommandList().getUsageTemplate(true, true) );
|
||||
pageLines.add( new CommandInfo().getUsageTemplate(true, true) );
|
||||
pageLines.add( new CommandHide().getUsageTemplate(true, true) );
|
||||
pageLines.add( new CommandUnhide().getUsageTemplate(true, true) );
|
||||
pageLines.add( new CommandSetHidden().getUsageTemplate(true, true) );
|
||||
pageLines.add( new CommandSetVisible().getUsageTemplate(true, true) );
|
||||
|
||||
helpPages.add(pageLines);
|
||||
}
|
||||
|
@ -1,28 +0,0 @@
|
||||
package org.mcteam.ancientgates.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CommandHide extends BaseCommand
|
||||
{
|
||||
|
||||
public CommandHide()
|
||||
{
|
||||
aliases.add("hide");
|
||||
|
||||
requiredParameters.add("id");
|
||||
|
||||
helpDescription = "Hide that gate";
|
||||
}
|
||||
|
||||
public void perform()
|
||||
{
|
||||
gate.setHidden(true);
|
||||
sendMessage("The gate " + gate.getId() + " is now hidden.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender)
|
||||
{
|
||||
return sender.hasPermission(permissionManage);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package org.mcteam.ancientgates.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.mcteam.ancientgates.Plugin;
|
||||
|
||||
|
||||
public class CommandInfo extends BaseCommand
|
||||
@ -13,7 +13,7 @@ public class CommandInfo extends BaseCommand
|
||||
|
||||
requiredParameters.add("id");
|
||||
|
||||
helpDescription = "Prints information about a gate";
|
||||
helpDescription = "Prints detailed informations about a certain gate.";
|
||||
|
||||
requiredPermission = Plugin.permissionInfo;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class CommandList extends BaseCommand
|
||||
optionalParameters.add("page");
|
||||
hasGateParam = false;
|
||||
|
||||
helpDescription = "Display a list of the gates";
|
||||
helpDescription = "Prints a list of all availible gates.";
|
||||
|
||||
requiredPermission = Plugin.permissionInfo;
|
||||
}
|
||||
|
@ -1,50 +1,34 @@
|
||||
package org.mcteam.ancientgates.commands;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.mcteam.ancientgates.Plugin;
|
||||
|
||||
public class CommandOpen extends BaseCommand {
|
||||
|
||||
public class CommandOpen extends BaseCommand
|
||||
{
|
||||
|
||||
public CommandOpen() {
|
||||
public CommandOpen()
|
||||
{
|
||||
aliases.add("open");
|
||||
|
||||
requiredParameters.add("id");
|
||||
|
||||
helpDescription = "Open that gate";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
if (gate.getLocation() == null) {
|
||||
sendMessage("You must set the from location first. To fix that:");
|
||||
sendMessage(new CommandSetFrom().getUsageTemplate(true, true));
|
||||
return;
|
||||
}
|
||||
helpDescription = "Open a gate so players can use it.";
|
||||
|
||||
if (gate.getExit() == null) {
|
||||
sendMessage("Sure, but note that this gate does not point anywhere :P");
|
||||
sendMessage("To fix that: " + new CommandSetTo().getUsageTemplate(true, true));
|
||||
}
|
||||
|
||||
if (gate.getLocation().getBlock().getType() != Material.AIR) {
|
||||
sendMessage("The gate could not open. The from location is not air.");
|
||||
return;
|
||||
}
|
||||
|
||||
gate.setOpen(true);
|
||||
|
||||
if (gate.isOpen()) {
|
||||
sendMessage("The gate was opened.");
|
||||
} else {
|
||||
sendMessage("Failed to open the gate. Have you built a frame?");
|
||||
sendMessage("More info here: " + new CommandHelp().getUsageTemplate(true, true));
|
||||
}
|
||||
requiredPermission = Plugin.permissionManage;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender)
|
||||
public void perform()
|
||||
{
|
||||
return sender.hasPermission(permissionManage);
|
||||
try {
|
||||
gate.setOpen(true);
|
||||
} catch (Exception e) {
|
||||
sendMessage(e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
sendMessage("The gate was opened.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
package org.mcteam.ancientgates.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.mcteam.ancientgates.Gate;
|
||||
|
||||
import org.mcteam.ancientgates.Plugin;
|
||||
|
||||
|
||||
public class CommandRename extends BaseCommand
|
||||
@ -19,7 +18,9 @@ public class CommandRename extends BaseCommand
|
||||
requiredParameters.add("current name");
|
||||
requiredParameters.add("new name");
|
||||
|
||||
helpDescription = "Change the name of a gate";
|
||||
helpDescription = "Changes the id of a gate.";
|
||||
|
||||
requiredPermission = Plugin.permissionManage;
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +29,7 @@ public class CommandRename extends BaseCommand
|
||||
String newId = parameters.get(1);
|
||||
|
||||
try {
|
||||
Gate.rename(gate, newId);
|
||||
Gate.rename(gate.getId(), newId);
|
||||
}
|
||||
catch (Exception e) {
|
||||
sendMessage("Cannot rename " + gate.getId() + ". There is already a gate named " + newId + ".");
|
||||
@ -36,11 +37,5 @@ public class CommandRename extends BaseCommand
|
||||
|
||||
sendMessage("Gate " + gate.getId() + " is now known as " + newId + ".");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender)
|
||||
{
|
||||
return sender.hasPermission(permissionManage);
|
||||
}
|
||||
|
||||
}
|
||||
|
34
src/org/mcteam/ancientgates/commands/CommandSetExit.java
Normal file
34
src/org/mcteam/ancientgates/commands/CommandSetExit.java
Normal file
@ -0,0 +1,34 @@
|
||||
package org.mcteam.ancientgates.commands;
|
||||
|
||||
import org.mcteam.ancientgates.Plugin;
|
||||
|
||||
|
||||
public class CommandSetExit extends BaseCommand
|
||||
{
|
||||
|
||||
public CommandSetExit()
|
||||
{
|
||||
aliases.add("setto");
|
||||
aliases.add("st");
|
||||
|
||||
requiredParameters.add("id");
|
||||
|
||||
helpDescription = "Changes the location where the gate will teleport players to your current location.";
|
||||
|
||||
requiredPermission = Plugin.permissionManage;
|
||||
}
|
||||
|
||||
|
||||
public void perform()
|
||||
{
|
||||
try {
|
||||
gate.setExit(player.getLocation());
|
||||
}
|
||||
catch (Exception e) {
|
||||
sendMessage(e.getMessage());
|
||||
}
|
||||
|
||||
sendMessage("The exit of gate '" + gate.getId() + "' is now where you stand.");
|
||||
}
|
||||
}
|
||||
|
@ -1,74 +0,0 @@
|
||||
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.bukkit.command.CommandSender;
|
||||
|
||||
import org.mcteam.ancientgates.util.FloodUtil;
|
||||
|
||||
|
||||
public class CommandSetFrom extends BaseCommand
|
||||
{
|
||||
|
||||
public CommandSetFrom()
|
||||
{
|
||||
aliases.add("setfrom");
|
||||
aliases.add("sf");
|
||||
|
||||
requiredParameters.add("id");
|
||||
|
||||
helpDescription = "Set \"from\" to your location.";
|
||||
}
|
||||
|
||||
public void perform()
|
||||
{
|
||||
// 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<Block> gateBlocks = FloodUtil.getGateFrameBlocks(player.getLocation().getBlock());
|
||||
|
||||
if (gateBlocks == null)
|
||||
{
|
||||
sendMessage("There is no portal here, or your portal is too large.\nMax size is: " /*+ Conf.getGateMaxArea()*/ + " Blocks.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (playerBlock.getType() == Material.AIR)
|
||||
{
|
||||
gate.setLocation(player.getLocation());
|
||||
}
|
||||
else if (upBlock.getType() == Material.AIR)
|
||||
{
|
||||
gate.setLocation(playerUpLocation);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMessage("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.");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender)
|
||||
{
|
||||
return sender.hasPermission(permissionManage);
|
||||
}
|
||||
|
||||
}
|
||||
|
32
src/org/mcteam/ancientgates/commands/CommandSetHidden.java
Normal file
32
src/org/mcteam/ancientgates/commands/CommandSetHidden.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.mcteam.ancientgates.commands;
|
||||
|
||||
import org.mcteam.ancientgates.Plugin;
|
||||
|
||||
|
||||
public class CommandSetHidden extends BaseCommand
|
||||
{
|
||||
public CommandSetHidden()
|
||||
{
|
||||
aliases.add("setHidden");
|
||||
aliases.add("sh");
|
||||
|
||||
requiredParameters.add("id");
|
||||
|
||||
helpDescription = "Makes a gate NOT consist of gate blocks while open.";
|
||||
|
||||
requiredPermission = Plugin.permissionManage;
|
||||
}
|
||||
|
||||
|
||||
public void perform()
|
||||
{
|
||||
try {
|
||||
gate.setHidden(true);
|
||||
}
|
||||
catch (Exception e) {
|
||||
sendMessage(e.getMessage());
|
||||
}
|
||||
|
||||
sendMessage("The gate '" + gate.getId() + "' is now hidden.");
|
||||
}
|
||||
}
|
44
src/org/mcteam/ancientgates/commands/CommandSetLocation.java
Normal file
44
src/org/mcteam/ancientgates/commands/CommandSetLocation.java
Normal file
@ -0,0 +1,44 @@
|
||||
package org.mcteam.ancientgates.commands;
|
||||
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.mcteam.ancientgates.Plugin;
|
||||
|
||||
|
||||
public class CommandSetLocation extends BaseLocationCommand
|
||||
{
|
||||
|
||||
public CommandSetLocation()
|
||||
{
|
||||
aliases.add("setlocation");
|
||||
aliases.add("sl");
|
||||
|
||||
requiredParameters.add("id");
|
||||
|
||||
helpDescription = "Set the entrance of the gate to your current location.";
|
||||
|
||||
requiredPermission = Plugin.permissionManage;
|
||||
}
|
||||
|
||||
|
||||
public void perform()
|
||||
{
|
||||
Location playerLocation = getValidPlayerLocation();
|
||||
|
||||
if (playerLocation == null) {
|
||||
sendMessage("There is not enough room for a gate to open here");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
gate.setLocation(playerLocation);
|
||||
}
|
||||
catch (Exception e) {
|
||||
sendMessage(e.getMessage());
|
||||
}
|
||||
|
||||
sendMessage("The location of '" + gate.getId() + "' is now at your current location.");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,28 +0,0 @@
|
||||
package org.mcteam.ancientgates.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CommandSetTo extends BaseCommand {
|
||||
|
||||
public CommandSetTo() {
|
||||
aliases.add("setto");
|
||||
aliases.add("st");
|
||||
|
||||
requiredParameters.add("id");
|
||||
|
||||
helpDescription = "Set \"to\" to your location.";
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
gate.setExit(player.getLocation());
|
||||
sendMessage("To location for gate \""+gate.getId()+"\" is now where you stand.");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender sender)
|
||||
{
|
||||
return sender.hasPermission(permissionManage);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user