Add /waypoint provider

This commit is contained in:
fullwall 2012-09-30 19:36:48 +08:00
parent 1494f92689
commit 4134982674
9 changed files with 390 additions and 310 deletions

View File

@ -68,48 +68,6 @@ import org.bukkit.plugin.PluginDescriptionFile;
*/
public class Metrics {
/**
* The current revision number
*/
private final static int REVISION = 5;
/**
* The base url of the metrics domain
*/
private static final String BASE_URL = "http://mcstats.org";
/**
* The url used to report a server's status
*/
private static final String REPORT_URL = "/report/%s";
/**
* The separator to use for custom data. This MUST NOT change unless you are
* hosting your own version of metrics and want to change it.
*/
private static final String CUSTOM_DATA_SEPARATOR = "~~";
/**
* Interval of time to ping (in minutes)
*/
private static final int PING_INTERVAL = 10;
/**
* The plugin this metrics submits for
*/
private final Plugin plugin;
/**
* All of the custom graphs to submit to metrics
*/
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
/**
* The default graph, used for addCustomData when you don't want a specific
* graph
*/
private final Graph defaultGraph = new Graph("Default");
/**
* The plugin configuration file
*/
@ -120,6 +78,17 @@ public class Metrics {
*/
private final File configurationFile;
/**
* The default graph, used for addCustomData when you don't want a specific
* graph
*/
private final Graph defaultGraph = new Graph("Default");
/**
* All of the custom graphs to submit to metrics
*/
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
/**
* Unique server id
*/
@ -130,6 +99,11 @@ public class Metrics {
*/
private final Object optOutLock = new Object();
/**
* The plugin this metrics submits for
*/
private final Plugin plugin;
/**
* Id of the scheduled task
*/
@ -160,6 +134,39 @@ public class Metrics {
guid = configuration.getString("guid");
}
/**
* Adds a custom data plotter to the default graph
*
* @param plotter
* The plotter to use to plot custom data
*/
public void addCustomData(final Plotter plotter) {
if (plotter == null) {
throw new IllegalArgumentException("Plotter cannot be null");
}
// Add the plotter to the graph o/
defaultGraph.addPlotter(plotter);
// Ensure the default graph is included in the submitted graphs
graphs.add(defaultGraph);
}
/**
* Add a Graph object to Metrics that represents data for the plugin that
* should be sent to the backend
*
* @param graph
* The name of the graph
*/
public void addGraph(final Graph graph) {
if (graph == null) {
throw new IllegalArgumentException("Graph cannot be null");
}
graphs.add(graph);
}
/**
* Construct and create a Graph that can be used to separate specific
* plotters to their own graphs on the metrics website. Plotters can be
@ -185,148 +192,6 @@ public class Metrics {
return graph;
}
/**
* Add a Graph object to Metrics that represents data for the plugin that
* should be sent to the backend
*
* @param graph
* The name of the graph
*/
public void addGraph(final Graph graph) {
if (graph == null) {
throw new IllegalArgumentException("Graph cannot be null");
}
graphs.add(graph);
}
/**
* Adds a custom data plotter to the default graph
*
* @param plotter
* The plotter to use to plot custom data
*/
public void addCustomData(final Plotter plotter) {
if (plotter == null) {
throw new IllegalArgumentException("Plotter cannot be null");
}
// Add the plotter to the graph o/
defaultGraph.addPlotter(plotter);
// Ensure the default graph is included in the submitted graphs
graphs.add(defaultGraph);
}
/**
* Start measuring statistics. This will immediately create an async
* repeating task as the plugin and send the initial data to the metrics
* backend, and then after that it will post in increments of PING_INTERVAL
* * 1200 ticks.
*
* @return True if statistics measuring is running, otherwise false.
*/
public boolean start() {
synchronized (optOutLock) {
// Did we opt out?
if (isOptOut()) {
return false;
}
// Is metrics already running?
if (taskId >= 0) {
return true;
}
// Begin hitting the server with glorious data
taskId = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
private boolean firstPost = true;
@Override
public void run() {
try {
// This has to be synchronized or it can collide with
// the disable method.
synchronized (optOutLock) {
// Disable Task, if it is running and the server
// owner decided to opt-out
if (isOptOut() && taskId > 0) {
plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
// Tell all plotters to stop gathering
// information.
for (Graph graph : graphs) {
graph.onOptOut();
}
}
}
// We use the inverse of firstPost because if it is the
// first time we are posting,
// it is not a interval ping, so it evaluates to FALSE
// Each time thereafter it will evaluate to TRUE, i.e
// PING!
postPlugin(!firstPost);
// After the first post we set firstPost to false
// Each post thereafter will be a ping
firstPost = false;
} catch (IOException e) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
}
}
}, 0, PING_INTERVAL * 1200);
return true;
}
}
/**
* Has the server owner denied plugin metrics?
*
* @return true if metrics should be opted out of it
*/
public boolean isOptOut() {
synchronized (optOutLock) {
try {
// Reload the metrics file
configuration.load(getConfigFile());
} catch (IOException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true;
} catch (InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true;
}
return configuration.getBoolean("opt-out", false);
}
}
/**
* Enables metrics for the server by setting "opt-out" to false in the
* config file and starting the metrics task.
*
* @throws IOException
*/
public void enable() throws IOException {
// This has to be synchronized or it can collide with the check in the
// task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set
// it.
if (isOptOut()) {
configuration.set("opt-out", false);
configuration.save(configurationFile);
}
// Enable Task, if it is not running
if (taskId < 0) {
start();
}
}
}
/**
* Disables metrics for the server by setting "opt-out" to true in the
* config file and canceling the metrics task.
@ -352,6 +217,30 @@ public class Metrics {
}
}
/**
* Enables metrics for the server by setting "opt-out" to false in the
* config file and starting the metrics task.
*
* @throws IOException
*/
public void enable() throws IOException {
// This has to be synchronized or it can collide with the check in the
// task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set
// it.
if (isOptOut()) {
configuration.set("opt-out", false);
configuration.save(configurationFile);
}
// Enable Task, if it is not running
if (taskId < 0) {
start();
}
}
}
/**
* Gets the File object of the config file that should be used to store data
* such as the GUID and opt-out status
@ -371,6 +260,42 @@ public class Metrics {
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
}
/**
* Check if mineshafter is present. If it is, we need to bypass it to send
* POST requests
*
* @return true if mineshafter is installed on the server
*/
private boolean isMineshafterPresent() {
try {
Class.forName("mineshafter.MineServer");
return true;
} catch (Exception e) {
return false;
}
}
/**
* Has the server owner denied plugin metrics?
*
* @return true if metrics should be opted out of it
*/
public boolean isOptOut() {
synchronized (optOutLock) {
try {
// Reload the metrics file
configuration.load(getConfigFile());
} catch (IOException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true;
} catch (InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true;
}
return configuration.getBoolean("opt-out", false);
}
}
/**
* Generic method that posts a plugin to the metrics website
*/
@ -471,54 +396,69 @@ public class Metrics {
}
/**
* Check if mineshafter is present. If it is, we need to bypass it to send
* POST requests
* Start measuring statistics. This will immediately create an async
* repeating task as the plugin and send the initial data to the metrics
* backend, and then after that it will post in increments of PING_INTERVAL
* * 1200 ticks.
*
* @return true if mineshafter is installed on the server
* @return True if statistics measuring is running, otherwise false.
*/
private boolean isMineshafterPresent() {
try {
Class.forName("mineshafter.MineServer");
public boolean start() {
synchronized (optOutLock) {
// Did we opt out?
if (isOptOut()) {
return false;
}
// Is metrics already running?
if (taskId >= 0) {
return true;
}
// Begin hitting the server with glorious data
taskId = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
private boolean firstPost = true;
@Override
public void run() {
try {
// This has to be synchronized or it can collide with
// the disable method.
synchronized (optOutLock) {
// Disable Task, if it is running and the server
// owner decided to opt-out
if (isOptOut() && taskId > 0) {
plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
// Tell all plotters to stop gathering
// information.
for (Graph graph : graphs) {
graph.onOptOut();
}
}
}
// We use the inverse of firstPost because if it is the
// first time we are posting,
// it is not a interval ping, so it evaluates to FALSE
// Each time thereafter it will evaluate to TRUE, i.e
// PING!
postPlugin(!firstPost);
// After the first post we set firstPost to false
// Each post thereafter will be a ping
firstPost = false;
} catch (IOException e) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
}
}
}, 0, PING_INTERVAL * 1200);
return true;
} catch (Exception e) {
return false;
}
}
/**
* <p>
* Encode a key/value data pair to be used in a HTTP post request. This
* INCLUDES a & so the first key/value pair MUST be included manually, e.g:
* </p>
* <code>
* StringBuffer data = new StringBuffer();
* data.append(encode("guid")).append('=').append(encode(guid));
* encodeDataPair(data, "version", description.getVersion());
* </code>
*
* @param buffer
* the stringbuilder to append the data pair onto
* @param key
* the key value
* @param value
* the value
*/
private static void encodeDataPair(final StringBuilder buffer, final String key, final String value)
throws UnsupportedEncodingException {
buffer.append('&').append(encode(key)).append('=').append(encode(value));
}
/**
* Encode text as UTF-8
*
* @param text
* the text to encode
* @return the encoded text, as UTF-8
*/
private static String encode(final String text) throws UnsupportedEncodingException {
return URLEncoder.encode(text, "UTF-8");
}
/**
* Represents a custom graph on the website
*/
@ -539,15 +479,6 @@ public class Metrics {
this.name = name;
}
/**
* Gets the graph's name
*
* @return the Graph's name
*/
public String getName() {
return name;
}
/**
* Add a plotter to the graph, which will be used to plot entries
*
@ -558,14 +489,23 @@ public class Metrics {
plotters.add(plotter);
}
@Override
public boolean equals(final Object object) {
if (!(object instanceof Graph)) {
return false;
}
final Graph graph = (Graph) object;
return graph.name.equals(name);
}
/**
* Remove a plotter from the graph
* Gets the graph's name
*
* @param plotter
* the plotter to remove from the graph
* @return the Graph's name
*/
public void removePlotter(final Plotter plotter) {
plotters.remove(plotter);
public String getName() {
return name;
}
/**
@ -582,16 +522,6 @@ public class Metrics {
return name.hashCode();
}
@Override
public boolean equals(final Object object) {
if (!(object instanceof Graph)) {
return false;
}
final Graph graph = (Graph) object;
return graph.name.equals(name);
}
/**
* Called when the server owner decides to opt-out of Metrics while the
* server is running.
@ -599,6 +529,16 @@ public class Metrics {
protected void onOptOut() {
}
/**
* Remove a plotter from the graph
*
* @param plotter
* the plotter to remove from the graph
*/
public void removePlotter(final Plotter plotter) {
plotters.remove(plotter);
}
}
/**
@ -629,16 +569,15 @@ public class Metrics {
this.name = name;
}
/**
* Get the current value for the plotted point. Since this function
* defers to an external function it may or may not return immediately
* thus cannot be guaranteed to be thread friendly or safe. This
* function can be called from any thread so care should be taken when
* accessing resources that need to be synchronized.
*
* @return the current value for the point to be plotted.
*/
public abstract int getValue();
@Override
public boolean equals(final Object object) {
if (!(object instanceof Plotter)) {
return false;
}
final Plotter plotter = (Plotter) object;
return plotter.name.equals(name) && plotter.getValue() == getValue();
}
/**
* Get the column name for the plotted point
@ -650,26 +589,87 @@ public class Metrics {
}
/**
* Called after the website graphs have been updated
* Get the current value for the plotted point. Since this function
* defers to an external function it may or may not return immediately
* thus cannot be guaranteed to be thread friendly or safe. This
* function can be called from any thread so care should be taken when
* accessing resources that need to be synchronized.
*
* @return the current value for the point to be plotted.
*/
public void reset() {
}
public abstract int getValue();
@Override
public int hashCode() {
return getColumnName().hashCode();
}
@Override
public boolean equals(final Object object) {
if (!(object instanceof Plotter)) {
return false;
}
final Plotter plotter = (Plotter) object;
return plotter.name.equals(name) && plotter.getValue() == getValue();
/**
* Called after the website graphs have been updated
*/
public void reset() {
}
}
/**
* The base url of the metrics domain
*/
private static final String BASE_URL = "http://mcstats.org";
/**
* The separator to use for custom data. This MUST NOT change unless you are
* hosting your own version of metrics and want to change it.
*/
private static final String CUSTOM_DATA_SEPARATOR = "~~";
/**
* Interval of time to ping (in minutes)
*/
private static final int PING_INTERVAL = 10;
/**
* The url used to report a server's status
*/
private static final String REPORT_URL = "/report/%s";
/**
* The current revision number
*/
private final static int REVISION = 5;
/**
* Encode text as UTF-8
*
* @param text
* the text to encode
* @return the encoded text, as UTF-8
*/
private static String encode(final String text) throws UnsupportedEncodingException {
return URLEncoder.encode(text, "UTF-8");
}
/**
* <p>
* Encode a key/value data pair to be used in a HTTP post request. This
* INCLUDES a & so the first key/value pair MUST be included manually, e.g:
* </p>
* <code>
* StringBuffer data = new StringBuffer();
* data.append(encode("guid")).append('=').append(encode(guid));
* encodeDataPair(data, "version", description.getVersion());
* </code>
*
* @param buffer
* the stringbuilder to append the data pair onto
* @param key
* the key value
* @param value
* the value
*/
private static void encodeDataPair(final StringBuilder buffer, final String key, final String value)
throws UnsupportedEncodingException {
buffer.append('&').append(encode(key)).append('=').append(encode(value));
}
}

