This repository has been archived by the owner on Jan 16, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete a pointless class, clean up TickTask a little... Change the tr…
…ader busy message.
- Loading branch information
fullwall
committed
May 24, 2012
1 parent
b8c5873
commit ad2473e
Showing
6 changed files
with
142 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
package net.citizensnpcs; | ||
|
||
import java.util.Map; | ||
|
||
import net.citizensnpcs.api.event.NPCCreateEvent.NPCCreateReason; | ||
import net.citizensnpcs.misc.Actions; | ||
import net.citizensnpcs.resources.npclib.HumanNPC; | ||
import net.citizensnpcs.resources.npclib.NPCManager; | ||
import net.citizensnpcs.resources.npclib.NPCSpawner; | ||
import net.citizensnpcs.utils.LocationUtils; | ||
import net.citizensnpcs.utils.MessageUtils; | ||
import net.citizensnpcs.utils.Messaging; | ||
|
@@ -15,32 +11,38 @@ | |
import net.citizensnpcs.waypoints.WaypointPath; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Player; | ||
|
||
import com.google.common.collect.MapMaker; | ||
import com.google.common.collect.HashMultimap; | ||
import com.google.common.collect.SetMultimap; | ||
|
||
public class TickTask implements Runnable { | ||
private static final Map<HumanNPC, Actions> cachedActions = new MapMaker().weakKeys().makeMap(); | ||
private static final SetMultimap<HumanNPC, String> cachedActions = HashMultimap.create(); | ||
|
||
@Override | ||
public void run() { | ||
Player[] online = Bukkit.getServer().getOnlinePlayers(); | ||
for (HumanNPC npc : NPCManager.getList().values()) { | ||
updateWaypoints(npc); | ||
npc.doTick(); | ||
NPCSpawner.removeNPCFromPlayerList(npc); | ||
if (!npc.getNPCData().isLookClose() && !npc.getNPCData().isTalkClose()) | ||
continue; | ||
boolean canLookClose = npc.getHandle().pathFinished() && !npc.getHandle().hasTarget() | ||
&& npc.getNPCData().isLookClose(); | ||
if (!npc.getNPCData().isTalkClose() && !canLookClose) | ||
continue; | ||
Location npcLoc = npc.getLocation(); | ||
for (Player player : online) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
fullwall
Member
|
||
if (!npc.getNPCData().isLookClose() && !npc.getNPCData().isTalkClose()) | ||
continue; | ||
// If the player is within 'seeing' range | ||
if (LocationUtils.withinRange(npc.getLocation(), player.getLocation(), Settings.getDouble("NPCRange"))) { | ||
if (npc.getHandle().pathFinished() && !npc.getHandle().hasTarget() | ||
&& npc.getNPCData().isLookClose()) { | ||
if (LocationUtils.withinRange(npcLoc, player.getLocation(), Settings.getDouble("NPCRange"))) { | ||
if (canLookClose) { | ||
NPCManager.faceEntity(npc, player); | ||
} | ||
cacheActions(npc, player); | ||
if (npc.getNPCData().isTalkClose()) | ||
cacheActions(npc, player); | ||
} else { | ||
clearActions(npc, player); | ||
cachedActions.remove(npc, player.getName()); | ||
} | ||
} | ||
} | ||
|
@@ -87,24 +89,10 @@ private void updateWaypoints(HumanNPC npc) { | |
} | ||
} | ||
|
||
private static void clearActions(HumanNPC npc, Player player) { | ||
Actions actions = cachedActions.get(npc); | ||
if (actions == null) { | ||
cachedActions.put(npc, new Actions()); | ||
return; | ||
} | ||
actions.clear("saidText", player.getName()); | ||
} | ||
|
||
private static void cacheActions(HumanNPC npc, Player player) { | ||
Actions actions = cachedActions.get(npc); | ||
if (actions == null) { | ||
cachedActions.put(npc, new Actions()); | ||
return; | ||
} | ||
if (!actions.has("saidText", player.getName()) && npc.getNPCData().isTalkClose()) { | ||
if (!cachedActions.containsEntry(npc, player.getName().toLowerCase()) && npc.getNPCData().isTalkClose()) { | ||
MessageUtils.sendText(npc, player); | ||
actions.set("saidText", player.getName()); | ||
cachedActions.put(npc, player.getName().toLowerCase()); | ||
} | ||
} | ||
|
||
|
@@ -122,7 +110,7 @@ public RespawnTask(HumanNPC npc) { | |
} | ||
|
||
public void register(int delay) { | ||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Citizens.plugin, this, delay); | ||
Bukkit.getScheduler().scheduleSyncDelayedTask(Citizens.plugin, this, delay); | ||
} | ||
|
||
@Override | ||
|
@@ -134,7 +122,7 @@ public void run() { | |
|
||
public static void clearActions(Player player) { | ||
for (HumanNPC npc : cachedActions.keySet()) { | ||
clearActions(npc, player); | ||
cachedActions.remove(npc, player.getName().toLowerCase()); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Replace online with
for more efficiency