Making a Fake GUI and Restricting Player Use

Discussion in 'Plugin Development' started by Virgoth098, Jul 9, 2013.

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

    Virgoth098

    I'm trying to make a "Shop" with a fake inventory screen, I know how to create the inventory, add an item, and display it to the player. But currently a player can take the items out of the inventory, and reopen the inventory, effectively duping them. I want to restrict the player from moving ANYTHING in their or the shop's inventory while it is open, besides click on it. How do i do this? Here is the code that I tried to do:
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. inventory = event.getPlayer().getServer().createInventory(null, 18, "ECShop");
    4. ItemStack item1 = new ItemStack(57, 1);
    5. inventory.addItem(item1);
    6. Player player = event.getPlayer();
    7. Action action = event.getAction();
    8. if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK && player.getItemInHand().getType() == Material.WRITTEN_BOOK) {
    9.  
    10. BookMeta meta = (BookMeta) player.getItemInHand().getItemMeta();
    11. if (meta.getTitle().equals(ChatColor.GREEN + "ECShop")) {
    12.  
    13. player.sendMessage("Coming soon!");
    14. player.closeInventory();
    15. player.openInventory(inventory);
    16.  
    17. }
    18.  
    19.  
    20. }
    21. }
    22.  
    23. @EventHandler
    24. public void onInventoryClickEvent(InventoryClickEvent event) {
    25. if (event.getInventory().equals("inventory")) {
    26. if(event.getCurrentItem().getType() == Material.DIAMOND_BLOCK){
    27. event.setCancelled(true);
    28. }
    29.  
    30. }
    31.  
    32. }

    Any help?
     
  2. Offline

    danslayerx

    Without actually reading your source (I know terrible), I would suggest cancelling the event (InventoryClickEvent).

    Be aware, there are ways to get round this which can cause duplication glitches left, centre and right.

    EDIT: And I read your source, oh snap I'm a fool.

    So what's the problem? Does it not stop you from taking out the diamond block?
     
Thread Status:
Not open for further replies.

Share This Page