Skip to content

Commit

Permalink
complete remove list
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Joy-Shadow committed Dec 29, 2021
1 parent b0e524c commit 8c40ac7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package njoyshadowsmod.fabricchatkoreanconvertor;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientLoginConnectionEvents;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.network.C2SPacketTypeCallback;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.text.Text;
import njoyshadowsmod.fabricchatkoreanconvertor.utils.EnKData;
import njoyshadowsmod.fabricchatkoreanconvertor.utils.UUidUtil;
Expand All @@ -27,7 +30,7 @@ public void onInitialize() {
IsExist = true;

playerdata.setIsEnable(!playerdata.getIsEnable());
context.getSource().getPlayer().sendSystemMessage(Text.of(String.format("EnK is %b", playerdata.getIsEnable())),playerUUID);
context.getSource().getPlayer().sendSystemMessage(Text.of(String.format("EnK is %s", (playerdata.getIsEnable() ? "enable" : "disable" ))),playerUUID);
break;
}
}
Expand All @@ -40,7 +43,12 @@ public void onInitialize() {

return 1;
}));
dispatcher.register((literal("enklist").executes(context -> {
for (EnKData playerdata : UUidUtil.playerList){
System.out.println(playerdata.getUUID());
}
return 1;
})));
});

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package njoyshadowsmod.fabricchatkoreanconvertor.mixin;

import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

import njoyshadowsmod.fabricchatkoreanconvertor.utils.EnKData;
import njoyshadowsmod.fabricchatkoreanconvertor.utils.UUidUtil;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Arrays;
import java.util.UUID;

@Mixin(ServerPlayNetworkHandler.class)
public abstract class MixinOnDisconnected {
@Shadow public abstract ServerPlayerEntity getPlayer();
@Inject(method = "onDisconnected", at = @At(value = "HEAD"))
public void onDisconnected(Text reason, CallbackInfo ci){
UUID PlayerUUID = this.getPlayer().getUuid();

for(int i = 0; i < UUidUtil.playerList.size(); i++){
if(UUidUtil.playerList.get(i).getUUID() == PlayerUUID){
try{
UUidUtil.playerList.remove(i);
}
catch (Exception E){
System.out.println(E.getMessage());
}
}
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ public class EnKData {
private UUID playerUUID;
private boolean IsEnable;

public EnKData(UUID uuid,boolean isEnable){
public EnKData(UUID uuid,boolean isEnable){
this.playerUUID = uuid;
this.IsEnable = isEnable;
}


public void setUUID(UUID uuid){
this.playerUUID = uuid;
}
Expand All @@ -23,4 +24,4 @@ public UUID getUUID(){
public boolean getIsEnable(){
return IsEnable;
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/FabricChatKoreanConvertor.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"package": "njoyshadowsmod.fabricchatkoreanconvertor.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
"MixinServerPlayNetworkHandler"
"MixinServerPlayNetworkHandler",
"MixinOnDisconnected"
],
"client": [
],
Expand Down

0 comments on commit 8c40ac7

Please sign in to comment.