Minor improvements for #85. Resolves #84

This commit is contained in:
Daniel Saukel 2016-06-08 16:28:53 +02:00
parent 969fc44d4e
commit 7716ed0cad
2 changed files with 111 additions and 105 deletions

View File

@ -45,9 +45,9 @@ public enum DSignTypeDefault implements DSignType {
SCRIPT("Script", "script", false, ScriptSign.class), SCRIPT("Script", "script", false, ScriptSign.class),
SOUND_MESSAGE("SoundMSG", "soundmsg", false, SoundMessageSign.class), SOUND_MESSAGE("SoundMSG", "soundmsg", false, SoundMessageSign.class),
START("Start", "start", true, StartSign.class), START("Start", "start", true, StartSign.class),
TELEPORT("Teleport", "teleport", false, TeleportSign.class),
TRIGGER("Trigger", "trigger", true, TriggerSign.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 name;
private String buildPermission; private String buildPermission;

View File

@ -1,22 +1,41 @@
/*
* Copyright (C) 2012-2016 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; package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.world.GameWorld; import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/**
* @author Milan Albrecht
*/
public class TeleportSign extends DSign { public class TeleportSign extends DSign {
private DSignType type = DSignTypeDefault.TELEPORT; private DSignType type = DSignTypeDefault.TELEPORT;
private Location location; private Location location;
public TeleportSign(Sign sign, GameWorld gameWorld) { public TeleportSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, gameWorld); super(sign, lines, gameWorld);
} }
@SuppressWarnings("ResultOfMethodCallIgnored")
@Override @Override
public boolean check() { public boolean check() {
String lines[] = getSign().getLines(); String lines[] = getSign().getLines();
@ -27,13 +46,9 @@ public class TeleportSign extends DSign {
if (loc.length != 3) { if (loc.length != 3) {
return false; return false;
} }
try { NumberUtil.parseDouble(loc[0]);
Double.parseDouble(loc[0]); NumberUtil.parseDouble(loc[1]);
Double.parseDouble(loc[1]); NumberUtil.parseDouble(loc[2]);
Double.parseDouble(loc[2]);
} catch (NumberFormatException e) {
return false;
}
} }
} }
} }
@ -53,25 +68,17 @@ public class TeleportSign extends DSign {
} else { } else {
String[] loc = lines[i].split(","); String[] loc = lines[i].split(",");
if (loc.length == 3) { if (loc.length == 3) {
try { double x = NumberUtil.parseDouble(loc[0]);
double x = Double.parseDouble(loc[0]); double y = NumberUtil.parseDouble(loc[1]);
double y = Double.parseDouble(loc[1]); double z = NumberUtil.parseDouble(loc[2]);
double z = Double.parseDouble(loc[2]);
// If round number, add 0.5 to tp to middle of block // If round number, add 0.5 to tp to middle of block
try { x = NumberUtil.parseInt(loc[0]) + 0.5;
x = Integer.parseInt(loc[0]) + 0.5; z = NumberUtil.parseInt(loc[2]) + 0.5;
} catch (NumberFormatException ignored) {}
try {
z = Integer.parseInt(loc[2]) + 0.5;
} catch (NumberFormatException ignored) {}
location.setX(x); location.setX(x);
location.setY(y); location.setY(y);
location.setZ(z); location.setZ(z);
} catch (NumberFormatException e) {
e.printStackTrace();
}
} }
} }
} }
@ -114,11 +121,10 @@ public class TeleportSign extends DSign {
return 180; return 180;
case 'E': case 'E':
case 'e': case 'e':
case 'O':
case 'o':
return -90; return -90;
default: default:
return -1; return -1;
} }
} }
} }