Skip to content

Commit

Permalink
#693 Allow item frame chameleon presets to be rotated 45° angles
Browse files Browse the repository at this point in the history
  • Loading branch information
eccentricdevotion committed May 26, 2023
1 parent 05ea897 commit 8a80f46
Show file tree
Hide file tree
Showing 16 changed files with 199 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static void saveDoorLocation(BuildData bd) {
ResultSetDoors rsd = new ResultSetDoors(TARDIS.plugin, whered, false);
HashMap<String, Object> 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<String, Object> whereid = new HashMap<>();
whereid.put("door_id", rsd.getDoor_id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -475,7 +475,7 @@ private void processDoor(String doorloc) {
ResultSetDoors rsd = new ResultSetDoors(plugin, whered, false);
HashMap<String, Object> 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<String, Object> whereid = new HashMap<>();
whereid.put("door_id", rsd.getDoor_id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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<String, Object> 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<String, Object> whereid = new HashMap<>();
whereid.put("door_id", rsd.getDoor_id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,7 +39,6 @@
import org.bukkit.entity.Player;

import java.util.HashMap;
import java.util.Locale;
import java.util.UUID;

/**
Expand All @@ -55,19 +54,31 @@ 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<String, Object> where = new HashMap<>();
where.put("uuid", uuid.toString());
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;
Expand Down Expand Up @@ -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<String, Object> wherecl = new HashMap<>();
wherecl.put("tardis_id", id);
ResultSetCurrentLocation rsc = new ResultSetCurrentLocation(plugin, wherecl);
Expand All @@ -114,18 +125,17 @@ public boolean changeDirection(Player player, String[] args) {
HashMap<String, Object> tid = new HashMap<>();
HashMap<String, Object> set = new HashMap<>();
tid.put("tardis_id", id);
set.put("direction", dir);
set.put("direction", compass.toString());
plugin.getQueryFactory().doUpdate("current", set, tid);
HashMap<String, Object> did = new HashMap<>();
HashMap<String, Object> 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)) {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class TARDISTabComplete extends TARDISCompleter implements TabCompleter {
private final List<String> ON_OFF_SUBS = ImmutableList.of("on", "off");
private final List<String> DOOR_SUBS = ImmutableList.of("open", "close");
private final List<String> ITEM_SUBS = ImmutableList.of("hand", "inventory");
private final List<String> DIR_SUBS = ImmutableList.of("north", "west", "south", "east");
private final List<String> DIR_SUBS = ImmutableList.of("north", "west", "south", "east", "north_east", "north_west", "south_west", "south_east");
private final List<String> LIST_SUBS = ImmutableList.of("companions", "saves", "areas", "rechargers");
private final List<String> ARCHIVE_SUBS = ImmutableList.of("add", "description", "remove", "scan", "update", "y");
private final List<String> EXTRA_SUBS = ImmutableList.of("blocks", "unlock");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +31,8 @@
import org.bukkit.Location;
import org.bukkit.entity.Player;

import java.util.HashMap;

/**
*
* @author eccentric_nz
Expand Down Expand Up @@ -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<String, Object> tid = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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")) {
Expand Down
Loading

0 comments on commit 8a80f46

Please sign in to comment.