Fix up issues with code

Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
solonovamax
2020-11-06 22:26:57 -05:00
parent a362ed47ce
commit 0c8c0723ef
130 changed files with 1228 additions and 1059 deletions

View File

@@ -40,27 +40,116 @@ public final class RotationUtil {
BlockFace n = f;
int rotateNum = r.getDegrees() / 90;
int rn = faceRotation(f);
if(rn >= 0) {
if (rn >= 0) {
n = fromRotation(faceRotation(n) + 4 * rotateNum);
}
return n;
}
/**
* Get an integer representation of a BlockFace, to perform math on.
*
* @param f BlockFace to get integer for
* @return integer representation of BlockFace
*/
public static int faceRotation(BlockFace f) {
switch(f) {
case NORTH:
return 0;
case NORTH_NORTH_EAST:
return 1;
case NORTH_EAST:
return 2;
case EAST_NORTH_EAST:
return 3;
case EAST:
return 4;
case EAST_SOUTH_EAST:
return 5;
case SOUTH_EAST:
return 6;
case SOUTH_SOUTH_EAST:
return 7;
case SOUTH:
return 8;
case SOUTH_SOUTH_WEST:
return 9;
case SOUTH_WEST:
return 10;
case WEST_SOUTH_WEST:
return 11;
case WEST:
return 12;
case WEST_NORTH_WEST:
return 13;
case NORTH_WEST:
return 14;
case NORTH_NORTH_WEST:
return 15;
default:
return -1;
}
}
/**
* Convert integer to BlockFace representation
*
* @param r integer to get BlockFace for
* @return BlockFace represented by integer.
*/
public static BlockFace fromRotation(int r) {
switch(Math.floorMod(r, 16)) {
case 0:
return BlockFace.NORTH;
case 1:
return BlockFace.NORTH_NORTH_EAST;
case 2:
return BlockFace.NORTH_EAST;
case 3:
return BlockFace.EAST_NORTH_EAST;
case 4:
return BlockFace.EAST;
case 5:
return BlockFace.EAST_SOUTH_EAST;
case 6:
return BlockFace.SOUTH_EAST;
case 7:
return BlockFace.SOUTH_SOUTH_EAST;
case 8:
return BlockFace.SOUTH;
case 9:
return BlockFace.SOUTH_SOUTH_WEST;
case 10:
return BlockFace.SOUTH_WEST;
case 11:
return BlockFace.WEST_SOUTH_WEST;
case 12:
return BlockFace.WEST;
case 13:
return BlockFace.WEST_NORTH_WEST;
case 14:
return BlockFace.NORTH_WEST;
case 15:
return BlockFace.NORTH_NORTH_WEST;
default:
throw new IllegalArgumentException();
}
}
public static org.bukkit.Axis getRotatedAxis(org.bukkit.Axis orig, Structure.Rotation r) {
org.bukkit.Axis other = orig;
final boolean shouldSwitch = r.equals(Structure.Rotation.CW_90) || r.equals(Structure.Rotation.CCW_90);
switch(orig) {
case X:
if(shouldSwitch) other = org.bukkit.Axis.Z;
if (shouldSwitch) other = org.bukkit.Axis.Z;
break;
case Z:
if(shouldSwitch) other = org.bukkit.Axis.X;
if (shouldSwitch) other = org.bukkit.Axis.X;
break;
}
return other;
}
/**
* Method to rotate the incredibly obnoxious Rail.Shape enum
*

View File

@@ -12,13 +12,6 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public final class WorldEditUtil {
public static WorldEditPlugin getWorldEdit() {
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
if(p instanceof WorldEditPlugin) return (WorldEditPlugin) p;
Bukkit.getLogger().severe("[Terra] a command requiring WorldEdit was executed, but WorldEdit was not detected!");
return null;
}
public static Location[] getSelectionLocations(Player sender) {
WorldEditPlugin we = WorldEditUtil.getWorldEdit();
if(we == null) {
@@ -43,9 +36,16 @@ public final class WorldEditUtil {
return new Location[] {l1, l2};
}
public static WorldEditPlugin getWorldEdit() {
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
if (p instanceof WorldEditPlugin) return (WorldEditPlugin) p;
Bukkit.getLogger().severe("[Terra] a command requiring WorldEdit was executed, but WorldEdit was not detected!");
return null;
}
public static Location[] getSelectionPositions(Player sender) {
WorldEditPlugin we = WorldEditUtil.getWorldEdit();
if(we == null) {
if (we == null) {
sender.sendMessage("WorldEdit is not installed! Please install WorldEdit before attempting to export structures.");
return null;
}