mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 13:36:33 +01:00
Make all teleportation signs respect yaw. Resolves #234
This commit is contained in:
parent
3366d3c9b9
commit
dceadc399b
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2018 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.sign;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.world.DGameWorld;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public abstract class LocationSign extends DSign {
|
||||
|
||||
protected Location location;
|
||||
|
||||
public LocationSign(Sign sign, String[] lines, DGameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
double x = sign.getX() + 0.5;
|
||||
double y = sign.getY();
|
||||
double z = sign.getZ() + 0.5;
|
||||
float yaw = letterToYaw(((org.bukkit.material.Sign) getSign().getData()).getFacing().getOppositeFace().name().charAt(0));
|
||||
float pitch = 0;
|
||||
location = new Location(gameWorld.getWorld(), x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* the location marked by this sign
|
||||
*/
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
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':
|
||||
return -90;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -18,7 +18,6 @@ package io.github.dre2n.dungeonsxl.sign;
|
||||
|
||||
import de.erethon.commons.misc.NumberUtil;
|
||||
import io.github.dre2n.dungeonsxl.world.DGameWorld;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -26,12 +25,10 @@ import org.bukkit.entity.Player;
|
||||
/**
|
||||
* @author Milan Albrecht, Daniel Saukel
|
||||
*/
|
||||
public class TeleportSign extends DSign {
|
||||
public class TeleportSign extends LocationSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.TELEPORT;
|
||||
|
||||
private Location location;
|
||||
|
||||
public TeleportSign(Sign sign, String[] lines, DGameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
@ -53,8 +50,6 @@ 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)));
|
||||
for (int i = 1; i <= 2; i++) {
|
||||
if (!lines[i].isEmpty()) {
|
||||
int yaw = letterToYaw(lines[i].charAt(0));
|
||||
@ -103,23 +98,4 @@ public class TeleportSign extends DSign {
|
||||
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':
|
||||
return -90;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.sign.lobby;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.sign.DSign;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSignType;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault;
|
||||
import io.github.dre2n.dungeonsxl.sign.LocationSign;
|
||||
import io.github.dre2n.dungeonsxl.world.DGameWorld;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
@ -26,7 +26,7 @@ import org.bukkit.block.Sign;
|
||||
/**
|
||||
* @author Frank Baumann, Daniel Saukel
|
||||
*/
|
||||
public class LobbySign extends DSign {
|
||||
public class LobbySign extends LocationSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.LOBBY;
|
||||
|
||||
@ -41,7 +41,7 @@ public class LobbySign extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
getGameWorld().setLobbyLocation(getSign().getLocation());
|
||||
getGameWorld().setLobbyLocation(getLocation());
|
||||
getSign().getBlock().setType(Material.AIR);
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,9 @@
|
||||
package io.github.dre2n.dungeonsxl.sign.lobby;
|
||||
|
||||
import de.erethon.commons.misc.NumberUtil;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSign;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSignType;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault;
|
||||
import io.github.dre2n.dungeonsxl.sign.LocationSign;
|
||||
import io.github.dre2n.dungeonsxl.world.DGameWorld;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
@ -27,7 +27,7 @@ import org.bukkit.block.Sign;
|
||||
/**
|
||||
* @author Frank Baumann, Daniel Saukel
|
||||
*/
|
||||
public class StartSign extends DSign {
|
||||
public class StartSign extends LocationSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.START;
|
||||
|
||||
|
@ -29,6 +29,7 @@ import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSign;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSignType;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault;
|
||||
import io.github.dre2n.dungeonsxl.sign.LocationSign;
|
||||
import io.github.dre2n.dungeonsxl.sign.lobby.StartSign;
|
||||
import io.github.dre2n.dungeonsxl.sign.mob.MobSign;
|
||||
import io.github.dre2n.dungeonsxl.trigger.FortuneTrigger;
|
||||
@ -172,7 +173,7 @@ public class DGameWorld extends DInstanceWorld {
|
||||
for (DSign dSign : dSigns) {
|
||||
if (dSign.getType() == DSignTypeDefault.START) {
|
||||
if (((StartSign) dSign).getId() == index) {
|
||||
return dSign.getSign().getLocation();
|
||||
return ((LocationSign) dSign).getLocation();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -180,7 +181,7 @@ public class DGameWorld extends DInstanceWorld {
|
||||
// Try any location
|
||||
for (DSign dSign : dSigns) {
|
||||
if (dSign.getType() == DSignTypeDefault.START) {
|
||||
return dSign.getSign().getLocation();
|
||||
return ((LocationSign) dSign).getLocation();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user