Anyone wnna help lol

Discussion in 'Spigot Plugin Development' started by Mhalllz, May 31, 2018.

  1. I'm kind of new to this and ive put together a plugin that semi works, the only thing that doesnt is my items dont go in the GUI could someone fix the code for me xd thx

    https://pastebin.com/2GAcALZq
     
  2. The ItemStack is nothing use something like this:
    Code (Text):
    ItemStack itemstack = new ItemStack(Material.DIAMOND);
     
  3. wouldent this set the material?

    Code (Text):
    if (mediaType != null)
                return;
            {
                boolean mediaTypeEnabled = getConfig().getBoolean(
                        "Enable" + mediaType);
                if (!mediaTypeEnabled) {
                    mediaType = new ItemStack(Material.REDSTONE_BLOCK, 1);
                    ItemMeta mooshroomMeta2 = mediaType.getItemMeta();
                    mooshroomMeta2.setDisplayName(ChatColor
                            .translateAlternateColorCodes('&', "&4" + mediaType
                                    + " Disabled!"));
                    mediaType.setItemMeta(mooshroomMeta2);

                    if (mediaTypeEnabled) {

                        mediaType = new ItemStack(Material.EMERALD_BLOCK, 1);
                        ItemMeta mediaTypeMeta1 = mediaType.getItemMeta();
                        mediaTypeMeta1.setDisplayName(ChatColor
                                .translateAlternateColorCodes('&', "&2" + mediaType
                                        + " Enabled!"));
                        mediaType.setItemMeta(mediaTypeMeta1);

                    }
                }

            }
        }
     
  4. That checks if mediatype is not null and tjen immediately returns therefore none of the code is executed
     
  5. lol i didnt realize I put that, i set it to this now would it work?


    Code (Text):
            if (mediaType != null) {
                boolean mediaTypeEnabled = getConfig().getBoolean(
                        "Enable" + mediaType);
                if (!mediaTypeEnabled) {
                    mediaType = new ItemStack(Material.REDSTONE_BLOCK, 1);
                    ItemMeta mooshroomMeta2 = mediaType.getItemMeta();
                    mooshroomMeta2.setDisplayName(ChatColor
                            .translateAlternateColorCodes('&', "&4" + mediaType
                                    + " Disabled!"));
                    mediaType.setItemMeta(mooshroomMeta2);

                    if (mediaTypeEnabled) {

                        mediaType = new ItemStack(Material.EMERALD_BLOCK, 1);
                        ItemMeta mediaTypeMeta1 = mediaType.getItemMeta();
                        mediaTypeMeta1.setDisplayName(ChatColor
                                .translateAlternateColorCodes('&', "&2" + mediaType
                                        + " Enabled!"));
                        mediaType.setItemMeta(mediaTypeMeta1);

                    }
                }
                return;
            }
        }
     
  6. did you try it?
     
    • Funny Funny x 1
  7. So I took a gander at your paste bin and wanted to let you know that I got lost. It's not very wise to put all your code into one file.

    Your main file should extend the JavaPlugin and have the onEnable and onDisable methods. I usually store a couple handy methods there and some variables. Think of this as an initialization point and a place to store data in memory.

    Your commands should be put in another class file that implements a CommandExecutor. You can then store all your logic for commands and put a nice clean this.getCommand("yadayada").setExecutor(new CommandsExecutor()); in the onEnable() method

    Your events should be put into another class file that implements a Listener. Within here you will put your logic and put a getServer().getPluginManager().registerEvents(new OnFished(), this); in the onEnable() method

    This should make code readability better by a large margin. You will also be thanking me later down the road when you take a break from the project and have to delve that 1136+ lined monstrosity.
     
    #7 John_Willikers, May 31, 2018
    Last edited: May 31, 2018
    • Agree Agree x 1
  8. Well said. This is something lots of people need to do.