Fix loading
This commit is contained in:
parent
6661ccfede
commit
8887bfc6e8
|
|
@ -2,7 +2,6 @@ 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.core.Pl3xMap;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
|
@ -15,8 +14,9 @@ public class GridLines extends JavaPlugin {
|
|||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
new Config().reload();
|
||||
getServer().getPluginManager().registerEvents(new WorldListener(), this);
|
||||
Config.reload();
|
||||
Pl3xMap.api().getWorldRegistry().forEach(GridLinesLayer::new);
|
||||
// getServer().getPluginManager().registerEvents(new WorldListener(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
package com.alttd.gridlines.configuration;
|
||||
|
||||
import com.alttd.gridlines.GridLines;
|
||||
import net.pl3x.map.core.configuration.AbstractConfig;
|
||||
|
||||
public class Config extends AbstractConfig {
|
||||
import java.io.File;
|
||||
|
||||
public Config() {
|
||||
reload();
|
||||
}
|
||||
public class Config extends AbstractConfig {
|
||||
|
||||
@Key("settings.layer.label")
|
||||
@Comment("Label for map layer")
|
||||
|
|
@ -27,7 +24,8 @@ public class Config extends AbstractConfig {
|
|||
|
||||
private static final Config CONFIG = new Config();
|
||||
|
||||
public void reload() {
|
||||
reload(GridLines.getPlugin(GridLines.class).getDataFolder().toPath(), Config.class);
|
||||
public static void reload() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.alttd.gridlines.configuration.Config;
|
|||
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.MultiPolyline;
|
||||
import net.pl3x.map.core.markers.marker.Polyline;
|
||||
import net.pl3x.map.core.markers.option.Fill;
|
||||
import net.pl3x.map.core.markers.option.Options;
|
||||
|
|
@ -21,36 +22,42 @@ public class GridLinesLayer extends WorldLayer {
|
|||
|
||||
public static final String KEY = "gridlines";
|
||||
private final Collection<Marker<?>> MARKERS = new HashSet<>();
|
||||
private final World mapWorld;
|
||||
|
||||
public GridLinesLayer(@NotNull World world) {
|
||||
super(KEY, world, () -> Config.LAYER_LABEL);
|
||||
this.mapWorld = world;
|
||||
|
||||
setShowControls(Config.LAYER_SHOW_CONTROLS);
|
||||
setDefaultHidden(Config.LAYER_DEFAULT_HIDDEN);
|
||||
setPriority(Config.LAYER_PRIORITY);
|
||||
setZIndex(Config.LAYER_ZINDEX);
|
||||
setUpdateInterval(0);
|
||||
updateLayer();
|
||||
world.getLayerRegistry().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<Marker<?>> getMarkers() {
|
||||
return MARKERS;
|
||||
return this.MARKERS;
|
||||
}
|
||||
|
||||
public void updateLayer() {
|
||||
MARKERS.clear();
|
||||
org.bukkit.World world = Bukkit.getWorld(mapWorld.getName());
|
||||
org.bukkit.World world = Bukkit.getWorld(getWorld().getName());
|
||||
if (world == null) return;
|
||||
WorldBorder worldBorder = world.getWorldBorder();
|
||||
double radius = worldBorder.getSize() / 2;
|
||||
double radius2 = radius * -1;
|
||||
|
||||
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) {
|
||||
t = i * -1;
|
||||
MARKERS.add(Marker.multiPolyline(key + "-" + i,
|
||||
MARKERS.add(
|
||||
MultiPolyline.of(key + i,
|
||||
Polyline.of(key + i + "-1",
|
||||
Point.of(radius, i),
|
||||
Point.of(radius2, i)
|
||||
|
|
@ -67,13 +74,8 @@ public class GridLinesLayer extends WorldLayer {
|
|||
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);
|
||||
).setOptions(options)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user