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.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
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,36 +22,42 @@ 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(
|
||||||
|
MultiPolyline.of(key + i,
|
||||||
Polyline.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)
|
||||||
|
|
@ -67,13 +74,8 @@ public class GridLinesLayer extends WorldLayer {
|
||||||
Point.of(t, radius),
|
Point.of(t, radius),
|
||||||
Point.of(t, radius2)
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user