Skip to content

Commit

Permalink
Fix guardian update method
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed May 26, 2015
1 parent 220c8d9 commit 8a0134d
Show file tree
Hide file tree
Showing 64 changed files with 409 additions and 375 deletions.
24 changes: 12 additions & 12 deletions src/main/java/net/citizensnpcs/Citizens.java
Expand Up @@ -6,6 +6,16 @@
import java.util.Locale;
import java.util.Map;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;

import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.CitizensPlugin;
Expand Down Expand Up @@ -51,16 +61,6 @@
import net.citizensnpcs.util.Util;
import net.milkbowl.vault.economy.Economy;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;

public class Citizens extends JavaPlugin implements CitizensPlugin {
private final CommandManager commands = new CommandManager();
private boolean compatible;
Expand Down Expand Up @@ -134,8 +134,8 @@ private void enableSubPlugins() {
Messaging.logTr(Messages.LOADING_SUB_PLUGIN, plugin.getDescription().getFullName());
plugin.onLoad();
} catch (Throwable ex) {
Messaging.severeTr(Messages.ERROR_INITALISING_SUB_PLUGIN, ex.getMessage(), plugin.getDescription()
.getFullName());
Messaging.severeTr(Messages.ERROR_INITALISING_SUB_PLUGIN, ex.getMessage(),
plugin.getDescription().getFullName());
ex.printStackTrace();
}
}
Expand Down
52 changes: 26 additions & 26 deletions src/main/java/net/citizensnpcs/EventListen.java
Expand Up @@ -131,8 +131,8 @@ public void onChunkUnload(ChunkUnloadEvent event) {
}
toRespawn.put(coord, npc);
if (Messaging.isDebugging()) {
Messaging
.debug("Despawned id", npc.getId(), "due to chunk unload at [" + coord.x + "," + coord.z + "]");
Messaging.debug("Despawned id", npc.getId(),
"due to chunk unload at [" + coord.x + "," + coord.z + "]");
}
}
}
Expand Down Expand Up @@ -228,8 +228,8 @@ public void onEntityTarget(EntityTargetEvent event) {
NPC npc = npcRegistry.getNPC(event.getTarget());
if (npc == null)
return;
event.setCancelled(!npc.data().get(NPC.TARGETABLE_METADATA,
!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)));
event.setCancelled(
!npc.data().get(NPC.TARGETABLE_METADATA, !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)));
Bukkit.getPluginManager().callEvent(new EntityTargetNPCEvent(event, npc));
}

Expand Down Expand Up @@ -300,27 +300,27 @@ public void recalculatePlayer(final Player player) {
new BukkitRunnable() {
@Override
public void run() {
final List<EntityPlayer> nearbyNPCs = new ArrayList<EntityPlayer>();
for (NPC npc : getAllNPCs()) {
Entity npcEntity = npc.getEntity();
if (npcEntity instanceof Player && player.canSee((Player) npcEntity)
&& player.getWorld().equals(npcEntity.getWorld())
&& player.getLocation().distanceSquared(npcEntity.getLocation()) < 100 * 100) {
nearbyNPCs.add(((CraftPlayer) npcEntity).getHandle());
}
}
new BukkitRunnable() {
@Override
public void run() {
sendToPlayer(player, nearbyNPCs);
}
}.runTaskLater(CitizensAPI.getPlugin(), 30);
new BukkitRunnable() {
@Override
public void run() {
sendToPlayer(player, nearbyNPCs);
final List<EntityPlayer> nearbyNPCs = new ArrayList<EntityPlayer>();
for (NPC npc : getAllNPCs()) {
Entity npcEntity = npc.getEntity();
if (npcEntity instanceof Player && player.canSee((Player) npcEntity)
&& player.getWorld().equals(npcEntity.getWorld())
&& player.getLocation().distanceSquared(npcEntity.getLocation()) < 100 * 100) {
nearbyNPCs.add(((CraftPlayer) npcEntity).getHandle());
}
}
}.runTaskLater(CitizensAPI.getPlugin(), 70);
new BukkitRunnable() {
@Override
public void run() {
sendToPlayer(player, nearbyNPCs);
}
}.runTaskLater(CitizensAPI.getPlugin(), 30);
new BukkitRunnable() {
@Override
public void run() {
sendToPlayer(player, nearbyNPCs);
}
}.runTaskLater(CitizensAPI.getPlugin(), 70);
}
}.runTaskLater(CitizensAPI.getPlugin(), 10);

Expand Down Expand Up @@ -405,8 +405,8 @@ private void respawnAllFromCoord(ChunkCoord coord) {
boolean success = spawn(npc);
if (!success) {
if (Messaging.isDebugging()) {
Messaging.debug("Couldn't respawn id", npc.getId(), "during chunk event at [" + coord.x + ","
+ coord.z + "]");
Messaging.debug("Couldn't respawn id", npc.getId(),
"during chunk event at [" + coord.x + "," + coord.z + "]");
}
continue;
}
Expand Down
48 changes: 18 additions & 30 deletions src/main/java/net/citizensnpcs/Metrics.java
Expand Up @@ -129,8 +129,7 @@ public void addCustomData(Plotter plotter) {
}

/**
* 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
* The name of the graph
Expand All @@ -144,14 +143,12 @@ public void addGraph(final Graph 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
* added to the graph object returned.
* 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.
*
* @param name
* 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
*/
public Graph createGraph(final String name) {
if (name == null) {
Expand All @@ -169,8 +166,7 @@ public Graph createGraph(final String name) {
}

/**
* 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
*/
Expand All @@ -194,8 +190,7 @@ public void disable() throws IOException {
}

/**
* 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
*/
Expand All @@ -218,8 +213,7 @@ public void enable() throws IOException {
}

/**
* 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
*/
Expand All @@ -237,8 +231,7 @@ public File getConfigFile() {
}

/**
* 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
*/
Expand Down Expand Up @@ -443,10 +436,9 @@ private void postPlugin(final boolean isPing) throws IOException {
}

/**
* 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.
* 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.
*/
Expand Down Expand Up @@ -514,8 +506,8 @@ public void run() {
public static class Graph {

/**
* The graph's name, alphanumeric and spaces only :) If it does not
* comply to the above when submitted, it is rejected
* The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is
* rejected
*/
private final String name;

Expand Down Expand Up @@ -572,8 +564,7 @@ public int hashCode() {
}

/**
* Called when the server owner decides to opt-out of BukkitMetrics
* while the server is running.
* Called when the server owner decides to opt-out of BukkitMetrics while the server is running.
*/
protected void onOptOut() {
}
Expand Down Expand Up @@ -610,8 +601,7 @@ public Plotter() {
* Construct a plotter with a specific plot 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
*/
public Plotter(final String name) {
this.name = name;
Expand All @@ -637,11 +627,9 @@ public String getColumnName() {
}

/**
* 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.
* 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.
*/
Expand Down
Expand Up @@ -104,10 +104,8 @@ public static void startWithCallback(Callback callback, NPCRegistry npcRegistry,
}
for (NPC test : npcRegistry) {
if (test.getName().equalsIgnoreCase(name)) {
if (range > 0
&& test.isSpawned()
&& !Util.locationWithinRange(args.getSenderLocation(), test.getEntity().getLocation(),
range))
if (range > 0 && test.isSpawned() && !Util.locationWithinRange(args.getSenderLocation(),
test.getEntity().getLocation(), range))
continue;
possible.add(test);
}
Expand Down

0 comments on commit 8a0134d

Please sign in to comment.