mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
Pull out duplicated method sub in BukkitPlayer
This commit is contained in:
parent
587c942d88
commit
032484b0f5
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user