From 479935f00797d0d76e31cad5bb8f03fa6f64009b Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Wed, 1 Jun 2016 15:22:04 +0200 Subject: [PATCH 1/2] Added TeleportSign --- .../dungeonsxl/sign/DSignTypeDefault.java | 3 +- .../dre2n/dungeonsxl/sign/TeleportSign.java | 109 ++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/sign/TeleportSign.java diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index 875c8ee5..7de7165a 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -45,7 +45,8 @@ public enum DSignTypeDefault implements DSignType { SOUND_MESSAGE("SoundMSG", "soundmsg", false, SoundMessageSign.class), START("Start", "start", true, StartSign.class), TRIGGER("Trigger", "trigger", true, TriggerSign.class), - WAVE("Wave", "wave", false, WaveSign.class); + WAVE("Wave", "wave", false, WaveSign.class), + TELEPORT("Teleport", "teleport", false, TeleportSign.class); private String name; private String buildPermission; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/TeleportSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/TeleportSign.java new file mode 100644 index 00000000..3d301ed5 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/TeleportSign.java @@ -0,0 +1,109 @@ +package io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.dungeonsxl.world.GameWorld; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; + +public class TeleportSign extends DSign { + + private DSignType type = DSignTypeDefault.TELEPORT; + + private Location location; + + public TeleportSign(Sign sign, GameWorld gameWorld) { + super(sign, gameWorld); + } + + @SuppressWarnings("ResultOfMethodCallIgnored") + @Override + public boolean check() { + String lines[] = getSign().getLines(); + for (int i = 1; i <= 2; i++) { + if (!lines[i].isEmpty()) { + if (lines[i].equalsIgnoreCase("N") || lines[i].equalsIgnoreCase("E") || lines[i].equalsIgnoreCase("S") || lines[i].equalsIgnoreCase("W")) { + continue; + } else { + String[] loc = lines[i].split(","); + if (loc.length != 3) { + return false; + } + try { + Double.parseDouble(loc[0]); + Double.parseDouble(loc[1]); + Double.parseDouble(loc[2]); + } catch (NumberFormatException e) { + return false; + } + } + } + } + return true; + } + + @Override + public void onInit() { + location = getSign().getLocation().add(0.5, 0, 0.5); + String lines[] = getSign().getLines(); + for (int i = 1; i <= 2; i++) { + if (!lines[i].isEmpty()) { + if (lines[i].equalsIgnoreCase("S")) { + location.setYaw(0); + } else if (lines[i].equalsIgnoreCase("W")) { + location.setYaw(90); + } else if (lines[i].equalsIgnoreCase("N")) { + location.setYaw(180); + } else if (lines[i].equalsIgnoreCase("E")) { + location.setYaw(-90); + } else { + String[] loc = lines[i].split(","); + if (loc.length == 3) { + try { + double x = Double.parseDouble(loc[0]); + double y = Double.parseDouble(loc[1]); + double z = Double.parseDouble(loc[2]); + + // If round number, add 0.5 to tp to middle of block + try { + x = Integer.parseInt(loc[0]) + 0.5; + } catch (NumberFormatException ignored) {} + try { + z = Integer.parseInt(loc[2]) + 0.5; + } catch (NumberFormatException ignored) {} + + location.setX(x); + location.setY(y); + location.setZ(z); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } + } + } + } + getSign().getBlock().setType(Material.AIR); + } + + @Override + public void onTrigger() { + if (location != null) { + for (Player player : getGameWorld().getWorld().getPlayers()) { + player.teleport(location); + } + } + } + + @Override + public boolean onPlayerTrigger(Player player) { + if (location != null) { + player.teleport(location); + } + return true; + } + + @Override + public DSignType getType() { + return type; + } +} From dd8d3b1d0fef83bff53401f95e1f4dd302a4abb2 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Wed, 1 Jun 2016 21:35:23 +0200 Subject: [PATCH 2/2] If no direction on sign, use sign rotation --- .../dre2n/dungeonsxl/sign/TeleportSign.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/TeleportSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/TeleportSign.java index 3d301ed5..66349d59 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/TeleportSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/TeleportSign.java @@ -22,9 +22,7 @@ public class TeleportSign extends DSign { String lines[] = getSign().getLines(); for (int i = 1; i <= 2; i++) { if (!lines[i].isEmpty()) { - if (lines[i].equalsIgnoreCase("N") || lines[i].equalsIgnoreCase("E") || lines[i].equalsIgnoreCase("S") || lines[i].equalsIgnoreCase("W")) { - continue; - } else { + if (letterToYaw(lines[i].charAt(0)) == -1) { String[] loc = lines[i].split(","); if (loc.length != 3) { return false; @@ -45,17 +43,13 @@ public class TeleportSign extends DSign { @Override public void onInit() { location = getSign().getLocation().add(0.5, 0, 0.5); + location.setYaw(letterToYaw(((org.bukkit.material.Sign) getSign().getData()).getFacing().getOppositeFace().name().charAt(0))); String lines[] = getSign().getLines(); for (int i = 1; i <= 2; i++) { if (!lines[i].isEmpty()) { - if (lines[i].equalsIgnoreCase("S")) { - location.setYaw(0); - } else if (lines[i].equalsIgnoreCase("W")) { - location.setYaw(90); - } else if (lines[i].equalsIgnoreCase("N")) { - location.setYaw(180); - } else if (lines[i].equalsIgnoreCase("E")) { - location.setYaw(-90); + int yaw = letterToYaw(lines[i].charAt(0)); + if (yaw != -1) { + location.setYaw(yaw); } else { String[] loc = lines[i].split(","); if (loc.length == 3) { @@ -106,4 +100,25 @@ public class TeleportSign extends DSign { public DSignType getType() { return type; } + + public static int letterToYaw(char c) { + switch (c) { + case 'S': + case 's': + return 0; + case 'W': + case 'w': + return 90; + case 'N': + case 'n': + return 180; + case 'E': + case 'e': + case 'O': + case 'o': + return -90; + default: + return -1; + } + } }