Solved Plugin help

Discussion in 'Plugin Help/Development/Requests' started by seanliam2000, Mar 8, 2015.

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

    seanliam2000

    So I am kind of new to this making plugin thing and I have a custom inventory testing thing but the problem isn't the plugin it is getting it onto my server I export it and everything reload my server and it doesn't appear in the plugins list (/pl) Any help is appreciated as to why it isn't loading :) If you need any additional info please post asking what you need thanks

    [​IMG]
    [​IMG]
     
  2. Offline

    Skionz

    The class you specified as your main class doesn't exist. Also, use naming conventions.
     
  3. Online

    timtower Administrator Administrator Moderator

    @seanliam2000 Please use this for code: [syntax=java] < code here > [/syntax], [code] < yml here > [/code] for the plugin.yml
    And please post your server log using http://pastebin.com
     
  4. Your class is called Main. In your plugin.yml you called your class main. It is case sensitive.
     
  5. Offline

    seanliam2000

    Yeah it doesn't work when it was Main either I was just trying to get it to work

    OkayI got it to register because I accidentally tabbed instead of doing 4 spaces lol.... Im sorry guys
     
    Last edited by a moderator: Mar 8, 2015
  6. @seanliam2000 If you are using Notepad++ (which you should be) You can edit that to replace tabs with spaces. Go to settings -> preferences -> Tab Settings -> Tick "Replace by space"

    EDIT: I looked at the screenshots and your not. I recommend using Notepad++ as it is the best text editor out there.
     
  7. Offline

    seanliam2000

    I got it to load the plugin but it doesnt register a command and I dont get any console errors.
    http://pastebin.com/52SghJfT

    Plugin
    Code:java
    1.  
    2. package me.seanliam2000.ParticleGUI;
    3.  
    4. import java.util.Arrays;
    5. import java.util.List;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.Material;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.inventory.Inventory;
    13. import org.bukkit.inventory.ItemStack;
    14. import org.bukkit.inventory.meta.ItemMeta;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17. public class Main extends JavaPlugin {
    18.  
    19. private Inventory inv;
    20.  
    21. public void onEnable() {
    22. inv = Bukkit.createInventory(null, 18, "Title");
    23. inv.addItem(make(Material.WOOL, 1, 0, "Name", Arrays.asList("Line 1", "Line 2")));
    24. }
    25.  
    26. private ItemStack make(Material material, int amount, int shrt, String displayName, List<String> lore) {
    27. ItemStack item = new ItemStack(material, amount, (short) shrt);
    28. ItemMeta meta = item.getItemMeta();
    29. meta.setDisplayName(displayName);
    30. meta.setLore(lore);
    31. item.setItemMeta(meta);
    32. return item;
    33. }
    34.  
    35. @Override
    36. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    37. if (cmd.getName().equalsIgnoreCase("test")) {
    38. if (!(sender instanceof Player)) {
    39. sender.sendMessage("This command can only be run by a player.");
    40. } else {
    41. Player player = (Player) sender;
    42. player.openInventory(inv);
    43. player.sendMessage("hi");
    44. }
    45. return true;
    46. }
    47. return false;
    48. }
    49. }
    50.  
    51.  

    Plugin.yml
    Code:
    name: ParticleGUI
    main: me.seanliam2000.ParticleGUI.Main
    version: 1.0
    author: seanliam2000
    command:
        test:
            description: test
     
     
  8. Offline

    seanliam2000

    Yes I have notepad ++ it was just a derp on my part, I am now asking for assistance on my code as to why the command isn't working :)
     
  9. @seanliam2000
    Have you tried to debug? I just tested the code because I could not see anything wrong and it worked perfectly.
    [​IMG]
     
    seanliam2000 likes this.
  10. Offline

    seanliam2000

    Oh good to know it works :D Something must be wrong with my server. Know i know it works i don't have to continually fiddle with the code lol. Do you think I could have set my project up wrong?


    *Sigh*
    It really doesnt want to work for me lol...

    EDIT: I remade the project, put in a new jar file and updated my server and it still doesnt work :/ Could you send me like a dropbox link to the file you used and see if it works on my server pls?
     
    Last edited: Mar 10, 2015
  11. @seanliam2000
    Sure, no problem. What version are you using though?
     
    seanliam2000 likes this.
  12. Offline

    seanliam2000

    I am using a 1.8 spigot build
     
  13. seanliam2000 likes this.
  14. Offline

    seanliam2000

    Yeh I plopped that in there to see if it was just a broken inventory

    EDIT: It works, I must be doing something in eclipse wrong..... (Sorry for so many questions still learning :) )

    EDIT: *Sigh* I am the dumbest person alive, I forgot to put an s on commands i had command.....

    Could I ask how i could make the item untakeable and does something when you click it? Thanks :)
     
    Last edited by a moderator: Mar 11, 2015
  15. seanliam2000 likes this.
  16. Offline

    seanliam2000

    So I changed it up a bit following a tutorial but something went wrong the command executes but when the inventory is about to open an internal error occures:
    Main class:
    Code:java
    1.  
    2. package me.seanliam2000.ParticleGUI;
    3.  
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Main extends JavaPlugin {
    11. public static Main instance;
    12. @Override
    13. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    14. if (cmd.getName().equalsIgnoreCase("particlegui")) {
    15. if (!(sender instanceof Player)) {
    16. sender.sendMessage("This command can only be run by a player.");
    17. } else {
    18. Player player = (Player) sender;
    19. player.sendMessage("hi");
    20. ParticleMenu.open(player);
    21. }
    22. return true;
    23. }
    24. return false;
    25. }
    26. public static Main getInstance(){
    27. return instance;
    28. }
    29. }
    30.  
    31.  

    Particlemenu class:
    Code:java
    1.  
    2. package me.seanliam2000.ParticleGUI;
    3.  
    4. import me.seanliam2000.ParticleGUI.utils.IconMenu;
    5. import me.seanliam2000.ParticleGUI.utils.IconMenu.OptionClickEvent;
    6.  
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Material;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.inventory.ItemStack;
    11.  
    12. public class ParticleMenu {
    13. private static IconMenu menu = new IconMenu("Particle List", 54, new IconMenu.OptionClickEventHandler() {
    14.  
    15. @Override
    16. public void onOptionClick(OptionClickEvent event) {
    17. Player player = event.getPlayer();
    18. String name = event.getName().toLowerCase();
    19. if (name.equals(ChatColor.RED + "flame")) {
    20. player.sendMessage("It works!");
    21. }
    22. }
    23. }, Main.getInstance());
    24. public static void open(Player player){
    25. fillMenu();
    26. menu.open(player);
    27. }
    28. private static void fillMenu(){
    29. menu.setOption(16, new ItemStack(Material.FLINT_AND_STEEL), ChatColor.RED + "Flame", "Flame particle bought in store");
    30. menu.setOption(17, new ItemStack(Material.LAVA_BUCKET), ChatColor.RED + "Lave", "Lava particle bought in store");
    31. }
    32. }
    33.  

    What I am using to make the inv:
    Code:java
    1.  
    2. package me.seanliam2000.ParticleGUI.utils;
    3.  
    4. import java.util.Arrays;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.EventPriority;
    10. import org.bukkit.event.HandlerList;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.inventory.ClickType;
    13. import org.bukkit.event.inventory.InventoryClickEvent;
    14. import org.bukkit.inventory.Inventory;
    15. import org.bukkit.inventory.ItemStack;
    16. import org.bukkit.inventory.meta.ItemMeta;
    17. import org.bukkit.plugin.Plugin;
    18.  
    19. public class IconMenu implements Listener {
    20.  
    21. private String name;
    22. private int size;
    23. private OptionClickEventHandler handler;
    24. private Plugin plugin;
    25. private Player player;
    26.  
    27. private String[] optionNames;
    28. private ItemStack[] optionIcons;
    29.  
    30. public IconMenu(String name, int size, OptionClickEventHandler handler, Plugin plugin) {
    31. this.name = name;
    32. this.size = size;
    33. this.handler = handler;
    34. this.plugin = plugin;
    35. this.optionNames = new String[size];
    36. this.optionIcons = new ItemStack[size];
    37. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    38. }
    39.  
    40. public IconMenu setOption(int position, ItemStack icon, String name, String... info) {
    41. optionNames[position] = name;
    42. optionIcons[position] = setItemNameAndLore(icon, name, info);
    43. return this;
    44. }
    45.  
    46. public void setSpecificTo(Player player) {
    47. this.player = player;
    48. }
    49.  
    50. public boolean isSpecific() {
    51. return player != null;
    52. }
    53.  
    54. public void open(Player player) {
    55. Inventory inventory = Bukkit.createInventory(player, size, name);
    56. for (int i = 0; i < optionIcons.length; i++) {
    57. if (optionIcons[I] != null) {
    58. inventory.setItem(i, optionIcons[I]);
    59. }
    60. }
    61. player.openInventory(inventory);
    62. }
    63.  
    64. public void destroy() {
    65. HandlerList.unregisterAll(this);
    66. handler = null;
    67. plugin = null;
    68. optionNames = null;
    69. optionIcons = null;
    70. }
    71. @EventHandler(priority = EventPriority.HIGHEST)
    72. void onInventoryClick(InventoryClickEvent event) {
    73. if (event.getInventory().getTitle().equals(name) && (player == null || event.getWhoClicked() == player)) {
    74. event.setCancelled(true);
    75. if (event.getClick() != ClickType.LEFT)
    76. return;
    77. int slot = event.getRawSlot();
    78. if (slot >= 0 && slot < size && optionNames[slot] != null) {
    79. Plugin plugin = this.plugin;
    80. OptionClickEvent e = new OptionClickEvent((Player) event.getWhoClicked(), slot, optionNames[slot], optionIcons[slot]);
    81. handler.onOptionClick(e);
    82. ((Player) event.getWhoClicked()).updateInventory();
    83. if (e.willClose()) {
    84. final Player p = (Player) event.getWhoClicked();
    85. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    86. public void run() {
    87. p.closeInventory();
    88. }
    89. });
    90. }
    91. if (e.willDestroy()) {
    92. destroy();
    93. }
    94. }
    95. }
    96. }
    97.  
    98. public interface OptionClickEventHandler {
    99. public void onOptionClick(OptionClickEvent event);
    100. }
    101.  
    102. public class OptionClickEvent {
    103. private Player player;
    104. private int position;
    105. private String name;
    106. private boolean close;
    107. private boolean destroy;
    108. private ItemStack item;
    109.  
    110. public OptionClickEvent(Player player, int position, String name, ItemStack item) {
    111. this.player = player;
    112. this.position = position;
    113. this.name = name;
    114. this.close = true;
    115. this.destroy = false;
    116. this.item = item;
    117. }
    118.  
    119. public Player getPlayer() {
    120. return player;
    121. }
    122.  
    123. public int getPosition() {
    124. return position;
    125. }
    126.  
    127. public String getName() {
    128. return name;
    129. }
    130.  
    131. public boolean willClose() {
    132. return close;
    133. }
    134.  
    135. public boolean willDestroy() {
    136. return destroy;
    137. }
    138.  
    139. public void setWillClose(boolean close) {
    140. this.close = close;
    141. }
    142.  
    143. public void setWillDestroy(boolean destroy) {
    144. this.destroy = destroy;
    145. }
    146.  
    147. public ItemStack getItem() {
    148. return item;
    149. }
    150. }
    151.  
    152. private ItemStack setItemNameAndLore(ItemStack item, String name, String[] lore) {
    153. ItemMeta im = item.getItemMeta();
    154. im.setDisplayName(name);
    155. im.setLore(Arrays.asList(lore));
    156. item.setItemMeta(im);
    157. return item;
    158. }
    159. }
    160. [/I][/I]

    plugin yml:
    Code:
    name: ParticleGUI
    main: me.seanliam2000.ParticleGUI.Main
    version: 1.0
    author: seanliam2000
    commands:
        particlegui:
            description: test
    
    Error when i type command:
    http://pastebin.com/RzNR5e5P
     
  17. Offline

    seanliam2000

  18. Offline

    seanliam2000

    It is fixed if anyone was wondering(I know no one cares lol)
     
  19. Offline

    MCMatters

    @seanliam2000 You can't use the Inventory class until the server is enabled. And the classes get enabled before the Inventory class.
     
Thread Status:
Not open for further replies.

Share This Page