OnSignChange Errors

Discussion in 'Plugin Development' started by chriztopia, Mar 28, 2013.

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

    chriztopia

    My Plugin has been causing a few people some errors but not other people. This is causing it hard to track. I have been battling this issue for months and have finally decided to request the help of other bukkit developers.

    The problems are from SignChange Event and Player Interact Event Both dealing with signs... Here is one of the errors...

    http://pastebin.com/wiShk24R

    and this is the other

    http://pastebin.com/XSTFCw3q

    Any help to fix this issue would be great...

    You can get to my code by github or the OnSignChange is below..

    Code:
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onSignChange(SignChangeEvent event) {
           
            Player p = event.getPlayer();
           
           
            Location loc = event.getBlock().getLocation();
            loc.setY(loc.getY() - 1);
            loc.setX(loc.getX() - 1);
           
            Sign s = (Sign) event.getBlock().getState();
           
          if(event.getLine(0).contains("[BuyLand]") || event.getLine(0).equalsIgnoreCase("[BuyLand]")){
          if(p.hasPermission("buyland.signcreate") || p.hasPermission("buyland.all")){
             
              event.setLine(0, "[BuyLand]");
      //-----             
              if (event.getLine(1).equalsIgnoreCase("For Sale")){
                event.setLine(1, "For Sale");
               
                String plotname = event.getLine(2);
                World world1 = p.getWorld();
                RegionManager regionManager = plugin.getWorldGuard().getRegionManager(world1);
                if(regionManager.getRegionExact(plotname) == null){
    event.setLine(2, "Invalid Region");
                }else{
                    World world2 = p.getWorld();
                    RegionManager regionManager1 = plugin.getWorldGuard().getRegionManager(world2);
                    ProtectedRegion set2 = regionManager1.getRegionExact(plotname);
                   
                    Double pflag = set2.getFlag(DefaultFlag.PRICE);
           
                if (pflag == null){
                    if (plugin.getConfig().getBoolean("buyland.usepriceperblock") == true){
                       
                            int size =set2.volume();
                            int ppb = plugin.getConfig().getInt("buyland.defaultpriceperblock");
                            pflag = (double)size * ppb;
                       
                    }else{
                pflag = plugin.getConfig().getDouble("buyland.defaultprice");
                    }
                }
                   
                    String price = pflag.toString();
                    event.setLine(3, price);
                   
                    Location signloc = s.getLocation();
                    String location = (signloc.getWorld().getName() + ":" + signloc.getX() + ":" + signloc.getY() + ":" + signloc.getZ());
                    String signname = event.getLine(2);
                    plugin.getsignConfig().set("sign." + signname, location);
                    plugin.savesignConfig();
                    plugin.reloadsignConfig();
                }
               
              }else if (event.getLine(1).equalsIgnoreCase("For Rent")){
                event.setLine(1, "For Rent");
               
                String plotname = event.getLine(2);
                World world1 = p.getWorld();
                RegionManager regionManager = plugin.getWorldGuard().getRegionManager(world1);
                if(regionManager.getRegionExact(plotname) == null){
    event.setLine(2, "Invalid Region");
                }else{
               
                   
                    Location signloc = s.getLocation();
                    String location = (signloc.getWorld().getName() + ":" + signloc.getX() + ":" + signloc.getY() + ":" + signloc.getZ());
                    String signname = event.getLine(2);
                    plugin.getsignConfig().set("sign." + signname, location);
                    plugin.savesignConfig();
                    plugin.reloadsignConfig();
                   
                   
                }
                }else if (event.getLine(1).equalsIgnoreCase("unrent")){
    //UNRENT COMMAND
                    event.setLine(1, "UnRent");
                   
                    String plotname = event.getLine(2);
                    World world1 = p.getWorld();
                    RegionManager regionManager = plugin.getWorldGuard().getRegionManager(world1);
                    if(regionManager.getRegionExact(plotname) == null){
        event.setLine(2, "Invalid Region");
                    }else{
                   
                       
                       
                       
                       
                    }
                   
    //END UNRENT COMMAND   
                }else{   
            event.setLine(1, "Error");
              }
             
                       
              s.update();
             
          p.sendMessage(ChatColor.RED + "BuyLand: " + ChatColor.WHITE + "BuyLand Sign Created!");
          }else{
          p.sendMessage(ChatColor.RED + "BuyLand: You Do Not Have Permission To Create A BuyLand Sign!");
          event.setLine(0, "Error");
          event.setLine(1, "---");
          event.setLine(2, "---");
          event.setLine(3, "---");
         
          s.update();
          }
    }
    }
     
  2. Offline

    Tirelessly

    Check if the blockState is an instance of a sign.
     
  3. Offline

    chriztopia

    So basicly check that s is instance of sign or how would be the best way. If this is what's causing problems for some but not others would it not cause the plugin to just not error for those people?
     
  4. Offline

    RingOfStorms

    if(!(block.getState() instanceof Sign)) return;
    Sign sign = block.getState();
     
  5. Offline

    chriztopia

    I will have them try this.

    Doing this caused a lot of problems many more errors than there was before. Any other suggestions?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  6. Offline

    dillyg10

    What is your updated code... this should work (if you didn't just copy and paste it randomly)
     
  7. Offline

    chriztopia

    Without pasting all of the code for both my player interact and signchangeevent I pasted this at the top of both.
     
  8. Offline

    dillyg10

    Show us updated code.?
     
  9. Offline

    chriztopia

    Code:
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onSignUse(PlayerInteractEvent event) {
    if(!(event.getClickedBlock().getState() instanceof Sign)) return;
    //HERE   
       
            RegisteredServiceProvider<Economy> rsp = plugin.getServer().getServicesManager().getRegistration(Economy.class);
            econ = rsp.getProvider();
        final Player p = event.getPlayer();
       
       
    //Stops players from breaking signs.   
        if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
           
        if (event.getClickedBlock().getType() == Material.SIGN || event.getClickedBlock().getType() == Material.SIGN_POST || event.getClickedBlock().getType() == Material.WALL_SIGN) {
     
           
            Sign s = (Sign) event.getClickedBlock().getState();
        if (s.getLine(0).equalsIgnoreCase("[BuyLand]") || (s.getLine(0).contains("[BuyLand]"))) {
            Location loc = event.getClickedBlock().getLocation();
            loc.setY(loc.getY() - 1);
            loc.setX(loc.getX() - 1);
        if (!p.hasPermission("buyland.signbreak") || !p.hasPermission("buyland.all")) {
        p.sendMessage(ChatColor.RED + "BuyLand: " + ChatColor.RED + "You can not break this sign.");
        event.setCancelled(true);
        return;
        }
        }
        }
        }
    //Stops Players from breakins signs.   
       
       
        if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (event.getClickedBlock().getType() == Material.SIGN || event.getClickedBlock().getType() == Material.SIGN_POST || event.getClickedBlock().getType() == Material.WALL_SIGN) {
       
        Sign s = (Sign) event.getClickedBlock().getState();
       
       
        if (s.getLine(0).equalsIgnoreCase("[BuyLand]") || (s.getLine(0).contains("[BuyLand]"))) {
           
           
    if (p.hasPermission("buyland.signuse") || p.hasPermission("buyland.all")) {
        String plotname = s.getLine(2).toString();
       
       
    //RENT SIGN   
        if (s.getLine(1).equalsIgnoreCase("For Rent") || (s.getLine(1).contains("FOR RENT"))) {
            if (p.hasPermission("buyland.rent") || p.hasPermission("buyland.all")){
                          String line3 = s.getLine(3);
                            Bukkit.dispatchCommand(Bukkit.getPlayer(p.getName()), "rentland " + plotname + " " + line3);       
        }else{
            p.sendMessage(ChatColor.DARK_RED + "BuyLand: Sorry you do not have permission to rent land.");
        }
        }
       
       
       
       
    //Sale Back SIGN   
     
            if (s.getLine(1).equalsIgnoreCase("Sale Back")) {
               
            //    if(p.isSneaking()){
            //        p.sendMessage("DEBUG: Player is Sneaking...");
            //    }else{
            //        p.sendMessage("DEBUG: Player is NOT Sneaking...");
            //    }
               
                if (p.hasPermission("buyland.sell") || p.hasPermission("buyland.all")){
               
           
            World world2 = p.getWorld();
            RegionManager regionManager1 = plugin.getWorldGuard().getRegionManager(world2);
            ProtectedRegion set2 = regionManager1.getRegionExact(plotname);
           
            Double pflag = set2.getFlag(DefaultFlag.PRICE);
           
             
            DefaultDomain owner = set2.getOwners();
                String owner2 = owner.toPlayersString();
                String pn = p.getName().toLowerCase();
     
               
                if (owner2.contains(pn)){
                   
                //------------
                if (pflag == null){
                    if (plugin.getConfig().getBoolean("buyland.usepriceperblock") == true){
                        //BETA AREA
                            int size =set2.volume();
                            //player.sendMessage("Area of blocks: " + size);
                            int ppb = plugin.getConfig().getInt("buyland.defaultpriceperblock");
                            pflag = (double)size * ppb;
                        //BETA AREA
                    }else{
                pflag = plugin.getConfig().getDouble("buyland.defaultprice");
                    }
                }
                   
                    String price = pflag.toString();
                   
                hashbuy.put(plotname, System.currentTimeMillis());
     
    s.setLine(0, "[BuyLand]");
    s.setLine(1, "For Sale");
    s.setLine(2, plotname);
    s.setLine(3, price);
    s.update();
    Bukkit.dispatchCommand(Bukkit.getPlayer(p.getName()), "sellland " + plotname);
     
             
             
                //-----------------------------------------   
                }else{
                    p.sendMessage(ChatColor.DARK_RED + "BuyLand: Sorry you are not the owner of this region!");
                }
     
           
            }else{
                p.sendMessage(ChatColor.DARK_RED + "BuyLand: Sorry you do not have permission to sale land.");
            }
            }
       
    //Buy Sign   
        if (s.getLine(1).equalsIgnoreCase("For Sale")) {
            if (p.hasPermission("buyland.buy") || p.hasPermission("buyland.all")){
     
                double bal = econ.getBalance(p.getName());
                String sb = s.getLine(3);
                double signbal = Double.parseDouble(sb);
     
                  if(hashbuy.containsKey(plotname))
                    {
     
                      long time = hashbuy.get(plotname);
                      int timebuy = 3 * 1000;
                      if(System.currentTimeMillis() - time < timebuy){
                            return;
                      }else{
                         
                            World world2 = p.getWorld();
                            RegionManager regionManager1 = plugin.getWorldGuard().getRegionManager(world2);
                            ProtectedRegion set2 = regionManager1.getRegionExact(plotname);
     
                           
                            Boolean bflag = set2.getFlag(DefaultFlag.BUYABLE);
                               
                                if (bflag == true){
                         
                          if (signbal > bal){
                                p.sendMessage(ChatColor.RED + "BuyLand: Insignificant funds to buy.");
                            }else{
                               
                                String nm = p.getName();
                                int numofland = plugin.getCustomConfig().getInt(nm);
                                int maxofland = plugin.getConfig().getInt("buyland.maxamountofland");
                               
     
                            if (numofland +1 > maxofland){
                                String convertedmax = ChatColor.translateAlternateColorCodes('&', plugin.getlanguageConfig().getString("buyland.buy.max"));
                               
                                p.sendMessage(ChatColor.RED + "BuyLand: " + ChatColor.WHITE + convertedmax);
                            }else{
     
                               
                            if (plugin.getConfig().getBoolean("buyland.breaksignonbuy") == true){
                                    s.getBlock().setType(Material.AIR);
                                    }else{
                                   
                                    s.setLine(0, "[BuyLand]");
                                    s.setLine(1, "Sale Back");
                                    s.setLine(2, plotname);
                                    s.setLine(3, p.getName());
                                    s.update();
                                    }
                                    Bukkit.dispatchCommand(Bukkit.getPlayer(p.getName()), "buyland " + plotname);
                  hashbuy.remove(plotname);
                 
                            }
                 
     
                            }
                                                          }else{
                                       
                                    String convertednotforsale = ChatColor.translateAlternateColorCodes('&', plugin.getlanguageConfig().getString("buyland.price.dontown"));
                                       
                                    p.sendMessage(ChatColor.RED + "BuyLand: " + ChatColor.WHITE + convertednotforsale);
                               
                                       
                                    }
                      }
                   
                    }else{
                       
                                World world2 = p.getWorld();
                            RegionManager regionManager1 = plugin.getWorldGuard().getRegionManager(world2);
                            ProtectedRegion set2 = regionManager1.getRegionExact(plotname);
     
                           
                            Boolean bflag = set2.getFlag(DefaultFlag.BUYABLE);
                               
                                if (bflag == true){
                        if (signbal > bal){
     
                            p.sendMessage(ChatColor.RED + "BuyLand: Insignificant funds to buy.");
                        }else{
                           
                   
                           
                        if (plugin.getConfig().getBoolean("buyland.breaksignonbuy") == true){
                                s.getBlock().setType(Material.AIR);
                                }
                            String nm = p.getName();
                            int numofland = plugin.getCustomConfig().getInt(nm);
                            int maxofland = plugin.getConfig().getInt("buyland.maxamountofland");
                           
     
                        if (numofland +1 > maxofland){
                            String convertedmax = ChatColor.translateAlternateColorCodes('&', plugin.getlanguageConfig().getString("buyland.buy.max"));
                           
                            p.sendMessage(ChatColor.RED + "BuyLand: " + ChatColor.WHITE + convertedmax);
                        }else{
                                s.setLine(0, "[BuyLand]");
                                s.setLine(1, "Sale Back");
                                s.setLine(2, plotname);
                                s.setLine(3, p.getName());
                                s.update();
                                Bukkit.dispatchCommand(Bukkit.getPlayer(p.getName()), "buyland " + plotname);
                        }
                                hashbuy.remove(plotname);   
           
                                }
                                }else{
                                   
                                String convertednotforsale = ChatColor.translateAlternateColorCodes('&', plugin.getlanguageConfig().getString("buyland.price.dontown"));
                                   
                                p.sendMessage(ChatColor.RED + "BuyLand: " + ChatColor.WHITE + convertednotforsale);
       
                                }
     
                    }
               
    //----------------------------------
            }else{
                p.sendMessage(ChatColor.DARK_RED + "BuyLand: Sorry you do not have permission to buy.");
            }
           
       
        }
       
        }else{
    p.sendMessage("[BUYLAND] You do not have the correct permissions to use this.");
    event.setCancelled(true);
    return;
    }
       
        }
       
        }
        }
       
        }
    Code:
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onSignChange(SignChangeEvent event) {
            if(!(event.getBlock().getState() instanceof Sign)) return;
            //HERE   
     
            Player p = event.getPlayer();
           
         
            Location loc = event.getBlock().getLocation();
            loc.setY(loc.getY() - 1);
            loc.setX(loc.getX() - 1);
           
            Sign s = (Sign) event.getBlock().getState();
           
           
          if(event.getLine(0).contains("[BuyLand]") || event.getLine(0).equalsIgnoreCase("[BuyLand]")){
          if(p.hasPermission("buyland.signcreate") || p.hasPermission("buyland.all")){
             
              event.setLine(0, "[BuyLand]");
      //-----             
              if (event.getLine(1).equalsIgnoreCase("For Sale")){
                event.setLine(1, "For Sale");
               
                String plotname = event.getLine(2);
                World world1 = p.getWorld();
                RegionManager regionManager = plugin.getWorldGuard().getRegionManager(world1);
                if(regionManager.getRegionExact(plotname) == null){
    event.setLine(2, "Invalid Region");
                }else{
                    World world2 = p.getWorld();
                    RegionManager regionManager1 = plugin.getWorldGuard().getRegionManager(world2);
                    ProtectedRegion set2 = regionManager1.getRegionExact(plotname);
                   
                    Double pflag = set2.getFlag(DefaultFlag.PRICE);
           
                if (pflag == null){
                    if (plugin.getConfig().getBoolean("buyland.usepriceperblock") == true){
                       
                            int size =set2.volume();
                            int ppb = plugin.getConfig().getInt("buyland.defaultpriceperblock");
                            pflag = (double)size * ppb;
                       
                    }else{
                pflag = plugin.getConfig().getDouble("buyland.defaultprice");
                    }
                }
                   
                    String price = pflag.toString();
                    event.setLine(3, price);
                   
                    Location signloc = s.getLocation();
                    String location = (signloc.getWorld().getName() + ":" + signloc.getX() + ":" + signloc.getY() + ":" + signloc.getZ());
                    String signname = event.getLine(2);
                    plugin.getsignConfig().set("sign." + signname, location);
                    plugin.savesignConfig();
                    plugin.reloadsignConfig();
                }
               
              }else if (event.getLine(1).equalsIgnoreCase("For Rent")){
                event.setLine(1, "For Rent");
               
                String plotname = event.getLine(2);
                World world1 = p.getWorld();
                RegionManager regionManager = plugin.getWorldGuard().getRegionManager(world1);
                if(regionManager.getRegionExact(plotname) == null){
    event.setLine(2, "Invalid Region");
                }else{
               
                   
                    Location signloc = s.getLocation();
                    String location = (signloc.getWorld().getName() + ":" + signloc.getX() + ":" + signloc.getY() + ":" + signloc.getZ());
                    String signname = event.getLine(2);
                    plugin.getsignConfig().set("sign." + signname, location);
                    plugin.savesignConfig();
                    plugin.reloadsignConfig();
                   
                   
                }
                }else if (event.getLine(1).equalsIgnoreCase("unrent")){
    //UNRENT COMMAND
                    event.setLine(1, "UnRent");
                   
                    String plotname = event.getLine(2);
                    World world1 = p.getWorld();
                    RegionManager regionManager = plugin.getWorldGuard().getRegionManager(world1);
                    if(regionManager.getRegionExact(plotname) == null){
        event.setLine(2, "Invalid Region");
                    }else{
                   
                       
                       
                       
                       
                    }
                   
    //END UNRENT COMMAND   
                }else{   
            event.setLine(1, "Error");
              }
             
                       
              s.update();
             
          p.sendMessage(ChatColor.RED + "BuyLand: " + ChatColor.WHITE + "BuyLand Sign Created!");
          }else{
          p.sendMessage(ChatColor.RED + "BuyLand: You Do Not Have Permission To Create A BuyLand Sign!");
          event.setLine(0, "Error");
          event.setLine(1, "---");
          event.setLine(2, "---");
          event.setLine(3, "---");
         
          s.update();
          }
    }
    }
    Again Pasted at the very top of both...

    Any further help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  10. Offline

    chriztopia

Thread Status:
Not open for further replies.

Share This Page