From 8a80f46ec00ec7b211f97735d382e604ad6e876c Mon Sep 17 00:00:00 2001 From: Rate Date: Sat, 27 May 2023 10:14:03 +1200 Subject: [PATCH] =?UTF-8?q?#693=20Allow=20item=20frame=20chameleon=20prese?= =?UTF-8?q?ts=20to=20be=20rotated=2045=C2=B0=20angles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TARDIS/builders/TARDISBuilderUtility.java | 2 +- .../TARDIS/builders/TARDISInstantPreset.java | 10 +- .../builders/TARDISMaterialisePreset.java | 20 +-- .../builders/TARDISPresetBuilderFactory.java | 9 +- .../tardis/TARDISDirectionCommand.java | 38 +++-- .../commands/tardis/TARDISTabComplete.java | 2 +- .../commands/travel/TARDISTravelArea.java | 7 +- .../destroyers/TARDISDeinstantPreset.java | 7 +- .../destroyers/TARDISDematerialisePreset.java | 27 +-- .../TARDIS/enumeration/COMPASS.java | 15 +- .../TARDIS/flight/TARDISFlightAdjustment.java | 2 +- .../flight/TARDISMaterialseFromVortex.java | 10 +- .../TARDISDirectionFrameListener.java | 158 +++++++++++------- .../TARDIS/move/TARDISDoorListener.java | 15 +- src/main/resources/en.yml | 3 +- todo.md | 2 +- 16 files changed, 199 insertions(+), 128 deletions(-) diff --git a/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISBuilderUtility.java b/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISBuilderUtility.java index 2d905118a..c689b1656 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISBuilderUtility.java +++ b/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISBuilderUtility.java @@ -43,7 +43,7 @@ static void saveDoorLocation(BuildData bd) { ResultSetDoors rsd = new ResultSetDoors(TARDIS.plugin, whered, false); HashMap setd = new HashMap<>(); setd.put("door_location", doorloc); - setd.put("door_direction", bd.getDirection().toString()); + setd.put("door_direction", bd.getDirection().forPreset().toString()); if (rsd.resultSet()) { HashMap whereid = new HashMap<>(); whereid.put("door_id", rsd.getDoor_id()); diff --git a/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISInstantPreset.java b/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISInstantPreset.java index 4616b1128..9b5fc2b49 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISInstantPreset.java +++ b/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISInstantPreset.java @@ -90,13 +90,13 @@ public void buildPreset() { } TARDISChameleonColumn column; if (preset.equals(ChameleonPreset.CONSTRUCT)) { - column = new TARDISConstructColumn(plugin, bd.getTardisID(), "blueprintData", bd.getDirection()).getColumn(); + column = new TARDISConstructColumn(plugin, bd.getTardisID(), "blueprintData", bd.getDirection().forPreset()).getColumn(); if (column == null) { TARDISMessage.send(bd.getPlayer().getPlayer(), "INVALID_CONSTRUCT"); return; } } else { - column = plugin.getPresets().getColumn(preset, bd.getDirection()); + column = plugin.getPresets().getColumn(preset, bd.getDirection().forPreset()); } int plusx, minusx, x, plusz, y, minusz, z; // get relative locations @@ -129,7 +129,7 @@ public void buildPreset() { } plugin.getTrackerKeeper().getRescue().remove(bd.getTardisID()); } - switch (bd.getDirection()) { + switch (bd.getDirection().forPreset()) { case SOUTH -> { //if (yaw >= 315 || yaw < 45) signx = x; @@ -412,7 +412,7 @@ public void buildPreset() { TARDISBlockSetters.setBlock(world, xx, (y + yy), zz, Material.GLOWSTONE); } else { Rotatable rotatable = (Rotatable) colData[yy]; - rotatable.setRotation(plugin.getPresetBuilder().getSkullDirection(bd.getDirection())); + rotatable.setRotation(plugin.getPresetBuilder().getSkullDirection(bd.getDirection().forPreset())); TARDISBlockSetters.setBlockAndRemember(world, xx, (y + yy), zz, rotatable, bd.getTardisID()); } } @@ -475,7 +475,7 @@ private void processDoor(String doorloc) { ResultSetDoors rsd = new ResultSetDoors(plugin, whered, false); HashMap setd = new HashMap<>(); setd.put("door_location", doorloc); - setd.put("door_direction", bd.getDirection().toString()); + setd.put("door_direction", bd.getDirection().forPreset().toString()); if (rsd.resultSet()) { HashMap whereid = new HashMap<>(); whereid.put("door_id", rsd.getDoor_id()); diff --git a/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISMaterialisePreset.java b/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISMaterialisePreset.java index 7a97b4dfd..81484631d 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISMaterialisePreset.java +++ b/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISMaterialisePreset.java @@ -102,13 +102,13 @@ class TARDISMaterialisePreset implements Runnable { plugin.getPresets().setR(TARDISConstants.RANDOM.nextInt(2)); } if (this.preset.equals(ChameleonPreset.CONSTRUCT)) { - column = new TARDISConstructColumn(plugin, bd.getTardisID(), "blueprintData", bd.getDirection()).getColumn(); - stained_column = new TARDISConstructColumn(plugin, bd.getTardisID(), "stainData", bd.getDirection()).getColumn(); - glass_column = new TARDISConstructColumn(plugin, bd.getTardisID(), "glassData", bd.getDirection()).getColumn(); + column = new TARDISConstructColumn(plugin, bd.getTardisID(), "blueprintData", bd.getDirection().forPreset()).getColumn(); + stained_column = new TARDISConstructColumn(plugin, bd.getTardisID(), "stainData", bd.getDirection().forPreset()).getColumn(); + glass_column = new TARDISConstructColumn(plugin, bd.getTardisID(), "glassData", bd.getDirection().forPreset()).getColumn(); } else { - column = plugin.getPresets().getColumn(preset, bd.getDirection()); - stained_column = plugin.getPresets().getStained(preset, bd.getDirection()); - glass_column = plugin.getPresets().getGlass(preset, bd.getDirection()); + column = plugin.getPresets().getColumn(preset, bd.getDirection().forPreset()); + stained_column = plugin.getPresets().getStained(preset, bd.getDirection().forPreset()); + glass_column = plugin.getPresets().getGlass(preset, bd.getDirection().forPreset()); } Material[] colours = new Material[]{Material.WHITE_WOOL, Material.ORANGE_WOOL, Material.MAGENTA_WOOL, Material.LIGHT_BLUE_WOOL, Material.YELLOW_WOOL, Material.LIME_WOOL, Material.PINK_WOOL, Material.CYAN_WOOL, Material.PURPLE_WOOL, Material.BLUE_WOOL, Material.BROWN_WOOL, Material.GREEN_WOOL, Material.RED_WOOL}; Material[] glassColours = new Material[]{Material.WHITE_STAINED_GLASS, Material.ORANGE_STAINED_GLASS, Material.MAGENTA_STAINED_GLASS, Material.LIGHT_BLUE_STAINED_GLASS, Material.YELLOW_STAINED_GLASS, Material.LIME_STAINED_GLASS, Material.PINK_STAINED_GLASS, Material.CYAN_STAINED_GLASS, Material.PURPLE_STAINED_GLASS, Material.BLUE_STAINED_GLASS, Material.BROWN_STAINED_GLASS, Material.GREEN_STAINED_GLASS, Material.RED_STAINED_GLASS}; @@ -190,7 +190,7 @@ public void run() { } } // get direction player is facing from yaw place block under door if block is in list of blocks an iron door cannot go on - switch (bd.getDirection()) { + switch (bd.getDirection().forPreset()) { case SOUTH -> { // if (yaw >= 315 || yaw < 45) signx = x; @@ -477,7 +477,7 @@ public void run() { TARDISBlockSetters.setBlock(world, xx, (y + yy), zz, Material.GLOWSTONE); } else { Rotatable rotatable = (Rotatable) colData[yy]; - rotatable.setRotation(plugin.getPresetBuilder().getSkullDirection(bd.getDirection())); + rotatable.setRotation(plugin.getPresetBuilder().getSkullDirection(bd.getDirection().forPreset())); TARDISBlockSetters.setBlockAndRemember(world, xx, (y + yy), zz, rotatable, bd.getTardisID()); } } @@ -659,7 +659,7 @@ public void run() { TARDISBlockSetters.setBlock(world, xx, (y + yy), zz, Material.GLOWSTONE); } else { Rotatable rotatable = (Rotatable) coldatas[yy]; - rotatable.setRotation(plugin.getPresetBuilder().getSkullDirection(bd.getDirection())); + rotatable.setRotation(plugin.getPresetBuilder().getSkullDirection(bd.getDirection().forPreset())); TARDISBlockSetters.setBlock(world, xx, (y + yy), zz, rotatable); } } @@ -780,7 +780,7 @@ private void saveDoorLocation(World world, int xx, int y, int yy, int zz) { ResultSetDoors rsd = new ResultSetDoors(plugin, whered, false); HashMap setd = new HashMap<>(); setd.put("door_location", doorloc); - setd.put("door_direction", bd.getDirection().toString()); + setd.put("door_direction", bd.getDirection().forPreset().toString()); if (rsd.resultSet()) { HashMap whereid = new HashMap<>(); whereid.put("door_id", rsd.getDoor_id()); diff --git a/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISPresetBuilderFactory.java b/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISPresetBuilderFactory.java index 0f5ff965a..bd3792996 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISPresetBuilderFactory.java +++ b/src/main/java/me/eccentric_nz/TARDIS/builders/TARDISPresetBuilderFactory.java @@ -16,9 +16,6 @@ */ package me.eccentric_nz.TARDIS.builders; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import me.eccentric_nz.TARDIS.TARDIS; import me.eccentric_nz.TARDIS.TARDISConstants; import me.eccentric_nz.TARDIS.chameleon.utils.TARDISChameleonCircuit; @@ -38,6 +35,10 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + /** * The Wibbly lever was a part of The Doctor's TARDIS console. The lever had at least two functions: opening and closing * doors and controlling implosions used to revert paradoxes in which the TARDIS had materialised within itself. @@ -92,7 +93,7 @@ public void buildPreset(BuildData bd) { thisChunk.load(); } if (bd.isRebuild()) { - biome = bd.getLocation().getBlock().getRelative(getOppositeFace(bd.getDirection()), 2).getBiome(); + biome = bd.getLocation().getBlock().getRelative(getOppositeFace(bd.getDirection().forPreset()), 2).getBiome(); } else { biome = bd.getLocation().getBlock().getBiome(); // disable force field diff --git a/src/main/java/me/eccentric_nz/TARDIS/commands/tardis/TARDISDirectionCommand.java b/src/main/java/me/eccentric_nz/TARDIS/commands/tardis/TARDISDirectionCommand.java index dd7adbd71..41a9acf3b 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/commands/tardis/TARDISDirectionCommand.java +++ b/src/main/java/me/eccentric_nz/TARDIS/commands/tardis/TARDISDirectionCommand.java @@ -25,8 +25,8 @@ import me.eccentric_nz.TARDIS.database.resultset.ResultSetCurrentLocation; import me.eccentric_nz.TARDIS.database.resultset.ResultSetTardis; import me.eccentric_nz.TARDIS.enumeration.COMPASS; -import me.eccentric_nz.TARDIS.enumeration.Difficulty; import me.eccentric_nz.TARDIS.enumeration.ChameleonPreset; +import me.eccentric_nz.TARDIS.enumeration.Difficulty; import me.eccentric_nz.TARDIS.enumeration.SpaceTimeThrottle; import me.eccentric_nz.TARDIS.messaging.TARDISMessage; import me.eccentric_nz.TARDIS.move.TARDISDoorCloser; @@ -39,7 +39,6 @@ import org.bukkit.entity.Player; import java.util.HashMap; -import java.util.Locale; import java.util.UUID; /** @@ -55,9 +54,16 @@ public TARDISDirectionCommand(TARDIS plugin) { public boolean changeDirection(Player player, String[] args) { if (TARDISPermission.hasPermission(player, "tardis.timetravel")) { - if (args.length < 2 || (!args[1].equalsIgnoreCase("north") && !args[1].equalsIgnoreCase("west") && !args[1].equalsIgnoreCase("south") && !args[1].equalsIgnoreCase("east"))) { + if (args.length < 2) { TARDISMessage.send(player, "DIRECTION_NEED"); - return false; + return true; + } + COMPASS compass; + try { + compass = COMPASS.valueOf(args[1].toUpperCase()); + } catch (IllegalArgumentException e) { + TARDISMessage.send(player, "DIRECTION_NEED"); + return true; } UUID uuid = player.getUniqueId(); HashMap where = new HashMap<>(); @@ -65,9 +71,14 @@ public boolean changeDirection(Player player, String[] args) { ResultSetTardis rs = new ResultSetTardis(plugin, where, "", false, 0); if (!rs.resultSet()) { TARDISMessage.send(player, "NO_TARDIS"); - return false; + return true; } Tardis tardis = rs.getTardis(); + if (!tardis.getPreset().usesItemFrame() + && (args[1].equalsIgnoreCase("north_east") || args[1].equalsIgnoreCase("north_west") || args[1].equalsIgnoreCase("south_west") || args[1].equalsIgnoreCase("south_east"))) { + TARDISMessage.send(player, "DIRECTION_PRESET"); + return true; + } if (plugin.getConfig().getBoolean("allow.power_down") && !tardis.isPowered_on()) { TARDISMessage.send(player, "POWER_DOWN"); return true; @@ -102,7 +113,7 @@ public boolean changeDirection(Player player, String[] args) { } boolean hid = tardis.isHidden(); ChameleonPreset demat = tardis.getDemat(); - String dir = args[1].toUpperCase(Locale.ENGLISH); +// String dir = args[1].toUpperCase(Locale.ENGLISH); HashMap wherecl = new HashMap<>(); wherecl.put("tardis_id", id); ResultSetCurrentLocation rsc = new ResultSetCurrentLocation(plugin, wherecl); @@ -114,18 +125,17 @@ public boolean changeDirection(Player player, String[] args) { HashMap tid = new HashMap<>(); HashMap set = new HashMap<>(); tid.put("tardis_id", id); - set.put("direction", dir); + set.put("direction", compass.toString()); plugin.getQueryFactory().doUpdate("current", set, tid); HashMap did = new HashMap<>(); HashMap setd = new HashMap<>(); did.put("door_type", 0); did.put("tardis_id", id); - setd.put("door_direction", dir); + setd.put("door_direction", compass.forPreset().toString()); plugin.getQueryFactory().doUpdate("doors", setd, did); // close doors & therefore remove open portals... new TARDISDoorCloser(plugin, uuid, id).closeDoors(); Location l = new Location(rsc.getWorld(), rsc.getX(), rsc.getY(), rsc.getZ()); - COMPASS d = COMPASS.valueOf(dir); // destroy sign if (!hid) { if (demat.equals(ChameleonPreset.DUCK)) { @@ -143,7 +153,7 @@ public boolean changeDirection(Player player, String[] args) { plugin.getPresetDestroyer().destroyDoor(id); plugin.getPresetDestroyer().destroySign(l, old_d, demat); BuildData bd = new BuildData(uuid.toString()); - bd.setDirection(d); + bd.setDirection(compass); bd.setLocation(l); bd.setMalfunction(false); bd.setOutside(false); @@ -173,11 +183,15 @@ public boolean changeDirection(Player player, String[] args) { } for (Entity e : chunk.getEntities()) { if (e instanceof ItemFrame frame && e.getLocation().toString().equals(locToCheck)) { - Rotation r = switch (d) { + Rotation r = switch (compass) { case EAST -> Rotation.COUNTER_CLOCKWISE; + case SOUTH_EAST -> Rotation.COUNTER_CLOCKWISE_45; case SOUTH -> Rotation.NONE; + case SOUTH_WEST -> Rotation.CLOCKWISE_45; case WEST -> Rotation.CLOCKWISE; - default -> Rotation.FLIPPED; + case NORTH_WEST -> Rotation.CLOCKWISE_135; + case NORTH -> Rotation.FLIPPED; + default -> Rotation.FLIPPED_45; }; frame.setRotation(r); break; diff --git a/src/main/java/me/eccentric_nz/TARDIS/commands/tardis/TARDISTabComplete.java b/src/main/java/me/eccentric_nz/TARDIS/commands/tardis/TARDISTabComplete.java index 8e44e8127..8305b0df8 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/commands/tardis/TARDISTabComplete.java +++ b/src/main/java/me/eccentric_nz/TARDIS/commands/tardis/TARDISTabComplete.java @@ -42,7 +42,7 @@ public class TARDISTabComplete extends TARDISCompleter implements TabCompleter { private final List ON_OFF_SUBS = ImmutableList.of("on", "off"); private final List DOOR_SUBS = ImmutableList.of("open", "close"); private final List ITEM_SUBS = ImmutableList.of("hand", "inventory"); - private final List DIR_SUBS = ImmutableList.of("north", "west", "south", "east"); + private final List DIR_SUBS = ImmutableList.of("north", "west", "south", "east", "north_east", "north_west", "south_west", "south_east"); private final List LIST_SUBS = ImmutableList.of("companions", "saves", "areas", "rechargers"); private final List ARCHIVE_SUBS = ImmutableList.of("add", "description", "remove", "scan", "update", "y"); private final List EXTRA_SUBS = ImmutableList.of("blocks", "unlock"); diff --git a/src/main/java/me/eccentric_nz/TARDIS/commands/travel/TARDISTravelArea.java b/src/main/java/me/eccentric_nz/TARDIS/commands/travel/TARDISTravelArea.java index 2c0018b2c..3503c5173 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/commands/travel/TARDISTravelArea.java +++ b/src/main/java/me/eccentric_nz/TARDIS/commands/travel/TARDISTravelArea.java @@ -16,14 +16,13 @@ */ package me.eccentric_nz.TARDIS.commands.travel; -import java.util.HashMap; import me.eccentric_nz.TARDIS.TARDIS; import me.eccentric_nz.TARDIS.api.event.TARDISTravelEvent; import me.eccentric_nz.TARDIS.blueprints.TARDISPermission; import me.eccentric_nz.TARDIS.database.resultset.ResultSetAreas; import me.eccentric_nz.TARDIS.database.resultset.ResultSetCurrentLocation; -import me.eccentric_nz.TARDIS.enumeration.Difficulty; import me.eccentric_nz.TARDIS.enumeration.ChameleonPreset; +import me.eccentric_nz.TARDIS.enumeration.Difficulty; import me.eccentric_nz.TARDIS.enumeration.TravelType; import me.eccentric_nz.TARDIS.flight.TARDISLand; import me.eccentric_nz.TARDIS.messaging.TARDISMessage; @@ -32,6 +31,8 @@ import org.bukkit.Location; import org.bukkit.entity.Player; +import java.util.HashMap; + /** * * @author eccentric_nz @@ -104,7 +105,7 @@ public boolean action(Player player, String[] args, int id, ChameleonPreset pres TARDISMessage.send(player, "CURRENT_NOT_FOUND"); return true; } - set.put("direction", rsc.getDirection().toString()); + set.put("direction", rsc.getDirection().forPreset().toString()); } set.put("submarine", 0); HashMap tid = new HashMap<>(); diff --git a/src/main/java/me/eccentric_nz/TARDIS/destroyers/TARDISDeinstantPreset.java b/src/main/java/me/eccentric_nz/TARDIS/destroyers/TARDISDeinstantPreset.java index ba14d828d..4faa6041c 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/destroyers/TARDISDeinstantPreset.java +++ b/src/main/java/me/eccentric_nz/TARDIS/destroyers/TARDISDeinstantPreset.java @@ -16,8 +16,6 @@ */ package me.eccentric_nz.TARDIS.destroyers; -import java.util.Collections; -import java.util.HashMap; import me.eccentric_nz.TARDIS.TARDIS; import me.eccentric_nz.TARDIS.TARDISConstants; import me.eccentric_nz.TARDIS.builders.MaterialisationData; @@ -37,6 +35,9 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.ItemFrame; +import java.util.Collections; +import java.util.HashMap; + /** * A police box is a telephone kiosk that can be used by members of the public wishing to get help from the police. * Early in the First Doctor's travels, the TARDIS assumed the exterior shape of a police box during a five-month @@ -62,7 +63,7 @@ public TARDISDeinstantPreset(TARDIS plugin) { public void instaDestroyPreset(MaterialisationData dd, boolean hide, ChameleonPreset preset) { Location l = dd.getLocation(); - COMPASS d = dd.getDirection(); + COMPASS d = dd.getDirection().forPreset(); int id = dd.getTardisID(); boolean sub = dd.isSubmarine(); if (plugin.getConfig().getBoolean("preferences.walk_in_tardis")) { diff --git a/src/main/java/me/eccentric_nz/TARDIS/destroyers/TARDISDematerialisePreset.java b/src/main/java/me/eccentric_nz/TARDIS/destroyers/TARDISDematerialisePreset.java index c2050fbc6..36a87fda8 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/destroyers/TARDISDematerialisePreset.java +++ b/src/main/java/me/eccentric_nz/TARDIS/destroyers/TARDISDematerialisePreset.java @@ -16,8 +16,6 @@ */ package me.eccentric_nz.TARDIS.destroyers; -import java.util.HashMap; -import java.util.List; import me.eccentric_nz.TARDIS.TARDIS; import me.eccentric_nz.TARDIS.chameleon.construct.TARDISConstructColumn; import me.eccentric_nz.TARDIS.chameleon.utils.TARDISChameleonColumn; @@ -39,6 +37,9 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import java.util.HashMap; +import java.util.List; + /** * A dematerialisation circuit was an essential part of a Type 40 TARDIS which * enabled it to dematerialise from normal space into the Time Vortex and @@ -79,13 +80,13 @@ class TARDISDematerialisePreset implements Runnable { i = 0; this.cham_id = cham_id; if (this.preset.equals(ChameleonPreset.CONSTRUCT)) { - column = new TARDISConstructColumn(plugin, dd.getTardisID(), "blueprintData", dd.getDirection()).getColumn(); - stained_column = new TARDISConstructColumn(plugin, dd.getTardisID(), "stainData", dd.getDirection()).getColumn(); - glass_column = new TARDISConstructColumn(plugin, dd.getTardisID(), "glassData", dd.getDirection()).getColumn(); + column = new TARDISConstructColumn(plugin, dd.getTardisID(), "blueprintData", dd.getDirection().forPreset()).getColumn(); + stained_column = new TARDISConstructColumn(plugin, dd.getTardisID(), "stainData", dd.getDirection().forPreset()).getColumn(); + glass_column = new TARDISConstructColumn(plugin, dd.getTardisID(), "glassData", dd.getDirection().forPreset()).getColumn(); } else { - column = plugin.getPresets().getColumn(preset, dd.getDirection()); - stained_column = plugin.getPresets().getStained(preset, dd.getDirection()); - glass_column = plugin.getPresets().getGlass(preset, dd.getDirection()); + column = plugin.getPresets().getColumn(preset, dd.getDirection().forPreset()); + stained_column = plugin.getPresets().getStained(preset, dd.getDirection().forPreset()); + glass_column = plugin.getPresets().getGlass(preset, dd.getDirection().forPreset()); } } @@ -123,7 +124,7 @@ public void run() { int flowerx; int flowery = (dd.getLocation().getBlockY() + 1); int flowerz; - switch (dd.getDirection()) { + switch (dd.getDirection().forPreset()) { case NORTH -> { flowerx = dd.getLocation().getBlockX(); flowerz = dd.getLocation().getBlockZ() + 1; @@ -145,10 +146,10 @@ public void run() { } case CAKE -> plugin.getPresetDestroyer().destroyLamp(dd.getLocation(), preset); case JUNK_MODE -> { - plugin.getPresetDestroyer().destroySign(dd.getLocation(), dd.getDirection(), preset); - plugin.getPresetDestroyer().destroyHandbrake(dd.getLocation(), dd.getDirection()); + plugin.getPresetDestroyer().destroySign(dd.getLocation(), dd.getDirection().forPreset(), preset); + plugin.getPresetDestroyer().destroyHandbrake(dd.getLocation(), dd.getDirection().forPreset()); } - case SWAMP -> plugin.getPresetDestroyer().destroySign(dd.getLocation(), dd.getDirection(), preset); + case SWAMP -> plugin.getPresetDestroyer().destroySign(dd.getLocation(), dd.getDirection().forPreset(), preset); case JAIL, TOPSYTURVEY -> plugin.getPresetDestroyer().destroyDoor(dd.getTardisID()); case MESA -> { // destroy door @@ -159,7 +160,7 @@ public void run() { int bushy = (dd.getLocation().getBlockY() + 3); int deadz; int bushz; - switch (dd.getDirection()) { + switch (dd.getDirection().forPreset()) { case NORTH -> { deadx = dd.getLocation().getBlockX() + 1; deadz = dd.getLocation().getBlockZ() + 1; diff --git a/src/main/java/me/eccentric_nz/TARDIS/enumeration/COMPASS.java b/src/main/java/me/eccentric_nz/TARDIS/enumeration/COMPASS.java index e93a2bde0..40172e32c 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/enumeration/COMPASS.java +++ b/src/main/java/me/eccentric_nz/TARDIS/enumeration/COMPASS.java @@ -24,9 +24,13 @@ public enum COMPASS { EAST(Rotation.FLIPPED), + SOUTH_EAST(Rotation.FLIPPED_45), SOUTH(Rotation.COUNTER_CLOCKWISE), + SOUTH_WEST(Rotation.COUNTER_CLOCKWISE_45), WEST(Rotation.NONE), - NORTH(Rotation.CLOCKWISE); + NORTH_WEST(Rotation.CLOCKWISE_45), + NORTH(Rotation.CLOCKWISE), + NORTH_EAST(Rotation.COUNTER_CLOCKWISE_45); private final Rotation rotation; @@ -37,4 +41,13 @@ public enum COMPASS { public Rotation getRotation() { return rotation; } + + public COMPASS forPreset() { + return switch (this) { + case EAST, NORTH_EAST -> COMPASS.EAST; + case SOUTH, SOUTH_EAST -> COMPASS.SOUTH; + case WEST, SOUTH_WEST -> COMPASS.WEST; + default -> COMPASS.NORTH; + }; + } } diff --git a/src/main/java/me/eccentric_nz/TARDIS/flight/TARDISFlightAdjustment.java b/src/main/java/me/eccentric_nz/TARDIS/flight/TARDISFlightAdjustment.java index c67ca1f91..37eee21ee 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/flight/TARDISFlightAdjustment.java +++ b/src/main/java/me/eccentric_nz/TARDIS/flight/TARDISFlightAdjustment.java @@ -72,7 +72,7 @@ public Location getLocation(BuildData bd, int r) { Location sub = null; boolean safe; if (bd.isSubmarine()) { - sub = tt.submarine(adjusted_location.getBlock(), bd.getDirection()); + sub = tt.submarine(adjusted_location.getBlock(), bd.getDirection().forPreset()); safe = (sub != null); } else { int[] start = TARDISTimeTravel.getStartLocation(adjusted_location, bd.getDirection()); diff --git a/src/main/java/me/eccentric_nz/TARDIS/flight/TARDISMaterialseFromVortex.java b/src/main/java/me/eccentric_nz/TARDIS/flight/TARDISMaterialseFromVortex.java index a18893df5..e7f3b1729 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/flight/TARDISMaterialseFromVortex.java +++ b/src/main/java/me/eccentric_nz/TARDIS/flight/TARDISMaterialseFromVortex.java @@ -257,7 +257,13 @@ public void run() { setcurrent.put("x", final_location.getBlockX()); setcurrent.put("y", final_location.getBlockY()); setcurrent.put("z", final_location.getBlockZ()); - setcurrent.put("direction", bd.getDirection().toString()); + String direction; + if (preset.usesItemFrame()) { + direction = bd.getDirection().toString(); + } else { + direction = bd.getDirection().forPreset().toString(); + } + setcurrent.put("direction", direction); setcurrent.put("submarine", (bd.isSubmarine()) ? 1 : 0); wherecurrent.put("tardis_id", id); // back @@ -269,7 +275,7 @@ public void run() { setback.put("submarine", (rscl.isSubmarine()) ? 1 : 0); whereback.put("tardis_id", id); // update Police Box door direction - setdoor.put("door_direction", bd.getDirection().toString()); + setdoor.put("door_direction", bd.getDirection().forPreset().toString()); wheredoor.put("tardis_id", id); wheredoor.put("door_type", 0); if (setcurrent.size() > 0) { diff --git a/src/main/java/me/eccentric_nz/TARDIS/listeners/controls/TARDISDirectionFrameListener.java b/src/main/java/me/eccentric_nz/TARDIS/listeners/controls/TARDISDirectionFrameListener.java index 209b22690..ee7171679 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/listeners/controls/TARDISDirectionFrameListener.java +++ b/src/main/java/me/eccentric_nz/TARDIS/listeners/controls/TARDISDirectionFrameListener.java @@ -16,9 +16,8 @@ */ package me.eccentric_nz.TARDIS.listeners.controls; -import java.util.HashMap; -import java.util.logging.Level; import me.eccentric_nz.TARDIS.TARDIS; +import me.eccentric_nz.TARDIS.database.data.Tardis; import me.eccentric_nz.TARDIS.database.resultset.ResultSetControls; import me.eccentric_nz.TARDIS.database.resultset.ResultSetCurrentLocation; import me.eccentric_nz.TARDIS.database.resultset.ResultSetTardis; @@ -31,6 +30,9 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEntityEvent; +import java.util.HashMap; +import java.util.logging.Level; + /** * @author eccentric_nz */ @@ -59,72 +61,102 @@ public void onDirectionFrameClick(PlayerInteractEntityEvent event) { HashMap wherep = new HashMap<>(); wherep.put("tardis_id", id); ResultSetTardis rso = new ResultSetTardis(plugin, wherep, "", false, 2); - if (rso.resultSet() && !rso.getTardis().getUuid().equals(player.getUniqueId())) { - event.setCancelled(true); - return; - } - // if the item frame has a tripwire hook in it - if (frame.getItem().getType().equals(Material.TRIPWIRE_HOOK)) { - if (plugin.getConfig().getBoolean("allow.power_down") && !rso.getTardis().isPowered_on()) { - TARDISMessage.send(player, "POWER_DOWN"); + if (rso.resultSet()) { + Tardis tardis = rso.getTardis(); + if (!tardis.getUuid().equals(player.getUniqueId())) { + event.setCancelled(true); return; } - String direction; - if (player.isSneaking()) { - // cancel the rotation! - event.setCancelled(true); - // perform the rotation - direction = switch (frame.getRotation()) { - case FLIPPED -> "NORTH"; - case COUNTER_CLOCKWISE -> "EAST"; - case NONE -> "SOUTH"; - default -> "WEST"; - }; - player.performCommand("tardis direction " + direction); - plugin.getLogger().log(Level.INFO, player.getName() + " issued server command: /tardis direction " + direction); - } else { - Rotation r; - // set the rotation - switch (frame.getRotation()) { - case FLIPPED -> { - r = Rotation.FLIPPED_45; - direction = "EAST"; - } - case COUNTER_CLOCKWISE -> { - r = Rotation.COUNTER_CLOCKWISE_45; - direction = "SOUTH"; - } - case NONE -> { - r = Rotation.CLOCKWISE_45; - direction = "WEST"; + // if the item frame has a tripwire hook in it + if (frame.getItem().getType().equals(Material.TRIPWIRE_HOOK)) { + if (plugin.getConfig().getBoolean("allow.power_down") && !rso.getTardis().isPowered_on()) { + TARDISMessage.send(player, "POWER_DOWN"); + return; + } + String direction; + if (player.isSneaking()) { + // cancel the rotation! + event.setCancelled(true); + // perform the rotation + direction = switch (frame.getRotation()) { + case FLIPPED -> "NORTH"; + case FLIPPED_45 -> "NORTH_EAST"; + case COUNTER_CLOCKWISE -> "EAST"; + case COUNTER_CLOCKWISE_45 -> "SOUTH_EAST"; + case NONE -> "SOUTH"; + case CLOCKWISE_45 -> "SOUTH_WEST"; + case CLOCKWISE -> "WEST"; + default -> "NORTH_WEST"; + }; + player.performCommand("tardis direction " + direction); + plugin.getLogger().log(Level.INFO, player.getName() + " issued server command: /tardis direction " + direction); + } else { + boolean isPreset = !tardis.getPreset().usesItemFrame(); + Rotation r; + // set the rotation + switch (frame.getRotation()) { + case FLIPPED -> { + r = Rotation.FLIPPED_45; + direction = (isPreset) ? "EAST" : "NORTH_EAST"; + } + case FLIPPED_45 -> { + r = Rotation.COUNTER_CLOCKWISE; + direction = "EAST"; + } + case COUNTER_CLOCKWISE_45 -> { + r = Rotation.NONE; + direction = "SOUTH"; + } + case CLOCKWISE_45 -> { + r = Rotation.CLOCKWISE; + direction = "WEST"; + } + case CLOCKWISE_135 -> { + r = Rotation.FLIPPED; + direction = "NORTH"; + } + case COUNTER_CLOCKWISE -> { + r = Rotation.COUNTER_CLOCKWISE_45; + direction = (isPreset) ? "SOUTH" : "SOUTH_EAST"; + } + case NONE -> { + r = Rotation.CLOCKWISE_45; + direction = (isPreset) ? "WEST" : "SOUTH_WEST"; + } + default -> { + r = Rotation.CLOCKWISE_135; + direction = (isPreset) ? "NORTH" : "NORTH_WEST"; + } } - default -> { - r = Rotation.CLOCKWISE_135; - direction = "NORTH"; + if (isPreset) { + frame.setRotation(r); } + TARDISMessage.send(player, "DIRECTON_SET", direction); } - frame.setRotation(r); - TARDISMessage.send(player, "DIRECTON_SET", direction); - } - } else { - // are they placing a tripwire hook? - if (frame.getItem().getType().isAir() && player.getInventory().getItemInMainHand().getType().equals(Material.TRIPWIRE_HOOK)) { - // get current tardis direction - HashMap wherec = new HashMap<>(); - wherec.put("tardis_id", id); - ResultSetCurrentLocation rscl = new ResultSetCurrentLocation(plugin, wherec); - if (rscl.resultSet()) { - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { - // update the TRIPWIRE_HOOK rotation - Rotation r = switch (rscl.getDirection()) { - case EAST -> Rotation.COUNTER_CLOCKWISE; - case SOUTH -> Rotation.NONE; - case WEST -> Rotation.CLOCKWISE; - default -> Rotation.FLIPPED; - }; - frame.setRotation(r); - TARDISMessage.send(player, "DIRECTION_CURRENT", rscl.getDirection().toString()); - }, 4L); + } else { + // are they placing a tripwire hook? + if (frame.getItem().getType().isAir() && player.getInventory().getItemInMainHand().getType().equals(Material.TRIPWIRE_HOOK)) { + // get current tardis direction + HashMap wherec = new HashMap<>(); + wherec.put("tardis_id", id); + ResultSetCurrentLocation rscl = new ResultSetCurrentLocation(plugin, wherec); + if (rscl.resultSet()) { + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { + // update the TRIPWIRE_HOOK rotation + Rotation r = switch (rscl.getDirection()) { + case EAST -> Rotation.COUNTER_CLOCKWISE; + case SOUTH_EAST -> Rotation.COUNTER_CLOCKWISE_45; + case SOUTH -> Rotation.NONE; + case SOUTH_WEST -> Rotation.CLOCKWISE_45; + case WEST -> Rotation.CLOCKWISE; + case NORTH_WEST -> Rotation.CLOCKWISE_135; + case NORTH -> Rotation.FLIPPED; + default -> Rotation.FLIPPED_45; + }; + frame.setRotation(r); + TARDISMessage.send(player, "DIRECTION_CURRENT", rscl.getDirection().toString()); + }, 4L); + } } } } diff --git a/src/main/java/me/eccentric_nz/TARDIS/move/TARDISDoorListener.java b/src/main/java/me/eccentric_nz/TARDIS/move/TARDISDoorListener.java index a7fa51a47..9afda54d8 100644 --- a/src/main/java/me/eccentric_nz/TARDIS/move/TARDISDoorListener.java +++ b/src/main/java/me/eccentric_nz/TARDIS/move/TARDISDoorListener.java @@ -16,9 +16,6 @@ */ package me.eccentric_nz.TARDIS.move; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; import me.eccentric_nz.TARDIS.TARDIS; import me.eccentric_nz.TARDIS.TARDISConstants; import me.eccentric_nz.TARDIS.api.event.TARDISEnterEvent; @@ -42,6 +39,10 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + /** * @author eccentric_nz */ @@ -352,10 +353,10 @@ private void giveKey(Player player) { */ public float adjustYaw(COMPASS d1, COMPASS d2) { return switch (d1) { - case EAST -> adjustYaw[0][d2.ordinal()]; - case SOUTH -> adjustYaw[1][d2.ordinal()]; - case WEST -> adjustYaw[2][d2.ordinal()]; - default -> adjustYaw[3][d2.ordinal()]; + case EAST -> adjustYaw[0][d2.ordinal() / 2]; + case SOUTH -> adjustYaw[1][d2.ordinal() / 2]; + case WEST -> adjustYaw[2][d2.ordinal() / 2]; + default -> adjustYaw[3][d2.ordinal() / 2]; }; } diff --git a/src/main/resources/en.yml b/src/main/resources/en.yml index 630a48522..f71745c23 100644 --- a/src/main/resources/en.yml +++ b/src/main/resources/en.yml @@ -392,8 +392,9 @@ DIFF_HARD_REMOTE: "You need to craft a Stattenheim Remote Control! Type %s to se DIFF_SAVED: "Difficulty preference saved." DIRECTION_CHANGED: "Direction changed." DIRECTION_CURRENT: "Current TARDIS direction is %s" -DIRECTION_NEED: "You need to specify the compass direction e.g. north, west, south or east!" +DIRECTION_NEED: "You need to specify the compass direction!" DIRECTION_NOT_FOUND: "Could not get the TARDIS direction!" +DIRECTION_PRESET: "Chameleon block presets can only be north, west, south or east!" DIRECTON_SET: "SHIFT-RIGHT click the Direction Frame to set the TARDIS to %s" DISABLED: "Disabled" DISK_BLANK_BIOME: "You must use a blank Biome Storage Disk!" diff --git a/todo.md b/todo.md index 3715aa455..f81bde01f 100755 --- a/todo.md +++ b/todo.md @@ -27,7 +27,7 @@ ## Wiki Documentation -* Add new surgery room +* ? ## Resource Pack / Monsters