
X_ZombieSlayer_X
Members-
Posts
35 -
Joined
-
Last visited
Everything posted by X_ZombieSlayer_X
-
How to force a resend of serialized ArgumentTypes?
X_ZombieSlayer_X replied to X_ZombieSlayer_X's topic in Modder Support
I found a solution! I modified the /ranks command to use a custom StringArgument. StringArgument is empty and wont have any suggestions. Then I follow up this Commands.argument with a .suggest() that calls a function to return uptodate suggestions. Did not have to mess with packets at all! This is new code incase anyone in the future needs this! Command /ranks: public class RankCommands extends ModCommand{ @Override protected void initCommand() { command = Commands.literal("ranks").requires( (commandContext) -> {return commandContext.hasPermission(3);} ).then(join()).then(create()).then(delete()).then(modify()); } private LiteralArgumentBuilder<CommandSourceStack> join(){ return Commands.literal("join").then(Commands.argument("player", EntityArgument.player()).then(Commands.argument("rank", StringArgument.string()).suggests(CustomSuggestionProvider::getRankSuggestions).executes( (commandContext) -> { return joinRank(commandContext);} ))); } private LiteralArgumentBuilder<CommandSourceStack> create(){ return Commands.literal("create").then(Commands.argument("name", StringArgument.string()).executes( (commandContext) -> { return createRank(commandContext);} )); } private LiteralArgumentBuilder<CommandSourceStack> delete(){ return Commands.literal("delete").then(Commands.argument("rank", StringArgument.string()).suggests(CustomSuggestionProvider::getRankSuggestions).executes( (commandContext) -> { return deleteRank(commandContext);} )); } private LiteralArgumentBuilder<CommandSourceStack> modify(){ return Commands.literal("modify").then(Commands.argument("rank", StringArgument.string()).suggests(CustomSuggestionProvider::getRankSuggestions) .then(modifySetColor()) .then(modifySetColoredChat()) .then(modifyAddCommand()) .then(modifyRemoveCommand())); } private LiteralArgumentBuilder<CommandSourceStack> modifySetColor(){ return Commands.literal("setColor").then(Commands.argument("color", ColorArgument.color()).executes( (commandContext) -> {return setColor(commandContext);} )); } private LiteralArgumentBuilder<CommandSourceStack> modifySetColoredChat(){ return Commands.literal("setColoredChat") .then(Commands.literal("true").executes( (commandContext) -> {return setColoredChat(commandContext,true);} )) .then(Commands.literal("false").executes( (commandContext) -> {return setColoredChat(commandContext, false);} )); } private LiteralArgumentBuilder<CommandSourceStack> modifyAddCommand(){ return Commands.literal("addCommand").then(Commands.argument("command", StringArgument.string()).suggests(CustomSuggestionProvider::getCommandSuggestions).executes( (commandContext) -> {return addCommand(commandContext);} )); } private LiteralArgumentBuilder<CommandSourceStack> modifyRemoveCommand(){ return Commands.literal("removeCommand").then(Commands.argument("command", StringArgument.string()).suggests(CustomSuggestionProvider::getCommandSuggestions).executes( (commandContext) -> {return removeCommand(commandContext);} )); } private int joinRank(CommandContext<CommandSourceStack> commandContext) throws CommandSyntaxException { String name = StringArgument.getString(commandContext, "rank"); Player player = EntityArgument.getPlayer(commandContext, "player"); if(ModStatics.rankManager.joinRank(player.getUUID(), name)) { commandContext.getSource().sendSuccess(new TextComponent("Joined rank ["+name+"] !"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to join rank ["+name+"] !")); } return 1; } private static int createRank(CommandContext<CommandSourceStack> commandContext) throws CommandSyntaxException { String name = StringArgument.getString(commandContext, "name"); if(ModStatics.rankManager.createRank(name)) { commandContext.getSource().sendSuccess(new TextComponent("Created rank ["+name+"] !"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to create rank ["+name+"] !")); } return 1; } private static int deleteRank(CommandContext<CommandSourceStack> commandContext) { String name = StringArgument.getString(commandContext, "rank"); if(ModStatics.rankManager.deleteRank(name)) { commandContext.getSource().sendSuccess(new TextComponent("Deleted rank ["+name+"] !"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to delete rank ["+name+"] !")); } return 1; } private static int addCommand(CommandContext<CommandSourceStack> commandContext) { String name = StringArgument.getString(commandContext, "rank"); String literal = StringArgument.getString(commandContext, "command"); if(ModStatics.rankManager.addCommandToRank(name, literal)) { commandContext.getSource().sendSuccess(new TextComponent("Added command /"+literal+" to rank ["+name+"] !"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to add command /"+literal+" to rank ["+name+"] !")); } return 1; } private static int removeCommand(CommandContext<CommandSourceStack> commandContext) { String name = StringArgument.getString(commandContext, "rank"); String literal = StringArgument.getString(commandContext, "command"); if(ModStatics.rankManager.removeCommandFromRank(name, literal)) { commandContext.getSource().sendSuccess(new TextComponent("Removed command "+literal+" to rank ["+name+"] !"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to removed command "+literal+" from rank ["+name+"] !")); } return 1; } private static int setColor(CommandContext<CommandSourceStack> commandContext) { String name = StringArgument.getString(commandContext, "rank"); ChatFormatting formatting = ColorArgument.getColor(commandContext, "color"); if(ModStatics.rankManager.getRank(name).setColor(formatting)) { commandContext.getSource().sendSuccess(new TextComponent("Updated rank color!"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to update rank color!")); } return 1; } private static int setColoredChat(CommandContext<CommandSourceStack> commandContext, boolean b) { String name = StringArgument.getString(commandContext, "rank"); if(ModStatics.rankManager.setRankColoredChat(name, b)) { commandContext.getSource().sendSuccess(new TextComponent("Updated rank canColoredChat!"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to update rank canColoredChat!")); } return 1; } } StringArgument: public class StringArgument implements ArgumentType<String>{ private StringArgument() { } public static StringArgument string() { return new StringArgument(); } public static String getString(CommandContext<CommandSourceStack> commandContext, String name) { return commandContext.getArgument(name, String.class); } @Override public String parse(StringReader reader) throws CommandSyntaxException { String string = reader.readString(); return string; } public static class Serializer implements ArgumentSerializer<StringArgument>{ @Override public StringArgument deserializeFromNetwork(FriendlyByteBuf buffer) { return new StringArgument(); } @Override public void serializeToNetwork(StringArgument p_121579_, FriendlyByteBuf p_121580_) { } @Override public void serializeToJson(StringArgument p_121577_, JsonObject p_121578_) { } } } CustomSuggestionProvider: public class CustomSuggestionProvider{ public static CompletableFuture getRankSuggestions(CommandContext context, SuggestionsBuilder builder)throws CommandSyntaxException { Iterable<String> choices = ModStatics.rankManager.getAvaliableRanks(); for(String choice : choices) { builder.suggest(choice); } return builder.buildFuture(); } public static CompletableFuture getCommandSuggestions(CommandContext context, SuggestionsBuilder builder)throws CommandSyntaxException { Iterable<String> choices = ModStatics.modCommandList.getAvaliable(); for(String choice : choices) { builder.suggest(choice); } return builder.buildFuture(); } } Also don't forget to registry the custom argument type: ArgumentTypes.register("se:stringargument", StringArgument.class, new StringArgument.Serializer()); -
How to force a resend of serialized ArgumentTypes?
X_ZombieSlayer_X posted a topic in Modder Support
So I am building a rank system for forge servers. Very basic as of right now. When the player joins the server it automatically serializes the arguments required for /ranks so suggestions do work. However if and admin creates a new rank, the rank wont be suggested till the player disconnects and rejoins(retrieves new serialized arguments). Is there a way I can force the reserialization of ArgumentTypes to send to clients? Example: Look at the images attached! First two images are on the first connection. I had to leave and rejoin to get the suggestion to work for the third image. /ranks command: @Override protected void initCommand() { command = Commands.literal("ranks").requires( (commandContext) -> {return commandContext.hasPermission(3);} ).then(join()).then(create()).then(delete()).then(modify()); } private LiteralArgumentBuilder<CommandSourceStack> join(){ return Commands.literal("join").then(Commands.argument("player", EntityArgument.player()).then(Commands.argument("rank", IterableArgumentType.choices(ModStatics.rankManager.getAvaliableRanks())).executes( (commandContext) -> { return joinRank(commandContext);} ))); } private LiteralArgumentBuilder<CommandSourceStack> create(){ return Commands.literal("create").then(Commands.argument("name", MessageArgument.message()).executes( (commandContext) -> { return createRank(commandContext);} )); } private LiteralArgumentBuilder<CommandSourceStack> delete(){ return Commands.literal("delete").then(Commands.argument("rank", IterableArgumentType.choices(ModStatics.rankManager.getAvaliableRanks())).executes( (commandContext) -> { return deleteRank(commandContext);} )); } private LiteralArgumentBuilder<CommandSourceStack> modify(){ return Commands.literal("modify").then(Commands.argument("rank", IterableArgumentType.choices(ModStatics.rankManager.getAvaliableRanks())) .then(modifySetColor()) .then(modifySetColoredChat()) .then(modifyAddCommand()) .then(modifyRemoveCommand())); } private LiteralArgumentBuilder<CommandSourceStack> modifySetColor(){ return Commands.literal("setColor").then(Commands.argument("color", ColorArgument.color()).executes( (commandContext) -> {return setColor(commandContext);} )); } private LiteralArgumentBuilder<CommandSourceStack> modifySetColoredChat(){ return Commands.literal("setColoredChat") .then(Commands.literal("true").executes( (commandContext) -> {return setColoredChat(commandContext,true);} )) .then(Commands.literal("false").executes( (commandContext) -> {return setColoredChat(commandContext, false);} )); } private LiteralArgumentBuilder<CommandSourceStack> modifyAddCommand(){ return Commands.literal("addCommand").then(Commands.argument("command", IterableArgumentType.choices(ModStatics.modCommandList.getAvaliable())).executes( (commandContext) -> {return addCommand(commandContext);} )); } private LiteralArgumentBuilder<CommandSourceStack> modifyRemoveCommand(){ return Commands.literal("removeCommand").then(Commands.argument("command", IterableArgumentType.choices(ModStatics.modCommandList.getAvaliable())).executes( (commandContext) -> {return removeCommand(commandContext);} )); } private int joinRank(CommandContext<CommandSourceStack> commandContext) throws CommandSyntaxException { String name = IterableArgumentType.getChoice(commandContext, "rank"); Player player = EntityArgument.getPlayer(commandContext, "player"); System.out.println(player.getUUID().toString() + " : " + name); if(ModStatics.rankManager.joinRank(player.getUUID(), name)) { commandContext.getSource().sendSuccess(new TextComponent("Joined rank ["+name+"] !"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to join rank ["+name+"] !")); } return 1; } private static int createRank(CommandContext<CommandSourceStack> commandContext) throws CommandSyntaxException { Component message = MessageArgument.getMessage(commandContext, "name"); String name = message.getContents(); if(ModStatics.rankManager.createRank(name)) { commandContext.getSource().sendSuccess(new TextComponent("Created rank ["+name+"] !"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to create rank ["+name+"] !")); } return 1; } private static int deleteRank(CommandContext<CommandSourceStack> commandContext) { String name = IterableArgumentType.getChoice(commandContext, "rank"); if(ModStatics.rankManager.deleteRank(name)) { commandContext.getSource().sendSuccess(new TextComponent("Deleted rank ["+name+"] !"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to delete rank ["+name+"] !")); } return 1; } private static int addCommand(CommandContext<CommandSourceStack> commandContext) { String name = IterableArgumentType.getChoice(commandContext, "rank"); String literal = IterableArgumentType.getChoice(commandContext, "command"); if(ModStatics.rankManager.addCommandToRank(name, literal)) { commandContext.getSource().sendSuccess(new TextComponent("Added command /"+literal+" to rank ["+name+"] !"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to add command /"+literal+" to rank ["+name+"] !")); } return 1; } private static int removeCommand(CommandContext<CommandSourceStack> commandContext) { String name = IterableArgumentType.getChoice(commandContext, "rank"); String literal = IterableArgumentType.getChoice(commandContext, "command"); if(ModStatics.rankManager.removeCommandFromRank(name, literal)) { commandContext.getSource().sendSuccess(new TextComponent("Removed command "+literal+" to rank ["+name+"] !"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to removed command "+literal+" from rank ["+name+"] !")); } return 1; } private static int setColor(CommandContext<CommandSourceStack> commandContext) { String name = IterableArgumentType.getChoice(commandContext, "rank"); ChatFormatting formatting = ColorArgument.getColor(commandContext, "color"); if(ModStatics.rankManager.getRank(name).setColor(formatting)) { commandContext.getSource().sendSuccess(new TextComponent("Updated rank color!"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to update rank color!")); } return 1; } private static int setColoredChat(CommandContext<CommandSourceStack> commandContext, boolean b) { String name = IterableArgumentType.getChoice(commandContext, "rank"); if(ModStatics.rankManager.setRankColoredChat(name, b)) { commandContext.getSource().sendSuccess(new TextComponent("Updated rank canColoredChat!"),true); }else { commandContext.getSource().sendFailure(new TextComponent("Failed to update rank canColoredChat!")); } return 1; } IterableArgumentType: private Iterable<String> choices; private IterableArgumentType(Iterable<String> choices) { this.choices = choices; } public static IterableArgumentType choices(Iterable<String> choices) { return new IterableArgumentType(choices); } public static String getChoice(CommandContext<CommandSourceStack> commandContext, String name) { return commandContext.getArgument(name, String.class); } @Override public String parse(StringReader reader) throws CommandSyntaxException { String string = reader.readString(); return string; } public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> commandContext, SuggestionsBuilder suggestionBuilder) { return SharedSuggestionProvider.suggest(choices, suggestionBuilder); } public Iterable<String> getChoices(){ return choices; } public static class Serializer implements ArgumentSerializer<IterableArgumentType>{ private String delimiter = "-"; public String convertToString(Iterable<String> choices) { StringBuilder builder = new StringBuilder(); ArrayList<String> array_choices = new ArrayList<String>(); for(String choice : choices) { array_choices.add(choice); } for(int i = 0; i < array_choices.size(); i++) { builder.append(array_choices.get(i)); if(i != array_choices.size()-1) { builder.append(delimiter); } } return builder.toString(); } public Iterable<String> convertToIterable(String choices){ String[] array_choices = choices.split(delimiter); Hashtable<String, Byte> hashtable_choices = new Hashtable<String, Byte>(); for(String choice : array_choices) { hashtable_choices.put(choice, (byte) 0); } return hashtable_choices.keySet(); } @Override public void serializeToNetwork(IterableArgumentType argument, FriendlyByteBuf buffer) { buffer.writeUtf(convertToString(argument.getChoices())); } @Override public IterableArgumentType deserializeFromNetwork(FriendlyByteBuf buffer) { String utf = buffer.readUtf(); return new IterableArgumentType(convertToIterable(utf)); } @Override public void serializeToJson(IterableArgumentType argument, JsonObject json) { json.addProperty("iterableargumenttype", convertToString(argument.getChoices())); } } -
Custom ArgumentType(s) not Serializing!
X_ZombieSlayer_X replied to X_ZombieSlayer_X's topic in Modder Support
Found solution! Don't use "." as a delimiter, now using "-" instead for better .split(delimiter)! -
Custom ArgumentType(s) not Serializing!
X_ZombieSlayer_X replied to X_ZombieSlayer_X's topic in Modder Support
So I did a bit of primitive debugging(printing out from serializer methods). The server is sending information but the client is not deserializing the data for whatever reason. Client Log: [16:47:49] [Netty Client IO #2/INFO]: Connected to a modded server. [04Sep2021 16:47:50.587] [Render thread/INFO] [com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService/]: Environment: authHost='https://authserver.mojang.com', accountsHost='https://api.mojang.com', sessionHost='https://sessionserver.mojang.com', servicesHost='https://api.minecraftservices.com', name='PROD' [16:47:51] [Render thread/INFO]: Loaded 0 advancements [16:48:08] [Render thread/INFO]: [CHAT] §8[default]§f<X_ZombieSlayer_X> test [16:48:14] [Render thread/INFO]: Stopping! Server Log: [16:47:49] [Server thread/INFO]: X_ZombieSlayer_X joined the game seserializeToNetwork:ench seserializeToNetwork:rename seserializeToNetwork:ench seserializeToNetwork:rename seserializeToNetwork:ench seserializeToNetwork:rename seserializeToNetwork:ench seserializeToNetwork:rename seserializeToNetwork:ench seserializeToNetwork:rename [16:48:08] [Server thread/INFO]: º8[default]ºf<X_ZombieSlayer_X> test [16:48:11] [Server thread/INFO]: X_ZombieSlayer_X lost connection: Disconnected [16:48:11] [Server thread/INFO]: X_ZombieSlayer_X left the game Serializer: public static class Serializer implements ArgumentSerializer<IterableArgumentType>{ private String delimiter = "."; public String convertToString(Iterable<String> choices) { StringBuilder builder = new StringBuilder(); ArrayList<String> array_choices = new ArrayList<String>(); for(String choice : choices) { array_choices.add(choice); System.out.println("seserializeToNetwork:"+choice); } for(int i = 0; i < array_choices.size(); i++) { builder.append(array_choices.get(i)); if(i != array_choices.size()-1) { builder.append(delimiter); } } return builder.toString(); } public Iterable<String> convertToIterable(String choices){ String[] array_choices = choices.split(delimiter); Hashtable<String, Byte> hashtable_choices = new Hashtable<String, Byte>(); for(String choice : array_choices) { System.out.println("deserializeFromNetwork:"+choice); hashtable_choices.put(choice, (byte) 0); } return hashtable_choices.keySet(); } @Override public void serializeToNetwork(IterableArgumentType argument, FriendlyByteBuf buffer) { buffer.writeUtf(convertToString(argument.getChoices())); } @Override public IterableArgumentType deserializeFromNetwork(FriendlyByteBuf buffer) { String utf = buffer.readUtf(); return new IterableArgumentType(convertToIterable(utf)); } @Override public void serializeToJson(IterableArgumentType argument, JsonObject json) { json.addProperty("iterableargumenttype", convertToString(argument.getChoices())); } } I should be hitting the println("deserializeFromNetwork:"+choice) but the client is outputting nothing? -
Custom ArgumentType(s) not Serializing!
X_ZombieSlayer_X replied to X_ZombieSlayer_X's topic in Modder Support
I made one that should replace both my ranks and modcommands argumenttype. It is no longer throwing errors/or red(invalid command), however, I can't see the suggestions. No suggestions are being listed(on multiplayer) and I am not sure why? Here is my new code: public class IterableArgumentType implements ArgumentType<String>{ private Iterable<String> choices; private IterableArgumentType(Iterable<String> choices) { this.choices = choices; } public static IterableArgumentType choices(Iterable<String> choices) { return new IterableArgumentType(choices); } public static String getChoice(CommandContext<CommandSourceStack> commandContext, String name) { return commandContext.getArgument(name, String.class); } @Override public String parse(StringReader reader) throws CommandSyntaxException { String string = reader.readString(); return string; } public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> commandContext, SuggestionsBuilder suggestionBuilder) { return SharedSuggestionProvider.suggest(choices, suggestionBuilder); } public Iterable<String> getChoices(){ return choices; } public static class Serializer implements ArgumentSerializer<IterableArgumentType>{ private String delimiter = "."; public String convertToString(Iterable<String> choices) { StringBuilder builder = new StringBuilder(); ArrayList<String> array_choices = new ArrayList<String>(); for(String choice : choices) { array_choices.add(choice); } for(int i = 0; i < array_choices.size(); i++) { builder.append(array_choices.get(i)); if(i != array_choices.size()-1) { builder.append(delimiter); } } return builder.toString(); } public Iterable<String> convertToIterable(String choices){ String[] array_choices = choices.split(delimiter); Hashtable<String, Byte> hashtable_choices = new Hashtable<String, Byte>(); for(String choice : array_choices) { hashtable_choices.put(choice, (byte) 0); } return hashtable_choices.keySet(); } @Override public void serializeToNetwork(IterableArgumentType argument, FriendlyByteBuf buffer) { buffer.writeUtf(convertToString(argument.getChoices())); } @Override public IterableArgumentType deserializeFromNetwork(FriendlyByteBuf buffer) { String utf = buffer.readUtf(); return new IterableArgumentType(convertToIterable(utf)); } @Override public void serializeToJson(IterableArgumentType argument, JsonObject json) { json.addProperty("iterableargumenttype", convertToString(argument.getChoices())); } } } Any ideas as to why it is not suggesting anything? -
Custom ArgumentType(s) not Serializing!
X_ZombieSlayer_X replied to X_ZombieSlayer_X's topic in Modder Support
Ah, thank you for the enlightenment and help! -
Custom ArgumentType(s) not Serializing!
X_ZombieSlayer_X replied to X_ZombieSlayer_X's topic in Modder Support
I thought enqueueWork was for modifying existing attributes? I am just needing tab-complete suggestions to work on multiplayer. The commands run and operated as expected but they just appear red on multiplayer do to my lack of an ArgumentSerializer. If you could explain in further detail why it would be a good idea to include enqueuWork, that would be much appreciated! I will take a look and create my custom serializer ! Thanks. -
Custom ArgumentType(s) not Serializing!
X_ZombieSlayer_X replied to X_ZombieSlayer_X's topic in Modder Support
If I need to make an ArgumentSerializer how do I do so? -
I am having problems with my custom ArgumentType(s) not serializing when running my mod on a server. It works fine on single player because there is not serialization required. Log: [00:00:24] [Server thread/INFO]: Made X_ZombieSlayer_X a server operator [00:00:24] [Netty Server IO #4/ERROR]: Could not serialize mod.ranks.commands.RankArgument@3f19c861 (class mod.ranks.commands.RankArgument) - will not be sent to client! [00:00:24] [Netty Server IO #4/ERROR]: Could not serialize mod.ranks.commands.RankArgument@72f73fc4 (class mod.ranks.commands.RankArgument) - will not be sent to client! [00:00:24] [Netty Server IO #4/ERROR]: Could not serialize mod.ranks.commands.RankArgument@78019307 (class mod.ranks.commands.RankArgument) - will not be sent to client! [00:00:24] [Netty Server IO #4/ERROR]: Could not serialize mod.commands.base.ModCommandArgument@5ff1379e (class mod.commands.base.ModCommandArgument) - will not be sent to client! [00:00:24] [Netty Server IO #4/ERROR]: Could not serialize mod.commands.base.ModCommandArgument@27d41c38 (class mod.commands.base.ModCommandArgument) - will not be sent to client! RankArgument: ModCommandArgument: Like I said before it works great on single player. I just need to get multiplayer working. Any help would be much appreciated. Seems like I need to call ArgumentTypes.register() but I am a bit confused on the arguments. Can someone please explain? Do I need a custom ArgumentSerializer?