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:
parent
20ea3cca17
commit
94f06589c4
@ -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<Player> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user