Skip to content

Commit

Permalink
properly voxel map support + config rework (1.1.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
AltronMaxX committed Jan 13, 2024
1 parent cbfedaa commit 0e5f3a7
Show file tree
Hide file tree
Showing 17 changed files with 360 additions and 187 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id("com.github.johnrengelman.shadow") version "7.1.2"
}

val versionStr = (System.getenv("VERSION")?: "v1.0.0").removePrefix("v")
val versionStr = "1.1.0"

group = "net.edenor.minimap"
version = versionStr
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/net/edenor/minimap/DefaultWorldConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.edenor.minimap;

import net.edenor.minimap.jm.data.JMWorldConfig;
import net.edenor.minimap.voxel.data.VoxelWorldConfig;
import net.edenor.minimap.xaeros.XaerosWorldConfig;
import org.bukkit.configuration.file.FileConfiguration;

public class DefaultWorldConfig {

public DefaultWorldConfig(){
defaultXaerosWorldConfig = new XaerosWorldConfig();
defaultVoxelWorldConfig = new VoxelWorldConfig();
defaultJMWorldConfig = new JMWorldConfig();
}
XaerosWorldConfig defaultXaerosWorldConfig;
VoxelWorldConfig defaultVoxelWorldConfig;
public JMWorldConfig defaultJMWorldConfig;

public void addDefaultsToConfig(FileConfiguration cfg){
cfg.createSection("default-world-config");
cfg.createSection("default-world-config.xaeros", defaultXaerosWorldConfig.toMap());
cfg.createSection("default-world-config.jm", defaultJMWorldConfig.toMap());
cfg.createSection("default-world-config.voxel", defaultVoxelWorldConfig.toMap());
}
}
68 changes: 44 additions & 24 deletions src/main/java/net/edenor/minimap/MinimapConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import net.edenor.minimap.jm.data.JMConfig;
import net.edenor.minimap.jm.data.JMWorldConfig;
import net.edenor.minimap.voxel.VoxelMapConfig;
import net.edenor.minimap.voxel.data.VoxelConfig;
import net.edenor.minimap.voxel.data.VoxelWorldConfig;
import net.edenor.minimap.xaeros.XaerosConfig;
import net.edenor.minimap.xaeros.XaerosWorldConfig;
import org.bukkit.World;
import org.bukkit.configuration.MemoryConfiguration;
import org.bukkit.configuration.file.FileConfiguration;

