Skip to content

Commit

Permalink
Switch to Navigator api & add Xaeros maps integration (#91)
Browse files Browse the repository at this point in the history
* Switch to Navigator api & add Xaeros maps integration

* fix readme link

* fix dep

* remove debug logging

* Spotless apply for branch navigator-api-migration for #91 (#92)

Co-authored-by: GitHub GTNH Actions <>

* update navigator dep

* Unify buttons

* Simplify Xaero tooltips

* no need to register all this anymore

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Martin Robertz <[email protected]>
  • Loading branch information
3 people authored Jul 20, 2024
1 parent cd8dbdc commit 9da77f8
Show file tree
Hide file tree
Showing 26 changed files with 346 additions and 218 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ ServerUtilities
===============
ServerUtilities for server owners and daring single players. Backport and Rebrand of the 1.12.2 version of FTBUtilities, FTBLibrary, and Aurora for 1.7.10.

Fully backwards compatible with homes, chunks, and warps. These will be loaded from FTBU on first load.
Fully backwards compatible with homes, chunks, and more. These will be imported on first load.

Utilizes a permission system to handle whether a player can use certain commands and do certain things. A full list of permissions along with their description can be dumped using the command `/dump_permissions`, the file will be placed at ``.minecraft/serverutilities/server/``. They can also be viewed using the Aurora webapi.
Utilizes a permission system to handle whether a player can use certain commands and do certain things. A full list of permissions along with their description can be found in the Ranks edit gui found in the admin panel or by using `/dump permissions`.

## Dependencies
* [GTNHLib](https://www.curseforge.com/minecraft/mc-mods/gtnhlib)
* Optionally [Navigator](https://github.com/GTNewHorizons/Navigator) which enables claims and chunkload integration for JourneyMap or Xaeros World & Minimap

## Quick Install

Expand Down
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

dependencies {

api("com.github.GTNewHorizons:GTNHLib:0.3.1:dev")
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.6.14-GTNH:dev")
compileOnly("com.github.GTNewHorizons:VisualProspecting:1.3.3:dev")
compileOnly("com.github.GTNewHorizons:EnderIO:2.8.14:dev")
compileOnly("com.github.GTNewHorizons:Navigator:1.0.5:dev")

runtimeOnlyNonPublishable("com.github.GTNewHorizons:waila:1.8.1:dev")
// runtimeOnlyNonPublishable("com.github.GTNewHorizons:VisualProspecting:1.3.3:dev")

shadowCompile("it.unimi.dsi:fastutil:8.5.12")
}
2 changes: 1 addition & 1 deletion src/main/java/serverutils/ServerUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
modid = ServerUtilities.MOD_ID,
name = ServerUtilities.MOD_NAME,
version = ServerUtilities.VERSION,
dependencies = "after:visualprospecting;",
dependencies = "required-after:gtnhlib;" + "after:navigator;",
guiFactory = "serverutils.client.gui.GuiFactory")
public class ServerUtilities {

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/serverutils/client/ServerUtilitiesClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import serverutils.command.client.CommandPrintState;
import serverutils.command.client.CommandSimulateButton;
import serverutils.handlers.ServerUtilitiesClientEventHandler;
import serverutils.integration.vp.VPIntegration;
import serverutils.integration.navigator.NavigatorIntegration;
import serverutils.lib.OtherMods;
import serverutils.lib.client.ClientUtils;
import serverutils.lib.client.IncompatibleModException;
Expand Down Expand Up @@ -75,8 +75,8 @@ public void postInit(FMLPostInitializationEvent event) {
ClientCommandHandler.instance.registerCommand(new CommandPrintState());
ClientCommandHandler.instance.registerCommand(new CommandPing());

if (OtherMods.isVPLoaded() && ServerUtilitiesClientConfig.general.journeymap_overlay) {
VPIntegration.init();
if (OtherMods.isNavigatorLoaded() && ServerUtilitiesClientConfig.general.journeymap_overlay) {
NavigatorIntegration.init();
}

if (Loader.isModLoaded("FTBU") || Loader.isModLoaded("FTBL")) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/serverutils/data/ClaimedChunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void removeChunk(ChunkDimPos pos) {
prevChunk.setInvalid();
markDirty();
}
if (OtherMods.isVPLoaded()) {
if (OtherMods.isNavigatorLoaded()) {
for (EntityPlayerMP player : instance.universe.server.getConfigurationManager().playerEntityList) {
if (PermissionAPI.hasPermission(player, ServerUtilitiesPermissions.CLAIMS_JOURNEYMAP)) {
new MessageJourneyMapRemove(pos).sendTo(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import serverutils.client.gui.GuiSidebar;
import serverutils.events.chunks.UpdateClientDataEvent;
import serverutils.events.client.CustomClickEvent;
import serverutils.integration.vp.VPIntegration;
import serverutils.integration.navigator.NavigatorIntegration;
import serverutils.lib.OtherMods;
import serverutils.lib.client.ClientUtils;
import serverutils.lib.client.GlStateManager;
Expand Down Expand Up @@ -68,8 +68,8 @@ public static void readSyncData(NBTTagCompound nbt) {
public void onClientDisconnected(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {
shutdownTime = 0L;
SidedUtils.SERVER_MODS.clear();
if (OtherMods.isVPLoaded()) {
VPIntegration.CLAIMS.clear();
if (OtherMods.isNavigatorLoaded()) {
NavigatorIntegration.CLAIMS.clear();
}
}

Expand All @@ -95,8 +95,8 @@ public void onClientWorldTick(TickEvent.ClientTickEvent event) {
public void onChunkDataUpdate(UpdateClientDataEvent event) {
MessageClaimedChunksUpdate message = event.getMessage();
GuiClaimedChunks.onChunkDataUpdate(message);
if (OtherMods.isVPLoaded()) {
VPIntegration.onChunkDataUpdate(message);
if (OtherMods.isNavigatorLoaded()) {
NavigatorIntegration.onChunkDataUpdate(message);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package serverutils.integration.navigator;

import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;

import com.gtnewhorizons.navigator.api.model.SupportedMods;
import com.gtnewhorizons.navigator.api.model.buttons.ButtonManager;

import serverutils.ServerUtilities;

public class ClaimsButtonManager extends ButtonManager {

public static final ClaimsButtonManager INSTANCE = new ClaimsButtonManager();

@Override
public ResourceLocation getIcon(SupportedMods mod, String theme) {
return new ResourceLocation(ServerUtilities.MOD_ID, "textures/icons/team_blank.png");
}

@Override
public String getButtonText() {
return StatCollector.translateToLocal("serverutilities.navigator.button");
}
}
Original file line number Diff line number Diff line change
@@ -1,59 +1,54 @@
package serverutils.integration.vp;
package serverutils.integration.navigator;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nullable;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.world.ChunkCoordIntPair;

import com.sinthoras.visualprospecting.Utils;
import com.sinthoras.visualprospecting.integration.model.layers.WaypointProviderManager;
import com.sinthoras.visualprospecting.integration.model.locations.IWaypointAndLocationProvider;
import com.gtnewhorizons.navigator.api.model.SupportedMods;
import com.gtnewhorizons.navigator.api.model.layers.InteractableLayerManager;
import com.gtnewhorizons.navigator.api.model.layers.LayerRenderer;
import com.gtnewhorizons.navigator.api.model.locations.IWaypointAndLocationProvider;
import com.gtnewhorizons.navigator.api.model.waypoints.Waypoint;
import com.gtnewhorizons.navigator.api.util.Util;

import journeymap.client.model.BlockCoordIntPair;
import serverutils.client.gui.ClientClaimedChunks;
import serverutils.integration.navigator.journeymap.JMClaimsRenderer;
import serverutils.integration.navigator.xaero.XaeroClaimsRenderer;
import serverutils.lib.math.ChunkDimPos;
import serverutils.net.MessageClaimedChunksModify;
import serverutils.net.MessageJourneyMapRequest;

public class VPLayerManager extends WaypointProviderManager {
public class ClaimsLayerManager extends InteractableLayerManager {

public static final VPLayerManager INSTANCE = new VPLayerManager();
public static final ClaimsLayerManager INSTANCE = new ClaimsLayerManager();
private int oldMinBlockX = 0;
private int oldMinBlockZ = 0;
private int oldMaxBlockX = 0;
private int oldMaxBlockZ = 0;
private long lastRequest = 0;

public VPLayerManager() {
super(VPButtonManager.INSTANCE);
public ClaimsLayerManager() {
super(ClaimsButtonManager.INSTANCE);
}

@Nullable
@Override
public boolean doActionOutsideLayer(BlockCoordIntPair blockCoord) {
Minecraft mc = Minecraft.getMinecraft();
int selectionMode = MessageClaimedChunksModify.CLAIM;
int blockX = blockCoord.x;
int blockZ = blockCoord.z;
int chunkX = Utils.coordBlockToChunk(blockX);
int chunkZ = Utils.coordBlockToChunk(blockZ);
Collection<ChunkCoordIntPair> chunk = Collections.singleton(new ChunkCoordIntPair(chunkX, chunkZ));
ChunkDimPos chunkDimPos = new ChunkDimPos(chunkX, chunkZ, mc.thePlayer.dimension);
new MessageClaimedChunksModify(chunkX, chunkZ, selectionMode, chunk).sendToServer();

if (VPIntegration.OWNTEAM == null) {
new MessageJourneyMapRequest(blockX, blockX, blockZ, blockZ).sendToServer();
} else {
VPIntegration.addToOwnTeam(chunkDimPos);
}
return true;
protected LayerRenderer addLayerRenderer(InteractableLayerManager manager, SupportedMods mod) {
return switch (mod) {
case JourneyMap -> new JMClaimsRenderer(manager);
case XaeroWorldMap -> new XaeroClaimsRenderer(manager);
default -> null;
};
}

@Override
public void setActiveWaypoint(Waypoint waypoint) {}

@Override
protected boolean needsRegenerateVisibleElements(int minBlockX, int minBlockZ, int maxBlockX, int maxBlockZ) {
if (minBlockX != oldMinBlockX || minBlockZ != oldMinBlockZ
Expand All @@ -63,7 +58,7 @@ protected boolean needsRegenerateVisibleElements(int minBlockX, int minBlockZ, i
oldMinBlockZ = minBlockZ;
oldMaxBlockX = maxBlockX;
oldMaxBlockZ = maxBlockZ;
if (System.currentTimeMillis() - lastRequest >= TimeUnit.SECONDS.toMillis(10)) {
if (System.currentTimeMillis() - lastRequest >= TimeUnit.SECONDS.toMillis(2)) {
lastRequest = System.currentTimeMillis();
new MessageJourneyMapRequest(minBlockX, maxBlockX, minBlockZ, maxBlockZ).sendToServer();
}
Expand All @@ -75,15 +70,15 @@ protected boolean needsRegenerateVisibleElements(int minBlockX, int minBlockZ, i
@Override
protected List<? extends IWaypointAndLocationProvider> generateVisibleElements(int minBlockX, int minBlockZ,
int maxBlockX, int maxBlockZ) {
int minX = Utils.coordBlockToChunk(minBlockX);
int minZ = Utils.coordBlockToChunk(minBlockZ);
int maxX = Utils.coordBlockToChunk(maxBlockX);
int maxZ = Utils.coordBlockToChunk(maxBlockZ);
int minX = Util.coordBlockToChunk(minBlockX);
int minZ = Util.coordBlockToChunk(minBlockZ);
int maxX = Util.coordBlockToChunk(maxBlockX);
int maxZ = Util.coordBlockToChunk(maxBlockZ);
final EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;

ArrayList<VPClaimsLocation> locations = new ArrayList<>();
ArrayList<ClaimsLocation> locations = new ArrayList<>();

for (Map.Entry<ChunkDimPos, ClientClaimedChunks.ChunkData> entry : VPIntegration.CLAIMS.entrySet()) {
for (Map.Entry<ChunkDimPos, ClientClaimedChunks.ChunkData> entry : NavigatorIntegration.CLAIMS.entrySet()) {
ChunkDimPos key = entry.getKey();
ClientClaimedChunks.ChunkData value = entry.getValue();
boolean withinRange = key.posX >= minX && key.posX <= maxX
Expand All @@ -93,7 +88,7 @@ protected List<? extends IWaypointAndLocationProvider> generateVisibleElements(i
if (!withinRange) {
continue;
}
locations.add(new VPClaimsLocation(key, value));
locations.add(new ClaimsLocation(key, value));
}

return locations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package serverutils.integration.vp;
package serverutils.integration.navigator;

import java.util.Collection;
import java.util.Collections;
Expand All @@ -9,18 +9,18 @@

import org.lwjgl.input.Keyboard;

import com.sinthoras.visualprospecting.Utils;
import com.sinthoras.visualprospecting.VP;
import com.sinthoras.visualprospecting.integration.model.locations.IWaypointAndLocationProvider;
import com.sinthoras.visualprospecting.integration.model.waypoints.Waypoint;
import com.gtnewhorizons.navigator.api.NavigatorApi;
import com.gtnewhorizons.navigator.api.model.locations.IWaypointAndLocationProvider;
import com.gtnewhorizons.navigator.api.model.waypoints.Waypoint;
import com.gtnewhorizons.navigator.api.util.Util;

import serverutils.client.gui.ClientClaimedChunks;
import serverutils.lib.EnumTeamColor;
import serverutils.lib.math.ChunkDimPos;
import serverutils.net.MessageClaimedChunksModify;
import serverutils.net.MessageJourneyMapRequest;

public class VPClaimsLocation implements IWaypointAndLocationProvider {
public class ClaimsLocation implements IWaypointAndLocationProvider {

private final int blockX;
private final int blockZ;
Expand All @@ -31,9 +31,9 @@ public class VPClaimsLocation implements IWaypointAndLocationProvider {
private final boolean member;
private final EnumTeamColor color;

public VPClaimsLocation(ChunkDimPos chunk, ClientClaimedChunks.ChunkData data) {
blockX = Utils.coordChunkToBlock(chunk.posX);
blockZ = Utils.coordChunkToBlock(chunk.posZ);
public ClaimsLocation(ChunkDimPos chunk, ClientClaimedChunks.ChunkData data) {
blockX = Util.coordChunkToBlock(chunk.posX);
blockZ = Util.coordChunkToBlock(chunk.posZ);
dimensionId = chunk.dim;
teamName = data.team.nameComponent.getUnformattedText();
loaded = data.isLoaded();
Expand Down Expand Up @@ -93,18 +93,18 @@ public String toggleLoadHint() {
}

public String unclaimHint() {
return EnumChatFormatting.DARK_GRAY
+ I18n.format("serverutilities.jm.unclaim_hint", Keyboard.getKeyName(VP.keyAction.getKeyCode()));
return EnumChatFormatting.DARK_GRAY + I18n
.format("serverutilities.jm.unclaim_hint", Keyboard.getKeyName(NavigatorApi.ACTION_KEY.getKeyCode()));
}

public void toggleLoaded() {
// Double click loads/unloads the chunk
int selectionMode = isLoaded() ? MessageClaimedChunksModify.UNLOAD : MessageClaimedChunksModify.LOAD;
Collection<ChunkCoordIntPair> chunks = Collections
.singleton(new ChunkCoordIntPair(Utils.coordBlockToChunk(blockX), Utils.coordBlockToChunk(blockZ)));
.singleton(new ChunkCoordIntPair(Util.coordBlockToChunk(blockX), Util.coordBlockToChunk(blockZ)));
new MessageClaimedChunksModify(
Utils.coordBlockToChunk(blockX),
Utils.coordBlockToChunk(blockZ),
Util.coordBlockToChunk(blockX),
Util.coordBlockToChunk(blockZ),
selectionMode,
chunks).sendToServer();
new MessageJourneyMapRequest(blockX, blockX, blockZ, blockZ).sendToServer();
Expand All @@ -114,10 +114,10 @@ public void removeClaim() {
// Deplete/VP Action key unclaims the chunk
int selectionMode = MessageClaimedChunksModify.UNCLAIM;
Collection<ChunkCoordIntPair> chunks = Collections
.singleton(new ChunkCoordIntPair(Utils.coordBlockToChunk(blockX), Utils.coordBlockToChunk(blockZ)));
.singleton(new ChunkCoordIntPair(Util.coordBlockToChunk(blockX), Util.coordBlockToChunk(blockZ)));
new MessageClaimedChunksModify(
Utils.coordBlockToChunk(blockX),
Utils.coordBlockToChunk(blockZ),
Util.coordBlockToChunk(blockX),
Util.coordBlockToChunk(blockZ),
selectionMode,
chunks).sendToServer();
new MessageJourneyMapRequest(blockX, blockX, blockZ, blockZ).sendToServer();
Expand Down
Loading

0 comments on commit 9da77f8

Please sign in to comment.