One-Row Enderchests?

Discussion in 'Plugin Development' started by football70500, Jun 1, 2014.

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

    football70500

    How would code it so that if a player has a certain permission, when they open their enderchest, they only have one row to store things?
     
  2. Offline

    Konkz

    When player opens an ender chest open an inventory that you've created with 9 slots.
     
  3. Offline

    football70500

    Okay, so I created the custom inventory, now what event do I call to check when the player opens the enderchest?
     
  4. Offline

    Konkz

    Think what event gets called when player interacts with a block that you can check if its an ender chest.
     
  5. Offline

    football70500

    Just figured that out, how do I check to make sure that the block is an enderchest?
     
  6. Offline

    Konkz


    PHP:
    if(event.getBlock().getType().equals(Material.ENDER_CHEST)) {
    //open inv
    }
     
  7. Offline

    xYourFreindx

    Make sure to check and make sure the action is a right click. ^-^
     
  8. Offline

    football70500

    Alright cool. Now, I kinda want to be able to check if a player has a certain permission, it will open up whatever multiple of 9 rows the number in the permission is.

    How would I do this?

    I would have to change something up top at the ender inventory?
     
  9. Offline

    Konkz

    Code:
    oninteract
    if action is right click block
    if block is an ender chest
    if player has permission "myinv.open"
    open the inv you made before
     
  10. Offline

    badboysteee98

    Also you will have to make an HashMap or ArrayList to save the Stuff they put inside the inventory otherwise it's just like having a Trash Enderchest when items are placed in there it will disappear straight away
     
  11. Offline

    football70500

    Konkz badboysteee98 EDIT: whenever I open an enderchest, it just gives the normal amount

    Code:java
    1. import org.bukkit.Bukkit;
    2. import org.bukkit.Material;
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.block.Action;
    6. import org.bukkit.event.player.PlayerInteractEvent;
    7. import org.bukkit.inventory.Inventory;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Main extends JavaPlugin implements Listener{
    11.  
    12. public static Inventory enderone = Bukkit.createInventory(null, 9, "EnderChest");
    13. public static Inventory endertwo = Bukkit.createInventory(null, 18, "EnderChest");
    14. public static Inventory enderthree = Bukkit.createInventory(null, 27, "EnderChest");
    15. public static Inventory enderfour = Bukkit.createInventory(null, 36, "EnderChest");
    16. public static Inventory enderfive = Bukkit.createInventory(null, 45, "EnderChest");
    17. public static Inventory endersix = Bukkit.createInventory(null, 54, "EnderChest");
    18.  
    19. @Override
    20. public void onEnable(){
    21. getLogger().info("JumboChest has been enabled!");
    22. }
    23.  
    24. @Override
    25. public void onDisable(){
    26. getLogger().info("JumboChest has been disabled!");
    27. }
    28.  
    29. public void onOpen(PlayerInteractEvent e){
    30. Player player = e.getPlayer();
    31. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
    32. if(e.getClickedBlock().getType().equals(Material.ENDER_CHEST)){
    33. if(player.hasPermission("jc.ender.one")){
    34. player.openInventory(enderone);
    35. }
    36. if(player.hasPermission("jc.ender.two")){
    37. player.openInventory(endertwo);
    38. }
    39. if(player.hasPermission("jc.ender.three")){
    40. player.openInventory(enderthree);
    41. }
    42. if(player.hasPermission("jc.ender.four")){
    43. player.openInventory(enderfour);
    44. }
    45. if(player.hasPermission("jc.ender.five")){
    46. player.openInventory(enderfive);
    47. }
    48. if(player.hasPermission("jc.ender.six")){
    49. player.openInventory(endersix);
    50. }
    51. }
    52. }
    53. }
    54.  
    55. }
    56.  


    Konkz badboysteee98 EDIT: whenever I open an enderchest, it just gives the normal amount

    Code:java
    1. import org.bukkit.Bukkit;
    2. import org.bukkit.Material;
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.block.Action;
    6. import org.bukkit.event.player.PlayerInteractEvent;
    7. import org.bukkit.inventory.Inventory;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Main extends JavaPlugin implements Listener{
    11.  
    12. public static Inventory enderone = Bukkit.createInventory(null, 9, "EnderChest");
    13. public static Inventory endertwo = Bukkit.createInventory(null, 18, "EnderChest");
    14. public static Inventory enderthree = Bukkit.createInventory(null, 27, "EnderChest");
    15. public static Inventory enderfour = Bukkit.createInventory(null, 36, "EnderChest");
    16. public static Inventory enderfive = Bukkit.createInventory(null, 45, "EnderChest");
    17. public static Inventory endersix = Bukkit.createInventory(null, 54, "EnderChest");
    18.  
    19. @Override
    20. public void onEnable(){
    21. getLogger().info("JumboChest has been enabled!");
    22. }
    23.  
    24. @Override
    25. public void onDisable(){
    26. getLogger().info("JumboChest has been disabled!");
    27. }
    28.  
    29. public void onOpen(PlayerInteractEvent e){
    30. Player player = e.getPlayer();
    31. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
    32. if(e.getClickedBlock().getType().equals(Material.ENDER_CHEST)){
    33. if(player.hasPermission("jc.ender.one")){
    34. player.openInventory(enderone);
    35. }
    36. if(player.hasPermission("jc.ender.two")){
    37. player.openInventory(endertwo);
    38. }
    39. if(player.hasPermission("jc.ender.three")){
    40. player.openInventory(enderthree);
    41. }
    42. if(player.hasPermission("jc.ender.four")){
    43. player.openInventory(enderfour);
    44. }
    45. if(player.hasPermission("jc.ender.five")){
    46. player.openInventory(enderfive);
    47. }
    48. if(player.hasPermission("jc.ender.six")){
    49. player.openInventory(endersix);
    50. }
    51. }
    52. }
    53. }
    54.  
    55. }
    56.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 1, 2016
  12. Offline

    Konkz

    You never cancelled the event.
     
  13. Offline

    football70500


    Code:java
    1. public void onOpen(PlayerInteractEvent e){
    2. Player player = e.getPlayer();
    3. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
    4. if(e.getClickedBlock().getType().equals(Material.ENDER_CHEST)){
    5. if(player.hasPermission("jc.ender.one")){
    6. player.openInventory(enderone);
    7. }
    8. if(player.hasPermission("jc.ender.two")){
    9. player.openInventory(endertwo);
    10. }
    11. if(player.hasPermission("jc.ender.three")){
    12. player.openInventory(enderthree);
    13. }
    14. if(player.hasPermission("jc.ender.four")){
    15. player.openInventory(enderfour);
    16. }
    17. if(player.hasPermission("jc.ender.five")){
    18. player.openInventory(enderfive);
    19. }
    20. if(player.hasPermission("jc.ender.six")){
    21. player.openInventory(endersix);
    22. }
    23. }
    24. return;
    25. }
    26. }
    27.  
    28. Like that?


    Like that?
     
  14. Offline

    Konkz

    Still did not cancel the event.
     
  15. Offline

    football70500

    e.setCancelled()??
    Konkz
     
  16. Offline

    Konkz

    In the parameters it requires a boolean.
    event.setCancelled(true);

    Just put that after you check if the item is an ender chest.
     
  17. Offline

    football70500


    Code:java
    1. public void onOpen(PlayerInteractEvent e){
    2. Player player = e.getPlayer();
    3. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
    4. if(e.getClickedBlock().getType().equals(Material.ENDER_CHEST)){
    5. e.setCancelled(true);
    6. if(player.hasPermission("jc.ender.one")){
    7. player.openInventory(enderone);
    8. }
    9. if(player.hasPermission("jc.ender.two")){
    10. player.openInventory(endertwo);
    11. }
    12. if(player.hasPermission("jc.ender.three")){
    13. player.openInventory(enderthree);
    14. }
    15. if(player.hasPermission("jc.ender.four")){
    16. player.openInventory(enderfour);
    17. }
    18. if(player.hasPermission("jc.ender.five")){
    19. player.openInventory(enderfive);
    20. }
    21. if(player.hasPermission("jc.ender.six")){
    22. player.openInventory(endersix);
    23. }
    24. }
    25. }
    26. }


    Still nothing
     
  18. Offline

    AoH_Ruthless

    football70500
    You don't have the @EventHandler and you may have not registered your events.
     
  19. Offline

    football70500


    Code:java
    1. package me.cavasi.enderslot;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.Action;
    9. import org.bukkit.event.player.PlayerInteractEvent;
    10. import org.bukkit.inventory.Inventory;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Main extends JavaPlugin implements Listener{
    14. private Main plugin;
    15.  
    16. public Main(Main plugin)
    17. {
    18. this.plugin = plugin;
    19. }
    20.  
    21. public static Inventory enderone = Bukkit.createInventory(null, 9, "EnderChest");
    22. public static Inventory endertwo = Bukkit.createInventory(null, 18, "EnderChest");
    23. public static Inventory enderthree = Bukkit.createInventory(null, 27, "EnderChest");
    24. public static Inventory enderfour = Bukkit.createInventory(null, 36, "EnderChest");
    25. public static Inventory enderfive = Bukkit.createInventory(null, 45, "EnderChest");
    26. public static Inventory endersix = Bukkit.createInventory(null, 54, "EnderChest");
    27.  
    28. @Override
    29. public void onEnable(){
    30. getLogger().info("JumboChest has been enabled!");
    31. register();
    32. }
    33.  
    34. @Override
    35. public void onDisable(){
    36. getLogger().info("JumboChest has been disabled!");
    37. }
    38.  
    39. public void register(){
    40. getServer().getPluginManager().registerEvents(new Main(this), this);
    41. }
    42.  
    43. @EventHandler
    44. public void onOpen(PlayerInteractEvent e){
    45. Player player = e.getPlayer();
    46. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
    47. if(e.getClickedBlock().getType().equals(Material.ENDER_CHEST)){
    48. e.setCancelled(true);
    49. if(player.hasPermission("jc.ender.one")){
    50. player.openInventory(enderone);
    51. }
    52. if(player.hasPermission("jc.ender.two")){
    53. player.openInventory(endertwo);
    54. }
    55. if(player.hasPermission("jc.ender.three")){
    56. player.openInventory(enderthree);
    57. }
    58. if(player.hasPermission("jc.ender.four")){
    59. player.openInventory(enderfour);
    60. }
    61. if(player.hasPermission("jc.ender.five")){
    62. player.openInventory(enderfive);
    63. }
    64. if(player.hasPermission("jc.ender.six")){
    65. player.openInventory(endersix);
    66. }
    67. }
    68. }
    69. }
    70.  
    71. }
    72.  


    Still nope
     
  20. Offline

    itzrobotix


    Code:java
    1. @Override
    2. public void onEnable(){
    3. getLogger().info("JumboChest has been enabled!");
    4. Bukkit.getPluginManager.registerEvents(this, this);
    5. }
     
  21. Offline

    football70500

    I have that in my register method.
     
  22. Offline

    AoH_Ruthless

    football70500
    No, your register method is incorrect. You are calling a new instance of your main class. Replace new Main(this) with just 'this'
     
  23. Offline

    football70500

    getPluginManager cannot be resolved or is not a field
     
  24. Offline

    FisheyLP

    you need a () after getPluginManager, like this:
    Code:
     @Override
    public void onEnable(){
    Bukkit.getPluginManager().registerEvents(this, this);
    }
    and you don't really need to print out that your plugin is enabled or disabled, bukkit does that by itself ;)
     
    itzrobotix and AoH_Ruthless like this.
  25. Offline

    itzrobotix

    My bad. #BlameMyPhone
     
  26. Offline

    MayoDwarf

    Also guys this will need a saving mechanism. He is creating inventories and they are not being saved at all. This will requiring saving the inventories to a config or file to keep track of player's private custom ender chests.
     
  27. Offline

    zombiekiller753

    I hate to be the buzzkill here, but football70500 you should take a look at the Bukkit plugin tutorial. From what I see on this thread it's mostly people feeding you little bits of code that, had you read about Java and Bukkit, should not have been an issue

    EDIT:
    MayoDwarf
    Material is an Enum. #equals() works on enums
     
  28. Offline

    MayoDwarf

    zombiekiller753 Hadn't known Material is an Enum. My bad. Nonetheless this requires a lot more work than just creating these private inventories.
     
  29. Offline

    football70500

    Still doesn't work

    Code:java
    1. public class Main extends JavaPlugin implements Listener{
    2. private Main plugin;
    3.  
    4. public Main(Main plugin)
    5. {
    6. this.plugin = plugin;
    7. }
    8.  
    9. public static Inventory enderone = Bukkit.createInventory(null, 9, "EnderChest");
    10. public static Inventory endertwo = Bukkit.createInventory(null, 18, "EnderChest");
    11. public static Inventory enderthree = Bukkit.createInventory(null, 27, "EnderChest");
    12. public static Inventory enderfour = Bukkit.createInventory(null, 36, "EnderChest");
    13. public static Inventory enderfive = Bukkit.createInventory(null, 45, "EnderChest");
    14. public static Inventory endersix = Bukkit.createInventory(null, 54, "EnderChest");
    15.  
    16. @Override
    17. public void onEnable(){
    18. getLogger().info("JumboChest has been enabled!");
    19. Bukkit.getPluginManager().registerEvents(this, this);
    20. }
    21.  
    22. @Override
    23. public void onDisable(){
    24. getLogger().info("JumboChest has been disabled!");
    25. }
    26. @EventHandler
    27. public void onOpen(PlayerInteractEvent e){
    28. Player player = e.getPlayer();
    29. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
    30. if(e.getClickedBlock().getType().equals(Material.ENDER_CHEST)){
    31. e.setCancelled(true);
    32. if(player.hasPermission("jc.ender.one")){
    33. player.openInventory(enderone);
    34. }
    35. if(player.hasPermission("jc.ender.two")){
    36. player.openInventory(endertwo);
    37. }
    38. if(player.hasPermission("jc.ender.three")){
    39. player.openInventory(enderthree);
    40. }
    41. if(player.hasPermission("jc.ender.four")){
    42. player.openInventory(enderfour);
    43. }
    44. if(player.hasPermission("jc.ender.five")){
    45. player.openInventory(enderfive);
    46. }
    47. if(player.hasPermission("jc.ender.six")){
    48. player.openInventory(endersix);
    49. }
    50. }
    51. }
    52. }
    53.  
    54. }
    55.  
     
  30. Offline

    MayoDwarf

    football70500 Is your plugin.yml set up correctly? Also don't mean to be rude, but if the plugin.yml isn't set up then zombiekiller753 is right about you needing to take a look at how to actually construct plugins.
     
Thread Status:
Not open for further replies.

Share This Page