import java.io.IOException;
Expand All @@ -16,32 +18,53 @@
public class MinimapConfig{
public static JMConfig globalJourneymapConfig = new JMConfig();
public static XaerosConfig globalXaerosConfig = new XaerosConfig();
public static JMWorldConfig defaultWorldConfig = new JMWorldConfig();
public static VoxelMapConfig globalVoxelConfig = new VoxelMapConfig();
public static VoxelConfig globalVoxelConfig = new VoxelConfig();
public static DefaultWorldConfig defaultWorldConfig;
private static final Map<String, WorldConfig> worlds = new HashMap<>();
private static FileConfiguration config;
public static void initConfig(){
config = MinimapPlugin.getInstance().getConfig();

globalJourneymapConfig.loadFromConfig(config);
globalXaerosConfig.loadFromConfig(config);
globalVoxelConfig.loadFromConfig(config);
defaultWorldConfig.loadFromConfig(config);
defaultWorldConfig = new DefaultWorldConfig();

globalJourneymapConfig.loadFromConfig();
globalXaerosConfig.loadFromConfig();
globalVoxelConfig.loadFromConfig();

for (World world : MinimapPlugin.getInstance().getServer().getWorlds()){
addWorld(world);
}

try {
if (!config.getBoolean("generated", false))
{
config.createSection("global-journeymap-config", globalJourneymapConfig.toMap());
config.createSection("global-voxel-config", globalVoxelConfig.toMap());
config.createSection("global-xaeros-config", globalXaerosConfig.toMap());
defaultWorldConfig.addDefaultsToConfig(config);
config.set("generated", true);
saveConfig();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static Object get(String id, Object def) {
if (config == null)
throw new RuntimeException("Config is not initialized!");

if (!config.contains(id)) {
config.set(id, def);
}
return config.get(id);
}

public static void saveConfig() throws IOException {
config.save("config.yml");
MinimapPlugin.getInstance().saveConfig();
}

public static void addWorld(World world){
if (!config.contains("worlds"))
{
config.createSection("worlds");
}
if (config.contains("worlds." + world.getName())){
WorldConfig worldConfig = new WorldConfig();
worldConfig.fromConfig(config, world.getName());
Expand Down Expand Up @@ -75,24 +98,21 @@ public static class WorldConfig {
public UUID worldId = UUID.randomUUID();
public JMWorldConfig journeymapConfig = new JMWorldConfig();
public XaerosWorldConfig xaerosConfig = new XaerosWorldConfig();
public VoxelWorldConfig voxelWorldConfig = new VoxelWorldConfig();

public void fromConfig(FileConfiguration cfg, String worldName) {
this.worldId = cfg.getObject("worlds." + worldName + ".worldId", UUID.class);
this.journeymapConfig.loadFromConfig(cfg);
this.xaerosConfig.loadFromConfig(cfg);
}

public String toString(){
return "worldId: " + worldId + "\n" +
"journeymapConfig: " + '\n' + journeymapConfig.toString() + "\n" +
"xaerosConfig: " + '\n' + xaerosConfig.toString();
this.journeymapConfig.loadFromConfig(worldName);
this.xaerosConfig.loadFromConfig(worldName);
this.voxelWorldConfig.loadFromConfig(worldName);
}

public Map<String, String> toMap() {
Map<String, String> ret = new HashMap<>();
public Map<String, Object> toMap() {
Map<String, Object> ret = new HashMap<>();
ret.put("worldId", worldId.toString());
ret.put("journeymapConfig", journeymapConfig.toString());
ret.put("xaerosConfig", xaerosConfig.toString());
ret.put("journeymapConfig", journeymapConfig.toMap());
ret.put("xaerosConfig", xaerosConfig.toMap());
ret.put("voxelConfig", voxelWorldConfig.toMap());

return ret;
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/net/edenor/minimap/MinimapEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ public void onJoin(PlayerJoinEvent event) {

@EventHandler
public void onWorldChange(PlayerChangedWorldEvent event) {
handlePackets(new MinimapPlayer(event.getPlayer()));
plugin.getServer().getGlobalRegionScheduler().runDelayed(plugin,
v->this.handlePackets(new MinimapPlayer(event.getPlayer())), 20L);
plugin.getServer().getGlobalRegionScheduler().runDelayed(plugin,
v->this.handlePackets(new MinimapPlayer(event.getPlayer())), 100L); //Resend later
plugin.getServer().getGlobalRegionScheduler().runDelayed(plugin,
v->this.handlePackets(new MinimapPlayer(event.getPlayer())), 200L); //Resend later
}

public void handlePackets(MinimapPlayer player) {
plugin.xaerosHandler.sendXaerosHandshake(player);
plugin.xaerosHandler.sendXaerosConfig(player);
plugin.voxelHandler.sendSettings(player);
}
}
3 changes: 2 additions & 1 deletion src/main/java/net/edenor/minimap/MinimapListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class MinimapListener implements PluginMessageListener {
"journeymap:common",
"worldinfo:world_id",
"xaerominimap:main",
"xaeroworldmap:main"
"xaeroworldmap:main",
"voxelmap:settings"
);

private MinimapPlugin plugin;
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/net/edenor/minimap/MinimapPlugin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.edenor.minimap;

import net.edenor.minimap.jm.JMHandler;
import net.edenor.minimap.voxel.VoxelHandler;
import net.edenor.minimap.worldinfo.WorldInfoHandler;
import net.edenor.minimap.xaeros.XaerosHandler;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -11,6 +12,7 @@ public class MinimapPlugin extends JavaPlugin {
public final JMHandler jmHandler = new JMHandler(this);
public final XaerosHandler xaerosHandler = new XaerosHandler();
public final WorldInfoHandler worldInfoHandler = new WorldInfoHandler();
public final VoxelHandler voxelHandler = new VoxelHandler(this);

public MinimapPlugin plugin;

Expand All @@ -32,12 +34,4 @@ public void onDisable() {
public static MinimapPlugin getInstance() {
return instance;
}

public void saveConfig() {
try {
MinimapConfig.saveConfig();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
5 changes: 3 additions & 2 deletions src/main/java/net/edenor/minimap/jm/JMHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.edenor.minimap.jm;

import net.edenor.minimap.DefaultWorldConfig;
import net.edenor.minimap.MinimapPlugin;
import net.edenor.minimap.MinimapConfig;
import net.edenor.minimap.api.MessageHandler;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void handleAdminReq(MinimapPlayer player, byte[] message, String replyCha
HashMap<String, String> payloads = new HashMap<>();

payloads.put("GLOBAL", gson.toJson(MinimapConfig.globalJourneymapConfig));
payloads.put("DEFAULT", gson.toJson(MinimapConfig.defaultWorldConfig));
payloads.put("DEFAULT", gson.toJson(MinimapConfig.defaultWorldConfig.defaultJMWorldConfig));

for (World world : plugin.getServer().getWorlds()){
payloads.put(world.getName(),gson.toJson(MinimapConfig.getWorldConfig(world.getName())));
Expand Down Expand Up @@ -113,7 +114,7 @@ public void handleAdminSave(MinimapPlayer player, byte[] message, String replyCh
worldConfig.journeymapConfig = newConfig;
System.out.println(dimension);
} else {
MinimapConfig.defaultWorldConfig = newConfig;
MinimapConfig.defaultWorldConfig.defaultJMWorldConfig = newConfig;
}
}
plugin.saveConfig();
Expand Down
105 changes: 56 additions & 49 deletions src/main/java/net/edenor/minimap/jm/data/JMConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package net.edenor.minimap.jm.data;

import org.bukkit.configuration.file.FileConfiguration;
import net.edenor.minimap.MinimapConfig;
import org.bukkit.configuration.MemoryConfiguration;

import java.util.HashMap;
import java.util.Map;

public class JMConfig {
public String journeymapEnabled = "true";
Expand Down Expand Up @@ -57,55 +61,58 @@ public JMConfig copy() {
return clone;
}

public void loadFromConfig(FileConfiguration cfg){
this.journeymapEnabled = cfg.getString("global-journeymap-config.journeymapEnabled");
this.useWorldId = cfg.getString("global-journeymap-config.useWorldId");
this.viewOnlyServerProperties = cfg.getString("global-journeymap-config.viewOnlyServerProperties");
this.allowMultiplayerSettings = cfg.getString("global-journeymap-config.allowMultiplayerSettings");
this.worldPlayerRadar = cfg.getString("global-journeymap-config.worldPlayerRadar");
this.worldPlayerRadarUpdateTime = cfg.getString("global-journeymap-config.worldPlayerRadarUpdateTime");
this.seeUndergroundPlayers = cfg.getString("global-journeymap-config.seeUndergroundPlayers");
this.hideOps = cfg.getString("global-journeymap-config.hideOps");
this.hideSpectators = cfg.getString("global-journeymap-config.hideSpectators");
this.allowDeathPoints = cfg.getString("global-journeymap-config.allowDeathPoints");
this.showInGameBeacons = cfg.getString("global-journeymap-config.showInGameBeacons");
this.allowWaypoints = cfg.getString("global-journeymap-config.allowWaypoints");
this.teleportEnabled = cfg.getString("global-journeymap-config.teleportEnabled");
this.renderRange = cfg.getString("global-journeymap-config.renderRange");
this.surfaceMapping = cfg.getString("global-journeymap-config.surfaceMapping");
this.topoMapping = cfg.getString("global-journeymap-config.topoMapping");
this.biomeMapping = cfg.getString("global-journeymap-config.biomeMapping");
this.caveMapping = cfg.getString("global-journeymap-config.caveMapping");
this.radarEnabled = cfg.getString("global-journeymap-config.radarEnabled");
this.playerRadarEnabled = cfg.getString("global-journeymap-config.playerRadarEnabled");
this.villagerRadarEnabled = cfg.getString("global-journeymap-config.villagerRadarEnabled");
this.animalRadarEnabled = cfg.getString("global-journeymap-config.animalRadarEnabled");
this.mobRadarEnabled = cfg.getString("global-journeymap-config.mobRadarEnabled");
public void loadFromConfig(){
this.journeymapEnabled = (String) MinimapConfig.get("global-journeymap-config.journeymapEnabled", journeymapEnabled);
this.useWorldId = (String) MinimapConfig.get("global-journeymap-config.useWorldId", useWorldId);
this.viewOnlyServerProperties = (String) MinimapConfig.get("global-journeymap-config.viewOnlyServerProperties", viewOnlyServerProperties);
this.allowMultiplayerSettings = (String) MinimapConfig.get("global-journeymap-config.allowMultiplayerSettings", allowMultiplayerSettings);
this.worldPlayerRadar = (String) MinimapConfig.get("global-journeymap-config.worldPlayerRadar", worldPlayerRadar);
this.worldPlayerRadarUpdateTime = (String) MinimapConfig.get("global-journeymap-config.worldPlayerRadarUpdateTime", worldPlayerRadarUpdateTime);
this.seeUndergroundPlayers = (String) MinimapConfig.get("global-journeymap-config.seeUndergroundPlayers", seeUndergroundPlayers);
this.hideOps = (String) MinimapConfig.get("global-journeymap-config.hideOps", hideOps);
this.hideSpectators = (String) MinimapConfig.get("global-journeymap-config.hideSpectators", hideSpectators);
this.allowDeathPoints = (String) MinimapConfig.get("global-journeymap-config.allowDeathPoints", allowDeathPoints);
this.showInGameBeacons = (String) MinimapConfig.get("global-journeymap-config.showInGameBeacons", showInGameBeacons);
this.allowWaypoints = (String) MinimapConfig.get("global-journeymap-config.allowWaypoints", allowWaypoints);
this.teleportEnabled = (String) MinimapConfig.get("global-journeymap-config.teleportEnabled", teleportEnabled);
this.renderRange = (String) MinimapConfig.get("global-journeymap-config.renderRange", renderRange);
this.surfaceMapping = (String) MinimapConfig.get("global-journeymap-config.surfaceMapping", surfaceMapping);
this.topoMapping = (String) MinimapConfig.get("global-journeymap-config.topoMapping", topoMapping);
this.biomeMapping = (String) MinimapConfig.get("global-journeymap-config.biomeMapping", biomeMapping);
this.caveMapping = (String) MinimapConfig.get("global-journeymap-config.caveMapping", caveMapping);
this.radarEnabled = (String) MinimapConfig.get("global-journeymap-config.radarEnabled", radarEnabled);
this.playerRadarEnabled = (String) MinimapConfig.get("global-journeymap-config.playerRadarEnabled", playerRadarEnabled);
this.villagerRadarEnabled = (String) MinimapConfig.get("global-journeymap-config.villagerRadarEnabled", villagerRadarEnabled);
this.animalRadarEnabled = (String) MinimapConfig.get("global-journeymap-config.animalRadarEnabled", animalRadarEnabled);
this.mobRadarEnabled = (String) MinimapConfig.get("global-journeymap-config.mobRadarEnabled", mobRadarEnabled);
}

public String toString(){
return "journeymapEnabled: " + journeymapEnabled + "\n" +
"useWorldId: " + useWorldId + "\n" +
"viewOnlyServerProperties: " + viewOnlyServerProperties + "\n" +
"allowMultiplayerSettings: " + allowMultiplayerSettings + "\n" +
"worldPlayerRadar: " + worldPlayerRadar + "\n" +
"worldPlayerRadarUpdateTime: " + worldPlayerRadarUpdateTime + "\n" +
"seeUndergroundPlayers: " + seeUndergroundPlayers + "\n" +
"hideOps: " + hideOps + "\n" +
"hideSpectators: " + hideSpectators + "\n" +
"allowDeathPoints: " + allowDeathPoints + "\n" +
"showInGameBeacons: " + showInGameBeacons + "\n" +
"allowWaypoints: " + allowWaypoints + "\n" +
"renderRange: " + renderRange + "\n" +
"teleportEnabled: " + teleportEnabled + "\n" +
"surfaceMapping: " + surfaceMapping + "\n" +
"topoMapping: " + topoMapping + "\n" +
"biomeMapping: " + biomeMapping + "\n" +
"caveMapping: " + caveMapping + "\n" +
"radarEnabled: " + radarEnabled + "\n" +
"playerRadarEnabled: " + playerRadarEnabled + "\n" +
"villagerRadarEnabled: " + villagerRadarEnabled + "\n" +
"animalRadarEnabled: " + animalRadarEnabled + "\n" +
"mobRadarEnabled: " + mobRadarEnabled;
public Map<String, String> toMap() {
Map<String, String> ret = new HashMap<>(); //global-journeymap-config
ret.put("journeymapEnabled", journeymapEnabled);
ret.put("useWorldId", useWorldId);
ret.put("viewOnlyServerProperties", viewOnlyServerProperties);
ret.put("allowMultiplayerSettings", allowMultiplayerSettings);
ret.put("worldPlayerRadar", worldPlayerRadar);
ret.put("worldPlayerRadarUpdateTime", worldPlayerRadarUpdateTime);
ret.put(".seeUndergroundPlayers", seeUndergroundPlayers);
ret.put("hideOps", hideOps);
ret.put("hideSpectators", hideSpectators);
ret.put("allowDeathPoints", allowDeathPoints);
ret.put("showInGameBeacons", showInGameBeacons);
ret.put("allowWaypoints", allowWaypoints);
ret.put("teleportEnabled", teleportEnabled);
ret.put("renderRange", renderRange);
ret.put("surfaceMapping", surfaceMapping);
ret.put("topoMapping", topoMapping);
ret.put("biomeMapping", biomeMapping);
ret.put("caveMapping", caveMapping);
ret.put("radarEnabled", radarEnabled);
ret.put("playerRadarEnabled", playerRadarEnabled);
ret.put("villagerRadarEnabled", villagerRadarEnabled);
ret.put("animalRadarEnabled", animalRadarEnabled);
ret.put("mobRadarEnabled", mobRadarEnabled);

return ret;
}
}
Loading

0 comments on commit 0e5f3a7

Please sign in to comment.