Fix loading

This commit is contained in:
Len 2023-07-03 08:51:21 +02:00
parent 6661ccfede
commit 8887bfc6e8
3 changed files with 39 additions and 39 deletions

View File

@ -2,7 +2,6 @@ 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.layer.GridLinesLayer;
import com.alttd.gridlines.listener.WorldListener;
import net.pl3x.map.core.Pl3xMap; import net.pl3x.map.core.Pl3xMap;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -15,8 +14,9 @@ public class GridLines extends JavaPlugin {
getServer().getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
return; return;
} }
new Config().reload(); Config.reload();
getServer().getPluginManager().registerEvents(new WorldListener(), this); Pl3xMap.api().getWorldRegistry().forEach(GridLinesLayer::new);
// getServer().getPluginManager().registerEvents(new WorldListener(), this);
} }
@Override @Override

View File

@ -1,13 +1,10 @@
package com.alttd.gridlines.configuration; package com.alttd.gridlines.configuration;
import com.alttd.gridlines.GridLines;
import net.pl3x.map.core.configuration.AbstractConfig; import net.pl3x.map.core.configuration.AbstractConfig;
public class Config extends AbstractConfig { import java.io.File;
public Config() { public class Config extends AbstractConfig {
reload();
}
@Key("settings.layer.label") @Key("settings.layer.label")
@Comment("Label for map layer") @Comment("Label for map layer")
@ -27,7 +24,8 @@ public class Config extends AbstractConfig {
private static final Config CONFIG = new Config(); private static final Config CONFIG = new Config();
public void reload() { public static void reload() {
reload(GridLines.getPlugin(GridLines.class).getDataFolder().toPath(), Config.class); File configPath = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "gridlines");
CONFIG.reload(configPath.toPath().resolve("config.yml"), Config.class);
} }
} }

View File

@ -5,6 +5,7 @@ import com.alttd.gridlines.configuration.Config;
import net.pl3x.map.core.markers.Point; import net.pl3x.map.core.markers.Point;
import net.pl3x.map.core.markers.layer.WorldLayer; import net.pl3x.map.core.markers.layer.WorldLayer;
import net.pl3x.map.core.markers.marker.Marker; import net.pl3x.map.core.markers.marker.Marker;
import net.pl3x.map.core.markers.marker.MultiPolyline;
import net.pl3x.map.core.markers.marker.Polyline; import net.pl3x.map.core.markers.marker.Polyline;
import net.pl3x.map.core.markers.option.Fill; import net.pl3x.map.core.markers.option.Fill;
import net.pl3x.map.core.markers.option.Options; import net.pl3x.map.core.markers.option.Options;
@ -21,59 +22,60 @@ public class GridLinesLayer extends WorldLayer {
public static final String KEY = "gridlines"; public static final String KEY = "gridlines";
private final Collection<Marker<?>> MARKERS = new HashSet<>(); private final Collection<Marker<?>> MARKERS = new HashSet<>();
private final World mapWorld;
public GridLinesLayer(@NotNull World world) { public GridLinesLayer(@NotNull World world) {
super(KEY, world, () -> Config.LAYER_LABEL); super(KEY, world, () -> Config.LAYER_LABEL);
this.mapWorld = world;
setShowControls(Config.LAYER_SHOW_CONTROLS); setShowControls(Config.LAYER_SHOW_CONTROLS);
setDefaultHidden(Config.LAYER_DEFAULT_HIDDEN); setDefaultHidden(Config.LAYER_DEFAULT_HIDDEN);
setPriority(Config.LAYER_PRIORITY); setPriority(Config.LAYER_PRIORITY);
setZIndex(Config.LAYER_ZINDEX); setZIndex(Config.LAYER_ZINDEX);
setUpdateInterval(0);
updateLayer(); updateLayer();
world.getLayerRegistry().register(this);
} }
@Override @Override
public @NotNull Collection<Marker<?>> getMarkers() { public @NotNull Collection<Marker<?>> getMarkers() {
return MARKERS; return this.MARKERS;
} }
public void updateLayer() { public void updateLayer() {
MARKERS.clear(); MARKERS.clear();
org.bukkit.World world = Bukkit.getWorld(mapWorld.getName()); org.bukkit.World world = Bukkit.getWorld(getWorld().getName());
if (world == null) return; if (world == null) return;
WorldBorder worldBorder = world.getWorldBorder(); WorldBorder worldBorder = world.getWorldBorder();
double radius = worldBorder.getSize() / 2; double radius = worldBorder.getSize() / 2;
double radius2 = radius * -1; double radius2 = radius * -1;
int t; int t;
String key = "gridline"; String key = "gridline_" + world.getName();
Options options = Options.builder()
.strokeColor(0xFFFF0000)
.strokeWeight(1)
.fill(false).build();
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 + "-" + i, MARKERS.add(
Polyline.of(key + i + "-1", MultiPolyline.of(key + i,
Point.of(radius, i), Polyline.of(key + i + "-1",
Point.of(radius2, i) Point.of(radius, i),
), Point.of(radius2, i)
Polyline.of(key + i + "-2", ),
Point.of(i, radius), Polyline.of(key + i + "-2",
Point.of(i, radius2) Point.of(i, radius),
), Point.of(i, radius2)
Polyline.of(key + i + "-3", ),
Point.of(radius, t), Polyline.of(key + i + "-3",
Point.of(radius2, t) Point.of(radius, t),
), Point.of(radius2, t)
Polyline.of(key + i + "-4", ),
Point.of(t, radius), Polyline.of(key + i + "-4",
Point.of(t, radius2) Point.of(t, radius),
) Point.of(t, radius2)
)); )
} ).setOptions(options)
Options options = new Options() );
.setStroke(new Stroke().setColor(0xFFFF0000).setWeight(1))
.setFill(new Fill().setEnabled(false));
for (Marker<?> marker : MARKERS) {
marker.setOptions(options);
} }
} }