Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-05 02:50:05 +01:00
Convert across the network handlers
Dieser Commit ist enthalten in:
Ursprung
9fccfdfaeb
Commit
c849f69ef4
@ -30,7 +30,6 @@ import com.sk89q.worldedit.util.command.Dispatcher;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.registry.Registries;
|
||||
import net.minecraft.command.ServerCommandManager;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.management.PlayerList;
|
||||
@ -69,7 +68,7 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {
|
||||
|
||||
@Override
|
||||
public boolean isValidMobType(String type) {
|
||||
return EntityList.isRegistered(new ResourceLocation(type));
|
||||
return net.minecraftforge.registries.ForgeRegistries.ENTITIES.containsKey(new ResourceLocation(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,6 +24,7 @@ import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.forge.net.handler.WECUIPacketHandler;
|
||||
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
@ -32,10 +33,8 @@ import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.play.server.SPacketCustomPayload;
|
||||
|
@ -26,7 +26,9 @@ import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.forge.net.LeftClickAirEventMessage;
|
||||
import com.sk89q.worldedit.forge.net.handler.WECUIPacketHandler;
|
||||
import com.sk89q.worldedit.forge.net.packet.LeftClickAirEventMessage;
|
||||
import com.sk89q.worldedit.forge.net.handler.InternalPacketHandler;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
@ -65,7 +67,7 @@ public class ForgeWorldEdit {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final String MOD_ID = "worldedit";
|
||||
public static final String CUI_PLUGIN_CHANNEL = "worldedit:cui";
|
||||
public static final String CUI_PLUGIN_CHANNEL = "cui";
|
||||
|
||||
private ForgePermissionsProvider provider;
|
||||
|
||||
@ -176,7 +178,7 @@ public class ForgeWorldEdit {
|
||||
|
||||
if (event.getWorld().isRemote && event instanceof LeftClickEmpty) {
|
||||
// catch LCE, pass it to server
|
||||
InternalPacketHandler.CHANNEL.sendToServer(new LeftClickAirEventMessage());
|
||||
InternalPacketHandler.HANDLER.sendToServer(new LeftClickAirEventMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* 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.forge;
|
||||
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.ThreadQuickExitException;
|
||||
import net.minecraft.network.play.server.SPacketCustomPayload;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.network.FMLEventChannel;
|
||||
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientCustomPacketEvent;
|
||||
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class WECUIPacketHandler {
|
||||
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
|
||||
public static FMLEventChannel WECUI_CHANNEL;
|
||||
|
||||
public static void init() {
|
||||
WECUI_CHANNEL = NetworkRegistry.INSTANCE.newEventDrivenChannel(ForgeWorldEdit.CUI_PLUGIN_CHANNEL);
|
||||
WECUI_CHANNEL.register(new WECUIPacketHandler());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPacketData(ServerCustomPacketEvent event) {
|
||||
if (event.getPacket().channel().equals(ForgeWorldEdit.CUI_PLUGIN_CHANNEL)) {
|
||||
EntityPlayerMP player = getPlayerFromEvent(event);
|
||||
LocalSession session = ForgeWorldEdit.inst.getSession(player);
|
||||
|
||||
if (session.hasCUISupport()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String text = event.getPacket().payload().toString(UTF_8_CHARSET);
|
||||
session.handleCUIInitializationMessage(text);
|
||||
session.describeCUI(ForgeWorldEdit.inst.wrap(player));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void callProcessPacket(ClientCustomPacketEvent event) {
|
||||
try {
|
||||
new SPacketCustomPayload(event.getPacket().channel(), new PacketBuffer(event.getPacket().payload())).processPacket(event.getHandler());
|
||||
} catch (ThreadQuickExitException suppress) {
|
||||
}
|
||||
}
|
||||
|
||||
private static EntityPlayerMP getPlayerFromEvent(ServerCustomPacketEvent event) {
|
||||
return ((NetHandlerPlayServer) event.getHandler()).player;
|
||||
}
|
||||
}
|
@ -17,25 +17,26 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.forge;
|
||||
package com.sk89q.worldedit.forge.net.handler;
|
||||
|
||||
import com.sk89q.worldedit.forge.net.LeftClickAirEventMessage;
|
||||
import javafx.geometry.Side;
|
||||
import com.sk89q.worldedit.forge.ForgeWorldEdit;
|
||||
import com.sk89q.worldedit.forge.net.packet.LeftClickAirEventMessage;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class InternalPacketHandler {
|
||||
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
|
||||
public static SimpleChannel CHANNEL;
|
||||
private static final String PROTOCOL_VERSION = Integer.toString(1);
|
||||
public static SimpleChannel HANDLER = NetworkRegistry.ChannelBuilder
|
||||
.named(new ResourceLocation(ForgeWorldEdit.MOD_ID, "internal"))
|
||||
.clientAcceptedVersions(PROTOCOL_VERSION::equals)
|
||||
.serverAcceptedVersions(PROTOCOL_VERSION::equals)
|
||||
.networkProtocolVersion(() -> PROTOCOL_VERSION)
|
||||
.simpleChannel();
|
||||
|
||||
public static void init() {
|
||||
CHANNEL = NetworkRegistry.newSimpleChannel(new ResourceLocation(ForgeWorldEdit.MOD_ID, "worldedit"), () -> "1", check -> true, check -> true);
|
||||
CHANNEL.registerMessage(LeftClickAirEventMessage.Handler.class, LeftClickAirEventMessage.class, 0, Side.SERVER);
|
||||
}
|
||||
int disc = 0;
|
||||
|
||||
private InternalPacketHandler() {
|
||||
HANDLER.registerMessage(disc++, LeftClickAirEventMessage.class, LeftClickAirEventMessage::encode, LeftClickAirEventMessage::decode, LeftClickAirEventMessage.Handler::handle);
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.forge.net.handler;
|
||||
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.forge.ForgeWorldEdit;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.ThreadQuickExitException;
|
||||
import net.minecraft.network.play.server.SPacketCustomPayload;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.event.EventNetworkChannel;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class WECUIPacketHandler {
|
||||
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
|
||||
private static final String PROTOCOL_VERSION = Integer.toString(1);
|
||||
public static EventNetworkChannel HANDLER = NetworkRegistry.ChannelBuilder
|
||||
.named(new ResourceLocation(ForgeWorldEdit.MOD_ID, ForgeWorldEdit.CUI_PLUGIN_CHANNEL))
|
||||
.clientAcceptedVersions(PROTOCOL_VERSION::equals)
|
||||
.serverAcceptedVersions(PROTOCOL_VERSION::equals)
|
||||
.networkProtocolVersion(() -> PROTOCOL_VERSION)
|
||||
.eventNetworkChannel();
|
||||
|
||||
public static void init() {
|
||||
HANDLER.addListener(WECUIPacketHandler::onPacketData);
|
||||
HANDLER.addListener(WECUIPacketHandler::callProcessPacket);
|
||||
}
|
||||
|
||||
public static void onPacketData(NetworkEvent.ServerCustomPayloadEvent event) {
|
||||
EntityPlayerMP player = event.getSource().get().getSender();
|
||||
LocalSession session = ForgeWorldEdit.inst.getSession(player);
|
||||
|
||||
if (session.hasCUISupport()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String text = event.getPayload().toString(UTF_8_CHARSET);
|
||||
session.handleCUIInitializationMessage(text);
|
||||
session.describeCUI(ForgeWorldEdit.inst.wrap(player));
|
||||
}
|
||||
|
||||
public static void callProcessPacket(NetworkEvent.ClientCustomPayloadEvent event) {
|
||||
try {
|
||||
new SPacketCustomPayload(
|
||||
new ResourceLocation(ForgeWorldEdit.MOD_ID, ForgeWorldEdit.CUI_PLUGIN_CHANNEL),
|
||||
event.getPayload()
|
||||
).processPacket(Minecraft.getInstance().player.connection);
|
||||
} catch (ThreadQuickExitException suppress) {
|
||||
}
|
||||
}
|
||||
}
|
@ -17,34 +17,32 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.forge.net;
|
||||
package com.sk89q.worldedit.forge.net.packet;
|
||||
|
||||
import com.sk89q.worldedit.forge.ForgeWorldEdit;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
public class LeftClickAirEventMessage implements IMessage {
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public static final class Handler implements IMessageHandler<LeftClickAirEventMessage, IMessage> {
|
||||
public class LeftClickAirEventMessage {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(LeftClickAirEventMessage message, final MessageContext ctx) {
|
||||
ctx.getServerHandler().player.mcServer.addScheduledTask(
|
||||
() -> ForgeWorldEdit.inst.onPlayerInteract(new PlayerInteractEvent.LeftClickEmpty(ctx.getServerHandler().player)));
|
||||
return null;
|
||||
public static final class Handler {
|
||||
|
||||
public static void handle(final LeftClickAirEventMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
NetworkEvent.Context context = ctx.get();
|
||||
context.enqueueWork(() -> ForgeWorldEdit.inst.onPlayerInteract(new PlayerInteractEvent.LeftClickEmpty(context.getSender())));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public static LeftClickAirEventMessage decode(ByteBuf buf) {
|
||||
return new LeftClickAirEventMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public static void encode(LeftClickAirEventMessage msg, PacketBuffer buf) {
|
||||
}
|
||||
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren