Java Code Examples for org.bukkit.event.player.PlayerTeleportEvent#setCancelled()

The following examples show how to use org.bukkit.event.player.PlayerTeleportEvent#setCancelled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayerEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent event) {
    if (event.getTo() != null || !plugin.getWorldManager().isSkyWorld(event.getTo().getWorld())) {
        return;
    }
    final Player player = event.getPlayer();
    boolean isAdmin = player.isOp() || player.hasPermission("usb.mod.bypassprotection");
    IslandInfo islandInfo = uSkyBlock.getInstance().getIslandInfo(WorldGuardHandler.getIslandNameAt(event.getTo()));
    if (!isAdmin && islandInfo != null && islandInfo.isBanned(player.getUniqueId())) {
        event.setCancelled(true);
        player.sendMessage(tr("\u00a74That player has forbidden you from teleporting to their island."));
    }
    if (!isAdmin && islandInfo != null && islandInfo.isLocked() && !islandInfo.getMembers().contains(player.getName()) && !islandInfo.isTrusted(player)) {
        event.setCancelled(true);
        player.sendMessage(tr("\u00a74That island is \u00a7clocked.\u00a7e No teleporting to the island."));
    }
    if (!event.isCancelled()) {
        final PlayerInfo playerInfo = plugin.getPlayerInfo(player);
        playerInfo.onTeleport(player);
    }
}
 
Example 2
Source File: DPlayerListener.java    From DungeonsXL with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerTeleport(PlayerTeleportEvent event) {
    Player player = event.getPlayer();
    if (isCitizensNPC(player)) {
        return;
    }
    GlobalPlayer dPlayer = dPlayers.get(player);

    World toWorld = event.getTo().getWorld();

    if (dPlayer instanceof InstancePlayer && ((InstancePlayer) dPlayer).getWorld() == toWorld) {
        return;
    }

    if (plugin.getInstanceWorld(toWorld) != null) {
        dPlayer.sendMessage(DMessage.ERROR_JOIN_GROUP.getMessage());
        dPlayer.sendMessage(ChatColor.GOLD + DMessage.CMD_ENTER_HELP.getMessage());
        event.setCancelled(true);
    }
}
 
Example 3
Source File: ListenerTeleport.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
public void onTeleport(PlayerTeleportEvent e) {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("teleportation.prevent-teleport")) return;

    Player player = e.getPlayer();
    ICombatManager manager = this.plugin.getCombatManager();
    if(!manager.isInCombat(player)) return;

    PlayerTeleportEvent.TeleportCause cause = e.getCause();
    if(isAllowed(cause)) {
        if(cause == PlayerTeleportEvent.TeleportCause.ENDER_PEARL && config.getBoolean("teleportation.restart-timer-for-ender-pearl")) {
            manager.tag(player, null, PlayerPreTagEvent.TagType.UNKNOWN, PlayerPreTagEvent.TagReason.UNKNOWN);
        }
        return;
    }

    e.setCancelled(true);
    String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.teleportation.block-" + (cause == PlayerTeleportEvent.TeleportCause.ENDER_PEARL ? "pearl" : "other"));
    this.plugin.sendMessage(player, message);
}
 
Example 4
Source File: NoEntryListener.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void onTeleport(PlayerTeleportEvent e) {
    ICombatLogX plugin = this.expansion.getPlugin();
    ICombatManager manager = plugin.getCombatManager();

    Player player = e.getPlayer();
    if(!manager.isInCombat(player)) return;

    LivingEntity enemy = manager.getEnemy(player);
    if(enemy == null) return;

    Location toLocation = e.getTo();
    TagType tagType = (enemy instanceof Player ? TagType.PLAYER : TagType.MOB);

    NoEntryHandler handler = this.expansion.getNoEntryHandler();
    if(!handler.isSafeZone(player, toLocation, tagType)) return;

    e.setCancelled(true);
    this.expansion.sendNoEntryMessage(player, enemy);
}
 
Example 5
Source File: FlagQueueLobby.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {
	SpleefPlayer player = getHeavySpleef().getSpleefPlayer(event.getPlayer());
	
	if (!game.isQueued(player) || player.getPlayerState(this) == null) {
		return;
	}
	
	event.setCancelled(true);
	player.sendMessage(getI18N().getString(Messages.Player.CANNOT_TELEPORT_IN_QUEUE));
}
 
