Skip to content

Commit 8a80f46

Browse files
#693 Allow item frame chameleon presets to be rotated 45° angles
1 parent 05ea897 commit 8a80f46

16 files changed

+199
-128
lines changed

src/main/java/me/eccentric_nz/TARDIS/builders/TARDISBuilderUtility.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static void saveDoorLocation(BuildData bd) {
4343
ResultSetDoors rsd = new ResultSetDoors(TARDIS.plugin, whered, false);
4444
HashMap<String, Object> setd = new HashMap<>();
4545
setd.put("door_location", doorloc);
46-
setd.put("door_direction", bd.getDirection().toString());
46+
setd.put("door_direction", bd.getDirection().forPreset().toString());
4747
if (rsd.resultSet()) {
4848
HashMap<String, Object> whereid = new HashMap<>();
4949
whereid.put("door_id", rsd.getDoor_id());

src/main/java/me/eccentric_nz/TARDIS/builders/TARDISInstantPreset.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ public void buildPreset() {
9090
}
9191
TARDISChameleonColumn column;
9292
if (preset.equals(ChameleonPreset.CONSTRUCT)) {
93-
column = new TARDISConstructColumn(plugin, bd.getTardisID(), "blueprintData", bd.getDirection()).getColumn();
93+
column = new TARDISConstructColumn(plugin, bd.getTardisID(), "blueprintData", bd.getDirection().forPreset()).getColumn();
9494
if (column == null) {
9595
TARDISMessage.send(bd.getPlayer().getPlayer(), "INVALID_CONSTRUCT");
9696
return;
9797
}
9898
} else {
99-
column = plugin.getPresets().getColumn(preset, bd.getDirection());
99+
column = plugin.getPresets().getColumn(preset, bd.getDirection().forPreset());
100100
}
101101
int plusx, minusx, x, plusz, y, minusz, z;
102102
// get relative locations
@@ -129,7 +129,7 @@ public void buildPreset() {
129129
}
130130
plugin.getTrackerKeeper().getRescue().remove(bd.getTardisID());
131131
}
132-
switch (bd.getDirection()) {
132+
switch (bd.getDirection().forPreset()) {
133133
case SOUTH -> {
134134
//if (yaw >= 315 || yaw < 45)
135135
signx = x;
@@ -412,7 +412,7 @@ public void buildPreset() {
412412
TARDISBlockSetters.setBlock(world, xx, (y + yy), zz, Material.GLOWSTONE);
413413
} else {
414414
Rotatable rotatable = (Rotatable) colData[yy];
415-
rotatable.setRotation(plugin.getPresetBuilder().getSkullDirection(bd.getDirection()));
415+
rotatable.setRotation(plugin.getPresetBuilder().getSkullDirection(bd.getDirection().forPreset()));
416416
TARDISBlockSetters.setBlockAndRemember(world, xx, (y + yy), zz, rotatable, bd.getTardisID());
417417
}
418418
}
@@ -475,7 +475,7 @@ private void processDoor(String doorloc) {
475475
ResultSetDoors rsd = new ResultSetDoors(plugin, whered, false);
476476
HashMap<String, Object> setd = new HashMap<>();
477477
setd.put("door_location", doorloc);
478-
setd.put("door_direction", bd.getDirection().toString());
478+
setd.put("door_direction", bd.getDirection().forPreset().toString());
479479
if (rsd.resultSet()) {
480480
HashMap<String, Object> whereid = new HashMap<>();
481481
whereid.put("door_id", rsd.getDoor_id());

src/main/java/me/eccentric_nz/TARDIS/builders/TARDISMaterialisePreset.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ class TARDISMaterialisePreset implements Runnable {
102102
plugin.getPresets().setR(TARDISConstants.RANDOM.nextInt(2));
103103
}
104104
if (this.preset.equals(ChameleonPreset.CONSTRUCT)) {
105-
column = new TARDISConstructColumn(plugin, bd.getTardisID(), "blueprintData", bd.getDirection()).getColumn();
106-
stained_column = new TARDISConstructColumn(plugin, bd.getTardisID(), "stainData", bd.getDirection()).getColumn();
107-
glass_column = new TARDISConstructColumn(plugin, bd.getTardisID(), "glassData", bd.getDirection()).getColumn();
105+
column = new TARDISConstructColumn(plugin, bd.getTardisID(), "blueprintData", bd.getDirection().forPreset()).getColumn();
106+
stained_column = new TARDISConstructColumn(plugin, bd.getTardisID(), "stainData", bd.getDirection().forPreset()).getColumn();
107+
glass_column = new TARDISConstructColumn(plugin, bd.getTardisID(), "glassData", bd.getDirection().forPreset()).getColumn();
108108
} else {
109-
column = plugin.getPresets().getColumn(preset, bd.getDirection());
110-
stained_column = plugin.getPresets().getStained(preset, bd.getDirection());
111-
glass_column = plugin.getPresets().getGlass(preset, bd.getDirection());
109+
column = plugin.getPresets().getColumn(preset, bd.getDirection().forPreset());
110+
stained_column = plugin.getPresets().getStained(preset, bd.getDirection().forPreset());
111+
glass_column = plugin.getPresets().getGlass(preset, bd.getDirection().forPreset());
112112
}
113113
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};
114114
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() {
190190
}
191191
}
192192
// get direction player is facing from yaw place block under door if block is in list of blocks an iron door cannot go on
193-
switch (bd.getDirection()) {
193+
switch (bd.getDirection().forPreset()) {
194194
case SOUTH -> {
195195
// if (yaw >= 315 || yaw < 45)
196196
signx = x;
@@ -477,7 +477,7 @@ public void run() {
477477
TARDISBlockSetters.setBlock(world, xx, (y + yy), zz, Material.GLOWSTONE);
478478
} else {
479479
Rotatable rotatable = (Rotatable) colData[yy];
480-
rotatable.setRotation(plugin.getPresetBuilder().getSkullDirection(bd.getDirection()));
480+
rotatable.setRotation(plugin.getPresetBuilder().getSkullDirection(bd.getDirection().forPreset()));
481481
TARDISBlockSetters.setBlockAndRemember(world, xx, (y + yy), zz, rotatable, bd.getTardisID());
482482
}
483483
}
@@ -659,7 +659,7 @@ public void run() {
659659
TARDISBlockSetters.setBlock(world, xx, (y + yy), zz, Material.GLOWSTONE);
660660
} else {
661661
Rotatable rotatable = (Rotatable) coldatas[yy];
662-
rotatable.setRotation(plugin.getPresetBuilder().getSkullDirection(bd.getDirection()));
662+
rotatable.setRotation(plugin.getPresetBuilder().getSkullDirection(bd.getDirection().forPreset()));
663663
TARDISBlockSetters.setBlock(world, xx, (y + yy), zz, rotatable);
664664
}
665665
}
@@ -780,7 +780,7 @@ private void saveDoorLocation(World world, int xx, int y, int yy, int zz) {
780780
ResultSetDoors rsd = new ResultSetDoors(plugin, whered, false);
781781
HashMap<String, Object> setd = new HashMap<>();
782782
setd.put("door_location", doorloc);
783-
setd.put("door_direction", bd.getDirection().toString());
783+
setd.put("door_direction", bd.getDirection().forPreset().toString());
784784
if (rsd.resultSet()) {
785785
HashMap<String, Object> whereid = new HashMap<>();
786786
whereid.put("door_id", rsd.getDoor_id());

src/main/java/me/eccentric_nz/TARDIS/builders/TARDISPresetBuilderFactory.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
*/
1717
package me.eccentric_nz.TARDIS.builders;
1818

19-
import java.util.ArrayList;
20-
import java.util.HashMap;
21-
import java.util.List;
2219
import me.eccentric_nz.TARDIS.TARDIS;
2320
import me.eccentric_nz.TARDIS.TARDISConstants;
2421
import me.eccentric_nz.TARDIS.chameleon.utils.TARDISChameleonCircuit;
@@ -38,6 +35,10 @@
3835
import org.bukkit.block.Block;
3936
import org.bukkit.block.BlockFace;
4037

38+
import java.util.ArrayList;
39+
import java.util.HashMap;
40+
import java.util.List;
41+
4142
/**
4243
* The Wibbly lever was a part of The Doctor's TARDIS console. The lever had at least two functions: opening and closing
4344
* 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) {
9293
thisChunk.load();
9394
}
9495
if (bd.isRebuild()) {
95-
biome = bd.getLocation().getBlock().getRelative(getOppositeFace(bd.getDirection()), 2).getBiome();
96+
biome = bd.getLocation().getBlock().getRelative(getOppositeFace(bd.getDirection().forPreset()), 2).getBiome();
9697
} else {
9798
biome = bd.getLocation().getBlock().getBiome();
9899
// disable force field

src/main/java/me/eccentric_nz/TARDIS/commands/tardis/TARDISDirectionCommand.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import me.eccentric_nz.TARDIS.database.resultset.ResultSetCurrentLocation;
2626
import me.eccentric_nz.TARDIS.database.resultset.ResultSetTardis;
2727
import me.eccentric_nz.TARDIS.enumeration.COMPASS;
28-
import me.eccentric_nz.TARDIS.enumeration.Difficulty;
2928
import me.eccentric_nz.TARDIS.enumeration.ChameleonPreset;
29+
import me.eccentric_nz.TARDIS.enumeration.Difficulty;
3030
import me.eccentric_nz.TARDIS.enumeration.SpaceTimeThrottle;
3131
import me.eccentric_nz.TARDIS.messaging.TARDISMessage;
3232
import me.eccentric_nz.TARDIS.move.TARDISDoorCloser;
@@ -39,7 +39,6 @@
3939
import org.bukkit.entity.Player;
4040

4141
import java.util.HashMap;
42-
import java.util.Locale;
4342
import java.util.UUID;
4443

4544
/**
@@ -55,19 +54,31 @@ public TARDISDirectionCommand(TARDIS plugin) {
5554

5655
public boolean changeDirection(Player player, String[] args) {
5756
if (TARDISPermission.hasPermission(player, "tardis.timetravel")) {
58-
if (args.length < 2 || (!args[1].equalsIgnoreCase("north") && !args[1].equalsIgnoreCase("west") && !args[1].equalsIgnoreCase("south") && !args[1].equalsIgnoreCase("east"))) {
57+
if (args.length < 2) {
5958
TARDISMessage.send(player, "DIRECTION_NEED");
60-
return false;
59+
return true;
60+
}
61+
COMPASS compass;
62+
try {
63+
compass = COMPASS.valueOf(args[1].toUpperCase());
64+
} catch (IllegalArgumentException e) {
65+
TARDISMessage.send(player, "DIRECTION_NEED");
66+
return true;
6167
}
6268
UUID uuid = player.getUniqueId();
6369
HashMap<String, Object> where = new HashMap<>();
6470
where.put("uuid", uuid.toString());
6571
ResultSetTardis rs = new ResultSetTardis(plugin, where, "", false, 0);
6672
if (!rs.resultSet()) {
6773
TARDISMessage.send(player, "NO_TARDIS");
68-
return false;
74+
return true;
6975
}
7076
Tardis tardis = rs.getTardis();
77+
if (!tardis.getPreset().usesItemFrame()
78+
&& (args[1].equalsIgnoreCase("north_east") || args[1].equalsIgnoreCase("north_west") || args[1].equalsIgnoreCase("south_west") || args[1].equalsIgnoreCase("south_east"))) {
79+
TARDISMessage.send(player, "DIRECTION_PRESET");
80+
return true;
81+
}
7182
if (plugin.getConfig().getBoolean("allow.power_down") && !tardis.isPowered_on()) {
7283
TARDISMessage.send(player, "POWER_DOWN");
7384
return true;
@@ -102,7 +113,7 @@ public boolean changeDirection(Player player, String[] args) {
102113
}
103114
boolean hid = tardis.isHidden();
104115
ChameleonPreset demat = tardis.getDemat();
105-
String dir = args[1].toUpperCase(Locale.ENGLISH);
116+
// String dir = args[1].toUpperCase(Locale.ENGLISH);
106117
HashMap<String, Object> wherecl = new HashMap<>();
107118
wherecl.put("tardis_id", id);
108119
ResultSetCurrentLocation rsc = new ResultSetCurrentLocation(plugin, wherecl);
@@ -114,18 +125,17 @@ public boolean changeDirection(Player player, String[] args) {
114125
HashMap<String, Object> tid = new HashMap<>();
115126
HashMap<String, Object> set = new HashMap<>();
116127
tid.put("tardis_id", id);
117-
set.put("direction", dir);
128+
set.put("direction", compass.toString());
118129
plugin.getQueryFactory().doUpdate("current", set, tid);
119130
HashMap<String, Object> did = new HashMap<>();
120131
HashMap<String, Object> setd = new HashMap<>();
121132
did.put("door_type", 0);
122133
did.put("tardis_id", id);
123-
setd.put("door_direction", dir);
134+
setd.put("door_direction", compass.forPreset().toString());
124135
plugin.getQueryFactory().doUpdate("doors", setd, did);
125136
// close doors & therefore remove open portals...
126137
new TARDISDoorCloser(plugin, uuid, id).closeDoors();
127138
Location l = new Location(rsc.getWorld(), rsc.getX(), rsc.getY(), rsc.getZ());
128-
COMPASS d = COMPASS.valueOf(dir);
129139
// destroy sign
130140
if (!hid) {
131141
if (demat.equals(ChameleonPreset.DUCK)) {
@@ -143,7 +153,7 @@ public boolean changeDirection(Player player, String[] args) {
143153
plugin.getPresetDestroyer().destroyDoor(id);
144154
plugin.getPresetDestroyer().destroySign(l, old_d, demat);
145155
BuildData bd = new BuildData(uuid.toString());
146-
bd.setDirection(d);
156+
bd.setDirection(compass);
147157
bd.setLocation(l);
148158
bd.setMalfunction(false);
149159
bd.setOutside(false);
@@ -173,11 +183,15 @@ public boolean changeDirection(Player player, String[] args) {
173183
}
174184
for (Entity e : chunk.getEntities()) {
175185
if (e instanceof ItemFrame frame && e.getLocation().toString().equals(locToCheck)) {
176-
Rotation r = switch (d) {
186+
Rotation r = switch (compass) {
177187
case EAST -> Rotation.COUNTER_CLOCKWISE;
188+
case SOUTH_EAST -> Rotation.COUNTER_CLOCKWISE_45;
178189
case SOUTH -> Rotation.NONE;
190+
case SOUTH_WEST -> Rotation.CLOCKWISE_45;
179191
case WEST -> Rotation.CLOCKWISE;
180-
default -> Rotation.FLIPPED;
192+
case NORTH_WEST -> Rotation.CLOCKWISE_135;
193+
case NORTH -> Rotation.FLIPPED;
194+
default -> Rotation.FLIPPED_45;
181195
};
182196
frame.setRotation(r);
183197
break;

src/main/java/me/eccentric_nz/TARDIS/commands/tardis/TARDISTabComplete.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class TARDISTabComplete extends TARDISCompleter implements TabCompleter {
4242
private final List<String> ON_OFF_SUBS = ImmutableList.of("on", "off");
4343
private final List<String> DOOR_SUBS = ImmutableList.of("open", "close");
4444
private final List<String> ITEM_SUBS = ImmutableList.of("hand", "inventory");
45-
private final List<String> DIR_SUBS = ImmutableList.of("north", "west", "south", "east");
45+
private final List<String> DIR_SUBS = ImmutableList.of("north", "west", "south", "east", "north_east", "north_west", "south_west", "south_east");
4646
private final List<String> LIST_SUBS = ImmutableList.of("companions", "saves", "areas", "rechargers");
4747
private final List<String> ARCHIVE_SUBS = ImmutableList.of("add", "description", "remove", "scan", "update", "y");
4848
private final List<String> EXTRA_SUBS = ImmutableList.of("blocks", "unlock");

src/main/java/me/eccentric_nz/TARDIS/commands/travel/TARDISTravelArea.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
*/
1717
package me.eccentric_nz.TARDIS.commands.travel;
1818

19-
import java.util.HashMap;
2019
import me.eccentric_nz.TARDIS.TARDIS;
2120
import me.eccentric_nz.TARDIS.api.event.TARDISTravelEvent;
2221
import me.eccentric_nz.TARDIS.blueprints.TARDISPermission;
2322
import me.eccentric_nz.TARDIS.database.resultset.ResultSetAreas;
2423
import me.eccentric_nz.TARDIS.database.resultset.ResultSetCurrentLocation;
25-
import me.eccentric_nz.TARDIS.enumeration.Difficulty;
2624
import me.eccentric_nz.TARDIS.enumeration.ChameleonPreset;
25+
import me.eccentric_nz.TARDIS.enumeration.Difficulty;
2726
import me.eccentric_nz.TARDIS.enumeration.TravelType;
2827
import me.eccentric_nz.TARDIS.flight.TARDISLand;
2928
import me.eccentric_nz.TARDIS.messaging.TARDISMessage;
@@ -32,6 +31,8 @@
3231
import org.bukkit.Location;
3332
import org.bukkit.entity.Player;
3433

34+
import java.util.HashMap;
35+
3536
/**
3637
*
3738
* @author eccentric_nz
@@ -104,7 +105,7 @@ public boolean action(Player player, String[] args, int id, ChameleonPreset pres
104105
TARDISMessage.send(player, "CURRENT_NOT_FOUND");
105106
return true;
106107
}
107-
set.put("direction", rsc.getDirection().toString());
108+
set.put("direction", rsc.getDirection().forPreset().toString());
108109
}
109110
set.put("submarine", 0);
110111
HashMap<String, Object> tid = new HashMap<>();

src/main/java/me/eccentric_nz/TARDIS/destroyers/TARDISDeinstantPreset.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*/
1717
package me.eccentric_nz.TARDIS.destroyers;
1818

19-
import java.util.Collections;
20-
import java.util.HashMap;
2119
import me.eccentric_nz.TARDIS.TARDIS;
2220
import me.eccentric_nz.TARDIS.TARDISConstants;
2321
import me.eccentric_nz.TARDIS.builders.MaterialisationData;
@@ -37,6 +35,9 @@
3735
import org.bukkit.entity.Entity;
3836
import org.bukkit.entity.ItemFrame;
3937

38+
import java.util.Collections;
39+
import java.util.HashMap;
40+
4041
/**
4142
* A police box is a telephone kiosk that can be used by members of the public wishing to get help from the police.
4243
* 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) {
6263
public void instaDestroyPreset(MaterialisationData dd, boolean hide, ChameleonPreset preset) {
6364

6465
Location l = dd.getLocation();
65-
COMPASS d = dd.getDirection();
66+
COMPASS d = dd.getDirection().forPreset();
6667
int id = dd.getTardisID();
6768
boolean sub = dd.isSubmarine();
6869
if (plugin.getConfig().getBoolean("preferences.walk_in_tardis")) {

0 commit comments

Comments
 (0)