org.bukkit.event.player.PlayerChangedWorldEvent Java Examples

The following examples show how to use org.bukkit.event.player.PlayerChangedWorldEvent. 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: PetOwnerListener.java    From SonarPet with GNU General Public License v3.0 6 votes vote down vote up
@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 #2
Source File: PlayerListener.java    From ScoreboardStats with MIT License 6 votes vote down vote up
/**
 * 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 #3
Source File: HoloListener.java    From HoloAPI with GNU General Public License v3.0 6 votes vote down vote up
@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 #4
Source File: JoinItems.java    From HubBasics with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onWorldChange(PlayerChangedWorldEvent event) {
    if (!this.worlds.contains(event.getPlayer().getWorld().getName())) return;
    if (!this.items.containsKey(event.getPlayer().getWorld().getName())) return;
    if (!this.worldChange.get(event.getPlayer().getWorld().getName())) return;
    if (this.clearInventory.get(event.getPlayer().getWorld().getName())) {
        event.getPlayer().getInventory().clear();
    }
    this.items.get(event.getPlayer().getWorld().getName()).forEach(id -> {
        CustomItem item = HubBasics.getItemManager().get(id);
        if (item == null) return;
        if (item.getPermission() != null && !event.getPlayer().hasPermission(item.getPermission())) return;
        this.removeItem(item, event.getPlayer().getInventory());
        if (item.getSlot() == null || item.getSlot() == -1) {
            event.getPlayer().getInventory().addItem(item.toItemStack(event.getPlayer()));
        } else {
            event.getPlayer().getInventory().setItem(item.getSlot(), item.toItemStack(event.getPlayer()));
        }
    });
}
 
Example #5
Source File: WorldChangeEvent.java    From SuperVanish with Mozilla Public License 2.0 6 votes vote down vote up
@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 #6
Source File: HologramManager.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #7
Source File: HologramManager.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #8
Source File: DataUpdaterEvents.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onWorldChange(final PlayerChangedWorldEvent event)
{
    final User user = UserManager.getUser(event.getPlayer().getUniqueId());

    if (user != null) {
        user.getTimestampMap().nullifyTimeStamp(TimestampKey.INVENTORY_OPENED);
        user.getTimestampMap().updateTimeStamps(TimestampKey.LAST_TELEPORT, TimestampKey.LAST_WORLD_CHANGE);
    }
}
 
Example #9
Source File: InventoryChangeProcess.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #10
Source File: NightVision.java    From SuperVanish with Mozilla Public License 2.0 5 votes vote down vote up
@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 #11
Source File: InventoryChangeProcess.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #12
Source File: BossAnnouncer.java    From HubBasics with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onWorld(PlayerChangedWorldEvent event) {
    World world = event.getPlayer().getWorld();
    BossBarMessage bbm = getBossBar(world.getName(), getPointer(world.getName()));
    if (bbm != null) {
        this.setBossBar(event.getPlayer(), bbm.toBossBar(event.getPlayer()));
    }
}
 
Example #13
Source File: PlayerListener.java    From GlobalWarming with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Track a player's current world
 * - This information is needed when players go offline, but have planted saplings,
 * left furnaces running or have active bounties
 */
@EventHandler(ignoreCancelled = true)
public void onPlayerChangedWorldEvent(PlayerChangedWorldEvent event) {
    //Update the player's world:
    PlayerTable playerTable = gw.getTableManager().getPlayerTable();
    GPlayer gPlayer = playerTable.getPlayers().get(event.getPlayer().getUniqueId());
    gPlayer.setWorldId(event.getPlayer().getWorld().getUID());

    //Database update:
    PlayerUpdateQuery updateQuery = new PlayerUpdateQuery(gPlayer);
    AsyncDBQueue.getInstance().queueUpdateQuery(updateQuery);
}
 
Example #14
Source File: Main.java    From TAB with Apache License 2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void a(PlayerChangedWorldEvent e){
	try {
		if (Shared.disabled) return;
		if (Configs.bukkitBridgeMode) return;
		ITabPlayer p = Shared.getPlayer(e.getPlayer().getUniqueId());
		if (p == null) return;
		p.onWorldChange(e.getFrom().getName(), p.world = e.getPlayer().getWorld().getName());
	} catch (Throwable t) {
		Shared.errorManager.printError("An error occurred when processing PlayerChangedWorldEvent", t);
	}
}
 
Example #15
Source File: PlayerListener.java    From WorldEditSelectionVisualizer with MIT License 5 votes vote down vote up
@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 #16
Source File: JoinMessages.java    From HubBasics with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onChange(PlayerChangedWorldEvent event) {
    if (this.worldMessages.containsKey(event.getPlayer().getWorld().getName())) {
        HubBasics.getMessenger().send(event.getPlayer().getWorld(),
                PlaceHolderUtil.replace(event.getPlayer(), this.worldMessages.get(event.getPlayer().getWorld().getName())));
    }
}
 
