Java Code Examples for org.bukkit.event.player.PlayerChangedWorldEvent#getPlayer()
The following examples show how to use
org.bukkit.event.player.PlayerChangedWorldEvent#getPlayer() .
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: HologramManager.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onWorldChange(PlayerChangedWorldEvent event) { if (HOLOGRAMS.isEmpty()) { return; } List<Hologram> copy = new ArrayList<>(HOLOGRAMS); for (Hologram hologram : copy) { if (hologram.isEmpty() || !hologram.hasViewers()) { HOLOGRAMS.remove(hologram); continue; } try { Player player = event.getPlayer(); List<Player> viewers = hologram.getViewers(); Location loc = hologram.getLocation(); if (viewers.contains(player) && player.getWorld().equals(loc.getWorld()) && !event.getFrom().equals(loc.getWorld())) { if (player.getLocation().distanceSquared(loc) < VISIBILITY_DISTANCE_SQUARED) { hologram.update(player, hologram.getAllSpawnPackets(), false); } } } catch (Throwable t) { } } }
Example 2
Source File: HologramManager.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onWorldChange(PlayerChangedWorldEvent event) { if (HOLOGRAMS.isEmpty()) { return; } List<Hologram> copy = new ArrayList<>(HOLOGRAMS); for (Hologram hologram : copy) { if (hologram.isEmpty() || !hologram.hasViewers()) { HOLOGRAMS.remove(hologram); continue; } try { Player player = event.getPlayer(); List<Player> viewers = hologram.getViewers(); Location loc = hologram.getLocation(); if (viewers.contains(player) && player.getWorld().equals(loc.getWorld()) && !event.getFrom().equals(loc.getWorld())) { if (player.getLocation().distanceSquared(loc) < VISIBILITY_DISTANCE_SQUARED) { hologram.update(player, hologram.getAllSpawnPackets(), false); } } } catch (Throwable t) { } } }
Example 3
Source File: PetOwnerListener.java From SonarPet with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onWorldChange(PlayerChangedWorldEvent event) { final Player p = event.getPlayer(); final IPet pi = EchoPet.getManager().getPet(p); if (pi != null) { EchoPet.getManager().saveFileData("autosave", pi); EchoPet.getSqlManager().saveToDatabase(pi, false); EchoPet.getManager().removePet(pi, false); new BukkitRunnable() { @Override public void run() { EchoPet.getManager().loadPets(p, false, false, false); } }.runTaskLater(EchoPet.getPlugin(), 20L); } }
Example 4
Source File: WorldChangeEvent.java From SuperVanish with Mozilla Public License 2.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onWorldChange(PlayerChangedWorldEvent e) { try { final Player p = e.getPlayer(); if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) return; // check auto-reappear option if (plugin.getSettings().getBoolean("VanishStateFeatures.ReappearOnWorldChange") || plugin.getSettings().getBoolean("VanishStateFeatures.CheckPermissionOnWorldChange") && !CommandAction.VANISH_SELF.checkPermission(p, plugin)) { plugin.getVisibilityChanger().showPlayer(p); } } catch (Exception er) { plugin.logException(er); } }
Example 5
Source File: HoloListener.java From HoloAPI with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onWorldChange(PlayerChangedWorldEvent event) { final Player player = event.getPlayer(); for (final Hologram h : HoloAPI.getManager().getAllHolograms().keySet()) { if (player.getLocation().getWorld().getName().equals(h.getWorldName()) && h.getVisibility().isVisibleTo(player, h.getSaveId())) { if (h instanceof AnimatedHologram && !((AnimatedHologram) h).isAnimating()) { ((AnimatedHologram) h).animate(); } h.show(player, true); } else if (event.getFrom().getName().equals(h.getWorldName()) && h.getLocationFor(player) != null) { new BukkitRunnable() { @Override public void run() { h.clear(player); } }.runTaskLater(HoloAPI.getCore(), 20L); } } }
Example 6
Source File: PlayerListener.java From ScoreboardStats with MIT License | 6 votes |
/** * Check if the player moves in a scoreboard disabled world * * @param worldChange the teleport event * @see com.github.games647.scoreboardstats.RefreshTask */ //ignore cancelled events @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onWorldChange(PlayerChangedWorldEvent worldChange) { Player player = worldChange.getPlayer(); //new world if (Settings.isActiveWorld(player.getWorld().getName())) { //old world if (!Settings.isActiveWorld(worldChange.getFrom().getName())) { //Activate the scoreboard if it was disabled plugin.getRefreshTask().addToQueue(player); } } else { //Disable the scoreboard if the player goes into a disabled world plugin.getRefreshTask().remove(player); plugin.getScoreboardManager().unregister(player); } }
Example 7
Source File: TeleportListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerChangedWorld(PlayerChangedWorldEvent e){ GameManager gm = GameManager.getGameManager(); Player player = e.getPlayer(); if (gm.getConfiguration().getEnableTheEnd() && e.getFrom().getName().equals(gm.getConfiguration().getTheEndUuid())){ World world = Bukkit.getServer().getWorld(gm.getConfiguration().getOverworldUuid()); double maxDistance = 0.9 * gm.getWorldBorder().getCurrentSize(); Location loc = gm.getPlayersManager().findRandomSafeLocation(world, maxDistance); player.teleport(loc); } }
Example 8
Source File: WorldChangeListener.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
private void actOnEvent(PlayerChangedWorldEvent event) { long time = System.currentTimeMillis(); Player player = event.getPlayer(); UUID uuid = player.getUniqueId(); String worldName = player.getWorld().getName(); String gameMode = player.getGameMode().name(); dbSystem.getDatabase().executeTransaction(new WorldNameStoreTransaction(serverInfo.getServerUUID(), worldName)); worldAliasSettings.addWorld(worldName); Optional<Session> cachedSession = SessionCache.getCachedSession(uuid); cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time)); }
Example 9
Source File: PlayerListener.java From WorldEditSelectionVisualizer with MIT License | 5 votes |
@EventHandler public void onPlayerChangedWorld(PlayerChangedWorldEvent e) { Player player = e.getPlayer(); plugin.getPlayerInfosSafe(player).ifPresent(infos -> { plugin.updateHoldingSelectionItem(infos); infos.getEnabledVisualizations().forEach(PlayerSelection::resetSelection); plugin.getWorldEditHelper().updatePlayerVisualizations(infos); }); }
Example 10
Source File: InventoryChangeProcess.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * Begins the process of a player changing worlds. * * @param event The called {@link PlayerChangedWorldEvent}. */ public void preProcessWorldChange(PlayerChangedWorldEvent event) { Player player = event.getPlayer(); String worldFrom = event.getFrom().getName(); String worldTo = player.getWorld().getName(); Group groupFrom = groupManager.getGroupFromWorld(worldFrom); Group groupTo = groupManager.getGroupFromWorld(worldTo); processWorldChange(player, groupFrom, groupTo); }
Example 11
Source File: NightVision.java From SuperVanish with Mozilla Public License 2.0 | 5 votes |
@EventHandler public void onWorldChange(PlayerChangedWorldEvent e) { Player p = e.getPlayer(); if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) return; sendAddPotionEffect(p, new PotionEffect(PotionEffectType.NIGHT_VISION, INFINITE_POTION_EFFECT_LENGTH, 0)); }
Example 12
Source File: InventoryChangeProcess.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * Begins the process of a player changing worlds. * * @param event The called {@link PlayerChangedWorldEvent}. */ public void preProcessWorldChange(PlayerChangedWorldEvent event) { Player player = event.getPlayer(); String worldFrom = event.getFrom().getName(); String worldTo = player.getWorld().getName(); Group groupFrom = groupManager.getGroupFromWorld(worldFrom); Group groupTo = groupManager.getGroupFromWorld(worldTo); processWorldChange(player, groupFrom, groupTo); }
Example 13
Source File: TabView.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
protected void onWorldChange(PlayerChangedWorldEvent event) { if (this.viewer == event.getPlayer()) this.respawnFakeEntities(); }
Example 14
Source File: BukkitFollowListener.java From Parties with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler (ignoreCancelled = true) public void onChangeWorld(PlayerChangedWorldEvent event) { if (BukkitConfigMain.ADDITIONAL_FOLLOW_ENABLE) { // Make it async Player bukkitPlayer = event.getPlayer(); User user = plugin.getPlayer(bukkitPlayer.getUniqueId()); plugin.getScheduler().runAsync(() -> { if (BukkitConfigMain.ADDITIONAL_FOLLOW_LISTWORLDS.contains("*") || BukkitConfigMain.ADDITIONAL_FOLLOW_LISTWORLDS.contains(bukkitPlayer.getWorld().getName())) { BukkitPartyPlayerImpl pp = (BukkitPartyPlayerImpl) plugin.getPlayerManager().getPlayer(bukkitPlayer.getUniqueId()); if (!pp.getPartyName().isEmpty()) { PartyImpl party = plugin.getPartyManager().getParty(pp.getPartyName()); if (party != null && party.isFollowEnabled() && pp.getRank() >= BukkitConfigMain.ADDITIONAL_FOLLOW_RANKNEEDED) { // Init teleport for (PartyPlayer pl : party.getOnlineMembers(true)) { Player bukkitPl = Bukkit.getPlayer(pl.getPlayerUUID()); if (bukkitPl != null && !pl.getPlayerUUID().equals(bukkitPlayer.getUniqueId()) && bukkitPl.getWorld().equals(event.getFrom())) { BukkitPartyPlayerImpl ppVictim = (BukkitPartyPlayerImpl) plugin.getPlayerManager().getPlayer(pl.getPlayerUUID()); if (ppVictim.getRank() >= BukkitConfigMain.ADDITIONAL_FOLLOW_RANKMINIMUM) { // Make it sync plugin.getScheduler().getSyncExecutor().execute(() -> { CancellableTask task; task = plugin.getScheduler().scheduleAsyncLater(new PortalTask(plugin, pl.getPlayerUUID()), BukkitConfigMain.ADDITIONAL_FOLLOW_TIMEOUT * 50, TimeUnit.MILLISECONDS); ppVictim.setPortalTimeoutTask(task); user.sendMessage(plugin.getMessageUtils().convertPlayerPlaceholders(BukkitMessages.OTHER_FOLLOW_WORLD .replace("%player%", bukkitPlayer.getName()) .replace("%world%", bukkitPlayer.getWorld().getName()), ppVictim), true); switch (BukkitConfigMain.ADDITIONAL_FOLLOW_TYPE) { case 1: bukkitPl.teleport(bukkitPlayer.getWorld().getSpawnLocation()); break; case 2: bukkitPl.teleport(bukkitPlayer); break; default: // Nothing to do break; } }); } } } } } } }); } }
Example 15
Source File: WorldsChangedListener.java From Statz with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onWorldSwitch(final PlayerChangedWorldEvent event) { final PlayerStat stat = PlayerStat.WORLDS_CHANGED; // Get player final Player player = event.getPlayer(); // Do general check if (!plugin.doGeneralCheck(player, stat)) return; PlayerStatSpecification specification = new WorldsChangedSpecification(player.getUniqueId(), 1, event.getFrom().getName(), player.getWorld().getName()); // Update value to new stat. plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery()); }