Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #7 #11

Merged
merged 11 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ Just keep in mind that not everything may be implemented 😄
| 1.17 - 1.17.1 | ✅ | 🚫 ||| ✅ | ✅ | 🚫 | 🚫 |
| 1.18 - 1.18.2 | ✅ | 🚫 ||| ✅ | ✅ | 🚫 | 🚫 |
| 1.19 - 1.19.4 | ✅ | 🚫 ||| ✅ | ✅ | 🚫 | ⚠️<a><sup>[3]</sup></a>|
| 1.20 - 1.20.4 | ✅ | 🚫 ||| ✅ | ✅ | 🚫 | ⚠️<a><sup>[3]</sup></a>|
| 1.20 - 1.20.2 | ✅ | 🚫 ||| ✅ | ✅ | 🚫 | ⚠️<a><sup>[3]</sup></a>|
| 1.20.3 - 1.20.4 | ✅ | 🚫 ||| ✅ | ✅ | 🚫 | ⚠️<a><sup>[3]</sup></a>|
| 1.20.5 - 1.20.6 | ✅ | 🚫 ||| ✅ | ✅ | ✅ | ⚠️<a><sup>[3]</sup></a>|
| 1.21 - 1.21.3 | ✅ | 🚫 ||| ✅ | ✅ | ✅ | ⚠️<a><sup>[3]</sup></a>|
| 1.21.4 | ✅ | 🚫 ||| ✅ | ✅ | ✅ | 🚫 |
Expand Down Expand Up @@ -89,5 +90,4 @@ Just keep in mind that not everything may be implemented 😄
🇾 [yamlang](https://github.com/Fallen-Breath/yamlang) by Fallen-Breath <br>
🇬 [Gson](https://github.com/google/gson) by google<br>

<small>Last README Update `2025/1/11 12:57` UTC+9

<small>Last README Update `2025/1/14 18:45` UTC+9
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ stonecutter {
mc("1.17.1", "fabric", "forge")
mc("1.18.2", "fabric", "forge")
mc("1.19.4", "fabric", "forge", "paper")
mc("1.20.2", "fabric", "forge", "paper")
mc("1.20.4", "fabric", "forge", "paper")
mc("1.20.6", "fabric", "forge", "neoforge", "paper")
mc("1.21.3", "fabric", "forge", "neoforge", "paper")
Expand Down
3 changes: 3 additions & 0 deletions settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"fabric-1.17.1",
"fabric-1.18.2",
"fabric-1.19.4",
"fabric-1.20.2",
"fabric-1.20.4",
"fabric-1.20.6",
"fabric-1.21.3",
Expand All @@ -17,6 +18,7 @@
"forge-1.17.1",
"forge-1.18.2",
"forge-1.19.4",
"forge-1.20.2",
"forge-1.20.4",
"forge-1.20.6",
"forge-1.21.3",
Expand All @@ -27,6 +29,7 @@
"neoforge-1.21.4",

"paper-1.19.4",
"paper-1.20.2",
"paper-1.20.4",
"paper-1.20.6",
"paper-1.21.3"
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/com/vulpeus/kyoyu/CompatibleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

import net.minecraft.resources.ResourceLocation;

import java.util.UUID;

//? if PAPER {
/* import org.bukkit.entity.Player; */
//?} else {
import net.minecraft.server.level.ServerPlayer;
//?}

//? if >=1.19 {
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
Expand All @@ -24,4 +32,61 @@ public static ResourceLocation identifier(String namespace, String path) {
/* return new ResourceLocation(namespace, path); */
//?}
}


public static class KyoyuPlayer {
private boolean isCompatible = false;

//? if PAPER {
/* private final Player player; */
//?} else {
private final ServerPlayer player;
//?}

public KyoyuPlayer(
//? if PAPER {
/* Player player */
//?} else {
ServerPlayer player
//?}
) {
this.player = player;
}

public UUID getUUID() {
//? if PAPER {
/* return player.getUniqueId(); */
//?} else {
return player.getUUID();
//?}
}
public String getName() {
//? if PAPER {
/* return player.getName(); */
//?} else {
return player.getName().getString();
//?}
}
public void setCompatible(boolean isCompatible) {
this.isCompatible = isCompatible;
}
public boolean isCompatible() {
return this.isCompatible;
}

//? if PAPER {
/* public Player player() { */
//?} else {
public ServerPlayer player() {
//?}
return this.player;
}

@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj instanceof KyoyuPlayer) return ((KyoyuPlayer) obj).player.equals(this.player);
return this.player.equals(obj);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/vulpeus/kyoyu/Kyoyu.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Kyoyu {

public static KyoyuConfig CONFIG = null;

public static List<ServerPlayer> PLAYERS = new ArrayList<>();
public static PlayerList<CompatibleUtils.KyoyuPlayer> PLAYERS = new PlayerList<>();

private static boolean isClient = false;

Expand Down
19 changes: 13 additions & 6 deletions src/main/java/com/vulpeus/kyoyu/KyoyuLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;

import java.util.UUID;

public class KyoyuLogger {
private final String prefix;
private Level chatLevel;
Expand Down Expand Up @@ -48,13 +50,18 @@ public void error(String fmt, Object... objects) {
private void log(Level level, String fmt, Object... objects) {
String message = format(fmt, objects);
if (shouldLog(level, this.chatLevel)) {
for (ServerPlayer serverPlayer: Kyoyu.PLAYERS) {
//? if >=1.19 {
serverPlayer.sendSystemMessage(CompatibleUtils.text(message));
//?} elif >=1.16 {
/* serverPlayer.sendMessage(CompatibleUtils.text(message), net.minecraft.Util.NIL_UUID); */
for (UUID uuid: Kyoyu.PLAYERS.getAll()) {
CompatibleUtils.KyoyuPlayer player = Kyoyu.PLAYERS.getServerPlayer(uuid);
//? if PAPER {
/* player.player().sendMessage(message); */
//?} else {
/* serverPlayer.sendMessage(CompatibleUtils.text(message)); */
//? if >=1.19 {
player.player().sendSystemMessage(CompatibleUtils.text(message));
//?} elif >=1.16 {
/* player.player().sendMessage(CompatibleUtils.text(message), net.minecraft.Util.NIL_UUID); */
//?} else {
/* player.player().sendMessage(CompatibleUtils.text(message)); */
//?}
//?}
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/vulpeus/kyoyu/KyoyuMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,5 @@ public class KyoyuMod
);

Kyoyu.loadConfig();

//? if FABRIC
KyoyuPacketPayload.register();
//? if NEOFORGE
/* modBus.addListener(KyoyuPacketPayload::register); */
// TODO: Forge Packet Register
}
}
124 changes: 124 additions & 0 deletions src/main/java/com/vulpeus/kyoyu/PlayerList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.vulpeus.kyoyu;

import org.jetbrains.annotations.NotNull;

import java.util.*;

public class PlayerList<T> {
private final Map<UUID, Player<T>> playerMap;
private final Map<String, UUID> mcidMap;

public PlayerList() {
this.playerMap = new HashMap<>();
this.mcidMap = new HashMap<>();
}

public int size() {
return this.playerMap.size();
}

public boolean isEmpty() {
return this.playerMap.isEmpty();
}

public void clear() {
this.playerMap.clear();
this.mcidMap.clear();
}

// Get
public T getServerPlayer(@NotNull String mcid) {
UUID uuid = this.getUUID(mcid);
if (uuid == null) return null;
return this.getServerPlayer(uuid);
}
public T getServerPlayer(@NotNull UUID uuid) {
Player<T> player = playerMap.get(uuid);
if (player == null) return null;
return player.serverPlayer();
}
public UUID getUUID(@NotNull String mcid) {
return mcidMap.get(mcid.toLowerCase());
}

// Contains
public boolean contains(@NotNull String mcid) {
return this.mcidMap.containsKey(mcid.toLowerCase());
}
public boolean contains(@NotNull UUID uuid) {
return this.playerMap.containsKey(uuid);
}

// Add
public boolean add(@NotNull UUID uuid, @NotNull String mcid) {
Player<T> player = new Player<>(uuid, mcid);
return this.add(player);
}
public boolean add(@NotNull UUID uuid, @NotNull String mcid, @NotNull T serverPlayer) {
Player<T> player = new Player<>(uuid, mcid, serverPlayer);
return this.add(player);
}
private boolean add(@NotNull Player<T> player) {
Player<T> i = this.playerMap.put(player.uuid, player);
UUID j = this.mcidMap.put(player.mcid, player.uuid);
return i == null && j == null;
}

// Remove
public boolean remove(@NotNull String mcid) {
return this.remove(this.getUUID(mcid));
}
public boolean remove(@NotNull UUID uuid) {
return this.remove(this.playerMap.get(uuid));
}
private boolean remove(@NotNull Player<T> player) {
Player<T> i = this.playerMap.remove(player.uuid);
UUID j = this.mcidMap.remove(player.mcid);
return i != null && j != null;
}

// Get All
@NotNull
public Set<UUID> getAll() {
return playerMap.keySet();
}

private static class Player<T> {
private final String mcid;
private final UUID uuid;
private T serverPlayer = null;

public Player(@NotNull UUID uuid, @NotNull String mcid) {
this.uuid = uuid;
this.mcid = mcid.toLowerCase();
}

public Player(@NotNull UUID uuid, @NotNull String mcid, @NotNull T serverPlayer) {
this.uuid = uuid;
this.mcid = mcid.toLowerCase();
this.serverPlayer = serverPlayer;
}

public void setServerPlayer(@NotNull T serverPlayer) {
this.serverPlayer = serverPlayer;
}
public T serverPlayer() {
return this.serverPlayer;
}

public UUID uuid() {
return this.uuid;
}

public String mcid() {
return this.mcid;
}

@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (!(obj instanceof Player)) return false;
return ((Player<?>) obj).uuid.equals(this.uuid);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/vulpeus/kyoyu/client/KyoyuClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void init(String serverVersion, KyoyuConfig config) {
instance = new KyoyuClient(serverVersion, config);
}

public static void deinitClient() {
public static void deinit() {
if (instance != null) {
Kyoyu.LOGGER.info("Kyoyu client deinit");
instance = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.vulpeus.kyoyu.client.mixins;

//? if client {
import com.vulpeus.kyoyu.Kyoyu;
import com.vulpeus.kyoyu.net.KyoyuPacketPayload;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

//? if >=1.20.2
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;

//? if <=1.19.4 {
/* import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; */
//?} else {
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
//?}

@Mixin(
//? if >=1.20.2 {
net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl.class
//?} else {
/* net.minecraft.client.multiplayer.ClientPacketListener.class */
//?}
)
public class ClientCommonPacketListenerImplMixin {
@Unique
private final String targetMethod =
//? if >=1.20.2 {
"handleCustomPayload(Lnet/minecraft/network/protocol/common/ClientboundCustomPayloadPacket;)V";
//?} else {
/* "handleCustomPayload"; */
//?}

@Inject(method = targetMethod, at = @At("HEAD"), cancellable = true)
private void handleCustomPayload(ClientboundCustomPayloadPacket customPayloadPacket, CallbackInfo ci) {
//? if >=1.20.2 {
CustomPacketPayload payload = customPayloadPacket.payload();
if (payload instanceof KyoyuPacketPayload) {
KyoyuPacketPayload kyoyuPacketPayload = (KyoyuPacketPayload) payload;
// handle(player)
//? if <1.20.5 {
/*
// handle
Kyoyu.LOGGER.info("on custom packet payload");
*/
//?} else {
// handle
Kyoyu.LOGGER.info("on custom packet payload");
//?}
ci.cancel();
}
//?} else {
/*
if (customPayloadPacket.getIdentifier().equals(KyoyuPacketPayload.identifier)) {
byte[] payload = customPayloadPacket.getData().readByteArray();
Kyoyu.LOGGER.info("on custom packet payload");
// handle(player)
ci.cancel();
}
*/
//?}
}
}
//?}
Loading
Loading