[Snippet] Create a [Free] Sign

Discussion in 'Resources' started by FisheyLP, May 8, 2014.

Thread Status:
Not open for further replies.
  1. This a tutorial which shows you how to make these [Free]-signs like in essentials:
    Code:java
    1. @EventHandler
    2. public void onSignCreate(SignChangeEvent e) {
    3. if (e.getLine(0).equalsIgnoreCase("[Free]") && !e.getLine(1).isEmpty()) {
    4. e.setLine(0, "§1[Free]");
    5. }
    6. }
    7.  
    8. @EventHandler
    9. public void onSignClick(PlayerInteractEvent e) {
    10. Player p = e.getPlayer();
    11. if (e.getAction()==Action.RIGHT_CLICK_BLOCK) {
    12. if (e.getClickedBlock().getType() == Material.WALL_SIGN ||
    13. e.getClickedBlock().getType() == Material.SIGN_POST ) {
    14. Sign s = (Sign) e.getClickedBlock().getState();
    15. if (s.getLine(0).equals("§1[Free]")) {
    16. try {
    17. int item = Integer.parseInt(s.getLine(1));
    18.  
    19. Inventory inv = Bukkit.createInventory(null, 27, "§1Free Stuff");
    20. for (int slot = 0; slot < inv.getSize(); slot++) {
    21. inv.setItem(slot, new ItemStack(item, 64));
    22. }
    23. p.openInventory(inv);
    24. } catch (Exception ex) {
    25. }
    26. }
    27. }
    28. }

    have fun :)
     
  2. Offline

    HungerCraftNL

    It's not really a tutorial but ok, maybe add something to check or the ID is really a existing item ID?
     
  3. Offline

    SoThatsIt

    FisheyLP change the title to [Snippet], this isnt a tutorial, its a snippet of code that people can use. Also fix the formatting of the code so we can read it :)
     
  4. Offline

    DoctorDark

    Few things I noticed:
    • You didn't check if the clicked block was null.
    You could have just checked if (e.getClickedBlock instanceof Sign) instead of checking all the sign states.
     
  5. Offline

    SoThatsIt

    He checks that the action is right click block which means that the right clicked block will not be null.
     
Thread Status:
Not open for further replies.

Share This Page