plugin: Add some preliminary pl3xmap support

This commit is contained in:
Torrie Fischer 2021-07-08 00:34:12 -07:00
parent b5a28e40cf
commit ff70dd255b
4 changed files with 144 additions and 2 deletions

View File

@ -4,13 +4,19 @@
<groupId>us.camin.regions</groupId>
<artifactId>Regions</artifactId>
<packaging>jar</packaging>
<version>0.3.0</version>
<version>0.3.1-SNAPSHOT</version>
<name>regions</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>net.pl3x.map</groupId>
<artifactId>pl3xmap-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
@ -171,6 +177,7 @@
<id>papermc</id>
<url>http://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository><id>pl3x-repo</id><url>http://repo.pl3x.net/</url></repository>
<repository><id>dynmap-repo</id><url>http://repo.mikeprimm.com/</url></repository>
<repository><id>imagej</id><url>http://maven.imagej.net/content/repositories/public/</url></repository>
</repositories>

View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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<MapWorld> opt = m_map.getWorldIfEnabled(world);
opt.ifPresent((MapWorld mapWorld) -> {
Registry<LayerProvider> 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<Marker> getMarkers() {
ArrayList<Marker> markers = new ArrayList<Marker>();
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 = "<h3>" + region.name() + "</h3>";
clickTooltip += "<ul>";
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 += "<li>" + neighbor.name() + " - Cost: ";
clickTooltip += region.getTravelCost(neighbor);
clickTooltip += " levels</li>";
}
clickTooltip += "</ul>";
marker = Marker.circle(point, size);
marker.markerOptions(MarkerOptions.builder()
.hoverTooltip(region.name())
.clickTooltip(clickTooltip)
.strokeColor(awtColor)
.strokeOpacity(0.8));
markers.add(marker);
}
return markers;
}
}
}

View File

@ -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);

View File

@ -4,7 +4,7 @@ author: Torrie Fischer <tdfischer@hackerbots.net>
website: http://hackerbots.net/
version: ${version}
api-version: 1.16
softdepend: [dynmap, ProtocolLib]
softdepend: [dynmap, ProtocolLib, Pl3xMap]
commands:
regions:
description: "List available regions."