Made ingame prints colored.

This commit is contained in:
Tobias Ottenweller 2013-02-11 21:06:10 +01:00
parent b9e84b122d
commit cf2155ab40
13 changed files with 150 additions and 84 deletions

View File

@ -3,6 +3,7 @@ package de.craftinc.gates.commands;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -89,28 +90,28 @@ public abstract class BaseCommand
senderHasPermission = this.hasPermission();
}
catch (Exception e) { // the gate paramter is missing or incorrect!
senderHasPermission = parameterIsGate ? false : true; // only display the lack of permission message if there is a gate
// this should prevent giving permission to the user if there is
// a bug inside the permission validation code.
senderHasPermission = this.hasGateParam ? false : true; // only display the lack of permission message if there is a gate
// this should prevent giving permission to the user if there is
// a bug inside the permission validation code.
}
if(!senderHasPermission)
{
sendMessage("You lack the permissions to " + this.helpDescription.toLowerCase() + ".");
sendMessage(ChatColor.RED + "You lack the permissions to " + this.helpDescription.toLowerCase() + ".");
return false;
}
if (this.senderMustBePlayer && !senderIsPlayer)
{
sendMessage("This command can only be used by ingame players.");
sendMessage(ChatColor.RED + "This command can only be used by ingame players.");
return false;
}
if (this.hasGateParam && !parameterIsGate)
{
sendMessage("There exists no gate with id " + this.parameters.get(0));
sendMessage(ChatColor.RED + "There exists no gate with id " + this.parameters.get(0));
return false;
}
@ -201,9 +202,9 @@ public abstract class BaseCommand
protected String getUsageTemplate(boolean withColor, boolean withDescription) {
String ret = "";
// if (withColor) {
// ret += Conf.colorCommand;
// }
if (withColor) {
ret += ChatColor.AQUA;
}
ret += "/" + Plugin.instance.getBaseCommand() + " " + TextUtil.implode(this.getAliases(), ",")+" ";
@ -217,15 +218,21 @@ public abstract class BaseCommand
parts.add("*["+optionalParameter+"]");
}
// if (withColor) {
// ret += Conf.colorParameter;
// }
if (withColor) {
ret += ChatColor.DARK_AQUA;
}
ret += TextUtil.implode(parts, " ");
// if (withDescription) {
// ret += " "+Conf.colorSystem + this.helpDescription;
// }
if (withDescription) {
ret += " ";
if (withColor) {
ret += ChatColor.YELLOW;
}
ret += this.helpDescription;
}
return ret;
}

View File

