GridLines addon
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.alttd.gridlines;
|
||||
|
||||
import com.alttd.gridlines.configuration.Config;
|
||||
import com.alttd.gridlines.listener.WorldListener;
|
||||
import net.pl3x.map.Pl3xMap;
|
||||
import net.pl3x.map.addon.Addon;
|
||||
|
||||
public class GridLines extends Addon {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Config.reload();
|
||||
Pl3xMap.api().getEventRegistry().register(new WorldListener(this));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.alttd.gridlines.configuration;
|
||||
|
||||
import net.pl3x.map.addon.AddonRegistry;
|
||||
import net.pl3x.map.configuration.AbstractConfig;
|
||||
|
||||
public class Config extends AbstractConfig {
|
||||
|
||||
@Key("settings.layer.label")
|
||||
@Comment("Label for map layer")
|
||||
public static String LAYER_LABEL = "Gridlines";
|
||||
@Key("settings.layer.show-controls")
|
||||
@Comment("Show controls for map layer")
|
||||
public static boolean LAYER_SHOW_CONTROLS = true;
|
||||
@Key("settings.layer.default-hidden")
|
||||
@Comment("Whether map layer is hidden by default")
|
||||
public static boolean LAYER_DEFAULT_HIDDEN = true;
|
||||
@Key("settings.layer.priority")
|
||||
@Comment("Priority for map layer")
|
||||
public static int LAYER_PRIORITY = 99;
|
||||
@Key("settings.layer.z-index")
|
||||
@Comment("zIndex for map layer")
|
||||
public static int LAYER_ZINDEX = 99;
|
||||
|
||||
private static final Config CONFIG = new Config();
|
||||
|
||||
public static void reload() {
|
||||
CONFIG.reload(AddonRegistry.ADDONS_CONFIG_DIR.resolve("GridLines.yml"), Config.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.alttd.gridlines.layer;
|
||||
|
||||
import com.alttd.gridlines.GridLines;
|
||||
import com.alttd.gridlines.configuration.Config;
|
||||
import net.pl3x.map.Key;
|
||||
import net.pl3x.map.markers.Point;
|
||||
import net.pl3x.map.markers.layer.SimpleLayer;
|
||||
import net.pl3x.map.markers.marker.Marker;
|
||||
import net.pl3x.map.markers.marker.Polyline;
|
||||
import net.pl3x.map.markers.option.Fill;
|
||||
import net.pl3x.map.markers.option.Options;
|
||||
import net.pl3x.map.markers.option.Stroke;
|
||||
import net.pl3x.map.world.World;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.WorldBorder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class GridLinesLayer extends SimpleLayer {
|
||||
|
||||
public static final Key KEY = Key.of("gridlines");
|
||||
private final Collection<Marker<?>> MARKERS = new HashSet<>();
|
||||
private final GridLines addon;
|
||||
private final World mapWorld;
|
||||
|
||||
public GridLinesLayer(GridLines addon, @NotNull World world) {
|
||||
super(KEY, () -> Config.LAYER_LABEL);
|
||||
this.addon = addon;
|
||||
this.mapWorld = world;
|
||||
setShowControls(Config.LAYER_SHOW_CONTROLS);
|
||||
setDefaultHidden(Config.LAYER_DEFAULT_HIDDEN);
|
||||
setPriority(Config.LAYER_PRIORITY);
|
||||
setZIndex(Config.LAYER_ZINDEX);
|
||||
updateLayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<Marker<?>> getMarkers() {
|
||||
return MARKERS;
|
||||
}
|
||||
|
||||
public void updateLayer() {
|
||||
MARKERS.clear();
|
||||
org.bukkit.World world = Bukkit.getWorld(mapWorld.getName());
|
||||
if (world == null) return;
|
||||
WorldBorder worldBorder = world.getWorldBorder();
|
||||
double radius = worldBorder.getSize() / 2;
|
||||
double radius2 = radius * -1;
|
||||
|
||||
int t;
|
||||
String key = "gridline";
|
||||
for(int i = -64; i < radius; i += 128) {
|
||||
t = i * -1;
|
||||
MARKERS.add(Marker.multiPolyline(Key.of(key + "-" + i),
|
||||
Polyline.of(Key.of(key + i + "-1"),
|
||||
Point.of(radius, i),
|
||||
Point.of(radius2, i)
|
||||
),
|
||||
Polyline.of(Key.of(key + i + "-2"),
|
||||
Point.of(i, radius),
|
||||
Point.of(i, radius2)
|
||||
),
|
||||
Polyline.of(Key.of(key + i + "-3"),
|
||||
Point.of(radius, t),
|
||||
Point.of(radius2, t)
|
||||
),
|
||||
Polyline.of(Key.of(key + i + "-4"),
|
||||
Point.of(t, radius),
|
||||
Point.of(t, radius2)
|
||||
)
|
||||
));
|
||||
}
|
||||
Options options = new Options()
|
||||
.setStroke(new Stroke().setColor(0xFFFF0000).setWeight(1))
|
||||
.setFill(new Fill().setEnabled(false));
|
||||
for (Marker<?> marker : MARKERS) {
|
||||
marker.setOptions(options);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.alttd.gridlines.listener;
|
||||
|
||||
import com.alttd.gridlines.GridLines;
|
||||
import com.alttd.gridlines.layer.GridLinesLayer;
|
||||
import net.pl3x.map.Pl3xMap;
|
||||
import net.pl3x.map.event.EventHandler;
|
||||
import net.pl3x.map.event.EventListener;
|
||||
import net.pl3x.map.event.server.ServerLoadedEvent;
|
||||
import net.pl3x.map.event.world.WorldLoadedEvent;
|
||||
import net.pl3x.map.event.world.WorldUnloadedEvent;
|
||||
|
||||
public class WorldListener implements EventListener {
|
||||
private final GridLines addon;
|
||||
|
||||
public WorldListener(GridLines addon) {
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerLoaded(ServerLoadedEvent event) {
|
||||
Pl3xMap.api().getWorldRegistry().entries().forEach((key, world) ->
|
||||
world.getLayerRegistry().register(new GridLinesLayer(addon, world))
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldLoaded(WorldLoadedEvent event) {
|
||||
event.getWorld().getLayerRegistry().register(new GridLinesLayer(addon, event.getWorld()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldUnloaded(WorldUnloadedEvent event) {
|
||||
event.getWorld().getLayerRegistry().unregister(GridLinesLayer.KEY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
name: "GridLines"
|
||||
main: "com.alttd.gridlines.GridLines"
|
||||
version: "1.0-SNAPSHOT"
|
||||
author: "destro174"
|
||||
Reference in New Issue
Block a user