Added WorldEdit CUI support

This commit is contained in:
Wyatt Childers 2016-05-18 17:38:46 -04:00
parent 03819a2342
commit baa3a0a8b5
3 changed files with 65 additions and 7 deletions

View File

@ -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));
}
}
}

View File

@ -30,11 +30,8 @@
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.world.World;
import javax.annotation.Nullable;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.UUID;
@ -116,6 +114,9 @@ public void dispatchCUIEvent(CUIEvent event) {
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

View File

@ -37,14 +37,11 @@
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 void preInit(GamePreInitializationEvent event) {
@Listener
public void init(GameInitializationEvent event) {
// WECUIPacketHandler.init();
CUIChannelHandler.init();
}
@Listener