@ -1,5 +1,9 @@
package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin;
@ -22,13 +26,19 @@ public class CommandClose extends BaseCommand
@Override
public void perform()
{
try {
try
{
gate.setOpen(false);
sendMessage(ChatColor.GREEN + "The gate was closed.");
}
catch(Exception e) {
catch(Exception e)
{
sendMessage(ChatColor.RED + "Opening the gate failed! See server log for more information");
Plugin.log(Level.WARNING, e.getMessage());
e.printStackTrace();
}
sendMessage("The gate was closed.");
}
}

View File

@ -1,5 +1,8 @@
package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import de.craftinc.gates.Gate;
@ -30,27 +33,36 @@ public class CommandCreate extends BaseLocationCommand
{
String id = parameters.get(0);
try {
try
{
gate = Gate.create(id);
sendMessage("ChatColor.GREEN + Gate with id \"" + id + "\" was created.");
}
catch (Exception e) {
System.out.println(e.getMessage());
catch (Exception e)
{
sendMessage(ChatColor.RED + "Creating the gate failed! See server log for more information");
Plugin.log(Level.WARNING, e.getMessage());
e.printStackTrace();
return;
}
Location playerLocation = getValidPlayerLocation();
if (playerLocation != null) {
try {
if (playerLocation != null)
{
try
{
gate.setLocation(playerLocation);
sendMessage(ChatColor.AQUA + "The gates location has been set to your current location.");
}
catch (Exception e) {
catch (Exception e)
{
}
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.");
else
{
sendMessage(ChatColor.GREEN + "Gate with id \"" + id + "\" was created.");
sendMessage("Now you should build a frame and:");
sendMessage(new CommandSetLocation().getUsageTemplate(true, true));
}

View File

@ -1,5 +1,7 @@
package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin;
@ -27,7 +29,7 @@ public class CommandDelete extends BaseCommand
public void perform()
{
Gate.delete(gate.getId());
sendMessage("Gate with id '" + gate.getId() + "' was deleted.");
sendMessage(ChatColor.GREEN + "Gate with id '" + gate.getId() + "' was deleted.");
}
}

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import org.bukkit.command.CommandSender;
import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin;
import de.craftinc.gates.util.TextUtil;
public class CommandHelp extends BaseCommand
@ -17,10 +18,11 @@ public class CommandHelp extends BaseCommand
aliases.add("?");
optionalParameters.add("page");
helpDescription = "prints this help page";
requiredPermission = Plugin.permissionInfo;
hasGateParam = false;
helpDescription = "Prints a list of all availible commands.";
needsPermissionAtCurrentLocation = false;
}
@ -47,7 +49,7 @@ public class CommandHelp extends BaseCommand
}
}
sendMessage(TextUtil.titleize("Craft Inc. Gates Help ("+page+"/"+helpPages.size()+")"));
sendMessage(TextUtil.titleize("Craft Inc. Gates Help (" + page + "/" + helpPages.size() + ")"));
page -= 1;
if (page < 0 || page >= helpPages.size())

View File

@ -1,8 +1,10 @@
package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin;
import de.craftinc.gates.util.TextUtil;
public class CommandInfo extends BaseCommand
@ -24,31 +26,31 @@ public class CommandInfo extends BaseCommand
public void perform()
{
sendMessage(ChatColor.LIGHT_PURPLE + "Information about " + ChatColor.WHITE + gate.getId() + ChatColor.LIGHT_PURPLE + ":");
sendMessage(TextUtil.titleize("Information about: '" + ChatColor.WHITE + gate.getId() + ChatColor.YELLOW + "'"));
String openHiddenMessage = "This gate is";
String openHiddenMessage = ChatColor.DARK_AQUA + "This gate is";
if (gate.isOpen())
openHiddenMessage += " open";
openHiddenMessage += ChatColor.AQUA + " open";
else
openHiddenMessage += " closed";
openHiddenMessage += ChatColor.AQUA + " closed";
if (gate.isHidden())
openHiddenMessage += " and hidden";
openHiddenMessage += ChatColor.DARK_AQUA +" and" + ChatColor.AQUA + " hidden";
openHiddenMessage += ".";
openHiddenMessage += ".\n";
sendMessage(openHiddenMessage);
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());
sendMessage(ChatColor.DARK_AQUA + "from: " + ChatColor.AQUA + "( " + gate.getLocation().getBlockX() + " | " + gate.getLocation().getBlockY() + " | " + gate.getLocation().getBlockZ() + " ) in " + gate.getLocation().getWorld().getName());
else
sendMessage(ChatColor.GREEN + "this gate has no 'from' location");
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no 'from' location");
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());
sendMessage(ChatColor.DARK_AQUA + "to: " + ChatColor.AQUA + "( " + gate.getExit().getBlockX() + " | " + gate.getExit().getBlockY() + " | " + gate.getExit().getBlockZ() + " ) in " + gate.getExit().getWorld().getName());
else
sendMessage(ChatColor.GREEN + "this gate has no 'to' location");
sendMessage(ChatColor.DARK_AQUA + "NOTE: this gate has no 'to' location");
}
}

View File

@ -21,25 +21,24 @@ public class CommandList extends BaseCommand
optionalParameters.add("page");
hasGateParam = false;
needsPermissionAtCurrentLocation = false;
helpDescription = "Prints a list of all availible gates.";
helpDescription = "lists all availible gates.";
requiredPermission = Plugin.permissionInfo;
needsPermissionAtCurrentLocation = false;
}
protected String intToTitleString(int i)
{
if ( i < 26 ) {
return ChatColor.GREEN + "" + (char)(i+65) + ":";
return ChatColor.DARK_AQUA + "" + (char)(i+65) + ":";
}
else if ( i == 26 ) {
return ChatColor.GREEN + "0 - 9:";
return ChatColor.DARK_AQUA + "0 - 9:";
}
else {
return ChatColor.GREEN + "!@#$:";
return ChatColor.DARK_AQUA + "!@#$:";
}
}
@ -121,7 +120,7 @@ public class CommandList extends BaseCommand
linesLeftOnCurrentPage -= numLinesForCurrentChar;
if (currentPage == page) {
pageMessages.add(TextUtil.implode(currentIds, ", "));
pageMessages.add(ChatColor.AQUA + TextUtil.implode(currentIds, ", "));
if (finishedCurrentIds == false) {
pageMessages.set(pageMessages.size() -2, pageMessages.get(pageMessages.size() -2) + " (more on previous page)");
}
@ -144,7 +143,7 @@ public class CommandList extends BaseCommand
String stringToPutOnCurrentPage = TextUtil.implode(idsToPutOnCurrentPage, ", ");
if (currentPage == page) {
pageMessages.add(stringToPutOnCurrentPage);
pageMessages.add(ChatColor.AQUA + stringToPutOnCurrentPage);
pageMessages.set(pageMessages.size() -2, pageMessages.get(pageMessages.size() -2) + " (more on next page)");
}
@ -167,7 +166,7 @@ public class CommandList extends BaseCommand
}
else {
ArrayList<String> retVal = new ArrayList<String>();
retVal.add(ChatColor.LIGHT_PURPLE + "This is page " + ChatColor.WHITE + page + ChatColor.LIGHT_PURPLE + "/" + ChatColor.WHITE + --currentPage + ChatColor.LIGHT_PURPLE + ". There are " + gates.size() + " gates on this server: ");
retVal.add(TextUtil.titleize("List of all gates (" + page + "/" + + --currentPage + ")"));
retVal.addAll(pageMessages);
return retVal;
@ -180,7 +179,7 @@ public class CommandList extends BaseCommand
Collection<Gate> gates = Gate.getAll();
if (gates.size() == 0) {
sendMessage("There are no gates yet.");
sendMessage(ChatColor.RED + "There are no gates yet.");
}
else {
int page = 1;
@ -194,7 +193,7 @@ public class CommandList extends BaseCommand
List<String> messages = message(page);
if (messages == null) {
sendMessage("The requested page is not availible");
sendMessage(ChatColor.RED + "The requested page is not availible");
}
else {
sendMessage(messages);

View File

@ -1,5 +1,8 @@
package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin;
@ -22,15 +25,15 @@ public class CommandOpen extends BaseCommand
public void perform()
{
try {
try
{
gate.setOpen(true);
} catch (Exception e) {
sendMessage(e.getMessage());
return;
sendMessage(ChatColor.GREEN + "The gate was opened.");
}
catch (Exception e)
{
sendMessage(ChatColor.RED + e.getMessage());
}
sendMessage("The gate was opened.");
}
}

View File

@ -1,5 +1,7 @@
package de.craftinc.gates.commands;
import org.bukkit.ChatColor;
import de.craftinc.gates.Gate;
import de.craftinc.gates.Plugin;
@ -30,14 +32,15 @@ public class CommandRename extends BaseCommand
{
String newId = parameters.get(1);
try {
try
{
Gate.rename(gate.getId(), newId);
sendMessage(ChatColor.GREEN + "Gate " + gate.getId() + " is now known as " + newId + ".");
}
catch (Exception e) {
sendMessage("Cannot rename " + gate.getId() + ". There is already a gate named " + newId + ".");
catch (Exception e)
{
sendMessage(ChatColor.RED + "Cannot rename " + gate.getId() + ". There is already a gate named " + newId + ".");
}
sendMessage("Gate " + gate.getId() + " is now known as " + newId + ".");
}
}

View File

@ -1,5 +1,9 @@
package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin;
@ -23,14 +27,16 @@ public class CommandSetExit extends BaseCommand
public void perform()
{
try {
try
{
gate.setExit(player.getLocation());
sendMessage(ChatColor.GREEN + "The exit of gate '" + gate.getId() + "' is now where you stand.");
}
catch (Exception e) {
sendMessage(e.getMessage());
sendMessage(ChatColor.RED + "Setting the exit for the gate failed! See server log for more information");
Plugin.log(Level.WARNING, e.getMessage());
e.printStackTrace();
}
sendMessage("The exit of gate '" + gate.getId() + "' is now where you stand.");
}
}

View File

@ -1,5 +1,9 @@
package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin;
@ -22,13 +26,16 @@ public class CommandSetHidden extends BaseCommand
public void perform()
{
try {
try
{
gate.setHidden(true);
sendMessage(ChatColor.GREEN + "The gate '" + gate.getId() + "' is now hidden.");
}
catch (Exception e) {
sendMessage(e.getMessage());
catch (Exception e)
{
sendMessage(ChatColor.RED + "Hiding the gate failed! See server log for more information");
Plugin.log(Level.WARNING, e.getMessage());
e.printStackTrace();
}
sendMessage("The gate '" + gate.getId() + "' is now hidden.");
}
}

View File

@ -1,6 +1,9 @@
package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import de.craftinc.gates.Plugin;
@ -28,19 +31,23 @@ public class CommandSetLocation extends BaseLocationCommand
{
Location playerLocation = getValidPlayerLocation();
if (playerLocation == null) {
if (playerLocation == null)
{
sendMessage("There is not enough room for a gate to open here");
return;
}
try {
try
{
gate.setLocation(playerLocation);
sendMessage(ChatColor.GREEN + "The location of '" + gate.getId() + "' is now at your current location.");
}
catch (Exception e) {
sendMessage(e.getMessage());
catch (Exception e)
{
sendMessage(ChatColor.RED + "Setting the location for the gate failed! See server log for more information");
Plugin.log(Level.WARNING, e.getMessage());
e.printStackTrace();
}
sendMessage("The location of '" + gate.getId() + "' is now at your current location.");
}
}

View File

@ -1,5 +1,9 @@
package de.craftinc.gates.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import de.craftinc.gates.Plugin;
@ -23,14 +27,16 @@ public class CommandSetVisible extends BaseCommand
public void perform()
{
try {
try
{
gate.setHidden(false);
sendMessage(ChatColor.GREEN + "The gate " + gate.getId() + " is now visible.");
}
catch (Exception e) {
sendMessage(e.getMessage());
sendMessage(ChatColor.RED + e.getMessage());
}
sendMessage("The gate " + gate.getId() + " is now visible.");
}
}