|
19 | 19 | import org.bukkit.event.hanging.HangingBreakEvent;
|
20 | 20 | import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause;
|
21 | 21 | import org.bukkit.event.hanging.HangingPlaceEvent;
|
| 22 | +import org.bukkit.event.player.PlayerInteractAtEntityEvent; |
| 23 | +import org.bukkit.event.player.PlayerInteractEntityEvent; |
22 | 24 | import org.bukkit.event.player.PlayerPortalEvent;
|
23 | 25 | import org.bukkit.potion.PotionEffect;
|
24 | 26 | import org.bukkit.potion.PotionEffectType;
|
@@ -132,6 +134,39 @@ public void onEntityDamage(EntityDamageEvent event) {
|
132 | 134 | }
|
133 | 135 | }
|
134 | 136 | } else {
|
| 137 | + // Protect armor stands/item frames from being damaged in protected territories |
| 138 | + if (damagee.getType() == EntityType.ITEM_FRAME || damagee.getType() == EntityType.ARMOR_STAND) { |
| 139 | + // Manage projectiles launched by players |
| 140 | + if (damager instanceof Projectile && ((Projectile) damager).getShooter() instanceof Entity) { |
| 141 | + damager = (Entity) ((Projectile) damager).getShooter(); |
| 142 | + } |
| 143 | + |
| 144 | + // Run the check for a player |
| 145 | + if (damager instanceof Player) { |
| 146 | + // Generate the action message. |
| 147 | + String entityAction; |
| 148 | + |
| 149 | + if (damagee.getType() == EntityType.ITEM_FRAME) { |
| 150 | + entityAction = "item frames"; |
| 151 | + } else { |
| 152 | + entityAction = "armor stands"; |
| 153 | + } |
| 154 | + |
| 155 | + if (!FactionsBlockListener.playerCanBuildDestroyBlock((Player) damager, damagee.getLocation(), "destroy " + entityAction, false)) { |
| 156 | + event.setCancelled(true); |
| 157 | + } |
| 158 | + } else { |
| 159 | + // we don't want to let mobs/arrows destroy item frames/armor stands |
| 160 | + // so we only have to run the check as if there had been an explosion at the damager location |
| 161 | + if (!this.checkExplosionForBlock(damager, damagee.getLocation().getBlock())) { |
| 162 | + event.setCancelled(true); |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + // we don't need to go after |
| 167 | + return; |
| 168 | + } |
| 169 | + |
135 | 170 | //this one should trigger if something other than a player takes damage
|
136 | 171 | if (damager instanceof Player) {
|
137 | 172 | // now itll only go here if the damage is dealt by a player
|
@@ -582,6 +617,8 @@ public void onPaintingBreak(HangingBreakEvent event) {
|
582 | 617 | public void onPaintingPlace(HangingPlaceEvent event) {
|
583 | 618 | if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "place paintings", false)) {
|
584 | 619 | event.setCancelled(true);
|
| 620 | + // Fix: update player's inventory to avoid items glitches |
| 621 | + event.getPlayer().updateInventory(); |
585 | 622 | }
|
586 | 623 | }
|
587 | 624 |
|
@@ -680,6 +717,37 @@ public void onBowHit(EntityDamageByEntityEvent e) {
|
680 | 717 | }
|
681 | 718 | }
|
682 | 719 |
|
| 720 | + // For disabling interactions with item frames in another faction's territory |
| 721 | + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) |
| 722 | + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { |
| 723 | + // only need to check for item frames |
| 724 | + if (event.getRightClicked().getType() != EntityType.ITEM_FRAME) { |
| 725 | + return; |
| 726 | + } |
| 727 | + |
| 728 | + Player player = event.getPlayer(); |
| 729 | + Entity entity = event.getRightClicked(); |
| 730 | + |
| 731 | + if (!FactionsBlockListener.playerCanBuildDestroyBlock(player, entity.getLocation(), "use item frames", false)) { |
| 732 | + event.setCancelled(true); |
| 733 | + } |
| 734 | + } |
| 735 | + |
| 736 | + // For disabling interactions with armor stands in another faction's territory |
| 737 | + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) |
| 738 | + public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { |
| 739 | + Entity entity = event.getRightClicked(); |
| 740 | + |
| 741 | + // only need to check for armor stand and item frames |
| 742 | + if (entity.getType() != EntityType.ARMOR_STAND) { |
| 743 | + return; |
| 744 | + } |
| 745 | + |
| 746 | + if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), entity.getLocation(), "use armor stands", false)) { |
| 747 | + event.setCancelled(true); |
| 748 | + } |
| 749 | + } |
| 750 | + |
683 | 751 | private boolean stopEndermanBlockManipulation(Location loc) {
|
684 | 752 | if (loc == null) {
|
685 | 753 | return false;
|
|
0 commit comments