View File

@ -3,6 +3,8 @@ package net.citizensnpcs.command;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import net.citizensnpcs.api.trait.Trait;
@Retention(RetentionPolicy.RUNTIME)
public @interface Command {
String[] aliases();
@ -19,5 +21,7 @@ public @interface Command {
String permission() default "";
Class<? extends Trait>[] traits() default {};
String usage() default "";
}

View File

@ -85,24 +85,6 @@ public class HelpCommands {
throw new CommandException("The page '" + page + "' does not exist.");
}
@Command(
aliases = { "waypoint", "waypoint", "wp" },
usage = "help (page)",
desc = "Waypoints help menu",
modifiers = { "help" },
min = 1,
max = 2,
permission = "waypoints.help")
@Requirements
public void waypointsHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
int page = args.argsLength() == 2 ? args.getInteger(1) : 1;
Paginator paginator = new Paginator().header("Waypoints Help");
for (String line : getLines(sender, npc, "waypoints"))
paginator.addLine(line);
if (!paginator.sendPage(sender, page))
throw new CommandException("The page '" + page + "' does not exist.");
}
@Command(
aliases = { "script" },
usage = "help (page)",
@ -138,4 +120,22 @@ public class HelpCommands {
if (!paginator.sendPage(sender, page))
throw new CommandException("The page '" + page + "' does not exist.");
}
@Command(
aliases = { "waypoint", "waypoint", "wp" },
usage = "help (page)",
desc = "Waypoints help menu",
modifiers = { "help" },
min = 1,
max = 2,
permission = "waypoints.help")
@Requirements
public void waypointsHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
int page = args.argsLength() == 2 ? args.getInteger(1) : 1;
Paginator paginator = new Paginator().header("Waypoints Help");
for (String line : getLines(sender, npc, "waypoints"))
paginator.addLine(line);
if (!paginator.sendPage(sender, page))
throw new CommandException("The page '" + page + "' does not exist.");
}
}

