mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-29 15:47:40 +02:00
Small cleanup
This commit is contained in:
parent
98dbdfd784
commit
cba533f317
@ -80,8 +80,6 @@ public class CitizensTraitManager implements TraitManager {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends Trait> T getTrait(String name, NPC npc) {
|
public <T extends Trait> T getTrait(String name, NPC npc) {
|
||||||
// TODO: we could replace NPC with Object... and search for the
|
|
||||||
// constructor
|
|
||||||
Class<? extends Trait> clazz = registered.get(name);
|
Class<? extends Trait> clazz = registered.get(name);
|
||||||
if (clazz == null)
|
if (clazz == null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -20,8 +20,6 @@ public class Waypoints extends Trait {
|
|||||||
public Waypoints(NPC npc) {
|
public Waypoints(NPC npc) {
|
||||||
this.npc = npc;
|
this.npc = npc;
|
||||||
npc.getAI().registerNavigationCallback(provider.getCallback());
|
npc.getAI().registerNavigationCallback(provider.getCallback());
|
||||||
// TODO: this is necessary because traits aren't loaded when added
|
|
||||||
// manually so we may be in an uninitialised state.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Editor getEditor(Player player) {
|
public Editor getEditor(Player player) {
|
||||||
@ -53,8 +51,7 @@ public class Waypoints extends Trait {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current {@link WaypointProvider} by using the given class. The
|
* Sets the current {@link WaypointProvider} by using the given class. The class should have been registered using
|
||||||
* class should have been registered using
|
|
||||||
* {@link Waypoints#registerWaypointProvider(Class, String)}.
|
* {@link Waypoints#registerWaypointProvider(Class, String)}.
|
||||||
*
|
*
|
||||||
* @param provider
|
* @param provider
|
||||||
@ -80,8 +77,7 @@ public class Waypoints extends Trait {
|
|||||||
private static final Map<Class<? extends WaypointProvider>, String> providers = new HashMap<Class<? extends WaypointProvider>, String>();
|
private static final Map<Class<? extends WaypointProvider>, String> providers = new HashMap<Class<? extends WaypointProvider>, String>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a {@link WaypointProvider}, which can be subsequently used by
|
* Registers a {@link WaypointProvider}, which can be subsequently used by NPCs.
|
||||||
* NPCs.
|
|
||||||
*
|
*
|
||||||
* @param clazz
|
* @param clazz
|
||||||
* The class of the waypoint provider
|
* The class of the waypoint provider
|
||||||
|
@ -24,13 +24,6 @@ public class ByIdArray<T> implements Iterable<T> {
|
|||||||
elementData = new Object[capacity];
|
elementData = new Object[capacity];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Uses a linear search to insert an object at the first available space.
|
|
||||||
*
|
|
||||||
* @param t
|
|
||||||
* The object to add
|
|
||||||
* @return The index the object was added at
|
|
||||||
*/
|
|
||||||
public int add(T t) {
|
public int add(T t) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (elementData[index++] != null) {
|
while (elementData[index++] != null) {
|
||||||
|
@ -48,25 +48,16 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
/**
|
|
||||||
* Tooling to post to metrics.griefcraft.com
|
|
||||||
*/
|
|
||||||
public class Metrics {
|
public class Metrics {
|
||||||
|
private static final String BASE_URL = "http://metrics.griefcraft.com";
|
||||||
|
private static final String CONFIG_FILE = "plugins/PluginMetrics/config.yml";
|
||||||
|
private final static int PING_INTERVAL = 10;
|
||||||
|
private static final String REPORT_URL = "/report/%s";
|
||||||
|
private final static int REVISION = 4;
|
||||||
|
|
||||||
/**
|
|
||||||
* The plugin configuration file
|
|
||||||
*/
|
|
||||||
private final YamlConfiguration configuration;
|
private final YamlConfiguration configuration;
|
||||||
|
|
||||||
/**
|
|
||||||
* A map of the custom data plotters for plugins
|
|
||||||
*/
|
|
||||||
private final Map<Plugin, Set<Plotter>> customData = Collections
|
private final Map<Plugin, Set<Plotter>> customData = Collections
|
||||||
.synchronizedMap(new HashMap<Plugin, Set<Plotter>>());
|
.synchronizedMap(new HashMap<Plugin, Set<Plotter>>());
|
||||||
|
|
||||||
/**
|
|
||||||
* Unique server id
|
|
||||||
*/
|
|
||||||
private final String guid;
|
private final String guid;
|
||||||
|
|
||||||
public Metrics() throws IOException {
|
public Metrics() throws IOException {
|
||||||
@ -88,12 +79,6 @@ public class Metrics {
|
|||||||
guid = configuration.getString("guid");
|
guid = configuration.getString("guid");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a custom data plotter for a given plugin
|
|
||||||
*
|
|
||||||
* @param plugin
|
|
||||||
* @param plotter
|
|
||||||
*/
|
|
||||||
public void addCustomData(Plugin plugin, Plotter plotter) {
|
public void addCustomData(Plugin plugin, Plotter plotter) {
|
||||||
Set<Plotter> plotters = customData.get(plugin);
|
Set<Plotter> plotters = customData.get(plugin);
|
||||||
|
|
||||||
@ -105,11 +90,6 @@ public class Metrics {
|
|||||||
plotters.add(plotter);
|
plotters.add(plotter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Begin measuring a plugin
|
|
||||||
*
|
|
||||||
* @param plugin
|
|
||||||
*/
|
|
||||||
public void beginMeasuringPlugin(final Plugin plugin) throws IOException {
|
public void beginMeasuringPlugin(final Plugin plugin) throws IOException {
|
||||||
// Did we opt out?
|
// Did we opt out?
|
||||||
if (configuration.getBoolean("opt-out", false)) {
|
if (configuration.getBoolean("opt-out", false)) {
|
||||||
@ -132,12 +112,6 @@ public class Metrics {
|
|||||||
}, PING_INTERVAL * 1200, PING_INTERVAL * 1200);
|
}, PING_INTERVAL * 1200, PING_INTERVAL * 1200);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if mineshafter is present. If it is, we need to bypass it to send
|
|
||||||
* POST requests
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private boolean isMineshafterPresent() {
|
private boolean isMineshafterPresent() {
|
||||||
try {
|
try {
|
||||||
Class.forName("mineshafter.MineServer");
|
Class.forName("mineshafter.MineServer");
|
||||||
@ -147,11 +121,6 @@ public class Metrics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic method that posts a plugin to the metrics website
|
|
||||||
*
|
|
||||||
* @param plugin
|
|
||||||
*/
|
|
||||||
private void postPlugin(Plugin plugin, boolean isPing) throws IOException {
|
private void postPlugin(Plugin plugin, boolean isPing) throws IOException {
|
||||||
// Construct the post data
|
// Construct the post data
|
||||||
String response = "ERR No response";
|
String response = "ERR No response";
|
||||||
@ -220,9 +189,6 @@ public class Metrics {
|
|||||||
// optional description if everything goes right
|
// optional description if everything goes right
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface used to collect custom data for a plugin
|
|
||||||
*/
|
|
||||||
public static abstract class Plotter {
|
public static abstract class Plotter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -235,66 +201,20 @@ public class Metrics {
|
|||||||
return plotter.getColumnName().equals(getColumnName()) && plotter.getValue() == getValue();
|
return plotter.getColumnName().equals(getColumnName()) && plotter.getValue() == getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the column name for the plotted point
|
|
||||||
*
|
|
||||||
* @return the plotted point's column name
|
|
||||||
*/
|
|
||||||
public abstract String getColumnName();
|
public abstract String getColumnName();
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current value for the plotted point
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public abstract int getValue();
|
public abstract int getValue();
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getColumnName().hashCode() + getValue();
|
return getColumnName().hashCode() + 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://metrics.griefcraft.com";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The file where guid and opt out is stored in
|
|
||||||
*/
|
|
||||||
private static final String CONFIG_FILE = "plugins/PluginMetrics/config.yml";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interval of time to ping in minutes
|
|
||||||
*/
|
|
||||||
private final static int PING_INTERVAL = 10;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The url used to report a server's status
|
|
||||||
*/
|
|
||||||
private static final String REPORT_URL = "/report/%s";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The metrics revision number
|
|
||||||
*/
|
|
||||||
private final static int REVISION = 4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encode text as UTF-8
|
|
||||||
*
|
|
||||||
* @param text
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static String encode(String text) throws UnsupportedEncodingException {
|
private static String encode(String text) throws UnsupportedEncodingException {
|
||||||
return URLEncoder.encode(text, "UTF-8");
|
return URLEncoder.encode(text, "UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -35,17 +35,6 @@ import net.citizensnpcs.npc.entity.CitizensZombieNPC;
|
|||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
public class NPCBuilder {
|
public class NPCBuilder {
|
||||||
public CitizensNPC getByType(EntityType type, CitizensNPCManager npcManager, int id, String name) {
|
|
||||||
Class<? extends CitizensNPC> npcClass = types.get(type);
|
|
||||||
try {
|
|
||||||
return npcClass.getConstructor(CitizensNPCManager.class, int.class, String.class).newInstance(npcManager,
|
|
||||||
id, name);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Map<EntityType, Class<? extends CitizensNPC>> types = new HashMap<EntityType, Class<? extends CitizensNPC>>();
|
private static final Map<EntityType, Class<? extends CitizensNPC>> types = new HashMap<EntityType, Class<? extends CitizensNPC>>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -76,4 +65,15 @@ public class NPCBuilder {
|
|||||||
types.put(EntityType.WOLF, CitizensWolfNPC.class);
|
types.put(EntityType.WOLF, CitizensWolfNPC.class);
|
||||||
types.put(EntityType.ZOMBIE, CitizensZombieNPC.class);
|
types.put(EntityType.ZOMBIE, CitizensZombieNPC.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CitizensNPC getByType(EntityType type, CitizensNPCManager npcManager, int id, String name) {
|
||||||
|
Class<? extends CitizensNPC> npcClass = types.get(type);
|
||||||
|
try {
|
||||||
|
return npcClass.getConstructor(CitizensNPCManager.class, int.class, String.class).newInstance(npcManager,
|
||||||
|
id, name);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user