Update GridLines

This commit is contained in:
Len 2023-07-02 22:03:17 +02:00
parent ce88aa999d
commit e670ccf1a1
7 changed files with 72 additions and 55 deletions

View File

@ -3,7 +3,7 @@ plugins {
} }
group = "com.alttd.gridlines" group = "com.alttd.gridlines"
version = "1.0-SNAPSHOT" version = "2.0-SNAPSHOT"
repositories { repositories {
maven { maven {
@ -15,6 +15,6 @@ repositories {
} }
dependencies { dependencies {
compileOnly("io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT") compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
compileOnly("maven.modrinth:pl3xmap:1.19.2-306") compileOnly("maven.modrinth:pl3xmap:1.20.1-464")
} }

View File

@ -1,15 +1,32 @@
package com.alttd.gridlines; package com.alttd.gridlines;
import com.alttd.gridlines.configuration.Config; import com.alttd.gridlines.configuration.Config;
import com.alttd.gridlines.layer.GridLinesLayer;
import com.alttd.gridlines.listener.WorldListener; import com.alttd.gridlines.listener.WorldListener;
import net.pl3x.map.Pl3xMap; import net.pl3x.map.core.Pl3xMap;
import net.pl3x.map.addon.Addon; import org.bukkit.plugin.java.JavaPlugin;
public class GridLines extends Addon { public class GridLines extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
Config.reload(); if (!getServer().getPluginManager().isPluginEnabled("Pl3xMap")) {
Pl3xMap.api().getEventRegistry().register(new WorldListener(this)); getLogger().severe("Pl3xMap not found!");
getServer().getPluginManager().disablePlugin(this);
return;
}
new Config().reload();
getServer().getPluginManager().registerEvents(new WorldListener(), this);
} }
@Override
public void onDisable() {
Pl3xMap.api().getWorldRegistry().forEach(world -> {
try {
world.getLayerRegistry().unregister(GridLinesLayer.KEY);
} catch (Throwable ignore) {
}
});
}
} }

View File

