Pull out duplicated method sub in BukkitPlayer

This commit is contained in:
sauilitired 2018-08-20 12:15:03 +02:00
parent 587c942d88
commit 032484b0f5

View File

@ -10,6 +10,7 @@ import org.bukkit.Effect;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.WeatherType; import org.bukkit.WeatherType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventException; import org.bukkit.event.EventException;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@ -63,6 +64,16 @@ public class BukkitPlayer extends PlotPlayer {
org.bukkit.Location to = BukkitUtil.getLocation(loc); org.bukkit.Location to = BukkitUtil.getLocation(loc);
org.bukkit.Location from = player.getLocation(); org.bukkit.Location from = player.getLocation();
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to); PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
callEvent(event);
if (event.isCancelled() || !event.getTo().equals(to)) {
return false;
}
event = new PlayerTeleportEvent(player, to, from);
callEvent(event);
return true;
}
private void callEvent(final Event event) {
RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners(); RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners();
for (RegisteredListener listener : listeners) { for (RegisteredListener listener : listeners) {
if (listener.getPlugin().getName().equals(PS.imp().getPluginName())) { if (listener.getPlugin().getName().equals(PS.imp().getPluginName())) {
@ -74,21 +85,6 @@ public class BukkitPlayer extends PlotPlayer {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (event.isCancelled() || !event.getTo().equals(to)) {
return false;
}
event = new PlayerTeleportEvent(player, to, from);
for (RegisteredListener listener : listeners) {
if (listener.getPlugin().getName().equals(PS.imp().getPluginName())) {
continue;
}
try {
listener.callEvent(event);
} catch (EventException e) {
e.printStackTrace();
}
}
return true;
} }
@Override public boolean hasPermission(String permission) { @Override public boolean hasPermission(String permission) {