refactoring: commands now working again

This commit is contained in:
Tobias Ottenweller 2012-05-13 17:35:49 +02:00
parent 737ea7521e
commit 750a867d2f
13 changed files with 51 additions and 75 deletions

View File

@ -8,7 +8,6 @@ import org.bukkit.entity.Player;
import org.mcteam.ancientgates.Gate;
import org.mcteam.ancientgates.Plugin;
import org.mcteam.ancientgates.Conf;
import org.mcteam.ancientgates.util.TextUtil;
public class BaseCommand
@ -67,7 +66,7 @@ public class BaseCommand
}
public void sendMessage(String message) {
sender.sendMessage(Conf.colorSystem+message);
sender.sendMessage(message);
}
public void sendMessage(List<String> messages) {
@ -126,11 +125,11 @@ public class BaseCommand
public String getUsageTemplate(boolean withColor, boolean withDescription) {
String ret = "";
if (withColor) {
ret += Conf.colorCommand;
}
// if (withColor) {
// ret += Conf.colorCommand;
// }
ret += "/" + Plugin.instance.getBaseCommand()+ " " +TextUtil.implode(this.getAliases(), ",")+" ";
ret += "/" + Plugin.instance.getBaseCommand() + " " + TextUtil.implode(this.getAliases(), ",")+" ";
List<String> parts = new ArrayList<String>();
@ -142,15 +141,15 @@ public class BaseCommand
parts.add("*["+optionalParameter+"]");
}
if (withColor) {
ret += Conf.colorParameter;
}
// if (withColor) {
// ret += Conf.colorParameter;
// }
ret += TextUtil.implode(parts, " ");
if (withDescription) {
ret += " "+Conf.colorSystem + this.helpDescription;
}
// if (withDescription) {
// ret += " "+Conf.colorSystem + this.helpDescription;
// }
return ret;
}

View File

@ -1,7 +1,6 @@
package org.mcteam.ancientgates.commands;
import org.bukkit.command.CommandSender;
import org.mcteam.ancientgates.Gate;
public class CommandClose extends BaseCommand
{
@ -17,9 +16,8 @@ public class CommandClose extends BaseCommand
@Override
public void perform()
{
gate.close();
gate.setOpen(false);
sendMessage("The gate was closed.");
Gate.save();
}

View File

@ -31,7 +31,6 @@ public class CommandCreate extends BaseCommand
Gate.create(id);
sendMessage("Gate with id \"" + id + "\" was created. Now you should:");
sendMessage(new CommandSetFrom().getUsageTemplate(true, true));
Gate.save();
}

View File

@ -7,7 +7,6 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandSender;
import org.mcteam.ancientgates.Conf;
import org.mcteam.ancientgates.Gate;
import org.mcteam.ancientgates.util.FloodUtil;
@ -56,17 +55,17 @@ public class CommandCreateSetFrom extends BaseCommand
if (gateBlocks == null)
{
sendMessage("Could not set from! Your portal is too large.\nMax size is: " + Conf.getGateMaxArea() + " Blocks.");
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.setLocation(player.getLocation());
}
else if (upBlock.getType() == Material.AIR)
{
gate.setFrom(playerUpLocation);
gate.setLocation(playerUpLocation);
}
else
{
@ -76,8 +75,6 @@ public class CommandCreateSetFrom extends BaseCommand
sendMessage("From location for gate \""+gate.getId()+"\" is now where you stand.");
sendMessage("Your gate includes " + gateBlocks.size() + " Blocks.");
Gate.save();
}

View File

@ -18,10 +18,9 @@ public class CommandDelete extends BaseCommand {
public void perform()
{
gate.close();
gate.setOpen(false);
sendMessage("Gate with id \"" + gate.getId() + "\" was deleted.");
Gate.delete(gate.getId());
Gate.save();
}

View File

@ -1,7 +1,6 @@
package org.mcteam.ancientgates.commands;
import org.bukkit.command.CommandSender;
import org.mcteam.ancientgates.Gate;
public class CommandHide extends BaseCommand
{
@ -19,8 +18,6 @@ public class CommandHide extends BaseCommand
{
gate.setHidden(true);
sendMessage("The gate " + gate.getId() + " is now hidden.");
Gate.save();
}
@Override

View File

@ -2,7 +2,6 @@ package org.mcteam.ancientgates.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.mcteam.ancientgates.Gate;
public class CommandInfo extends BaseCommand
@ -36,18 +35,15 @@ public class CommandInfo extends BaseCommand
sendMessage(openHiddenMessage);
if (gate.getFrom() != null)
sendMessage(ChatColor.GREEN + "'from' location: " + ChatColor.YELLOW + "( " + gate.getFrom().getBlockX() + " | " + gate.getFrom().getBlockY() + " | " + gate.getFrom().getBlockZ() + " ) in " + gate.getFrom().getWorld().getName());
if (gate.getLocation() != null)
sendMessage(ChatColor.GREEN + "'from' location: " + ChatColor.YELLOW + "( " + gate.getLocation().getBlockX() + " | " + gate.getLocation().getBlockY() + " | " + gate.getLocation().getBlockZ() + " ) in " + gate.getLocation().getWorld().getName());
else
sendMessage(ChatColor.GREEN + "this gate has no 'from' location");
if (gate.getTo() != null)
sendMessage(ChatColor.GREEN + "'to' location: " + ChatColor.YELLOW + "( " + gate.getTo().getBlockX() + " | " + gate.getTo().getBlockY() + " | " + gate.getTo().getBlockZ() + " ) in " + gate.getTo().getWorld().getName());
if (gate.getExit() != null)
sendMessage(ChatColor.GREEN + "'to' location: " + ChatColor.YELLOW + "( " + gate.getExit().getBlockX() + " | " + gate.getExit().getBlockY() + " | " + gate.getExit().getBlockZ() + " ) in " + gate.getExit().getWorld().getName());
else
sendMessage(ChatColor.GREEN + "this gate has no 'to' location");
Gate.save();
}

View File

@ -8,10 +8,11 @@ import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.mcteam.ancientgates.Conf;
import org.mcteam.ancientgates.Gate;
import org.mcteam.ancientgates.util.TextUtil;
public class CommandList extends BaseCommand
{
public CommandList()
@ -29,11 +30,11 @@ public class CommandList extends BaseCommand
protected String intToTitleString(int i)
{
if ( i < 26 )
return Conf.colorMember + "" + (char)(i+65) + ":";
return ChatColor.GREEN + "" + (char)(i+65) + ":";
else if ( i == 26 )
return Conf.colorMember + "0 - 9:";
return ChatColor.GREEN + "0 - 9:";
else
return Conf.colorMember + "!@#$:";
return ChatColor.GREEN + "!@#$:";
}
@ -211,8 +212,6 @@ public class CommandList extends BaseCommand
else
sendMessage(messages);
}
Gate.save();
}

