Correction de bug : La protection non-PVP n'était pas actif quand le PVP est désactivé par un plugin, mais activé par le serveur Vanilla

This commit is contained in:
Marc Baloup 2015-09-30 00:55:21 +02:00
parent 20ea3cca17
commit 94f06589c4
2 changed files with 54 additions and 18 deletions

View File

@ -5,11 +5,13 @@ import java.util.List;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; 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.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockFromToEvent; 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.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.event.player.PlayerBucketEmptyEvent; 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 { public class NoPvpProtectManager {
private PandacraftUtils plugin = PandacraftUtils.getInstance(); private PandacraftUtils plugin = PandacraftUtils.getInstance();
@ -48,8 +54,6 @@ public class NoPvpProtectManager {
public void onBlockPlace(BlockPlaceEvent event) public void onBlockPlace(BlockPlaceEvent event)
{ {
if (event.getBlock().getWorld().getPVP())
return;
Material mat = event.getBlockPlaced().getType(); Material mat = event.getBlockPlaced().getType();
if (mat.equals(Material.LAVA) || mat.equals(Material.FIRE)) if (mat.equals(Material.LAVA) || mat.equals(Material.FIRE))
@ -83,6 +87,9 @@ public class NoPvpProtectManager {
if (OnlinePlayerManager.get(pl).isVanished()) if (OnlinePlayerManager.get(pl).isVanished())
continue; continue;
if (canPVPInLocation(pl.getLocation()))
continue;
Location ent_loc = pl.getLocation(); Location ent_loc = pl.getLocation();
if (ent_loc.distance(block_loc) < distance) if (ent_loc.distance(block_loc) < distance)
{ // un joueur autre que celui qui a pos§ est trop proche { // un joueur autre que celui qui a pos§ est trop proche
@ -103,8 +110,6 @@ public class NoPvpProtectManager {
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) { public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
if (event.getBlockClicked().getWorld().getPVP())
return;
if (event.getBucket() != null && event.getBucket() == Material.LAVA_BUCKET) if (event.getBucket() != null && event.getBucket() == Material.LAVA_BUCKET)
{ // on fait l'analyse pour le placement du bloc de lave { // on fait l'analyse pour le placement du bloc de lave
@ -125,6 +130,9 @@ public class NoPvpProtectManager {
if (OnlinePlayerManager.get(pl).isVanished()) if (OnlinePlayerManager.get(pl).isVanished())
continue; continue;
if (canPVPInLocation(pl.getLocation()))
continue;
Location ent_loc = pl.getLocation(); Location ent_loc = pl.getLocation();
if (ent_loc.distance(block_loc) < distance) if (ent_loc.distance(block_loc) < distance)
@ -148,8 +156,6 @@ public class NoPvpProtectManager {
if (event.getPlayer() == null) if (event.getPlayer() == null)
return; return;
if (event.getBlock().getWorld().getPVP())
return;
if (event.getCause() == IgniteCause.FIREBALL || event.getCause() == IgniteCause.FLINT_AND_STEEL) if (event.getCause() == IgniteCause.FIREBALL || event.getCause() == IgniteCause.FLINT_AND_STEEL)
{ // on fait l'analyse pour l'allumage avec un briquet { // on fait l'analyse pour l'allumage avec un briquet
@ -170,6 +176,9 @@ public class NoPvpProtectManager {
if (OnlinePlayerManager.get(pl).isVanished()) if (OnlinePlayerManager.get(pl).isVanished())
continue; continue;
if (canPVPInLocation(pl.getLocation()))
return;
Location ent_loc = pl.getLocation(); Location ent_loc = pl.getLocation();
if (ent_loc.distance(block_loc) < distance) if (ent_loc.distance(block_loc) < distance)
{ // un joueur autre que celui qui a pos§ est trop proche { // un joueur autre que celui qui a pos§ est trop proche
@ -190,8 +199,6 @@ public class NoPvpProtectManager {
public void onBlockBreak(BlockBreakEvent event) public void onBlockBreak(BlockBreakEvent event)
{ {
if (event.getBlock().getWorld().getPVP())
return;
Player p = event.getPlayer(); Player p = event.getPlayer();
Block b = event.getBlock(); Block b = event.getBlock();
@ -210,6 +217,9 @@ public class NoPvpProtectManager {
if (OnlinePlayerManager.get(pl).isVanished()) if (OnlinePlayerManager.get(pl).isVanished())
continue; continue;
if (canPVPInLocation(pl.getLocation()))
continue;
Location pl_loc = pl.getLocation().getBlock().getLocation(); Location pl_loc = pl.getLocation().getBlock().getLocation();
Location pl_loc_under = new Location(pl_loc.getWorld(), pl_loc.getX(), pl_loc.getY()-1, pl_loc.getZ()); Location pl_loc_under = new Location(pl_loc.getWorld(), pl_loc.getX(), pl_loc.getY()-1, pl_loc.getZ());
@ -235,17 +245,15 @@ public class NoPvpProtectManager {
public void onBlockFromTo(BlockFromToEvent event) public void onBlockFromTo(BlockFromToEvent event)
{ {
if (event.getBlock().getWorld().getPVP())
return;
Block bf = event.getBlock(); Block bf = event.getBlock();
Block bt = event.getToBlock(); Block bt = event.getToBlock();
Location loc_bt = bt.getLocation(); Location loc_bt = bt.getLocation();
List<Player> pls = bf.getWorld().getPlayers(); List<Player> pls = bf.getWorld().getPlayers();
boolean player_standing = false; boolean player_standing = false;
String nearby_pl_aff = "";
// on fait le tour de tout les joueurs de la map // on fait le tour de tout les joueurs de la map
for (Player pl : pls) for (Player pl : pls)
{ {
@ -259,6 +267,8 @@ public class NoPvpProtectManager {
Location pl_loc = pl.getLocation().getBlock().getLocation(); 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 // 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)) if ((new Location(pl_loc.getWorld(), x, y, z)).equals(loc_bt))
{ {
player_standing = true; player_standing = true;
nearby_pl_aff = nearby_pl_aff + " " + pl.getDisplayName();
} }
} }
@ -296,5 +305,29 @@ public class NoPvpProtectManager {
event.setCancelled(true); 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;
}
} }

View File

@ -6,6 +6,7 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Horse; import org.bukkit.entity.Horse;
import org.bukkit.entity.Ocelot; import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -17,14 +18,13 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent; import org.bukkit.event.vehicle.VehicleEnterEvent;
public class TamedEntityProtectManager { public class TamedEntityProtectManager {
@SuppressWarnings("unused")
private PandacraftUtils plugin = PandacraftUtils.getInstance(); private PandacraftUtils plugin = PandacraftUtils.getInstance();
public void onEntityTame(EntityTameEvent event) { 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.getEntity() instanceof Tameable)) return;
if (!(event.getOwner() instanceof Player)) return; if (!(event.getOwner() instanceof Player)) return;
@ -39,7 +39,7 @@ public class TamedEntityProtectManager {
public void onVehicleEnter(VehicleEnterEvent event) { 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; if (!isConcerned(event.getEntered(), event.getVehicle())) return;
@ -56,7 +56,7 @@ public class TamedEntityProtectManager {
public void onEntityDamage(EntityDamageByEntityEvent event) { 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; if (!isConcerned(event.getDamager(), event.getEntity())) return;
@ -73,7 +73,6 @@ public class TamedEntityProtectManager {
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (event.getPlayer().getWorld().getPVP()) return;
if (!isConcerned(event.getPlayer(), event.getRightClicked())) 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)); 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; if (animal.getOwner().equals(event.getPlayer())) return;
event.setCancelled(true); event.setCancelled(true);