Commands Broken?

Discussion in 'Plugin Development' started by Is3kai, Mar 2, 2024.

Thread Status:
Not open for further replies.
  1. Offline

    Is3kai

    Sure. Here is the image:

    upload_2024-3-6_14-28-38.png

    and here is the code:
    Code:
    package org.smpmakers.dimensionsmpspigot.commands;
    
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.smpmakers.dimensionsmpspigot.items.ItemManager;
    
    
    public class GivePluginItems implements CommandExecutor {
        @Override
        public boolean onCommand(CommandSender commandSender,  Command command,  String s,  String[] strings) {
            if (!(commandSender instanceof Player)) {
                commandSender.sendMessage("Only Players can use this command");
                return true;
            }
            Player player = (Player) commandSender;
    
            player.sendMessage(String.valueOf(strings.length));
            if (strings.length != 2) {
                player.sendMessage("Usage: /giveitems <itemType> <typeNum>");
                return true;
            }
    
            String itemType = strings[0];
            int typeNum;
            try {
                typeNum = Integer.parseInt(strings[1]);
            } catch (NumberFormatException e) {
                player.sendMessage("Invalid type number.");
                return false;
            }
    
            // Get the custom item based on the itemType and typeNum
            if(itemType.equals("warps")){
                ItemStack warpItem;
                switch (typeNum) {
                    case 1:
                        warpItem = ItemManager.warp1;
                        break;
                    case 2:
                        warpItem = ItemManager.warp2;
                        break;
                    case 3:
                        warpItem = ItemManager.warp3;
                        break;
                    case 4:
                        warpItem = ItemManager.warp4;
                        break;
                    case 5:
                        warpItem = ItemManager.warp5;
                        break;
                    case 6:
                        warpItem = ItemManager.warp6;
                        break;
                    case 7:
                        warpItem = ItemManager.warp7;
                        break;
                    case 8:
                        warpItem = ItemManager.warp8;
                        break;
                    default:
                        player.sendMessage("Invalid warp number!");
                        return true;
                }
            }else if(itemType.equals("tablets")){
                ItemStack totemItem = null;
                switch (typeNum) {
                    case 1:
                        totemItem = ItemManager.totem1;
                        break;
                    case 2:
                        totemItem = ItemManager.totem2;
                        break;
                    case 3:
                        totemItem = ItemManager.totem3;
                        break;
                    case 4:
                        totemItem = ItemManager.totem4;
                        break;
                    case 5:
                        totemItem = ItemManager.totem5;
                        break;
                    case 6:
                        totemItem = ItemManager.totem6;
                        break;
                    case 7:
                        totemItem = ItemManager.totem7;
                        break;
                    case 8:
                        totemItem = ItemManager.totem8;
                        break;
                    default:
                        player.sendMessage("Invalid tablet number!");
                        return true;
                }
            }
    
            return false;
        }
    }
    
    the exact command i ran was "/giveitems warps 8"
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Is3kai Impressive this, never seen something acting up this bad.
    And it is the only plugin on the server? Usage in plugin.yml is different?
    Could be that it runs but the return false at the end sends back the command usage and you never use the items in your switch?
     
  3. Offline

    Is3kai

    It is the only plugin on the server, the plugin yml is identical, and the return, I am testing right now

    *Update*

    return true stops the /usage error, but the item is not given.
     
  4. Offline

    timtower Administrator Administrator Moderator

    There is no code to give the item either.
    So that is not weird.
     
  5. Offline

    Is3kai

    Oh my god i forgot the give item code.

    Everything works now, but I have one last question.

    I am trying to implement an item similar to a flashbang, would you by any chance know if its possible to white out a players screen?
     
    Last edited: Mar 6, 2024
  6. Offline

    timtower Administrator Administrator Moderator

    From a quick search: try blindness effect with night vision
     
  7. Offline

    Is3kai

    Thanks, that worked. I also may have broken my plugin fully. Could I get your input? Below I put a link to the latest log as a pastebin. I see where the issue is, but I fixed it but it still gives the same error.

    https://pastebin.com/n9EAsHx7

    It says the error is somewhere in my recipe manager, but i fixed the area it mentions and have no clue where it would be.

    here is the recipe manager code:

    Code:java
    1.  
    2. package org.smpmakers.dimensionsmpspigot.items;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.Material;
    6. import org.bukkit.NamespacedKey;
    7. import org.bukkit.inventory.ItemStack;
    8. import org.bukkit.inventory.ShapedRecipe;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class RecipieManager {
    12. private static JavaPlugin plugin = null;
    13. private static ItemStack item1 = ItemManager.material1;
    14. private static ItemStack item2 = ItemManager.material2;
    15. private static ItemStack item3 = ItemManager.material3;
    16. private static ItemStack item4 = ItemManager.material4;
    17. private static ItemStack item5 = ItemManager.material5;
    18. private static ItemStack item6 = ItemManager.material6;
    19. private static ItemStack item7 = ItemManager.material7;
    20. private static ItemStack item8 = ItemManager.material8;
    21. private static ItemStack item9 = ItemManager.material9;
    22. private static ItemStack result1 = ItemManager.totem1;
    23. private static ItemStack result2 = ItemManager.totem2;
    24. private static ItemStack result3 = ItemManager.totem3;
    25. private static ItemStack result4 = ItemManager.totem4;
    26. private static ItemStack result5 = ItemManager.totem5;
    27. private static ItemStack result6 = ItemManager.totem6;
    28. private static ItemStack result7 = ItemManager.totem7;
    29. private static ItemStack result8 = ItemManager.totem8;
    30.  
    31.  
    32.  
    33. public static void init(){
    34. registerRecipes();
    35. }
    36.  
    37. private static void registerRecipes() {
    38. // Create unique keys for one-time craftable recipes
    39. NamespacedKey uniqueKey1 = new NamespacedKey("dimensionsmpspigot", "unique_recipe_1");
    40. NamespacedKey uniqueKey2 = new NamespacedKey("dimensionsmpspigot", "unique_recipe_2");
    41. NamespacedKey uniqueKey3 = new NamespacedKey("dimensionsmpspigot", "unique_recipe_3");
    42. NamespacedKey uniqueKey4 = new NamespacedKey("dimensionsmpspigot", "unique_recipe_4");
    43. NamespacedKey uniqueKey5 = new NamespacedKey("dimensionsmpspigot", "unique_recipe_5");
    44. NamespacedKey uniqueKey6 = new NamespacedKey("dimensionsmpspigot", "unique_recipe_6");
    45. NamespacedKey uniqueKey7 = new NamespacedKey("dimensionsmpspigot", "unique_recipe_7");
    46. NamespacedKey uniqueKey8 = new NamespacedKey("dimensionsmpspigot", "unique_recipe_8");
    47.  
    48. // Create one-time craftable recipes
    49. ShapedRecipe uniqueRecipe1 = new ShapedRecipe(uniqueKey1, result1);
    50. uniqueRecipe1.shape("DDD", "DSD", "DDD");
    51. uniqueRecipe1.setIngredient('D', item1.getData());
    52. uniqueRecipe1.setIngredient('S', item9.getData());
    53. ShapedRecipe uniqueRecipe2 = new ShapedRecipe(uniqueKey2, result2);
    54. uniqueRecipe2.shape(" DDD ", " DSD ", "DDD");
    55. uniqueRecipe2.setIngredient('D', item2.getData());
    56. uniqueRecipe2.setIngredient('S', item9.getData());
    57. ShapedRecipe uniqueRecipe3 = new ShapedRecipe(uniqueKey3, result3);
    58. uniqueRecipe3.shape("DDD", "DSD", "DDD");
    59. uniqueRecipe3.setIngredient('D', item3.getData());
    60. uniqueRecipe3.setIngredient('S', item9.getData());
    61. ShapedRecipe uniqueRecipe4 = new ShapedRecipe(uniqueKey4, result4);
    62. uniqueRecipe4.shape("DDD", "DSD", "DDD");
    63. uniqueRecipe4.setIngredient('D', item4.getData());
    64. uniqueRecipe4.setIngredient('S', item9.getData());
    65. ShapedRecipe uniqueRecipe5 = new ShapedRecipe(uniqueKey5, result5);
    66. uniqueRecipe5.shape("DDD", "DSD", "DDD");
    67. uniqueRecipe5.setIngredient('D', item5.getData());
    68. uniqueRecipe5.setIngredient('S', item9.getData());
    69. ShapedRecipe uniqueRecipe6 = new ShapedRecipe(uniqueKey6, result6);
    70. uniqueRecipe6.shape("DDD", "DSD", "DDD");
    71. uniqueRecipe6.setIngredient('D', item6.getData());
    72. uniqueRecipe6.setIngredient('S', item9.getData());
    73. ShapedRecipe uniqueRecipe7 = new ShapedRecipe(uniqueKey7, result7);
    74. uniqueRecipe7.shape("DDD", "DSD", "DDD");
    75. uniqueRecipe7.setIngredient('D', item7.getData());
    76. uniqueRecipe7.setIngredient('S', item9.getData());
    77. ShapedRecipe uniqueRecipe8 = new ShapedRecipe(uniqueKey8, result8);
    78. uniqueRecipe8.shape("DDD", "DSD", "DDD");
    79. uniqueRecipe8.setIngredient('D', item8.getData());
    80. uniqueRecipe8.setIngredient('S', item9.getData());
    81.  
    82.  
    83.  
    84. // Repeat for the remaining unique recipes...
    85.  
    86. // Register the unique recipes
    87. Bukkit.addRecipe(uniqueRecipe1);
    88. Bukkit.addRecipe(uniqueRecipe2);
    89. Bukkit.addRecipe(uniqueRecipe3);
    90. Bukkit.addRecipe(uniqueRecipe4);
    91. Bukkit.addRecipe(uniqueRecipe5);
    92. Bukkit.addRecipe(uniqueRecipe6);
    93. Bukkit.addRecipe(uniqueRecipe7);
    94. Bukkit.addRecipe(uniqueRecipe8);
    95. // Repeat for the remaining unique recipes...
    96.  
    97. // Create recipes that can be crafted multiple times
    98. // Repeat for the remaining regular recipes...
    99. }
    100. }
    101.  
     
    Last edited by a moderator: Mar 7, 2024
  8. Offline

    timtower Administrator Administrator Moderator

    @Is3kai You have spaces around the recipe item
    " DDD " instead of "DDD"
     
  9. Offline

    Is3kai

    Thanks. Got one final question for you. Is it possible to use the Location to teleport to other worlds in a servers ftp? or do I need to somehow register them as dimensions?, cause whenever I try to code that, it gives me this error:

    Code:
    [19:47:21] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to dimensionsmpspigot v0.1-SNAPSHOT
    
    java.lang.IllegalArgumentException: location.world
    
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:143) ~[guava-32.1.2-jre.jar:?]
    
    at org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer.teleport(CraftPlayer.java:1329) ~[paper-1.20.4.jar:git-Paper-436]
    
    at org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer.teleport(CraftPlayer.java:1261) ~[paper-1.20.4.jar:git-Paper-436]
    
    at org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity.teleport(CraftEntity.java:226) ~[paper-1.20.4.jar:git-Paper-436]
    
    at org.smpmakers.dimensionsmpspigot.handlers.EventScript.teleportPlayer(EventScript.java:421) ~[dimensionsmpspigot-0.1-SNAPSHOT.jar:?]
    
    at org.smpmakers.dimensionsmpspigot.handlers.EventScript.activateWarp(EventScript.java:60) ~[dimensionsmpspigot-0.1-SNAPSHOT.jar:?]
    
    at org.smpmakers.dimensionsmpspigot.handlers.EventScript.onPlayerInteract(EventScript.java:50) ~[dimensionsmpspigot-0.1-SNAPSHOT.jar:?]
    
    at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor6.execute(Unknown Source) ~[?:?]
    
    at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:77) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
    
    at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:81) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:git-Paper-436]
    
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
    
    at io.papermc.paper.plugin.manager.PaperEventManager.callEvent(PaperEventManager.java:54) ~[paper-1.20.4.jar:git-Paper-436]
    
    at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.callEvent(PaperPluginManagerImpl.java:126) ~[paper-1.20.4.jar:git-Paper-436]
    
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:615) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
    
    at org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:593) ~[paper-1.20.4.jar:git-Paper-436]
    
    at net.minecraft.server.level.ServerPlayerGameMode.useItemOn(ServerPlayerGameMode.java:536) ~[?:?]
    
    at net.minecraft.server.network.ServerGamePacketListenerImpl.handleUseItemOn(ServerGamePacketListenerImpl.java:1935) ~[?:?]
    
    at net.minecraft.network.protocol.game.ServerboundUseItemOnPacket.handle(ServerboundUseItemOnPacket.java:37) ~[?:?]
    
    at net.minecraft.network.protocol.game.ServerboundUseItemOnPacket.a(ServerboundUseItemOnPacket.java:9) ~[?:?]
    
    at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$0(PacketUtils.java:54) ~[?:?]
    
    at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.20.4.jar:git-Paper-436]
    
    at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:153) ~[?:?]
    
    at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[?:?]
    
    at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1455) ~[paper-1.20.4.jar:git-Paper-436]
    
    at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:194) ~[paper-1.20.4.jar:git-Paper-436]
    
    at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
    
    at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1432) ~[paper-1.20.4.jar:git-Paper-436]
    
    at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1355) ~[paper-1.20.4.jar:git-Paper-436]
    
    at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
    
    at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1333) ~[paper-1.20.4.jar:git-Paper-436]
    
    at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1222) ~[paper-1.20.4.jar:git-Paper-436]
    
    at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:319) ~[paper-1.20.4.jar:git-Paper-436]
    
    at java.lang.Thread.run(Thread.java:833) ~[?:?]
    
     
    Last edited: Mar 8, 2024
  10. Offline

    KarimAKL

    @Is3kai The location you passed as an argument to the teleport method has no world; it is null. Make sure you load the world first using the WorldCreator#createWorld() method if it has not already been loaded.
     
  11. Offline

    KathleenCampos

    I think there are a few things worth checking:
    Make sure the GiveWarpItem class is in the correct package (org.smpmakers.dimensionsmp.commands) and contains the correct CommandExecutor import.
    Check the correct imports and ensure that all required classes (CommandSender, Player, ItemStack, etc.) are imported correctly from org.bukkit.
    Check out the onCommand method in the GiveWarpItem class. Make sure you are using the correct methods to send messages, for example player.sendMessage(Component.text("Your message")).
     
Thread Status:
Not open for further replies.

Share This Page