mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
fabric: support Minecraft 1.20.6
This commit is contained in:
10 files changed
+109
-58
No files matched your search
@@ -21,24 +21,18 @@ package net.william278.huskhomes;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.fabric.FabricServerAudiences;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.william278.desertwell.util.Version;
|
||||
import net.william278.huskhomes.command.Command;
|
||||
import net.william278.huskhomes.command.FabricCommand;
|
||||
@@ -55,6 +49,7 @@ import net.william278.huskhomes.listener.EventListener;
|
||||
import net.william278.huskhomes.listener.FabricEventListener;
|
||||
import net.william278.huskhomes.manager.Manager;
|
||||
import net.william278.huskhomes.network.Broker;
|
||||
import net.william278.huskhomes.network.FabricPluginMessage;
|
||||
import net.william278.huskhomes.network.PluginMessageBroker;
|
||||
import net.william278.huskhomes.network.RedisBroker;
|
||||
import net.william278.huskhomes.position.World;
|
||||
@@ -88,7 +83,7 @@ import java.util.stream.Collectors;
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class FabricHuskHomes implements DedicatedServerModInitializer, HuskHomes, FabricTask.Supplier,
|
||||
FabricEventDispatcher, FabricSafetyResolver, ServerPlayNetworking.PlayChannelHandler {
|
||||
FabricEventDispatcher, FabricSafetyResolver, ServerPlayNetworking.PlayPayloadHandler<FabricPluginMessage> {
|
||||
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("HuskHomes");
|
||||
private final ModContainer modContainer = FabricLoader.getInstance().getModContainer("huskhomes")
|
||||
@@ -326,20 +321,18 @@ public class FabricHuskHomes implements DedicatedServerModInitializer, HuskHomes
|
||||
|
||||
@Override
|
||||
public void initializePluginChannels() {
|
||||
ServerPlayNetworking.registerGlobalReceiver(new Identifier("bungeecord", "main"), this);
|
||||
ServerPlayNetworking.registerGlobalReceiver(FabricPluginMessage.BUNGEE_CHANNEL_ID, this);
|
||||
}
|
||||
|
||||
// When the server receives a plugin message
|
||||
@Override
|
||||
public void receive(@NotNull MinecraftServer server, @NotNull ServerPlayerEntity player,
|
||||
@NotNull ServerPlayNetworkHandler handler, @NotNull PacketByteBuf buf,
|
||||
@NotNull PacketSender responseSender) {
|
||||
public void receive(@NotNull FabricPluginMessage payload, @NotNull ServerPlayNetworking.Context context) {
|
||||
if (broker instanceof PluginMessageBroker messenger
|
||||
&& getSettings().getCrossServer().getBrokerType() == Broker.Type.PLUGIN_MESSAGE) {
|
||||
messenger.onReceive(
|
||||
PluginMessageBroker.BUNGEE_CHANNEL_ID,
|
||||
FabricUser.adapt(player, this),
|
||||
ByteBufUtil.getBytes(buf)
|
||||
FabricUser.adapt(context.player(), this),
|
||||
payload.getData()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.network;
|
||||
|
||||
import lombok.*;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@NoArgsConstructor
|
||||
public class FabricPluginMessage implements CustomPayload {
|
||||
|
||||
public static final Id<FabricPluginMessage> BUNGEE_CHANNEL_ID = new Id<>(
|
||||
Identifier.of("bungeecord", "main")
|
||||
);
|
||||
|
||||
private Id<FabricPluginMessage> id;
|
||||
private byte[] data;
|
||||
|
||||
@NotNull
|
||||
public static FabricPluginMessage of(@NotNull String id, byte[] data) {
|
||||
return new FabricPluginMessage(
|
||||
id.equals("BungeeCord") ? BUNGEE_CHANNEL_ID : new Id<>(Identifier.tryParse(id)), data
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,10 +21,8 @@ package net.william278.huskhomes.user;
|
||||
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
@@ -33,6 +31,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.TeleportTarget;
|
||||
import net.william278.huskhomes.FabricHuskHomes;
|
||||
import net.william278.huskhomes.network.FabricPluginMessage;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.position.World;
|
||||
@@ -163,10 +162,7 @@ public class FabricUser extends OnlineUser {
|
||||
|
||||
@Override
|
||||
public void sendPluginMessage(@NotNull String channel, byte[] message) {
|
||||
final PacketByteBuf buf = PacketByteBufs.create();
|
||||
buf.writeIdentifier(parseIdentifier(channel));
|
||||
buf.writeBytes(message);
|
||||
player.networkHandler.sendPacket(new CustomPayloadS2CPacket(buf));
|
||||
player.networkHandler.sendPacket(new CustomPayloadS2CPacket(FabricPluginMessage.of(channel, message)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -193,14 +189,4 @@ public class FabricUser extends OnlineUser {
|
||||
plugin.runSyncDelayed(() -> player.setInvulnerable(false), invulnerabilityTimeInTicks);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private static Identifier parseIdentifier(@NotNull String channel) {
|
||||
if (channel.equals("BungeeCord")) {
|
||||
return new Identifier("bungeecord", "main");
|
||||
}
|
||||
return Optional.ofNullable(Identifier.tryParse(channel))
|
||||
.orElseThrow(() -> new IllegalArgumentException("Invalid channel name: " + channel));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user