Created build.gradle
Restructured folder structure for ForgeGradle Signed-off-by: deathrat <deathrat43@gmail.com>
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
package StevenDimDoors.mod_pocketDim.commands;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||
import StevenDimDoors.mod_pocketDim.core.DimLink;
|
||||
import StevenDimDoors.mod_pocketDim.core.LinkTypes;
|
||||
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
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;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class CommandCreateDungeonRift extends DDCommandBase
|
||||
{
|
||||
private static CommandCreateDungeonRift instance = null;
|
||||
|
||||
private CommandCreateDungeonRift()
|
||||
{
|
||||
super("dd-rift", "<dungeon name | 'list' | 'random'>");
|
||||
}
|
||||
|
||||
public static CommandCreateDungeonRift instance()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = new CommandCreateDungeonRift();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "Usage: /dd-rift <dungeon name>\r\n" +
|
||||
" /dd-rift list\r\n" +
|
||||
" /dd-rift random";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
|
||||
{
|
||||
NewDimData dimension;
|
||||
DungeonHelper dungeonHelper = DungeonHelper.instance();
|
||||
|
||||
if (sender.worldObj.isRemote)
|
||||
{
|
||||
return DDCommandResult.SUCCESS;
|
||||
}
|
||||
if (command.length == 0)
|
||||
{
|
||||
return DDCommandResult.TOO_FEW_ARGUMENTS;
|
||||
}
|
||||
if (command.length > 1)
|
||||
{
|
||||
return DDCommandResult.TOO_MANY_ARGUMENTS;
|
||||
}
|
||||
|
||||
if (command[0].equals("list"))
|
||||
{
|
||||
Collection<String> dungeonNames = dungeonHelper.getDungeonNames();
|
||||
for (String name : dungeonNames)
|
||||
{
|
||||
sendChat(sender,(name));
|
||||
}
|
||||
sendChat(sender,(""));
|
||||
}
|
||||
else
|
||||
{
|
||||
DimLink link;
|
||||
DungeonData result;
|
||||
int x = MathHelper.floor_double(sender.posX);
|
||||
int y = MathHelper.floor_double(sender.posY);
|
||||
int z = MathHelper.floor_double (sender.posZ);
|
||||
int orientation = MathHelper.floor_double((sender.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3;
|
||||
|
||||
if (command[0].equals("random"))
|
||||
{
|
||||
|
||||
dimension = PocketManager.getDimensionData(sender.worldObj);
|
||||
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON,orientation);
|
||||
sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID,0,3);
|
||||
|
||||
sendChat(sender,("Created a rift to a random dungeon."));
|
||||
}
|
||||
else
|
||||
{
|
||||
result = findDungeonByPartialName(command[0], dungeonHelper.getRegisteredDungeons());
|
||||
if (result == null)
|
||||
{
|
||||
result = findDungeonByPartialName(command[0], dungeonHelper.getUntaggedDungeons());
|
||||
}
|
||||
//Check if we found any matches
|
||||
if (result != null)
|
||||
{
|
||||
//Create a rift to our selected dungeon and notify the player
|
||||
//TODO currently crashes, need to create the dimension first
|
||||
dimension = PocketManager.getDimensionData(sender.worldObj);
|
||||
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON,orientation);
|
||||
PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result);
|
||||
|
||||
sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID,0,3);
|
||||
sendChat(sender,("Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ")."));
|
||||
}
|
||||
else
|
||||
{
|
||||
//No matches!
|
||||
return new DDCommandResult("Error: The specified dungeon was not found. Use 'list' to see a list of the available dungeons.");
|
||||
}
|
||||
}
|
||||
}
|
||||
return DDCommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
private DungeonData findDungeonByPartialName(String query, Collection<DungeonData> dungeons)
|
||||
{
|
||||
//Search for the shortest dungeon name that contains the lowercase query string.
|
||||
String dungeonName;
|
||||
String normalQuery = query.toLowerCase();
|
||||
DungeonData bestMatch = null;
|
||||
int matchLength = Integer.MAX_VALUE;
|
||||
|
||||
for (DungeonData dungeon : dungeons)
|
||||
{
|
||||
//We need to extract the file's name. Comparing against schematicPath could
|
||||
//yield false matches if the query string is contained within the path.
|
||||
|
||||
dungeonName = dungeon.schematicName().toLowerCase();
|
||||
if (dungeonName.length() < matchLength && dungeonName.contains(normalQuery))
|
||||
{
|
||||
matchLength = dungeonName.length();
|
||||
bestMatch = dungeon;
|
||||
}
|
||||
}
|
||||
return bestMatch;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package StevenDimDoors.mod_pocketDim.commands;
|
||||
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
||||
|
||||
public class CommandCreatePocket extends DDCommandBase
|
||||
{
|
||||
private static CommandCreatePocket instance = null;
|
||||
|
||||
private CommandCreatePocket()
|
||||
{
|
||||
super("dd-create", "");
|
||||
}
|
||||
|
||||
public static CommandCreatePocket instance()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = new CommandCreatePocket();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "Usage: /dd-create";
|
||||
}
|
||||
|
||||
@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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package StevenDimDoors.mod_pocketDim.commands;
|
||||
|
||||
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;
|
||||
|
||||
private CommandDeleteAllLinks()
|
||||
{
|
||||
super("dd-deletelinks", "???");
|
||||
}
|
||||
|
||||
public static CommandDeleteAllLinks instance()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = new CommandDeleteAllLinks();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "Usage: /dd-deletelinks <targetDimensionID>";
|
||||
}
|
||||
|
||||
@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 <targetDimID>"));
|
||||
}
|
||||
|
||||
if(shouldGo)
|
||||
{
|
||||
|
||||
NewDimData dim = PocketManager.getDimensionData(targetDim);
|
||||
ArrayList<DimLink> 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
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;
|
||||
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;
|
||||
|
||||
private CommandDeleteRifts()
|
||||
{
|
||||
super("dd-???", "???");
|
||||
}
|
||||
|
||||
public static CommandDeleteRifts instance()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = new CommandDeleteRifts();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "Usage: /dd-??? <dimension ID>";
|
||||
}
|
||||
|
||||
@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 <targetDimID>"));
|
||||
}
|
||||
|
||||
if(shouldGo)
|
||||
{
|
||||
|
||||
NewDimData dim = PocketManager.getDimensionData(targetDim);
|
||||
ArrayList<DimLink> linksInDim = dim.getAllLinks();
|
||||
|
||||
for (DimLink link : linksInDim)
|
||||
{
|
||||
World targetWorld = PocketManager.loadDimension(targetDim);
|
||||
|
||||
if(sender.worldObj.getBlockId(link.source().getX(), link.source().getY(), link.source().getZ())==mod_pocketDim.blockRift.blockID)
|
||||
{
|
||||
targetWorld.setBlock(link.source().getX(), link.source().getY(), link.source().getZ(), 0);
|
||||
linksRemoved++;
|
||||
dim.deleteLink(link);
|
||||
}
|
||||
}
|
||||
sendChat(sender,("Removed " + linksRemoved + " rifts."));
|
||||
|
||||
}
|
||||
return DDCommandResult.SUCCESS; //TEMPORARY HACK
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
package StevenDimDoors.mod_pocketDim.commands;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import StevenDimDoors.mod_pocketDim.DDProperties;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
||||
|
||||
public class CommandExportDungeon extends DDCommandBase
|
||||
{
|
||||
private static CommandExportDungeon instance = null;
|
||||
|
||||
private CommandExportDungeon()
|
||||
{
|
||||
super("dd-export", new String[] {
|
||||
"<dungeon type> <dungeon name> <'open' | 'closed'> [weight]",
|
||||
"<schematic name> override" } );
|
||||
}
|
||||
|
||||
public static CommandExportDungeon instance()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = new CommandExportDungeon();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "Usage: /dd-export <dungeon type> <dungeon name> open <weight>\r\n" +
|
||||
" /dd-export <dungeon type> <dungeon name> closed <weight>\r\n" +
|
||||
" /dd-export <schematic name> override";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
|
||||
{
|
||||
/*
|
||||
* There are two versions of this command. One version takes 3 to 4 arguments consisting
|
||||
* of the information needed for a proper schematic name.
|
||||
*
|
||||
* If the user wishes to name his schematic in a different format, then he will have to use
|
||||
* the 2-argument version of this command, which accepts a schematic name and a mandatory
|
||||
* override argument.
|
||||
*/
|
||||
|
||||
DungeonHelper dungeonHelper = DungeonHelper.instance();
|
||||
|
||||
if (command.length < 2)
|
||||
{
|
||||
return DDCommandResult.TOO_FEW_ARGUMENTS;
|
||||
}
|
||||
if (command.length > 4)
|
||||
{
|
||||
return DDCommandResult.TOO_MANY_ARGUMENTS;
|
||||
}
|
||||
|
||||
//Check if we received the 2-argument version
|
||||
if (command.length == 2)
|
||||
{
|
||||
if (command[1].equalsIgnoreCase("override"))
|
||||
{
|
||||
//Check that the schematic name is a legal name
|
||||
if (DungeonHelper.SCHEMATIC_NAME_PATTERN.matcher(command[0]).matches())
|
||||
{
|
||||
//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 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")))
|
||||
{
|
||||
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 DDCommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
private static DDCommandResult exportDungeon(EntityPlayer player, String name)
|
||||
{
|
||||
DDProperties properties = DDProperties.instance();
|
||||
DungeonHelper dungeonHelper = DungeonHelper.instance();
|
||||
|
||||
int x = (int) player.posX;
|
||||
int y = (int) player.posY;
|
||||
int z = (int) player.posZ;
|
||||
String exportPath = properties.CustomSchematicDirectory + File.separator + name + ".schematic";
|
||||
if (dungeonHelper.exportDungeon(player.worldObj, x, y, z, exportPath))
|
||||
{
|
||||
sendChat(player,("Saved dungeon schematic in " + exportPath));
|
||||
dungeonHelper.registerDungeon(exportPath, dungeonHelper.getDungeonPack("ruins"), false, true);
|
||||
return DDCommandResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new DDCommandResult("Error: Failed to save dungeon schematic!");
|
||||
}
|
||||
}
|
||||
|
||||
private static String join(String[] source, String delimiter, int start, int end)
|
||||
{
|
||||
//TODO: This function should be moved to a helper, but we have several single-function helpers as is.
|
||||
//I find that to be worse than keeping this private. ~SenseiKiwi
|
||||
|
||||
int index;
|
||||
int length = 0;
|
||||
StringBuilder buffer;
|
||||
for (index = start; index < end; index++)
|
||||
{
|
||||
length += source[index].length();
|
||||
}
|
||||
length += (end - start - 1) * delimiter.length();
|
||||
|
||||
buffer = new StringBuilder(length);
|
||||
buffer.append(source[start]);
|
||||
for (index = start + 1; index < end; index++)
|
||||
{
|
||||
buffer.append(delimiter);
|
||||
buffer.append(source[index]);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
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;
|
||||
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;
|
||||
|
||||
private CommandResetDungeons()
|
||||
{
|
||||
super("dd-resetdungeons", "");
|
||||
}
|
||||
|
||||
public static CommandResetDungeons instance()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = new CommandResetDungeons();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "/dd-resetdungeons";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
|
||||
{
|
||||
if(sender.worldObj.isRemote)
|
||||
{
|
||||
return DDCommandResult.SUCCESS;
|
||||
}
|
||||
if (command.length > 0)
|
||||
{
|
||||
return DDCommandResult.TOO_FEW_ARGUMENTS;
|
||||
}
|
||||
|
||||
int dungeonCount = 0;
|
||||
int resetCount = 0;
|
||||
ArrayList<Integer> dimsToDelete = new ArrayList<Integer>();
|
||||
ArrayList<Integer> dimsToFix = new ArrayList<Integer>();
|
||||
|
||||
for (NewDimData data : PocketManager.getDimensions())
|
||||
{
|
||||
|
||||
if(DimensionManager.getWorld(data.id())==null&&data.isDungeon())
|
||||
{
|
||||
resetCount++;
|
||||
dungeonCount++;
|
||||
dimsToDelete.add(data.id());
|
||||
}
|
||||
else if(data.isDungeon())
|
||||
{
|
||||
dimsToFix.add(data.id());
|
||||
dungeonCount++;
|
||||
for(DimLink link : data.links())
|
||||
{
|
||||
if(link.linkType()==LinkTypes.REVERSE)
|
||||
{
|
||||
data.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation());
|
||||
}
|
||||
if(link.linkType()==LinkTypes.DUNGEON)
|
||||
{
|
||||
data.createLink(link.source(), LinkTypes.DUNGEON, 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
|
||||
sendChat(sender,("Reset complete. " + resetCount + " out of " + dungeonCount + " dungeons were reset."));
|
||||
return DDCommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package StevenDimDoors.mod_pocketDim.commands;
|
||||
|
||||
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;
|
||||
|
||||
private CommandTeleportPlayer()
|
||||
{
|
||||
super("dd-tp", new String[] {"<Player Name> <Dimension ID> <X Coord> <Y Coord> <Z Coord>"} );
|
||||
}
|
||||
|
||||
public static CommandTeleportPlayer instance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new CommandTeleportPlayer();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "Usage: /dd-tp <player name> <dimension id> <x> <y> <z>";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
List<Integer> dimensionIDs = Arrays.asList(DimensionManager.getStaticDimensionIDs()); //Gets list of all registered dimensions, regardless if loaded or not
|
||||
EntityPlayer targetPlayer = sender;
|
||||
int dimDestinationID = sender.worldObj.provider.dimensionId;
|
||||
|
||||
if(command.length == 5)
|
||||
{
|
||||
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(!dimensionIDs.contains(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);
|
||||
}
|
||||
else
|
||||
{
|
||||
return DDCommandResult.INVALID_ARGUMENTS;
|
||||
}
|
||||
return DDCommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
public boolean isInteger( String input )
|
||||
{
|
||||
try
|
||||
{
|
||||
Integer.parseInt( input );
|
||||
return true;
|
||||
}
|
||||
catch(Exception e )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package StevenDimDoors.mod_pocketDim.commands;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
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
|
||||
* some convenience improvements.
|
||||
*/
|
||||
public abstract class DDCommandBase extends CommandBase
|
||||
{
|
||||
private String name;
|
||||
private String[] formats;
|
||||
|
||||
public DDCommandBase(String name, String format)
|
||||
{
|
||||
this.name = name;
|
||||
this.formats = new String[] { format };
|
||||
}
|
||||
|
||||
public DDCommandBase(String name, String[] formats)
|
||||
{
|
||||
this.name = name;
|
||||
this.formats = formats;
|
||||
}
|
||||
|
||||
/*
|
||||
* When overridden in a derived class, processes the command sent by the server
|
||||
* and returns a status code and message for the result of the operation.
|
||||
*/
|
||||
protected abstract DDCommandResult processCommand(EntityPlayer sender, String[] command);
|
||||
|
||||
@Override
|
||||
public final String getCommandName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/*
|
||||
* Registers the command at server startup.
|
||||
*/
|
||||
public void register(FMLServerStartingEvent event)
|
||||
{
|
||||
event.registerServerCommand(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Method invoked by the server to execute a command. The call is forwarded to a derived class
|
||||
* to provide the sending player directly.
|
||||
*/
|
||||
@Override
|
||||
public final void processCommand(ICommandSender sender, String[] command)
|
||||
{
|
||||
//Forward the command
|
||||
EntityPlayer player = getCommandSenderAsPlayer(sender);
|
||||
DDCommandResult result = processCommand(player, command);
|
||||
|
||||
//If the command failed, send the player a status message.
|
||||
if (result.failed())
|
||||
{
|
||||
if (result.shouldPrintUsage())
|
||||
{
|
||||
//Send the argument formats for this command
|
||||
for (String format : formats)
|
||||
{
|
||||
sendChat(player,("Usage: " + name + " " + format));
|
||||
}
|
||||
}
|
||||
sendChat(player,(result.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendChat(EntityPlayer player, String message)
|
||||
{
|
||||
ChatMessageComponent cmp = new ChatMessageComponent();
|
||||
cmp.addText(message);
|
||||
player.sendChatToPlayer(cmp);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package StevenDimDoors.mod_pocketDim.commands;
|
||||
|
||||
public class DDCommandResult {
|
||||
|
||||
|
||||
public static final DDCommandResult SUCCESS = new DDCommandResult(0, "", false);
|
||||
public static final DDCommandResult TOO_FEW_ARGUMENTS = new DDCommandResult(1, "Error: Too few arguments passed to the command", true);
|
||||
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 int CUSTOM_ERROR_CODE = -1;
|
||||
|
||||
private int code;
|
||||
private String message;
|
||||
private boolean printUsage;
|
||||
|
||||
private DDCommandResult(int code, String message, boolean printUsage)
|
||||
{
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.printUsage = printUsage;
|
||||
}
|
||||
|
||||
public DDCommandResult(String message)
|
||||
{
|
||||
this(CUSTOM_ERROR_CODE, message, false);
|
||||
}
|
||||
|
||||
public DDCommandResult(String message, boolean printUsage)
|
||||
{
|
||||
this(CUSTOM_ERROR_CODE, message, printUsage);
|
||||
}
|
||||
|
||||
public boolean failed()
|
||||
{
|
||||
return (code != 0);
|
||||
}
|
||||
|
||||
public int getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
public boolean shouldPrintUsage()
|
||||
{
|
||||
return printUsage;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user