use of org.bukkit.event.player.PlayerPortalEvent in project BKCommonLib by bergerhealer.
the class PortalHandler_1_9 method enable.
@Override
public void enable(CommonPlugin plugin) {
// Listener to disable player portal events pre-emptively while players are viewing credits
// This is required, otherwise other plugins get very confused and teleport players out of the
// credits screen.
plugin.register(new Listener() {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPortalEvent(PlayerPortalEvent event) {
if (EntityPlayerHandle.fromBukkit(event.getPlayer()).isViewingCredits()) {
event.setCancelled(true);
}
}
});
// While the player is inside the end portal, it continuously fires a portal enter event.
// This causes a horrible sound effect to play, because that effect is sent every tick.
// This is obviously very unwanted while viewing the credits!
plugin.register(new PacketListener() {
@Override
public void onPacketReceive(PacketReceiveEvent event) {
}
@Override
public void onPacketSend(PacketSendEvent event) {
if (EntityPlayerHandle.fromBukkit(event.getPlayer()).isViewingCredits()) {
event.setCancelled(true);
}
}
}, PacketType.OUT_WORLD_EVENT);
}
use of org.bukkit.event.player.PlayerPortalEvent in project BKCommonLib by bergerhealer.
the class PortalHandler_1_8 method enable.
@Override
public void enable(CommonPlugin plugin) {
// Cleans up players ignored for a single tick. If something broke, this
// prevents a memory leak.
_ignorePortalEventPlayersCleanup = RunOnceTask.create(plugin, () -> _ignorePortalEventPlayers.clear());
// Listener to disable player portal events pre-emptively while players are viewing credits
// This is required, otherwise other plugins get very confused and teleport players out of the
// credits screen.
plugin.register(new Listener() {
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityPortalEnter(EntityPortalEnterEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
if (EntityPlayerHandle.fromBukkit(player).isViewingCredits()) {
_ignorePortalEventPlayers.add(player);
_ignorePortalEventPlayersCleanup.start();
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPortalEvent(PlayerPortalEvent event) {
if (_ignorePortalEventPlayers.remove(event.getPlayer())) {
event.setCancelled(true);
}
}
});
}
use of org.bukkit.event.player.PlayerPortalEvent in project Glowstone by GlowstoneMC.
the class GlowPlayer method teleportToEnd.
@Override
protected boolean teleportToEnd() {
if (!server.getAllowEnd()) {
return false;
}
Location target = null;
for (World world : server.getWorlds()) {
if (world.getEnvironment() == Environment.THE_END) {
target = world.getSpawnLocation();
break;
}
}
if (target == null) {
return false;
}
PlayerPortalEvent event = EventFactory.getInstance().callEvent(new PlayerPortalEvent(this, location.clone(), target, null));
if (event.isCancelled()) {
return false;
}
target = event.getTo();
spawnAt(target);
teleported = true;
return true;
}
use of org.bukkit.event.player.PlayerPortalEvent in project Glowstone by GlowstoneMC.
the class GlowPlayer method teleportToSpawn.
@Override
protected boolean teleportToSpawn() {
Location target = getBedSpawnLocation();
if (target == null) {
target = server.getWorlds().get(0).getSpawnLocation();
}
PlayerPortalEvent event = EventFactory.getInstance().callEvent(new PlayerPortalEvent(this, location.clone(), target, null));
if (event.isCancelled()) {
return false;
}
target = event.getTo();
spawnAt(target);
teleported = true;
return true;
}
Aggregations