Need Help with my SignEvent

Discussion in 'Plugin Development' started by JeykoExample, Aug 10, 2014.

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

    JeykoExample

    1.7.2
     
  2. Offline

    CullanP


    Are you sure? It says 1.6.4
     
  3. Offline

    Necrodoom

    JeykoExample paste full class again.
    CullanP learning how to solve an issue is the best way to solve an issue.
    Also, look at the build number/NMS.
     
  4. Offline

    JeykoExample

    Class:
    PHP:
    package de.glorymc.freeforall;

    import org.bukkit.Bukkit;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.World;
    import org.bukkit.block.Sign;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    public class 
    SignEvent implements Listener{

        
         @
    EventHandler
         
    public void onSignPlaceEvent1(SignChangeEvent e)
         {
            if (!
    e.getPlayer().isOp()) {
              return;
            }
           
    String s e.getLine(0);
           if (!
    s.equalsIgnoreCase("[freeforall]")) {
             return;
           }
           
    e.setLine(0"§e§l-----------");
                 
    e.setLine(1"§aFreeForAll 1");
                 
    e.setLine(2"§bSurv. Games 4");
                 
    e.setLine(3"§e§l-----------");
         }
         
        @
    EventHandler
        
    public void onPlayerInteract(PlayerInteractEvent event) {
            
    Sign mysign = (Signevent.getClickedBlock().getState();
            if(
    event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                if(
    event.getClickedBlock().equals(Material.SIGN) || event.getClickedBlock().equals(Material.SIGN_POST)) {
                    if (
    mysign.getLine(1).contains("FreeForAll 1")) {
                    
    Player player event.getPlayer();
           
                    
    World w Bukkit.getWorld("FreeForAll");
                    
    Location loc w.getSpawnLocation();
                    
                    
    player.teleport(loc);

                    
    player.playSound(player.getLocation(), Sound.NOTE_PIANO11); 
                    
                    
    player.sendMessage("§r");
                    
                    
    player.sendMessage("§aFreeForAll Alpha developed by JeykoPlays.");
                    
                    
    player.sendMessage("§eLet's get ready to §lRUUUUMBLEEE§r§e!!");
                    
                    
    player.setGameMode(GameMode.ADVENTURE);
                    
                    
    player.setLevel(0);
                
                    if (
    player.hasPermission("FreeForAll.member")) {
                    
                        
    player.setOp(true);
                        
    player.getInventory().clear();
                    
                    
    ItemStack Slot1 = new ItemStack(Material.IRON_SWORD1);
                    
    ItemMeta met1 Slot1.getItemMeta();
                    
    met1.setDisplayName("§aIron Sword");
                    
    Slot1.setItemMeta(met1);
                    
    player.getInventory().setItem(0Slot1);
                    
                    
    ItemStack Slot2 = new ItemStack(Material.FISHING_ROD1);
                    
    ItemMeta met2 Slot2.getItemMeta();
                    
    met2.setDisplayName("§aFishing Rod");
                    
    Slot2.setItemMeta(met2);
                    
    player.getInventory().setItem(1Slot2);
                    
                    
    ItemStack Slot3 = new ItemStack(Material.BOW1);
                    
    ItemMeta met3 Slot3.getItemMeta();
                    
    met3.setDisplayName("§aBow");
                    
    Slot3.setItemMeta(met3);
                    
    player.getInventory().setItem(2Slot3);
                    
                    
    ItemStack Slot4 = new ItemStack(Material.ARROW8);
                    
    ItemMeta met4 Slot4.getItemMeta();
                    
    met4.setDisplayName("§aArrow");
                    
    Slot4.setItemMeta(met4);
                    
    player.getInventory().setItem(8Slot4);
                    
                    
    ItemStack Slot5 = new ItemStack(Material.IRON_HELMET1);
                    
    ItemMeta met5 Slot5.getItemMeta();
                    
    met5.setDisplayName("§aIron Helmet");
                    
    Slot5.setItemMeta(met5);
                    
    player.getInventory().setHelmet(Slot5);
                    
                    
    ItemStack Slot6 = new ItemStack(Material.CHAINMAIL_CHESTPLATE1);
                    
    Slot6.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL1);
                    
    ItemMeta met6 Slot6.getItemMeta();
                    
    met6.setDisplayName("§aChainmail Chestplate");
                    
    Slot6.setItemMeta(met6);
                    
    player.getInventory().setChestplate(Slot6);
                    
                    
    ItemStack Slot7 = new ItemStack(Material.IRON_LEGGINGS1);
                    
    ItemMeta met7 Slot7.getItemMeta();
                    
    met7.setDisplayName("§aIron Leggings");
                    
    Slot7.setItemMeta(met7);
                    
    player.getInventory().setLeggings(Slot7);
                    
                    
    ItemStack Slot8 = new ItemStack(Material.IRON_BOOTS1);
                    
    ItemMeta met8 Slot8.getItemMeta();
                    
    met8.setDisplayName("§aIron Boots");
                    
    Slot8.setItemMeta(met8);
                    
    player.getInventory().setBoots(Slot8);
                    
                    if(!
    player.hasPermission("FreeForAll.op")) {
                        
    player.setOp(false);
                        } 
                    
                } else 
                    if (
    player.hasPermission("FreeForAll.premium")) {
                        
                        
    player.setOp(true);
                        
    player.getInventory().clear();
                        
                        
    ItemStack Slot1 = new ItemStack(Material.IRON_SWORD1);
                        
    ItemMeta met1 Slot1.getItemMeta();
                        
    met1.setDisplayName("§aIron Sword");
                        
    Slot1.setItemMeta(met1);
                        
    player.getInventory().setItem(0Slot1);
                        
                        
    ItemStack Slot2 = new ItemStack(Material.FISHING_ROD1);
                        
    ItemMeta met2 Slot2.getItemMeta();
                        
    met2.setDisplayName("§aFishing Rod");
                        
    Slot2.setItemMeta(met2);
                        
    player.getInventory().setItem(1Slot2);
                        
                        
    ItemStack Slot3 = new ItemStack(Material.BOW1);
                        
    ItemMeta met3 Slot3.getItemMeta();
                        
    met3.setDisplayName("§aBow");
                        
    Slot3.setItemMeta(met3);
                        
    player.getInventory().setItem(2Slot3);
                        
                        
    ItemStack Slot4 = new ItemStack(Material.ARROW8);
                        
    ItemMeta met4 Slot4.getItemMeta();
                        
    met4.setDisplayName("§aArrow");
                        
    Slot4.setItemMeta(met4);
                        
    player.getInventory().setItem(8Slot4);
                        
                        
    ItemStack Slot5 = new ItemStack(Material.IRON_HELMET1);
                        
    ItemMeta met5 Slot5.getItemMeta();
                        
    met5.setDisplayName("§aIron Helmet");
                        
    Slot5.setItemMeta(met5);
                        
    player.getInventory().setHelmet(Slot5);
                        
                        
    ItemStack Slot6 = new ItemStack(Material.IRON_CHESTPLATE1);
                        
    Slot6.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL1);
                        
    ItemMeta met6 Slot6.getItemMeta();
                        
    met6.setDisplayName("§aIron Chestplate");
                        
    Slot6.setItemMeta(met6);
                        
    player.getInventory().setChestplate(Slot6);
                        
                        
    ItemStack Slot7 = new ItemStack(Material.IRON_LEGGINGS1);
                        
    ItemMeta met7 Slot7.getItemMeta();
                        
    met7.setDisplayName("§aIron Leggings");
                        
    Slot7.setItemMeta(met7);
                        
    player.getInventory().setLeggings(Slot7);
                        
                        
    ItemStack Slot8 = new ItemStack(Material.IRON_BOOTS1);
                        
    ItemMeta met8 Slot8.getItemMeta();
                        
    met8.setDisplayName("§aIron Boots");
                        
    Slot8.setItemMeta(met8);
                        
    player.getInventory().setBoots(Slot8);
                        
                        if(!
    player.hasPermission("FreeForAll.op")) {
                            
    player.setOp(false);
                        }
                    }
                    }
                }
            }
        }
    }


       
    Yeah im sure that im using 1.7.2 :)
     
  5. Offline

    pookeythekid

    JeykoExample If you know how to read stack traces, it's probably an error in your SignEvent class on line 41...
     
  6. Offline

    JeykoExample

    :eek: it's this line:

    PHP:
     Sign mysign = (Signevent.getClickedBlock().getState();
     
  7. Offline

    pookeythekid

    JeykoExample Split it up into several lines to debug it even further.
     
  8. Offline

    CullanP

    I've compiled this using 1.7.10 and it works for me, if it doesn't work then reply and I'll try compiling in 1.7.2
    below onPlayerInteract replace everything upto "if(event.getClickedBlock().getTypeId() == 63 || event.getClickedBlock().getTypeId() == 68) {"

    It will look like this

    Code:
    public void onPlayerInteract(PlayerInteractEvent event) {
            Sign mysign = (Sign) event.getClickedBlock().getState();
            if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
              return;
            }
            Block b = event.getClickedBlock();
            if ((!b.getType().equals(Material.SIGN)) && (!b.getType().equals(Material.WALL_SIGN)) && (!b.getType().equals(Material.SIGN_POST))) {
              return;
            }
                if(event.getClickedBlock().getTypeId() == 63 || event.getClickedBlock().getTypeId() == 68) {
    
     
  9. Offline

    JeykoExample

    Yeah but still what is wrong in this line? Should we not get the State? :O
     
  10. Offline

    Necrodoom

    JeykoExample you cast before you are even sure a sign was clicked.
    Move it to inside the if checks.
    Also, Material.SIGN is an item, use WALL_SIGN and SIGN_POST.
    CullanP that spoonfeed is complete nonsense. JeykoExample don't copy his code.
     
  11. Offline

    pookeythekid

    JeykoExample I don't know what's wrong with the line. That's why I asked you to split it so it can be debugged. Anyway, here's a little chunk out of my own code that I think you should compare yours to. I have no idea what difference it makes other than that I use block.getType() == Material.SIGN_POST (and etc.) to check if it's a sign.
    Code:java
    1. Block clickedBlock = e.getClickedBlock();
    2.  
    3. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4.  
    5. if (clickedBlock.getType() == Material.SIGN
    6. || clickedBlock.getType() == Material.SIGN_POST
    7. || clickedBlock.getType() == Material.WALL_SIGN) {
    8.  
    9. Sign sign = (Sign) clickedBlock.getState();

    Necrodoom Lol I figured that out after I made my plugin that's code I just put in here, I've just been too lazy to remove it. Doesn't make a difference, really.
     
    JeykoExample likes this.
  12. Offline

    JeykoExample

    It's working bros :) Look i just changed this:

    PHP:
    if(event.getClickedBlock().equals(Material.SIGN) || event.getClickedBlock().equals(Material.SIGN_POST)) {
    to this:

    PHP:
    if(event.getClickedBlock().getType().equals(Material.SIGN) || event.getClickedBlock().getType().equals(Material.SIGN_POST)) {
     
  13. Offline

    CullanP


    Congrats


    Nonsense that works, are you mad?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
    JeykoExample likes this.
  14. Offline

    Necrodoom

    JeykoExample again, you still check SIGN, which is an item, and your cast is still outside the if checks.
    CullanP
    You check if block is a SIGN, WALL_SIGN or a SIGN_POST... Then, if succeeds, you use a deprecated method to check if its a WALL_SIGN or a SIGN_POST...
     
  15. Offline

    pookeythekid

    JeykoExample *facepalm* How did I not see that? Of course, can't compare a block to a material without using getType(). Anyway... congrats. Hope you post the plugin actually (however make it MUCH more customizable). It looks like a pretty good idea.
     
  16. Offline

    Gater12

    CullanP
    The fact that you use deprecated methods involving with magic values is complete nonsense when there is a perfectly non-potential-breakage method to do the exact same function.
     
  17. Offline

    CullanP


    Everyone uses deprecated methods rather you want to or not. Face it. :)
    Edit: and actually I didn't use that method, I kept the code he used from before. I just simply added on to it. The methods I added were NOT deprecated thank you very much. <3
     
  18. Offline

    pookeythekid

    Gater12 I'm curious: Do you know what magic values are? It makes absolutely no sense when I see that as a deprecation reason.
     
  19. Offline

    Necrodoom

    CullanP oh, yes, that makes complete sense!
    Use the proper method, AND the deprecated method, in the SAME code, to do the SAME check, for no reason at all but to make it break when the deprecated methods are removed.
    Congrats.
     
  20. Offline

    CullanP


    Hey, you, retired admin dude, Do you know about the player.updateinventory check? That about EVERYONE uses. I don't think that'll be removed any time soon, does that mean it's not okay to use it?
     
  21. Offline

    Necrodoom

    CullanP different method, different reasons to deprecation, different use cases. And none of this cancels the fact that your code is nonsense.
     
  22. Offline

    CullanP


    Again I quote, Nonsense that works, is there a problem?
     
  23. Offline

    Gater12

    pookeythekid
    Let's say getData() returns value 1. You have 10 checks generally like this:
    Code:java
    1. if(getData() == 1)


    Let's say getData() now returns 2. Your plugin is now broken and you would have to go find all your 10 checks and fix them.

    And then getData() now returns 3 and you do it all over again.

    Also Mojang is phasing out using IDs for blocks and rather favoring to use item names to bring in more support for mods implementing new blocks. (E.g. minecraft:anvil pixelmon:anvil)
     
  24. Offline

    Necrodoom

    CullanP you mean that just happens to work, is inefficient, and is bad practice?
    I could also make a method that gets a certain number by looping though any number in existence, and get the one that matches with mine, that technically works, but if you try to present it as a solution, you go down all the stairs.

    If you can't bother making proper code, don't bother spoonfeeding.
     
  25. Offline

    CullanP


    Let me make everyone happy
    Rather then using
    Code:
    if(event.getClickedBlock().getTypeId() == 63 || event.getClickedBlock().getTypeId() == 68) {
    You can use
    Code:
    public final String free = "[freeforall]";
        String line = sign.getLine(0);
        if (line.equals(this.free))
    
    Non-Deprecated method, Is everyone happy? and as I stated earlier if you read, the method that was deprecated I did not create. I simply added on to it.
     
  26. Offline

    pookeythekid

    Gater12 Ah okay. So... Magic Value is an ever-changing method that's for some reason called magic?
     
  27. Offline

    Necrodoom

  28. Offline

    CullanP

    Necrodoom
    Do you even know how to use the code I posted? Because it works lol, Would you like me to show you the entire new class?
     
  29. Offline

    Necrodoom

  30. Offline

    CullanP


    I simply fixed the deprecated method that you were complaining about. If you really want I will re-code that entire event if it will make you happy.
     
Thread Status:
Not open for further replies.

Share This Page