mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-12 04:23:54 +00:00
Update Upstream
0036e06 Alter the CUI lifecycle to be more consistent and reliable (1633)
This commit is contained in:
@ -62,6 +62,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -283,7 +284,7 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
if (params.length > 0) {
|
||||
send = send + "|" + StringUtil.joinString(params, "|");
|
||||
}
|
||||
player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
|
||||
player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
@ -343,18 +344,18 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
|
||||
@Override
|
||||
public SessionKey getSessionKey() {
|
||||
return new SessionKeyImpl(this.player.getUniqueId(), player.getName());
|
||||
return new SessionKeyImpl(this.player);
|
||||
}
|
||||
|
||||
private static class SessionKeyImpl implements SessionKey {
|
||||
static class SessionKeyImpl implements SessionKey {
|
||||
// If not static, this will leak a reference
|
||||
|
||||
private final UUID uuid;
|
||||
private final String name;
|
||||
|
||||
private SessionKeyImpl(UUID uuid, String name) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
SessionKeyImpl(Player player) {
|
||||
this.uuid = player.getUniqueId();
|
||||
this.name = player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,7 +31,6 @@ import java.nio.charset.StandardCharsets;
|
||||
*/
|
||||
public class CUIChannelListener implements PluginMessageListener {
|
||||
|
||||
public static final Charset UTF_8_CHARSET = StandardCharsets.UTF_8;
|
||||
private final WorldEditPlugin plugin;
|
||||
|
||||
public CUIChannelListener(WorldEditPlugin plugin) {
|
||||
@ -41,10 +40,9 @@ public class CUIChannelListener implements PluginMessageListener {
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
LocalSession session = plugin.getSession(player);
|
||||
String text = new String(message, UTF_8_CHARSET);
|
||||
String text = new String(message, StandardCharsets.UTF_8);
|
||||
final BukkitPlayer actor = plugin.wrapPlayer(player);
|
||||
session.handleCUIInitializationMessage(text, actor);
|
||||
session.describeCUI(actor);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.event.platform.SessionIdleEvent;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
@ -35,6 +36,7 @@ import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerCommandSendEvent;
|
||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.enginehub.piston.CommandManager;
|
||||
import org.enginehub.piston.inject.InjectedValueStore;
|
||||
@ -142,4 +144,9 @@ public class WorldEditListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
plugin.getWorldEdit().getEventBus().post(new SessionIdleEvent(new BukkitPlayer.SessionKeyImpl(event.getPlayer())));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user