mirror of
https://e.coding.net/circlecloud/ResFly.git
synced 2024-12-26 16:38:46 +00:00
Optimization performance and fix perm error...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
parent
b06f262e24
commit
74ecd2e08e
@ -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<Player, Player> fall = new HashMap<Player, Player>();
|
||||
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<Player, Player> fall = new HashMap<Player, Player>();
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user