Merge pull request #8 from utarwyn/1.6.x

Bug fix: item frame/armor stand protection
This commit is contained in:
Naman 2018-05-30 19:48:13 -05:00 committed by GitHub
commit e0183a90a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 0 deletions

View File

@ -411,6 +411,7 @@ public class Conf {
territoryDenyUseageMaterials.add(Material.BUCKET);
territoryDenyUseageMaterials.add(Material.WATER_BUCKET);
territoryDenyUseageMaterials.add(Material.LAVA_BUCKET);
territoryDenyUseageMaterials.add(Material.ARMOR_STAND);
territoryProtectedMaterialsWhenOffline.add(Material.WOODEN_DOOR);
territoryProtectedMaterialsWhenOffline.add(Material.TRAP_DOOR);
@ -437,6 +438,7 @@ public class Conf {
territoryDenyUseageMaterialsWhenOffline.add(Material.BUCKET);
territoryDenyUseageMaterialsWhenOffline.add(Material.WATER_BUCKET);
territoryDenyUseageMaterialsWhenOffline.add(Material.LAVA_BUCKET);
territoryDenyUseageMaterialsWhenOffline.add(Material.ARMOR_STAND);
safeZoneNerfedCreatureTypes.add(EntityType.BLAZE);
safeZoneNerfedCreatureTypes.add(EntityType.CAVE_SPIDER);

View File

@ -131,6 +131,39 @@ public class FactionsEntityListener implements Listener {
}
}
} else {
// Protect armor stands/item frames from being damaged in protected territories
if (damagee.getType() == EntityType.ITEM_FRAME || damagee.getType() == EntityType.ARMOR_STAND) {
// Manage projectiles launched by players
if (damager instanceof Projectile && ((Projectile) damager).getShooter() instanceof Entity) {
damager = (Entity) ((Projectile) damager).getShooter();
}
// Run the check for a player
if (damager instanceof Player) {
// Generate the action message.
String entityAction;
if (damagee.getType() == EntityType.ITEM_FRAME) {
entityAction = "item frames";
} else {
entityAction = "armor stands";
}
if (!FactionsBlockListener.playerCanBuildDestroyBlock((Player) damager, damagee.getLocation(), "destroy " + entityAction, false)) {
event.setCancelled(true);
}
} else {
// we don't want to let mobs/arrows destroy item frames/armor stands
// so we only have to run the check as if there had been an explosion at the damager location
if (!this.checkExplosionForBlock(damager, damagee.getLocation().getBlock())) {
event.setCancelled(true);
}
}
// we don't need to go after
return;
}
//this one should trigger if something other than a player takes damage
if (damager instanceof Player) {
// now itll only go here if the damage is dealt by a player
@ -584,6 +617,8 @@ public class FactionsEntityListener implements Listener {
public void onPaintingPlace(HangingPlaceEvent event) {
if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "place paintings", false)) {
event.setCancelled(true);
// Fix: update player's inventory to avoid items glitches
event.getPlayer().updateInventory();
}
}

View File

@ -658,6 +658,36 @@ public class FactionsPlayerListener implements Listener {
}
}
// For disabling interactions with item frames in another faction's territory
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
// only need to check for item frames
if (event.getRightClicked().getType() != EntityType.ITEM_FRAME) {
return;
}
Player player = event.getPlayer();
Entity entity = event.getRightClicked();
if (!FactionsBlockListener.playerCanBuildDestroyBlock(player, entity.getLocation(), "use item frames", false)) {
event.setCancelled(true);
}
}
// For disabling interactions with armor stands in another faction's territory
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
Entity entity = event.getRightClicked();
// only need to check for armor stand and item frames
if (entity.getType() != EntityType.ARMOR_STAND) {
return;
}
if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), entity.getLocation(), "use armor stands", false)) {
event.setCancelled(true);
}
}
// for handling people who repeatedly spam attempts to open a door (or similar) in another faction's territory
private Map<String, InteractAttemptSpam> interactSpammers = new HashMap<>();