Commands Broken?

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

  1. Offline


    Sure. Here is the image:


    and here is the 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 {
        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;
            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
                ItemStack warpItem;
                switch (typeNum) {
                    case 1:
                        warpItem = ItemManager.warp1;
                    case 2:
                        warpItem = ItemManager.warp2;
                    case 3:
                        warpItem = ItemManager.warp3;
                    case 4:
                        warpItem = ItemManager.warp4;
                    case 5:
                        warpItem = ItemManager.warp5;
                    case 6:
                        warpItem = ItemManager.warp6;
                    case 7:
                        warpItem = ItemManager.warp7;
                    case 8:
                        warpItem = ItemManager.warp8;
                        player.sendMessage("Invalid warp number!");
                        return true;
            }else if(itemType.equals("tablets")){
                ItemStack totemItem = null;
                switch (typeNum) {
                    case 1:
                        totemItem = ItemManager.totem1;
                    case 2:
                        totemItem = ItemManager.totem2;
                    case 3:
                        totemItem = ItemManager.totem3;
                    case 4:
                        totemItem = ItemManager.totem4;
                    case 5:
                        totemItem = ItemManager.totem5;
                    case 6:
                        totemItem = ItemManager.totem6;
                    case 7:
                        totemItem = ItemManager.totem7;
                    case 8:
                        totemItem = ItemManager.totem8;
                        player.sendMessage("Invalid tablet number!");
                        return true;
            return false;
    the exact command i ran was "/giveitems warps 8"
  2. Online

    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


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


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

    timtower Administrator Administrator Moderator

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


    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. Online

    timtower Administrator Administrator Moderator

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


    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.

    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:

    2. package org.smpmakers.dimensionsmpspigot.items;
    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;
    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;
    33. public static void init(){
    34. registerRecipes();
    35. }
    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");
    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());
    84. // Repeat for the remaining unique recipes...
    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...
    97. // Create recipes that can be crafted multiple times
    98. // Repeat for the remaining regular recipes...
    99. }
    100. }
    Last edited by a moderator: Mar 7, 2024
  8. Online

    timtower Administrator Administrator Moderator

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


    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:

    [19:47:21] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to dimensionsmpspigot v0.1-SNAPSHOT
    at ~[guava-32.1.2-jre.jar:?]
    at org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer.teleport( ~[paper-1.20.4.jar:git-Paper-436]
    at org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer.teleport( ~[paper-1.20.4.jar:git-Paper-436]
    at org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity.teleport( ~[paper-1.20.4.jar:git-Paper-436]
    at org.smpmakers.dimensionsmpspigot.handlers.EventScript.teleportPlayer( ~[dimensionsmpspigot-0.1-SNAPSHOT.jar:?]
    at org.smpmakers.dimensionsmpspigot.handlers.EventScript.activateWarp( ~[dimensionsmpspigot-0.1-SNAPSHOT.jar:?]
    at org.smpmakers.dimensionsmpspigot.handlers.EventScript.onPlayerInteract( ~[dimensionsmpspigot-0.1-SNAPSHOT.jar:?]
    at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor6.execute(Unknown Source) ~[?:?]
    at org.bukkit.plugin.EventExecutor$2.execute( ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
    at co.aikar.timings.TimedEventExecutor.execute( ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:git-Paper-436]
    at org.bukkit.plugin.RegisteredListener.callEvent( ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
    at io.papermc.paper.plugin.manager.PaperEventManager.callEvent( ~[paper-1.20.4.jar:git-Paper-436]
    at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.callEvent( ~[paper-1.20.4.jar:git-Paper-436]
    at org.bukkit.plugin.SimplePluginManager.callEvent( ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory.callPlayerInteractEvent( ~[paper-1.20.4.jar:git-Paper-436]
    at net.minecraft.server.level.ServerPlayerGameMode.useItemOn( ~[?:?]
    at ~[?:?]
    at ~[?:?]
    at ~[?:?]
    at$ensureRunningOnSameThread$0( ~[?:?]
    at ~[paper-1.20.4.jar:git-Paper-436]
    at net.minecraft.util.thread.BlockableEventLoop.doRunTask( ~[?:?]
    at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask( ~[?:?]
    at net.minecraft.server.MinecraftServer.doRunTask( ~[paper-1.20.4.jar:git-Paper-436]
    at net.minecraft.server.MinecraftServer.d( ~[paper-1.20.4.jar:git-Paper-436]
    at net.minecraft.util.thread.BlockableEventLoop.pollTask( ~[?:?]
    at net.minecraft.server.MinecraftServer.pollTaskInternal( ~[paper-1.20.4.jar:git-Paper-436]
    at net.minecraft.server.MinecraftServer.pollTask( ~[paper-1.20.4.jar:git-Paper-436]
    at net.minecraft.util.thread.BlockableEventLoop.managedBlock( ~[?:?]
    at net.minecraft.server.MinecraftServer.waitUntilNextTick( ~[paper-1.20.4.jar:git-Paper-436]
    at net.minecraft.server.MinecraftServer.runServer( ~[paper-1.20.4.jar:git-Paper-436]
    at net.minecraft.server.MinecraftServer.lambda$spin$0( ~[paper-1.20.4.jar:git-Paper-436]
    at ~[?:?]
    Last edited: Mar 8, 2024
  10. Offline


    @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


    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")).

Share This Page