refactoring: commands now working again
This commit is contained in:
parent
737ea7521e
commit
750a867d2f
@ -8,7 +8,6 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import org.mcteam.ancientgates.Gate;
|
import org.mcteam.ancientgates.Gate;
|
||||||
import org.mcteam.ancientgates.Plugin;
|
import org.mcteam.ancientgates.Plugin;
|
||||||
import org.mcteam.ancientgates.Conf;
|
|
||||||
import org.mcteam.ancientgates.util.TextUtil;
|
import org.mcteam.ancientgates.util.TextUtil;
|
||||||
|
|
||||||
public class BaseCommand
|
public class BaseCommand
|
||||||
@ -67,7 +66,7 @@ public class BaseCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(String message) {
|
public void sendMessage(String message) {
|
||||||
sender.sendMessage(Conf.colorSystem+message);
|
sender.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(List<String> messages) {
|
public void sendMessage(List<String> messages) {
|
||||||
@ -126,11 +125,11 @@ public class BaseCommand
|
|||||||
public String getUsageTemplate(boolean withColor, boolean withDescription) {
|
public String getUsageTemplate(boolean withColor, boolean withDescription) {
|
||||||
String ret = "";
|
String ret = "";
|
||||||
|
|
||||||
if (withColor) {
|
// if (withColor) {
|
||||||
ret += Conf.colorCommand;
|
// 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>();
|
List<String> parts = new ArrayList<String>();
|
||||||
|
|
||||||
@ -142,15 +141,15 @@ public class BaseCommand
|
|||||||
parts.add("*["+optionalParameter+"]");
|
parts.add("*["+optionalParameter+"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (withColor) {
|
// if (withColor) {
|
||||||
ret += Conf.colorParameter;
|
// ret += Conf.colorParameter;
|
||||||
}
|
// }
|
||||||
|
|
||||||
ret += TextUtil.implode(parts, " ");
|
ret += TextUtil.implode(parts, " ");
|
||||||
|
|
||||||
if (withDescription) {
|
// if (withDescription) {
|
||||||
ret += " "+Conf.colorSystem + this.helpDescription;
|
// ret += " "+Conf.colorSystem + this.helpDescription;
|
||||||
}
|
// }
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.mcteam.ancientgates.commands;
|
package org.mcteam.ancientgates.commands;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.mcteam.ancientgates.Gate;
|
|
||||||
|
|
||||||
public class CommandClose extends BaseCommand
|
public class CommandClose extends BaseCommand
|
||||||
{
|
{
|
||||||
@ -17,9 +16,8 @@ public class CommandClose extends BaseCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
gate.close();
|
gate.setOpen(false);
|
||||||
sendMessage("The gate was closed.");
|
sendMessage("The gate was closed.");
|
||||||
Gate.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@ public class CommandCreate extends BaseCommand
|
|||||||
Gate.create(id);
|
Gate.create(id);
|
||||||
sendMessage("Gate with id \"" + id + "\" was created. Now you should:");
|
sendMessage("Gate with id \"" + id + "\" was created. Now you should:");
|
||||||
sendMessage(new CommandSetFrom().getUsageTemplate(true, true));
|
sendMessage(new CommandSetFrom().getUsageTemplate(true, true));
|
||||||
Gate.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.mcteam.ancientgates.Conf;
|
|
||||||
import org.mcteam.ancientgates.Gate;
|
import org.mcteam.ancientgates.Gate;
|
||||||
import org.mcteam.ancientgates.util.FloodUtil;
|
import org.mcteam.ancientgates.util.FloodUtil;
|
||||||
|
|
||||||
@ -56,17 +55,17 @@ public class CommandCreateSetFrom extends BaseCommand
|
|||||||
|
|
||||||
if (gateBlocks == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerBlock.getType() == Material.AIR)
|
if (playerBlock.getType() == Material.AIR)
|
||||||
{
|
{
|
||||||
gate.setFrom(player.getLocation());
|
gate.setLocation(player.getLocation());
|
||||||
}
|
}
|
||||||
else if (upBlock.getType() == Material.AIR)
|
else if (upBlock.getType() == Material.AIR)
|
||||||
{
|
{
|
||||||
gate.setFrom(playerUpLocation);
|
gate.setLocation(playerUpLocation);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -76,8 +75,6 @@ public class CommandCreateSetFrom extends BaseCommand
|
|||||||
|
|
||||||
sendMessage("From location for gate \""+gate.getId()+"\" is now where you stand.");
|
sendMessage("From location for gate \""+gate.getId()+"\" is now where you stand.");
|
||||||
sendMessage("Your gate includes " + gateBlocks.size() + " Blocks.");
|
sendMessage("Your gate includes " + gateBlocks.size() + " Blocks.");
|
||||||
|
|
||||||
Gate.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,10 +18,9 @@ public class CommandDelete extends BaseCommand {
|
|||||||
|
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
gate.close();
|
gate.setOpen(false);
|
||||||
sendMessage("Gate with id \"" + gate.getId() + "\" was deleted.");
|
sendMessage("Gate with id \"" + gate.getId() + "\" was deleted.");
|
||||||
Gate.delete(gate.getId());
|
Gate.delete(gate.getId());
|
||||||
Gate.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.mcteam.ancientgates.commands;
|
package org.mcteam.ancientgates.commands;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.mcteam.ancientgates.Gate;
|
|
||||||
|
|
||||||
public class CommandHide extends BaseCommand
|
public class CommandHide extends BaseCommand
|
||||||
{
|
{
|
||||||
@ -19,8 +18,6 @@ public class CommandHide extends BaseCommand
|
|||||||
{
|
{
|
||||||
gate.setHidden(true);
|
gate.setHidden(true);
|
||||||
sendMessage("The gate " + gate.getId() + " is now hidden.");
|
sendMessage("The gate " + gate.getId() + " is now hidden.");
|
||||||
|
|
||||||
Gate.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,7 +2,6 @@ package org.mcteam.ancientgates.commands;
|
|||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.mcteam.ancientgates.Gate;
|
|
||||||
|
|
||||||
|
|
||||||
public class CommandInfo extends BaseCommand
|
public class CommandInfo extends BaseCommand
|
||||||
@ -36,18 +35,15 @@ public class CommandInfo extends BaseCommand
|
|||||||
|
|
||||||
sendMessage(openHiddenMessage);
|
sendMessage(openHiddenMessage);
|
||||||
|
|
||||||
if (gate.getFrom() != null)
|
if (gate.getLocation() != null)
|
||||||
sendMessage(ChatColor.GREEN + "'from' location: " + ChatColor.YELLOW + "( " + gate.getFrom().getBlockX() + " | " + gate.getFrom().getBlockY() + " | " + gate.getFrom().getBlockZ() + " ) in " + gate.getFrom().getWorld().getName());
|
sendMessage(ChatColor.GREEN + "'from' location: " + ChatColor.YELLOW + "( " + gate.getLocation().getBlockX() + " | " + gate.getLocation().getBlockY() + " | " + gate.getLocation().getBlockZ() + " ) in " + gate.getLocation().getWorld().getName());
|
||||||
else
|
else
|
||||||
sendMessage(ChatColor.GREEN + "this gate has no 'from' location");
|
sendMessage(ChatColor.GREEN + "this gate has no 'from' location");
|
||||||
|
|
||||||
if (gate.getTo() != null)
|
if (gate.getExit() != null)
|
||||||
sendMessage(ChatColor.GREEN + "'to' location: " + ChatColor.YELLOW + "( " + gate.getTo().getBlockX() + " | " + gate.getTo().getBlockY() + " | " + gate.getTo().getBlockZ() + " ) in " + gate.getTo().getWorld().getName());
|
sendMessage(ChatColor.GREEN + "'to' location: " + ChatColor.YELLOW + "( " + gate.getExit().getBlockX() + " | " + gate.getExit().getBlockY() + " | " + gate.getExit().getBlockZ() + " ) in " + gate.getExit().getWorld().getName());
|
||||||
else
|
else
|
||||||
sendMessage(ChatColor.GREEN + "this gate has no 'to' location");
|
sendMessage(ChatColor.GREEN + "this gate has no 'to' location");
|
||||||
|
|
||||||
|
|
||||||
Gate.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,10 +8,11 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.mcteam.ancientgates.Conf;
|
|
||||||
import org.mcteam.ancientgates.Gate;
|
import org.mcteam.ancientgates.Gate;
|
||||||
import org.mcteam.ancientgates.util.TextUtil;
|
import org.mcteam.ancientgates.util.TextUtil;
|
||||||
|
|
||||||
|
|
||||||
public class CommandList extends BaseCommand
|
public class CommandList extends BaseCommand
|
||||||
{
|
{
|
||||||
public CommandList()
|
public CommandList()
|
||||||
@ -29,11 +30,11 @@ public class CommandList extends BaseCommand
|
|||||||
protected String intToTitleString(int i)
|
protected String intToTitleString(int i)
|
||||||
{
|
{
|
||||||
if ( i < 26 )
|
if ( i < 26 )
|
||||||
return Conf.colorMember + "" + (char)(i+65) + ":";
|
return ChatColor.GREEN + "" + (char)(i+65) + ":";
|
||||||
else if ( i == 26 )
|
else if ( i == 26 )
|
||||||
return Conf.colorMember + "0 - 9:";
|
return ChatColor.GREEN + "0 - 9:";
|
||||||
else
|
else
|
||||||
return Conf.colorMember + "!@#$:";
|
return ChatColor.GREEN + "!@#$:";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -211,8 +212,6 @@ public class CommandList extends BaseCommand
|
|||||||
else
|
else
|
||||||
sendMessage(messages);
|
sendMessage(messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gate.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package org.mcteam.ancientgates.commands;
|
|||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.mcteam.ancientgates.Gate;
|
|
||||||
|
|
||||||
public class CommandOpen extends BaseCommand {
|
public class CommandOpen extends BaseCommand {
|
||||||
|
|
||||||
@ -15,30 +14,30 @@ public class CommandOpen extends BaseCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void perform() {
|
public void perform() {
|
||||||
if (gate.getFrom() == null) {
|
if (gate.getLocation() == null) {
|
||||||
sendMessage("You must set the from location first. To fix that:");
|
sendMessage("You must set the from location first. To fix that:");
|
||||||
sendMessage(new CommandSetFrom().getUsageTemplate(true, true));
|
sendMessage(new CommandSetFrom().getUsageTemplate(true, true));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gate.getTo() == null) {
|
if (gate.getExit() == null) {
|
||||||
sendMessage("Sure, but note that this gate does not point anywhere :P");
|
sendMessage("Sure, but note that this gate does not point anywhere :P");
|
||||||
sendMessage("To fix that: " + new CommandSetTo().getUsageTemplate(true, true));
|
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.");
|
sendMessage("The gate could not open. The from location is not air.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gate.open()) {
|
gate.setOpen(true);
|
||||||
|
|
||||||
|
if (gate.isOpen()) {
|
||||||
sendMessage("The gate was opened.");
|
sendMessage("The gate was opened.");
|
||||||
} else {
|
} else {
|
||||||
sendMessage("Failed to open the gate. Have you built a frame?");
|
sendMessage("Failed to open the gate. Have you built a frame?");
|
||||||
sendMessage("More info here: " + new CommandHelp().getUsageTemplate(true, true));
|
sendMessage("More info here: " + new CommandHelp().getUsageTemplate(true, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
Gate.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,19 +26,15 @@ public class CommandRename extends BaseCommand
|
|||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
String newId = parameters.get(1);
|
String newId = parameters.get(1);
|
||||||
String oldId = gate.getId();
|
|
||||||
|
|
||||||
if (Gate.exists(newId))
|
try {
|
||||||
{
|
Gate.rename(gate, newId);
|
||||||
sendMessage("Cannot rename " + oldId + ". There is already a gate named " + newId + ".");
|
}
|
||||||
return;
|
catch (Exception e) {
|
||||||
|
sendMessage("Cannot rename " + gate.getId() + ". There is already a gate named " + newId + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
Gate.rename(gate, newId);
|
sendMessage("Gate " + gate.getId() + " is now known as " + newId + ".");
|
||||||
|
|
||||||
sendMessage("Gate " + oldId + " is now known as " + newId + ".");
|
|
||||||
|
|
||||||
Gate.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
package org.mcteam.ancientgates.commands;
|
package org.mcteam.ancientgates.commands;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.mcteam.ancientgates.Conf;
|
|
||||||
import org.mcteam.ancientgates.Gate;
|
|
||||||
import org.mcteam.ancientgates.util.FloodUtil;
|
import org.mcteam.ancientgates.util.FloodUtil;
|
||||||
|
|
||||||
|
|
||||||
public class CommandSetFrom extends BaseCommand
|
public class CommandSetFrom extends BaseCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -40,17 +41,17 @@ public class CommandSetFrom extends BaseCommand
|
|||||||
|
|
||||||
if (gateBlocks == null)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerBlock.getType() == Material.AIR)
|
if (playerBlock.getType() == Material.AIR)
|
||||||
{
|
{
|
||||||
gate.setFrom(player.getLocation());
|
gate.setLocation(player.getLocation());
|
||||||
}
|
}
|
||||||
else if (upBlock.getType() == Material.AIR)
|
else if (upBlock.getType() == Material.AIR)
|
||||||
{
|
{
|
||||||
gate.setFrom(playerUpLocation);
|
gate.setLocation(playerUpLocation);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -60,8 +61,6 @@ public class CommandSetFrom extends BaseCommand
|
|||||||
|
|
||||||
sendMessage("From location for gate \""+gate.getId()+"\" is now where you stand.");
|
sendMessage("From location for gate \""+gate.getId()+"\" is now where you stand.");
|
||||||
sendMessage("Your gate includes " + gateBlocks.size() + " Blocks.");
|
sendMessage("Your gate includes " + gateBlocks.size() + " Blocks.");
|
||||||
|
|
||||||
Gate.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.mcteam.ancientgates.commands;
|
package org.mcteam.ancientgates.commands;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.mcteam.ancientgates.Gate;
|
|
||||||
|
|
||||||
public class CommandSetTo extends BaseCommand {
|
public class CommandSetTo extends BaseCommand {
|
||||||
|
|
||||||
@ -15,10 +14,8 @@ public class CommandSetTo extends BaseCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void perform() {
|
public void perform() {
|
||||||
gate.setTo(player.getLocation());
|
gate.setExit(player.getLocation());
|
||||||
sendMessage("To location for gate \""+gate.getId()+"\" is now where you stand.");
|
sendMessage("To location for gate \""+gate.getId()+"\" is now where you stand.");
|
||||||
|
|
||||||
Gate.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.mcteam.ancientgates.commands;
|
package org.mcteam.ancientgates.commands;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.mcteam.ancientgates.Gate;
|
|
||||||
|
|
||||||
public class CommandUnhide extends BaseCommand
|
public class CommandUnhide extends BaseCommand
|
||||||
{
|
{
|
||||||
@ -17,12 +16,14 @@ public class CommandUnhide extends BaseCommand
|
|||||||
|
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
if (gate.setHidden(false))
|
boolean isOpen = gate.isOpen();
|
||||||
sendMessage("The gate " + gate.getId() + " is no longer hidden.");
|
|
||||||
else
|
|
||||||
sendMessage("Failed to unhide the gate. Does the portal have a frame?");
|
|
||||||
|
|
||||||
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?");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user