@ -1,10 +1,14 @@
package com.alttd.gridlines.configuration; package com.alttd.gridlines.configuration;
import net.pl3x.map.addon.AddonRegistry; import com.alttd.gridlines.GridLines;
import net.pl3x.map.configuration.AbstractConfig; import net.pl3x.map.core.configuration.AbstractConfig;
public class Config extends AbstractConfig { public class Config extends AbstractConfig {
public Config() {
reload();
}
@Key("settings.layer.label") @Key("settings.layer.label")
@Comment("Label for map layer") @Comment("Label for map layer")
public static String LAYER_LABEL = "Gridlines"; public static String LAYER_LABEL = "Gridlines";
@ -23,7 +27,7 @@ public class Config extends AbstractConfig {
private static final Config CONFIG = new Config(); private static final Config CONFIG = new Config();
public static void reload() { public void reload() {
CONFIG.reload(AddonRegistry.ADDONS_CONFIG_DIR.resolve("GridLines.yml"), Config.class); reload(GridLines.getPlugin(GridLines.class).getDataFolder().toPath(), Config.class);
} }
} }

View File

@ -1,16 +1,15 @@
package com.alttd.gridlines.layer; package com.alttd.gridlines.layer;
import com.alttd.gridlines.GridLines;
import com.alttd.gridlines.configuration.Config; import com.alttd.gridlines.configuration.Config;
import net.pl3x.map.Key;
import net.pl3x.map.markers.Point; import net.pl3x.map.core.markers.Point;
import net.pl3x.map.markers.layer.SimpleLayer; import net.pl3x.map.core.markers.layer.WorldLayer;
import net.pl3x.map.markers.marker.Marker; import net.pl3x.map.core.markers.marker.Marker;
import net.pl3x.map.markers.marker.Polyline; import net.pl3x.map.core.markers.marker.Polyline;
import net.pl3x.map.markers.option.Fill; import net.pl3x.map.core.markers.option.Fill;
import net.pl3x.map.markers.option.Options; import net.pl3x.map.core.markers.option.Options;
import net.pl3x.map.markers.option.Stroke; import net.pl3x.map.core.markers.option.Stroke;
import net.pl3x.map.world.World; import net.pl3x.map.core.world.World;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.WorldBorder; import org.bukkit.WorldBorder;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -18,16 +17,14 @@ import org.jetbrains.annotations.NotNull;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
public class GridLinesLayer extends SimpleLayer { public class GridLinesLayer extends WorldLayer {
public static final Key KEY = Key.of("gridlines"); public static final String KEY = "gridlines";
private final Collection<Marker<?>> MARKERS = new HashSet<>(); private final Collection<Marker<?>> MARKERS = new HashSet<>();
private final GridLines addon;
private final World mapWorld; private final World mapWorld;
public GridLinesLayer(GridLines addon, @NotNull World world) { public GridLinesLayer(@NotNull World world) {
super(KEY, () -> Config.LAYER_LABEL); super(KEY, world, () -> Config.LAYER_LABEL);
this.addon = addon;
this.mapWorld = world; this.mapWorld = world;
setShowControls(Config.LAYER_SHOW_CONTROLS); setShowControls(Config.LAYER_SHOW_CONTROLS);
setDefaultHidden(Config.LAYER_DEFAULT_HIDDEN); setDefaultHidden(Config.LAYER_DEFAULT_HIDDEN);
@ -53,20 +50,20 @@ public class GridLinesLayer extends SimpleLayer {
String key = "gridline"; String key = "gridline";
for(int i = -64; i < radius; i += 128) { for(int i = -64; i < radius; i += 128) {
t = i * -1; t = i * -1;
MARKERS.add(Marker.multiPolyline(Key.of(key + "-" + i), MARKERS.add(Marker.multiPolyline(key + "-" + i,
Polyline.of(Key.of(key + i + "-1"), Polyline.of(key + i + "-1",
Point.of(radius, i), Point.of(radius, i),
Point.of(radius2, i) Point.of(radius2, i)
), ),
Polyline.of(Key.of(key + i + "-2"), Polyline.of(key + i + "-2",
Point.of(i, radius), Point.of(i, radius),
Point.of(i, radius2) Point.of(i, radius2)
), ),
Polyline.of(Key.of(key + i + "-3"), Polyline.of(key + i + "-3",
Point.of(radius, t), Point.of(radius, t),
Point.of(radius2, t) Point.of(radius2, t)
), ),
Polyline.of(Key.of(key + i + "-4"), Polyline.of(key + i + "-4",
Point.of(t, radius), Point.of(t, radius),
Point.of(t, radius2) Point.of(t, radius2)
) )

View File

@ -1,34 +1,29 @@
package com.alttd.gridlines.listener; package com.alttd.gridlines.listener;
import com.alttd.gridlines.GridLines;
import com.alttd.gridlines.layer.GridLinesLayer; import com.alttd.gridlines.layer.GridLinesLayer;
import net.pl3x.map.Pl3xMap; import net.pl3x.map.core.Pl3xMap;
import net.pl3x.map.event.EventHandler; import net.pl3x.map.core.event.EventListener;
import net.pl3x.map.event.EventListener; import net.pl3x.map.core.event.server.ServerLoadedEvent;
import net.pl3x.map.event.server.ServerLoadedEvent; import net.pl3x.map.core.event.world.WorldLoadedEvent;
import net.pl3x.map.event.world.WorldLoadedEvent; import net.pl3x.map.core.event.world.WorldUnloadedEvent;
import net.pl3x.map.event.world.WorldUnloadedEvent; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class WorldListener implements EventListener { public class WorldListener implements Listener, EventListener {
private final GridLines addon;
public WorldListener(GridLines addon) {
this.addon = addon;
}
@EventHandler @EventHandler
public void onServerLoaded(ServerLoadedEvent event) { public void onServerLoaded(ServerLoadedEvent event) {
Pl3xMap.api().getWorldRegistry().entries().forEach((key, world) -> Pl3xMap.api().getWorldRegistry().forEach(world ->
world.getLayerRegistry().register(new GridLinesLayer(addon, world)) world.getLayerRegistry().register(new GridLinesLayer(world))
); );
} }
@EventHandler @net.pl3x.map.core.event.EventHandler
public void onWorldLoaded(WorldLoadedEvent event) { public void onWorldLoaded(WorldLoadedEvent event) {
event.getWorld().getLayerRegistry().register(new GridLinesLayer(addon, event.getWorld())); event.getWorld().getLayerRegistry().register(new GridLinesLayer(event.getWorld()));
} }
@EventHandler @net.pl3x.map.core.event.EventHandler
public void onWorldUnloaded(WorldUnloadedEvent event) { public void onWorldUnloaded(WorldUnloadedEvent event) {
event.getWorld().getLayerRegistry().unregister(GridLinesLayer.KEY); event.getWorld().getLayerRegistry().unregister(GridLinesLayer.KEY);
} }

View File

@ -1,4 +0,0 @@
name: "GridLines"
main: "com.alttd.gridlines.GridLines"
version: "1.0-SNAPSHOT"
author: "destro174"

View File

@ -0,0 +1,8 @@
name: "GridLines"
main: "com.alttd.gridlines.GridLines"
version: "2.0-SNAPSHOT"
author: "destro174"
api-version: "1.20"
load: "POSTWORLD"
softdepend:
- Pl3xMap