View File

@ -13,6 +13,7 @@ import net.citizensnpcs.command.Requirements;
import net.citizensnpcs.command.exception.CommandException;
import net.citizensnpcs.npc.Template;
import net.citizensnpcs.npc.Template.TemplateBuilder;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper;
@ -36,22 +37,25 @@ public class TemplateCommands {
modifiers = { "apply" },
min = 2,
permission = "templates.apply")
@Requirements
public void apply(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Template template = Template.byName(args.getString(1));
if (template == null)
throw new CommandException("Template not found.");
int appliedCount = 0;
if (args.argsLength() == 2) {
if (npc == null)
throw new CommandException(Messaging.tr(Messages.COMMAND_MUST_HAVE_SELECTED));
template.apply(npc);
appliedCount++;
} else {
String joined = args.getJoinedStrings(2, ',');
List<Integer> j = Lists.newArrayList();
List<Integer> ids = Lists.newArrayList();
for (String id : Splitter.on(',').trimResults().split(joined)) {
int parsed = Integer.parseInt(id);
j.add(parsed);
ids.add(parsed);
}
Iterable<NPC> transformed = Iterables.transform(j, new Function<Integer, NPC>() {
Iterable<NPC> transformed = Iterables.transform(ids, new Function<Integer, NPC>() {
@Override
public NPC apply(@Nullable Integer arg0) {
if (arg0 == null)

View File

@ -1,10 +1,47 @@
package net.citizensnpcs.command.command;
import net.citizensnpcs.Citizens;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.command.Command;
import net.citizensnpcs.command.CommandContext;
import net.citizensnpcs.command.Requirements;
import net.citizensnpcs.command.exception.CommandException;
import net.citizensnpcs.trait.waypoint.Waypoints;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@Requirements(ownership = true, selected = true)
public class WaypointCommands {
public WaypointCommands(Citizens plugin) {
}
@Command(
aliases = { "waypoints", "waypoint", "wp" },
usage = "provider (provider name) (-a)",
desc = "Sets the current waypoint provider",
modifiers = { "provider" },
min = 1,
max = 2,
permission = "waypoints.provider",
traits = Waypoints.class)
public void provider(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Waypoints waypoints = npc.getTrait(Waypoints.class);
if (args.argsLength() == 1) {
if (args.hasFlag('a')) {
waypoints.describeProviders(sender);
} else
Messaging.sendTr(sender, ChatColor.GREEN, Messages.CURRENT_WAYPOINT_PROVIDER,
StringHelper.wrap(waypoints.getCurrentProviderName()));
return;
}
boolean success = waypoints.setWaypointProvider(args.getString(1));
if (!success)
throw new CommandException("Provider not found.");
Messaging.sendTr(sender, ChatColor.GREEN, Messages.WAYPOINT_PROVIDER_SET,
StringHelper.wrap(args.getString(1)));
}
}

View File

@ -1,6 +1,5 @@
package net.citizensnpcs.trait.waypoint;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@ -8,9 +7,16 @@ import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.google.common.collect.Maps;
public class Waypoints extends Trait {
private WaypointProvider provider = new LinearWaypointProvider();
private String providerName = "linear";
@ -29,6 +35,13 @@ public class Waypoints extends Trait {
}
}
public void describeProviders(CommandSender sender) {
Messaging.sendTr(sender, ChatColor.AQUA, Messages.AVAILABLE_WAYPOINT_PROVIDERS);
for (String name : providers.keySet()) {
Messaging.send(sender, ChatColor.GREEN + " - " + StringHelper.wrap(name));
}
}
/**
* Returns the current {@link WaypointProvider}. May be null during
* initialisation.
@ -39,6 +52,13 @@ public class Waypoints extends Trait {
return provider;
}
/**
* @return The current provider name
*/
public String getCurrentProviderName() {
return providerName;
}
public Editor getEditor(Player player) {
return provider.createEditor(player);
}
@ -47,9 +67,9 @@ public class Waypoints extends Trait {
public void load(DataKey key) throws NPCLoadException {
provider = null;
providerName = key.getString("provider", "linear");
for (Entry<Class<? extends WaypointProvider>, String> entry : providers.entrySet()) {
if (entry.getValue().equals(providerName)) {
provider = create(entry.getKey());
for (Entry<String, Class<? extends WaypointProvider>> entry : providers.entrySet()) {
if (entry.getKey().equals(providerName)) {
provider = create(entry.getValue());
break;
}
}
@ -73,21 +93,26 @@ public class Waypoints extends Trait {
}
/**
* Sets the current {@link WaypointProvider} by using the given class. The
* class should have been registered using
* {@link Waypoints#registerWaypointProvider(Class, String)}.
* Sets the current {@link WaypointProvider} using the given name.
*
* @param provider
* Class to set as waypoint provider
* @param name
* The name of the waypoint provider, registered using
* {@link #registerWaypointProvider(Class, String)}
* @return Whether the operation succeeded
*/
public void setWaypointProvider(Class<? extends WaypointProvider> clazz) {
public boolean setWaypointProvider(String name) {
name = name.toLowerCase();
Class<? extends WaypointProvider> clazz = providers.get(name);
if (clazz == null)
return false;
provider = create(clazz);
if (provider != null) {
providerName = providers.get(clazz);
}
if (provider == null)
return false;
providerName = name;
return true;
}
private static final Map<Class<? extends WaypointProvider>, String> providers = new HashMap<Class<? extends WaypointProvider>, String>();
private static final Map<String, Class<? extends WaypointProvider>> providers = Maps.newHashMap();
/**
* Registers a {@link WaypointProvider}, which can be subsequently used by
@ -99,11 +124,11 @@ public class Waypoints extends Trait {
* The name of the waypoint provider
*/
public static void registerWaypointProvider(Class<? extends WaypointProvider> clazz, String name) {
providers.put(clazz, name);
providers.put(name, clazz);
}
static {
providers.put(LinearWaypointProvider.class, "linear");
providers.put(WanderingWaypointProvider.class, "wander");
providers.put("linear", LinearWaypointProvider.class);
providers.put("wander", WanderingWaypointProvider.class);
}
}

View File

@ -15,6 +15,7 @@ import java.util.ResourceBundle;
import com.google.common.io.Closeables;
public class Messages {
public static final String AVAILABLE_WAYPOINT_PROVIDERS = "citizens.waypoints.available-providers-message";
public static final String CITIZENS_DISABLED = "citizens.notifications.disabled";
public static final String CITIZENS_ENABLED = "citizens.notifications.enabled";
public static final String CITIZENS_IMPLEMENTATION_DISABLED = "citizens.changed-implementation";
@ -26,6 +27,7 @@ public class Messages {
public static final String COMMAND_MUST_BE_OWNER = "citizens.commands.must-be-owner";
public static final String COMMAND_MUST_HAVE_SELECTED = "citizens.commands.must-have-selected";
public static final String COMMAND_REPORT_ERROR = "citizens.commands.console-error";
public static final String CURRENT_WAYPOINT_PROVIDER = "citizens.waypoints.current-provider-message";
public static final String DATABASE_CONNECTION_FAILED = "citizens.notifications.database-connection-failed";
private static ResourceBundle defaultBundle;
public static final String ERROR_INITALISING_SUB_PLUGIN = "citizens.sub-plugins.error-on-load";
@ -44,6 +46,7 @@ public class Messages {
public static final String OVER_NPC_LIMIT = "citizens.limits.over-npc-limit";
public static final String SAVE_METHOD_SET_NOTIFICATION = "citizens.notifications.save-method-set";
public static final String UNKNOWN_COMMAND = "citizens.commands.unknown-command";
public static final String WAYPOINT_PROVIDER_SET = "citizens.waypoints.set-provider-message";
public static final String WRITING_DEFAULT_SETTING = "citizens.settings.writing-default";
private static Properties getDefaultBundleProperties() {

View File

@ -75,6 +75,10 @@ public class Messaging {
sender.sendMessage(msg);
}
public static void sendTr(CommandSender sender, ChatColor rootColour, String key, Object... msg) {
sendMessageTo(sender, rootColour + Translator.tr(key, msg));
}
public static void sendTr(CommandSender sender, String key, Object... msg) {
sendMessageTo(sender, Translator.tr(key, msg));
}

View File

@ -26,4 +26,7 @@ citizens.notifications.npc-name-not-found=Could not find a name for ID '{0}'.
citizens.notifications.npcs-loaded=Loaded {0} NPCs ({1} spawned).
citizens.notifications.save-method-set=Save method set to {0}.
citizens.notifications.database-connection-failed=Unable to connect to database, falling back to YAML
citizens.notifications.unknown-npc-type=NPC type '{0}' was not recognized. Did you spell it correctly?
citizens.notifications.unknown-npc-type=NPC type '{0}' was not recognized. Did you spell it correctly?
citizens.waypoints.current-provider-message=The current waypoint provider is {0}.
citizens.waypoints.set-provider-message=Set the waypoint provider to {0}.
citizens.waypoints.available-providers-message=List of available providers