Example #17
Source File: NametagHandler.java    From NametagEdit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Some users may have different permissions per world.
 * If this is enabled, their tag will be reloaded on TP.
 */
@EventHandler
public void onTeleport(final PlayerChangedWorldEvent event) {
    if (!refreshTagOnWorldChange) return;

    new BukkitRunnable() {
        @Override
        public void run() {
            applyTagToPlayer(event.getPlayer(), false);
        }
    }.runTaskLater(plugin, 3);
}
 
Example #18
Source File: WorldEnter.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled=true)
public void onWorldEnter(final PlayerChangedWorldEvent event) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG " + event.getEventName());
    if (!event.getPlayer().getWorld().equals(ASkyBlock.getIslandWorld()) &&
            !event.getPlayer().getWorld().equals(ASkyBlock.getNetherWorld())) {
        return;
    }
    if (DEBUG)
        plugin.getLogger().info("DEBUG correct world");
    Location islandLoc = plugin.getPlayers().getIslandLocation(event.getPlayer().getUniqueId());
    if (islandLoc == null) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG  no island");
        // They have no island
        if (Settings.makeIslandIfNone || Settings.immediateTeleport) {
            event.getPlayer().performCommand(Settings.ISLANDCOMMAND);
        }
        if (DEBUG)
            plugin.getLogger().info("DEBUG Make island");
    } else {
        // They have an island and are going to their own world
        if (Settings.immediateTeleport && islandLoc.getWorld().equals(event.getPlayer().getWorld())) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG teleport");
            event.getPlayer().performCommand(Settings.ISLANDCOMMAND + " go");
        }
    }
}
 
Example #19
Source File: WorldChangeListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #20
Source File: WorldChangeListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onWorldChange(PlayerChangedWorldEvent event) {
    try {
        actOnEvent(event);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example #21
Source File: TeleportListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@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 #22
Source File: PlayerListener.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onSwitchWorld(PlayerChangedWorldEvent change) {
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(change.getPlayer());
  if (game != null) {
    if (game.getState() == GameState.RUNNING) {
      if (!game.getCycle().isEndGameRunning()) {
        if (!game.getPlayerSettings(change.getPlayer()).isTeleporting()) {
          game.playerLeave(change.getPlayer(), false);
        } else {
          game.getPlayerSettings(change.getPlayer()).setTeleporting(false);
        }
      }
    } else if (game.getState() == GameState.WAITING) {
      if (!game.getPlayerSettings(change.getPlayer()).isTeleporting()) {
        game.playerLeave(change.getPlayer(), false);
      } else {
        game.getPlayerSettings(change.getPlayer()).setTeleporting(false);
      }
    }
  }

  if (!BedwarsRel.getInstance().isHologramsEnabled()
      || BedwarsRel.getInstance().getHolographicInteractor() == null) {
    return;
  }

  BedwarsRel.getInstance().getHolographicInteractor().updateHolograms(change.getPlayer());
}
 
Example #23
Source File: BukkitEventListener.java    From BungeePerms with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onChangedWorld(PlayerChangedWorldEvent e)
{
    BukkitPlugin.getInstance().getNotifier().sendWorldUpdate(e.getPlayer());

    User u = config.isUseUUIDs() ? pm().getUser(e.getPlayer().getUniqueId()) : pm().getUser(e.getPlayer().getName());
    updateAttachment(e.getPlayer(), u);
}
 
Example #24
Source File: WorldInventoriesDupingPatch.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerWorldChange(PlayerChangedWorldEvent event) {
    if (updateTimeoutsTaskId != -1) { // Only when enabled
        timeouts.put(event.getPlayer().getUniqueId(), SLOT_TIMEOUT);
    }
}
 
Example #25
Source File: PlayerChangedWorldListener.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) {
    process.preProcessWorldChange(event);
}
 
Example #26
Source File: PlayerChangedWorldListener.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) {
    process.preProcessWorldChange(event);
}
 
Example #27
Source File: TabManager.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldChange(PlayerChangedWorldEvent event) {
  TabView view = this.getViewOrNull(event.getPlayer());
  if (view != null) view.onWorldChange(event);
}
 
Example #28
Source File: WorldBorderListener.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onPlayerWorldChange(PlayerChangedWorldEvent event) {
	PacketPlayOutWorldBorder packet = new PacketPlayOutWorldBorder(WorldBorder.getInstance(event.getPlayer().getWorld()), WorldBorderAction.INITIALIZE);
	Utilities.sendPacket(event.getPlayer(), packet);
}
 
Example #29
Source File: TabView.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
protected void onWorldChange(PlayerChangedWorldEvent event) {
  if (this.viewer == event.getPlayer()) this.respawnFakeEntities();
}
 
Example #30
Source File: MoveListener.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
	PlayerManager.getPlayer(event.getPlayer()).cancelToolProgress();
}