Implements Sentinel support

This commit is contained in:
Kristian Knarvik 2022-10-19 13:20:57 +02:00
parent 909863a2f7
commit 22b621801b
3 changed files with 50 additions and 2 deletions

13
pom.xml
View File

@ -120,5 +120,18 @@
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.mcmonkey</groupId>
<artifactId>sentinel</artifactId>
<version>2.7.0-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -57,7 +57,7 @@ public final class DynmapCitizens extends JavaPlugin {
handler.updateMarkers(); handler.updateMarkers();
} }
} }
}, 5 * 20, 120 * 20); }, 5 * 20, 5 * 20);
} }
@Override @Override

View File

@ -1,18 +1,53 @@
package net.knarcraft.dynmapcitizens.trait; package net.knarcraft.dynmapcitizens.trait;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait;
import net.knarcraft.dynmapcitizens.DynmapCitizens;
import net.knarcraft.dynmapcitizens.Icon;
import org.bukkit.Bukkit;
import org.dynmap.DynmapAPI;
import org.dynmap.markers.GenericMarker;
import org.dynmap.markers.MarkerSet;
import org.mcmonkey.sentinel.SentinelPlugin;
import org.mcmonkey.sentinel.SentinelTrait;
/** /**
* A handler class for the sentinel trait * A handler class for the sentinel trait
*/ */
public class SentinelHandler extends AbstractTraitHandler { public class SentinelHandler extends AbstractTraitHandler {
private MarkerSet sentinelSet;
@Override @Override
public void initialize() { public void initialize() {
SentinelPlugin sentinelPlugin = (SentinelPlugin) Bukkit.getServer().getPluginManager().getPlugin("Sentinel");
DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI();
if (sentinelPlugin != null) {
sentinelSet = getMarkerSet(dynmapAPI, "sentinels", "Sentinels");
if (sentinelSet != null) {
sentinelSet.setHideByDefault(false);
isEnabled = true;
return;
}
}
isEnabled = false;
} }
@Override @Override
public void updateMarkers() { public void updateMarkers() {
sentinelSet.getMarkers().forEach(GenericMarker::deleteMarker);
Class<? extends Trait> sentinelTrait = CitizensAPI.getTraitFactory().getTraitClass("sentinel");
for (NPC npc : CitizensAPI.getNPCRegistry()) {
if (npc.hasTrait(sentinelTrait)) {
SentinelTrait trait = CitizensAPI.getTraitFactory().getTrait("sentinel");
String description = "<b>Name:</b> " + npc.getName() + "<br><b>Armor:</b> " +
trait.armor + "<br><b>Health:</b> " + trait.health;
addNPCMarker(npc.getUniqueId(), "Sentinel NPC: ", description,
DynmapCitizens.getInstance().getMarkerIcons().get(Icon.SENTINEL), sentinelSet);
}
}
} }
} }