diff --git a/.gitignore b/.gitignore index 4420102b2..107f441e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.gradle/ -libs \ No newline at end of file +libs +begradle-0.2.3-SNAPSHOT-fg3.jar diff --git a/1.09.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.09.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 651a05c52..e69de29bb 100644 --- a/1.09.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.09.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.09.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.09.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 651a05c52..e69de29bb 100644 --- a/1.09.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.09.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.09.4/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.09.4/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 651a05c52..e69de29bb 100644 --- a/1.09.4/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.09.4/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.10.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.10.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 651a05c52..e69de29bb 100644 --- a/1.10.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.10.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.10.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.10.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 651a05c52..e69de29bb 100644 --- a/1.10.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.10.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.11.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.11.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 651a05c52..e69de29bb 100644 --- a/1.11.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.11.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.11.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.11.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 651a05c52..e69de29bb 100644 --- a/1.11.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.11.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.12.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.12.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 651a05c52..e69de29bb 100644 --- a/1.12.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.12.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.12.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.12.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 651a05c52..e69de29bb 100644 --- a/1.12.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.12.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.12.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.12.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 651a05c52..e69de29bb 100644 --- a/1.12.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.12.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.13.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.13.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 651a05c52..e69de29bb 100644 --- a/1.13.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.13.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.13.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.13.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 651a05c52..e69de29bb 100644 --- a/1.13.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.13.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.13.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.13.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 651a05c52..e69de29bb 100644 --- a/1.13.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.13.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.14.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.14.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 647b05819..e69de29bb 100644 --- a/1.14.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.14.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.14.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.14.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 647b05819..e69de29bb 100644 --- a/1.14.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.14.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.14.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.14.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 647b05819..e69de29bb 100644 --- a/1.14.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.14.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.14.3/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.14.3/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 647b05819..e69de29bb 100644 --- a/1.14.3/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.14.3/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.14.4/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.14.4/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 647b05819..e69de29bb 100644 --- a/1.14.4/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.14.4/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.15.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.15.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 647b05819..e69de29bb 100644 --- a/1.15.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.15.0/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.15.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.15.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 647b05819..e69de29bb 100644 --- a/1.15.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.15.1/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/1.15.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch b/1.15.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch index 647b05819..e69de29bb 100644 --- a/1.15.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch +++ b/1.15.2/src/main/base-patches/net.minecraft.client.ClientBrandRetriever.patch @@ -1,10 +0,0 @@ ---- net/minecraft/client/ClientBrandRetriever.java -+++ net/minecraft/client/ClientBrandRetriever.java -@@ -2,6 +2,6 @@ - - public class ClientBrandRetriever { - public static String getClientModName() { -- return "vanilla"; -+ return "WorldDownloader-" + wdl.VersionConstants.getModVersion(); - } - } diff --git a/share/src/main/java/wdl/EntityUtils.java b/share/src/main/java/wdl/EntityUtils.java index 84356265d..fc88e77c7 100644 --- a/share/src/main/java/wdl/EntityUtils.java +++ b/share/src/main/java/wdl/EntityUtils.java @@ -147,15 +147,16 @@ public static int getEntityTrackDistance(TrackDistanceMode mode, @Nonnull String return -1; } case SERVER: { - int serverDistance = WDLPluginChannels - .getEntityRange(type); - - if (serverDistance < 0) { return getEntityTrackDistance(TrackDistanceMode.DEFAULT, type, entity); - } - - return serverDistance; - } +// int serverDistance = WDLPluginChannels +// .getEntityRange(type); +// +// if (serverDistance < 0) { +// return getEntityTrackDistance(TrackDistanceMode.DEFAULT, type, entity); +// } +// +// return serverDistance; + } case USER: { int value = WDL.getInstance().worldProps.getUserEntityTrackDistance(type); diff --git a/share/src/main/java/wdl/WDL.java b/share/src/main/java/wdl/WDL.java index be0c61555..d6f2735ce 100644 --- a/share/src/main/java/wdl/WDL.java +++ b/share/src/main/java/wdl/WDL.java @@ -422,9 +422,9 @@ public void startDownload() { minecraft.displayGuiScreen(null); worldClient = minecraft.world; - if (!WDLPluginChannels.canDownloadAtAll()) { - return; - } +// if (!WDLPluginChannels.canDownloadAtAll()) { +// return; +// } if (promptForInfoForSettings("startDownload", true, this::startDownload, () -> minecraft.displayGuiScreen(null))) { return; @@ -536,7 +536,7 @@ public boolean loadWorld() { loadServerProps(); } - WDLPluginChannels.onWorldLoad(); +// WDLPluginChannels.onWorldLoad(); // Is this a different server? if (networkManager != newNM) { @@ -611,11 +611,11 @@ public void onSaveComplete() { * when stopping. */ public void saveEverything() throws Exception { - if (!WDLPluginChannels.canDownloadAtAll()) { - WDLMessages.chatMessageTranslated(WDL.serverProps, - WDLMessageTypes.ERROR, "wdl.messages.generalError.forbidden"); - return; - } +// if (!WDLPluginChannels.canDownloadAtAll()) { +// WDLMessages.chatMessageTranslated(WDL.serverProps, +// WDLMessageTypes.ERROR, "wdl.messages.generalError.forbidden"); +// return; +// } WorldBackupType backupType = serverProps.getValue(MiscSettings.BACKUP_TYPE); @@ -727,7 +727,7 @@ public boolean shouldCancel() { * @return The player NBT tag. Needed for later use in the world info. */ private NBTTagCompound savePlayer(GuiWDLSaveProgress progressScreen) { - if (!WDLPluginChannels.canDownloadAtAll()) { return new NBTTagCompound(); } +// if (!WDLPluginChannels.canDownloadAtAll()) { return new NBTTagCompound(); } progressScreen.startMajorTask( I18n.format("wdl.saveProgress.playerData.title"), @@ -799,7 +799,7 @@ private NBTTagCompound savePlayer(GuiWDLSaveProgress progressScreen) { */ private void saveWorldInfo(GuiWDLSaveProgress progressScreen, NBTTagCompound playerInfoNBT) { - if (!WDLPluginChannels.canDownloadAtAll()) { return; } +// if (!WDLPluginChannels.canDownloadAtAll()) { return; } progressScreen.startMajorTask( I18n.format("wdl.saveProgress.worldMetadata.title"), @@ -881,7 +881,7 @@ private void saveWorldInfo(GuiWDLSaveProgress progressScreen, */ private void saveChunks(GuiWDLSaveProgress progressScreen) throws IllegalArgumentException, IllegalAccessException { - if (!WDLPluginChannels.canDownloadAtAll()) { return; } +// if (!WDLPluginChannels.canDownloadAtAll()) { return; } WDLMessages.chatMessageTranslated(WDL.serverProps, WDLMessageTypes.SAVING, "wdl.messages.saving.savingChunks"); @@ -911,9 +911,9 @@ private void saveChunks(GuiWDLSaveProgress progressScreen) Chunk c = chunks.get(currentChunk); if (c != null) { //Serverside restrictions check - if (!WDLPluginChannels.canSaveChunk(c)) { - continue; - } +// if (!WDLPluginChannels.canSaveChunk(c)) { +// continue; +// } progressScreen.setMinorTaskProgress(I18n.format( "wdl.saveProgress.chunk.saving", c.getPos().x, @@ -930,9 +930,9 @@ private void saveChunks(GuiWDLSaveProgress progressScreen) * Import all non-overwritten TileEntities, then save the chunk */ public void saveChunk(Chunk c) { - if (!WDLPluginChannels.canDownloadAtAll()) { return; } - - if (!WDLPluginChannels.canSaveChunk(c)) { return; } +// if (!WDLPluginChannels.canDownloadAtAll()) { return; } +// +// if (!WDLPluginChannels.canSaveChunk(c)) { return; } try { savedChunks.add(c.getPos()); @@ -1327,7 +1327,7 @@ private void addForgeDataToWorldInfo(NBTTagCompound rootWorldInfoNBT, NBTTagComp * that contain pictures. */ private void saveMapData(GuiWDLSaveProgress progressScreen) { - if (!WDLPluginChannels.canSaveMaps()) { return; } +// if (!WDLPluginChannels.canSaveMaps()) { return; } File dataDirectory = new File(saveHandler.getWorldDirectory(), "data"); diff --git a/share/src/main/java/wdl/WDLChunkLoader.java b/share/src/main/java/wdl/WDLChunkLoader.java index 37801e28a..0e2b0bdd1 100644 --- a/share/src/main/java/wdl/WDLChunkLoader.java +++ b/share/src/main/java/wdl/WDLChunkLoader.java @@ -77,9 +77,9 @@ public WDLChunkLoader(WDL wdl, File file) { protected NBTTagList getEntityList(Chunk chunk) { NBTTagList entityList = new NBTTagList(); - if (!WDLPluginChannels.canSaveEntities(chunk)) { - return entityList; - } +// if (!WDLPluginChannels.canSaveEntities(chunk)) { +// return entityList; +// } // Build a list of all entities in the chunk. List entities = new ArrayList<>(); @@ -204,9 +204,9 @@ protected static boolean shouldSaveEntity(Entity e) { protected NBTTagList getTileEntityList(Chunk chunk) { NBTTagList tileEntityList = new NBTTagList(); - if (!WDLPluginChannels.canSaveTileEntities(chunk)) { - return tileEntityList; - } +// if (!WDLPluginChannels.canSaveTileEntities(chunk)) { +// return tileEntityList; +// } Map chunkTEMap = chunk.getTileEntityMap(); Map oldTEMap = getOldTileEntities(chunk); diff --git a/share/src/main/java/wdl/WDLEvents.java b/share/src/main/java/wdl/WDLEvents.java index fffa0f388..9f5457202 100644 --- a/share/src/main/java/wdl/WDLEvents.java +++ b/share/src/main/java/wdl/WDLEvents.java @@ -64,8 +64,8 @@ import wdl.gui.GuiTurningCameraBase; import wdl.gui.GuiWDL; import wdl.gui.GuiWDLAbout; -import wdl.gui.GuiWDLChunkOverrides; -import wdl.gui.GuiWDLPermissions; +//import wdl.gui.GuiWDLChunkOverrides; +//import wdl.gui.GuiWDLPermissions; import wdl.gui.widget.WDLButton; import wdl.handler.HandlerException; import wdl.handler.block.BlockHandler; @@ -159,19 +159,19 @@ public void onChunkNoLongerNeeded(Chunk unneededChunk) { if (unneededChunk == null) { return; } - - if (WDLPluginChannels.canSaveChunk(unneededChunk)) { - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.ON_CHUNK_NO_LONGER_NEEDED, - "wdl.messages.onChunkNoLongerNeeded.saved", unneededChunk.getPos().x, unneededChunk.getPos().z); - wdl.saveChunk(unneededChunk); - } else { - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.ON_CHUNK_NO_LONGER_NEEDED, - "wdl.messages.onChunkNoLongerNeeded.didNotSave", unneededChunk.getPos().x, unneededChunk.getPos().z); - } + wdl.saveChunk(unneededChunk); +// if (WDLPluginChannels.canSaveChunk(unneededChunk)) { +// WDLMessages.chatMessageTranslated( +// WDL.serverProps, +// WDLMessageTypes.ON_CHUNK_NO_LONGER_NEEDED, +// "wdl.messages.onChunkNoLongerNeeded.saved", unneededChunk.getPos().x, unneededChunk.getPos().z); +// wdl.saveChunk(unneededChunk); +// } else { +// WDLMessages.chatMessageTranslated( +// WDL.serverProps, +// WDLMessageTypes.ON_CHUNK_NO_LONGER_NEEDED, +// "wdl.messages.onChunkNoLongerNeeded.didNotSave", unneededChunk.getPos().x, unneededChunk.getPos().z); +// } } /** @@ -226,16 +226,16 @@ public boolean onItemGuiClosed() { EntityHandler handler = EntityHandler.getHandler(ridingEntity.getClass(), windowContainer.getClass()); if (handler != null) { if (handler.checkRidingCasting(windowContainer, ridingEntity)) { - if (!WDLPluginChannels.canSaveEntities( - ridingEntity.chunkCoordX, - ridingEntity.chunkCoordZ)) { - // Run this check now that we've confirmed that we're saving - // the entity being ridden. If we're riding a pig but opening - // a chest in another chunk, that should go to the other check. - WDLMessages.chatMessageTranslated(WDL.serverProps, - WDLMessageTypes.ON_GUI_CLOSED_INFO, "wdl.messages.onGuiClosedInfo.cannotSaveEntities"); - return true; - } +// if (!WDLPluginChannels.canSaveEntities( +// ridingEntity.chunkCoordX, +// ridingEntity.chunkCoordZ)) { +// // Run this check now that we've confirmed that we're saving +// // the entity being ridden. If we're riding a pig but opening +// // a chest in another chunk, that should go to the other check. +// WDLMessages.chatMessageTranslated(WDL.serverProps, +// WDLMessageTypes.ON_GUI_CLOSED_INFO, "wdl.messages.onGuiClosedInfo.cannotSaveEntities"); +// return true; +// } try { ITextComponent msg = handler.copyDataCasting(windowContainer, ridingEntity, true); @@ -255,11 +255,11 @@ public boolean onItemGuiClosed() { // If the last thing clicked was an ENTITY Entity entity = wdl.lastEntity; if (entity != null) { - if (!WDLPluginChannels.canSaveEntities(entity.chunkCoordX, entity.chunkCoordZ)) { - WDLMessages.chatMessageTranslated(WDL.serverProps, - WDLMessageTypes.ON_GUI_CLOSED_INFO, "wdl.messages.onGuiClosedInfo.cannotSaveEntities"); - return true; - } +// if (!WDLPluginChannels.canSaveEntities(entity.chunkCoordX, entity.chunkCoordZ)) { +// WDLMessages.chatMessageTranslated(WDL.serverProps, +// WDLMessageTypes.ON_GUI_CLOSED_INFO, "wdl.messages.onGuiClosedInfo.cannotSaveEntities"); +// return true; +// } EntityHandler handler = EntityHandler.getHandler(entity.getClass(), windowContainer.getClass()); if (handler != null) { @@ -297,12 +297,12 @@ public boolean onItemGuiClosed() { } //Permissions check. - if (!WDLPluginChannels.canSaveContainers(te.getPos().getX() >> 4, te - .getPos().getZ() >> 4)) { - WDLMessages.chatMessageTranslated(WDL.serverProps, - WDLMessageTypes.ON_GUI_CLOSED_INFO, "wdl.messages.onGuiClosedInfo.cannotSaveTileEntities"); - return true; - } +// if (!WDLPluginChannels.canSaveContainers(te.getPos().getX() >> 4, te +// .getPos().getZ() >> 4)) { +// WDLMessages.chatMessageTranslated(WDL.serverProps, +// WDLMessageTypes.ON_GUI_CLOSED_INFO, "wdl.messages.onGuiClosedInfo.cannotSaveTileEntities"); +// return true; +// } BlockHandler handler = BlockHandler.getHandler(te.getClass(), wdl.windowContainer.getClass()); @@ -345,10 +345,10 @@ public boolean onItemGuiClosed() { public void onBlockEvent(BlockPos pos, Block block, int data1, int data2) { if (!WDL.downloading) { return; } - if (!WDLPluginChannels.canSaveTileEntities(pos.getX() >> 4, - pos.getZ() >> 4)) { - return; - } +// if (!WDLPluginChannels.canSaveTileEntities(pos.getX() >> 4, +// pos.getZ() >> 4)) { +// return; +// } TileEntity blockEntity = wdl.worldClient.getTileEntity(pos); if (blockEntity == null) { @@ -375,9 +375,9 @@ public void onBlockEvent(BlockPos pos, Block block, int data1, int data2) { public void onMapDataLoaded(int mapID, @Nonnull MapData mapData) { if (!WDL.downloading) { return; } - if (!WDLPluginChannels.canSaveMaps()) { - return; - } +// if (!WDLPluginChannels.canSaveMaps()) { +// return; +// } // Assume that the current dimension is the right one EntityPlayerSP player = wdl.player; @@ -394,10 +394,10 @@ public void onMapDataLoaded(int mapID, @Nonnull MapData mapData) { * Must be called whenever a plugin channel message / custom payload packet * is received. */ - public void onPluginChannelPacket(NetHandlerPlayClient sender, - String channel, byte[] bytes) { - WDLPluginChannels.onPluginChannelPacket(sender, channel, bytes); - } +// public void onPluginChannelPacket(NetHandlerPlayClient sender, +// String channel, byte[] bytes) { +// WDLPluginChannels.onPluginChannelPacket(sender, channel, bytes); +// } /** * Must be called when an entity is about to be removed from the world. @@ -405,9 +405,10 @@ public void onPluginChannelPacket(NetHandlerPlayClient sender, public void onRemoveEntityFromWorld(Entity entity) { // If the entity is being removed and it's outside the default tracking // range, go ahead and remember it until the chunk is saved. - if (WDL.downloading && entity != null - && WDLPluginChannels.canSaveEntities(entity.chunkCoordX, - entity.chunkCoordZ)) { +// if (WDL.downloading && entity != null +// && WDLPluginChannels.canSaveEntities(entity.chunkCoordX, +// entity.chunkCoordZ)) + if (WDL.downloading && entity != null){ if (!EntityUtils.isEntityEnabled(entity)) { WDLMessages.chatMessageTranslated( WDL.serverProps, @@ -685,60 +686,60 @@ public void onNHPCHandleMaps(NetHandlerPlayClient sender, @Override public void onNHPCHandleCustomPayload(NetHandlerPlayClient sender, SPacketCustomPayload packet) { - try { - if (!Minecraft.getInstance().isOnExecutionThread()) { - return; - } - if (ENABLE_PROFILER) PROFILER.startSection("wdl.onPluginMessage"); - - if (ENABLE_PROFILER) PROFILER.startSection("Parse"); - String channel = packet.getChannelName().toString(); // 1.13: ResourceLocation -> String; otherwise no-op - ByteBuf buf = packet.getBufferData(); - int refCnt = buf.refCnt(); - if (refCnt <= 0) { - // The buffer has already been released. Just break out now. - // This happens with e.g. the MC|TrList packet (villager trade list), - // which closes the buffer after reading it. - if (ENABLE_PROFILER) PROFILER.endSection(); // "Parse" - if (ENABLE_PROFILER) PROFILER.endSection(); // "wdl.onPluginMessage" - return; - } - - // Something else may have already read the payload; return to the start - buf.markReaderIndex(); - buf.readerIndex(0); - byte[] payload = new byte[buf.readableBytes()]; - buf.readBytes(payload); - // OK, now that we've done our reading, return to where it was before - // (which could be the end, or other code might not have read it yet) - buf.resetReaderIndex(); - // buf will be released by the packet handler, eventually. - // It definitely is NOT our responsibility to release it, as - // doing so would probably break other code outside of wdl. - // Perhaps we might want to call retain once at the start of this method - // and then release at the end, but that feels excessive (since there - // _shouldn't_ be multiple threads at play at this point, and if there - // were we'd be in trouble anyways). - - if (ENABLE_PROFILER) PROFILER.endSection(); // "Parse" - - if (ENABLE_PROFILER) PROFILER.startSection("Core"); - wdlEvents.onPluginChannelPacket(sender, channel, payload); - if (ENABLE_PROFILER) PROFILER.endSection(); // "Core" - - for (ModInfo info : WDLApi - .getImplementingExtensions(IPluginChannelListener.class)) { - if (ENABLE_PROFILER) PROFILER.startSection(info.id); - info.mod.onPluginChannelPacket(wdl.worldClient, channel, - payload); - if (ENABLE_PROFILER) PROFILER.endSection(); // info.id - } - - if (ENABLE_PROFILER) PROFILER.endSection(); // "wdl.onPluginMessage" - } catch (Throwable e) { - wdl.crashed(e, - "WDL mod: exception in onNHPCHandleCustomPayload event"); - } +// try { +// if (!Minecraft.getInstance().isOnExecutionThread()) { +// return; +// } +// if (ENABLE_PROFILER) PROFILER.startSection("wdl.onPluginMessage"); +// +// if (ENABLE_PROFILER) PROFILER.startSection("Parse"); +// String channel = packet.getChannelName().toString(); // 1.13: ResourceLocation -> String; otherwise no-op +// ByteBuf buf = packet.getBufferData(); +// int refCnt = buf.refCnt(); +// if (refCnt <= 0) { +// // The buffer has already been released. Just break out now. +// // This happens with e.g. the MC|TrList packet (villager trade list), +// // which closes the buffer after reading it. +// if (ENABLE_PROFILER) PROFILER.endSection(); // "Parse" +// if (ENABLE_PROFILER) PROFILER.endSection(); // "wdl.onPluginMessage" +// return; +// } +// +// // Something else may have already read the payload; return to the start +// buf.markReaderIndex(); +// buf.readerIndex(0); +// byte[] payload = new byte[buf.readableBytes()]; +// buf.readBytes(payload); +// // OK, now that we've done our reading, return to where it was before +// // (which could be the end, or other code might not have read it yet) +// buf.resetReaderIndex(); +// // buf will be released by the packet handler, eventually. +// // It definitely is NOT our responsibility to release it, as +// // doing so would probably break other code outside of wdl. +// // Perhaps we might want to call retain once at the start of this method +// // and then release at the end, but that feels excessive (since there +// // _shouldn't_ be multiple threads at play at this point, and if there +// // were we'd be in trouble anyways). +// +// if (ENABLE_PROFILER) PROFILER.endSection(); // "Parse" +// +// if (ENABLE_PROFILER) PROFILER.startSection("Core"); +// wdlEvents.onPluginChannelPacket(sender, channel, payload); +// if (ENABLE_PROFILER) PROFILER.endSection(); // "Core" +// +// for (ModInfo info : WDLApi +// .getImplementingExtensions(IPluginChannelListener.class)) { +// if (ENABLE_PROFILER) PROFILER.startSection(info.id); +// info.mod.onPluginChannelPacket(wdl.worldClient, channel, +// payload); +// if (ENABLE_PROFILER) PROFILER.endSection(); // info.id +// } +// +// if (ENABLE_PROFILER) PROFILER.endSection(); // "wdl.onPluginMessage" +// } catch (Throwable e) { +// wdl.crashed(e, +// "WDL mod: exception in onNHPCHandleCustomPayload event"); +// } } @Override public void onNHPCHandleBlockAction(NetHandlerPlayClient sender, @@ -826,19 +827,21 @@ public void beforeDraw() { displayString = I18n .format("wdl.gui.ingameMenu.downloadStatus.singlePlayer"); enabled = false; - } else if (!WDLPluginChannels.canDownloadAtAll()) { - if (WDLPluginChannels.canRequestPermissions()) { - // Allow requesting permissions. - displayString = I18n - .format("wdl.gui.ingameMenu.downloadStatus.request"); - enabled = true; - } else { - // Out of date plugin :/ - displayString = I18n - .format("wdl.gui.ingameMenu.downloadStatus.disabled"); - enabled = false; - } - } else if (WDL.saving) { + } +// else if (!WDLPluginChannels.canDownloadAtAll()) { +// if (WDLPluginChannels.canRequestPermissions()) { +// // Allow requesting permissions. +// displayString = I18n +// .format("wdl.gui.ingameMenu.downloadStatus.request"); +// enabled = true; +// } else { +// // Out of date plugin :/ +// displayString = I18n +// .format("wdl.gui.ingameMenu.downloadStatus.disabled"); +// enabled = false; +// } +// } + else if (WDL.saving) { // Normally not accessible; only happens as a major fallback... displayString = I18n .format("wdl.gui.ingameMenu.downloadStatus.saving"); @@ -866,23 +869,23 @@ public void performAction() { wdl.stopDownload(); setEnabled(false); // Disable to stop double-clicks } else { - if (!WDLPluginChannels.canDownloadAtAll()) { - // If they don't have any permissions, let the player - // request some. - if (WDLPluginChannels.canRequestPermissions()) { - wdl.minecraft.displayGuiScreen(new GuiWDLPermissions(menu, wdl)); - } else { - // Should never happen - } - } else if (WDLPluginChannels.hasChunkOverrides() - && !WDLPluginChannels.canDownloadInGeneral()) { - // Handle the "only has chunk overrides" state - notify - // the player of limited areas. - wdl.minecraft.displayGuiScreen(new GuiWDLChunkOverrides(menu, wdl)); - } else { +// if (!WDLPluginChannels.canDownloadAtAll()) { +// // If they don't have any permissions, let the player +// // request some. +// if (WDLPluginChannels.canRequestPermissions()) { +// wdl.minecraft.displayGuiScreen(new GuiWDLPermissions(menu, wdl)); +// } else { +// // Should never happen +// } +// } else if (WDLPluginChannels.hasChunkOverrides() +// && !WDLPluginChannels.canDownloadInGeneral()) { +// // Handle the "only has chunk overrides" state - notify +// // the player of limited areas. +// wdl.minecraft.displayGuiScreen(new GuiWDLChunkOverrides(menu, wdl)); +// } else { wdl.startDownload(); setEnabled(false); // Disable to stop double-clicks - } + //} } } } diff --git a/share/src/main/java/wdl/WDLPluginChannels.java b/share/src/main/java/wdl/WDLPluginChannels.java deleted file mode 100644 index 42c4bc176..000000000 --- a/share/src/main/java/wdl/WDLPluginChannels.java +++ /dev/null @@ -1,1037 +0,0 @@ -/* - * This file is part of World Downloader: A mod to make backups of your multiplayer worlds. - * https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/2520465-world-downloader-mod-create-backups-of-your-builds - * - * Copyright (c) 2014 nairol, cubic72 - * Copyright (c) 2017-2020 Pokechu22, julialy - * - * This project is licensed under the MMPLv2. The full text of the MMPL can be - * found in LICENSE.md, or online at https://github.com/iopleke/MMPLv2/blob/master/LICENSE.md - * For information about this the MMPLv2, see https://stopmodreposts.org/ - * - * Do not redistribute (in modified or unmodified form) without prior permission. - */ -package wdl; - -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.WeakHashMap; - -import javax.annotation.CheckForSigned; -import javax.annotation.Nullable; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteArrayDataOutput; -import com.google.common.io.ByteStreams; -import com.google.gson.JsonObject; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.network.NetHandlerPlayClient; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.play.client.CPacketCustomPayload; -import net.minecraft.world.chunk.Chunk; -import wdl.versioned.VersionedFunctions; -import wdl.versioned.VersionedFunctions.ChannelName; - -/** - * World Downloader permission system implemented with Plugin Channels. - * - * This system is used to configure the mod, and disable certain features, - * at a server's decision. I've made this system because there already were - * other (more esoteric) methods of finding the mod, based off of forge and - * lightloader handshakes. I think that a system like this, where there are - * degrees of control, is better than one where the player is - * indiscriminately kicked. For instance, this system allows for permission - * requests, which would be hard to do with another mechanism. - * - * This system makes use of plugin channels (hence the class name). If you - * haven't read their info, - * they're a vanilla minecraft packet intended for mods. But they do - * need each channel to be REGISTERed before use, so the server does know - * when the mod is installed. As such, I actually did a second step and - * instead send a second packet when the data is ready to be received by the - * client, since mid-download permission changes can be problematic. - * - * Theoretically, these could be implemented with chat-based codes or even - * MOTD-based codes. However, I really do not like that system, as - * it is really rigid. So I chose this one, which is also highly expandable. - * - * This system is also used to fetch a few things from willing servers, mainly - * entity track distances so that things can be saved correctly. - * - * And yes, this is the fabled "backdoor" / "back door"; I don't like that term - * but people will call it that. I think it's the best possible system out - * of the available options (and doing nothing wouldn't work - as I said, - * there are weird ways of finding mods). - * - * Packet - * documentation is on wiki.vg, if you're interested. - */ -public class WDLPluginChannels { - private static final Logger LOGGER = LogManager.getLogger(); - /** - * Packets that have been received. - */ - private static HashSet receivedPackets = new HashSet<>(); - - /** - * Whether functions that the server is not aware of can be used. - * (Packet #0) - */ - private static boolean canUseFunctionsUnknownToServer = true; - /** - * Whether all players are allowed to download the world in general. - * If false, they aren't allowed, regardless of the other values below. - */ - private static boolean canDownloadInGeneral = true; - /** - * The distance from a player that WDL can save chunks. - * - * This is only used when {@link #canCacheChunks} is false. - */ - private static int saveRadius = -1; - /** - * Whether a player can cache chunks as they move. In essence, this means - * that if the value is true, the player can download the entire map while - * moving about, but if false, the player will only save the nearby chunks - * when they stop download. - */ - private static boolean canCacheChunks = true; - /** - * Whether or not a player can save entities in the map. - */ - private static boolean canSaveEntities = true; - /** - * Whether or not a player can save TileEntities in general. - *
- * Chests and other containers also require {@link #canSaveContainers}. - */ - private static boolean canSaveTileEntities = true; - /** - * Whether a player can save containers that require opening to save their - * contents, such as chests. For this value to have meaning, the value of - * {@link #canSaveTileEntities} must also be true. - */ - private static boolean canSaveContainers = true; - /** - * Map of entity ranges. - * - * Key is the entity string, int is the range. - */ - private static Map entityRanges = - new HashMap<>(); - - /** - * Whether players can request permissions. - * - * With the default implementation, this is always sent as - * true. However, this needs to be sent for it to be useful - - * if the plugin does NOT send it, it does not support permission requests. - */ - private static boolean canRequestPermissions = false; - - /** - * Message to display when requesting. If empty, nothing - * is displayed. - */ - private static String requestMessage = ""; - - /** - * Chunk overrides. Any chunk within a range is allowed to be downloaded in. - */ - private static Map> chunkOverrides = new HashMap<>(); - - /** - * Active permission requests. - */ - private static Map requests = new HashMap<>(); - - /** - * Permission request fields that take boolean parameters. - */ - public static final List BOOLEAN_REQUEST_FIELDS = Arrays.asList( - "downloadInGeneral", "cacheChunks", "saveEntities", - "saveTileEntities", "saveContainers", "getEntityRanges"); - /** - * Permission request fields that take integer parameters. - */ - public static final List INTEGER_REQUEST_FIELDS = Arrays.asList( - "saveRadius"); - - /** - * List of new chunk override requests. - */ - private static List chunkOverrideRequests = new ArrayList<>(); - - /** - * Checks whether players can use functions unknown to the server. - */ - public static boolean canUseFunctionsUnknownToServer() { - if (receivedPackets.contains(0)) { - return canUseFunctionsUnknownToServer; - } else { - return true; - } - } - - /** - * Checks whether the player should be able to start download at all: Either - * {@link #canDownloadInGeneral()} is true, or the player has some chunks - * overridden. - */ - public static boolean canDownloadAtAll() { - if (hasChunkOverrides()) { - return true; - } else { - return canDownloadInGeneral(); - } - } - - /** - * Checks whether players are allowed to download in general (outside of - * overridden chunks). - */ - public static boolean canDownloadInGeneral() { - if (receivedPackets.contains(1)) { - return canDownloadInGeneral; - } else { - return canUseFunctionsUnknownToServer(); - } - } - - /** - * Checks if a chunk is within the saveRadius - * (and chunk caching is disabled). - */ - public static boolean canSaveChunk(Chunk chunk) { - if (isChunkOverridden(chunk)) { - return true; - } - - if (!canDownloadInGeneral()) { - return false; - } - - if (receivedPackets.contains(1)) { - if (!canCacheChunks && saveRadius >= 0) { - int distanceX = chunk.getPos().x - WDL.getInstance().player.chunkCoordX; - int distanceZ = chunk.getPos().z - WDL.getInstance().player.chunkCoordZ; - - if (Math.abs(distanceX) > saveRadius || - Math.abs(distanceZ) > saveRadius) { - return false; - } - } - - return true; - } else { - return canUseFunctionsUnknownToServer(); - } - } - - /** - * Checks whether entities are allowed to be saved. - */ - public static boolean canSaveEntities() { - if (!canDownloadInGeneral()) { - return false; - } - - if (receivedPackets.contains(1)) { - return canSaveEntities; - } else { - return canUseFunctionsUnknownToServer(); - } - } - - /** - * Checks whether entities are allowed to be saved in the given chunk. - */ - public static boolean canSaveEntities(Chunk chunk) { - if (isChunkOverridden(chunk)) { - return true; - } - - return canSaveEntities(); - } - - /** - * Checks whether entities are allowed to be saved in the given chunk. - */ - public static boolean canSaveEntities(int chunkX, int chunkZ) { - if (isChunkOverridden(chunkX, chunkZ)) { - return true; - } - - return canSaveEntities(); - } - - /** - * Checks whether a player can save tile entities. - */ - public static boolean canSaveTileEntities() { - if (!canDownloadInGeneral()) { - return false; - } - - if (receivedPackets.contains(1)) { - return canSaveTileEntities; - } else { - return canUseFunctionsUnknownToServer(); - } - } - - /** - * Checks whether a player can save tile entities in the given chunk. - */ - public static boolean canSaveTileEntities(Chunk chunk) { - if (isChunkOverridden(chunk)) { - return true; - } - - return canSaveTileEntities(); - } - - /** - * Checks whether a player can save tile entities in the given chunk. - */ - public static boolean canSaveTileEntities(int chunkX, int chunkZ) { - if (isChunkOverridden(chunkX, chunkZ)) { - return true; - } - - return canSaveTileEntities(); - } - - /** - * Checks whether containers (such as chests) can be saved. - */ - public static boolean canSaveContainers() { - if (!canDownloadInGeneral()) { - return false; - } - if (!canSaveTileEntities()) { - return false; - } - if (receivedPackets.contains(1)) { - return canSaveContainers; - } else { - return canUseFunctionsUnknownToServer(); - } - } - - /** - * Checks whether containers (such as chests) can be saved. - */ - public static boolean canSaveContainers(Chunk chunk) { - if (isChunkOverridden(chunk)) { - return true; - } - - return canSaveContainers(); - } - - /** - * Checks whether containers (such as chests) can be saved. - */ - public static boolean canSaveContainers(int chunkX, int chunkZ) { - if (isChunkOverridden(chunkX, chunkZ)) { - return true; - } - - return canSaveContainers(); - } - - /** - * Checks whether maps (the map item, not the world itself) can be saved. - */ - public static boolean canSaveMaps() { - if (!canDownloadInGeneral()) { - return false; - } - //TODO: Better value than 'canSaveTileEntities'. - if (receivedPackets.contains(1)) { - return canSaveTileEntities; - } else { - return canUseFunctionsUnknownToServer(); - } - } - - /** - * Gets the server-set range for the given entity. - * - * @param entity The entity's name (via {@link EntityUtils#getEntityType}). - * @return The entity's range, or -1 if no data was recieved. - */ - @CheckForSigned - public static int getEntityRange(String entity) { - if (!canSaveEntities(null)) { - return -1; - } - if (receivedPackets.contains(2)) { - if (entityRanges.containsKey(entity)) { - return entityRanges.get(entity); - } else { - return -1; - } - } else { - return -1; - } - } - - /** - * Gets the save radius. - * - * Note that using {@link #canSaveChunk(Chunk)} is generally better - * as it handles most of the radius logic. - * - * @return {@link #saveRadius}. - */ - public static int getSaveRadius() { - return saveRadius; - } - - /** - * Gets whether chunks can be cached. - * - * Note that using {@link #canSaveChunk(Chunk)} is generally better - * as it handles most of the radius logic. - * - * @return {@link #canCacheChunks}. - */ - public static boolean canCacheChunks() { - return canCacheChunks; - } - - /** - * Checks if the server-set entity range is configured. - */ - public static boolean hasServerEntityRange() { - return receivedPackets.contains(2) && entityRanges.size() > 0; - } - - public static Map getEntityRanges() { - return new HashMap<>(entityRanges); - } - - /** - * Gets whether permissions are available. - */ - public static boolean hasPermissions() { - return receivedPackets != null && !receivedPackets.isEmpty(); - } - - /** - * Gets whether permissions are available. - */ - public static boolean canRequestPermissions() { - return receivedPackets.contains(3) && canRequestPermissions; - } - - /** - * Gets the request message. - * @return The {@link #requestMessage}. - */ - public static String getRequestMessage() { - if (receivedPackets.contains(3)) { - return requestMessage; - } else { - return null; - } - } - - /** - * Is the given chunk part of a chunk override? - */ - public static boolean isChunkOverridden(Chunk chunk) { - if (chunk == null) { - return false; - } - - return isChunkOverridden(chunk.getPos().x, chunk.getPos().z); - } - /** - * Is the given chunk location part of a chunk override? - */ - public static boolean isChunkOverridden(int x, int z) { - for (Multimap map : chunkOverrides.values()) { - for (ChunkRange range : map.values()) { - if (x >= range.x1 && - x <= range.x2 && - z >= range.z1 && - z <= range.z2) { - return true; - } - } - } - - return false; - } - - /** - * Are there any chunk overrides present? - */ - public static boolean hasChunkOverrides() { - if (!receivedPackets.contains(4)) { - // XXX It's possible that some implementations may not send - // packet 4, but still send ranges. If so, that may lead to issues. - // But right now, I'm not checking that. - return false; - } - if (chunkOverrides == null || chunkOverrides.isEmpty()) { - return false; - } - for (Multimap m : chunkOverrides.values()) { - if (!m.isEmpty()) { - return true; - } - } - return false; - } - - /** - * Gets an immutable copy of the {@link #chunkOverrides} map. - */ - public static Map> getChunkOverrides() { - Map> returned = new - HashMap<>(); - - for (Map.Entry> e : chunkOverrides - .entrySet()) { - // Create a copy of the given map. - Multimap map = ImmutableMultimap.copyOf(e.getValue()); - - returned.put(e.getKey(), map); - } - - return ImmutableMap.copyOf(returned); - } - - /** - * Create a new permission request. - * @param key The key for the request. - * @param value The wanted value. - */ - public static void addRequest(String key, String value) { - if (!isValidRequest(key, value)) { - return; - } - - requests.put(key, value); - } - - /** - * Gets an immutable copy of the current requests. - */ - public static Map getRequests() { - return ImmutableMap.copyOf(requests); - } - - /** - * Is the given set of values valid for the given request? - * - * Handles checking if the key exists and if the value is valid. - * - * @param key The key for the request. - * @param value The wanted value. - */ - public static boolean isValidRequest(String key, String value) { - if (key == null || value == null) { - return false; - } - - if (BOOLEAN_REQUEST_FIELDS.contains(key)) { - return value.equals("true") || value.equals("false"); - } else if (INTEGER_REQUEST_FIELDS.contains(key)) { - try { - Integer.parseInt(value); - return true; - } catch (NumberFormatException e) { - return false; - } - } - - return false; - } - - /** - * Gets the current list of chunk override requests. - */ - public static List getChunkOverrideRequests() { - return ImmutableList.copyOf(chunkOverrideRequests); - } - /** - * Adds a new chunk override request for the given range. - */ - public static void addChunkOverrideRequest(ChunkRange range) { - chunkOverrideRequests.add(range); - } - - /** - * Sends the current requests to the server. - */ - public static void sendRequests() { - if (requests.isEmpty() && chunkOverrideRequests.isEmpty()) { - return; - } - - ByteArrayDataOutput output = ByteStreams.newDataOutput(); - - output.writeUTF("REQUEST REASON WILL GO HERE"); //TODO - output.writeInt(requests.size()); - for (Map.Entry request : requests.entrySet()) { - output.writeUTF(request.getKey()); - output.writeUTF(request.getValue()); - } - - output.writeInt(chunkOverrideRequests.size()); - for (ChunkRange range : chunkOverrideRequests) { - range.writeToOutput(output); - } - - NetHandlerPlayClient nhpc = Minecraft.getInstance().getConnection(); - final String channel; - if (isRegistered(nhpc, REQUEST_CHANNEL_NEW)) { - channel = REQUEST_CHANNEL_NEW; - } else if (isRegistered(nhpc, REQUEST_CHANNEL_OLD)) { - channel = REQUEST_CHANNEL_OLD; - } else { - throw new RuntimeException("No request channel has been registered :("); // XXX - } - CPacketCustomPayload requestPacket = VersionedFunctions.makePluginMessagePacket(channel, output.toByteArray()); - nhpc.sendPacket(requestPacket); - } - - /** - * Channels that the server has registered/unregistered. - * - * A map from a NetworkManager instance to a String, so that data is kept per-server. - * - * Unfortunately, clearing in onWorldLoad -> newServer doesn't work right, as that happens - * after (possibly far after) plugin messages are handled. - * - * XXX Equally unfortunately, the server never bothers to tell the client what channels it will send on... - */ - private static final Map> REGISTERED_CHANNELS = new WeakHashMap<>(); - - /** Channels for the init packet */ - private static final String INIT_CHANNEL_OLD = "WDL|INIT", INIT_CHANNEL_NEW = "wdl:init"; - /** Channels for the control packet */ - private static final String CONTROL_CHANNEL_OLD = "WDL|CONTROL", CONTROL_CHANNEL_NEW = "wdl:control"; - /** Channels for the request packet */ - private static final String REQUEST_CHANNEL_OLD = "WDL|REQUEST", REQUEST_CHANNEL_NEW = "wdl:request"; - - /** All known channels */ - private static final List<@ChannelName String> WDL_CHANNELS = VersionedFunctions.removeInvalidChannelNames( - INIT_CHANNEL_NEW, CONTROL_CHANNEL_NEW, REQUEST_CHANNEL_NEW, - INIT_CHANNEL_OLD, CONTROL_CHANNEL_OLD, REQUEST_CHANNEL_OLD - ); - - /** - * Gets the current set of registered channels for this server. - */ - private static Set<@ChannelName String> getRegisteredChannels(NetHandlerPlayClient nhpc) { - return REGISTERED_CHANNELS.computeIfAbsent( - nhpc.getNetworkManager(), - key -> new HashSet<>()); - } - - /** - * Checks if the given channel is registered on this server. - */ - private static boolean isRegistered(NetHandlerPlayClient nhpc, String channelName) { - return getRegisteredChannels(nhpc).contains(channelName); - } - - private static final String UPDATE_NOTE = "For 1.13 compatibility, please update your plugin as channel names have changed."; - - /** - * The state for {@link #sendInitPacket(String)} if it was called when no channels were registered. - */ - @Nullable - private static String deferredInitState = null; - - public static void sendInitPacket(String state) { - sendInitPacket(Minecraft.getInstance().getConnection(), state); - } - private static void sendInitPacket(NetHandlerPlayClient nhpc, String state) { - assert nhpc != null : "Unexpected null nhpc: state=" + state + ", chans=" + REGISTERED_CHANNELS; - - final String channel; - if (isRegistered(nhpc, INIT_CHANNEL_NEW)) { - channel = INIT_CHANNEL_NEW; - } else if (isRegistered(nhpc, INIT_CHANNEL_OLD)) { - channel = INIT_CHANNEL_OLD; - } else { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("[WDL] Deferring init packet for state {} (existing deferred state is {} -- should be null), as no registered channel: {}", state, deferredInitState, REGISTERED_CHANNELS); - } - deferredInitState = state; - return; - } - - LOGGER.debug("[WDL] Sending init packet for state {} on {}", state, channel); - - JsonObject object = new JsonObject(); - object.addProperty("X-RTFM", "https://wiki.vg/Plugin_channels/World_downloader"); - object.addProperty("X-UpdateNote", UPDATE_NOTE); - object.addProperty("Version", VersionConstants.getModVersion()); - object.addProperty("State", state); - byte[] bytes = object.toString().getBytes(StandardCharsets.UTF_8); - - CPacketCustomPayload initPacket = VersionedFunctions.makePluginMessagePacket(channel, bytes); - - nhpc.sendPacket(initPacket); - - deferredInitState = null; - } - - /** - * Event that is called when the world is loaded. - * Sets the default values, and then asks the server to give the - * correct ones. - */ - static void onWorldLoad() { - Minecraft minecraft = Minecraft.getInstance(); - - receivedPackets = new HashSet<>(); - requests = new HashMap<>(); - chunkOverrideRequests = new ArrayList<>(); - - canUseFunctionsUnknownToServer = true; - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, "wdl.messages.permissions.init"); - - // Register the WDL messages. - byte[] registerBytes = String.join("\0", WDL_CHANNELS).getBytes(); - - CPacketCustomPayload registerPacket = VersionedFunctions.makePluginMessagePacket(VersionedFunctions.getRegisterChannel(), registerBytes); - minecraft.getConnection().sendPacket(registerPacket); - - // Send the init message. - sendInitPacket("Init?"); - } - - static void onPluginChannelPacket(NetHandlerPlayClient sender, @ChannelName String channel, byte[] bytes) { - if ("REGISTER".equals(channel) || "minecraft:register".equals(channel)) { - registerChannels(sender, bytes); - } else if ("UNREGISTER".equals(channel) || "minecraft:unregister".equals(channel)) { - unregisterChannels(sender, bytes); - } else if (CONTROL_CHANNEL_NEW.equals(channel) || CONTROL_CHANNEL_OLD.equals(channel)) { - handleControlPacket(bytes); - } - } - - private static void registerChannels(NetHandlerPlayClient nhpc, byte[] bytes) { - String existing = LOGGER.isDebugEnabled() ? REGISTERED_CHANNELS.toString() : null; - - String str = new String(bytes, StandardCharsets.UTF_8); - - List channels = Arrays.asList(str.split("\0")); - channels.stream() - .filter(WDL_CHANNELS::contains) - .forEach(getRegisteredChannels(nhpc)::add); - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("[WDL] REGISTER: " + str + "/" + channels + ": " + existing + " => " + REGISTERED_CHANNELS); - } - - if (deferredInitState != null) { - LOGGER.debug("[WDL] REGISTER: Trying to resolve deferred {}", deferredInitState); - sendInitPacket(nhpc, deferredInitState); - } - } - - private static void unregisterChannels(NetHandlerPlayClient nhpc, byte[] bytes) { - String existing = LOGGER.isDebugEnabled() ? REGISTERED_CHANNELS.toString() : null; - - String str = new String(bytes, StandardCharsets.UTF_8); - List channels = Arrays.asList(str.split("\0")); - channels.stream() - .filter(WDL_CHANNELS::contains) - .forEach(getRegisteredChannels(nhpc)::remove); - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("[WDL] UNREGISTER: " + str + "/" + channels + ": " + existing + " => " + REGISTERED_CHANNELS); - } - } - - private static void handleControlPacket(byte[] bytes) { - try { - ByteArrayDataInput input = ByteStreams.newDataInput(bytes); - - int section = input.readInt(); - - receivedPackets.add(section); - - switch (section) { - case 0: - canUseFunctionsUnknownToServer = input.readBoolean(); - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet0", canUseFunctionsUnknownToServer); - - break; - case 1: - canDownloadInGeneral = input.readBoolean(); - saveRadius = input.readInt(); - canCacheChunks = input.readBoolean(); - canSaveEntities = input.readBoolean(); - canSaveTileEntities = input.readBoolean(); - canSaveContainers = input.readBoolean(); - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet1", canDownloadInGeneral, - saveRadius, canCacheChunks, - canSaveEntities, canSaveTileEntities, canSaveContainers); - - //Cancel a download if it is occurring. - if (!canDownloadInGeneral) { - if (WDL.downloading) { - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.ERROR, "wdl.messages.generalError.forbidden"); - WDL.getInstance().cancelDownload(); - } - } - break; - case 2: - entityRanges.clear(); - - int count = input.readInt(); - for (int i = 0; i < count; i++) { - String name = input.readUTF(); - int range = input.readInt(); - - entityRanges.put(name, range); - } - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet2", entityRanges.size()); - break; - case 3: - canRequestPermissions = input.readBoolean(); - requestMessage = input.readUTF(); - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet3", canRequestPermissions, - requestMessage.length(), Integer.toHexString(requestMessage.hashCode())); - // Don't include the exact message because it's too long and would be spammy. - break; - case 4: - chunkOverrides.clear(); - - int numRangeGroups = input.readInt(); - int totalRanges = 0; - for (int i = 0; i < numRangeGroups; i++) { - String groupName = input.readUTF(); - int groupSize = input.readInt(); - - Multimap ranges = HashMultimap - . create(); - - for (int j = 0; j < groupSize; j++) { - ChunkRange range = ChunkRange.readFromInput(input); - ranges.put(range.tag, range); - } - - chunkOverrides.put(groupName, ranges); - - totalRanges += groupSize; - } - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet4", numRangeGroups, totalRanges); - break; - case 5: - - String groupToEdit = input.readUTF(); - boolean replaceGroups = input.readBoolean(); - int numNewGroups = input.readInt(); - - Multimap newRanges = HashMultimap - . create(); - if (!replaceGroups) { - newRanges.putAll(chunkOverrides.get(groupToEdit)); - } - - for (int i = 0; i < numNewGroups; i++) { - ChunkRange range = ChunkRange.readFromInput(input); - - newRanges.put(range.tag, range); - } - chunkOverrides.put(groupToEdit, newRanges); - - if (replaceGroups) { - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet5.set", numNewGroups, groupToEdit); - } else { - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet5.added", numNewGroups, groupToEdit); - } - break; - case 6: - String groupToChangeTagsFor = input.readUTF(); - int numTags = input.readInt(); - String[] tags = new String[numTags]; - - for (int i = 0; i < numTags; i++) { - tags[i] = input.readUTF(); - } - - int oldCount = 0; - for (String tag : tags) { - oldCount += chunkOverrides.get(groupToChangeTagsFor) - .get(tag).size(); - chunkOverrides.get(groupToChangeTagsFor).removeAll(tag); - } - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet6", oldCount, groupToChangeTagsFor, Arrays.toString(tags)); - break; - case 7: - String groupToSetTagFor = input.readUTF(); - String tag = input.readUTF(); - int numNewRanges = input.readInt(); - - Collection oldRanges = chunkOverrides.get( - groupToSetTagFor).removeAll(tag); - int numRangesRemoved = oldRanges.size(); - - for (int i = 0; i < numNewRanges; i++) { - //TODO: Ensure that the range has the right tag. - - chunkOverrides.get(groupToSetTagFor).put(tag, - ChunkRange.readFromInput(input)); - } - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet7", numRangesRemoved, groupToSetTagFor, tag, numNewRanges); - break; - default: - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, "wdl.messages.permissions.unknownPacket", section); - dump(bytes); - } - } catch (Exception ex) { - WDLMessages.chatMessageTranslated(WDL.serverProps, WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.badPacket", ex); - } - } - - private static void dump(byte[] bytes) { - StringBuilder messageBuilder = new StringBuilder(); - for (byte b : bytes) { - messageBuilder.append(b).append(' '); - } - - LOGGER.info(messageBuilder.toString()); - } - - /** - * A range of chunks. - */ - public static class ChunkRange { - public ChunkRange(String tag, int x1, int z1, int x2, int z2) { - this.tag = tag; - - // Ensure that the order is correct - if (x1 > x2) { - this.x1 = x2; - this.x2 = x1; - } else { - this.x1 = x1; - this.x2 = x2; - } - if (z1 > z2) { - this.z1 = z2; - this.z2 = z1; - } else { - this.z1 = z1; - this.z2 = z2; - } - } - - /** - * The tag of this chunk range. - */ - public final String tag; - /** - * Range of coordinates. x1 will never be higher than x2, as will z1 - * with z2. - */ - public final int x1, z1, x2, z2; - - /** - * Reads and creates a new ChunkRange from the given - * {@link ByteArrayDataInput}. - */ - public static ChunkRange readFromInput(ByteArrayDataInput input) { - String tag = input.readUTF(); - int x1 = input.readInt(); - int z1 = input.readInt(); - int x2 = input.readInt(); - int z2 = input.readInt(); - - return new ChunkRange(tag, x1, z1, x2, z2); - } - - /** - * Writes this ChunkRange to the given {@link ByteArrayDataOutput}. - * - * Note that I expect most serverside implementations will ignore the - * tag, but it still is included for clarity. The value in it can be - * anything so long as it is not null - an empty string will do. - */ - public void writeToOutput(ByteArrayDataOutput output) { - output.writeUTF(this.tag); - - output.writeInt(this.x1); - output.writeInt(this.z1); - output.writeInt(this.x2); - output.writeInt(this.z2); - } - - @Override - public String toString() { - return "ChunkRange [tag=" + tag + ", x1=" + x1 + ", z1=" + z1 - + ", x2=" + x2 + ", z2=" + z2 + "]"; - } - } -} diff --git a/share/src/main/java/wdl/api/APIImpl.java b/share/src/main/java/wdl/api/APIImpl.java index b06a662f7..149c45347 100644 --- a/share/src/main/java/wdl/api/APIImpl.java +++ b/share/src/main/java/wdl/api/APIImpl.java @@ -34,7 +34,7 @@ import wdl.VersionConstants; import wdl.WDL; import wdl.WDLMessages; -import wdl.WDLPluginChannels; +//import wdl.WDLPluginChannels; import wdl.api.WDLApi.ModInfo; import wdl.config.Setting; import wdl.config.settings.MiscSettings.ExtensionEnabledSetting; @@ -51,15 +51,15 @@ private APIImpl() { } // Internal use only @Override public void saveTileEntity(BlockPos pos, TileEntity te) { - if (!WDLPluginChannels.canSaveTileEntities(pos.getX() >> 4, - pos.getZ() >> 4)) { - LOGGER.warn("API attempted to call saveTileEntity when " + - "saving TileEntities is not allowed! Pos: " + pos + - ", te: " + te + ". StackTrace: "); - logStackTrace(); - - return; - } +// if (!WDLPluginChannels.canSaveTileEntities(pos.getX() >> 4, +// pos.getZ() >> 4)) { +// LOGGER.warn("API attempted to call saveTileEntity when " + +// "saving TileEntities is not allowed! Pos: " + pos + +// ", te: " + te + ". StackTrace: "); +// logStackTrace(); +// +// return; +// } WDL.getInstance().saveTileEntity(pos, te); } diff --git a/share/src/main/java/wdl/config/settings/EntitySettings.java b/share/src/main/java/wdl/config/settings/EntitySettings.java index b04e1ace2..3119e440a 100644 --- a/share/src/main/java/wdl/config/settings/EntitySettings.java +++ b/share/src/main/java/wdl/config/settings/EntitySettings.java @@ -23,7 +23,7 @@ import net.minecraft.util.IStringSerializable; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentTranslation; -import wdl.WDLPluginChannels; +//import wdl.WDLPluginChannels; import wdl.config.CyclableSetting; import wdl.config.IConfiguration; @@ -38,7 +38,7 @@ public final class EntitySettings { new TrackDistanceModeSetting("Entity.TrackDistanceMode", "wdl.gui.entities.trackDistanceMode"); @VisibleForTesting - static BooleanSupplier hasServerEntityRange = WDLPluginChannels::hasServerEntityRange; +// static BooleanSupplier hasServerEntityRange = WDLPluginChannels::hasServerEntityRange; public enum TrackDistanceMode implements IStringSerializable { DEFAULT("default"), @@ -88,21 +88,23 @@ public String getConfigurationKey() { @Override public TrackDistanceMode getDefault(IConfiguration context) { - if (hasServerEntityRange.getAsBoolean()) { - return TrackDistanceMode.SERVER; - } else { - return TrackDistanceMode.DEFAULT; - } +// if (hasServerEntityRange.getAsBoolean()) { +// return TrackDistanceMode.SERVER; +// } else { +// return TrackDistanceMode.DEFAULT; +// } + return TrackDistanceMode.DEFAULT; } @Override public TrackDistanceMode cycle(TrackDistanceMode value) { if (value == TrackDistanceMode.DEFAULT) { - if (hasServerEntityRange.getAsBoolean()) { - return TrackDistanceMode.SERVER; - } else { - return TrackDistanceMode.USER; - } +// if (hasServerEntityRange.getAsBoolean()) { +// return TrackDistanceMode.SERVER; +// } else { +// return TrackDistanceMode.USER; +// } + return TrackDistanceMode.USER; } else if (value == TrackDistanceMode.SERVER) { return TrackDistanceMode.USER; } else { diff --git a/share/src/main/java/wdl/gui/GuiWDL.java b/share/src/main/java/wdl/gui/GuiWDL.java index 6fc39418d..97b6568c8 100644 --- a/share/src/main/java/wdl/gui/GuiWDL.java +++ b/share/src/main/java/wdl/gui/GuiWDL.java @@ -23,7 +23,7 @@ import net.minecraft.client.resources.I18n; import net.minecraft.util.text.TextComponentTranslation; import wdl.WDL; -import wdl.WDLPluginChannels; +//import wdl.WDLPluginChannels; import wdl.config.IConfiguration; import wdl.config.settings.MiscSettings; import wdl.gui.widget.ButtonDisplayGui; @@ -67,9 +67,9 @@ public ButtonEntry(String key, BiFunction openFunc, b this.button = this.addButton(new ButtonDisplayGui(0, 0, 200, 20, I18n.format("wdl.gui.wdl." + key + ".name"), () -> openFunc.apply(GuiWDL.this, GuiWDL.this.wdl)), -100, 0); - if (needsPerms) { - button.setEnabled(WDLPluginChannels.canDownloadAtAll()); - } +// if (needsPerms) { +// button.setEnabled(WDLPluginChannels.canDownloadAtAll()); +// } this.tooltip = I18n.format("wdl.gui.wdl." + key + ".description"); } @@ -94,7 +94,7 @@ public void drawEntry(int x, int y, int width, int height, int mouseX, int mouse entries.add(new ButtonEntry("backupOptions", GuiWDLBackup::new, true)); entries.add(new ButtonEntry("messageOptions", GuiWDLMessages::new, false)); entries.add(new ButtonEntry("savedChunks", GuiSavedChunks::new, true)); - entries.add(new ButtonEntry("permissionsInfo", GuiWDLPermissions::new, false)); +// entries.add(new ButtonEntry("permissionsInfo", GuiWDLPermissions::new, false)); entries.add(new ButtonEntry("about", GuiWDLAbout::new, false)); if (WDLUpdateChecker.hasNewVersion()) { // Put at start diff --git a/share/src/main/java/wdl/gui/GuiWDLChunkOverrides.java b/share/src/main/java/wdl/gui/GuiWDLChunkOverrides.java deleted file mode 100644 index f6a378aeb..000000000 --- a/share/src/main/java/wdl/gui/GuiWDLChunkOverrides.java +++ /dev/null @@ -1,409 +0,0 @@ -/* - * This file is part of World Downloader: A mod to make backups of your multiplayer worlds. - * https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/2520465-world-downloader-mod-create-backups-of-your-builds - * - * Copyright (c) 2014 nairol, cubic72 - * Copyright (c) 2017-2019 Pokechu22, julialy - * - * This project is licensed under the MMPLv2. The full text of the MMPL can be - * found in LICENSE.md, or online at https://github.com/iopleke/MMPLv2/blob/master/LICENSE.md - * For information about this the MMPLv2, see https://stopmodreposts.org/ - * - * Do not redistribute (in modified or unmodified form) without prior permission. - */ -package wdl.gui; - -import javax.annotation.Nullable; - -import com.google.common.collect.Multimap; - -import net.minecraft.client.audio.SimpleSound; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.resources.I18n; -import net.minecraft.init.SoundEvents; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.text.TextComponentString; -import wdl.WDL; -import wdl.WDLPluginChannels; -import wdl.WDLPluginChannels.ChunkRange; -import wdl.gui.widget.ButtonDisplayGui; -import wdl.gui.widget.WDLButton; -import wdl.gui.widget.WDLScreen; -import wdl.versioned.VersionedFunctions; - -/** - * A GUI that lists and allows requesting chunk overrides. - * - * Also, expect a possible minimap integration in the future. - */ -public class GuiWDLChunkOverrides extends WDLScreen { - private static final int TOP_MARGIN = 61, BOTTOM_MARGIN = 32; - - /** - * Location of the button overlay textures. - */ - private static final ResourceLocation WIDGET_TEXTURES = new ResourceLocation( - "wdl:textures/permission_widgets.png"); - - private static enum Mode { - PANNING(0, 128), - REQUESTING(16, 128), - ERASING(32, 128), - MOVING(48, 128); - - private Mode(int overlayU, int overlayV) { - this.overlayU = overlayU; - this.overlayV = overlayV; - } - - /** - * Coordinates for the U and V of the texture for the button associated - * with this mode. - */ - public final int overlayU, overlayV; - } - - /** - * Parent GUI screen; displayed when this GUI is closed. - */ - @Nullable - private final GuiScreen parent; - private final WDL wdl; - - private WDLButton startDownloadButton; - - /** - * The current position. - */ - private float scrollX, scrollZ; - /** - * How large each chunk is on-screen. - */ - private static final int SCALE = 8; - - /** - * Current mode for the GUI - */ - private Mode mode = Mode.PANNING; - - /** - * Is the request end coordinate being set (true) or start coordinate being - * set (false)? - */ - private boolean partiallyRequested; - /** - * Coordinates of the active request. - */ - private int requestStartX, requestStartZ, requestEndX, requestEndZ; - /** - * The position of the mouse on the last tick, for dragging. - */ - private int lastTickX, lastTickY; - - public GuiWDLChunkOverrides(@Nullable GuiScreen parent, WDL wdl) { - super(new TextComponentString("Chunk overrides")); // XXX Untranslated - this.parent = parent; - this.wdl = wdl; - - if (wdl.player != null) { - this.scrollX = wdl.player.chunkCoordX; - this.scrollZ = wdl.player.chunkCoordZ; - } - } - - @Override - public void init() { - this.addButton(new RequestModeButton(width / 2 - 155, 18, Mode.PANNING) { - public @Override void performAction() { - GuiWDLChunkOverrides.this.mode = Mode.PANNING; - } - }); - this.addButton(new RequestModeButton(width / 2 - 130, 18, Mode.REQUESTING) { - public @Override void performAction() { - GuiWDLChunkOverrides.this.mode = Mode.REQUESTING; - partiallyRequested = false; - } - }); - this.addButton(new RequestModeButton(width / 2 - 105, 18, Mode.ERASING) { - { setEnabled(false); } - public @Override void performAction() { } - }); - this.addButton(new RequestModeButton(width / 2 - 80, 18, Mode.MOVING) { - { setEnabled(false); } - public @Override void performAction() { } - }); - - this.addButton(new WDLButton(width / 2 - 80, 18, 80, 20, - "Send request") { - public @Override void performAction() { - WDLPluginChannels.sendRequests(); - } - }); - - this.startDownloadButton = this.addButton(new WDLButton(width / 2 + 5, 18, 150, 20, - "Start download in these ranges") { - public @Override void performAction() { - if (!WDLPluginChannels.canDownloadAtAll()) { - setEnabled(false); - return; - } - wdl.startDownload(); - } - }); - startDownloadButton.setEnabled(WDLPluginChannels.canDownloadAtAll()); - - this.addButton(new ButtonDisplayGui(width / 2 - 100, height - 29, - 200, 20, this.parent)); - - this.addButton(new ButtonDisplayGui(this.width / 2 - 155, 39, 100, 20, - I18n.format("wdl.gui.permissions.current"), () -> new GuiWDLPermissions(this.parent, this.wdl))); - this.addButton(new ButtonDisplayGui(this.width / 2 - 50, 39, 100, 20, - I18n.format("wdl.gui.permissions.request"), () -> new GuiWDLPermissionRequest(this.parent, this.wdl))); - this.addButton(new WDLButton(this.width / 2 + 55, 39, 100, 20, - I18n.format("wdl.gui.permissions.overrides")) { - public @Override void performAction() { - // Would open this GUI; do nothing. - }; - }); - } - - @Override - public void mouseDown(int mouseX, int mouseY) { - if (mouseY > TOP_MARGIN && mouseY < height - BOTTOM_MARGIN) { - switch (mode) { - case PANNING: - lastTickX = mouseX; - lastTickY = mouseY; - break; - case REQUESTING: - if (partiallyRequested) { - requestEndX = displayXToChunkX(mouseX); - requestEndZ = displayZToChunkZ(mouseY); - - ChunkRange requestRange = new ChunkRange("", requestStartX, - requestStartZ, requestEndX, requestEndZ); - WDLPluginChannels.addChunkOverrideRequest(requestRange); - - partiallyRequested = false; - } else { - requestStartX = displayXToChunkX(mouseX); - requestStartZ = displayZToChunkZ(mouseY); - - partiallyRequested = true; - } - - minecraft.getSoundHandler().play(SimpleSound.master( - SoundEvents.UI_BUTTON_CLICK, 1.0F)); - break; - case ERASING: - // TODO - minecraft.getSoundHandler().play(SimpleSound.master( - SoundEvents.BLOCK_DISPENSER_FAIL, 1.0F)); - break; - case MOVING: - // TODO - minecraft.getSoundHandler().play(SimpleSound.master( - SoundEvents.BLOCK_DISPENSER_FAIL, 1.0F)); - break; - } - } - } - - @Override - public void mouseDragged(int mouseX, int mouseY) { - int deltaX = lastTickX - mouseX; - int deltaY = lastTickY - mouseY; - - lastTickX = mouseX; - lastTickY = mouseY; - - if (mode == Mode.PANNING) { - scrollX += deltaX / (float)SCALE; - scrollZ += deltaY / (float)SCALE; - } - } - - @Override - public void render(int mouseX, int mouseY, float partialTicks) { - VersionedFunctions.drawDarkBackground(0, 0, height, width); - - // Draw the current request range. - if (mode == Mode.REQUESTING) { - int x1 = (partiallyRequested ? requestStartX : displayXToChunkX(mouseX)); - int z1 = (partiallyRequested ? requestStartZ : displayZToChunkZ(mouseY)); - int x2 = displayXToChunkX(mouseX); - int z2 = displayZToChunkZ(mouseY); - - // TODO: Maybe cache this range in some way rather than creating a new one each frame - ChunkRange requestRange = new ChunkRange("", x1, z1, x2, z2); - - // Fancy sin alpha changing by time. - int alpha = 127 + (int)(Math.sin(System.currentTimeMillis() * Math.PI / 5000) * 64); - drawRange(requestRange, 0xffffff, alpha); - } - - // Draw current ranges - for (Multimap group : WDLPluginChannels.getChunkOverrides().values()) { - for (ChunkRange range : group.values()) { - drawRange(range, RNG_SEED, 0xFF); - } - } - for (ChunkRange range : WDLPluginChannels.getChunkOverrideRequests()) { - // Fancy sin alpha changing by time. - int alpha = 127 + (int)(Math.sin(System.currentTimeMillis() * Math.PI / 5000) * 64); - drawRange(range, 0x808080, alpha); - } - - // Player position. - int playerPosX = (int)(((wdl.player.posX / 16.0D) - scrollX) * SCALE + (width / 2)); - int playerPosZ = (int)(((wdl.player.posZ / 16.0D) - scrollZ) * SCALE + (height / 2)); - - hLine(playerPosX - 3, playerPosX + 3, playerPosZ, 0xFFFFFFFF); - // Vertical is 1px taller because it seems to be needed to make it proportional - vLine(playerPosX, playerPosZ - 4, playerPosZ + 4, 0xFFFFFFFF); - - // Draw the main borders now so that ranges are hidden behind it. - Utils.drawBorder(TOP_MARGIN, BOTTOM_MARGIN, 0, 0, height, width); - - super.render(mouseX, mouseY, partialTicks); - - this.drawCenteredString(this.font, "\u00A7c\u00A7lThis is a work in progress.", - this.width / 2, this.height / 2, 0xFFFFFF); - } - - /** - * Default color for a chunk range with tag. Xor'd with the hashcode.
- * Preview:            - */ - private static final int RNG_SEED = 0xBBDFC; - - /** - * Draws the given range at the proper position on screen. - * - * @param range The range to draw. - * @param seed The default color for a tagless range. (See {@link #RNG_SEED}) - * @param alpha The transparency. 0xFF: Fully solid, 0x00: Fully transparent - */ - private void drawRange(ChunkRange range, int seed, int alpha) { - int color = (range.tag.hashCode() ^ seed) & 0x00FFFFFF; - - int x1 = chunkXToDisplayX(range.x1); - int z1 = chunkZToDisplayZ(range.z1); - int x2 = chunkXToDisplayX(range.x2) + SCALE - 1; - int z2 = chunkZToDisplayZ(range.z2) + SCALE - 1; - - fill(x1, z1, x2, z2, color + (alpha << 24)); - - int colorDark = darken(color); - - vLine(x1, z1, z2, colorDark + (alpha << 24)); - vLine(x2, z1, z2, colorDark + (alpha << 24)); - hLine(x1, x2, z1, colorDark + (alpha << 24)); - hLine(x1, x2, z2, colorDark + (alpha << 24)); - } - - /** - * Converts a chunk x coordinate to a display x coordinate, taking - * into account the value of {@link scrollX}. - * - * @param chunkX The chunk's x coordinate. - * @return The display position. - */ - private int chunkXToDisplayX(int chunkX) { - return (int)((chunkX - scrollX) * SCALE + (width / 2)); - } - - /** - * Converts a chunk z coordinate to a display z coordinate, taking - * into account the value of {@link scrollZ}. - * - * @param chunkZ The chunk's z coordinate. - * @return The display position. - */ - private int chunkZToDisplayZ(int chunkZ) { - return (int)((chunkZ - scrollZ) * SCALE + (height / 2)); - } - - /** - * Converts a display x coordinate to a chunk x coordinate, taking - * into account the value of {@link scrollX}. - * - * @param displayX The display x coordinate. - * @return The chunk position. - */ - private int displayXToChunkX(int displayX) { - return MathHelper.floor((displayX - (float)(width / 2)) / SCALE + scrollX); - } - - /** - * Converts a display z coordinate to a chunk z coordinate, taking - * into account the value of {@link scrollZ}. - * - * @param displayZ The display z coordinate. - * @return The chunk position. - */ - private int displayZToChunkZ(int displayZ) { - return MathHelper.floor((displayZ - (float)(height / 2)) / SCALE + scrollZ); - } - - /** - * Halves the brightness of the given color. - */ - private int darken(int color) { - int r = (color >> 16) & 0xFF; - int g = (color >> 8) & 0xFF; - int b = color & 0xFF; - - r /= 2; - g /= 2; - b /= 2; - - return (r << 16) + (g << 8) + b; - } - - /** - * Button for a mode that displays the icon for the given mode. - */ - private abstract class RequestModeButton extends WDLButton { - /** - * The mode for this button. - */ - public final Mode mode; - - /** - * Constructor - * @param buttonId - * @param x - * @param y - * @param mode - */ - public RequestModeButton(int x, int y, Mode mode) { - super(x, y, 20, 20, ""); - this.mode = mode; - } - - @Override - public void beforeDraw() { - if (GuiWDLChunkOverrides.this.mode == this.mode) { - // Mode is currently selected - draw a green outline. - fill(this.x - 2, this.y - 2, - this.x + width + 2, this.y + height + 2, - 0xFF007F00); - } - } - - @Override - public void afterDraw() { - // Reset the color, which gets set somewhere (probably when drawing text) - GlStateManager.color3f(1.0f, 1.0f, 1.0f); - minecraft.getTextureManager().bindTexture(WIDGET_TEXTURES); - - this.blit(this.x + 2, this.y + 2, - mode.overlayU, mode.overlayV, 16, 16); - } - } -} diff --git a/share/src/main/java/wdl/gui/GuiWDLEntityRangePresets.java b/share/src/main/java/wdl/gui/GuiWDLEntityRangePresets.java index 16a879c3f..250ea9f47 100644 --- a/share/src/main/java/wdl/gui/GuiWDLEntityRangePresets.java +++ b/share/src/main/java/wdl/gui/GuiWDLEntityRangePresets.java @@ -25,7 +25,7 @@ import wdl.EntityUtils; import wdl.EntityUtils.SpigotEntityType; import wdl.WDL; -import wdl.WDLPluginChannels; +//import wdl.WDLPluginChannels; import wdl.config.IConfiguration; import wdl.gui.widget.ButtonDisplayGui; import wdl.gui.widget.WDLButton; @@ -42,7 +42,7 @@ public class GuiWDLEntityRangePresets extends WDLScreen implements GuiYesNoCallb private WDLButton vanillaButton; private WDLButton spigotButton; - private WDLButton serverButton; +// private WDLButton serverButton; private WDLButton cancelButton; private static final int ID_VANILLA = 0, ID_SPIGOT = 1, ID_SERVER = 2; @@ -68,14 +68,14 @@ public void init() { I18n.format("wdl.gui.rangePresets.spigot"), makeYesNoGui("wdl.gui.rangePresets.spigot.warning", ID_SPIGOT))); y += 22; - this.serverButton = this.addButton(new ButtonDisplayGui( - this.width / 2 - 100, y, 200, 20, - I18n.format("wdl.gui.rangePresets.server"), - makeYesNoGui("wdl.gui.rangePresets.spigot.warning", ID_SERVER))); - - serverButton.setEnabled(WDLPluginChannels.hasServerEntityRange()); +// this.serverButton = this.addButton(new ButtonDisplayGui( +// this.width / 2 - 100, y, 200, 20, +// I18n.format("wdl.gui.rangePresets.server"), +// makeYesNoGui("wdl.gui.rangePresets.spigot.warning", ID_SERVER))); +// +// serverButton.setEnabled(WDLPluginChannels.hasServerEntityRange()); - y += 28; +// y += 28; this.cancelButton = this.addButton(new ButtonDisplayGui( this.width / 2 - 100, this.height - 29, 200, 20, @@ -99,15 +99,17 @@ public void render(int mouseX, int mouseY, float partialTicks) { infoText = I18n.format("wdl.gui.rangePresets.vanilla.description"); } else if (spigotButton.isHovered()) { infoText = I18n.format("wdl.gui.rangePresets.spigot.description"); - } else if (serverButton.isHovered()) { - infoText = I18n.format("wdl.gui.rangePresets.server.description") + "\n\n"; - - if (serverButton.isEnabled()) { - infoText += I18n.format("wdl.gui.rangePresets.server.installed"); - } else { - infoText += I18n.format("wdl.gui.rangePresets.server.notInstalled"); - } - } else if (cancelButton.isHovered()) { + } +// else if (serverButton.isHovered()) { +// infoText = I18n.format("wdl.gui.rangePresets.server.description") + "\n\n"; +// +// if (serverButton.isEnabled()) { +// infoText += I18n.format("wdl.gui.rangePresets.server.installed"); +// } else { +// infoText += I18n.format("wdl.gui.rangePresets.server.notInstalled"); +// } +// } + else if (cancelButton.isHovered()) { infoText = I18n.format("wdl.gui.rangePresets.cancel.description"); } @@ -137,8 +139,9 @@ public void confirmResult(boolean result, int id) { } } else if (id == ID_SERVER) { for (String entity : entities) { - config.setUserEntityTrackDistance(entity, - WDLPluginChannels.getEntityRange(entity)); +// config.setUserEntityTrackDistance(entity, +// WDLPluginChannels.getEntityRange(entity)); + config.setUserEntityTrackDistance(entity, EntityUtils.STANDARD_VANILLA_MANAGER.getTrackDistance(entity, null)); } } } diff --git a/share/src/main/java/wdl/gui/GuiWDLPermissionRequest.java b/share/src/main/java/wdl/gui/GuiWDLPermissionRequest.java deleted file mode 100644 index 8515056bc..000000000 --- a/share/src/main/java/wdl/gui/GuiWDLPermissionRequest.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * This file is part of World Downloader: A mod to make backups of your multiplayer worlds. - * https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/2520465-world-downloader-mod-create-backups-of-your-builds - * - * Copyright (c) 2014 nairol, cubic72 - * Copyright (c) 2017-2019 Pokechu22, julialy - * - * This project is licensed under the MMPLv2. The full text of the MMPL can be - * found in LICENSE.md, or online at https://github.com/iopleke/MMPLv2/blob/master/LICENSE.md - * For information about this the MMPLv2, see https://stopmodreposts.org/ - * - * Do not redistribute (in modified or unmodified form) without prior permission. - */ -package wdl.gui; - -import java.util.Map; - -import javax.annotation.Nullable; - -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.GuiTextField; -import net.minecraft.client.resources.I18n; -import net.minecraft.util.text.TextComponentString; -import wdl.WDL; -import wdl.WDLPluginChannels; -import wdl.gui.widget.ButtonDisplayGui; -import wdl.gui.widget.TextList; -import wdl.gui.widget.WDLButton; -import wdl.gui.widget.WDLScreen; - -/** - * GUI for requesting permissions. Again, this is a work in progress. - */ -public class GuiWDLPermissionRequest extends WDLScreen { - private static final int TOP_MARGIN = 61, BOTTOM_MARGIN = 32; - - private TextList list; - /** - * Parent GUI screen; displayed when this GUI is closed. - */ - @Nullable - private final GuiScreen parent; - private final WDL wdl; - /** - * Field in which the wanted request is entered. - */ - private GuiTextField requestField; - /** - * Button for submitting the request. - */ - private WDLButton submitButton; - - public GuiWDLPermissionRequest(@Nullable GuiScreen parent, WDL wdl) { - super(new TextComponentString("Permission request")); // XXX untranslated - this.parent = parent; - this.wdl = wdl; - } - - @Override - public void init() { - this.list = this.addList(new TextList(minecraft, width, height, TOP_MARGIN, BOTTOM_MARGIN)); - - list.addLine("\u00A7c\u00A7lThis is a work in progress."); - list.addLine("You can request permissions in this GUI, although " + - "it currently requires manually specifying the names."); - list.addBlankLine(); - list.addLine("Boolean fields: " + WDLPluginChannels.BOOLEAN_REQUEST_FIELDS); - list.addLine("Integer fields: " + WDLPluginChannels.INTEGER_REQUEST_FIELDS); - list.addBlankLine(); - - - //Get the existing requests. - for (Map.Entry request : WDLPluginChannels - .getRequests().entrySet()) { - list.addLine("Requesting '" + request.getKey() + "' to be '" - + request.getValue() + "'."); - } - - this.requestField = this.addTextField(new GuiTextField(0, font, - width / 2 - 155, 18, 150, 20)); - - this.submitButton = this.addButton(new WDLButton( - width / 2 + 5, 18, 150, 20, - "Submit request") { - public @Override void performAction() { - WDLPluginChannels.sendRequests(); - setMessage("Submitted!"); - } - }); - this.submitButton.setEnabled(!(WDLPluginChannels.getRequests().isEmpty())); - - this.addButton(new ButtonDisplayGui(width / 2 - 100, height - 29, - 200, 20, this.parent)); - - this.addButton(new ButtonDisplayGui(this.width / 2 - 155, 39, 100, 20, - I18n.format("wdl.gui.permissions.current"), () -> new GuiWDLPermissions(this.parent, this.wdl))); - this.addButton(new WDLButton(this.width / 2 - 50, 39, 100, 20, - I18n.format("wdl.gui.permissions.request")) { - public @Override void performAction() { - // Would open this GUI; do nothing. - } - }); - this.addButton(new ButtonDisplayGui(this.width / 2 + 55, 39, 100, 20, - I18n.format("wdl.gui.permissions.overrides"), () -> new GuiWDLChunkOverrides(this.parent, this.wdl))); - } - - @Override - public void charTyped(char keyChar) { - if (requestField.isFocused()) { - String request = requestField.getText(); - if (isValidRequest(request) && keyChar == '\n') { - String[] requestData = request.split("=", 2); - String key = requestData[0]; - String value = requestData[1]; - - WDLPluginChannels.addRequest(key, value); - list.addLine("Requesting '" + key + "' to be '" - + value + "'."); - submitButton.setEnabled(true); - - requestField.setText(""); - } - } - } - - @Override - public void anyKeyPressed() { - if (requestField.isFocused()) { - String request = requestField.getText(); - requestField.setTextColor(isValidRequest(request) ? 0x40E040 : 0xE04040); - } - } - - private boolean isValidRequest(String request) { - if (request.contains("=")) { - String[] requestData = request.split("=", 2); - if (requestData.length == 2) { - String key = requestData[0]; - String value = requestData[1]; - - return WDLPluginChannels.isValidRequest(key, value); - } - } - return false; - } -} diff --git a/share/src/main/java/wdl/gui/GuiWDLPermissions.java b/share/src/main/java/wdl/gui/GuiWDLPermissions.java deleted file mode 100644 index b6c9e01a0..000000000 --- a/share/src/main/java/wdl/gui/GuiWDLPermissions.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * This file is part of World Downloader: A mod to make backups of your multiplayer worlds. - * https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/2520465-world-downloader-mod-create-backups-of-your-builds - * - * Copyright (c) 2014 nairol, cubic72 - * Copyright (c) 2017-2019 Pokechu22, julialy - * - * This project is licensed under the MMPLv2. The full text of the MMPL can be - * found in LICENSE.md, or online at https://github.com/iopleke/MMPLv2/blob/master/LICENSE.md - * For information about this the MMPLv2, see https://stopmodreposts.org/ - * - * Do not redistribute (in modified or unmodified form) without prior permission. - */ -package wdl.gui; - -import javax.annotation.Nullable; - -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.resources.I18n; -import net.minecraft.util.text.TextComponentString; -import wdl.WDL; -import wdl.WDLPluginChannels; -import wdl.gui.widget.ButtonDisplayGui; -import wdl.gui.widget.TextList; -import wdl.gui.widget.WDLButton; -import wdl.gui.widget.WDLScreen; - -/** - * GUI that shows the current permissions for the user. - */ -public class GuiWDLPermissions extends WDLScreen { - /** - * Margins for the top and the bottom of the list. - */ - private static final int TOP_MARGIN = 61, BOTTOM_MARGIN = 32; - - /** - * Ticks (20ths of a second) until this UI needs to refresh. - * - * If -1, don't refresh. - */ - private int refreshTicks = -1; - - @Nullable - private final GuiScreen parent; - private final WDL wdl; - - private TextList list; - - /** - * Creates a new GUI with the given parent. - * - * @param parent - */ - public GuiWDLPermissions(@Nullable GuiScreen parent, WDL wdl) { - super(new TextComponentString("Permission info")); // XXX untranslated - this.parent = parent; - this.wdl = wdl; - } - - @Override - public void init() { - this.addButton(new ButtonDisplayGui(width / 2 - 100, height - 29, - 200, 20, this.parent)); - - this.addButton(new WDLButton(this.width / 2 - 155, 39, 100, 20, - I18n.format("wdl.gui.permissions.current")) { - public @Override void performAction() { - // Would open this GUI; do nothing. - }; - }); - if (WDLPluginChannels.canRequestPermissions()) { - this.addButton(new ButtonDisplayGui(this.width / 2 - 50, 39, 100, 20, - I18n.format("wdl.gui.permissions.request"), () -> new GuiWDLPermissionRequest(this.parent, this.wdl))); - this.addButton(new ButtonDisplayGui(this.width / 2 + 55, 39, 100, 20, - I18n.format("wdl.gui.permissions.overrides"), () -> new GuiWDLChunkOverrides(this.parent, this.wdl))); - } - - this.addButton(new WDLButton((this.width / 2) + 5, 18, 150, 20, - "Reload permissions") { - public @Override void performAction() { - // Send the init packet. - WDLPluginChannels.sendInitPacket("Refresh?"); - - setEnabled(false); - setMessage("Refreshing..."); - - refreshTicks = 50; // 2.5 seconds - } - }); - - this.list = this.addList(new TextList(minecraft, width, height, TOP_MARGIN, BOTTOM_MARGIN)); - - list.addLine("\u00A7c\u00A7lThis is a work in progress."); - - if (!WDLPluginChannels.hasPermissions()) { - return; - } - - list.addBlankLine(); - if (!WDLPluginChannels.canRequestPermissions()) { - list.addLine("\u00A7cThe serverside permission plugin is out of date " + - "and does support permission requests. Please go ask a " + - "server administrator to update the plugin."); - list.addBlankLine(); - } - - if (WDLPluginChannels.getRequestMessage() != null) { - list.addLine("Note from the server moderators: "); - list.addLine(WDLPluginChannels.getRequestMessage()); - list.addBlankLine(); - } - - list.addLine("These are your current permissions:"); - // TODO: I'd like to return the description lines here, but can't yet. - // Of course, I'd need to put in some better lines than before. - // Maybe also skip unsent permissions? - list.addLine("Can download: " - + WDLPluginChannels.canDownloadInGeneral()); - list.addLine("Can save chunks as you move: " + WDLPluginChannels.canCacheChunks()); - if (!WDLPluginChannels.canCacheChunks() && WDLPluginChannels.canDownloadInGeneral()) { - list.addLine("Nearby chunk save radius: " + WDLPluginChannels.getSaveRadius()); - } - list.addLine("Can save entities: " - + WDLPluginChannels.canSaveEntities()); - list.addLine("Can save tile entities: " - + WDLPluginChannels.canSaveTileEntities()); - list.addLine("Can save containers: " - + WDLPluginChannels.canSaveContainers()); - list.addLine("Received entity ranges: " - + WDLPluginChannels.hasServerEntityRange() + " (" - + WDLPluginChannels.getEntityRanges().size() + " total)"); - } - - @Override - public void tick() { - if (refreshTicks > 0) { - refreshTicks--; - } else if (refreshTicks == 0) { - init(); - refreshTicks = -1; - } - super.tick(); - } - - @Override - public void removed() { - wdl.saveProps(); - } - - @Override - public void render(int mouseX, int mouseY, float partialTicks) { - super.render(mouseX, mouseY, partialTicks); - - if (!WDLPluginChannels.hasPermissions()) { - this.drawCenteredString(this.font, - "No permissions received; defaulting to everything enabled.", - this.width / 2, (this.height - 32 - 23) / 2 + 23 - - font.FONT_HEIGHT / 2, 0xFFFFFF); - } - } -} diff --git a/share/src/main/resources/assets/wdl/lang/zh_CN.lang b/share/src/main/resources/assets/wdl/lang/zh_cn.lang similarity index 100% rename from share/src/main/resources/assets/wdl/lang/zh_CN.lang rename to share/src/main/resources/assets/wdl/lang/zh_cn.lang diff --git a/share/src/test/java/wdl/config/settings/EntitySettingsTest.java b/share/src/test/java/wdl/config/settings/EntitySettingsTest.java deleted file mode 100644 index c5c095df1..000000000 --- a/share/src/test/java/wdl/config/settings/EntitySettingsTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of World Downloader: A mod to make backups of your multiplayer worlds. - * https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/2520465-world-downloader-mod-create-backups-of-your-builds - * - * Copyright (c) 2014 nairol, cubic72 - * Copyright (c) 2018 Pokechu22, julialy - * - * This project is licensed under the MMPLv2. The full text of the MMPL can be - * found in LICENSE.md, or online at https://github.com/iopleke/MMPLv2/blob/master/LICENSE.md - * For information about this the MMPLv2, see https://stopmodreposts.org/ - * - * Do not redistribute (in modified or unmodified form) without prior permission. - */ -package wdl.config.settings; - -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import static wdl.config.settings.SettingTestUtils.*; - -import java.util.function.BooleanSupplier; - -import org.junit.Test; - -import wdl.MaybeMixinTest; -import wdl.config.Configuration; -import wdl.config.DefaultConfiguration; -import wdl.config.IConfiguration; -import wdl.config.settings.EntitySettings.TrackDistanceMode; - -public class EntitySettingsTest extends MaybeMixinTest { - - @Test - public void testTrackDistanceMode() { - doWithHasServerRange(() -> true, () -> { - checkAllText(EntitySettings.TRACK_DISTANCE_MODE); - checkParsability(EntitySettings.TRACK_DISTANCE_MODE); - }); - } - - @Test - public void testCycleSimple() { - doWithHasServerRange(() -> false, () -> { - IConfiguration config = new Configuration(new DefaultConfiguration()); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.DEFAULT)); // default - config.cycle(EntitySettings.TRACK_DISTANCE_MODE); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.USER)); - config.cycle(EntitySettings.TRACK_DISTANCE_MODE); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.DEFAULT)); - }); - doWithHasServerRange(() -> true, () -> { - IConfiguration config = new Configuration(new DefaultConfiguration()); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.SERVER)); // default - config.cycle(EntitySettings.TRACK_DISTANCE_MODE); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.USER)); - config.cycle(EntitySettings.TRACK_DISTANCE_MODE); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.DEFAULT)); - config.cycle(EntitySettings.TRACK_DISTANCE_MODE); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.SERVER)); - }); - } - - private synchronized void doWithHasServerRange(BooleanSupplier hasServerRange, Runnable action) { - BooleanSupplier old = EntitySettings.hasServerEntityRange; - try { - EntitySettings.hasServerEntityRange = hasServerRange; - action.run(); - } finally { - EntitySettings.hasServerEntityRange = old; - } - } -} diff --git a/share_14/src/main/java/wdl/EntityUtils.java b/share_14/src/main/java/wdl/EntityUtils.java index 6b7821165..8e7fbf583 100644 --- a/share_14/src/main/java/wdl/EntityUtils.java +++ b/share_14/src/main/java/wdl/EntityUtils.java @@ -147,14 +147,15 @@ public static int getEntityTrackDistance(TrackDistanceMode mode, @Nonnull String return -1; } case SERVER: { - int serverDistance = WDLPluginChannels - .getEntityRange(type); - - if (serverDistance < 0) { - return getEntityTrackDistance(TrackDistanceMode.DEFAULT, type, entity); - } - - return serverDistance; + return getEntityTrackDistance(TrackDistanceMode.DEFAULT, type, entity); +// int serverDistance = WDLPluginChannels +// .getEntityRange(type); +// +// if (serverDistance < 0) { +// return getEntityTrackDistance(TrackDistanceMode.DEFAULT, type, entity); +// } +// +// return serverDistance; } case USER: { int value = WDL.getInstance().worldProps.getUserEntityTrackDistance(type); diff --git a/share_14/src/main/java/wdl/WDL.java b/share_14/src/main/java/wdl/WDL.java index 4c54d0df2..9ee42164a 100644 --- a/share_14/src/main/java/wdl/WDL.java +++ b/share_14/src/main/java/wdl/WDL.java @@ -414,9 +414,9 @@ public void startDownload() { minecraft.displayGuiScreen(null); worldClient = minecraft.world; - if (!WDLPluginChannels.canDownloadAtAll()) { - return; - } +// if (!WDLPluginChannels.canDownloadAtAll()) { +// return; +// } if (promptForInfoForSettings("startDownload", true, this::startDownload, () -> minecraft.displayGuiScreen(null))) { return; @@ -533,7 +533,7 @@ public boolean loadWorld() { loadServerProps(); } - WDLPluginChannels.onWorldLoad(); + //WDLPluginChannels.onWorldLoad(); // Is this a different server? if (networkManager != newNM) { @@ -608,11 +608,11 @@ public void onSaveComplete() { * when stopping. */ public void saveEverything() throws Exception { - if (!WDLPluginChannels.canDownloadAtAll()) { - WDLMessages.chatMessageTranslated(WDL.serverProps, - WDLMessageTypes.ERROR, "wdl.messages.generalError.forbidden"); - return; - } +// if (!WDLPluginChannels.canDownloadAtAll()) { +// WDLMessages.chatMessageTranslated(WDL.serverProps, +// WDLMessageTypes.ERROR, "wdl.messages.generalError.forbidden"); +// return; +// } WorldBackupType backupType = serverProps.getValue(MiscSettings.BACKUP_TYPE); @@ -726,7 +726,7 @@ public boolean shouldCancel() { * @return The player NBT tag. Needed for later use in the world info. */ private CompoundNBT savePlayer(GuiWDLSaveProgress progressScreen) { - if (!WDLPluginChannels.canDownloadAtAll()) { return new CompoundNBT(); } +// if (!WDLPluginChannels.canDownloadAtAll()) { return new CompoundNBT(); } progressScreen.startMajorTask( I18n.format("wdl.saveProgress.playerData.title"), @@ -798,7 +798,7 @@ private CompoundNBT savePlayer(GuiWDLSaveProgress progressScreen) { */ private void saveWorldInfo(GuiWDLSaveProgress progressScreen, CompoundNBT playerInfoNBT) { - if (!WDLPluginChannels.canDownloadAtAll()) { return; } +// if (!WDLPluginChannels.canDownloadAtAll()) { return; } progressScreen.startMajorTask( I18n.format("wdl.saveProgress.worldMetadata.title"), @@ -880,7 +880,7 @@ private void saveWorldInfo(GuiWDLSaveProgress progressScreen, */ private void saveChunks(GuiWDLSaveProgress progressScreen) throws IllegalArgumentException, IllegalAccessException { - if (!WDLPluginChannels.canDownloadAtAll()) { return; } +// if (!WDLPluginChannels.canDownloadAtAll()) { return; } WDLMessages.chatMessageTranslated(WDL.serverProps, WDLMessageTypes.SAVING, "wdl.messages.saving.savingChunks"); @@ -901,9 +901,9 @@ private void saveChunks(GuiWDLSaveProgress progressScreen) Chunk c = chunks.get(currentChunk); if (c != null) { //Serverside restrictions check - if (!WDLPluginChannels.canSaveChunk(c)) { - continue; - } +// if (!WDLPluginChannels.canSaveChunk(c)) { +// continue; +// } progressScreen.setMinorTaskProgress(I18n.format( "wdl.saveProgress.chunk.saving", c.getPos().x, @@ -920,9 +920,9 @@ private void saveChunks(GuiWDLSaveProgress progressScreen) * Import all non-overwritten TileEntities, then save the chunk */ public void saveChunk(Chunk c) { - if (!WDLPluginChannels.canDownloadAtAll()) { return; } +// if (!WDLPluginChannels.canDownloadAtAll()) { return; } - if (!WDLPluginChannels.canSaveChunk(c)) { return; } +// if (!WDLPluginChannels.canSaveChunk(c)) { return; } try { savedChunks.add(c.getPos()); @@ -1317,7 +1317,7 @@ private void addForgeDataToWorldInfo(CompoundNBT rootWorldInfoNBT, CompoundNBT w * that contain pictures. */ private void saveMapData(GuiWDLSaveProgress progressScreen) { - if (!WDLPluginChannels.canSaveMaps()) { return; } +// if (!WDLPluginChannels.canSaveMaps()) { return; } File dataDirectory = new File(saveHandler.getWorldDirectory(), "data"); diff --git a/share_14/src/main/java/wdl/WDLChunkLoader.java b/share_14/src/main/java/wdl/WDLChunkLoader.java index 8f1a52786..1bb607a4b 100644 --- a/share_14/src/main/java/wdl/WDLChunkLoader.java +++ b/share_14/src/main/java/wdl/WDLChunkLoader.java @@ -78,9 +78,9 @@ public WDLChunkLoader(WDL wdl, File file) { protected ListNBT getEntityList(Chunk chunk) { ListNBT entityList = new ListNBT(); - if (!WDLPluginChannels.canSaveEntities(chunk)) { - return entityList; - } +// if (!WDLPluginChannels.canSaveEntities(chunk)) { +// return entityList; +// } // Build a list of all entities in the chunk. List entities = new ArrayList<>(); @@ -205,9 +205,9 @@ protected static boolean shouldSaveEntity(Entity e) { protected ListNBT getTileEntityList(Chunk chunk) { ListNBT tileEntityList = new ListNBT(); - if (!WDLPluginChannels.canSaveTileEntities(chunk)) { - return tileEntityList; - } +// if (!WDLPluginChannels.canSaveTileEntities(chunk)) { +// return tileEntityList; +// } Map chunkTEMap = chunk.getTileEntityMap(); Map oldTEMap = getOldTileEntities(chunk); diff --git a/share_14/src/main/java/wdl/WDLEvents.java b/share_14/src/main/java/wdl/WDLEvents.java index 2e2c654b0..3588c81b6 100644 --- a/share_14/src/main/java/wdl/WDLEvents.java +++ b/share_14/src/main/java/wdl/WDLEvents.java @@ -67,8 +67,8 @@ import wdl.gui.GuiTurningCameraBase; import wdl.gui.GuiWDL; import wdl.gui.GuiWDLAbout; -import wdl.gui.GuiWDLChunkOverrides; -import wdl.gui.GuiWDLPermissions; +//import wdl.gui.GuiWDLChunkOverrides; +//import wdl.gui.GuiWDLPermissions; import wdl.gui.widget.WDLButton; import wdl.handler.HandlerException; import wdl.handler.block.BlockHandler; @@ -163,18 +163,24 @@ public void onChunkNoLongerNeeded(Chunk unneededChunk) { return; } - if (WDLPluginChannels.canSaveChunk(unneededChunk)) { - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.ON_CHUNK_NO_LONGER_NEEDED, - "wdl.messages.onChunkNoLongerNeeded.saved", unneededChunk.getPos().x, unneededChunk.getPos().z); - wdl.saveChunk(unneededChunk); - } else { - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.ON_CHUNK_NO_LONGER_NEEDED, - "wdl.messages.onChunkNoLongerNeeded.didNotSave", unneededChunk.getPos().x, unneededChunk.getPos().z); - } + WDLMessages.chatMessageTranslated( + WDL.serverProps, + WDLMessageTypes.ON_CHUNK_NO_LONGER_NEEDED, + "wdl.messages.onChunkNoLongerNeeded.saved", unneededChunk.getPos().x, unneededChunk.getPos().z); + wdl.saveChunk(unneededChunk); + +// if (WDLPluginChannels.canSaveChunk(unneededChunk)) { +// WDLMessages.chatMessageTranslated( +// WDL.serverProps, +// WDLMessageTypes.ON_CHUNK_NO_LONGER_NEEDED, +// "wdl.messages.onChunkNoLongerNeeded.saved", unneededChunk.getPos().x, unneededChunk.getPos().z); +// wdl.saveChunk(unneededChunk); +// } else { +// WDLMessages.chatMessageTranslated( +// WDL.serverProps, +// WDLMessageTypes.ON_CHUNK_NO_LONGER_NEEDED, +// "wdl.messages.onChunkNoLongerNeeded.didNotSave", unneededChunk.getPos().x, unneededChunk.getPos().z); +// } } /** @@ -230,17 +236,16 @@ public boolean onItemGuiClosed() { EntityHandler handler = EntityHandler.getHandler(ridingEntity.getClass(), windowContainer.getClass()); if (handler != null) { if (handler.checkRidingCasting(windowContainer, ridingEntity)) { - if (!WDLPluginChannels.canSaveEntities( - ridingEntity.chunkCoordX, - ridingEntity.chunkCoordZ)) { - // Run this check now that we've confirmed that we're saving - // the entity being ridden. If we're riding a pig but opening - // a chest in another chunk, that should go to the other check. - WDLMessages.chatMessageTranslated(WDL.serverProps, - WDLMessageTypes.ON_GUI_CLOSED_INFO, "wdl.messages.onGuiClosedInfo.cannotSaveEntities"); - return true; - } - +// if (!WDLPluginChannels.canSaveEntities( +// ridingEntity.chunkCoordX, +// ridingEntity.chunkCoordZ)) { +// // Run this check now that we've confirmed that we're saving +// // the entity being ridden. If we're riding a pig but opening +// // a chest in another chunk, that should go to the other check. +// WDLMessages.chatMessageTranslated(WDL.serverProps, +// WDLMessageTypes.ON_GUI_CLOSED_INFO, "wdl.messages.onGuiClosedInfo.cannotSaveEntities"); +// return true; +// } try { ITextComponent msg = handler.copyDataCasting(windowContainer, ridingEntity, true); WDLMessages.chatMessage(WDL.serverProps, WDLMessageTypes.ON_GUI_CLOSED_INFO, msg); @@ -259,11 +264,11 @@ public boolean onItemGuiClosed() { // If the last thing clicked was an ENTITY Entity entity = wdl.lastEntity; if (entity != null) { - if (!WDLPluginChannels.canSaveEntities(entity.chunkCoordX, entity.chunkCoordZ)) { - WDLMessages.chatMessageTranslated(WDL.serverProps, - WDLMessageTypes.ON_GUI_CLOSED_INFO, "wdl.messages.onGuiClosedInfo.cannotSaveEntities"); - return true; - } +// if (!WDLPluginChannels.canSaveEntities(entity.chunkCoordX, entity.chunkCoordZ)) { +// WDLMessages.chatMessageTranslated(WDL.serverProps, +// WDLMessageTypes.ON_GUI_CLOSED_INFO, "wdl.messages.onGuiClosedInfo.cannotSaveEntities"); +// return true; +// } EntityHandler handler = EntityHandler.getHandler(entity.getClass(), windowContainer.getClass()); if (handler != null) { @@ -301,12 +306,12 @@ public boolean onItemGuiClosed() { } //Permissions check. - if (!WDLPluginChannels.canSaveContainers(te.getPos().getX() >> 4, te - .getPos().getZ() >> 4)) { - WDLMessages.chatMessageTranslated(WDL.serverProps, - WDLMessageTypes.ON_GUI_CLOSED_INFO, "wdl.messages.onGuiClosedInfo.cannotSaveTileEntities"); - return true; - } +// if (!WDLPluginChannels.canSaveContainers(te.getPos().getX() >> 4, te +// .getPos().getZ() >> 4)) { +// WDLMessages.chatMessageTranslated(WDL.serverProps, +// WDLMessageTypes.ON_GUI_CLOSED_INFO, "wdl.messages.onGuiClosedInfo.cannotSaveTileEntities"); +// return true; +// } BlockHandler handler = BlockHandler.getHandler(te.getClass(), wdl.windowContainer.getClass()); @@ -349,10 +354,10 @@ public boolean onItemGuiClosed() { public void onBlockEvent(BlockPos pos, Block block, int data1, int data2) { if (!WDL.downloading) { return; } - if (!WDLPluginChannels.canSaveTileEntities(pos.getX() >> 4, - pos.getZ() >> 4)) { - return; - } +// if (!WDLPluginChannels.canSaveTileEntities(pos.getX() >> 4, +// pos.getZ() >> 4)) { +// return; +// } TileEntity blockEntity = wdl.worldClient.getTileEntity(pos); if (blockEntity == null) { @@ -379,9 +384,9 @@ public void onBlockEvent(BlockPos pos, Block block, int data1, int data2) { public void onMapDataLoaded(int mapID, @Nonnull MapData mapData) { if (!WDL.downloading) { return; } - if (!WDLPluginChannels.canSaveMaps()) { - return; - } +// if (!WDLPluginChannels.canSaveMaps()) { +// return; +// } // Assume that the current dimension is the right one ClientPlayerEntity player = wdl.player; @@ -398,10 +403,10 @@ public void onMapDataLoaded(int mapID, @Nonnull MapData mapData) { * Must be called whenever a plugin channel message / custom payload packet * is received. */ - public void onPluginChannelPacket(ClientPlayNetHandler sender, - String channel, byte[] bytes) { - WDLPluginChannels.onPluginChannelPacket(sender, channel, bytes); - } +// public void onPluginChannelPacket(ClientPlayNetHandler sender, +// String channel, byte[] bytes) { +// WDLPluginChannels.onPluginChannelPacket(sender, channel, bytes); +// } /** * Must be called when an entity is about to be removed from the world. @@ -409,9 +414,7 @@ public void onPluginChannelPacket(ClientPlayNetHandler sender, public void onRemoveEntityFromWorld(Entity entity) { // If the entity is being removed and it's outside the default tracking // range, go ahead and remember it until the chunk is saved. - if (WDL.downloading && entity != null - && WDLPluginChannels.canSaveEntities(entity.chunkCoordX, - entity.chunkCoordZ)) { + if (WDL.downloading && entity != null) { if (!EntityUtils.isEntityEnabled(entity)) { WDLMessages.chatMessageTranslated( WDL.serverProps, @@ -690,60 +693,60 @@ public void onNHPCHandleMaps(ClientPlayNetHandler sender, @Override public void onNHPCHandleCustomPayload(ClientPlayNetHandler sender, SCustomPayloadPlayPacket packet) { - try { - if (!wdl.minecraft.isOnExecutionThread()) { - return; - } - if (ENABLE_PROFILER) PROFILER.startSection("wdl.onPluginMessage"); - - if (ENABLE_PROFILER) PROFILER.startSection("Parse"); - String channel = packet.getChannelName().toString(); // 1.13: ResourceLocation -> String; otherwise no-op - ByteBuf buf = packet.getBufferData(); - int refCnt = buf.refCnt(); - if (refCnt <= 0) { - // The buffer has already been released. Just break out now. - // This happens with e.g. the MC|TrList packet (villager trade list), - // which closes the buffer after reading it. - if (ENABLE_PROFILER) PROFILER.endSection(); // "Parse" - if (ENABLE_PROFILER) PROFILER.endSection(); // "wdl.onPluginMessage" - return; - } - - // Something else may have already read the payload; return to the start - buf.markReaderIndex(); - buf.readerIndex(0); - byte[] payload = new byte[buf.readableBytes()]; - buf.readBytes(payload); - // OK, now that we've done our reading, return to where it was before - // (which could be the end, or other code might not have read it yet) - buf.resetReaderIndex(); - // buf will be released by the packet handler, eventually. - // It definitely is NOT our responsibility to release it, as - // doing so would probably break other code outside of wdl. - // Perhaps we might want to call retain once at the start of this method - // and then release at the end, but that feels excessive (since there - // _shouldn't_ be multiple threads at play at this point, and if there - // were we'd be in trouble anyways). - - if (ENABLE_PROFILER) PROFILER.endSection(); // "Parse" - - if (ENABLE_PROFILER) PROFILER.startSection("Core"); - wdlEvents.onPluginChannelPacket(sender, channel, payload); - if (ENABLE_PROFILER) PROFILER.endSection(); // "Core" - - for (ModInfo info : WDLApi - .getImplementingExtensions(IPluginChannelListener.class)) { - if (ENABLE_PROFILER) PROFILER.startSection(info.id); - info.mod.onPluginChannelPacket(wdl.worldClient, channel, - payload); - if (ENABLE_PROFILER) PROFILER.endSection(); // info.id - } - - if (ENABLE_PROFILER) PROFILER.endSection(); // "wdl.onPluginMessage" - } catch (Throwable e) { - wdl.crashed(e, - "WDL mod: exception in onNHPCHandleCustomPayload event"); - } +// try { +// if (!wdl.minecraft.isOnExecutionThread()) { +// return; +// } +// if (ENABLE_PROFILER) PROFILER.startSection("wdl.onPluginMessage"); +// +// if (ENABLE_PROFILER) PROFILER.startSection("Parse"); +// String channel = packet.getChannelName().toString(); // 1.13: ResourceLocation -> String; otherwise no-op +// ByteBuf buf = packet.getBufferData(); +// int refCnt = buf.refCnt(); +// if (refCnt <= 0) { +// // The buffer has already been released. Just break out now. +// // This happens with e.g. the MC|TrList packet (villager trade list), +// // which closes the buffer after reading it. +// if (ENABLE_PROFILER) PROFILER.endSection(); // "Parse" +// if (ENABLE_PROFILER) PROFILER.endSection(); // "wdl.onPluginMessage" +// return; +// } +// +// // Something else may have already read the payload; return to the start +// buf.markReaderIndex(); +// buf.readerIndex(0); +// byte[] payload = new byte[buf.readableBytes()]; +// buf.readBytes(payload); +// // OK, now that we've done our reading, return to where it was before +// // (which could be the end, or other code might not have read it yet) +// buf.resetReaderIndex(); +// // buf will be released by the packet handler, eventually. +// // It definitely is NOT our responsibility to release it, as +// // doing so would probably break other code outside of wdl. +// // Perhaps we might want to call retain once at the start of this method +// // and then release at the end, but that feels excessive (since there +// // _shouldn't_ be multiple threads at play at this point, and if there +// // were we'd be in trouble anyways). +// +// if (ENABLE_PROFILER) PROFILER.endSection(); // "Parse" +// +// if (ENABLE_PROFILER) PROFILER.startSection("Core"); +// //wdlEvents.onPluginChannelPacket(sender, channel, payload); +// if (ENABLE_PROFILER) PROFILER.endSection(); // "Core" +// +//// for (ModInfo info : WDLApi +//// .getImplementingExtensions(IPluginChannelListener.class)) { +//// if (ENABLE_PROFILER) PROFILER.startSection(info.id); +//// info.mod.onPluginChannelPacket(wdl.worldClient, channel, +//// payload); +//// if (ENABLE_PROFILER) PROFILER.endSection(); // info.id +//// } +// +// if (ENABLE_PROFILER) PROFILER.endSection(); // "wdl.onPluginMessage" +// } catch (Throwable e) { +// wdl.crashed(e, +// "WDL mod: exception in onNHPCHandleCustomPayload event"); +// } } @Override public void onNHPCHandleBlockAction(ClientPlayNetHandler sender, @@ -818,19 +821,20 @@ public void beforeDraw() { displayString = I18n .format("wdl.gui.ingameMenu.downloadStatus.singlePlayer"); enabled = false; - } else if (!WDLPluginChannels.canDownloadAtAll()) { - if (WDLPluginChannels.canRequestPermissions()) { - // Allow requesting permissions. - displayString = I18n - .format("wdl.gui.ingameMenu.downloadStatus.request"); - enabled = true; - } else { - // Out of date plugin :/ - displayString = I18n - .format("wdl.gui.ingameMenu.downloadStatus.disabled"); - enabled = false; - } - } else if (WDL.saving) { + } +// } else if (!WDLPluginChannels.canDownloadAtAll()) { +// if (WDLPluginChannels.canRequestPermissions()) { +// // Allow requesting permissions. +// displayString = I18n +// .format("wdl.gui.ingameMenu.downloadStatus.request"); +// enabled = true; +// } else { +// // Out of date plugin :/ +// displayString = I18n +// .format("wdl.gui.ingameMenu.downloadStatus.disabled"); +// enabled = false; +// } + else if (WDL.saving) { // Normally not accessible; only happens as a major fallback... displayString = I18n .format("wdl.gui.ingameMenu.downloadStatus.saving"); @@ -858,23 +862,23 @@ public void performAction() { wdl.stopDownload(); setEnabled(false); // Disable to stop double-clicks } else { - if (!WDLPluginChannels.canDownloadAtAll()) { - // If they don't have any permissions, let the player - // request some. - if (WDLPluginChannels.canRequestPermissions()) { - wdl.minecraft.displayGuiScreen(new GuiWDLPermissions(menu, wdl)); - } else { - // Should never happen - } - } else if (WDLPluginChannels.hasChunkOverrides() - && !WDLPluginChannels.canDownloadInGeneral()) { - // Handle the "only has chunk overrides" state - notify - // the player of limited areas. - wdl.minecraft.displayGuiScreen(new GuiWDLChunkOverrides(menu, wdl)); - } else { +// if (!WDLPluginChannels.canDownloadAtAll()) { +// // If they don't have any permissions, let the player +// // request some. +// if (WDLPluginChannels.canRequestPermissions()) { +// wdl.minecraft.displayGuiScreen(new GuiWDLPermissions(menu, wdl)); +// } else { +// // Should never happen +// } +// } else if (WDLPluginChannels.hasChunkOverrides() +// && !WDLPluginChannels.canDownloadInGeneral()) { +// // Handle the "only has chunk overrides" state - notify +// // the player of limited areas. +// wdl.minecraft.displayGuiScreen(new GuiWDLChunkOverrides(menu, wdl)); +// } else { wdl.startDownload(); setEnabled(false); // Disable to stop double-clicks - } + //} } } } diff --git a/share_14/src/main/java/wdl/WDLPluginChannels.java b/share_14/src/main/java/wdl/WDLPluginChannels.java deleted file mode 100644 index d9cb2e0d9..000000000 --- a/share_14/src/main/java/wdl/WDLPluginChannels.java +++ /dev/null @@ -1,1038 +0,0 @@ -/* - * This file is part of World Downloader: A mod to make backups of your multiplayer worlds. - * https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/2520465-world-downloader-mod-create-backups-of-your-builds - * - * Copyright (c) 2014 nairol, cubic72 - * Copyright (c) 2017-2020 Pokechu22, julialy - * - * This project is licensed under the MMPLv2. The full text of the MMPL can be - * found in LICENSE.md, or online at https://github.com/iopleke/MMPLv2/blob/master/LICENSE.md - * For information about this the MMPLv2, see https://stopmodreposts.org/ - * - * Do not redistribute (in modified or unmodified form) without prior permission. - */ -package wdl; - -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.WeakHashMap; - -import javax.annotation.CheckForSigned; -import javax.annotation.Nullable; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteArrayDataOutput; -import com.google.common.io.ByteStreams; -import com.google.gson.JsonObject; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.network.play.ClientPlayNetHandler; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.play.client.CCustomPayloadPacket; -import net.minecraft.world.chunk.Chunk; -import wdl.versioned.VersionedFunctions; -import wdl.versioned.VersionedFunctions.ChannelName; - -/** - * World Downloader permission system implemented with Plugin Channels. - * - * This system is used to configure the mod, and disable certain features, - * at a server's decision. I've made this system because there already were - * other (more esoteric) methods of finding the mod, based off of forge and - * lightloader handshakes. I think that a system like this, where there are - * degrees of control, is better than one where the player is - * indiscriminately kicked. For instance, this system allows for permission - * requests, which would be hard to do with another mechanism. - * - * This system makes use of plugin channels (hence the class name). If you - * haven't read their info, - * they're a vanilla minecraft packet intended for mods. But they do - * need each channel to be REGISTERed before use, so the server does know - * when the mod is installed. As such, I actually did a second step and - * instead send a second packet when the data is ready to be received by the - * client, since mid-download permission changes can be problematic. - * - * Theoretically, these could be implemented with chat-based codes or even - * MOTD-based codes. However, I really do not like that system, as - * it is really rigid. So I chose this one, which is also highly expandable. - * - * This system is also used to fetch a few things from willing servers, mainly - * entity track distances so that things can be saved correctly. - * - * And yes, this is the fabled "backdoor" / "back door"; I don't like that term - * but people will call it that. I think it's the best possible system out - * of the available options (and doing nothing wouldn't work - as I said, - * there are weird ways of finding mods). - * - * Packet - * documentation is on wiki.vg, if you're interested. - */ -public class WDLPluginChannels { - private static final Logger LOGGER = LogManager.getLogger(); - /** - * Packets that have been received. - */ - private static HashSet receivedPackets = new HashSet<>(); - - /** - * Whether functions that the server is not aware of can be used. - * (Packet #0) - */ - private static boolean canUseFunctionsUnknownToServer = true; - /** - * Whether all players are allowed to download the world in general. - * If false, they aren't allowed, regardless of the other values below. - */ - private static boolean canDownloadInGeneral = true; - /** - * The distance from a player that WDL can save chunks. - * - * This is only used when {@link #canCacheChunks} is false. - */ - private static int saveRadius = -1; - /** - * Whether a player can cache chunks as they move. In essence, this means - * that if the value is true, the player can download the entire map while - * moving about, but if false, the player will only save the nearby chunks - * when they stop download. - */ - private static boolean canCacheChunks = true; - /** - * Whether or not a player can save entities in the map. - */ - private static boolean canSaveEntities = true; - /** - * Whether or not a player can save TileEntities in general. - *
- * Chests and other containers also require {@link #canSaveContainers}. - */ - private static boolean canSaveTileEntities = true; - /** - * Whether a player can save containers that require opening to save their - * contents, such as chests. For this value to have meaning, the value of - * {@link #canSaveTileEntities} must also be true. - */ - private static boolean canSaveContainers = true; - /** - * Map of entity ranges. - * - * Key is the entity string, int is the range. - */ - private static Map entityRanges = - new HashMap<>(); - - /** - * Whether players can request permissions. - * - * With the default implementation, this is always sent as - * true. However, this needs to be sent for it to be useful - - * if the plugin does NOT send it, it does not support permission requests. - */ - private static boolean canRequestPermissions = false; - - /** - * Message to display when requesting. If empty, nothing - * is displayed. - */ - private static String requestMessage = ""; - - /** - * Chunk overrides. Any chunk within a range is allowed to be downloaded in. - */ - private static Map> chunkOverrides = new HashMap<>(); - - /** - * Active permission requests. - */ - private static Map requests = new HashMap<>(); - - /** - * Permission request fields that take boolean parameters. - */ - public static final List BOOLEAN_REQUEST_FIELDS = Arrays.asList( - "downloadInGeneral", "cacheChunks", "saveEntities", - "saveTileEntities", "saveContainers", "getEntityRanges"); - /** - * Permission request fields that take integer parameters. - */ - public static final List INTEGER_REQUEST_FIELDS = Arrays.asList( - "saveRadius"); - - /** - * List of new chunk override requests. - */ - private static List chunkOverrideRequests = new ArrayList<>(); - - /** - * Checks whether players can use functions unknown to the server. - */ - public static boolean canUseFunctionsUnknownToServer() { - if (receivedPackets.contains(0)) { - return canUseFunctionsUnknownToServer; - } else { - return true; - } - } - - /** - * Checks whether the player should be able to start download at all: Either - * {@link #canDownloadInGeneral()} is true, or the player has some chunks - * overridden. - */ - public static boolean canDownloadAtAll() { - if (hasChunkOverrides()) { - return true; - } else { - return canDownloadInGeneral(); - } - } - - /** - * Checks whether players are allowed to download in general (outside of - * overridden chunks). - */ - public static boolean canDownloadInGeneral() { - if (receivedPackets.contains(1)) { - return canDownloadInGeneral; - } else { - return canUseFunctionsUnknownToServer(); - } - } - - /** - * Checks if a chunk is within the saveRadius - * (and chunk caching is disabled). - */ - public static boolean canSaveChunk(Chunk chunk) { - if (isChunkOverridden(chunk)) { - return true; - } - - if (!canDownloadInGeneral()) { - return false; - } - - if (receivedPackets.contains(1)) { - if (!canCacheChunks && saveRadius >= 0) { - int distanceX = chunk.getPos().x - WDL.getInstance().player.chunkCoordX; - int distanceZ = chunk.getPos().z - WDL.getInstance().player.chunkCoordZ; - - if (Math.abs(distanceX) > saveRadius || - Math.abs(distanceZ) > saveRadius) { - return false; - } - } - - return true; - } else { - return canUseFunctionsUnknownToServer(); - } - } - - /** - * Checks whether entities are allowed to be saved. - */ - public static boolean canSaveEntities() { - if (!canDownloadInGeneral()) { - return false; - } - - if (receivedPackets.contains(1)) { - return canSaveEntities; - } else { - return canUseFunctionsUnknownToServer(); - } - } - - /** - * Checks whether entities are allowed to be saved in the given chunk. - */ - public static boolean canSaveEntities(Chunk chunk) { - if (isChunkOverridden(chunk)) { - return true; - } - - return canSaveEntities(); - } - - /** - * Checks whether entities are allowed to be saved in the given chunk. - */ - public static boolean canSaveEntities(int chunkX, int chunkZ) { - if (isChunkOverridden(chunkX, chunkZ)) { - return true; - } - - return canSaveEntities(); - } - - /** - * Checks whether a player can save tile entities. - */ - public static boolean canSaveTileEntities() { - if (!canDownloadInGeneral()) { - return false; - } - - if (receivedPackets.contains(1)) { - return canSaveTileEntities; - } else { - return canUseFunctionsUnknownToServer(); - } - } - - /** - * Checks whether a player can save tile entities in the given chunk. - */ - public static boolean canSaveTileEntities(Chunk chunk) { - if (isChunkOverridden(chunk)) { - return true; - } - - return canSaveTileEntities(); - } - - /** - * Checks whether a player can save tile entities in the given chunk. - */ - public static boolean canSaveTileEntities(int chunkX, int chunkZ) { - if (isChunkOverridden(chunkX, chunkZ)) { - return true; - } - - return canSaveTileEntities(); - } - - /** - * Checks whether containers (such as chests) can be saved. - */ - public static boolean canSaveContainers() { - if (!canDownloadInGeneral()) { - return false; - } - if (!canSaveTileEntities()) { - return false; - } - if (receivedPackets.contains(1)) { - return canSaveContainers; - } else { - return canUseFunctionsUnknownToServer(); - } - } - - /** - * Checks whether containers (such as chests) can be saved. - */ - public static boolean canSaveContainers(Chunk chunk) { - if (isChunkOverridden(chunk)) { - return true; - } - - return canSaveContainers(); - } - - /** - * Checks whether containers (such as chests) can be saved. - */ - public static boolean canSaveContainers(int chunkX, int chunkZ) { - if (isChunkOverridden(chunkX, chunkZ)) { - return true; - } - - return canSaveContainers(); - } - - /** - * Checks whether maps (the map item, not the world itself) can be saved. - */ - public static boolean canSaveMaps() { - if (!canDownloadInGeneral()) { - return false; - } - //TODO: Better value than 'canSaveTileEntities'. - if (receivedPackets.contains(1)) { - return canSaveTileEntities; - } else { - return canUseFunctionsUnknownToServer(); - } - } - - /** - * Gets the server-set range for the given entity. - * - * @param entity The entity's name (via {@link EntityUtils#getEntityType}). - * @return The entity's range, or -1 if no data was recieved. - */ - @CheckForSigned - public static int getEntityRange(String entity) { - if (!canSaveEntities(null)) { - return -1; - } - if (receivedPackets.contains(2)) { - if (entityRanges.containsKey(entity)) { - return entityRanges.get(entity); - } else { - return -1; - } - } else { - return -1; - } - } - - /** - * Gets the save radius. - * - * Note that using {@link #canSaveChunk(Chunk)} is generally better - * as it handles most of the radius logic. - * - * @return {@link #saveRadius}. - */ - public static int getSaveRadius() { - return saveRadius; - } - - /** - * Gets whether chunks can be cached. - * - * Note that using {@link #canSaveChunk(Chunk)} is generally better - * as it handles most of the radius logic. - * - * @return {@link #canCacheChunks}. - */ - public static boolean canCacheChunks() { - return canCacheChunks; - } - - /** - * Checks if the server-set entity range is configured. - */ - public static boolean hasServerEntityRange() { - return receivedPackets.contains(2) && entityRanges.size() > 0; - } - - public static Map getEntityRanges() { - return new HashMap<>(entityRanges); - } - - /** - * Gets whether permissions are available. - */ - public static boolean hasPermissions() { - return receivedPackets != null && !receivedPackets.isEmpty(); - } - - /** - * Gets whether permissions are available. - */ - public static boolean canRequestPermissions() { - return receivedPackets.contains(3) && canRequestPermissions; - } - - /** - * Gets the request message. - * @return The {@link #requestMessage}. - */ - public static String getRequestMessage() { - if (receivedPackets.contains(3)) { - return requestMessage; - } else { - return null; - } - } - - /** - * Is the given chunk part of a chunk override? - */ - public static boolean isChunkOverridden(Chunk chunk) { - if (chunk == null) { - return false; - } - - return isChunkOverridden(chunk.getPos().x, chunk.getPos().z); - } - /** - * Is the given chunk location part of a chunk override? - */ - public static boolean isChunkOverridden(int x, int z) { - for (Multimap map : chunkOverrides.values()) { - for (ChunkRange range : map.values()) { - if (x >= range.x1 && - x <= range.x2 && - z >= range.z1 && - z <= range.z2) { - return true; - } - } - } - - return false; - } - - /** - * Are there any chunk overrides present? - */ - public static boolean hasChunkOverrides() { - if (!receivedPackets.contains(4)) { - // XXX It's possible that some implementations may not send - // packet 4, but still send ranges. If so, that may lead to issues. - // But right now, I'm not checking that. - return false; - } - if (chunkOverrides == null || chunkOverrides.isEmpty()) { - return false; - } - for (Multimap m : chunkOverrides.values()) { - if (!m.isEmpty()) { - return true; - } - } - return false; - } - - /** - * Gets an immutable copy of the {@link #chunkOverrides} map. - */ - public static Map> getChunkOverrides() { - Map> returned = new - HashMap<>(); - - for (Map.Entry> e : chunkOverrides - .entrySet()) { - // Create a copy of the given map. - Multimap map = ImmutableMultimap.copyOf(e.getValue()); - - returned.put(e.getKey(), map); - } - - return ImmutableMap.copyOf(returned); - } - - /** - * Create a new permission request. - * @param key The key for the request. - * @param value The wanted value. - */ - public static void addRequest(String key, String value) { - if (!isValidRequest(key, value)) { - return; - } - - requests.put(key, value); - } - - /** - * Gets an immutable copy of the current requests. - */ - public static Map getRequests() { - return ImmutableMap.copyOf(requests); - } - - /** - * Is the given set of values valid for the given request? - * - * Handles checking if the key exists and if the value is valid. - * - * @param key The key for the request. - * @param value The wanted value. - */ - public static boolean isValidRequest(String key, String value) { - if (key == null || value == null) { - return false; - } - - if (BOOLEAN_REQUEST_FIELDS.contains(key)) { - return value.equals("true") || value.equals("false"); - } else if (INTEGER_REQUEST_FIELDS.contains(key)) { - try { - Integer.parseInt(value); - return true; - } catch (NumberFormatException e) { - return false; - } - } - - return false; - } - - /** - * Gets the current list of chunk override requests. - */ - public static List getChunkOverrideRequests() { - return ImmutableList.copyOf(chunkOverrideRequests); - } - /** - * Adds a new chunk override request for the given range. - */ - public static void addChunkOverrideRequest(ChunkRange range) { - chunkOverrideRequests.add(range); - } - - /** - * Sends the current requests to the server. - */ - public static void sendRequests() { - if (requests.isEmpty() && chunkOverrideRequests.isEmpty()) { - return; - } - - ByteArrayDataOutput output = ByteStreams.newDataOutput(); - - output.writeUTF("REQUEST REASON WILL GO HERE"); //TODO - output.writeInt(requests.size()); - for (Map.Entry request : requests.entrySet()) { - output.writeUTF(request.getKey()); - output.writeUTF(request.getValue()); - } - - output.writeInt(chunkOverrideRequests.size()); - for (ChunkRange range : chunkOverrideRequests) { - range.writeToOutput(output); - } - - ClientPlayNetHandler nhpc = Minecraft.getInstance().getConnection(); - final String channel; - if (isRegistered(nhpc, REQUEST_CHANNEL_NEW)) { - channel = REQUEST_CHANNEL_NEW; - } else if (isRegistered(nhpc, REQUEST_CHANNEL_OLD)) { - channel = REQUEST_CHANNEL_OLD; - } else { - throw new RuntimeException("No request channel has been registered :("); // XXX - } - CCustomPayloadPacket requestPacket = VersionedFunctions.makePluginMessagePacket(channel, output.toByteArray()); - nhpc.sendPacket(requestPacket); - } - - /** - * Channels that the server has registered/unregistered. - * - * A map from a NetworkManager instance to a String, so that data is kept per-server. - * - * Unfortunately, clearing in onWorldLoad -> newServer doesn't work right, as that happens - * after (possibly far after) plugin messages are handled. - * - * XXX Equally unfortunately, the server never bothers to tell the client what channels it will send on... - */ - private static final Map> REGISTERED_CHANNELS = new WeakHashMap<>(); - - /** Channels for the init packet */ - private static final String INIT_CHANNEL_OLD = "WDL|INIT", INIT_CHANNEL_NEW = "wdl:init"; - /** Channels for the control packet */ - private static final String CONTROL_CHANNEL_OLD = "WDL|CONTROL", CONTROL_CHANNEL_NEW = "wdl:control"; - /** Channels for the request packet */ - private static final String REQUEST_CHANNEL_OLD = "WDL|REQUEST", REQUEST_CHANNEL_NEW = "wdl:request"; - - /** All known channels */ - private static final List<@ChannelName String> WDL_CHANNELS = VersionedFunctions.removeInvalidChannelNames( - INIT_CHANNEL_NEW, CONTROL_CHANNEL_NEW, REQUEST_CHANNEL_NEW, - INIT_CHANNEL_OLD, CONTROL_CHANNEL_OLD, REQUEST_CHANNEL_OLD - ); - - /** - * Gets the current set of registered channels for this server. - */ - private static Set<@ChannelName String> getRegisteredChannels(ClientPlayNetHandler nhpc) { - return REGISTERED_CHANNELS.computeIfAbsent( - nhpc.getNetworkManager(), - key -> new HashSet<>()); - } - - /** - * Checks if the given channel is registered on this server. - */ - private static boolean isRegistered(ClientPlayNetHandler nhpc, String channelName) { - return getRegisteredChannels(nhpc).contains(channelName); - } - - private static final String UPDATE_NOTE = "For 1.13 compatibility, please update your plugin as channel names have changed."; - - /** - * The state for {@link #sendInitPacket(String)} if it was called when no channels were registered. - */ - @Nullable - private static String deferredInitState = null; - - public static void sendInitPacket(String state) { - sendInitPacket(Minecraft.getInstance().getConnection(), state); - } - private static void sendInitPacket(ClientPlayNetHandler nhpc, String state) { - assert nhpc != null : "Unexpected null nhpc: state=" + state + ", chans=" + REGISTERED_CHANNELS; - - final String channel; - if (isRegistered(nhpc, INIT_CHANNEL_NEW)) { - channel = INIT_CHANNEL_NEW; - } else if (isRegistered(nhpc, INIT_CHANNEL_OLD)) { - channel = INIT_CHANNEL_OLD; - } else { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("[WDL] Deferring init packet for state {} (existing deferred state is {} -- should be null), as no registered channel: {}", state, deferredInitState, REGISTERED_CHANNELS); - } - deferredInitState = state; - return; - } - - LOGGER.debug("[WDL] Sending init packet for state {} on {}", state, channel); - - JsonObject object = new JsonObject(); - object.addProperty("X-RTFM", "https://wiki.vg/Plugin_channels/World_downloader"); - object.addProperty("X-UpdateNote", UPDATE_NOTE); - object.addProperty("Version", VersionConstants.getModVersion()); - object.addProperty("State", state); - byte[] bytes = object.toString().getBytes(StandardCharsets.UTF_8); - - CCustomPayloadPacket initPacket = VersionedFunctions.makePluginMessagePacket(channel, bytes); - - nhpc.sendPacket(initPacket); - - deferredInitState = null; - } - - /** - * Event that is called when the world is loaded. - * Sets the default values, and then asks the server to give the - * correct ones. - */ - static void onWorldLoad() { - @SuppressWarnings("resource") - Minecraft minecraft = Minecraft.getInstance(); - - receivedPackets = new HashSet<>(); - requests = new HashMap<>(); - chunkOverrideRequests = new ArrayList<>(); - - canUseFunctionsUnknownToServer = true; - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, "wdl.messages.permissions.init"); - - // Register the WDL messages. - byte[] registerBytes = String.join("\0", WDL_CHANNELS).getBytes(); - - CCustomPayloadPacket registerPacket = VersionedFunctions.makePluginMessagePacket(VersionedFunctions.getRegisterChannel(), registerBytes); - minecraft.getConnection().sendPacket(registerPacket); - - // Send the init message. - sendInitPacket("Init?"); - } - - static void onPluginChannelPacket(ClientPlayNetHandler sender, @ChannelName String channel, byte[] bytes) { - if ("REGISTER".equals(channel) || "minecraft:register".equals(channel)) { - registerChannels(sender, bytes); - } else if ("UNREGISTER".equals(channel) || "minecraft:unregister".equals(channel)) { - unregisterChannels(sender, bytes); - } else if (CONTROL_CHANNEL_NEW.equals(channel) || CONTROL_CHANNEL_OLD.equals(channel)) { - handleControlPacket(bytes); - } - } - - private static void registerChannels(ClientPlayNetHandler nhpc, byte[] bytes) { - String existing = LOGGER.isDebugEnabled() ? REGISTERED_CHANNELS.toString() : null; - - String str = new String(bytes, StandardCharsets.UTF_8); - - List channels = Arrays.asList(str.split("\0")); - channels.stream() - .filter(WDL_CHANNELS::contains) - .forEach(getRegisteredChannels(nhpc)::add); - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("[WDL] REGISTER: " + str + "/" + channels + ": " + existing + " => " + REGISTERED_CHANNELS); - } - - if (deferredInitState != null) { - LOGGER.debug("[WDL] REGISTER: Trying to resolve deferred {}", deferredInitState); - sendInitPacket(nhpc, deferredInitState); - } - } - - private static void unregisterChannels(ClientPlayNetHandler nhpc, byte[] bytes) { - String existing = LOGGER.isDebugEnabled() ? REGISTERED_CHANNELS.toString() : null; - - String str = new String(bytes, StandardCharsets.UTF_8); - List channels = Arrays.asList(str.split("\0")); - channels.stream() - .filter(WDL_CHANNELS::contains) - .forEach(getRegisteredChannels(nhpc)::remove); - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("[WDL] UNREGISTER: " + str + "/" + channels + ": " + existing + " => " + REGISTERED_CHANNELS); - } - } - - private static void handleControlPacket(byte[] bytes) { - try { - ByteArrayDataInput input = ByteStreams.newDataInput(bytes); - - int section = input.readInt(); - - receivedPackets.add(section); - - switch (section) { - case 0: - canUseFunctionsUnknownToServer = input.readBoolean(); - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet0", canUseFunctionsUnknownToServer); - - break; - case 1: - canDownloadInGeneral = input.readBoolean(); - saveRadius = input.readInt(); - canCacheChunks = input.readBoolean(); - canSaveEntities = input.readBoolean(); - canSaveTileEntities = input.readBoolean(); - canSaveContainers = input.readBoolean(); - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet1", canDownloadInGeneral, - saveRadius, canCacheChunks, - canSaveEntities, canSaveTileEntities, canSaveContainers); - - //Cancel a download if it is occurring. - if (!canDownloadInGeneral) { - if (WDL.downloading) { - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.ERROR, "wdl.messages.generalError.forbidden"); - WDL.getInstance().cancelDownload(); - } - } - break; - case 2: - entityRanges.clear(); - - int count = input.readInt(); - for (int i = 0; i < count; i++) { - String name = input.readUTF(); - int range = input.readInt(); - - entityRanges.put(name, range); - } - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet2", entityRanges.size()); - break; - case 3: - canRequestPermissions = input.readBoolean(); - requestMessage = input.readUTF(); - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet3", canRequestPermissions, - requestMessage.length(), Integer.toHexString(requestMessage.hashCode())); - // Don't include the exact message because it's too long and would be spammy. - break; - case 4: - chunkOverrides.clear(); - - int numRangeGroups = input.readInt(); - int totalRanges = 0; - for (int i = 0; i < numRangeGroups; i++) { - String groupName = input.readUTF(); - int groupSize = input.readInt(); - - Multimap ranges = HashMultimap - . create(); - - for (int j = 0; j < groupSize; j++) { - ChunkRange range = ChunkRange.readFromInput(input); - ranges.put(range.tag, range); - } - - chunkOverrides.put(groupName, ranges); - - totalRanges += groupSize; - } - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet4", numRangeGroups, totalRanges); - break; - case 5: - - String groupToEdit = input.readUTF(); - boolean replaceGroups = input.readBoolean(); - int numNewGroups = input.readInt(); - - Multimap newRanges = HashMultimap - . create(); - if (!replaceGroups) { - newRanges.putAll(chunkOverrides.get(groupToEdit)); - } - - for (int i = 0; i < numNewGroups; i++) { - ChunkRange range = ChunkRange.readFromInput(input); - - newRanges.put(range.tag, range); - } - chunkOverrides.put(groupToEdit, newRanges); - - if (replaceGroups) { - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet5.set", numNewGroups, groupToEdit); - } else { - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet5.added", numNewGroups, groupToEdit); - } - break; - case 6: - String groupToChangeTagsFor = input.readUTF(); - int numTags = input.readInt(); - String[] tags = new String[numTags]; - - for (int i = 0; i < numTags; i++) { - tags[i] = input.readUTF(); - } - - int oldCount = 0; - for (String tag : tags) { - oldCount += chunkOverrides.get(groupToChangeTagsFor) - .get(tag).size(); - chunkOverrides.get(groupToChangeTagsFor).removeAll(tag); - } - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet6", oldCount, groupToChangeTagsFor, Arrays.toString(tags)); - break; - case 7: - String groupToSetTagFor = input.readUTF(); - String tag = input.readUTF(); - int numNewRanges = input.readInt(); - - Collection oldRanges = chunkOverrides.get( - groupToSetTagFor).removeAll(tag); - int numRangesRemoved = oldRanges.size(); - - for (int i = 0; i < numNewRanges; i++) { - //TODO: Ensure that the range has the right tag. - - chunkOverrides.get(groupToSetTagFor).put(tag, - ChunkRange.readFromInput(input)); - } - - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.packet7", numRangesRemoved, groupToSetTagFor, tag, numNewRanges); - break; - default: - WDLMessages.chatMessageTranslated( - WDL.serverProps, - WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, "wdl.messages.permissions.unknownPacket", section); - dump(bytes); - } - } catch (Exception ex) { - WDLMessages.chatMessageTranslated(WDL.serverProps, WDLMessageTypes.PLUGIN_CHANNEL_MESSAGE, - "wdl.messages.permissions.badPacket", ex); - } - } - - private static void dump(byte[] bytes) { - StringBuilder messageBuilder = new StringBuilder(); - for (byte b : bytes) { - messageBuilder.append(b).append(' '); - } - - LOGGER.info(messageBuilder.toString()); - } - - /** - * A range of chunks. - */ - public static class ChunkRange { - public ChunkRange(String tag, int x1, int z1, int x2, int z2) { - this.tag = tag; - - // Ensure that the order is correct - if (x1 > x2) { - this.x1 = x2; - this.x2 = x1; - } else { - this.x1 = x1; - this.x2 = x2; - } - if (z1 > z2) { - this.z1 = z2; - this.z2 = z1; - } else { - this.z1 = z1; - this.z2 = z2; - } - } - - /** - * The tag of this chunk range. - */ - public final String tag; - /** - * Range of coordinates. x1 will never be higher than x2, as will z1 - * with z2. - */ - public final int x1, z1, x2, z2; - - /** - * Reads and creates a new ChunkRange from the given - * {@link ByteArrayDataInput}. - */ - public static ChunkRange readFromInput(ByteArrayDataInput input) { - String tag = input.readUTF(); - int x1 = input.readInt(); - int z1 = input.readInt(); - int x2 = input.readInt(); - int z2 = input.readInt(); - - return new ChunkRange(tag, x1, z1, x2, z2); - } - - /** - * Writes this ChunkRange to the given {@link ByteArrayDataOutput}. - * - * Note that I expect most serverside implementations will ignore the - * tag, but it still is included for clarity. The value in it can be - * anything so long as it is not null - an empty string will do. - */ - public void writeToOutput(ByteArrayDataOutput output) { - output.writeUTF(this.tag); - - output.writeInt(this.x1); - output.writeInt(this.z1); - output.writeInt(this.x2); - output.writeInt(this.z2); - } - - @Override - public String toString() { - return "ChunkRange [tag=" + tag + ", x1=" + x1 + ", z1=" + z1 - + ", x2=" + x2 + ", z2=" + z2 + "]"; - } - } -} diff --git a/share_14/src/main/java/wdl/api/APIImpl.java b/share_14/src/main/java/wdl/api/APIImpl.java index 68e881ff9..f790d6373 100644 --- a/share_14/src/main/java/wdl/api/APIImpl.java +++ b/share_14/src/main/java/wdl/api/APIImpl.java @@ -34,7 +34,7 @@ import wdl.VersionConstants; import wdl.WDL; import wdl.WDLMessages; -import wdl.WDLPluginChannels; +//import wdl.WDLPluginChannels; import wdl.api.WDLApi.ModInfo; import wdl.config.Setting; import wdl.config.settings.MiscSettings.ExtensionEnabledSetting; @@ -51,15 +51,15 @@ private APIImpl() { } // Internal use only @Override public void saveTileEntity(BlockPos pos, TileEntity te) { - if (!WDLPluginChannels.canSaveTileEntities(pos.getX() >> 4, - pos.getZ() >> 4)) { - LOGGER.warn("API attempted to call saveTileEntity when " + - "saving TileEntities is not allowed! Pos: " + pos + - ", te: " + te + ". StackTrace: "); - logStackTrace(); - - return; - } +// if (!WDLPluginChannels.canSaveTileEntities(pos.getX() >> 4, +// pos.getZ() >> 4)) { +// LOGGER.warn("API attempted to call saveTileEntity when " + +// "saving TileEntities is not allowed! Pos: " + pos + +// ", te: " + te + ". StackTrace: "); +// logStackTrace(); +// +// return; +// } WDL.getInstance().saveTileEntity(pos, te); } diff --git a/share_14/src/main/java/wdl/config/settings/EntitySettings.java b/share_14/src/main/java/wdl/config/settings/EntitySettings.java index 392fd7abd..15aa3bb9d 100644 --- a/share_14/src/main/java/wdl/config/settings/EntitySettings.java +++ b/share_14/src/main/java/wdl/config/settings/EntitySettings.java @@ -16,14 +16,14 @@ import static wdl.config.settings.Utils.*; import java.util.Map; -import java.util.function.BooleanSupplier; +//import java.util.function.BooleanSupplier; import com.google.common.annotations.VisibleForTesting; import net.minecraft.util.IStringSerializable; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TranslationTextComponent; -import wdl.WDLPluginChannels; +//import wdl.WDLPluginChannels; import wdl.config.CyclableSetting; import wdl.config.IConfiguration; @@ -38,7 +38,7 @@ public final class EntitySettings { new TrackDistanceModeSetting("Entity.TrackDistanceMode", "wdl.gui.entities.trackDistanceMode"); @VisibleForTesting - static BooleanSupplier hasServerEntityRange = WDLPluginChannels::hasServerEntityRange; +// static BooleanSupplier hasServerEntityRange = WDLPluginChannels::hasServerEntityRange; public enum TrackDistanceMode implements IStringSerializable { DEFAULT("default"), @@ -88,21 +88,23 @@ public String getConfigurationKey() { @Override public TrackDistanceMode getDefault(IConfiguration context) { - if (hasServerEntityRange.getAsBoolean()) { - return TrackDistanceMode.SERVER; - } else { - return TrackDistanceMode.DEFAULT; - } +// if (hasServerEntityRange.getAsBoolean()) { +// return TrackDistanceMode.SERVER; +// } else { +// return TrackDistanceMode.DEFAULT; +// } + return TrackDistanceMode.DEFAULT; } @Override public TrackDistanceMode cycle(TrackDistanceMode value) { if (value == TrackDistanceMode.DEFAULT) { - if (hasServerEntityRange.getAsBoolean()) { - return TrackDistanceMode.SERVER; - } else { - return TrackDistanceMode.USER; - } +// if (hasServerEntityRange.getAsBoolean()) { +// return TrackDistanceMode.SERVER; +// } else { +// return TrackDistanceMode.USER; +// } + return TrackDistanceMode.USER; } else if (value == TrackDistanceMode.SERVER) { return TrackDistanceMode.USER; } else { diff --git a/share_14/src/main/java/wdl/gui/GuiWDL.java b/share_14/src/main/java/wdl/gui/GuiWDL.java index d08f847cb..339f63a35 100644 --- a/share_14/src/main/java/wdl/gui/GuiWDL.java +++ b/share_14/src/main/java/wdl/gui/GuiWDL.java @@ -23,7 +23,7 @@ import net.minecraft.client.resources.I18n; import net.minecraft.util.text.TranslationTextComponent; import wdl.WDL; -import wdl.WDLPluginChannels; +//import wdl.WDLPluginChannels; import wdl.config.IConfiguration; import wdl.config.settings.MiscSettings; import wdl.gui.widget.ButtonDisplayGui; @@ -67,9 +67,9 @@ public ButtonEntry(String key, BiFunction openFunc, boolean this.button = this.addButton(new ButtonDisplayGui(0, 0, 200, 20, I18n.format("wdl.gui.wdl." + key + ".name"), () -> openFunc.apply(GuiWDL.this, GuiWDL.this.wdl)), -100, 0); - if (needsPerms) { - button.setEnabled(WDLPluginChannels.canDownloadAtAll()); - } +// if (needsPerms) { +// button.setEnabled(WDLPluginChannels.canDownloadAtAll()); +// } this.tooltip = I18n.format("wdl.gui.wdl." + key + ".description"); } @@ -94,7 +94,7 @@ public void drawEntry(int x, int y, int width, int height, int mouseX, int mouse entries.add(new ButtonEntry("backupOptions", GuiWDLBackup::new, true)); entries.add(new ButtonEntry("messageOptions", GuiWDLMessages::new, false)); entries.add(new ButtonEntry("savedChunks", GuiSavedChunks::new, true)); - entries.add(new ButtonEntry("permissionsInfo", GuiWDLPermissions::new, false)); +// entries.add(new ButtonEntry("permissionsInfo", GuiWDLPermissions::new, false)); entries.add(new ButtonEntry("about", GuiWDLAbout::new, false)); if (WDLUpdateChecker.hasNewVersion()) { // Put at start diff --git a/share_14/src/main/java/wdl/gui/GuiWDLChunkOverrides.java b/share_14/src/main/java/wdl/gui/GuiWDLChunkOverrides.java deleted file mode 100644 index 786cae968..000000000 --- a/share_14/src/main/java/wdl/gui/GuiWDLChunkOverrides.java +++ /dev/null @@ -1,409 +0,0 @@ -/* - * This file is part of World Downloader: A mod to make backups of your multiplayer worlds. - * https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/2520465-world-downloader-mod-create-backups-of-your-builds - * - * Copyright (c) 2014 nairol, cubic72 - * Copyright (c) 2017-2019 Pokechu22, julialy - * - * This project is licensed under the MMPLv2. The full text of the MMPL can be - * found in LICENSE.md, or online at https://github.com/iopleke/MMPLv2/blob/master/LICENSE.md - * For information about this the MMPLv2, see https://stopmodreposts.org/ - * - * Do not redistribute (in modified or unmodified form) without prior permission. - */ -package wdl.gui; - -import javax.annotation.Nullable; - -import com.google.common.collect.Multimap; -//import com.mojang.blaze3d.platform.GlStateManager; - -import net.minecraft.client.audio.SimpleSound; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.resources.I18n; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.SoundEvents; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.text.StringTextComponent; -import wdl.WDL; -import wdl.WDLPluginChannels; -import wdl.WDLPluginChannels.ChunkRange; -import wdl.gui.widget.ButtonDisplayGui; -import wdl.gui.widget.WDLButton; -import wdl.gui.widget.WDLScreen; -import wdl.versioned.VersionedFunctions; - -/** - * A GUI that lists and allows requesting chunk overrides. - * - * Also, expect a possible minimap integration in the future. - */ -public class GuiWDLChunkOverrides extends WDLScreen { - private static final int TOP_MARGIN = 61, BOTTOM_MARGIN = 32; - - /** - * Location of the button overlay textures. - */ - private static final ResourceLocation WIDGET_TEXTURES = new ResourceLocation( - "wdl:textures/permission_widgets.png"); - - private static enum Mode { - PANNING(0, 128), - REQUESTING(16, 128), - ERASING(32, 128), - MOVING(48, 128); - - private Mode(int overlayU, int overlayV) { - this.overlayU = overlayU; - this.overlayV = overlayV; - } - - /** - * Coordinates for the U and V of the texture for the button associated - * with this mode. - */ - public final int overlayU, overlayV; - } - - /** - * Parent GUI screen; displayed when this GUI is closed. - */ - @Nullable - private final Screen parent; - private final WDL wdl; - - private WDLButton startDownloadButton; - - /** - * The current position. - */ - private float scrollX, scrollZ; - /** - * How large each chunk is on-screen. - */ - private static final int SCALE = 8; - - /** - * Current mode for the GUI - */ - private Mode mode = Mode.PANNING; - - /** - * Is the request end coordinate being set (true) or start coordinate being - * set (false)? - */ - private boolean partiallyRequested; - /** - * Coordinates of the active request. - */ - private int requestStartX, requestStartZ, requestEndX, requestEndZ; - /** - * The position of the mouse on the last tick, for dragging. - */ - private int lastTickX, lastTickY; - - public GuiWDLChunkOverrides(@Nullable Screen parent, WDL wdl) { - super(new StringTextComponent("Chunk overrides")); - this.parent = parent; - this.wdl = wdl; - - if (wdl.player != null) { - this.scrollX = wdl.player.chunkCoordX; - this.scrollZ = wdl.player.chunkCoordZ; - } - } - - @Override - public void init() { - this.addButton(new RequestModeButton(width / 2 - 155, 18, Mode.PANNING) { - public @Override void performAction() { - GuiWDLChunkOverrides.this.mode = Mode.PANNING; - } - }); - this.addButton(new RequestModeButton(width / 2 - 130, 18, Mode.REQUESTING) { - public @Override void performAction() { - GuiWDLChunkOverrides.this.mode = Mode.REQUESTING; - partiallyRequested = false; - } - }); - this.addButton(new RequestModeButton(width / 2 - 105, 18, Mode.ERASING) { - { setEnabled(false); } - public @Override void performAction() { } - }); - this.addButton(new RequestModeButton(width / 2 - 80, 18, Mode.MOVING) { - { setEnabled(false); } - public @Override void performAction() { } - }); - - this.addButton(new WDLButton(width / 2 - 80, 18, 80, 20, - "Send request") { - public @Override void performAction() { - WDLPluginChannels.sendRequests(); - } - }); - - this.startDownloadButton = this.addButton(new WDLButton(width / 2 + 5, 18, 150, 20, - "Start download in these ranges") { - public @Override void performAction() { - if (!WDLPluginChannels.canDownloadAtAll()) { - setEnabled(false); - return; - } - wdl.startDownload(); - } - }); - startDownloadButton.setEnabled(WDLPluginChannels.canDownloadAtAll()); - - this.addButton(new ButtonDisplayGui(width / 2 - 100, height - 29, - 200, 20, this.parent)); - - this.addButton(new ButtonDisplayGui(this.width / 2 - 155, 39, 100, 20, - I18n.format("wdl.gui.permissions.current"), () -> new GuiWDLPermissions(this.parent, this.wdl))); - this.addButton(new ButtonDisplayGui(this.width / 2 - 50, 39, 100, 20, - I18n.format("wdl.gui.permissions.request"), () -> new GuiWDLPermissionRequest(this.parent, this.wdl))); - this.addButton(new WDLButton(this.width / 2 + 55, 39, 100, 20, - I18n.format("wdl.gui.permissions.overrides")) { - public @Override void performAction() { - // Would open this GUI; do nothing. - }; - }); - } - - @Override - public void mouseDown(int mouseX, int mouseY) { - if (mouseY > TOP_MARGIN && mouseY < height - BOTTOM_MARGIN) { - switch (mode) { - case PANNING: - lastTickX = mouseX; - lastTickY = mouseY; - break; - case REQUESTING: - if (partiallyRequested) { - requestEndX = displayXToChunkX(mouseX); - requestEndZ = displayZToChunkZ(mouseY); - - ChunkRange requestRange = new ChunkRange("", requestStartX, - requestStartZ, requestEndX, requestEndZ); - WDLPluginChannels.addChunkOverrideRequest(requestRange); - - partiallyRequested = false; - } else { - requestStartX = displayXToChunkX(mouseX); - requestStartZ = displayZToChunkZ(mouseY); - - partiallyRequested = true; - } - - minecraft.getSoundHandler().play(SimpleSound.master( - SoundEvents.UI_BUTTON_CLICK, 1.0F)); - break; - case ERASING: - // TODO - minecraft.getSoundHandler().play(SimpleSound.master( - SoundEvents.BLOCK_DISPENSER_FAIL, 1.0F)); - break; - case MOVING: - // TODO - minecraft.getSoundHandler().play(SimpleSound.master( - SoundEvents.BLOCK_DISPENSER_FAIL, 1.0F)); - break; - } - } - } - - @Override - public void mouseDragged(int mouseX, int mouseY) { - int deltaX = lastTickX - mouseX; - int deltaY = lastTickY - mouseY; - - lastTickX = mouseX; - lastTickY = mouseY; - - if (mode == Mode.PANNING) { - scrollX += deltaX / (float)SCALE; - scrollZ += deltaY / (float)SCALE; - } - } - - @Override - public void render(int mouseX, int mouseY, float partialTicks) { - VersionedFunctions.drawDarkBackground(0, 0, height, width); - - // Draw the current request range. - if (mode == Mode.REQUESTING) { - int x1 = (partiallyRequested ? requestStartX : displayXToChunkX(mouseX)); - int z1 = (partiallyRequested ? requestStartZ : displayZToChunkZ(mouseY)); - int x2 = displayXToChunkX(mouseX); - int z2 = displayZToChunkZ(mouseY); - - // TODO: Maybe cache this range in some way rather than creating a new one each frame - ChunkRange requestRange = new ChunkRange("", x1, z1, x2, z2); - - // Fancy sin alpha changing by time. - int alpha = 127 + (int)(Math.sin(System.currentTimeMillis() * Math.PI / 5000) * 64); - drawRange(requestRange, 0xffffff, alpha); - } - - // Draw current ranges - for (Multimap group : WDLPluginChannels.getChunkOverrides().values()) { - for (ChunkRange range : group.values()) { - drawRange(range, RNG_SEED, 0xFF); - } - } - for (ChunkRange range : WDLPluginChannels.getChunkOverrideRequests()) { - // Fancy sin alpha changing by time. - int alpha = 127 + (int)(Math.sin(System.currentTimeMillis() * Math.PI / 5000) * 64); - drawRange(range, 0x808080, alpha); - } - - // Player position. - int playerPosX = (int)(((VersionedFunctions.getEntityX(wdl.player) / 16.0D) - scrollX) * SCALE + (width / 2)); - int playerPosZ = (int)(((VersionedFunctions.getEntityZ(wdl.player) / 16.0D) - scrollZ) * SCALE + (height / 2)); - - hLine(playerPosX - 3, playerPosX + 3, playerPosZ, 0xFFFFFFFF); - // Vertical is 1px taller because it seems to be needed to make it proportional - vLine(playerPosX, playerPosZ - 4, playerPosZ + 4, 0xFFFFFFFF); - - // Draw the main borders now so that ranges are hidden behind it. - Utils.drawBorder(TOP_MARGIN, BOTTOM_MARGIN, 0, 0, height, width); - - super.render(mouseX, mouseY, partialTicks); - - this.drawCenteredString(this.font, "\u00A7c\u00A7lThis is a work in progress.", - this.width / 2, this.height / 2, 0xFFFFFF); - } - - /** - * Default color for a chunk range with tag. Xor'd with the hashcode.
- * Preview:            - */ - private static final int RNG_SEED = 0xBBDFC; - - /** - * Draws the given range at the proper position on screen. - * - * @param range The range to draw. - * @param seed The default color for a tagless range. (See {@link #RNG_SEED}) - * @param alpha The transparency. 0xFF: Fully solid, 0x00: Fully transparent - */ - private void drawRange(ChunkRange range, int seed, int alpha) { - int color = (range.tag.hashCode() ^ seed) & 0x00FFFFFF; - - int x1 = chunkXToDisplayX(range.x1); - int z1 = chunkZToDisplayZ(range.z1); - int x2 = chunkXToDisplayX(range.x2) + SCALE - 1; - int z2 = chunkZToDisplayZ(range.z2) + SCALE - 1; - - fill(x1, z1, x2, z2, color + (alpha << 24)); - - int colorDark = darken(color); - - vLine(x1, z1, z2, colorDark + (alpha << 24)); - vLine(x2, z1, z2, colorDark + (alpha << 24)); - hLine(x1, x2, z1, colorDark + (alpha << 24)); - hLine(x1, x2, z2, colorDark + (alpha << 24)); - } - - /** - * Converts a chunk x coordinate to a display x coordinate, taking - * into account the value of {@link scrollX}. - * - * @param chunkX The chunk's x coordinate. - * @return The display position. - */ - private int chunkXToDisplayX(int chunkX) { - return (int)((chunkX - scrollX) * SCALE + (width / 2)); - } - - /** - * Converts a chunk z coordinate to a display z coordinate, taking - * into account the value of {@link scrollZ}. - * - * @param chunkZ The chunk's z coordinate. - * @return The display position. - */ - private int chunkZToDisplayZ(int chunkZ) { - return (int)((chunkZ - scrollZ) * SCALE + (height / 2)); - } - - /** - * Converts a display x coordinate to a chunk x coordinate, taking - * into account the value of {@link scrollX}. - * - * @param displayX The display x coordinate. - * @return The chunk position. - */ - private int displayXToChunkX(int displayX) { - return MathHelper.floor((displayX - (float)(width / 2)) / SCALE + scrollX); - } - - /** - * Converts a display z coordinate to a chunk z coordinate, taking - * into account the value of {@link scrollZ}. - * - * @param displayZ The display z coordinate. - * @return The chunk position. - */ - private int displayZToChunkZ(int displayZ) { - return MathHelper.floor((displayZ - (float)(height / 2)) / SCALE + scrollZ); - } - - /** - * Halves the brightness of the given color. - */ - private int darken(int color) { - int r = (color >> 16) & 0xFF; - int g = (color >> 8) & 0xFF; - int b = color & 0xFF; - - r /= 2; - g /= 2; - b /= 2; - - return (r << 16) + (g << 8) + b; - } - - /** - * Button for a mode that displays the icon for the given mode. - */ - private abstract class RequestModeButton extends WDLButton { - /** - * The mode for this button. - */ - public final Mode mode; - - /** - * Constructor - * @param buttonId - * @param x - * @param y - * @param mode - */ - public RequestModeButton(int x, int y, Mode mode) { - super(x, y, 20, 20, ""); - this.mode = mode; - } - - @Override - public void beforeDraw() { - if (GuiWDLChunkOverrides.this.mode == this.mode) { - // Mode is currently selected - draw a green outline. - fill(this.x - 2, this.y - 2, - this.x + width + 2, this.y + height + 2, - 0xFF007F00); - } - } - - @Override - public void afterDraw() { - // Reset the color, which gets set somewhere (probably when drawing text) - //GlStateManager.color3f(1.0f, 1.0f, 1.0f); XXX broken until 1.15 names work - minecraft.getTextureManager().bindTexture(WIDGET_TEXTURES); - - this.blit(this.x + 2, this.y + 2, - mode.overlayU, mode.overlayV, 16, 16); - } - } -} diff --git a/share_14/src/main/java/wdl/gui/GuiWDLEntityRangePresets.java b/share_14/src/main/java/wdl/gui/GuiWDLEntityRangePresets.java index 3ff0908bb..9c44b71fc 100644 --- a/share_14/src/main/java/wdl/gui/GuiWDLEntityRangePresets.java +++ b/share_14/src/main/java/wdl/gui/GuiWDLEntityRangePresets.java @@ -26,7 +26,7 @@ import wdl.EntityUtils; import wdl.EntityUtils.SpigotEntityType; import wdl.WDL; -import wdl.WDLPluginChannels; +//import wdl.WDLPluginChannels; import wdl.config.IConfiguration; import wdl.gui.widget.ButtonDisplayGui; import wdl.gui.widget.WDLButton; @@ -43,7 +43,7 @@ public class GuiWDLEntityRangePresets extends WDLScreen { private WDLButton vanillaButton; private WDLButton spigotButton; - private WDLButton serverButton; +// private WDLButton serverButton; private WDLButton cancelButton; private static final int ID_VANILLA = 0, ID_SPIGOT = 1, ID_SERVER = 2; @@ -69,14 +69,14 @@ public void init() { I18n.format("wdl.gui.rangePresets.spigot"), makeYesNoGui("wdl.gui.rangePresets.spigot.warning", ID_SPIGOT))); y += 22; - this.serverButton = this.addButton(new ButtonDisplayGui( - this.width / 2 - 100, y, 200, 20, - I18n.format("wdl.gui.rangePresets.server"), - makeYesNoGui("wdl.gui.rangePresets.spigot.warning", ID_SERVER))); - - serverButton.setEnabled(WDLPluginChannels.hasServerEntityRange()); +// this.serverButton = this.addButton(new ButtonDisplayGui( +// this.width / 2 - 100, y, 200, 20, +// I18n.format("wdl.gui.rangePresets.server"), +// makeYesNoGui("wdl.gui.rangePresets.spigot.warning", ID_SERVER))); +// +//// serverButton.setEnabled(WDLPluginChannels.hasServerEntityRange()); - y += 28; +// y += 28; this.cancelButton = this.addButton(new ButtonDisplayGui( this.width / 2 - 100, this.height - 29, 200, 20, @@ -100,15 +100,17 @@ public void render(int mouseX, int mouseY, float partialTicks) { infoText = I18n.format("wdl.gui.rangePresets.vanilla.description"); } else if (spigotButton.isHovered()) { infoText = I18n.format("wdl.gui.rangePresets.spigot.description"); - } else if (serverButton.isHovered()) { - infoText = I18n.format("wdl.gui.rangePresets.server.description") + "\n\n"; - - if (serverButton.isEnabled()) { - infoText += I18n.format("wdl.gui.rangePresets.server.installed"); - } else { - infoText += I18n.format("wdl.gui.rangePresets.server.notInstalled"); - } - } else if (cancelButton.isHovered()) { + } +// else if (serverButton.isHovered()) { +// infoText = I18n.format("wdl.gui.rangePresets.server.description") + "\n\n"; +// +// if (serverButton.isEnabled()) { +// infoText += I18n.format("wdl.gui.rangePresets.server.installed"); +// } else { +// infoText += I18n.format("wdl.gui.rangePresets.server.notInstalled"); +// } +// } + else if (cancelButton.isHovered()) { infoText = I18n.format("wdl.gui.rangePresets.cancel.description"); } @@ -137,8 +139,9 @@ private void confirmResult(boolean result, int id) { } } else if (id == ID_SERVER) { for (String entity : entities) { - config.setUserEntityTrackDistance(entity, - WDLPluginChannels.getEntityRange(entity)); +// config.setUserEntityTrackDistance(entity, +// WDLPluginChannels.getEntityRange(entity)); + config.setUserEntityTrackDistance(entity, EntityUtils.STANDARD_VANILLA_MANAGER.getTrackDistance(entity, null)); } } } diff --git a/share_14/src/main/java/wdl/gui/GuiWDLPermissionRequest.java b/share_14/src/main/java/wdl/gui/GuiWDLPermissionRequest.java deleted file mode 100644 index c63562f78..000000000 --- a/share_14/src/main/java/wdl/gui/GuiWDLPermissionRequest.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * This file is part of World Downloader: A mod to make backups of your multiplayer worlds. - * https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/2520465-world-downloader-mod-create-backups-of-your-builds - * - * Copyright (c) 2014 nairol, cubic72 - * Copyright (c) 2017-2019 Pokechu22, julialy - * - * This project is licensed under the MMPLv2. The full text of the MMPL can be - * found in LICENSE.md, or online at https://github.com/iopleke/MMPLv2/blob/master/LICENSE.md - * For information about this the MMPLv2, see https://stopmodreposts.org/ - * - * Do not redistribute (in modified or unmodified form) without prior permission. - */ -package wdl.gui; - -import java.util.Map; - -import javax.annotation.Nullable; - -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.client.resources.I18n; -import net.minecraft.util.text.StringTextComponent; -import wdl.WDL; -import wdl.WDLPluginChannels; -import wdl.gui.widget.ButtonDisplayGui; -import wdl.gui.widget.TextList; -import wdl.gui.widget.WDLButton; -import wdl.gui.widget.WDLScreen; - -/** - * GUI for requesting permissions. Again, this is a work in progress. - */ -public class GuiWDLPermissionRequest extends WDLScreen { - private static final int TOP_MARGIN = 61, BOTTOM_MARGIN = 32; - - private TextList list; - /** - * Parent GUI screen; displayed when this GUI is closed. - */ - @Nullable - private final Screen parent; - private final WDL wdl; - /** - * Field in which the wanted request is entered. - */ - private TextFieldWidget requestField; - /** - * Button for submitting the request. - */ - private WDLButton submitButton; - - public GuiWDLPermissionRequest(@Nullable Screen parent, WDL wdl) { - super(new StringTextComponent("Permission request")); // XXX Untranslated - this.parent = parent; - this.wdl = wdl; - } - - @Override - public void init() { - this.list = this.addList(new TextList(minecraft, width, height, TOP_MARGIN, BOTTOM_MARGIN)); - - list.addLine("\u00A7c\u00A7lThis is a work in progress."); - list.addLine("You can request permissions in this GUI, although " + - "it currently requires manually specifying the names."); - list.addBlankLine(); - list.addLine("Boolean fields: " + WDLPluginChannels.BOOLEAN_REQUEST_FIELDS); - list.addLine("Integer fields: " + WDLPluginChannels.INTEGER_REQUEST_FIELDS); - list.addBlankLine(); - - - //Get the existing requests. - for (Map.Entry request : WDLPluginChannels - .getRequests().entrySet()) { - list.addLine("Requesting '" + request.getKey() + "' to be '" - + request.getValue() + "'."); - } - - this.requestField = this.addTextField(new TextFieldWidget(font, - width / 2 - 155, 18, 150, 20, "Request")); - - this.submitButton = this.addButton(new WDLButton( - width / 2 + 5, 18, 150, 20, - "Submit request") { - public @Override void performAction() { - WDLPluginChannels.sendRequests(); - setMessage("Submitted!"); - } - }); - this.submitButton.setEnabled(!(WDLPluginChannels.getRequests().isEmpty())); - - this.addButton(new ButtonDisplayGui(width / 2 - 100, height - 29, - 200, 20, this.parent)); - - this.addButton(new ButtonDisplayGui(this.width / 2 - 155, 39, 100, 20, - I18n.format("wdl.gui.permissions.current"), () -> new GuiWDLPermissions(this.parent, this.wdl))); - this.addButton(new WDLButton(this.width / 2 - 50, 39, 100, 20, - I18n.format("wdl.gui.permissions.request")) { - public @Override void performAction() { - // Would open this GUI; do nothing. - } - }); - this.addButton(new ButtonDisplayGui(this.width / 2 + 55, 39, 100, 20, - I18n.format("wdl.gui.permissions.overrides"), () -> new GuiWDLChunkOverrides(this.parent, this.wdl))); - } - - @Override - public void charTyped(char keyChar) { - if (requestField.isFocused()) { - String request = requestField.getText(); - if (isValidRequest(request) && keyChar == '\n') { - String[] requestData = request.split("=", 2); - String key = requestData[0]; - String value = requestData[1]; - - WDLPluginChannels.addRequest(key, value); - list.addLine("Requesting '" + key + "' to be '" - + value + "'."); - submitButton.setEnabled(true); - - requestField.setText(""); - } - } - } - - @Override - public void anyKeyPressed() { - if (requestField.isFocused()) { - String request = requestField.getText(); - requestField.setTextColor(isValidRequest(request) ? 0x40E040 : 0xE04040); - } - } - - private boolean isValidRequest(String request) { - if (request.contains("=")) { - String[] requestData = request.split("=", 2); - if (requestData.length == 2) { - String key = requestData[0]; - String value = requestData[1]; - - return WDLPluginChannels.isValidRequest(key, value); - } - } - return false; - } -} diff --git a/share_14/src/main/java/wdl/gui/GuiWDLPermissions.java b/share_14/src/main/java/wdl/gui/GuiWDLPermissions.java deleted file mode 100644 index b2ab7af05..000000000 --- a/share_14/src/main/java/wdl/gui/GuiWDLPermissions.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * This file is part of World Downloader: A mod to make backups of your multiplayer worlds. - * https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/2520465-world-downloader-mod-create-backups-of-your-builds - * - * Copyright (c) 2014 nairol, cubic72 - * Copyright (c) 2017-2019 Pokechu22, julialy - * - * This project is licensed under the MMPLv2. The full text of the MMPL can be - * found in LICENSE.md, or online at https://github.com/iopleke/MMPLv2/blob/master/LICENSE.md - * For information about this the MMPLv2, see https://stopmodreposts.org/ - * - * Do not redistribute (in modified or unmodified form) without prior permission. - */ -package wdl.gui; - -import javax.annotation.Nullable; - -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.resources.I18n; -import net.minecraft.util.text.StringTextComponent; -import wdl.WDL; -import wdl.WDLPluginChannels; -import wdl.gui.widget.WDLButton; -import wdl.gui.widget.WDLScreen; -import wdl.gui.widget.ButtonDisplayGui; -import wdl.gui.widget.TextList; - -/** - * GUI that shows the current permissions for the user. - */ -public class GuiWDLPermissions extends WDLScreen { - /** - * Margins for the top and the bottom of the list. - */ - private static final int TOP_MARGIN = 61, BOTTOM_MARGIN = 32; - - /** - * Ticks (20ths of a second) until this UI needs to refresh. - * - * If -1, don't refresh. - */ - private int refreshTicks = -1; - - @Nullable - private final Screen parent; - private final WDL wdl; - - private TextList list; - - /** - * Creates a new GUI with the given parent. - * - * @param parent - */ - public GuiWDLPermissions(@Nullable Screen parent, WDL wdl) { - super(new StringTextComponent("Permission info")); // XXX Untranslated - this.parent = parent; - this.wdl = wdl; - } - - @Override - public void init() { - this.addButton(new ButtonDisplayGui(width / 2 - 100, height - 29, - 200, 20, this.parent)); - - this.addButton(new WDLButton(this.width / 2 - 155, 39, 100, 20, - I18n.format("wdl.gui.permissions.current")) { - public @Override void performAction() { - // Would open this GUI; do nothing. - }; - }); - if (WDLPluginChannels.canRequestPermissions()) { - this.addButton(new ButtonDisplayGui(this.width / 2 - 50, 39, 100, 20, - I18n.format("wdl.gui.permissions.request"), () -> new GuiWDLPermissionRequest(this.parent, this.wdl))); - this.addButton(new ButtonDisplayGui(this.width / 2 + 55, 39, 100, 20, - I18n.format("wdl.gui.permissions.overrides"), () -> new GuiWDLChunkOverrides(this.parent, this.wdl))); - } - - this.addButton(new WDLButton((this.width / 2) + 5, 18, 150, 20, - "Reload permissions") { - public @Override void performAction() { - // Send the init packet. - WDLPluginChannels.sendInitPacket("Refresh?"); - - setEnabled(false); - setMessage("Refreshing..."); - - refreshTicks = 50; // 2.5 seconds - } - }); - - this.list = this.addList(new TextList(minecraft, width, height, TOP_MARGIN, BOTTOM_MARGIN)); - - list.addLine("\u00A7c\u00A7lThis is a work in progress."); - - if (!WDLPluginChannels.hasPermissions()) { - return; - } - - list.addBlankLine(); - if (!WDLPluginChannels.canRequestPermissions()) { - list.addLine("\u00A7cThe serverside permission plugin is out of date " + - "and does support permission requests. Please go ask a " + - "server administrator to update the plugin."); - list.addBlankLine(); - } - - if (WDLPluginChannels.getRequestMessage() != null) { - list.addLine("Note from the server moderators: "); - list.addLine(WDLPluginChannels.getRequestMessage()); - list.addBlankLine(); - } - - list.addLine("These are your current permissions:"); - // TODO: I'd like to return the description lines here, but can't yet. - // Of course, I'd need to put in some better lines than before. - // Maybe also skip unsent permissions? - list.addLine("Can download: " - + WDLPluginChannels.canDownloadInGeneral()); - list.addLine("Can save chunks as you move: " + WDLPluginChannels.canCacheChunks()); - if (!WDLPluginChannels.canCacheChunks() && WDLPluginChannels.canDownloadInGeneral()) { - list.addLine("Nearby chunk save radius: " + WDLPluginChannels.getSaveRadius()); - } - list.addLine("Can save entities: " - + WDLPluginChannels.canSaveEntities()); - list.addLine("Can save tile entities: " - + WDLPluginChannels.canSaveTileEntities()); - list.addLine("Can save containers: " - + WDLPluginChannels.canSaveContainers()); - list.addLine("Received entity ranges: " - + WDLPluginChannels.hasServerEntityRange() + " (" - + WDLPluginChannels.getEntityRanges().size() + " total)"); - } - - @Override - public void tick() { - if (refreshTicks > 0) { - refreshTicks--; - } else if (refreshTicks == 0) { - init(); - refreshTicks = -1; - } - super.tick(); - } - - @Override - public void removed() { - wdl.saveProps(); - } - - @Override - public void render(int mouseX, int mouseY, float partialTicks) { - super.render(mouseX, mouseY, partialTicks); - - if (!WDLPluginChannels.hasPermissions()) { - this.drawCenteredString(this.font, - "No permissions received; defaulting to everything enabled.", - this.width / 2, (this.height - 32 - 23) / 2 + 23 - - font.FONT_HEIGHT / 2, 0xFFFFFF); - } - } -} diff --git a/share_14/src/test/java/wdl/config/settings/EntitySettingsTest.java b/share_14/src/test/java/wdl/config/settings/EntitySettingsTest.java deleted file mode 100644 index c5c095df1..000000000 --- a/share_14/src/test/java/wdl/config/settings/EntitySettingsTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of World Downloader: A mod to make backups of your multiplayer worlds. - * https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/2520465-world-downloader-mod-create-backups-of-your-builds - * - * Copyright (c) 2014 nairol, cubic72 - * Copyright (c) 2018 Pokechu22, julialy - * - * This project is licensed under the MMPLv2. The full text of the MMPL can be - * found in LICENSE.md, or online at https://github.com/iopleke/MMPLv2/blob/master/LICENSE.md - * For information about this the MMPLv2, see https://stopmodreposts.org/ - * - * Do not redistribute (in modified or unmodified form) without prior permission. - */ -package wdl.config.settings; - -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import static wdl.config.settings.SettingTestUtils.*; - -import java.util.function.BooleanSupplier; - -import org.junit.Test; - -import wdl.MaybeMixinTest; -import wdl.config.Configuration; -import wdl.config.DefaultConfiguration; -import wdl.config.IConfiguration; -import wdl.config.settings.EntitySettings.TrackDistanceMode; - -public class EntitySettingsTest extends MaybeMixinTest { - - @Test - public void testTrackDistanceMode() { - doWithHasServerRange(() -> true, () -> { - checkAllText(EntitySettings.TRACK_DISTANCE_MODE); - checkParsability(EntitySettings.TRACK_DISTANCE_MODE); - }); - } - - @Test - public void testCycleSimple() { - doWithHasServerRange(() -> false, () -> { - IConfiguration config = new Configuration(new DefaultConfiguration()); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.DEFAULT)); // default - config.cycle(EntitySettings.TRACK_DISTANCE_MODE); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.USER)); - config.cycle(EntitySettings.TRACK_DISTANCE_MODE); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.DEFAULT)); - }); - doWithHasServerRange(() -> true, () -> { - IConfiguration config = new Configuration(new DefaultConfiguration()); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.SERVER)); // default - config.cycle(EntitySettings.TRACK_DISTANCE_MODE); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.USER)); - config.cycle(EntitySettings.TRACK_DISTANCE_MODE); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.DEFAULT)); - config.cycle(EntitySettings.TRACK_DISTANCE_MODE); - assertThat(config.getValue(EntitySettings.TRACK_DISTANCE_MODE), is(TrackDistanceMode.SERVER)); - }); - } - - private synchronized void doWithHasServerRange(BooleanSupplier hasServerRange, Runnable action) { - BooleanSupplier old = EntitySettings.hasServerEntityRange; - try { - EntitySettings.hasServerEntityRange = hasServerRange; - action.run(); - } finally { - EntitySettings.hasServerEntityRange = old; - } - } -}