Casting Pugin

Discussion in 'Plugin Development' started by hi_guy_5, Feb 13, 2014.

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

    hi_guy_5

    i need to use the getConfig
    i know this is a noob question but this isn't my main class how would i getConfig() here?
    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent e){
    3. final Player player = (Player) e.getWhoClicked();
    4.  
    5. if (!(e.getInventory().getName().equalsIgnoreCase(inv.getName()))) return;
    6. if(e.getCurrentItem() == null) return;
    7.  
    8.  
    9.  
    10. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Launch Firework")){//FIREWORK!
    11. e.setCancelled(true);
    12. player.closeInventory();
    13. player.chat("/donationfirework");
    14.  
    15. }
     
  2. Offline

    Jakeob22

    You just need to do <NameOfYourMainClass>.getConfig();

    :)
     
  3. Offline

    xTigerRebornx

    hi_guy_5 Pass it through the class you want it in's constructor
     
  4. Offline

    Tirelessly

    xTigerRebornx You do know that the second link in your signature is satire, right?
     
  5. Offline

    hi_guy_5

    its not working I'm probably doing it wrong....
    Code:java
    1. if (e.getCurrentItem().getItemMeta().getDisplayName().contains(MenuInv.getConfig().getString(""))){
     
  6. Offline

    xTigerRebornx

    hi_guy_5 Can I see your full class?
     
  7. Offline

    hi_guy_5

    xTigerRebornx
    Here it is
    Code:java
    1. public class Menu implements Listener{
    2.  
    3. private Inventory inv;
    4. private ItemStack f, sj, st, ft, dk, c1, c2, c3, c4;
    5.  
    6. public Menu(Plugin p) {
    7. inv = Bukkit.getServer().createInventory(null, 9,ChatColor.DARK_RED + "Master" +ChatColor.GREEN +"Kraft"+ChatColor.BLUE +" DonatorMenu" );
    8.  
    9.  
    10. f = createItem(DyeColor.BLUE, ChatColor.BLUE + "Launch Firework");
    11. sj = createItem(DyeColor.RED, ChatColor.RED + "SuperJump");
    12. st = createItem(DyeColor.YELLOW, ChatColor.YELLOW + "SmokeTrail");
    13. ft = createItem(DyeColor.ORANGE, ChatColor.GOLD + "FireTrail");
    14. dk = createItem(DyeColor.PURPLE, ChatColor.DARK_PURPLE + "Kit");
    15. c1 = createItem(DyeColor.LIGHT_BLUE, ChatColor.WHITE + p.getConfig().getString("custom block1 name"));
    16. c2 = createItem(DyeColor.LIGHT_BLUE, ChatColor.WHITE + p.getConfig().getString("custom block1 name"));
    17. c3 = createItem(DyeColor.LIGHT_BLUE, ChatColor.WHITE + p.getConfig().getString("custom block1 name"));
    18. c4 = createItem(DyeColor.LIGHT_BLUE, ChatColor.WHITE + p.getConfig().getString("custom block1 name"));
    19. inv.setItem(0, f);
    20. inv.setItem(1, sj);
    21. inv.setItem(2, st);
    22. inv.setItem(3, ft);
    23. inv.setItem(4, dk);
    24. inv.setItem(5, c1);
    25. inv.setItem(6, c2);
    26. inv.setItem(7, c3);
    27. inv.setItem(8, c4);
    28.  
    29.  
    30. Bukkit.getServer().getPluginManager().registerEvents(this, p);
    31. }
    32.  
    33.  
    34. private ItemStack createItem(DyeColor dc, String name){
    35. ItemStack i = new Wool(dc).toItemStack(1);
    36. ItemMeta im = i.getItemMeta();
    37. im.setDisplayName(name);
    38. im.setLore(Arrays.asList( ChatColor.AQUA + "Click To Do This"));
    39. i.setItemMeta(im);
    40. return i;
    41. }
    42.  
    43. public void show(Player p) {
    44. p.openInventory(inv);
    45.  
    46.  
    47. }
    48.  
    49.  
    50. @EventHandler
    51. public void onInventoryClick(InventoryClickEvent e){
    52. final Player player = (Player) e.getWhoClicked();
    53.  
    54. if (!(e.getInventory().getName().equalsIgnoreCase(inv.getName()))) return;
    55. if(e.getCurrentItem() == null) return;
    56.  
    57.  
    58.  
    59. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Launch Firework")){//FIREWORK!
    60. e.setCancelled(true);
    61. player.closeInventory();
    62. player.chat("/donationfirework");
    63.  
    64. }
    65.  
    66.  
    67. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("SuperJump")){
    68. e.setCancelled(true);
    69. player.closeInventory();
    70. player.chat("/donationjump");
    71.  
    72. }
    73. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("SmokeTrail")){
    74. e.setCancelled(true);
    75. player.closeInventory();
    76. player.chat("/donationsmoke");
    77.  
    78. }
    79. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("FireTrail")){
    80. player.closeInventory();
    81. e.setCancelled(true);
    82. player.chat("/donationfire");
    83.  
    84. }
    85. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Kit")){
    86. e.setCancelled(true);
    87. player.closeInventory();
    88. player.chat("/donationkit");
    89.  
    90. }
    91. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("FactionHome")){
    92. e.setCancelled(true);
    93. player.closeInventory();
    94. player.chat("/f home");
    95.  
    96. }
    97. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Nothing")){
    98. e.setCancelled(true);
    99. player.closeInventory();
    100. player.sendMessage(ChatColor.RED + "This Block Dose Not Do Anything Yet!");
    101. }
    102. if (e.getCurrentItem().getItemMeta().getDisplayName().contains(MenuInv.getConfig().getString(""))){
    103. e.setCancelled(true);
    104. player.closeInventory();
    105. player.sendMessage(ChatColor.RED + "This Block Dose Not Do Anything Yet!");
    106. }
    107. }
    108. }
    109.  
     
  8. Offline

    Garris0n

    It's satire, but it makes a good point. I could easily manipulate a poll to make it appear that 1/5th of Americans believe Obama is a cactus.
     
  9. Offline

    xTigerRebornx

    hi_guy_5 For your constructor, pass in MenuInv (I am guessing this is your main class) and store it in a variable inside the listener
    I.E.
    Code:
    MenuInv pl;
     
    public MyListener(MenuInv pl){
    this.pl = pl;
    }
    This would allow MyListener access to everything in pl when given a valid instance, so you can use pl.getConfig() to access your main config
     
  10. Offline

    hi_guy_5

    @ xTigerRebornx
    Is This What You Said? (just Checkin)
    Code:java
    1. MenuInv pl;
    2. @EventHandler
    3. public void onInventoryClick(InventoryClickEvent e, MenuInv pl){
    4.  
    5. this.pl = pl;
     
Thread Status:
Not open for further replies.

Share This Page