diff --git a/src/main/kotlin/gamer/noir/curseenc/command/ModCommands.kt b/src/main/kotlin/gamer/noir/curseenc/command/ModCommands.kt index 012a47a..18d7e25 100644 --- a/src/main/kotlin/gamer/noir/curseenc/command/ModCommands.kt +++ b/src/main/kotlin/gamer/noir/curseenc/command/ModCommands.kt @@ -3,6 +3,7 @@ package gamer.noir.curseenc.command import com.mojang.brigadier.CommandDispatcher import com.mojang.brigadier.arguments.StringArgumentType import com.mojang.brigadier.context.CommandContext +import gamer.noir.curseenc.CurseOfEienNoChi import gamer.noir.curseenc.data.AttachmentsServer import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback import net.minecraft.commands.CommandBuildContext @@ -10,6 +11,7 @@ import net.minecraft.commands.CommandSourceStack import net.minecraft.commands.Commands import net.minecraft.commands.Commands.CommandSelection import net.minecraft.network.chat.Component +import net.minecraft.resources.ResourceLocation object ModCommands { @@ -21,35 +23,76 @@ object ModCommands { val player = context.source?.player val Power = StringArgumentType.getString(context, "Power") if (player != null) { - player.setAttached(AttachmentsServer.EXEMPLE,"$Power") - context.getSource()!!.sendSuccess( { Component.literal("Power set to $Power") }, false) + val powerList = player.getAttachedOrCreate(AttachmentsServer.Powers) + if (powerList.contains(ResourceLocation.fromNamespaceAndPath(CurseOfEienNoChi.MOD_ID ,Power))) { + + context.getSource()!!.sendSuccess( { Component.literal("$Power Existe déjà ") }, false) + } + else { + val newList = powerList.plus(ResourceLocation.fromNamespaceAndPath(CurseOfEienNoChi.MOD_ID,Power)) + player.setAttached(AttachmentsServer.Powers,newList) + context.getSource()!!.sendSuccess({ Component.literal("$Power A été ajouté") }, false) + } } return 1 } + + private fun executePowerRemove(context: CommandContext): Int { - context.getSource()!!.sendSuccess( { Component.literal("Power !!!") }, false) + val player = context.source?.player + val Power = StringArgumentType.getString(context, "Power") + if (player != null) { + val powerList = player.getAttachedOrCreate(AttachmentsServer.Powers) + if (powerList.contains(ResourceLocation.fromNamespaceAndPath(CurseOfEienNoChi.MOD_ID ,Power))) { + val newList = powerList.minus(ResourceLocation.fromNamespaceAndPath(CurseOfEienNoChi.MOD_ID,Power)) + player.setAttached(AttachmentsServer.Powers,newList) + context.getSource()!!.sendSuccess( { Component.literal("$Power a été révoqué") }, false) + } + else { + context.getSource()!!.sendSuccess({ Component.literal("Tu ne possèdes pas $Power") }, false) + } + } return 1 } + + private fun executePowerQuary(context: CommandContext): Int { val player = context.source?.player - if (player != null && player.hasAttached(AttachmentsServer.EXEMPLE)) { - val Power = player.getAttached(AttachmentsServer.EXEMPLE) - context.getSource()!!.sendSuccess( { Component.literal("Power is $Power") }, false) + if (player != null && player.hasAttached(AttachmentsServer.Powers)) { + val Power = player.getAttached(AttachmentsServer.Powers) + context.getSource()!!.sendSuccess( { Component.literal("La liste de vos pouvoirs est $Power") }, false) } else { context.getSource()!!.sendSuccess( { Component.literal("nop") }, false) } + return 1 + } + private fun executePowerQuaryTyped(context: CommandContext): Int { + val player = context.source?.player + val Power = StringArgumentType.getString(context, "Power") + if (player != null && player.hasAttached(AttachmentsServer.Powers)) { + val powerList = player.getAttachedOrCreate(AttachmentsServer.Powers) + if (powerList.contains(ResourceLocation.fromNamespaceAndPath(CurseOfEienNoChi.MOD_ID ,Power))) { + context.getSource()!!.sendSuccess( { Component.literal("Vous possédez $Power") }, false) + } + else{ + context.getSource()!!.sendSuccess( { Component.literal("Tu ne possèdes pas $Power") }, false) + } + } + else { + context.getSource()!!.sendSuccess( { Component.literal("nop") }, false) + } return 1 } val argument_power = Commands.argument("Power", StringArgumentType.string()).suggests { context, builder -> - builder.suggest("Night_vision") - .suggest("Hyper_speed") - .suggest("Bat_mod") + builder.suggest("night_vision") + .suggest("hyper_speed") + .suggest("bat_mod") .suggest("...") builder.buildFuture() } @@ -71,8 +114,9 @@ object ModCommands { .executes(ModCommands::executePowerRemove))) .then(Commands.literal("quary") + .executes(ModCommands::executePowerQuary) .then(argument_power - .executes(ModCommands::executePowerQuary))) + .executes(ModCommands::executePowerQuaryTyped))) ) diff --git a/src/main/kotlin/gamer/noir/curseenc/data/AttachmentsServer.kt b/src/main/kotlin/gamer/noir/curseenc/data/AttachmentsServer.kt index 2e9e02e..b8702a2 100644 --- a/src/main/kotlin/gamer/noir/curseenc/data/AttachmentsServer.kt +++ b/src/main/kotlin/gamer/noir/curseenc/data/AttachmentsServer.kt @@ -4,6 +4,7 @@ import com.mojang.serialization.Codec import gamer.noir.curseenc.CurseOfEienNoChi import net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry import net.fabricmc.fabric.api.attachment.v1.AttachmentSyncPredicate +import net.minecraft.nbt.CompoundTag import net.minecraft.network.codec.ByteBufCodecs import net.minecraft.resources.ResourceLocation @@ -13,4 +14,10 @@ object AttachmentsServer { builder -> builder.initializer { "" }.syncWith(ByteBufCodecs.STRING_UTF8, AttachmentSyncPredicate.all()).persistent( Codec.STRING).copyOnDeath() } + var Powers = AttachmentRegistry.create>(ResourceLocation.fromNamespaceAndPath(CurseOfEienNoChi.MOD_ID,"powers")) { + builder -> builder.initializer { listOf() } + .syncWith(ResourceLocation.STREAM_CODEC.apply(ByteBufCodecs.list()), AttachmentSyncPredicate.all()) + .persistent(ResourceLocation.CODEC.listOf()) + .copyOnDeath() + } } \ No newline at end of file