Changes the way quest updates are made
Removes the per-trait update-rate Adds a task timer to update the marker for any NPC moving around Sets the marker update delay to 5 minutes Skips all quest marker updates, unless a quest has changed
This commit is contained in:
parent
4555331988
commit
935a6ce662
@ -19,7 +19,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ -54,24 +53,17 @@ public final class DynmapCitizens extends JavaPlugin {
|
||||
handlers.add(new MinstrelHandler());
|
||||
for (CitizensTraitHandler handler : handlers) {
|
||||
handler.initialize();
|
||||
handler.updateMarkers();
|
||||
}
|
||||
|
||||
//Schedule handlers to run periodically
|
||||
AtomicInteger elapsedSeconds = new AtomicInteger();
|
||||
elapsedSeconds.set(240);
|
||||
Bukkit.getScheduler().runTaskTimer(this, () -> {
|
||||
for (CitizensTraitHandler handler : handlers) {
|
||||
if (handler.isEnabled() && elapsedSeconds.get() % handler.getUpdateRate().getEveryNSeconds() == 0) {
|
||||
if (handler.isEnabled()) {
|
||||
handler.updateMarkers();
|
||||
}
|
||||
}
|
||||
elapsedSeconds.addAndGet(5);
|
||||
if (elapsedSeconds.get() > 3600) {
|
||||
elapsedSeconds.set(240);
|
||||
}
|
||||
//TODO: It would probably make more sense to have individual timers for each marker based on whether the
|
||||
// NPC is likely to move about.
|
||||
}, 5 * 20, 5 * 20);
|
||||
}, 10 * 20, 300 * 20);
|
||||
|
||||
vaultHandler = new VaultHandler(this.getServer().getServicesManager());
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package net.knarcraft.dynmapcitizens.handler.trait;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.knarcraft.dynmapcitizens.DynmapCitizens;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.dynmap.DynmapAPI;
|
||||
@ -70,11 +71,20 @@ public abstract class AbstractTraitHandler implements CitizensTraitHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
Marker marker = markerSet.createMarker(null, markerName + npc.getName(), npcLocation.getWorld().getName(),
|
||||
npcLocation.getX(), npcLocation.getY(), npcLocation.getZ(), icon, false);
|
||||
Marker marker = markerSet.createMarker(npcId.toString(), markerName + npc.getName(),
|
||||
npcLocation.getWorld().getName(), npcLocation.getX(), npcLocation.getY(), npcLocation.getZ(), icon,
|
||||
false);
|
||||
if (marker != null) {
|
||||
marker.setDescription(markerDescription);
|
||||
}
|
||||
|
||||
//For NPCs that move around, update their marker's location every n seconds
|
||||
if (marker != null && isMoving(npc)) {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(DynmapCitizens.getInstance(),
|
||||
() -> marker.setLocation(npcLocation.getWorld().getName(), npc.getStoredLocation().getX(),
|
||||
npc.getStoredLocation().getY(), npc.getStoredLocation().getZ()), 20, 10 * 20);
|
||||
//TODO: Make the update rate configurable
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,7 +8,6 @@ import net.knarcraft.blacksmith.config.NPCSettings;
|
||||
import net.knarcraft.blacksmith.trait.BlacksmithTrait;
|
||||
import net.knarcraft.dynmapcitizens.DynmapCitizens;
|
||||
import net.knarcraft.dynmapcitizens.property.Icon;
|
||||
import net.knarcraft.dynmapcitizens.property.UpdateRate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.dynmap.DynmapAPI;
|
||||
@ -42,11 +41,6 @@ public class BlacksmithHandler extends AbstractTraitHandler {
|
||||
isEnabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateRate getUpdateRate() {
|
||||
return UpdateRate.VERY_SLOW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMarkers() {
|
||||
//Remove existing markers
|
||||
|
@ -1,7 +1,5 @@
|
||||
package net.knarcraft.dynmapcitizens.handler.trait;
|
||||
|
||||
import net.knarcraft.dynmapcitizens.property.UpdateRate;
|
||||
|
||||
/**
|
||||
* A handler which takes care of everything for one citizen trait
|
||||
*/
|
||||
@ -12,13 +10,6 @@ public interface CitizensTraitHandler {
|
||||
*/
|
||||
void initialize();
|
||||
|
||||
/**
|
||||
* Gets the update rate used for this handler
|
||||
*
|
||||
* @return <p>The update rate for this handler</p>
|
||||
*/
|
||||
UpdateRate getUpdateRate();
|
||||
|
||||
/**
|
||||
* Gets whether this handler was properly initialized and enabled
|
||||
*
|
||||
|
@ -5,7 +5,6 @@ import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.knarcraft.dynmapcitizens.DynmapCitizens;
|
||||
import net.knarcraft.dynmapcitizens.property.Icon;
|
||||
import net.knarcraft.dynmapcitizens.property.UpdateRate;
|
||||
import net.knarcraft.minstrel.MinstrelPlugin;
|
||||
import net.knarcraft.minstrel.music.Song;
|
||||
import net.knarcraft.minstrel.trait.MinstrelTrait;
|
||||
@ -39,11 +38,6 @@ public class MinstrelHandler extends AbstractTraitHandler {
|
||||
isEnabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateRate getUpdateRate() {
|
||||
return UpdateRate.VERY_SLOW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMarkers() {
|
||||
//Remove existing markers
|
||||
|
@ -5,7 +5,6 @@ import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.knarcraft.dynmapcitizens.DynmapCitizens;
|
||||
import net.knarcraft.dynmapcitizens.property.Icon;
|
||||
import net.knarcraft.dynmapcitizens.property.UpdateRate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.dynmap.DynmapAPI;
|
||||
import org.dynmap.markers.GenericMarker;
|
||||
@ -36,11 +35,6 @@ public class SentinelHandler extends AbstractTraitHandler {
|
||||
isEnabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateRate getUpdateRate() {
|
||||
return UpdateRate.FAST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMarkers() {
|
||||
sentinelSet.getMarkers().forEach(GenericMarker::deleteMarker);
|
||||
|
@ -8,7 +8,6 @@ import net.citizensnpcs.api.npc.NPCRegistry;
|
||||
import net.knarcraft.dynmapcitizens.DynmapCitizens;
|
||||
import net.knarcraft.dynmapcitizens.handler.trait.AbstractTraitHandler;
|
||||
import net.knarcraft.dynmapcitizens.property.Icon;
|
||||
import net.knarcraft.dynmapcitizens.property.UpdateRate;
|
||||
import net.knarcraft.dynmapcitizens.util.QuestsHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -59,11 +58,6 @@ public class QuestsHandler extends AbstractTraitHandler {
|
||||
isEnabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateRate getUpdateRate() {
|
||||
return UpdateRate.VERY_SLOW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMarkers() {
|
||||
if (questsAPI.isLoading()) {
|
||||
@ -79,14 +73,15 @@ public class QuestsHandler extends AbstractTraitHandler {
|
||||
|
||||
//Updates all quest area markers
|
||||
if (questsChanged) {
|
||||
//Update all area markers for quests
|
||||
updateQuestAreas();
|
||||
|
||||
//Generate information about all NPCs involved in quests
|
||||
generateQuestNPCInfo();
|
||||
|
||||
//Generate markers based on the generated info
|
||||
generateAllMarkers();
|
||||
}
|
||||
|
||||
//Generate information about all NPCs involved in quests
|
||||
generateQuestNPCInfo();
|
||||
|
||||
//Generate markers based on the generated info
|
||||
generateAllMarkers();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,38 +0,0 @@
|
||||
package net.knarcraft.dynmapcitizens.property;
|
||||
|
||||
/**
|
||||
* An update rate for a group of icons
|
||||
*/
|
||||
public enum UpdateRate {
|
||||
|
||||
/**
|
||||
* This is run quite often, to display movement
|
||||
*/
|
||||
FAST(5),
|
||||
|
||||
/**
|
||||
* This is run rarely, as change isn't expected
|
||||
*/
|
||||
VERY_SLOW(120);
|
||||
|
||||
private final int everyNSeconds;
|
||||
|
||||
/**
|
||||
* Instantiates a new update rate
|
||||
*
|
||||
* @param everyNSeconds <p>The number of seconds to wait between each run</p>
|
||||
*/
|
||||
UpdateRate(int everyNSeconds) {
|
||||
this.everyNSeconds = everyNSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of seconds between each time an update should be performed
|
||||
*
|
||||
* @return <p>The N in every N seconds</p>
|
||||
*/
|
||||
public int getEveryNSeconds() {
|
||||
return everyNSeconds;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user