From c29db9b7295e3051bc26caba74958a97f92f1e6b Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 12:02:36 -0400 Subject: [PATCH 01/17] Minor Changes Cleaned up the code in DDCommandBase a little. --- .../mod_pocketDim/commands/DDCommandBase.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandBase.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandBase.java index b62cc86..badb0a2 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandBase.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandBase.java @@ -5,7 +5,6 @@ import net.minecraft.command.ICommand; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChatMessageComponent; -import cpw.mods.fml.common.event.FMLServerStartingEvent; /* * An abstract base class for our Dimensional Doors commands. This cleans up the code a little and provides @@ -96,13 +95,15 @@ public abstract class DDCommandBase extends CommandBase * that Dryware and Technic Jenkins don't have those functions defined. How in the world? * I have no idea. But it's breaking our builds. -_- ~SenseiKiwi */ - public int compareTo(ICommand par1ICommand) + @Override + public int compareTo(ICommand command) { - return this.getCommandName().compareTo(par1ICommand.getCommandName()); + return this.getCommandName().compareTo(command.getCommandName()); } - public int compareTo(Object par1Obj) + @Override + public int compareTo(Object other) { - return this.compareTo((ICommand)par1Obj); + return this.compareTo((ICommand) other); } } -- 2.39.5 From 262595ff4d5555212943252b9b079a2774109cd8 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 12:25:00 -0400 Subject: [PATCH 02/17] Changes to Commands 1. Fixed some warnings in the affected commands. 2. Removed checks for whether a command is running on the server or client side. We have performed those checks inconsistently throughout our commands without problems. I assume that they must be running on the server side only. If I'm wrong, we can add a check to DDCommandBase. 3. Minor punctuation change in DDCommandResult --- .../commands/CommandCreateDungeonRift.java | 14 +-- .../commands/CommandCreatePocket.java | 32 +++--- .../commands/CommandCreateRandomRift.java | 11 +-- .../commands/CommandDeleteAllLinks.java | 11 +-- .../commands/CommandDeleteRifts.java | 2 - .../commands/CommandExportDungeon.java | 97 ++++++++----------- .../commands/CommandResetDungeons.java | 2 - .../commands/CommandTeleportPlayer.java | 11 +-- .../commands/DDCommandResult.java | 2 +- 9 files changed, 66 insertions(+), 116 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java index b1512e3..686b5d3 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java @@ -1,5 +1,9 @@ package StevenDimDoors.mod_pocketDim.commands; +import java.util.Collection; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.MathHelper; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.LinkTypes; @@ -9,12 +13,6 @@ import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.world.PocketBuilder; -import java.util.Collection; - -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.MathHelper; - public class CommandCreateDungeonRift extends DDCommandBase { private static CommandCreateDungeonRift instance = null; @@ -38,10 +36,6 @@ public class CommandCreateDungeonRift extends DDCommandBase NewDimData dimension; DungeonHelper dungeonHelper = DungeonHelper.instance(); - if (sender.worldObj.isRemote) - { - return DDCommandResult.SUCCESS; - } if (command.length == 0) { return DDCommandResult.TOO_FEW_ARGUMENTS; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java index b2843a6..9de7a3a 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java @@ -1,6 +1,5 @@ package StevenDimDoors.mod_pocketDim.commands; -import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; @@ -24,26 +23,21 @@ public class CommandCreatePocket extends DDCommandBase @Override protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { - //TODO: Some commands have isRemote checks, some do not. Why? Can commands even run locally anyway? - //What does it mean when you run a command locally? ~SenseiKiwi - - if (!sender.worldObj.isRemote) + if (command.length > 0) { - if (command.length > 0) - { - return DDCommandResult.TOO_MANY_ARGUMENTS; - } - - //Place a door leading to a pocket dimension where the player is standing. - //The pocket dimension will serve as a room for the player to build a dungeon. - int x = (int) sender.posX; - int y = (int) sender.posY; - int z = (int) sender.posZ; - DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z); - - //Notify the player - sendChat(sender,("Created a door to a pocket dimension. Please build your dungeon there.")); + return DDCommandResult.TOO_MANY_ARGUMENTS; } + + //Place a door leading to a pocket dimension where the player is standing. + //The pocket dimension will serve as a room for the player to build a dungeon. + int x = (int) sender.posX; + int y = (int) sender.posY; + int z = (int) sender.posZ; + DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z); + + //Notify the player + sendChat(sender, "Created a door to a pocket dimension. Please build your dungeon there."); + return DDCommandResult.SUCCESS; } } \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java index 97cc1a5..646fda3 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java @@ -38,11 +38,7 @@ public class CommandCreateRandomRift extends DDCommandBase { NewDimData dimension; DungeonHelper dungeonHelper = DungeonHelper.instance(); - - if (sender.worldObj.isRemote) - { - return DDCommandResult.SUCCESS; - } + if (command.length > 1) { return DDCommandResult.TOO_MANY_ARGUMENTS; @@ -118,9 +114,6 @@ public class CommandCreateRandomRift extends DDCommandBase { return null; } - else - { - return matches.get( random.nextInt(matches.size()) ); - } + return matches.get( random.nextInt(matches.size()) ); } } \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java index 317b101..af9f915 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java @@ -1,16 +1,13 @@ package StevenDimDoors.mod_pocketDim.commands; +import java.util.ArrayList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import java.util.ArrayList; - -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; - -@SuppressWarnings("deprecation") public class CommandDeleteAllLinks extends DDCommandBase { private static CommandDeleteAllLinks instance = null; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java index 328576c..a2aac97 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java @@ -2,7 +2,6 @@ package StevenDimDoors.mod_pocketDim.commands; import java.util.ArrayList; -import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.mod_pocketDim; @@ -10,7 +9,6 @@ import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -@SuppressWarnings("deprecation") public class CommandDeleteRifts extends DDCommandBase { private static CommandDeleteRifts instance = null; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandExportDungeon.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandExportDungeon.java index 4c0ad4d..84b9584 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandExportDungeon.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandExportDungeon.java @@ -2,7 +2,6 @@ package StevenDimDoors.mod_pocketDim.commands; import java.io.File; -import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; @@ -60,66 +59,51 @@ public class CommandExportDungeon extends DDCommandBase //Export the schematic return exportDungeon(sender, command[0]); } - else - { - //The schematic name contains illegal characters. Inform the user. - return new DDCommandResult("Error: Invalid schematic name. Please use only letters, numbers, dashes, and underscores."); - } - } - else - { - //The command is malformed in some way. Assume that the user meant to use - //the 3-argument version and report an error. - return DDCommandResult.TOO_FEW_ARGUMENTS; + //The schematic name contains illegal characters. Inform the user. + return new DDCommandResult("Error: Invalid schematic name. Please use only letters, numbers, dashes, and underscores."); } + //The command is malformed in some way. Assume that the user meant to use + //the 3-argument version and report an error. + return DDCommandResult.TOO_FEW_ARGUMENTS; } //The user must have used the 3-argument version of this command - //TODO: Why do we check remoteness here but not before? And why not for the other export case? - //Something feels wrong... ~SenseiKiwi - if (!sender.worldObj.isRemote) + //TODO: This validation should be in DungeonHelper or in another class. We should move it + //during the save file format rewrite. ~SenseiKiwi + + if (!dungeonHelper.validateDungeonType(command[0], dungeonHelper.getDungeonPack("ruins"))) { - //TODO: This validation should be in DungeonHelper or in another class. We should move it - //during the save file format rewrite. ~SenseiKiwi - - if (!dungeonHelper.validateDungeonType(command[0], dungeonHelper.getDungeonPack("ruins"))) - { - return new DDCommandResult("Error: Invalid dungeon type. Please use one of the existing types."); - } - if (!DungeonHelper.DUNGEON_NAME_PATTERN.matcher(command[1]).matches()) - { - return new DDCommandResult("Error: Invalid dungeon name. Please use only letters, numbers, and dashes."); - } - if (!command[2].equalsIgnoreCase("open") && !command[2].equalsIgnoreCase("closed")) - { - return new DDCommandResult("Error: Please specify whether the dungeon is 'open' or 'closed'."); - } - - //If there are no more arguments, export the dungeon. - if (command.length == 3) - { - return exportDungeon(sender, join(command, "_", 0, 3)); - } - else - { - //Validate the weight argument - try - { - int weight = Integer.parseInt(command[3]); - if (weight >= DungeonHelper.MIN_DUNGEON_WEIGHT && weight <= DungeonHelper.MAX_DUNGEON_WEIGHT) - { - return exportDungeon(sender, join(command, "_", 0, 4)); - } - } - catch (Exception e) { } - } - - //If we've reached this point, then we must have an invalid weight. - return new DDCommandResult("Invalid dungeon weight. Please specify a weight between " - + DungeonHelper.MIN_DUNGEON_WEIGHT + " and " + DungeonHelper.MAX_DUNGEON_WEIGHT + ", inclusive."); + return new DDCommandResult("Error: Invalid dungeon type. Please use one of the existing types."); + } + if (!DungeonHelper.DUNGEON_NAME_PATTERN.matcher(command[1]).matches()) + { + return new DDCommandResult("Error: Invalid dungeon name. Please use only letters, numbers, and dashes."); + } + if (!command[2].equalsIgnoreCase("open") && !command[2].equalsIgnoreCase("closed")) + { + return new DDCommandResult("Error: Please specify whether the dungeon is 'open' or 'closed'."); } - return DDCommandResult.SUCCESS; + //If there are no more arguments, export the dungeon. + if (command.length == 3) + { + return exportDungeon(sender, join(command, "_", 0, 3)); + } + + //Validate the weight argument + try + { + int weight = Integer.parseInt(command[3]); + if (weight >= DungeonHelper.MIN_DUNGEON_WEIGHT && weight <= DungeonHelper.MAX_DUNGEON_WEIGHT) + { + return exportDungeon(sender, join(command, "_", 0, 4)); + } + } + catch (Exception e) { } + + //If we've reached this point, then we must have an invalid weight. + return new DDCommandResult("Invalid dungeon weight. Please specify a weight between " + + DungeonHelper.MIN_DUNGEON_WEIGHT + " and " + DungeonHelper.MAX_DUNGEON_WEIGHT + ", inclusive."); } private static DDCommandResult exportDungeon(EntityPlayer player, String name) @@ -137,10 +121,7 @@ public class CommandExportDungeon extends DDCommandBase dungeonHelper.registerDungeon(exportPath, dungeonHelper.getDungeonPack("ruins"), false, true); return DDCommandResult.SUCCESS; } - else - { - return new DDCommandResult("Error: Failed to save dungeon schematic!"); - } + return new DDCommandResult("Error: Failed to save dungeon schematic!"); } private static String join(String[] source, String delimiter, int start, int end) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java index f9ed088..b3535cf 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java @@ -2,7 +2,6 @@ package StevenDimDoors.mod_pocketDim.commands; import java.util.ArrayList; -import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.core.DimLink; @@ -10,7 +9,6 @@ import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -@SuppressWarnings("deprecation") public class CommandResetDungeons extends DDCommandBase { private static CommandResetDungeons instance = null; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java index 1b29999..93b4d3f 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java @@ -1,16 +1,11 @@ package StevenDimDoors.mod_pocketDim.commands; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.util.Point4D; -import java.util.Arrays; -import java.util.List; - -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.common.DimensionManager; - public class CommandTeleportPlayer extends DDCommandBase { private static CommandTeleportPlayer instance = null; @@ -121,7 +116,7 @@ public class CommandTeleportPlayer extends DDCommandBase return DDCommandResult.SUCCESS; } - public boolean isInteger( String input ) + public static boolean isInteger( String input ) { try { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java index 9ec0cf7..f34b282 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java @@ -8,7 +8,7 @@ public class DDCommandResult { public static final DDCommandResult TOO_MANY_ARGUMENTS = new DDCommandResult(2, "Error: Too many arguments passed to the command", true); public static final DDCommandResult INVALID_DIMENSION_ID = new DDCommandResult(3, "Error: Invalid dimension ID", true); public static final DDCommandResult UNREGISTERED_DIMENSION = new DDCommandResult(4, "Error: Dimension is not registered", false); - public static final DDCommandResult INVALID_ARGUMENTS = new DDCommandResult(5, "Error: Invalid arguments passed to the command.", true); + public static final DDCommandResult INVALID_ARGUMENTS = new DDCommandResult(5, "Error: Invalid arguments passed to the command", true); public static final int CUSTOM_ERROR_CODE = -1; -- 2.39.5 From c5a77268fc6be470c5e06a0731b17081d8c20591 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 14:08:51 -0400 Subject: [PATCH 03/17] Changes to Commands Removed a few server-side checks that I missed on the previous commit. --- .../mod_pocketDim/commands/CommandListDungeons.java | 4 ---- .../mod_pocketDim/commands/CommandResetDungeons.java | 4 ---- src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java | 4 ---- 3 files changed, 12 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandListDungeons.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandListDungeons.java index 043d0fd..222b481 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandListDungeons.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandListDungeons.java @@ -31,10 +31,6 @@ public class CommandListDungeons extends DDCommandBase int pageCount; ArrayList dungeonNames; - if (sender.worldObj.isRemote) - { - return DDCommandResult.SUCCESS; - } if (command.length > 1) { return DDCommandResult.TOO_MANY_ARGUMENTS; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java index b3535cf..aad0671 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java @@ -29,10 +29,6 @@ public class CommandResetDungeons extends DDCommandBase @Override protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { - if(sender.worldObj.isRemote) - { - return DDCommandResult.SUCCESS; - } if (command.length > 0) { return DDCommandResult.TOO_FEW_ARGUMENTS; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index cf281e8..a1a93e6 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -351,15 +351,11 @@ public class mod_pocketDim event.registerServerCommand( CommandListDungeons.instance() ); event.registerServerCommand( CommandCreateRandomRift.instance() ); event.registerServerCommand( CommandDeleteAllLinks.instance() ); - //CommandDeleteDimensionData.instance().register(event); event.registerServerCommand( CommandDeleteRifts.instance() ); event.registerServerCommand( CommandExportDungeon.instance() ); - //CommandPrintDimensionData.instance().register(event); - //CommandPruneDimensions.instance().register(event); event.registerServerCommand( CommandCreatePocket.instance() ); event.registerServerCommand( CommandTeleportPlayer.instance() ); - try { ChunkLoaderHelper.loadChunkForcedWorlds(event); -- 2.39.5 From 80bb87dac66c0c87024e399721e1c9b2148577ca Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 14:19:08 -0400 Subject: [PATCH 04/17] Rewrote CommandDeleteRifts Rewrote CommandDeleteRifts for clarity and to remove several flaws. Previously, the command would have removed non-immune blocks that were in the same location as a rift. It also set blocks in the command sender's dimension rather than the target dimension, so blocks would have potentially disappeared from the wrong world. --- .../commands/CommandDeleteRifts.java | 86 +++++++++++-------- 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java index a2aac97..cc1a1a1 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java @@ -8,6 +8,7 @@ import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.util.Point4D; public class CommandDeleteRifts extends DDCommandBase { @@ -15,7 +16,7 @@ public class CommandDeleteRifts extends DDCommandBase private CommandDeleteRifts() { - super("dd-???", "???"); + super("dd-deleterifts", "[dimension number]"); } public static CommandDeleteRifts instance() @@ -29,47 +30,64 @@ public class CommandDeleteRifts extends DDCommandBase @Override protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { - int linksRemoved=0; - int targetDim; - boolean shouldGo= true; + int linksRemoved = 0; + int targetDimension; - if(command.length==1) + if (command.length > 1) { - targetDim = parseInt(sender, command[0]); + return DDCommandResult.TOO_MANY_ARGUMENTS; + } + if (command.length == 0) + { + targetDimension = sender.worldObj.provider.dimensionId; } else { - targetDim=0; - shouldGo=false; - sendChat(sender,("Error-Invalid argument, delete_all_links ")); + try + { + targetDimension = Integer.parseInt(command[0]); + } + catch (NumberFormatException e) + { + return DDCommandResult.INVALID_DIMENSION_ID; + } } - if(shouldGo) + World world = PocketManager.loadDimension(targetDimension); + if (world == null) { - - NewDimData dim = PocketManager.getDimensionData(targetDim); - ArrayList linksInDim = dim.getAllLinks(); - - for (DimLink link : linksInDim) - { - World targetWorld = PocketManager.loadDimension(targetDim); - - if(!mod_pocketDim.blockRift.isBlockImmune(sender.worldObj,link.source().getX(), link.source().getY(), link.source().getZ())|| - (targetWorld.getBlockId(link.source().getX(), link.source().getY(), link.source().getZ())==mod_pocketDim.blockRift.blockID)) - { - linksRemoved++; - targetWorld.setBlock(link.source().getX(), link.source().getY(), link.source().getZ(), 0); - dim.deleteLink(link); - - - } - //TODO Probably should check what the block is, but thats annoying so Ill do it later. - - - } - sendChat(sender,("Removed " + linksRemoved + " links.")); - + return DDCommandResult.UNREGISTERED_DIMENSION; } - return DDCommandResult.SUCCESS; //TEMPORARY HACK + + int x; + int y; + int z; + Point4D location; + NewDimData dimension = PocketManager.getDimensionData(targetDimension); + ArrayList links = dimension.getAllLinks(); + for (DimLink link : links) + { + location = link.source(); + x = location.getX(); + y = location.getY(); + z = location.getZ(); + if (world.getBlockId(x, y, z) == mod_pocketDim.blockRift.blockID) + { + // Remove the rift and its link + world.setBlockToAir(x, y, z); + dimension.deleteLink(link); + linksRemoved++; + } + else if (!mod_pocketDim.blockRift.isBlockImmune(world, x, y, z)) + { + // If a block is not immune, then it must not be a DD block. + // The link would regenerate into a rift eventually. + // We only need to remove the link. + dimension.deleteLink(link); + linksRemoved++; + } + } + sendChat(sender, "Removed " + linksRemoved + " links."); + return DDCommandResult.SUCCESS; } } \ No newline at end of file -- 2.39.5 From b4a58f5c884e4ea40082412eb6e1c16dc5a2f530 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 17:20:59 -0400 Subject: [PATCH 05/17] Simplified PocketManager 1. Rewrote or removed a few bits that were causing minor warnings. 2. Rewrote deleteDimensionFiles() and deleteDimensionData() to remove unnecessary casts and checks. We can confirm that those checks are unnecessary because those functions are only used inside PocketManager. If they were ever exposed externally, then we would need to add checks again. --- .../mod_pocketDim/core/PocketManager.java | 51 ++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 1882bba..acb6ed9 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -315,44 +315,43 @@ public class PocketManager { if (deleteFolder) { - deleteDimensionFiles(target); + deleteDimensionFiles(dimension); } dimensionIDBlackList.add(dimension.id); - deleteDimensionData(dimension.id); + deleteDimensionData(dimension); return true; } return false; } - private static boolean deleteDimensionFiles(NewDimData target) + private static void deleteDimensionFiles(InnerDimData dimension) { - InnerDimData dimension = (InnerDimData) target; - if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null) - { - String saveRootPath = DimensionManager.getCurrentSaveRootDirectory().getAbsolutePath(); - File saveDirectory = new File(saveRootPath + "/DimensionalDoors/pocketDimID" + dimension.id()); - DeleteFolder.deleteFolder(saveDirectory); - File dataFile = new File(saveRootPath + "/DimensionalDoors/data/dim_" + dimension.id() + ".txt"); - dataFile.delete(); - return true; - } - return false; + // We assume that the caller checks if the dimension is loaded, for the + // sake of efficiency. Don't call this on a loaded dimension or bad + // things will happen! + String saveRootPath = DimensionManager.getCurrentSaveRootDirectory().getAbsolutePath(); + File saveDirectory = new File(saveRootPath + "/DimensionalDoors/pocketDimID" + dimension.id()); + DeleteFolder.deleteFolder(saveDirectory); + File dataFile = new File(saveRootPath + "/DimensionalDoors/data/dim_" + dimension.id() + ".txt"); + dataFile.delete(); } - private static boolean deleteDimensionData(int dimensionID) + private static void deleteDimensionData(InnerDimData dimension) { - if (dimensionData.containsKey(dimensionID) && DimensionManager.getWorld(dimensionID) == null) + // We assume that the caller checks if the dimension is loaded, for the + // sake of efficiency. Don't call this on a loaded dimension or bad + // things will happen! + if (dimensionData.remove(dimension.id()) != null) { - NewDimData target = PocketManager.getDimensionData(dimensionID); - InnerDimData dimension = (InnerDimData) target; - - dimensionData.remove(dimensionID); // Raise the dim deleted event getDimwatcher().onDeleted(new ClientDimData(dimension)); dimension.clear(); - return true; } - return false; + else + { + // This should never happen. A simple sanity check. + throw new IllegalArgumentException("The specified dimension is not listed with PocketManager."); + } } private static void registerPockets(DDProperties properties) @@ -647,10 +646,7 @@ public class PocketManager { return dimension.getLink(x, y, z); } - else - { - return null; - } + return null; } public static boolean isBlackListed(int dimensionID) @@ -715,9 +711,6 @@ public class PocketManager // Load compacted client-side dimension data load(); Compactor.readDimensions(input, new DimRegistrationCallback()); - - // Register pocket dimensions - DDProperties properties = DDProperties.instance(); isLoaded = true; isLoading = false; -- 2.39.5 From 592aabf62771e4da08b7118c4fefe3960822de94 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 17:32:40 -0400 Subject: [PATCH 06/17] Minor Change Added a comment in PocketManager to explain why we don't unregister pocket dimensions with Forge when we delete them. --- .../StevenDimDoors/mod_pocketDim/core/PocketManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java index acb6ed9..7c7c3e0 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -317,6 +317,11 @@ public class PocketManager { deleteDimensionFiles(dimension); } + // Note: We INTENTIONALLY don't unregister the dimensions that we + // delete with Forge. Instead, we keep them registered to stop Forge + // from reallocating those IDs to other mods such as Mystcraft. This + // is to prevent bugs. Blacklisted dimensions are still properly + // unregistered when the server shuts down. dimensionIDBlackList.add(dimension.id); deleteDimensionData(dimension); return true; -- 2.39.5 From 972a67de766ec5784b92a337e8006ff160b1596a Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 22:46:31 -0400 Subject: [PATCH 07/17] Rewrote CommandResetDungeons 1. Rewrote CommandResetDungeons to improve clarity and remove bugs. This version of the command preserves valid links. Those were previously removed, which would break some dungeons unnecessarily. 2. Fixed NewDimData.setParentToRoot(). The function did not account for the possibility that the target's parent might still exist and would need to be updated, leading to conflicting data. It also did not reset pack depth. We now correctly update a dimension and all its descendants. --- .../commands/CommandResetDungeons.java | 93 +++++++++++-------- .../mod_pocketDim/core/NewDimData.java | 32 +++++++ 2 files changed, 88 insertions(+), 37 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java index aad0671..69eaace 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java @@ -1,9 +1,10 @@ package StevenDimDoors.mod_pocketDim.commands; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Stack; import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; @@ -31,55 +32,73 @@ public class CommandResetDungeons extends DDCommandBase { if (command.length > 0) { - return DDCommandResult.TOO_FEW_ARGUMENTS; + return DDCommandResult.TOO_MANY_ARGUMENTS; + } + + int id; + int resetCount = 0; + int dungeonCount = 0; + HashSet deletedDimensions = new HashSet(); + ArrayList loadedDungeons = new ArrayList(); + + // Copy the list of dimensions to iterate over the copy. Otherwise, + // we would trigger an exception by modifying the original list. + ArrayList dimensions = new ArrayList(); + for (NewDimData dimension : PocketManager.getDimensions()) + { + dimensions.add(dimension); } - int dungeonCount = 0; - int resetCount = 0; - ArrayList dimsToDelete = new ArrayList(); - ArrayList dimsToFix = new ArrayList(); - - for (NewDimData data : PocketManager.getDimensions()) + // Iterate over the list of dimensions. Check which ones are dungeons. + // If a dungeon is found, try to delete it. If it can't be deleted, + // then it must be loaded and needs to be updated to prevent bugs. + for (NewDimData dimension : dimensions) { - - if(DimensionManager.getWorld(data.id())==null&&data.isDungeon()) + if (dimension.isDungeon()) { - resetCount++; dungeonCount++; - dimsToDelete.add(data.id()); - } - else if(data.isDungeon()) - { - dimsToFix.add(data.id()); - dungeonCount++; - for(DimLink link : data.links()) + id = dimension.id(); + if (PocketManager.deletePocket(dimension, true)) { - if(link.linkType()==LinkTypes.REVERSE) + resetCount++; + deletedDimensions.add(id); + } + else + { + loadedDungeons.add(dimension); + } + } + } + + // Modify the loaded dungeons to prevent bugs + for (NewDimData dungeon : loadedDungeons) + { + // Find top-most loaded dungeons and update their parents. + // They will automatically update their children. + // Dungeons with non-dungeon parents don't need to be fixed. + if (dungeon.parent() == null) + { + dungeon.setParentToRoot(); + } + + // Links to any deleted dungeons must be replaced + for (DimLink link : dungeon.links()) + { + if (link.hasDestination() && deletedDimensions.contains(link.destination().getDimension())) + { + if (link.linkType() == LinkTypes.DUNGEON) { - data.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation()); + dungeon.createLink(link.source(), LinkTypes.DUNGEON, link.orientation()); } - if(link.linkType()==LinkTypes.DUNGEON) + else if (link.linkType() == LinkTypes.REVERSE) { - data.createLink(link.source(), LinkTypes.DUNGEON, link.orientation()); + dungeon.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation()); } } } } - - for(Integer dimID:dimsToDelete) - { - PocketManager.deletePocket(PocketManager.getDimensionData(dimID), true); - } - /** - * temporary workaround - */ - for(Integer dimID: dimsToFix) - { - PocketManager.getDimensionData(dimID).setParentToRoot(); - } - //TODO- for some reason the parent field of loaded dimenions get reset to null if I call .setParentToRoot() before I delete the pockets. - //TODO implement blackList - //Notify the user of the results + + // Notify the user of the results sendChat(sender,("Reset complete. " + resetCount + " out of " + dungeonCount + " dungeons were reset.")); return DDCommandResult.SUCCESS; } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 15182ed..8ed8d83 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Stack; import java.util.TreeMap; import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData; @@ -516,11 +517,42 @@ public abstract class NewDimData */ public void setParentToRoot() { + // Update this dimension's information + if (parent != null) + { + parent.children.remove(this); + } this.depth = 1; this.parent = this.root; this.root.children.add(this); this.root.modified = true; this.modified = true; + if (this.isDungeon) + { + this.packDepth = calculatePackDepth(this.parent, this.dungeon); + } + + // Update the depths for child dimensions using a depth-first traversal + Stack ordering = new Stack(); + ordering.addAll(this.children); + + while (!ordering.isEmpty()) + { + NewDimData current = ordering.pop(); + current.resetDepth(); + ordering.addAll(current.children); + } + } + + private void resetDepth() + { + // We assume that this is only applied to dimensions with parents + this.depth = this.parent.depth + 1; + if (this.isDungeon) + { + this.packDepth = calculatePackDepth(this.parent, this.dungeon); + } + this.modified = true; } public static int calculatePackDepth(NewDimData parent, DungeonData current) -- 2.39.5 From 805e9dd040e8ec5a27f737e926832f5845d4117b Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 22:49:15 -0400 Subject: [PATCH 08/17] Minor Changes Fixed up a few spots to clear some warnings. --- .../mod_pocketDim/commands/CommandResetDungeons.java | 1 - .../StevenDimDoors/mod_pocketDim/core/NewDimData.java | 11 +++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java index 69eaace..074124e 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java @@ -2,7 +2,6 @@ package StevenDimDoors.mod_pocketDim.commands; import java.util.ArrayList; import java.util.HashSet; -import java.util.Stack; import net.minecraft.entity.player.EntityPlayer; import StevenDimDoors.mod_pocketDim.core.DimLink; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 8ed8d83..326b7d4 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -581,10 +581,7 @@ public abstract class NewDimData { return parent.packDepth + 1; } - else - { - return 1; - } + return 1; } public void initializePocket(int originX, int originY, int originZ, int orientation, DimLink incoming) @@ -621,10 +618,7 @@ public abstract class NewDimData { return linkList.get(random.nextInt(linkList.size())); } - else - { - return linkList.get(0); - } + return linkList.get(0); } public boolean isModified() @@ -637,6 +631,7 @@ public abstract class NewDimData this.modified = false; } + @Override public String toString() { return "DimID= " + this.id; -- 2.39.5 From c1e58c25cc1fcb301a4128d59a0a35df99181cf5 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 01:17:25 -0400 Subject: [PATCH 09/17] Increased Max Monolith Aggro Increased the maximum Monolith aggro level and the cap range values by a factor of 1.25. The max aggro increase is to slow down how long it takes Monoliths to max out because they're just a little too fast right now. The cap adjustments will preserve the range of texture states they can have while idling. --- .../StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java index f54f515..279c123 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java @@ -21,9 +21,9 @@ import StevenDimDoors.mod_pocketDim.world.PocketProvider; public class MobMonolith extends EntityFlying implements IMob { - private static final short MAX_AGGRO = 200; - private static final short MAX_AGGRO_CAP = 80; - private static final short MIN_AGGRO_CAP = 20; + private static final short MAX_AGGRO = 250; + private static final short MAX_AGGRO_CAP = 100; + private static final short MIN_AGGRO_CAP = 25; private static final int MAX_TEXTURE_STATE = 18; private static final int MAX_SOUND_COOLDOWN = 200; private static final int MAX_AGGRO_RANGE = 35; -- 2.39.5 From f64768ed1631762f334b90a4a10fb897cee80305 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 02:14:24 -0400 Subject: [PATCH 10/17] Rewrote DeleteFolder Rewrote the helper class DeleteFolder. It was leaving behind empty directories when pockets were deleted. --- .../mod_pocketDim/helpers/DeleteFolder.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DeleteFolder.java b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DeleteFolder.java index 3f835be..495ca6b 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DeleteFolder.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DeleteFolder.java @@ -2,31 +2,33 @@ package StevenDimDoors.mod_pocketDim.helpers; import java.io.File; - public class DeleteFolder { - public static boolean deleteFolder(File file) + public static boolean deleteFolder(File directory) { try { - File[] files = file.listFiles(); - - if(files==null) + File[] contents = directory.listFiles(); + if (contents != null) { - file.delete(); - return true; + for (File entry : contents) + { + if (entry.isDirectory()) + { + deleteFolder(entry); + } + else + { + entry.delete(); + } + } } - for(File inFile : files) - { - DeleteFolder.deleteFolder(inFile); - } - + return directory.delete(); } catch (Exception e) { e.printStackTrace(); return false; } - return true; } } \ No newline at end of file -- 2.39.5 From d3860119e9c5b569ac6b38194f8248b3bbd5ad13 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 13:05:08 -0400 Subject: [PATCH 11/17] Minor Change to PocketManager Added a minor check to PocketManager.loadDimension() so that an attempt to load an unregistered dimension won't be passed on to Forge where it would cause an exception - which is then caught by Forge before it can cause problems. This isn't strictly necessary, but it's a nice consideration. --- .../StevenDimDoors/mod_pocketDim/core/PocketManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 7c7c3e0..5a1f1d6 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -483,6 +483,11 @@ public class PocketManager public static WorldServer loadDimension(int id) { + if (!DimensionManager.isDimensionRegistered(id)) + { + return null; + } + WorldServer world = DimensionManager.getWorld(id); if (world == null) { -- 2.39.5 From 4d53ae5f6a38ccd9f54a8aed74f62cb7b23ad5b1 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 13:53:44 -0400 Subject: [PATCH 12/17] Removed CommandDeleteAllLinks I removed CommandDeleteAllLinks because of the significant risk that it would harm a server. It's possible that someone could run this by accident instead of CommandDeleteRifts. It takes the same arguments or even no arguments and it would immediately wipe all links in a dimension. We can restore it later if it's really needed. --- .../commands/CommandDeleteAllLinks.java | 66 ------------------- .../mod_pocketDim/mod_pocketDim.java | 1 - 2 files changed, 67 deletions(-) delete mode 100644 src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java deleted file mode 100644 index af9f915..0000000 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java +++ /dev/null @@ -1,66 +0,0 @@ -package StevenDimDoors.mod_pocketDim.commands; - -import java.util.ArrayList; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; -import StevenDimDoors.mod_pocketDim.core.DimLink; -import StevenDimDoors.mod_pocketDim.core.NewDimData; -import StevenDimDoors.mod_pocketDim.core.PocketManager; - -public class CommandDeleteAllLinks extends DDCommandBase -{ - private static CommandDeleteAllLinks instance = null; - - private CommandDeleteAllLinks() - { - super("dd-deletelinks", "???"); - } - - public static CommandDeleteAllLinks instance() - { - if (instance == null) - instance = new CommandDeleteAllLinks(); - - return instance; - } - - @Override - protected DDCommandResult processCommand(EntityPlayer sender, String[] command) - { - int linksRemoved=0; - int targetDim; - boolean shouldGo= true; - - if(command.length==1) - { - targetDim = parseInt(sender, command[0]); - } - else - { - targetDim=0; - shouldGo=false; - sendChat(sender, ("Error-Invalid argument, delete_all_links ")); - } - - if(shouldGo) - { - - NewDimData dim = PocketManager.getDimensionData(targetDim); - ArrayList linksInDim = dim.getAllLinks(); - - for (DimLink link : linksInDim) - { - World targetWorld = PocketManager.loadDimension(targetDim); - targetWorld.setBlock(link.source().getX(), link.source().getY(), link.source().getZ(), 0); - dim.deleteLink(link); - //TODO Probably should check what the block is, but thats annoying so Ill do it later. - - linksRemoved++; - } - sendChat(sender,("Removed " + linksRemoved + " links.")); - - } - return DDCommandResult.SUCCESS; //TEMPORARY HACK - } -} \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index a1a93e6..9130a86 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -350,7 +350,6 @@ public class mod_pocketDim event.registerServerCommand( CommandCreateDungeonRift.instance() ); event.registerServerCommand( CommandListDungeons.instance() ); event.registerServerCommand( CommandCreateRandomRift.instance() ); - event.registerServerCommand( CommandDeleteAllLinks.instance() ); event.registerServerCommand( CommandDeleteRifts.instance() ); event.registerServerCommand( CommandExportDungeon.instance() ); event.registerServerCommand( CommandCreatePocket.instance() ); -- 2.39.5 From 1e3b32a15ca7d6c6b18852e8852d81a67e8d767c Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 14:06:41 -0400 Subject: [PATCH 13/17] Minor Change Removed a reference to CommandDeleteAllLinks from mod_pocketDim. --- src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 9130a86..62dd845 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -30,7 +30,6 @@ import StevenDimDoors.mod_pocketDim.blocks.WarpDoor; import StevenDimDoors.mod_pocketDim.commands.CommandCreateDungeonRift; import StevenDimDoors.mod_pocketDim.commands.CommandCreatePocket; import StevenDimDoors.mod_pocketDim.commands.CommandCreateRandomRift; -import StevenDimDoors.mod_pocketDim.commands.CommandDeleteAllLinks; import StevenDimDoors.mod_pocketDim.commands.CommandDeleteRifts; import StevenDimDoors.mod_pocketDim.commands.CommandExportDungeon; import StevenDimDoors.mod_pocketDim.commands.CommandListDungeons; -- 2.39.5 From 16f0a8303aca16a799f12cfc5c81b53e51083f0d Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 20:20:46 -0400 Subject: [PATCH 14/17] Rewrote CommandTeleportPlayer Rewrote CommandTeleportPlayer for the same reason as usual. There were a few bugs before, such as that lookups for players were limited to within the world from which the command sender was using the command. Players in other dimensions could not be teleported. The command would also place people in the ground because it did not adjust its coordinates for the way that DDTeleporter interprets them - as the location of the top block of a door and the player's head. --- .../commands/CommandTeleportPlayer.java | 203 ++++++++++-------- .../commands/DDCommandResult.java | 1 + 2 files changed, 110 insertions(+), 94 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java index 93b4d3f..83bf268 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java @@ -1,8 +1,10 @@ package StevenDimDoors.mod_pocketDim.commands; import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.common.DimensionManager; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.core.DDTeleporter; +import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.util.Point4D; @@ -12,7 +14,10 @@ public class CommandTeleportPlayer extends DDCommandBase private CommandTeleportPlayer() { - super("dd-tp", new String[] {" "," "} ); + super("dd-tp", new String[] { + " ", + " ", + " "} ); } public static CommandTeleportPlayer instance() @@ -23,110 +28,120 @@ public class CommandTeleportPlayer extends DDCommandBase return instance; } - /** - * TODO- Change to accept variety of input, like just coords, just dim ID, or two player names. - */ @Override protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { - EntityPlayer targetPlayer = sender; - int dimDestinationID = sender.worldObj.provider.dimensionId; + int x; + int y; + int z; + World world; + int dimensionID; + Point4D destination; + NewDimData dimension; + boolean checkOrientation; + EntityPlayer targetPlayer; - if(command.length == 5) + if (command.length < 2) { - for(int i= 1; i <5;i++) - { - if(!isInteger(command[i])) - { - return DDCommandResult.INVALID_ARGUMENTS; - } - } - if(sender.worldObj.getPlayerEntityByName(command[0])!=null) //Gets the targeted player - { - targetPlayer = sender.worldObj.getPlayerEntityByName(command[0]); - } - else - { - return DDCommandResult.INVALID_ARGUMENTS; - } - dimDestinationID=Integer.parseInt(command[1]);//gets the target dim ID from the command string - - if(!DimensionManager.isDimensionRegistered(dimDestinationID)) - { - return DDCommandResult.INVALID_DIMENSION_ID; - } - - PocketManager.loadDimension(dimDestinationID); - Point4D destination = new Point4D(Integer.parseInt(command[2]),Integer.parseInt(command[3]),Integer.parseInt(command[4]),dimDestinationID); - DDTeleporter.teleportEntity(targetPlayer, destination, false); + return DDCommandResult.TOO_FEW_ARGUMENTS; } - else if(command.length == 2 && isInteger(command[1])) + if (command.length > 5) { - if(sender.worldObj.getPlayerEntityByName(command[0])!=null) //Gets the targeted player - { - targetPlayer = sender.worldObj.getPlayerEntityByName(command[0]); - } - else - { - return DDCommandResult.INVALID_ARGUMENTS; - } - dimDestinationID=Integer.parseInt(command[1]);//gets the target dim ID from the command string - - if(!DimensionManager.isDimensionRegistered(dimDestinationID)) - { - return DDCommandResult.INVALID_DIMENSION_ID; - } - - - Point4D destination = PocketManager.getDimensionData(dimDestinationID).origin(); - if(!PocketManager.getDimensionData(dimDestinationID).isPocketDimension()) - { - destination = new Point4D(destination.getX(),PocketManager.loadDimension(dimDestinationID).getTopSolidOrLiquidBlock( - destination.getX(), destination.getZ()), - destination.getZ(),destination.getDimension()); - } - DDTeleporter.teleportEntity(targetPlayer, destination, false); + return DDCommandResult.TOO_MANY_ARGUMENTS; } - else if(command.length == 1 && isInteger(command[0])) - { - - targetPlayer = sender; - - dimDestinationID=Integer.parseInt(command[0]);//gets the target dim ID from the command string - - if(!DimensionManager.isDimensionRegistered(dimDestinationID)) - { - return DDCommandResult.INVALID_DIMENSION_ID; - } - - - Point4D destination = PocketManager.getDimensionData(dimDestinationID).origin(); - if(!PocketManager.getDimensionData(dimDestinationID).isPocketDimension()) - { - destination = new Point4D(destination.getX(),PocketManager.loadDimension(dimDestinationID).getTopSolidOrLiquidBlock( - destination.getX(), destination.getZ()), - destination.getZ(),destination.getDimension()); - } - DDTeleporter.teleportEntity(targetPlayer, destination, false); - } - else + if (command.length == 3) { return DDCommandResult.INVALID_ARGUMENTS; } + // Check that all arguments after the username are integers + for (int k = 1; k < command.length; k++) + { + if (!isInteger(command[k])) + { + return DDCommandResult.INVALID_ARGUMENTS; + } + } + // Check if the target player is logged in + targetPlayer = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(command[0]); + if (targetPlayer == null) + { + return DDCommandResult.PLAYER_OFFLINE; + } + // If a dimension ID was provided, try to load it + if (command.length != 4) + { + dimensionID = Integer.parseInt(command[1]); + world = PocketManager.loadDimension(dimensionID); + if (world == null) + { + return DDCommandResult.UNREGISTERED_DIMENSION; + } + } + else + { + dimensionID = targetPlayer.worldObj.provider.dimensionId; + // SenseiKiwi: Will not be used, but I prefer not to leave 'world' as null + world = targetPlayer.worldObj; + } + + // If we teleport to a pocket dimension, set checkOrientation to true + // so the player is placed correctly relative to the entrance door. + checkOrientation = false; + + // Parse or calculate the destination as necessary + // The Y coordinate must be increased by 1 because of the way that + // DDTeleporter considers destination points. It assumes that the + // point provided is the upper block of a door. + if (command.length == 2) + { + // Check if the destination is a pocket dimension + dimension = PocketManager.getDimensionData(dimensionID); + if (dimension.isPocketDimension()) + { + // The destination is a pocket dimension. + // Teleport the player to its original entrance (the origin). + destination = dimension.origin(); + checkOrientation = true; + } + else + { + // The destination is not a pocket dimension, which means we + // don't automatically know a safe location where we can send + // the player. Send the player to (0, Y, 0), where Y is chosen + // by searching. Add 2 to place the player ABOVE the top block. + y = world.getTopSolidOrLiquidBlock(0, 0) + 2; + destination = new Point4D(0, y, 0, dimensionID); + } + } + else if (command.length == 4) + { + x = Integer.parseInt(command[1]); + y = Integer.parseInt(command[2]) + 1; + z = Integer.parseInt(command[3]); + destination = new Point4D(x, y, z, dimensionID); + } + else + { + x = Integer.parseInt(command[2]); + y = Integer.parseInt(command[3]) + 1; + z = Integer.parseInt(command[4]); + destination = new Point4D(x, y, z, dimensionID); + } + // Teleport! + DDTeleporter.teleportEntity(targetPlayer, destination, checkOrientation); return DDCommandResult.SUCCESS; } - public static boolean isInteger( String input ) - { - try - { - Integer.parseInt( input ); - return true; - } - catch(Exception e ) - { - return false; - } - } - + private static boolean isInteger(String input) + { + try + { + Integer.parseInt(input); + return true; + } + catch(Exception e) + { + return false; + } + } } \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java index f34b282..b6a31b9 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java @@ -9,6 +9,7 @@ public class DDCommandResult { public static final DDCommandResult INVALID_DIMENSION_ID = new DDCommandResult(3, "Error: Invalid dimension ID", true); public static final DDCommandResult UNREGISTERED_DIMENSION = new DDCommandResult(4, "Error: Dimension is not registered", false); public static final DDCommandResult INVALID_ARGUMENTS = new DDCommandResult(5, "Error: Invalid arguments passed to the command", true); + public static final DDCommandResult PLAYER_OFFLINE = new DDCommandResult(6, "Error: Player is not online", false); public static final int CUSTOM_ERROR_CODE = -1; -- 2.39.5 From 17a770eaf0b02858a3b9cc5d0e855d48cb140043 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 20:55:57 -0400 Subject: [PATCH 15/17] Minor Change Added two comments to CommandTeleportPlayer --- .../mod_pocketDim/commands/CommandTeleportPlayer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java index 83bf268..b02222f 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java @@ -116,14 +116,14 @@ public class CommandTeleportPlayer extends DDCommandBase else if (command.length == 4) { x = Integer.parseInt(command[1]); - y = Integer.parseInt(command[2]) + 1; + y = Integer.parseInt(command[2]) + 1; // Correct the Y value z = Integer.parseInt(command[3]); destination = new Point4D(x, y, z, dimensionID); } else { x = Integer.parseInt(command[2]); - y = Integer.parseInt(command[3]) + 1; + y = Integer.parseInt(command[3]) + 1; // Correct the Y value z = Integer.parseInt(command[4]); destination = new Point4D(x, y, z, dimensionID); } -- 2.39.5 From 100fa38c52b67f31ac4e7343bd7beff5ea722be6 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 5 Jul 2014 14:18:18 -0400 Subject: [PATCH 16/17] Minor Changes to DDTeleporter Made some minor changes to DDTeleporter to get rid of a few warnings. Also tweaked and commented DDTeleporter.initializeDestination(). There were inappropriate references to a link's internal variables instead of using its getters and there was a subtle link overwrite for blacklist destinations. Without comments, it would probably be unclear that overwriting that link is safe. This changes are in preparation for fixing issues with blacklisted destination redirection. --- .../mod_pocketDim/core/DDTeleporter.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index c7d0c2b..fc793e5 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -25,7 +25,6 @@ import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor; import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; -import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; import StevenDimDoors.mod_pocketDim.util.Point4D; @@ -483,9 +482,12 @@ public class DDTeleporter { if (link.hasDestination()) { - if(PocketManager.isBlackListed(link.destination().getDimension())) + if (PocketManager.isBlackListed(link.destination().getDimension())) { - link=PocketManager.getDimensionData(link.source().getDimension()).createLink(link.link.point,LinkTypes.SAFE_EXIT,link.link.orientation); + // Overwrite this link to a blacklisted destination with a safe exit link + // We don't need to change 'link' to a different reference. + // NewDimData will overwrite the existing link in-place. + PocketManager.getDimensionData(link.source().getDimension()).createLink(link.source(), LinkTypes.SAFE_EXIT, link.orientation()); } else { @@ -499,7 +501,7 @@ public class DDTeleporter case LinkTypes.DUNGEON: return PocketBuilder.generateNewDungeonPocket(link, properties); case LinkTypes.POCKET: - return PocketBuilder.generateNewPocket(link, properties,door); + return PocketBuilder.generateNewPocket(link, properties, door); case LinkTypes.SAFE_EXIT: return generateSafeExit(link, properties); case LinkTypes.DUNGEON_EXIT: @@ -544,10 +546,7 @@ public class DDTeleporter { return matches.get( random.nextInt(matches.size()) ); } - else - { - return null; - } + return null; } private static boolean generateUnsafeExit(DimLink link) @@ -749,7 +748,7 @@ public class DDTeleporter // Set up the warp door at the destination orientation = BlockRotator.transformMetadata(orientation, 2, properties.WarpDoorID); - ItemDimensionalDoor.placeDoorBlock(world, x, y + 1, z, orientation, mod_pocketDim.warpDoor); + ItemDoor.placeDoorBlock(world, x, y + 1, z, orientation, mod_pocketDim.warpDoor); // Complete the link to the destination // This comes last so the destination isn't set unless everything else works first -- 2.39.5 From 06cf72f9f73fd058099e63a589d13ff72a74ede9 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 5 Jul 2014 21:28:10 -0400 Subject: [PATCH 17/17] Fixed Flawed Link Redirection Fixed the way in which we handle redirecting links to blacklisted dimensions. The previous method always converted links into safe exits. This lead to strange situations that could be seen as bugs. For instance, using a dungeon entrance in a root dimension would generate an exit door and a supporting platform directly above the entrance door. That also meant that any visited dungeons would be unusable if they were reset. We now do different things depending on the location of the link and its type. If the link is a dungeon link, then its destination is reset to allow a new dungeon to form. For other link types, if the link is in a pocket dimension, then it becomes a safe exit link, because it could be the only way out. If it's in a root dimension, then there are no reasonable destinations, so the teleport request is cancelled. --- .../mod_pocketDim/core/DDTeleporter.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index fc793e5..f8f7bc1 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -484,10 +484,31 @@ public class DDTeleporter { if (PocketManager.isBlackListed(link.destination().getDimension())) { - // Overwrite this link to a blacklisted destination with a safe exit link - // We don't need to change 'link' to a different reference. - // NewDimData will overwrite the existing link in-place. - PocketManager.getDimensionData(link.source().getDimension()).createLink(link.source(), LinkTypes.SAFE_EXIT, link.orientation()); + // This link leads to a dimension that has been blacklisted. + // That means that it was a pocket and it was deleted. + // Depending on the link type, we must overwrite it or cancel + // the teleport operation. We don't need to assign 'link' with + // a different value. NewDimData will overwrite it in-place. + NewDimData start = PocketManager.getDimensionData(link.source().getDimension()); + if (link.linkType() == LinkTypes.DUNGEON) + { + // Ovewrite the link into a dungeon link with no destination + start.createLink(link.source(), LinkTypes.DUNGEON, link.orientation()); + } + else + { + if (start.isPocketDimension()) + { + // Ovewrite the link into a safe exit link, because + // this could be the only way out from a pocket. + start.createLink(link.source(), LinkTypes.SAFE_EXIT, link.orientation()); + } + else + { + // Cancel the teleport attempt + return false; + } + } } else { -- 2.39.5