From 94f06589c4b49db506cdd7acb5db7797b4ea0ed4 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Wed, 30 Sep 2015 00:55:21 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20de=20bug=20:=20La=20protection=20n?= =?UTF-8?q?on-PVP=20n'=C3=A9tait=20pas=20actif=20quand=20le=20PVP=20est=20?= =?UTF-8?q?d=C3=A9sactiv=C3=A9=20par=20un=20plugin,=20mais=20activ=C3=A9?= =?UTF-8?q?=20par=20le=20serveur=20Vanilla?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protection/NoPvpProtectManager.java | 59 +++++++++++++++---- .../protection/TamedEntityProtectManager.java | 13 ++-- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/protection/NoPvpProtectManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/protection/NoPvpProtectManager.java index da2e5e0..47411d9 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/protection/NoPvpProtectManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/protection/NoPvpProtectManager.java @@ -5,11 +5,13 @@ import java.util.List; import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.WorldGuardInterface; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockFromToEvent; @@ -18,6 +20,10 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; import org.bukkit.event.player.PlayerBucketEmptyEvent; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.flags.DefaultFlag; +import com.sk89q.worldguard.protection.flags.StateFlag.State; + public class NoPvpProtectManager { private PandacraftUtils plugin = PandacraftUtils.getInstance(); @@ -48,8 +54,6 @@ public class NoPvpProtectManager { public void onBlockPlace(BlockPlaceEvent event) { - if (event.getBlock().getWorld().getPVP()) - return; Material mat = event.getBlockPlaced().getType(); if (mat.equals(Material.LAVA) || mat.equals(Material.FIRE)) @@ -82,6 +86,9 @@ public class NoPvpProtectManager { if (OnlinePlayerManager.get(pl).isVanished()) continue; + + if (canPVPInLocation(pl.getLocation())) + continue; Location ent_loc = pl.getLocation(); if (ent_loc.distance(block_loc) < distance) @@ -103,8 +110,6 @@ public class NoPvpProtectManager { public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) { - if (event.getBlockClicked().getWorld().getPVP()) - return; if (event.getBucket() != null && event.getBucket() == Material.LAVA_BUCKET) { // on fait l'analyse pour le placement du bloc de lave @@ -125,6 +130,9 @@ public class NoPvpProtectManager { if (OnlinePlayerManager.get(pl).isVanished()) continue; + if (canPVPInLocation(pl.getLocation())) + continue; + Location ent_loc = pl.getLocation(); if (ent_loc.distance(block_loc) < distance) @@ -148,8 +156,6 @@ public class NoPvpProtectManager { if (event.getPlayer() == null) return; - if (event.getBlock().getWorld().getPVP()) - return; if (event.getCause() == IgniteCause.FIREBALL || event.getCause() == IgniteCause.FLINT_AND_STEEL) { // on fait l'analyse pour l'allumage avec un briquet @@ -169,6 +175,9 @@ public class NoPvpProtectManager { if (OnlinePlayerManager.get(pl).isVanished()) continue; + + if (canPVPInLocation(pl.getLocation())) + return; Location ent_loc = pl.getLocation(); if (ent_loc.distance(block_loc) < distance) @@ -190,8 +199,6 @@ public class NoPvpProtectManager { public void onBlockBreak(BlockBreakEvent event) { - if (event.getBlock().getWorld().getPVP()) - return; Player p = event.getPlayer(); Block b = event.getBlock(); @@ -209,6 +216,9 @@ public class NoPvpProtectManager { if (OnlinePlayerManager.get(pl).isVanished()) continue; + + if (canPVPInLocation(pl.getLocation())) + continue; Location pl_loc = pl.getLocation().getBlock().getLocation(); @@ -235,17 +245,15 @@ public class NoPvpProtectManager { public void onBlockFromTo(BlockFromToEvent event) { - if (event.getBlock().getWorld().getPVP()) - return; Block bf = event.getBlock(); Block bt = event.getToBlock(); Location loc_bt = bt.getLocation(); + List pls = bf.getWorld().getPlayers(); boolean player_standing = false; - String nearby_pl_aff = ""; // on fait le tour de tout les joueurs de la map for (Player pl : pls) { @@ -258,7 +266,9 @@ public class NoPvpProtectManager { Location pl_loc = pl.getLocation().getBlock().getLocation(); - + + if (canPVPInLocation(pl.getLocation())) + continue; // si la distance par rapport au joueur courant est > 5 bloc, on ignore @@ -286,7 +296,6 @@ public class NoPvpProtectManager { if ((new Location(pl_loc.getWorld(), x, y, z)).equals(loc_bt)) { player_standing = true; - nearby_pl_aff = nearby_pl_aff + " " + pl.getDisplayName(); } } @@ -296,5 +305,29 @@ public class NoPvpProtectManager { event.setCancelled(true); } } + + + + public boolean canPVPInLocation(Location l) { + if (!l.getWorld().getPVP()) + return false; + // ici le PVP est actif en mode vanilla + WorldGuardPlugin wg = WorldGuardInterface.getPlugin(); + if (wg == null) + return true; // pas de protection PVP de worldguard, donc le PVP est actif + State st = wg.getRegionManager(l.getWorld()).getApplicableRegions(l).getFlag(DefaultFlag.PVP); + + return (st != State.DENY); + } + + public boolean entitiesCanPVPBetweenThem(Entity... ent) { + for (Entity e : ent) { + if (e == null) + continue; + if (!canPVPInLocation(e.getLocation())) + return false; + } + return true; + } } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/protection/TamedEntityProtectManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/protection/TamedEntityProtectManager.java index 4123272..e660809 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/protection/TamedEntityProtectManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/protection/TamedEntityProtectManager.java @@ -6,6 +6,7 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager import org.bukkit.ChatColor; import org.bukkit.entity.AnimalTamer; +import org.bukkit.entity.Entity; import org.bukkit.entity.Horse; import org.bukkit.entity.Ocelot; import org.bukkit.entity.Player; @@ -17,14 +18,13 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.vehicle.VehicleEnterEvent; public class TamedEntityProtectManager { - @SuppressWarnings("unused") private PandacraftUtils plugin = PandacraftUtils.getInstance(); public void onEntityTame(EntityTameEvent event) { - if (event.getEntity().getWorld().getPVP()) return; + if (plugin.noPvpProtectManager.entitiesCanPVPBetweenThem((Entity)event.getEntity(), (Entity)event.getOwner())) return; if (!(event.getEntity() instanceof Tameable)) return; if (!(event.getOwner() instanceof Player)) return; @@ -39,7 +39,7 @@ public class TamedEntityProtectManager { public void onVehicleEnter(VehicleEnterEvent event) { - if (event.getVehicle().getWorld().getPVP()) return; + if (plugin.noPvpProtectManager.entitiesCanPVPBetweenThem((Entity)event.getEntered(), (Entity)event.getVehicle())) return; if (!isConcerned(event.getEntered(), event.getVehicle())) return; @@ -56,7 +56,7 @@ public class TamedEntityProtectManager { public void onEntityDamage(EntityDamageByEntityEvent event) { - if (event.getEntity().getWorld().getPVP()) return; + if (plugin.noPvpProtectManager.entitiesCanPVPBetweenThem((Entity)event.getDamager(), (Entity)event.getEntity())) return; if (!isConcerned(event.getDamager(), event.getEntity())) return; @@ -73,7 +73,6 @@ public class TamedEntityProtectManager { public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { - if (event.getPlayer().getWorld().getPVP()) return; if (!isConcerned(event.getPlayer(), event.getRightClicked())) return; @@ -84,6 +83,10 @@ public class TamedEntityProtectManager { event.getPlayer().sendMessage(ChatColor.GREEN+"Vous venez de sélectionner "+get_thisAnimal_Name(animal)); } + if (plugin.noPvpProtectManager.entitiesCanPVPBetweenThem((Entity)event.getPlayer(), (Entity)event.getRightClicked())) + return; + + if (animal.getOwner().equals(event.getPlayer())) return; event.setCancelled(true);