Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

X_ZombieSlayer_X

Members
  • Posts

    22
  • Joined

  • Last visited

Everything posted by X_ZombieSlayer_X

  1. I don't understand where or how to create/find the MenuConstructor. Sorry, I am just not understanding, how to transform the player's enderchestinventory into a menu constructor.
  2. How do I get a menu provider for a player's inventory and enderchest? I believe the function to call to do this is player.openMenu(). I just don't know how to get or create a menu provider. The purpose of this is to add commands /enderchest and /invsee !
  3. Thanks, will keep an eye on it for when it gets merged!
  4. I have a chunkclaiming system that allows users to claim chunks so that they can only build in them. It works fine but I just want to add a message for when players enter their claimed chunks. Maybe I could do some type of movement event and cross reference it with claimed chunks?
  5. Thanks! It now works. Another quick question. What event should I be listening for to get a player chunk entering event. It used to be PlayerEvent.EnteringChunk in 1.16.5.
  6. Hello, my fly command is not working. Not sure why it is not working. I am setting the player.getAbilities().mayfly to true. It even prints out that is is true! @Override public void command() { command = Commands.literal("fly").executes( (commandContext) -> {return fly(commandContext);} ); } private int fly(CommandContext<CommandSourceStack> commandContext) throws CommandSyntaxException { Player player = commandContext.getSource().getPlayerOrException(); player.getAbilities().mayfly = !player.getAbilities().mayfly; commandContext.getSource().sendSuccess(Msg.buildMessage("Fly set to : "+player.getAbilities().mayfly), false); return 1; } Any reason why it would not be working?
  7. I am not at my computer at the moment. I meant I don’t see the player.sendAbilitiesUpdate method anymore. It is no longer there to use.
  8. I am having trouble getting players to fly in survival mode! I change the players mayfly boolean but I don't see the player.sendAbilitiesUpdate(); method anymore. I don’t think it is available to use. My code so far: @Override public void command() { command = Commands.literal("fly").executes( (commandContext) -> {return fly(commandContext);} ); } private int fly(CommandContext<CommandSourceStack> commandContext) throws CommandSyntaxException { Player player = commandContext.getSource().getPlayerOrException(); player.getAbilities().mayfly = !player.getAbilities().mayfly; commandContext.getSource().sendSuccess(Msg.buildMessage("Fly set to : "+player.getAbilities().mayfly), false); return 1; }
  9. I am getting an error switching dimensions only on servers. It works well in single player. Error: [13:16:51] [Server thread/WARN]: X_ZombieSlayer_X moved too quickly! -16.78373791554268,9.5,-65.79919724030039 [13:16:51] [Server thread/WARN]: X_ZombieSlayer_X moved too quickly! -16.78373791554268,9.5,-65.79919724030039 [13:16:57] [Server thread/FATAL]: Error executing task on Server java.lang.NullPointerException: Cannot invoke "it.unimi.dsi.fastutil.objects.ObjectSet.remove(Object)" because "objectset" is null at net.minecraft.server.level.DistanceManager.m_140828_(DistanceManager.java:230) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.level.ChunkMap.m_140184_(ChunkMap.java:863) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.level.ServerChunkCache.m_8385_(ServerChunkCache.java:433) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.network.ServerGamePacketListenerImpl.m_7185_(ServerGamePacketListenerImpl.java:849) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.m_5797_(SourceFile:114) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot.m_5797_(SourceFile:16) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.network.protocol.PacketUtils.m_131356_(SourceFile:21) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.TickTask.run(SourceFile:18) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.BlockableEventLoop.m_6367_(SourceFile:151) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.ReentrantBlockableEventLoop.m_6367_(SourceFile:23) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_6367_(MinecraftServer.java:775) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_6367_(MinecraftServer.java:162) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.BlockableEventLoop.m_7245_(SourceFile:125) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_129961_(MinecraftServer.java:758) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_7245_(MinecraftServer.java:752) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.BlockableEventLoop.m_18699_(SourceFile:110) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_130012_(MinecraftServer.java:737) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:687) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_177918_(MinecraftServer.java:258) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at java.lang.Thread.run(Thread.java:831) [?:?] [13:17:06] [Server thread/FATAL]: Error executing task on Server java.lang.NullPointerException: Cannot invoke "it.unimi.dsi.fastutil.objects.ObjectSet.remove(Object)" because "objectset" is null at net.minecraft.server.level.DistanceManager.m_140828_(DistanceManager.java:230) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.level.ChunkMap.m_140184_(ChunkMap.java:863) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.level.ServerChunkCache.m_8385_(ServerChunkCache.java:433) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.network.ServerGamePacketListenerImpl.m_7185_(ServerGamePacketListenerImpl.java:849) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.m_5797_(SourceFile:114) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot.m_5797_(SourceFile:16) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.network.protocol.PacketUtils.m_131356_(SourceFile:21) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.TickTask.run(SourceFile:18) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.BlockableEventLoop.m_6367_(SourceFile:151) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.ReentrantBlockableEventLoop.m_6367_(SourceFile:23) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_6367_(MinecraftServer.java:775) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_6367_(MinecraftServer.java:162) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.BlockableEventLoop.m_7245_(SourceFile:125) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_129961_(MinecraftServer.java:758) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_7245_(MinecraftServer.java:752) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.BlockableEventLoop.m_18701_(SourceFile:134) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_130012_(MinecraftServer.java:738) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:687) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_177918_(MinecraftServer.java:258) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at java.lang.Thread.run(Thread.java:831) [?:?] [13:17:07] [Server thread/FATAL]: Error executing task on Server java.lang.NullPointerException: Cannot invoke "it.unimi.dsi.fastutil.objects.ObjectSet.remove(Object)" because "objectset" is null at net.minecraft.server.level.DistanceManager.m_140828_(DistanceManager.java:230) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.level.ChunkMap.m_140184_(ChunkMap.java:863) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.level.ServerChunkCache.m_8385_(ServerChunkCache.java:433) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.network.ServerGamePacketListenerImpl.m_7185_(ServerGamePacketListenerImpl.java:849) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.m_5797_(SourceFile:114) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos.m_5797_(SourceFile:42) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.network.protocol.PacketUtils.m_131356_(SourceFile:21) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.TickTask.run(SourceFile:18) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.BlockableEventLoop.m_6367_(SourceFile:151) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.ReentrantBlockableEventLoop.m_6367_(SourceFile:23) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_6367_(MinecraftServer.java:775) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_6367_(MinecraftServer.java:162) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.BlockableEventLoop.m_7245_(SourceFile:125) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_129961_(MinecraftServer.java:758) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_7245_(MinecraftServer.java:752) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.BlockableEventLoop.m_18701_(SourceFile:134) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_130012_(MinecraftServer.java:738) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:687) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_177918_(MinecraftServer.java:258) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at java.lang.Thread.run(Thread.java:831) [?:?] [13:17:07] [Server thread/FATAL]: Error executing task on Server java.lang.NullPointerException: Cannot invoke "it.unimi.dsi.fastutil.objects.ObjectSet.remove(Object)" because "objectset" is null at net.minecraft.server.level.DistanceManager.m_140828_(DistanceManager.java:230) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.level.ChunkMap.m_140184_(ChunkMap.java:863) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.level.ServerChunkCache.m_8385_(ServerChunkCache.java:433) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.network.ServerGamePacketListenerImpl.m_7185_(ServerGamePacketListenerImpl.java:849) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.m_5797_(SourceFile:114) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos.m_5797_(SourceFile:42) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.network.protocol.PacketUtils.m_131356_(SourceFile:21) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.TickTask.run(SourceFile:18) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.BlockableEventLoop.m_6367_(SourceFile:151) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.ReentrantBlockableEventLoop.m_6367_(SourceFile:23) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_6367_(MinecraftServer.java:775) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_6367_(MinecraftServer.java:162) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.BlockableEventLoop.m_7245_(SourceFile:125) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_129961_(MinecraftServer.java:758) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_7245_(MinecraftServer.java:752) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.util.thread.BlockableEventLoop.m_18701_(SourceFile:134) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_130012_(MinecraftServer.java:738) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:687) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at net.minecraft.server.MinecraftServer.m_177918_(MinecraftServer.java:258) ~[server-1.17.1-20210706.113038-srg.jar%2325!:?] at java.lang.Thread.run(Thread.java:831) [?:?] Code to teleport: public void teleport(Player player) { ResourceKey<Level> dimension = ResourceKey.create(ResourceKey.createRegistryKey(new ResourceLocation(worldRegistry)), new ResourceLocation(worldEntry)); if(player.getCommandSenderWorld().dimension().compareTo(dimension)!=0) { player.changeDimension(ServerLifecycleHooks.getCurrentServer().getLevel(dimension)); } player.teleportTo(pos.getX(), (pos.getY()+0.5f), pos.getZ()); player.lookAt(ServerLifecycleHooks.getCurrentServer().createCommandSourceStack().getAnchor(), lookAt.getVec3()); } Any ideas on how to fix this? I read a few forums containing ITeleporter but could not find anything mentioning it in the docs.
  10. ResourceKey.create(ResourceLocation, ResourceLocation) is not visible. So I am using this! ResourceKey<Level> dimension = ResourceKey.create(ResourceKey.createRegistryKey(new ResourceLocation(worldRegistry)), new ResourceLocation(worldEntry));
  11. Thanks for the help, I just have one more question. ResourceKey.location only returns one resource location(I believe the registry). How would I get both?(entry and registry)
  12. How can I convert a resource key to a string(or other serializable type) and then back to a resource key? I need this for storing dimensions for /homes and /warps! Is this even possible? I read the docs on resource location but I can’t seem to find anything on resource key!
  13. 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());
  14. 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())); } }
  15. Found solution! Don't use "." as a delimiter, now using "-" instead for better .split(delimiter)!
  16. 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?
  17. 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?
  18. 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.
  19. If I need to make an ArgumentSerializer how do I do so?
  20. 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?
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.