mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
Added WorldEdit CUI support
This commit is contained in:
parent
03819a2342
commit
baa3a0a8b5
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.sponge;
|
||||
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import org.spongepowered.api.Platform;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.network.*;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class CUIChannelHandler implements RawDataListener {
|
||||
public static final String CUI_PLUGIN_CHANNEL = "WECUI";
|
||||
|
||||
private static ChannelBinding.RawDataChannel channel;
|
||||
|
||||
public static void init() {
|
||||
channel = Sponge.getChannelRegistrar().createRawChannel(SpongeWorldEdit.inst(), CUI_PLUGIN_CHANNEL);
|
||||
channel.addListener(Platform.Type.SERVER, new CUIChannelHandler());
|
||||
}
|
||||
|
||||
|
||||
public static ChannelBinding.RawDataChannel getActiveChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePayload(ChannelBuf data, RemoteConnection connection, Platform.Type side) {
|
||||
if (connection instanceof PlayerConnection) {
|
||||
Player player = ((PlayerConnection) connection).getPlayer();
|
||||
|
||||
LocalSession session = SpongeWorldEdit.inst().getSession(player);
|
||||
|
||||
if (session.hasCUISupport()) {
|
||||
return;
|
||||
}
|
||||
|
||||
session.handleCUIInitializationMessage(new String(data.readBytes(data.available()), StandardCharsets.UTF_8));
|
||||
session.describeCUI(SpongeWorldEdit.inst().wrapPlayer(player));
|
||||
}
|
||||
}
|
||||
}
|
@ -30,11 +30,8 @@ import com.sk89q.worldedit.internal.LocalWorldAdapter;
|
||||
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||
import com.sk89q.worldedit.session.SessionKey;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.item.inventory.ItemStack;
|
||||
import org.spongepowered.api.text.LiteralText;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.format.TextColor;
|
||||
import org.spongepowered.api.text.format.TextColors;
|
||||
@ -42,6 +39,7 @@ import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -116,6 +114,9 @@ public class SpongePlayer extends AbstractPlayerActor {
|
||||
if (params.length > 0) {
|
||||
send = send + "|" + StringUtil.joinString(params, "|");
|
||||
}
|
||||
|
||||
String finalData = send;
|
||||
CUIChannelHandler.getActiveChannel().sendTo(player, buffer -> buffer.writeBytes(finalData.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,14 +37,11 @@ import org.spongepowered.api.config.ConfigManager;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.block.InteractBlockEvent;
|
||||
import org.spongepowered.api.event.cause.NamedCause;
|
||||
import org.spongepowered.api.event.game.state.*;
|
||||
import org.spongepowered.api.item.inventory.ItemStack;
|
||||
import org.spongepowered.api.plugin.Plugin;
|
||||
import org.spongepowered.api.plugin.PluginContainer;
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
import org.spongepowered.api.text.Text;
|
||||
import org.spongepowered.api.text.channel.MessageChannel;
|
||||
import org.spongepowered.api.world.Location;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
@ -107,7 +104,7 @@ public class SpongeWorldEdit {
|
||||
|
||||
@Listener
|
||||
public void init(GameInitializationEvent event) {
|
||||
// WECUIPacketHandler.init();
|
||||
CUIChannelHandler.init();
|
||||
}
|
||||
|
||||
@Listener
|
||||
|
Loading…
Reference in New Issue
Block a user