Faction claims

Discussion in 'Spigot Plugin Development' started by harveycat1, Apr 23, 2017.

  1. this isnt disabling fly when a player leaves their claim and comes back
    Code (Text):
        @EventHandler
        public void onOwnLandFly(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            MPlayer mplayer;
            mplayer = MPlayer.get(player);

            if (this.factionsfly.contains(p.getName())) {
                if ((p.hasPermission("factionsfly.use"))) {
                    if ((!(mplayer.isInOwnTerritory()) && (p.isFlying()))) {
                        p.setAllowFlight(false);
                        p.setFlying(false);
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("prefix") + getConfig().getString("FlyOff")));
                    }
                    if ((mplayer.isInOwnTerritory()) && (!(p.isFlying()))) {
                        p.setAllowFlight(true);
                        p.setFlying(true);
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("prefix") + getConfig().getString("FlyOn")));
                    }
                }
            }
        }
    }
     
     
  2. Can someone please help me with this i dont know why it doesnt work
     
  3. There are a few possibilties why it doesn't work:

    - factionsfly doesn't contain p.getName()
    - isInOwnTerritory() method fails

    Please send isInOwnTerritory() or debug with messages within the if-clauses
     
    #3 Zwoerni, Apr 23, 2017
    Last edited: Apr 23, 2017
  4. yes the events are registered
     
  5. it does contain p.getName
     
  6. The event works it just doesnt disable their fly when they leave or enable when they come back
     
  7. Probably use getAllowFlight() instead of isFlying() in your if-clause and change

    Code (Text):
    p.setAllowFlight(false);
    p.setFlying(false);
    to

    Code (Text):
    p.setFlying(false);
    p.setAllowFlight(false);
    because it's possible that you can't change the permission of flight, while he is flying.
     
  8. still doesnt work and tried changing it a little bit
    Code (Text):
        @EventHandler
        public void onOwnLandFly(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            MPlayer mplayer;
            mplayer = MPlayer.get(player);

            if (this.factionsfly.contains(p.getName())) {
                if ((p.hasPermission("factionsfly.use"))) {
                    if ((mplayer.isInOwnTerritory() == false) && (p.getAllowFlight() == true)) {
                        p.setFlying(false);
                        p.setAllowFlight(false);
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("prefix") + getConfig().getString("FlyOff")));
                    }
                    if ((mplayer.isInOwnTerritory() == true) && (p.getAllowFlight() == false)) {
                        p.setFlying(true);
                        p.setAllowFlight(true);
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("prefix") + getConfig().getString("FlyOn")));
                    }
                }
            }
        }
    }
     
     
  9. that's.. inefficient. very inefficient..
     
  10. tell me a more efficient way then
     
  11. Try that

    Code (Text):
    public static List<String> players = new ArrayList<>();

    @EventHandler
      public void onOwnLandFly(PlayerMoveEvent e) {
      Player p = e.getPlayer();

      if ((p.hasPermission("factionsfly.use"))) {
      MPlayer mplayer = MPlayer.get(player);
      if(players.contains(p.getName())) {
      if(!mplayer.isInOwnTerritory()) {
      p.setFlying(false);
      p.setAllowFlight(false);
      players.remove(p.getName);
      p.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("prefix") + getConfig().getString("FlyOff")));
      }
      } else {
      if ((mplayer.isInOwnTerritory() == true) {
      players.add(p.getName);
      p.setFlying(true);
      p.setAllowFlight(true);
      p.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("prefix") + getConfig().getString("FlyOn")));
      }
      }
      }
      }
     
     
  12. For example cancel if player isn't moving x and z. Another possiblity are schedulers or one scheduler for all players, that loops every few seconds.
     
  13. Check at every Movement the x and z Coordinats seems for me inefficient too.
     
  14. Depends on what you want to do. But all in all comparing a double is in no way inefficient.
     
  15. it doesnt work if i leave my claim it doesnt remove my fly
     
  16. Then probably think about your methods or the list players.