-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
969fc44
commit 7716ed0
Showing
2 changed files
with
111 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
212 changes: 109 additions & 103 deletions
212
src/main/java/io/github/dre2n/dungeonsxl/sign/TeleportSign.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,130 @@ | ||
/* | ||
* 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; | ||
|
||
import io.github.dre2n.commons.util.NumberUtil; | ||
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; | ||
|
||
/** | ||
* @author Milan Albrecht | ||
*/ | ||
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) { | ||
super(sign, gameWorld); | ||
} | ||
public TeleportSign(Sign sign, String[] lines, GameWorld gameWorld) { | ||
super(sign, lines, gameWorld); | ||
} | ||
|
||
@SuppressWarnings("ResultOfMethodCallIgnored") | ||
@Override | ||
public boolean check() { | ||
String lines[] = getSign().getLines(); | ||
for (int i = 1; i <= 2; i++) { | ||
if (!lines[i].isEmpty()) { | ||
if (letterToYaw(lines[i].charAt(0)) == -1) { | ||
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 boolean check() { | ||
String lines[] = getSign().getLines(); | ||
for (int i = 1; i <= 2; i++) { | ||
if (!lines[i].isEmpty()) { | ||
if (letterToYaw(lines[i].charAt(0)) == -1) { | ||
String[] loc = lines[i].split(","); | ||
if (loc.length != 3) { | ||
return false; | ||
} | ||
NumberUtil.parseDouble(loc[0]); | ||
NumberUtil.parseDouble(loc[1]); | ||
NumberUtil.parseDouble(loc[2]); | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@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()) { | ||
int yaw = letterToYaw(lines[i].charAt(0)); | ||
if (yaw != -1) { | ||
location.setYaw(yaw); | ||
} 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]); | ||
@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()) { | ||
int yaw = letterToYaw(lines[i].charAt(0)); | ||
if (yaw != -1) { | ||
location.setYaw(yaw); | ||
} else { | ||
String[] loc = lines[i].split(","); | ||
if (loc.length == 3) { | ||
double x = NumberUtil.parseDouble(loc[0]); | ||
double y = NumberUtil.parseDouble(loc[1]); | ||
double z = NumberUtil.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) {} | ||
// If round number, add 0.5 to tp to middle of block | ||
x = NumberUtil.parseInt(loc[0]) + 0.5; | ||
z = NumberUtil.parseInt(loc[2]) + 0.5; | ||
|
||
location.setX(x); | ||
location.setY(y); | ||
location.setZ(z); | ||
} catch (NumberFormatException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
getSign().getBlock().setType(Material.AIR); | ||
} | ||
location.setX(x); | ||
location.setY(y); | ||
location.setZ(z); | ||
} | ||
} | ||
} | ||
} | ||
getSign().getBlock().setType(Material.AIR); | ||
} | ||
|
||
@Override | ||
public void onTrigger() { | ||
if (location != null) { | ||
for (Player player : getGameWorld().getWorld().getPlayers()) { | ||
player.teleport(location); | ||
} | ||
} | ||
} | ||
@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 boolean onPlayerTrigger(Player player) { | ||
if (location != null) { | ||
player.teleport(location); | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public DSignType getType() { | ||
return type; | ||
} | ||
@Override | ||
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': | ||
return -90; | ||
default: | ||
return -1; | ||
} | ||
} | ||
|
||
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; | ||
} | ||
} | ||
} |