From e670ccf1a1dd313db5a82be56a539531c9fae435 Mon Sep 17 00:00:00 2001 From: Len <40720638+destro174@users.noreply.github.com> Date: Sun, 2 Jul 2023 22:03:17 +0200 Subject: [PATCH] Update GridLines --- build.gradle.kts | 6 +-- .../java/com/alttd/gridlines/GridLines.java | 27 ++++++++++--- .../alttd/gridlines/configuration/Config.java | 12 ++++-- .../alttd/gridlines/layer/GridLinesLayer.java | 39 +++++++++---------- .../gridlines/listener/WorldListener.java | 31 +++++++-------- src/main/resources/addon.yml | 4 -- src/main/resources/plugin.yml | 8 ++++ 7 files changed, 72 insertions(+), 55 deletions(-) delete mode 100644 src/main/resources/addon.yml create mode 100644 src/main/resources/plugin.yml diff --git a/build.gradle.kts b/build.gradle.kts index 0d27283..3de6005 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } group = "com.alttd.gridlines" -version = "1.0-SNAPSHOT" +version = "2.0-SNAPSHOT" repositories { maven { @@ -15,6 +15,6 @@ repositories { } dependencies { - compileOnly("io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT") - compileOnly("maven.modrinth:pl3xmap:1.19.2-306") + compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") + compileOnly("maven.modrinth:pl3xmap:1.20.1-464") } \ No newline at end of file diff --git a/src/main/java/com/alttd/gridlines/GridLines.java b/src/main/java/com/alttd/gridlines/GridLines.java index 3c331d7..bd001d8 100644 --- a/src/main/java/com/alttd/gridlines/GridLines.java +++ b/src/main/java/com/alttd/gridlines/GridLines.java @@ -1,15 +1,32 @@ package com.alttd.gridlines; import com.alttd.gridlines.configuration.Config; +import com.alttd.gridlines.layer.GridLinesLayer; import com.alttd.gridlines.listener.WorldListener; -import net.pl3x.map.Pl3xMap; -import net.pl3x.map.addon.Addon; +import net.pl3x.map.core.Pl3xMap; +import org.bukkit.plugin.java.JavaPlugin; -public class GridLines extends Addon { +public class GridLines extends JavaPlugin { @Override public void onEnable() { - Config.reload(); - Pl3xMap.api().getEventRegistry().register(new WorldListener(this)); + if (!getServer().getPluginManager().isPluginEnabled("Pl3xMap")) { + 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) { + } + }); + } + } diff --git a/src/main/java/com/alttd/gridlines/configuration/Config.java b/src/main/java/com/alttd/gridlines/configuration/Config.java index b561c61..5919458 100644 --- a/src/main/java/com/alttd/gridlines/configuration/Config.java +++ b/src/main/java/com/alttd/gridlines/configuration/Config.java @@ -1,10 +1,14 @@ package com.alttd.gridlines.configuration; -import net.pl3x.map.addon.AddonRegistry; -import net.pl3x.map.configuration.AbstractConfig; +import com.alttd.gridlines.GridLines; +import net.pl3x.map.core.configuration.AbstractConfig; public class Config extends AbstractConfig { + public Config() { + reload(); + } + @Key("settings.layer.label") @Comment("Label for map layer") public static String LAYER_LABEL = "Gridlines"; @@ -23,7 +27,7 @@ public class Config extends AbstractConfig { private static final Config CONFIG = new Config(); - public static void reload() { - CONFIG.reload(AddonRegistry.ADDONS_CONFIG_DIR.resolve("GridLines.yml"), Config.class); + public void reload() { + reload(GridLines.getPlugin(GridLines.class).getDataFolder().toPath(), Config.class); } } diff --git a/src/main/java/com/alttd/gridlines/layer/GridLinesLayer.java b/src/main/java/com/alttd/gridlines/layer/GridLinesLayer.java index 45023fa..8973901 100644 --- a/src/main/java/com/alttd/gridlines/layer/GridLinesLayer.java +++ b/src/main/java/com/alttd/gridlines/layer/GridLinesLayer.java @@ -1,16 +1,15 @@ 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 net.pl3x.map.core.markers.Point; +import net.pl3x.map.core.markers.layer.WorldLayer; +import net.pl3x.map.core.markers.marker.Marker; +import net.pl3x.map.core.markers.marker.Polyline; +import net.pl3x.map.core.markers.option.Fill; +import net.pl3x.map.core.markers.option.Options; +import net.pl3x.map.core.markers.option.Stroke; +import net.pl3x.map.core.world.World; import org.bukkit.Bukkit; import org.bukkit.WorldBorder; import org.jetbrains.annotations.NotNull; @@ -18,16 +17,14 @@ import org.jetbrains.annotations.NotNull; import java.util.Collection; 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> 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; + public GridLinesLayer(@NotNull World world) { + super(KEY, world, () -> Config.LAYER_LABEL); this.mapWorld = world; setShowControls(Config.LAYER_SHOW_CONTROLS); setDefaultHidden(Config.LAYER_DEFAULT_HIDDEN); @@ -53,20 +50,20 @@ public class GridLinesLayer extends SimpleLayer { 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"), + MARKERS.add(Marker.multiPolyline(key + "-" + i, + Polyline.of(key + i + "-1", Point.of(radius, i), Point.of(radius2, i) ), - Polyline.of(Key.of(key + i + "-2"), + Polyline.of(key + i + "-2", Point.of(i, radius), Point.of(i, radius2) ), - Polyline.of(Key.of(key + i + "-3"), + Polyline.of(key + i + "-3", Point.of(radius, t), Point.of(radius2, t) ), - Polyline.of(Key.of(key + i + "-4"), + Polyline.of(key + i + "-4", Point.of(t, radius), Point.of(t, radius2) ) diff --git a/src/main/java/com/alttd/gridlines/listener/WorldListener.java b/src/main/java/com/alttd/gridlines/listener/WorldListener.java index b16d87d..e230b32 100644 --- a/src/main/java/com/alttd/gridlines/listener/WorldListener.java +++ b/src/main/java/com/alttd/gridlines/listener/WorldListener.java @@ -1,34 +1,29 @@ 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; +import net.pl3x.map.core.Pl3xMap; +import net.pl3x.map.core.event.EventListener; +import net.pl3x.map.core.event.server.ServerLoadedEvent; +import net.pl3x.map.core.event.world.WorldLoadedEvent; +import net.pl3x.map.core.event.world.WorldUnloadedEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; -public class WorldListener implements EventListener { - private final GridLines addon; - - public WorldListener(GridLines addon) { - this.addon = addon; - } +public class WorldListener implements Listener, EventListener { @EventHandler public void onServerLoaded(ServerLoadedEvent event) { - Pl3xMap.api().getWorldRegistry().entries().forEach((key, world) -> - world.getLayerRegistry().register(new GridLinesLayer(addon, world)) + Pl3xMap.api().getWorldRegistry().forEach(world -> + world.getLayerRegistry().register(new GridLinesLayer(world)) ); } - @EventHandler + @net.pl3x.map.core.event.EventHandler 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) { event.getWorld().getLayerRegistry().unregister(GridLinesLayer.KEY); } diff --git a/src/main/resources/addon.yml b/src/main/resources/addon.yml deleted file mode 100644 index 1fd0613..0000000 --- a/src/main/resources/addon.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: "GridLines" -main: "com.alttd.gridlines.GridLines" -version: "1.0-SNAPSHOT" -author: "destro174" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..e6d49cc --- /dev/null +++ b/src/main/resources/plugin.yml @@ -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 \ No newline at end of file