Example 6
Source File: PlayerTeleportListener.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {
    try {
        final Location toLocation = event.getTo();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        final Island island = islandManager.getIslandViaLocation(toLocation);
        if (island == null) return;

        final Player player = event.getPlayer();
        final User user = User.getUser(player);

        if (user.islandID == island.getId()) return;

        if ((island.isVisit() && !island.isBanned(user)) || user.bypassing) {
            Bukkit.getScheduler().scheduleSyncDelayedTask(IridiumSkyblock.getInstance(), () -> island.sendBorder(player), 1);
            if (user.islandID != island.getId()) {
                player.sendMessage(Utils.color(IridiumSkyblock.getMessages().visitingIsland.replace("%player%", User.getUser(island.getOwner()).name).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                for (String pl : island.getMembers()) {
                    Player p = Bukkit.getPlayer(User.getUser(pl).name);
                    if (p != null) {
                        p.sendMessage(Utils.color(IridiumSkyblock.getMessages().visitedYourIsland.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                    }
                }
            }
        } else {
            event.setCancelled(true);
            player.sendMessage(Utils.color(IridiumSkyblock.getMessages().playersIslandIsPrivate.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
        }
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 7
Source File: TitleRespawn.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerTeleportEvent event) {
    Player player = event.getPlayer();
    if (!this.spectate && (isDeadUUID(player.getUniqueId()) && deadPlayers.get(player.getUniqueId()) != 0)) {
        event.setCancelled(true);
    }
}
 
Example 8
Source File: SpectateListener.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent e) {
	final Player player = e.getPlayer();
	final GameMap gameMap = MatchManager.get().getSpectatorMap(player);
	if (gameMap == null || player.hasPermission("sw.opteleport")) {
		return;
	}
	if (e.getCause() != TeleportCause.END_PORTAL) {
		e.setCancelled(true);
	}
}
 
Example 9
Source File: Compat19.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent e) {

    final Player p = e.getPlayer();
    Location lfrom = e.getFrom();
    Location lto = e.getTo();

    if (e.getCause().equals(PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT)) {
        final Region rfrom = RedProtect.get().rm.getTopRegion(lfrom);
        final Region rto = RedProtect.get().rm.getTopRegion(lto);

        if (rfrom != null && !rfrom.canTeleport(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            e.setCancelled(true);
        }
        if (rto != null && !rto.canTeleport(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            e.setCancelled(true);
        }
    }

    if (p.getInventory().getChestplate() != null &&
            p.getInventory().getChestplate().getType().equals(Material.ELYTRA) &&
            !RedProtect.get().config.globalFlagsRoot().worlds.get(lto.getWorld().getName()).player_glide.allow_elytra) {
        RedProtect.get().lang.sendMessage(p, "globallistener.elytra.cantworld");
        e.setCancelled(true);
    }
}
 
Example 10
Source File: CFIPacketListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onTeleport(PlayerTeleportEvent event) {
    final Player player = event.getPlayer();
    VirtualWorld gen = getGenerator(player);
    if (gen != null) {
        Location from = event.getFrom();
        Location to = event.getTo();
        if (to.getWorld().equals(from.getWorld()) && to.distanceSquared(from) < 8) {
            event.setTo(player.getLocation());
            event.setCancelled(true);
            player.setVelocity(player.getVelocity());
        }
    }
}
 
Example 11
Source File: TeleportEvent.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void playerTeleport(PlayerTeleportEvent event) {
    Player p = event.getPlayer();
    int id = GameManager.getInstance().getPlayerGameId(p);
    if(id == -1) return;
    if(GameManager.getInstance().getGame(id).isPlayerActive(p) && event.getCause() == PlayerTeleportEvent.TeleportCause.COMMAND){
        p.sendMessage(ChatColor.RED +" Cannot teleport while ingame!");
        event.setCancelled(true);
    }
}
 
Example 12
Source File: DeathListener.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true) @SuppressWarnings("unused")
public void onPlayerTeleport(PlayerTeleportEvent event) {
    Player player = event.getPlayer();
    Civilian civilian = CivilianManager.getInstance().getCivilian(player.getUniqueId());

    if (!ConfigManager.getInstance().isAllowTeleportInCombat()) {
        if (civilian.isInCombat()) {
            event.setCancelled(true);
            player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(player,
                    "in-combat"));
            return;
        }
    }

    if (!ConfigManager.getInstance().isAllowTeleportingOutOfHostileTowns()) {
        Town town = TownManager.getInstance().getTownAt(event.getFrom());
        if (town != null && !town.getPeople().containsKey(player.getUniqueId())) {
            Region region = RegionManager.getInstance().getRegionAt(event.getTo());
            if (region == null || !region.getEffects().containsKey("bypass_hostile_port")) {
                event.setCancelled(true);
                player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(player,
                        "no-tp-out-of-town"));
                return;
            }
        }
    }
}
 
Example 13
Source File: TeleportListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent e){
	if (e.getCause() == TeleportCause.SPECTATE && !GameManager.getGameManager().getConfiguration().getSpectatingTeleport()){
		Player player = e.getPlayer();
		if (!player.hasPermission("uhc-core.commands.teleport-admin")){
			e.setCancelled(true);
			player.sendMessage(Lang.COMMAND_SPECTATING_TELEPORT_ERROR);
		}
	}
}
 
Example 14
Source File: WorldBorderMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Prevent teleporting outside the border
 */
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
    if(event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN) {
        if(WorldBorderUtils.isInsideBorder(event.getFrom()) &&
           !WorldBorderUtils.isInsideBorder(event.getTo())) {
            event.setCancelled(true);
        }
    }
}
 
Example 15
Source File: InternalMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Prevent teleporting outside the map
 */
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
    if(event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN) {
        double fromY = event.getFrom().getY();
        double toY = event.getTo().getY();

        if((fromY >= 0.0D && fromY < 255.0D) && (toY < 0.0D || toY >= 255.0D)) {
            event.setCancelled(true);
        }
    }
}
 
Example 16
Source File: WorldBorderMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
/** Prevent teleporting outside the border */
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
  if (event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN) {
    if (WorldBorders.isInsideBorder(event.getFrom())
        && !WorldBorders.isInsideBorder(event.getTo())) {
      event.setCancelled(true);
    }
  }
}
 
