@EventHandler public void onWorldChange(PlayerChangedWorldEvent e) { if (!Config.separateInv) return; Player p = e.getPlayer(); String group = getWorldGroup(p.getWorld()); // get world group (new world) if (group == null) return; // only serve those configured saveInventory(p, p.getInventory(), e.getFrom()); // save old inventory getInventory(p); // sets inv of player }
@EventHandler(priority = EventPriority.LOWEST) void playerChangedWorld(PlayerChangedWorldEvent event) { if (!plugin.getPlayerManager().isPlayerRegistered(event.getPlayer().getName())) { return; } plugin .getChannelManager() .playerWorldChange( event.getPlayer(), event.getFrom().getName(), event.getPlayer().getWorld().getName()); }
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerChangedWorld(PlayerChangedWorldEvent event) { BukkitMCPlayer currentPlayer = (BukkitMCPlayer) Static.GetPlayer(event.getPlayer().getName(), Target.UNKNOWN); // Apparently this happens sometimes, so prevent it if (!event.getFrom().equals(currentPlayer._Player().getWorld())) { EventUtils.TriggerListener( Driver.WORLD_CHANGED, "world_changed", new BukkitPlayerEvents.BukkitMCWorldChangedEvent(event)); } }
@Override public void executeTyped(Listener listener, PlayerChangedWorldEvent event) throws EventException { boolean saveRequired = false; String fromName = event.getFrom().getName(); String toName = event.getPlayer().getWorld().getName(); logger.finer("Player change from " + fromName + " to " + toName); try { // Save old game mode if required String fromWorldMode = plugin.getConfig().getString("worlds." + fromName + ".mode"); if (fromWorldMode != null) { ModeOptions fromMode = ModeOptions.valueOf(fromWorldMode); if (fromMode == ModeOptions.REMEMBER) { GameMode fromGameMode = GameMode.valueOf(plugin.getConfig().getString("worlds." + fromName + ".gamemode")); String rememberWorldString = plugin .getConfig() .getString( "players." + event.getPlayer().getUniqueId().toString() + "." + fromName); { // transition code String rememberWorldStringOld = plugin .getConfig() .getString("players." + event.getPlayer().getName() + "." + fromName); if (rememberWorldStringOld != null) { rememberWorldString = rememberWorldStringOld; plugin .getConfig() .set( "players." + event.getPlayer().getUniqueId().toString() + "." + fromName, rememberWorldString); plugin .getConfig() .set("players." + event.getPlayer().getName() + "." + fromName, null); saveRequired = true; } } if (event.getPlayer().getGameMode() != fromGameMode) { if (rememberWorldString == null || GameMode.valueOf(rememberWorldString) != event.getPlayer().getGameMode()) { logger.info("The player has a gamemode different to default. Saving"); plugin .getConfig() .set( "players." + event.getPlayer().getUniqueId().toString() + "." + fromName, event.getPlayer().getGameMode().toString()); saveRequired = true; } } if (rememberWorldString != null && event.getPlayer().getGameMode() == fromGameMode) { logger.info("The player used to have a unique gamemode but now it is the default"); plugin.getConfig().set("players." + event.getPlayer().getName(), null); saveRequired = true; } } } // Change to new gamemode String newWorldMode = plugin.getConfig().getString("worlds." + toName + ".mode"); if (newWorldMode != null) { ModeOptions toMode = ModeOptions.valueOf(newWorldMode); GameMode toGameMode = GameMode.valueOf(plugin.getConfig().getString("worlds." + toName + ".gamemode")); if (toMode == ModeOptions.REMEMBER) { String rememberWorldString = plugin .getConfig() .getString( "players." + event.getPlayer().getUniqueId().toString() + "." + toName); { // transition code String rememberWorldStringOld = plugin .getConfig() .getString("players." + event.getPlayer().getName() + "." + toName); if (rememberWorldStringOld != null) { rememberWorldString = rememberWorldStringOld; plugin .getConfig() .set( "players." + event.getPlayer().getUniqueId().toString() + "." + toName, rememberWorldString); plugin.getConfig().set("players." + event.getPlayer().getName() + "." + toName, null); saveRequired = true; } } if (rememberWorldString != null) { toGameMode = GameMode.valueOf(rememberWorldString); } } if (event.getPlayer().getGameMode() != toGameMode) { logger.finer("Changing game mode to " + toGameMode); event.getPlayer().setGameMode(toGameMode); } } else { logger.fine("There is no setting for " + toName); } } finally { if (saveRequired) { plugin.saveConfig(); } } }