Changed Explosion setting to Island and fixed explosion and mobgrief settings

This commit is contained in:
Fabrizio La Rosa 2020-06-17 01:58:57 +02:00
parent 8514c0233e
commit a186206d00
3 changed files with 131 additions and 37 deletions

View File

@ -27,6 +27,8 @@ import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import org.bukkit.event.player.PlayerShearEntityEvent; import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -109,7 +111,7 @@ public class Entity implements Listener {
skyblock.getPermissionManager() skyblock.getPermissionManager()
.processPermission(event, player, islandManager.getIslandAtLocation(player.getLocation())); .processPermission(event, player, islandManager.getIslandAtLocation(player.getLocation()));
} else if (event.getDamager() instanceof TNTPrimed) { } else { // Make it work with all the entities, not just TNT
org.bukkit.entity.Entity entity = event.getEntity(); org.bukkit.entity.Entity entity = event.getEntity();
// Check permissions. // Check permissions.
@ -217,6 +219,7 @@ public class Entity implements Listener {
@EventHandler @EventHandler
public void onHangingBreak(HangingBreakEvent event) { public void onHangingBreak(HangingBreakEvent event) {
Hanging hanging = event.getEntity(); Hanging hanging = event.getEntity();
if (!skyblock.getWorldManager().isIslandWorld(hanging.getWorld())) return; if (!skyblock.getWorldManager().isIslandWorld(hanging.getWorld())) return;
IslandManager islandManager = skyblock.getIslandManager(); IslandManager islandManager = skyblock.getIslandManager();
@ -229,14 +232,15 @@ public class Entity implements Listener {
public void onHangingBreak(HangingBreakByEntityEvent event) { public void onHangingBreak(HangingBreakByEntityEvent event) {
Hanging hanging = event.getEntity(); Hanging hanging = event.getEntity();
if (!(event.getRemover() instanceof Player))
return;
if (!skyblock.getWorldManager().isIslandWorld(hanging.getWorld())) return; if (!skyblock.getWorldManager().isIslandWorld(hanging.getWorld())) return;
IslandManager islandManager = skyblock.getIslandManager(); IslandManager islandManager = skyblock.getIslandManager();
Player p = null;
if(event.getRemover() instanceof Player){
p = (Player) event.getRemover();
}
// Check permissions. // Check permissions.
skyblock.getPermissionManager().processPermission(event, (Player) event.getRemover(), skyblock.getPermissionManager().processPermission(event, p,
islandManager.getIslandAtLocation(hanging.getLocation())); islandManager.getIslandAtLocation(hanging.getLocation()));
} }
@ -322,9 +326,11 @@ public class Entity implements Listener {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
// Check permissions. // Check permissions.
skyblock.getPermissionManager().processPermission(event, null, island); skyblock.getPermissionManager().processPermission(event, null, island);
if (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() if (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getBoolean("Island.Block.Level.Enable")) .getBoolean("Island.Block.Level.Enable"))
return; return;
@ -373,10 +379,10 @@ public class Entity implements Listener {
if (skyblock.getWorldManager().isIslandWorld(entity.getWorld())) { if (skyblock.getWorldManager().isIslandWorld(entity.getWorld())) {
// Check permissions. // Check permissions.
Island island = islandManager.getIslandAtLocation(entity.getLocation()); Island island = islandManager.getIslandAtLocation(entity.getLocation());
skyblock.getPermissionManager().processPermission(event, null, island); skyblock.getPermissionManager().processPermission(event, null, island);
if (!event.isCancelled()) { if (!event.isCancelled()) {
if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getBoolean("Island.Block.Level.Enable")) { .getBoolean("Island.Block.Level.Enable")) {
for (org.bukkit.block.Block blockList : event.blockList()) { for (org.bukkit.block.Block blockList : event.blockList()) {
@ -563,6 +569,22 @@ public class Entity implements Listener {
event.setCancelled(true); // For other plugin API reasons. event.setCancelled(true); // For other plugin API reasons.
} }
@EventHandler
public void onDamageVehicle(VehicleDamageEvent event) {
if (!(event.getAttacker() instanceof Player)) {
IslandManager islandManager = skyblock.getIslandManager();
skyblock.getPermissionManager().processPermission(event, null, islandManager.getIslandAtLocation(event.getVehicle().getLocation()));
}
}
@EventHandler
public void onDestroyVehicle(VehicleDestroyEvent event) {
if (!(event.getAttacker() instanceof Player)) {
IslandManager islandManager = skyblock.getIslandManager();
skyblock.getPermissionManager().processPermission(event, null, islandManager.getIslandAtLocation(event.getVehicle().getLocation()));
}
}
private static SpawnReason getSpawnReason(String reason) { private static SpawnReason getSpawnReason(String reason) {
try { try {
return SpawnReason.valueOf(reason); return SpawnReason.valueOf(reason);

View File

@ -1,53 +1,89 @@
package com.songoda.skyblock.permission.permissions.listening; package com.songoda.skyblock.permission.permissions.listening;
import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.CompatibleSound;
import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.permission.ListeningPermission; import com.songoda.skyblock.permission.ListeningPermission;
import com.songoda.skyblock.permission.PermissionHandler; import com.songoda.skyblock.permission.PermissionHandler;
import com.songoda.skyblock.permission.PermissionType; import com.songoda.skyblock.permission.PermissionType;
import org.bukkit.entity.Entity; import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType; import org.bukkit.entity.Creeper;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
public class ExplosionsPermission extends ListeningPermission { public class ExplosionsPermission extends ListeningPermission {
private SkyBlock plugin; private SkyBlock plugin;
public ExplosionsPermission(SkyBlock plugin) { public ExplosionsPermission(SkyBlock plugin) {
super("Explosions", CompatibleMaterial.GUNPOWDER, PermissionType.GENERIC); super("Explosions", CompatibleMaterial.GUNPOWDER, PermissionType.ISLAND);
this.plugin = plugin; this.plugin = plugin;
} }
@PermissionHandler @PermissionHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { public void onBlockExplode(BlockExplodeEvent event) {
Entity entity = event.getEntity(); event.setCancelled(true);
}
if (event.getDamager() instanceof TNTPrimed) @PermissionHandler
public void onEntityExplode(EntityExplodeEvent event) {
event.setCancelled(true);
}
@PermissionHandler
public void onVehicleDamage(VehicleDamageEvent event) {
if (event.getAttacker() instanceof TNTPrimed
|| event.getAttacker() instanceof ExplosiveMinecart
|| event.getAttacker() instanceof Creeper)
event.setCancelled(true); event.setCancelled(true);
if (entity.getType() == EntityType.PLAYER }
&& event.getDamager() instanceof TNTPrimed)
@PermissionHandler
public void onVehicleDestroy(VehicleDestroyEvent event) {
if (event.getAttacker() instanceof TNTPrimed
|| event.getAttacker() instanceof ExplosiveMinecart
|| event.getAttacker() instanceof Creeper)
event.setCancelled(true);
}
@PermissionHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)
|| event.getCause().equals(EntityDamageEvent.DamageCause.BLOCK_EXPLOSION)
|| event.getDamager() instanceof TNTPrimed
|| event.getDamager() instanceof ExplosiveMinecart
|| event.getDamager() instanceof Creeper)
event.setCancelled(true); event.setCancelled(true);
} }
@PermissionHandler @PermissionHandler
public void onHangingBreak(HangingBreakEvent event) { public void onHangingBreak(HangingBreakEvent event) {
if (event.getCause() != HangingBreakEvent.RemoveCause.EXPLOSION) if (event.getCause().equals(HangingBreakEvent.RemoveCause.EXPLOSION)) {
return; event.setCancelled(true);
}
event.setCancelled(true);
} }
@PermissionHandler @PermissionHandler
public void onBlockInteract(PlayerInteractEvent event) { public void onHangingBreak(HangingBreakByEntityEvent event) {
if (CompatibleMaterial.getMaterial(event.getPlayer().getItemInHand()) != CompatibleMaterial.FLINT_AND_STEEL) if(event.getCause().equals(HangingBreakEvent.RemoveCause.EXPLOSION)){
return; event.setCancelled(true);
}
}
CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getClickedBlock()); @PermissionHandler
if (material == CompatibleMaterial.TNT) public void onTNTInteract(PlayerInteractEvent event) {
if(event.getItem().getType().equals(CompatibleMaterial.FLINT_AND_STEEL.getMaterial())
&& event.getClickedBlock().getType().equals(CompatibleMaterial.TNT.getBlockMaterial())){
cancelAndMessage(event, event.getPlayer(), plugin, plugin.getMessageManager()); cancelAndMessage(event, event.getPlayer(), plugin, plugin.getMessageManager());
}
} }
} }

View File

@ -2,43 +2,79 @@ package com.songoda.skyblock.permission.permissions.listening;
import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.message.MessageManager;
import com.songoda.skyblock.permission.ListeningPermission; import com.songoda.skyblock.permission.ListeningPermission;
import com.songoda.skyblock.permission.PermissionHandler; import com.songoda.skyblock.permission.PermissionHandler;
import com.songoda.skyblock.permission.PermissionType; import com.songoda.skyblock.permission.PermissionType;
import org.bukkit.entity.*; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent; import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent;
public class MobGriefingPermission extends ListeningPermission { public class MobGriefingPermission extends ListeningPermission {
private final SkyBlock plugin; private final SkyBlock plugin;
private final MessageManager messageManager;
public MobGriefingPermission(SkyBlock plugin) { public MobGriefingPermission(SkyBlock plugin) {
super("MobGriefing", CompatibleMaterial.IRON_SHOVEL, PermissionType.ISLAND); super("MobGriefing", CompatibleMaterial.IRON_SHOVEL, PermissionType.ISLAND);
this.plugin = plugin; this.plugin = plugin;
this.messageManager = plugin.getMessageManager(); }
@PermissionHandler
public void onEntityExplode(EntityExplodeEvent event) {
if (!(event.getEntity() instanceof Player)
&& (!(event.getEntity() instanceof org.bukkit.entity.Projectile)
|| !(((org.bukkit.entity.Projectile) event.getEntity()).getShooter() instanceof Player))
&& !(event.getEntity() instanceof TNTPrimed)
&& !(event.getEntity() instanceof ExplosiveMinecart)) {
event.setCancelled(true);
}
} }
@PermissionHandler @PermissionHandler
public void onVehicleDamage(VehicleDamageEvent event) { public void onVehicleDamage(VehicleDamageEvent event) {
if (!(event.getAttacker() instanceof Player)
&& (!(event.getAttacker() instanceof org.bukkit.entity.Projectile)
Player player = (Player) event.getAttacker(); || !(((org.bukkit.entity.Projectile) event.getAttacker()).getShooter() instanceof Player))
cancelAndMessage(event, player, plugin, messageManager); && !(event.getAttacker() instanceof TNTPrimed)
&& !(event.getAttacker() instanceof ExplosiveMinecart)) {
event.setCancelled(true);
}
} }
@PermissionHandler @PermissionHandler
public void onVehicleDestroy(VehicleDestroyEvent event) { public void onVehicleDestroy(VehicleDestroyEvent event) {
if (!(event.getAttacker() instanceof Player)
&& (!(event.getAttacker() instanceof org.bukkit.entity.Projectile)
Player player = (Player) event.getAttacker(); || !(((org.bukkit.entity.Projectile) event.getAttacker()).getShooter() instanceof Player))
cancelAndMessage(event, player, plugin, messageManager); && !(event.getAttacker() instanceof TNTPrimed)
&& !(event.getAttacker() instanceof ExplosiveMinecart)) {
event.setCancelled(true);
}
} }
@PermissionHandler @PermissionHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player)
&& (!(event.getDamager() instanceof org.bukkit.entity.Projectile)
|| !(((org.bukkit.entity.Projectile) event.getDamager()).getShooter() instanceof Player))
&& !(event.getDamager() instanceof TNTPrimed)
&& !(event.getDamager() instanceof ExplosiveMinecart)) {
event.setCancelled(true);
}
}
@PermissionHandler
public void onHangingBreak(HangingBreakByEntityEvent event) {
if(!(event.getRemover() instanceof Player)){
event.setCancelled(true);
}
}
/*@PermissionHandler // TODO ? - Fabrimat
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
EntityType type = event.getEntityType(); EntityType type = event.getEntityType();
@ -53,6 +89,6 @@ public class MobGriefingPermission extends ListeningPermission {
else return; else return;
cancelAndMessage(event, player, plugin, messageManager); cancelAndMessage(event, player, plugin, messageManager);
} }*/
} }