View File

@ -2,7 +2,6 @@ package org.mcteam.ancientgates.commands;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.mcteam.ancientgates.Gate;
public class CommandOpen extends BaseCommand {
@ -15,30 +14,30 @@ public class CommandOpen extends BaseCommand {
}
public void perform() {
if (gate.getFrom() == null) {
if (gate.getLocation() == null) {
sendMessage("You must set the from location first. To fix that:");
sendMessage(new CommandSetFrom().getUsageTemplate(true, true));
return;
}
if (gate.getTo() == null) {
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.getFrom().getBlock().getType() != Material.AIR) {
if (gate.getLocation().getBlock().getType() != Material.AIR) {
sendMessage("The gate could not open. The from location is not air.");
return;
}
if (gate.open()) {
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));
}
Gate.save();
}

View File

@ -26,19 +26,15 @@ public class CommandRename extends BaseCommand
public void perform()
{
String newId = parameters.get(1);
String oldId = gate.getId();
if (Gate.exists(newId))
{
sendMessage("Cannot rename " + oldId + ". There is already a gate named " + newId + ".");
return;
try {
Gate.rename(gate, newId);
}
catch (Exception e) {
sendMessage("Cannot rename " + gate.getId() + ". There is already a gate named " + newId + ".");
}
Gate.rename(gate, newId);
sendMessage("Gate " + oldId + " is now known as " + newId + ".");
Gate.save();
sendMessage("Gate " + gate.getId() + " is now known as " + newId + ".");
}

View File

@ -1,15 +1,16 @@
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.Conf;
import org.mcteam.ancientgates.Gate;
import org.mcteam.ancientgates.util.FloodUtil;
public class CommandSetFrom extends BaseCommand
{
@ -40,17 +41,17 @@ public class CommandSetFrom extends BaseCommand
if (gateBlocks == null)
{
sendMessage("There is no portal here, or your portal is too large.\nMax size is: " + Conf.getGateMaxArea() + " Blocks.");
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.setFrom(player.getLocation());
gate.setLocation(player.getLocation());
}
else if (upBlock.getType() == Material.AIR)
{
gate.setFrom(playerUpLocation);
gate.setLocation(playerUpLocation);
}
else
{
@ -60,8 +61,6 @@ public class CommandSetFrom extends BaseCommand
sendMessage("From location for gate \""+gate.getId()+"\" is now where you stand.");
sendMessage("Your gate includes " + gateBlocks.size() + " Blocks.");
Gate.save();
}

View File

@ -1,7 +1,6 @@
package org.mcteam.ancientgates.commands;
import org.bukkit.command.CommandSender;
import org.mcteam.ancientgates.Gate;
public class CommandSetTo extends BaseCommand {
@ -15,10 +14,8 @@ public class CommandSetTo extends BaseCommand {
}
public void perform() {
gate.setTo(player.getLocation());
gate.setExit(player.getLocation());
sendMessage("To location for gate \""+gate.getId()+"\" is now where you stand.");
Gate.save();
}

View File

@ -1,7 +1,6 @@
package org.mcteam.ancientgates.commands;
import org.bukkit.command.CommandSender;
import org.mcteam.ancientgates.Gate;
public class CommandUnhide extends BaseCommand
{
@ -17,12 +16,14 @@ public class CommandUnhide extends BaseCommand
public void perform()
{
if (gate.setHidden(false))
sendMessage("The gate " + gate.getId() + " is no longer hidden.");
else
sendMessage("Failed to unhide the gate. Does the portal have a frame?");
boolean isOpen = gate.isOpen();
Gate.save();
gate.setHidden(false);
sendMessage("The gate " + gate.getId() + " is no longer hidden.");
if (isOpen != gate.isOpen()) {
sendMessage("The Portal is now closed. Does the portal have a frame?");
}
}