1
0
mirror of https://e.coding.net/circlecloud/ResFly.git synced 2024-11-21 10:48:48 +00:00

Optimization performance and fix perm error...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-06-14 13:53:15 +08:00
parent b06f262e24
commit 74ecd2e08e

View File

@ -26,38 +26,31 @@ public class PlayerListen implements Listener {
plugin = main; plugin = main;
} }
@EventHandler(ignoreCancelled = true) void ChangePlayerFly(Player p, boolean fly) {
public void PlayerMove(ResidenceChangedEvent event) { if (p.getAllowFlight() && !fly) {
Player player = event.getPlayer(); if (p.isFlying()) {
ClaimedResidence resto = event.getTo(); fall.put(p, p);
if (permCheck(player)) {
if (!resPermCheck(resto, player)) {
ChangePlayerFly(player, false);
} else {
ChangePlayerFly(player, true);
} }
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 // ResidenceDeleteEvent.class
// ResidenceFlagChangeEvent.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) @EventHandler(ignoreCancelled = true)
public void FlagChange(ResidenceFlagChangeEvent e) { public void FlagChange(ResidenceFlagChangeEvent e) {
ClaimedResidence res = e.getResidence(); ClaimedResidence res = e.getResidence();
for (Player p : res.getPlayersInResidence()) { for (Player p : res.getPlayersInResidence()) {
if (permCheck(p)) { if (!permCheck(p)) {
if (permCheck(p)) {
if (!resPermCheck(res, p)) { if (!resPermCheck(res, p)) {
ChangePlayerFly(p, false); ChangePlayerFly(p, false);
} else { } else {
@ -66,7 +59,6 @@ public class PlayerListen implements Listener {
} }
} }
} }
}
public void onFallDamage(EntityDamageEvent e) { public void onFallDamage(EntityDamageEvent e) {
if (e.getEntity() instanceof Player) { if (e.getEntity() instanceof Player) {
@ -81,37 +73,37 @@ public class PlayerListen implements Listener {
} }
} }
void ChangePlayerFly(Player p, boolean fly) { boolean permCheck(Player p) {
if (p.getAllowFlight() && !fly) { return p.hasPermission("resfly.ignore") || p.isOp() || p.getGameMode() == GameMode.CREATIVE;
if (p.isFlying()) }
fall.put(p, p);
p.setAllowFlight(false); @EventHandler(ignoreCancelled = true)
p.sendMessage(plugin.getfullmsg("Message.Not_Allow")); 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);
} }
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) { @EventHandler(ignoreCancelled = true)
if (p.hasPermission("fcp.ignore.resfly") || p.isOp() public void ResDelete(ResidenceDeleteEvent e) {
|| p.getGameMode() == GameMode.CREATIVE) { ClaimedResidence res = e.getResidence();
return false; for (Player p : res.getPlayersInResidence()) {
if (!permCheck(p)) {
ChangePlayerFly(p, false);
}
} }
return true;
} }
boolean resPermCheck(ClaimedResidence res, Player p) { boolean resPermCheck(ClaimedResidence res, Player p) {
if (res == null) { if (res == null)
return false; return false;
}
ResidencePermissions perms = res.getPermissions(); ResidencePermissions perms = res.getPermissions();
if (perms.playerHas(p.getName(), "fly", false)) { return perms.playerHas(p.getName(), "fly", false);
return true;
}
return false;
} }
} }