diff --git a/src/cn/citycraft/ResFly/listen/PlayerListen.java b/src/cn/citycraft/ResFly/listen/PlayerListen.java index 0b3fd15..5159567 100644 --- a/src/cn/citycraft/ResFly/listen/PlayerListen.java +++ b/src/cn/citycraft/ResFly/listen/PlayerListen.java @@ -1,117 +1,109 @@ -package cn.citycraft.ResFly.listen; - -import java.util.HashMap; - -import org.bukkit.GameMode; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; - -import cn.citycraft.ResFly.ResFly; - -import com.bekvon.bukkit.residence.event.ResidenceChangedEvent; -import com.bekvon.bukkit.residence.event.ResidenceDeleteEvent; -import com.bekvon.bukkit.residence.event.ResidenceFlagChangeEvent; -import com.bekvon.bukkit.residence.protection.ClaimedResidence; -import com.bekvon.bukkit.residence.protection.ResidencePermissions; - -public class PlayerListen implements Listener { - - HashMap fall = new HashMap(); - ResFly plugin; - - public PlayerListen(ResFly main) { - plugin = main; - } - - @EventHandler(ignoreCancelled = true) - public void PlayerMove(ResidenceChangedEvent event) { - Player player = event.getPlayer(); - ClaimedResidence resto = event.getTo(); - if (permCheck(player)) { - if (!resPermCheck(resto, player)) { - ChangePlayerFly(player, false); - } else { - ChangePlayerFly(player, true); - } - } - } - - // ResidenceDeleteEvent.class - // ResidenceFlagChangeEvent.class - - @EventHandler(ignoreCancelled = true) - public void ResDelete(ResidenceDeleteEvent e) { - ClaimedResidence res = e.getResidence(); - for (Player p : res.getPlayersInResidence()) { - if (permCheck(p)) { - ChangePlayerFly(p, false); - } - } - } - - @EventHandler(ignoreCancelled = true) - public void FlagChange(ResidenceFlagChangeEvent e) { - ClaimedResidence res = e.getResidence(); - for (Player p : res.getPlayersInResidence()) { - if (permCheck(p)) { - if (permCheck(p)) { - if (!resPermCheck(res, p)) { - ChangePlayerFly(p, false); - } else { - ChangePlayerFly(p, true); - } - } - } - } - } - - public void onFallDamage(EntityDamageEvent e) { - if (e.getEntity() instanceof Player) { - Player p = (Player) e.getEntity(); - if (e.getCause() == DamageCause.FALL) { - if (p == fall.get(p)) { - fall.remove(p); - e.setCancelled(true); - p.sendMessage(plugin.getfullmsg("Message.Protect")); - } - } - } - } - - void ChangePlayerFly(Player p, boolean fly) { - if (p.getAllowFlight() && !fly) { - if (p.isFlying()) - fall.put(p, p); - p.setAllowFlight(false); - p.sendMessage(plugin.getfullmsg("Message.Not_Allow")); - } - if (!p.getAllowFlight() && fly) { - if (p == fall.get(p)) - fall.remove(p); - p.setAllowFlight(true); - p.sendMessage(plugin.getfullmsg("Message.Allow")); - } - } - - boolean permCheck(Player p) { - if (p.hasPermission("fcp.ignore.resfly") || p.isOp() - || p.getGameMode() == GameMode.CREATIVE) { - return false; - } - return true; - } - - boolean resPermCheck(ClaimedResidence res, Player p) { - if (res == null) { - return false; - } - ResidencePermissions perms = res.getPermissions(); - if (perms.playerHas(p.getName(), "fly", false)) { - return true; - } - return false; - } +package cn.citycraft.ResFly.listen; + +import java.util.HashMap; + +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; + +import cn.citycraft.ResFly.ResFly; + +import com.bekvon.bukkit.residence.event.ResidenceChangedEvent; +import com.bekvon.bukkit.residence.event.ResidenceDeleteEvent; +import com.bekvon.bukkit.residence.event.ResidenceFlagChangeEvent; +import com.bekvon.bukkit.residence.protection.ClaimedResidence; +import com.bekvon.bukkit.residence.protection.ResidencePermissions; + +public class PlayerListen implements Listener { + + HashMap fall = new HashMap(); + ResFly plugin; + + public PlayerListen(ResFly main) { + plugin = main; + } + + void ChangePlayerFly(Player p, boolean fly) { + if (p.getAllowFlight() && !fly) { + if (p.isFlying()) { + fall.put(p, p); + } + p.setAllowFlight(false); + p.sendMessage(plugin.getfullmsg("Message.Not_Allow")); + } + if (!p.getAllowFlight() && fly) { + if (p == fall.get(p)) { + fall.remove(p); + } + p.setAllowFlight(true); + p.sendMessage(plugin.getfullmsg("Message.Allow")); + } + } + + // ResidenceDeleteEvent.class + // ResidenceFlagChangeEvent.class + + @EventHandler(ignoreCancelled = true) + public void FlagChange(ResidenceFlagChangeEvent e) { + ClaimedResidence res = e.getResidence(); + for (Player p : res.getPlayersInResidence()) { + if (!permCheck(p)) { + if (!resPermCheck(res, p)) { + ChangePlayerFly(p, false); + } else { + ChangePlayerFly(p, true); + } + } + } + } + + public void onFallDamage(EntityDamageEvent e) { + if (e.getEntity() instanceof Player) { + Player p = (Player) e.getEntity(); + if (e.getCause() == DamageCause.FALL) { + if (p == fall.get(p)) { + fall.remove(p); + e.setCancelled(true); + p.sendMessage(plugin.getfullmsg("Message.Protect")); + } + } + } + } + + boolean permCheck(Player p) { + return p.hasPermission("resfly.ignore") || p.isOp() || p.getGameMode() == GameMode.CREATIVE; + } + + @EventHandler(ignoreCancelled = true) + public void resChange(ResidenceChangedEvent event) { + Player player = event.getPlayer(); + ClaimedResidence resto = event.getTo(); + if (!permCheck(player)) { + if (!resPermCheck(resto, player)) { + ChangePlayerFly(player, false); + } else { + ChangePlayerFly(player, true); + } + } + } + + @EventHandler(ignoreCancelled = true) + public void ResDelete(ResidenceDeleteEvent e) { + ClaimedResidence res = e.getResidence(); + for (Player p : res.getPlayersInResidence()) { + if (!permCheck(p)) { + ChangePlayerFly(p, false); + } + } + } + + boolean resPermCheck(ClaimedResidence res, Player p) { + if (res == null) + return false; + ResidencePermissions perms = res.getPermissions(); + return perms.playerHas(p.getName(), "fly", false); + } } \ No newline at end of file