diff --git a/pom.xml b/pom.xml index 4925c97..442735a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,13 +4,19 @@ us.camin.regions Regions jar - 0.3.0 + 0.3.1-SNAPSHOT regions http://maven.apache.org UTF-8 + + net.pl3x.map + pl3xmap-api + 1.0.0-SNAPSHOT + provided + org.bstats bstats-bukkit @@ -171,6 +177,7 @@ papermc http://papermc.io/repo/repository/maven-public/ + pl3x-repohttp://repo.pl3x.net/ dynmap-repohttp://repo.mikeprimm.com/ imagejhttp://maven.imagej.net/content/repositories/public/ diff --git a/src/main/java/us/camin/regions/Pl3xMapRelay.java b/src/main/java/us/camin/regions/Pl3xMapRelay.java new file mode 100644 index 0000000..83ce267 --- /dev/null +++ b/src/main/java/us/camin/regions/Pl3xMapRelay.java @@ -0,0 +1,126 @@ +package us.camin.regions; + +/** + * This file is part of Regions + * + * Regions is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Regions is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Regions. If not, see . + * + */ + +import org.bukkit.event.Listener; +import net.pl3x.map.api.Pl3xMap; +import net.pl3x.map.api.Pl3xMapProvider; +import net.pl3x.map.api.LayerProvider; +import net.pl3x.map.api.MapWorld; +import net.pl3x.map.api.Registry; +import net.pl3x.map.api.Key; +import net.pl3x.map.api.Point; +import net.pl3x.map.api.marker.Marker; +import net.pl3x.map.api.marker.MarkerOptions; +import net.pl3x.map.api.marker.Icon; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Optional; + +import org.bukkit.World; +import org.bukkit.Color; + +import us.camin.regions.geometry.RegionSet; +import us.camin.regions.geometry.BorderMesh; + +public class Pl3xMapRelay implements Listener { + private Plugin m_plugin; + private Pl3xMap m_map; + + public Pl3xMapRelay(Plugin p) { + m_plugin = p; + m_map = null; + try { + m_map = Pl3xMapProvider.get(); + } catch (Exception e) { + } + + if (isEnabled()) { + for(World world : m_plugin.getServer().getWorlds()) { + Optional opt = m_map.getWorldIfEnabled(world); + opt.ifPresent((MapWorld mapWorld) -> { + Registry layers = mapWorld.layerRegistry(); + layers.register(Key.of("regions_" + mapWorld.uuid()), new RegionMarkerProvider(this, world)); + }); + } + } + } + + public boolean isEnabled() { + return m_map != null; + } + + private class RegionMarkerProvider implements LayerProvider { + private Pl3xMapRelay m_relay; + private World m_world; + + public RegionMarkerProvider(Pl3xMapRelay relay, World world) { + m_relay = relay; + m_world = world; + } + + public String getLabel() { + return "Regions"; + } + + public int layerPriority() { + return 0; + } + + public Collection getMarkers() { + ArrayList markers = new ArrayList(); + RegionSet regions = m_relay.m_plugin.regionManager().regionsForWorld(m_world); + BorderMesh geom = regions.borders(); + for(Region region : regions) { + Color lineColor = region.color().getColor(); + java.awt.Color awtColor = new java.awt.Color(lineColor.getRed(), lineColor.getGreen(), lineColor.getBlue()); + Point point = Point.of(region.location().getX(), region.location().getZ()); + int size = 32; + String clickTooltip = "

" + region.name() + "

"; + clickTooltip += "
    "; + Key imageKey = Key.of("sign_oak"); + Marker marker = Marker.icon(point, imageKey, size); + + for(Region neighbor : geom.neighbors(region)) { + marker = Marker.polyline(Point.of(region.location().getX(), region.location().getZ()), Point.of(neighbor.location().getX(), neighbor.location().getZ())); + marker.markerOptions(MarkerOptions.builder() + .hoverTooltip(region.name() + " / " + neighbor.name()) + .strokeColor(awtColor) + .strokeOpacity(0.8)); + markers.add(marker); + clickTooltip += "
  • " + neighbor.name() + " - Cost: "; + clickTooltip += region.getTravelCost(neighbor); + clickTooltip += " levels
  • "; + } + clickTooltip += "
"; + + marker = Marker.circle(point, size); + marker.markerOptions(MarkerOptions.builder() + .hoverTooltip(region.name()) + .clickTooltip(clickTooltip) + .strokeColor(awtColor) + .strokeOpacity(0.8)); + markers.add(marker); + } + + return markers; + } + } +} diff --git a/src/main/java/us/camin/regions/Plugin.java b/src/main/java/us/camin/regions/Plugin.java index 48100e2..95ad99c 100644 --- a/src/main/java/us/camin/regions/Plugin.java +++ b/src/main/java/us/camin/regions/Plugin.java @@ -78,6 +78,7 @@ public class Plugin extends JavaPlugin { if (markerAPI != null) { DynmapEventRelay regionHandler = new DynmapEventRelay (this, markerAPI); getServer().getPluginManager().registerEvents(regionHandler, this); + log.info("Dynmap support enabled."); } else { log.info("Dynmap marker API not found. Disabling map support."); } @@ -85,6 +86,14 @@ public class Plugin extends JavaPlugin { log.info("Dynmap not found. Disabling map support."); } + Pl3xMapRelay plexMapper = new Pl3xMapRelay(this); + if (plexMapper.isEnabled()) { + getServer().getPluginManager().registerEvents(plexMapper, this); + log.info("Pl3xmap support enabled."); + } else { + log.info("Pl3xmap not found. Disabling map support."); + } + // Install the event handler after things are loaded so players aren't spammed with text getServer().getPluginManager().registerEvents(m_playerWatcher, this); getServer().getPluginManager().registerEvents(new PlayerNotifier(this, m_regions), this); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7866768..58a7879 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ author: Torrie Fischer website: http://hackerbots.net/ version: ${version} api-version: 1.16 -softdepend: [dynmap, ProtocolLib] +softdepend: [dynmap, ProtocolLib, Pl3xMap] commands: regions: description: "List available regions."