Dynmap API start and some other fixes...

This commit is contained in:
Laika 2022-04-24 00:19:28 -07:00
parent 81ac63c998
commit db97cd7944
6 changed files with 118 additions and 5 deletions

View file

@ -78,5 +78,13 @@
<version>5.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>webukkit</groupId>
<artifactId>dynmap</artifactId>
<version>3.4-beta-3-spigot</version>
<systemPath>${pom.basedir}/libs/Dynmap-3.4-beta-3-spigot.jar</systemPath>
<!-- We define a system path and "system" scope, so maven doesn't attempt to pull from a repo -->
<scope>system</scope>
</dependency>
</dependencies>
</project>

View file

@ -2,12 +2,13 @@ package moe.oko.opennaw;
import moe.oko.opennaw.command.CityCommand;
import moe.oko.opennaw.command.NationCommand;
import moe.oko.opennaw.util.ChatHandler;
import moe.oko.opennaw.util.CityHandler;
import moe.oko.opennaw.util.GroupHandler;
import moe.oko.opennaw.util.NationHandler;
import moe.oko.opennaw.util.*;
import net.luckperms.api.LuckPerms;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.dynmap.DynmapCommonAPI;
import org.dynmap.DynmapCommonAPIListener;
import org.dynmap.bukkit.DynmapPlugin;
import static moe.oko.opennaw.util.CommandHelper.info;
@ -19,6 +20,10 @@ public final class OpenNAW extends JavaPlugin {
public GroupHandler groupHandler;
private LuckPerms luckPerms;
private DynmapHandler dynmapHandler;
private boolean dynmapEnabled;
public static OpenNAW getInstance() {
return instance;
}
@ -44,6 +49,12 @@ public final class OpenNAW extends JavaPlugin {
this.getCommand("nation").setExecutor(new NationCommand());
this.getCommand("city").setExecutor(new CityCommand());
getServer().getPluginManager().registerEvents(new ChatHandler(), this);
if(Bukkit.getPluginManager().isPluginEnabled("dynmap")) {
this.dynmapEnabled = true;
//Only initialize if dyn is loaded.
dynmapHandler = new DynmapHandler();
}
}
@Override
@ -51,4 +62,11 @@ public final class OpenNAW extends JavaPlugin {
info("OpenNAW is disabled!");
}
public boolean isDynmapEnabled() {
return dynmapEnabled;
}
public DynmapHandler getDynmapHandler() {
return dynmapHandler;
}
}

View file

@ -1,5 +1,11 @@
package moe.oko.opennaw.model;
import moe.oko.opennaw.OpenNAW;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
public class City {
@ -13,7 +19,8 @@ public class City {
public City(String name, String resource, Location location) {
this.name = name;
this.resource = resource;
this.owner = null;
//Default is unclaimed.
this.owner = Nation.UNCLAIMED;
this.state = CityState.NORMAL;
this.point = location;
this.health = 300;
@ -33,6 +40,7 @@ public class City {
public void setOwner(Nation nation) {
this.owner = nation;
capture();
}
public Location getPoint() {
@ -46,4 +54,17 @@ public class City {
public void damage(short damage) {
this.health -= damage;
}
public void capture() {
//This is our "capture" logic. So now we do shenanigans.
if(OpenNAW.getInstance().isDynmapEnabled()) {
//Dyn is enabled, we need to do setters.
OpenNAW.getInstance().getDynmapHandler().updateCityInfoMarker(this);
}
Bukkit.broadcast(Component.text(ChatColor.AQUA + getName() + ChatColor.GOLD + " has been successfully captured by " + ChatColor.RED + this.owner.getName()));
}
public boolean isUnclaimed() {
return owner == Nation.UNCLAIMED;
}
}

View file

@ -4,14 +4,19 @@ import net.luckperms.api.model.group.Group;
import org.bukkit.Location;
public class Nation {
public static final Nation UNCLAIMED = new Nation("UNCLAIMED", null);
private String name;
private Group group;
private Location spawn;
//The icon used for cities owned by this nation (default is a tower)
private String dynmapIcon;
public Nation(String name, Group group) {
this.name = name;
this.group = group;
this.dynmapIcon = "tower";
this.spawn = null;
}
@ -21,4 +26,12 @@ public class Nation {
public void setSpawn(Location l) {
this.spawn = l;
}
public String getDynmapIcon() {
return dynmapIcon;
}
public void setDynmapIcon(String dynmapIcon) {
this.dynmapIcon = dynmapIcon;
}
}

View file

@ -0,0 +1,52 @@
package moe.oko.opennaw.util;
import moe.oko.opennaw.model.City;
import org.bukkit.Location;
import org.dynmap.bukkit.DynmapPlugin;
import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerAPI;
import org.dynmap.markers.MarkerSet;
public class DynmapHandler {
public static final String SET_ID = "nawCity";
private MarkerAPI markerAPI;
private MarkerSet citySet;
public DynmapHandler() {
markerAPI = DynmapPlugin.plugin.getMarkerAPI();
if(markerAPI.getMarkerSet(SET_ID) != null) {
citySet = markerAPI.getMarkerSet(SET_ID);
} else {
//Creating a new Dynmap set with the ID predefined (finally) in the class, alongside the label "Cities",
//that has no limit on icon usage (any), and is persistent. (Dynmap has nearly no docs pertaining to api usage).
citySet = markerAPI.createMarkerSet(SET_ID, "Cities", markerAPI.getMarkerIcons(), true);
}
}
public boolean initializeCityMarker(City city) {
//Generate a new marker pertaining to shenanigans
try {
Location cityLoc = city.getPoint();
citySet.createMarker(city.getName(), city.getName() + " [**" + city.getOwner().getName() + "**]",
true, cityLoc.getWorld().getName(), cityLoc.getX(), cityLoc.getY(), cityLoc.getZ(), markerAPI.getMarkerIcon(city.getOwner().getDynmapIcon()), true);
return true;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
//Updates the name and icon of the marker.
public boolean updateCityInfoMarker(City city) {
try {
Marker marker = citySet.findMarker(city.getName());
marker.setLabel(city.getName() + " [**" + city.getOwner().getName() + "**]");
marker.setMarkerIcon(markerAPI.getMarkerIcon(city.getOwner().getDynmapIcon()));
return true;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
}

View file

@ -3,6 +3,7 @@ version: '${project.version}'
main: moe.oko.opennaw.OpenNAW
api-version: 1.18
prefix: OpenNAW
softdepend: [dynmap]
authors: [ oko ]
description: Open source recreation of Nations at War
website: https://oko.moe