Remove possible NPE from trait plotting

This commit is contained in:
fullwall 2018-03-09 22:33:09 +08:00
parent 8054667482
commit dd53b5eefa
3 changed files with 25 additions and 21 deletions

View File

@ -130,7 +130,7 @@ public class Metrics {
/** /**
* Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend * Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend
* *
* @param graph * @param graph
* The name of the graph * The name of the graph
*/ */
@ -145,7 +145,7 @@ public class Metrics {
/** /**
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics * Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics
* website. Plotters can be added to the graph object returned. * website. Plotters can be added to the graph object returned.
* *
* @param name * @param name
* The name of the graph * The name of the graph
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given * @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
@ -167,7 +167,7 @@ public class Metrics {
/** /**
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task. * Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
* *
* @throws java.io.IOException * @throws java.io.IOException
*/ */
public void disable() throws IOException { public void disable() throws IOException {
@ -191,7 +191,7 @@ public class Metrics {
/** /**
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task. * Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
* *
* @throws java.io.IOException * @throws java.io.IOException
*/ */
public void enable() throws IOException { public void enable() throws IOException {
@ -214,7 +214,7 @@ public class Metrics {
/** /**
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status * Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
* *
* @return the File object for the config file * @return the File object for the config file
*/ */
public File getConfigFile() { public File getConfigFile() {
@ -232,7 +232,7 @@ public class Metrics {
/** /**
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests * 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 * @return true if mineshafter is installed on the server
*/ */
private boolean isMineshafterPresent() { private boolean isMineshafterPresent() {
@ -246,7 +246,7 @@ public class Metrics {
/** /**
* Has the server owner denied plugin metrics? * Has the server owner denied plugin metrics?
* *
* @return true if metrics should be opted out of it * @return true if metrics should be opted out of it
*/ */
public boolean isOptOut() { public boolean isOptOut() {
@ -439,7 +439,7 @@ public class Metrics {
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send the * 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 * initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200
* ticks. * ticks.
* *
* @return True if statistics measuring is running, otherwise false. * @return True if statistics measuring is running, otherwise false.
*/ */
public boolean start() { public boolean start() {
@ -522,7 +522,7 @@ public class Metrics {
/** /**
* Add a plotter to the graph, which will be used to plot entries * Add a plotter to the graph, which will be used to plot entries
* *
* @param plotter * @param plotter
* the plotter to add to the graph * the plotter to add to the graph
*/ */
@ -542,7 +542,7 @@ public class Metrics {
/** /**
* Gets the graph's name * Gets the graph's name
* *
* @return the Graph's name * @return the Graph's name
*/ */
public String getName() { public String getName() {
@ -551,7 +551,7 @@ public class Metrics {
/** /**
* Gets an <b>unmodifiable</b> set of the plotter objects in the graph * Gets an <b>unmodifiable</b> set of the plotter objects in the graph
* *
* @return an unmodifiable {@link java.util.Set} of the plotter objects * @return an unmodifiable {@link java.util.Set} of the plotter objects
*/ */
public Set<Plotter> getPlotters() { public Set<Plotter> getPlotters() {
@ -571,7 +571,7 @@ public class Metrics {
/** /**
* Remove a plotter from the graph * Remove a plotter from the graph
* *
* @param plotter * @param plotter
* the plotter to remove from the graph * the plotter to remove from the graph
*/ */
@ -599,7 +599,7 @@ public class Metrics {
/** /**
* Construct a plotter with a specific plot name * Construct a plotter with a specific plot name
* *
* @param name * @param name
* the name of the plotter to use, which will show up on the website * the name of the plotter to use, which will show up on the website
*/ */
@ -619,7 +619,7 @@ public class Metrics {
/** /**
* Get the column name for the plotted point * Get the column name for the plotted point
* *
* @return the plotted point's column name * @return the plotted point's column name
*/ */
public String getColumnName() { public String getColumnName() {
@ -630,7 +630,7 @@ public class Metrics {
* Get the current value for the plotted point. Since this function defers to an external function it may or may * 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 * 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. * 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. * @return the current value for the point to be plotted.
*/ */
public abstract int getValue(); public abstract int getValue();
@ -649,7 +649,7 @@ public class Metrics {
/** /**
* Appends a json encoded key/value pair to the given string builder. * Appends a json encoded key/value pair to the given string builder.
* *
* @param json * @param json
* @param key * @param key
* @param value * @param value
@ -684,7 +684,7 @@ public class Metrics {
/** /**
* Escape a string to create a valid JSON string * Escape a string to create a valid JSON string
* *
* @param text * @param text
* @return * @return
*/ */
@ -730,7 +730,7 @@ public class Metrics {
/** /**
* GZip compress a string of bytes * GZip compress a string of bytes
* *
* @param input * @param input
* @return * @return
*/ */
@ -756,7 +756,7 @@ public class Metrics {
/** /**
* Encode text as UTF-8 * Encode text as UTF-8
* *
* @param text * @param text
* the text to encode * the text to encode
* @return the encoded text, as UTF-8 * @return the encoded text, as UTF-8

View File

@ -101,7 +101,7 @@ public class CitizensTraitFactory implements TraitFactory {
public void addPlotters(Graph graph) { public void addPlotters(Graph graph) {
for (Map.Entry<String, TraitInfo> entry : registered.entrySet()) { for (Map.Entry<String, TraitInfo> entry : registered.entrySet()) {
if (INTERNAL_TRAITS.contains(entry.getKey())) if (INTERNAL_TRAITS.contains(entry.getKey()) || entry.getKey() == null)
continue; continue;
final Class<? extends Trait> traitClass = entry.getValue().getTraitClass(); final Class<? extends Trait> traitClass = entry.getValue().getTraitClass();
graph.addPlotter(new Metrics.Plotter(entry.getKey()) { graph.addPlotter(new Metrics.Plotter(entry.getKey()) {
@ -109,8 +109,9 @@ public class CitizensTraitFactory implements TraitFactory {
public int getValue() { public int getValue() {
int numberUsingTrait = 0; int numberUsingTrait = 0;
for (NPC npc : CitizensAPI.getNPCRegistry()) { for (NPC npc : CitizensAPI.getNPCRegistry()) {
if (npc.hasTrait(traitClass)) if (npc.hasTrait(traitClass)) {
++numberUsingTrait; ++numberUsingTrait;
}
} }
return numberUsingTrait; return numberUsingTrait;
} }

View File

@ -89,6 +89,9 @@ public class Skin {
setNPCTexture(entity, localData); setNPCTexture(entity, localData);
// check if NPC prefers to use cached skin over the latest skin. // check if NPC prefers to use cached skin over the latest skin.
if (entity.getNPC().data().has("player-skin-use-latest")) {
entity.getNPC().data().remove("player-skin-use-latest");
}
if (!entity.getNPC().data().get(NPC.PLAYER_SKIN_USE_LATEST, Setting.NPC_SKIN_USE_LATEST.asBoolean())) { if (!entity.getNPC().data().get(NPC.PLAYER_SKIN_USE_LATEST, Setting.NPC_SKIN_USE_LATEST.asBoolean())) {
// cache preferred // cache preferred
return true; return true;