Example 17
Source File: InternalMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
/** Prevent teleporting outside the map */
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
  if (event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN) {
    double fromY = event.getFrom().getY();
    double toY = event.getTo().getY();

    if ((fromY >= 0.0D && fromY < 255.0D) && (toY < 0.0D || toY >= 255.0D)) {
      event.setCancelled(true);
    }
  }
}
 
Example 18
Source File: PlayerTeleportListener.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerTeleport(final PlayerTeleportEvent a1) {
		Player player = a1.getPlayer();
        final GameMap gameMap = MatchManager.get().getPlayerMap(player);
    	if (gameMap == null) {
    		if (SkyWarsReloaded.getCfg().getSpawn() != null) {
    			if (!a1.getFrom().getWorld().equals(SkyWarsReloaded.getCfg().getSpawn().getWorld()) && a1.getTo().getWorld().equals(SkyWarsReloaded.getCfg().getSpawn().getWorld())) {
            		PlayerStat.updatePlayer(a1.getPlayer().getUniqueId().toString());
            		return;
                }
            	if (a1.getFrom().getWorld().equals(SkyWarsReloaded.getCfg().getSpawn().getWorld()) && !a1.getTo().getWorld().equals(SkyWarsReloaded.getCfg().getSpawn().getWorld())) {
            		if (SkyWarsReloaded.getCfg().lobbyBoardEnabled()) {
        		        player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
    		        }
    		        if (SkyWarsReloaded.getCfg().optionsMenuEnabled()) {
    		        	if (player.getInventory().getItem(SkyWarsReloaded.getCfg().getOptionsSlot()) != null) {
        		        	if (player.getInventory().getItem(SkyWarsReloaded.getCfg().getOptionsSlot()).equals(SkyWarsReloaded.getIM().getItem("optionselect"))) {
                		        player.getInventory().setItem(SkyWarsReloaded.getCfg().getOptionsSlot(), new ItemStack(Material.AIR, 1));
        		        	}
    		        	}
    		        }
    		        if (SkyWarsReloaded.getCfg().joinMenuEnabled() && player.hasPermission("sw.join")) {
    		        	if (player.getInventory().getItem(SkyWarsReloaded.getCfg().getJoinSlot()) != null) {
        		        	if (player.getInventory().getItem(SkyWarsReloaded.getCfg().getJoinSlot()).equals(SkyWarsReloaded.getIM().getItem("joinselect"))) {
        		        		player.getInventory().setItem(SkyWarsReloaded.getCfg().getJoinSlot(),  new ItemStack(Material.AIR, 1));
        		        	}
    		        	}
    		        }
    		        if (SkyWarsReloaded.getCfg().spectateMenuEnabled() && player.hasPermission("sw.spectate")) {
    		        	if (player.getInventory().getItem(SkyWarsReloaded.getCfg().getSpectateSlot()) != null) {
        		        	if (player.getInventory().getItem(SkyWarsReloaded.getCfg().getSpectateSlot()).equals(SkyWarsReloaded.getIM().getItem("spectateselect"))) {
        		        		player.getInventory().setItem(SkyWarsReloaded.getCfg().getSpectateSlot(),  new ItemStack(Material.AIR, 1));
        		        	}
    		        	}
    		        }
            	}
    		}
    	} else {
        	if (a1.getCause().equals(TeleportCause.END_PORTAL) || player.hasPermission("sw.opteleport") || a1.getTo().getWorld().equals(a1.getFrom().getWorld())) {
        		a1.setCancelled(false);
        	} else {
        		if (a1.getCause().equals(TeleportCause.ENDER_PEARL) && gameMap.getMatchState() != MatchState.ENDING && gameMap.getMatchState() != MatchState.WAITINGSTART) {
        			a1.setCancelled(false);
        		} else {
        			a1.setCancelled(true);
        		} 
        	}
    	}
}
 
Example 19
Source File: FreezeModule.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {
    if (frozenPlayers.contains(event.getPlayer())) event.setCancelled(true);
}