Skip to content

Commit

Permalink
version 3.3.0 ; fixes #45
Browse files Browse the repository at this point in the history
sorry... to lazy to separate the commit :)
  • Loading branch information
thebuildcraft committed Feb 17, 2025
1 parent dedb99a commit 3e37371
Show file tree
Hide file tree
Showing 18 changed files with 268 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
*
* @author James Seibel
* @author Leander Knüttel
* @version 18.11.2024
* @version 17.02.2025
*/
public abstract class AbstractModInitializer
{
public static final String MOD_ID = "remote_player_waypoints_for_xaero";
public static final String MOD_NAME = "Remote Player Waypoints For Xaero's Map";
public static final String VERSION = "3.2.1";
public static final String VERSION = "3.3.0";
public static final Logger LOGGER = LogManager.getLogger("RemotePlayerWaypointsForXaero");
public static AbstractModInitializer INSTANCE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
package de.the_build_craft.remote_player_waypoints_for_xaero.common;

import de.the_build_craft.remote_player_waypoints_for_xaero.common.wrappers.Text;
import net.minecraft.client.Minecraft;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

/**
* @author Leander Knüttel
* @version 22.08.2024
* @version 17.02.2025
*/
public abstract class CommonModConfig {
public CommonModConfig() {
Expand Down Expand Up @@ -55,8 +60,10 @@ public CommonModConfig() {
public abstract boolean showAfkInTabList();
public abstract boolean hideAfkMinutes();
public abstract boolean debugMode();
public abstract boolean chatLogInDebugMode();
public abstract List<String> ignoredServers();
public abstract List<ServerEntry> serverEntries();
public abstract void setMarkerLayers(String ip, List<String> layers);
public abstract void setIgnoreMarkerMessage(boolean on);
public abstract boolean ignoreMarkerMessage();

Expand All @@ -79,19 +86,34 @@ public int getPlayerWaypointColor(String playerName) {
}
}

public ServerEntry getCurrentServerEntry() {
String serverIP = Objects.requireNonNull(Minecraft.getInstance().getCurrentServer()).ip.toLowerCase(Locale.ROOT);
ServerEntry serverEntry = null;
for (ServerEntry server : serverEntries()){
if (Objects.equals(serverIP, server.ip.toLowerCase(Locale.ROOT))){
serverEntry = server;
}
}
return serverEntry;
}

public static class ServerEntry {
public Maptype maptype;
public String ip;
public String link;
public MarkerVisibilityMode markerVisibilityMode;
public List<String> markerLayers;

public ServerEntry() {
this("", "", Maptype.Dynmap);
this("", "", Maptype.Dynmap, MarkerVisibilityMode.Auto, new ArrayList<>());
}

public ServerEntry(String ip, String link, Maptype maptype) {
public ServerEntry(String ip, String link, Maptype maptype, MarkerVisibilityMode markerVisibilityMode, List<String> markerLayers) {
this.ip = ip;
this.link = link;
this.maptype = maptype;
this.markerVisibilityMode = markerVisibilityMode;
this.markerLayers = markerLayers;
}

public enum Maptype {
Expand All @@ -103,6 +125,33 @@ public enum Maptype {
Maptype() {
}
}

public enum MarkerVisibilityMode {
Auto,
All,
None,
BlackList,
WhiteList;

MarkerVisibilityMode() {
}
}

public boolean includeMarkerLayer(String layer) {
switch (markerVisibilityMode) {
case Auto:
case All:
return true;
case None:
return false;
case BlackList:
return !markerLayers.contains(layer);
case WhiteList:
return markerLayers.contains(layer);
default:
throw new IllegalArgumentException();
}
}
}

public enum WaypointColor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
* @author eatmyvenom
* @author TheMrEngMan
* @author Leander Knüttel
* @version 22.08.2024
* @version 17.02.2025
*/
public class UpdateTask extends TimerTask {
private final Minecraft mc;
Expand Down Expand Up @@ -156,12 +156,8 @@ public void runUpdate() {

if (AbstractModInitializer.getConnection() == null){
try {
CommonModConfig.ServerEntry serverEntry = null;
for (CommonModConfig.ServerEntry server : CommonModConfig.Instance.serverEntries()){
if (Objects.equals(serverIP, server.ip.toLowerCase(Locale.ROOT))){
serverEntry = server;
}
}
CommonModConfig.ServerEntry serverEntry = CommonModConfig.Instance.getCurrentServerEntry();

if (Objects.equals(serverEntry, null)) {
if (!(CommonModConfig.Instance.ignoredServers().contains(serverIP) || cantFindServerErrorWasShown)) {
if ((AbstractModInitializer.INSTANCE.loaderType == LoaderType.Fabric)
Expand Down Expand Up @@ -446,7 +442,7 @@ public void runUpdate() {
markerMessageWasShown = true;
Utils.sendToClientChat(Text.literal("[" + AbstractModInitializer.MOD_NAME + "]: " +
"Looks like you have quite a lot of markers from the server visible! " +
"Did you know that you can decrease their maximum distance or disable marker waypoints entirely? ")
"Did you know that you can chose the marker layers that are shown in the config, decrease their maximum distance or disable marker waypoints entirely? ")
.withStyle(Style.EMPTY.withColor(ChatFormatting.GOLD))
.append(Text.literal("[Don't show this again]")
.withStyle(Style.EMPTY.withClickEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/**
* @author Leander Knüttel
* @author eatmyvenom
* @version 25.06.2024
* @version 17.02.2025
*/
public class BlueMapConnection extends MapConnection {
public int lastWorldIndex;
Expand Down Expand Up @@ -111,12 +111,23 @@ public HashMap<String, WaypointPosition> getWaypointPositions() throws IOExcepti

HashMap<String, WaypointPosition> positions = new HashMap<>();

CommonModConfig.ServerEntry serverEntry = CommonModConfig.Instance.getCurrentServerEntry();
if (serverEntry.markerVisibilityMode == CommonModConfig.ServerEntry.MarkerVisibilityMode.Auto) {
List<String> layers = new ArrayList<>();
for (Map.Entry<String, BlueMapMarkerSet> m : markerSets.entrySet()) {
layers.add(m.getKey());
}
CommonModConfig.Instance.setMarkerLayers(serverEntry.ip, layers);
}

for (Map.Entry<String, BlueMapMarkerSet> m : markerSets.entrySet()){
if (CommonModConfig.Instance.debugMode()){
if (CommonModConfig.Instance.debugMode() && CommonModConfig.Instance.chatLogInDebugMode()){
Utils.sendToClientChat("====================================");
Utils.sendToClientChat("markerSet: " + m.getKey());
}

if (!serverEntry.includeMarkerLayer(m.getKey())) continue;

for(BlueMapMarkerSet.Marker marker : m.getValue().markers.values()){
if (Objects.equals(marker.type, "poi") || Objects.equals(marker.type, "html")){
BlueMapMarkerSet.Position pos = marker.position;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

/**
Expand All @@ -37,7 +39,7 @@
* @author ewpratten
* @author Leander Knüttel
* @author eatmyvenom
* @version 25.06.2024
* @version 17.02.2025
*/
public class DynmapConnection extends MapConnection {
private String markerStringTemplate = "";
Expand Down Expand Up @@ -213,7 +215,18 @@ public HashMap<String, WaypointPosition> getWaypointPositions() throws IOExcepti
DynmapMarkerUpdate update = HTTP.makeJSONHTTPRequest(URI.create(markerStringTemplate.replace("{world}", dimension).replace(" ", "%20")).toURL(), DynmapMarkerUpdate.class);
HashMap<String, WaypointPosition> positions = new HashMap<>();

CommonModConfig.ServerEntry serverEntry = CommonModConfig.Instance.getCurrentServerEntry();
if (serverEntry.markerVisibilityMode == CommonModConfig.ServerEntry.MarkerVisibilityMode.Auto) {
List<String> layers = new ArrayList<>();
for (DynmapMarkerUpdate.Set set : update.sets.values()) {
layers.add(set.label);
}
CommonModConfig.Instance.setMarkerLayers(serverEntry.ip, layers);
}

for (DynmapMarkerUpdate.Set set : update.sets.values()){
if (!serverEntry.includeMarkerLayer(set.label)) continue;

for (DynmapMarkerUpdate.Set.Marker m : set.markers.values()){
WaypointPosition newWaypointPosition = new WaypointPosition(m.label, Math.round(m.x), Math.round(m.y), Math.round(m.z));
positions.put(newWaypointPosition.name, newWaypointPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/**
* @author Leander Knüttel
* @author eatmyvenom
* @version 04.09.2024
* @version 17.02.2025
*/
public abstract class MapConnection {
public URL queryURL;
Expand Down Expand Up @@ -116,7 +116,7 @@ public void UpdateAfkInfo(PlayerPosition playerPosition){
} else {
AbstractModInitializer.AfkTimeDic.put(playerPosition.player, (CommonModConfig.Instance.updateDelay() / 1000));
}
if (CommonModConfig.Instance.debugMode()) {
if (CommonModConfig.Instance.debugMode() && CommonModConfig.Instance.chatLogInDebugMode()) {
Utils.sendToClientChat(playerPosition.player + " afk_time: " + AbstractModInitializer.AfkTimeDic.get(playerPosition.player));
}
if (AbstractModInitializer.AfkTimeDic.get(playerPosition.player) >= CommonModConfig.Instance.timeUntilAfk()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

/**
* @author Leander Knüttel
* @author eatmyvenom
* @version 25.06.2024
* @version 17.02.2025
*/
public class Pl3xMapConnection extends MapConnection{
private String markerLayerStringTemplate = "";
Expand Down Expand Up @@ -127,12 +128,20 @@ private String[] getMarkerLayers() throws IOException {

ArrayList<String> layers = new ArrayList<>();

CommonModConfig.ServerEntry serverEntry = CommonModConfig.Instance.getCurrentServerEntry();

for (Pl3xMapMarkerLayerConfig layer : markerLayers){
if (!Objects.equals(layer.key, "pl3xmap_players")) {
layers.add(layer.key);
}
}

if (serverEntry.markerVisibilityMode == CommonModConfig.ServerEntry.MarkerVisibilityMode.Auto) {
CommonModConfig.Instance.setMarkerLayers(serverEntry.ip, layers);
}

layers.removeIf(o -> !serverEntry.includeMarkerLayer(o));

return layers.toArray(new String[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
import java.lang.reflect.Type;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

/**
* @author Leander Knüttel
* @author eatmyvenom
* @version 13.10.2024
* @version 17.02.2025
*/
public class SquareMapConnection extends MapConnection {
private String markerStringTemplate = "";
Expand Down Expand Up @@ -105,7 +107,18 @@ public HashMap<String, WaypointPosition> getWaypointPositions() throws IOExcepti

HashMap<String, WaypointPosition> positions = new HashMap<>();

CommonModConfig.ServerEntry serverEntry = CommonModConfig.Instance.getCurrentServerEntry();
if (serverEntry.markerVisibilityMode == CommonModConfig.ServerEntry.MarkerVisibilityMode.Auto) {
List<String> layers = new ArrayList<>();
for (SquareMapMarkerUpdate markerLayer : markersLayers) {
layers.add(markerLayer.name);
}
CommonModConfig.Instance.setMarkerLayers(serverEntry.ip, layers);
}

for (SquareMapMarkerUpdate markerLayer : markersLayers){
if (!serverEntry.includeMarkerLayer(markerLayer.name)) continue;

for (SquareMapMarkerUpdate.Marker marker : markerLayer.markers){
if (Objects.equals(marker.type, "icon")) {
WaypointPosition newWaypointPosition = new WaypointPosition(marker.tooltip, marker.point.x, CommonModConfig.Instance.defaultY(), marker.point.z);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/**
* @author Leander Knüttel
* @version 14.06.2024
* @version 17.02.2025
*/
public class SquareMapMarkerUpdate {
public static class Marker{
Expand All @@ -36,5 +36,6 @@ public static class Point{
public String type;
}

public String name;
public Marker[] markers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
"text.autoconfig.remote_player_waypoints_for_xaero.option.ServerEntry.ip": "server ip",
"text.autoconfig.remote_player_waypoints_for_xaero.option.ServerEntry.link": "online map link",
"text.autoconfig.remote_player_waypoints_for_xaero.option.ServerEntry.maptype": "online map type",
"text.autoconfig.remote_player_waypoints_for_xaero.option.ServerEntry.markerVisibilityMode": "marker visibility mode",
"text.autoconfig.remote_player_waypoints_for_xaero.option.ServerEntry.markerVisibilityMode.@Tooltip": "Set it to \"Auto\" to get all the layers from the online map.",
"text.autoconfig.remote_player_waypoints_for_xaero.option.ServerEntry.markerLayers": "marker layers",
"text.autoconfig.remote_player_waypoints_for_xaero.option.ServerEntry.markerLayers.@Tooltip": "Set the mode to \"Auto\" to get all the layers from the online map.",
"text.autoconfig.remote_player_waypoints_for_xaero.option.general.timeUntilAfk": "time until AFK",
"text.autoconfig.remote_player_waypoints_for_xaero.option.general.timeUntilAfk.@Tooltip": "in sec",
"text.autoconfig.remote_player_waypoints_for_xaero.option.general.unknownAfkStateColor": "unknown AFK state color",
Expand All @@ -58,6 +62,7 @@
"text.autoconfig.remote_player_waypoints_for_xaero.option.general.markerWaypointColor": "marker waypoint color",
"text.autoconfig.remote_player_waypoints_for_xaero.option.general.debugMode": "debug mode",
"text.autoconfig.remote_player_waypoints_for_xaero.option.general.debugMode.@PrefixText": "dev options - please ignore",
"text.autoconfig.remote_player_waypoints_for_xaero.option.general.chatLogInDebugMode": "chat logs in debug mode - chat spam...",
"text.autoconfig.remote_player_waypoints_for_xaero.option.general.showAfkInTabList": "show AFK status in tab list",
"text.autoconfig.remote_player_waypoints_for_xaero.option.general.hideAfkMinutes": "hide AFK minutes if AFK time is over 1 h",
"text.autoconfig.remote_player_waypoints_for_xaero.option.general.showAfkTimeInTabList": "show AFK time in tab list",
Expand Down
3 changes: 3 additions & 0 deletions docs/changelogs/3.3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## features:
* added a config option to chose which marker layers are enabled
* added a config option to disable the chat spam in debug mode
Loading

0 comments on commit 3e37371

Please sign in to comment.