Skip to content

Commit

Permalink
- Protect lily pads in towns from being destroyed by boats.
Browse files Browse the repository at this point in the history
    - Closes #6160.
  • Loading branch information
LlmDl committed Sep 8, 2022
1 parent 021502a commit 4ef476a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
4 changes: 3 additions & 1 deletion resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7751,4 +7751,6 @@ v0.92.0.11:
- Fix new reference file creation not working, courtesy of Warriorrrr with PR #6156.
- Use getPlayerExact for resident#getPlayer, courtesy of Warriorrrr with PR #6154.
0.98.3.9:
- Fix angry wolves not being attackable while in Towns when wolves are a protected entity.
- Fix angry wolves not being attackable while in Towns when wolves are a protected entity.
- Protect lily pads in towns from being destroyed by boats.
- Closes #6160.
39 changes: 26 additions & 13 deletions src/com/palmergames/bukkit/towny/listeners/TownyEntityListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Creature;
import org.bukkit.entity.DragonFireball;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -478,6 +479,7 @@ public void onEntityInteract(EntityInteractEvent event) {

}

@SuppressWarnings("deprecation")
/**
* Handles:
* Enderman thieving protected blocks.
Expand Down Expand Up @@ -513,28 +515,39 @@ public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
}
}

switch (event.getEntity().getType()) {

case ENDERMAN:
// Switch over name instead of EntityType to maintain pre-1.19 compatibility. (For chest_boats.)
switch (event.getEntity().getType().name()) {

case "ENDERMAN":
if (townyWorld.isEndermanProtect())
event.setCancelled(true);
break;

case RAVAGER:


/* Protect lily pads. */
case "BOAT", "CHEST_BOAT":
if (!event.getBlock().getType().equals(Material.LILY_PAD))
return;
Boat boat = (Boat) event.getEntity();
if (boat.getPassenger() != null && boat.getPassenger() instanceof Player player)
// Test if the player can break here.
event.setCancelled(!TownyActionEventExecutor.canDestroy(player, event.getBlock()));
else if (!TownyAPI.getInstance().isWilderness(event.getBlock()))
// Protect townland from non-player-ridden boats. (Maybe someone is pushing a boat?)
event.setCancelled(true);
break;

case "RAVAGER":
if (townyWorld.isDisableCreatureTrample())
event.setCancelled(true);
break;
case WITHER:

case "WITHER":
List<Block> allowed = TownyActionEventExecutor.filterExplodableBlocks(Collections.singletonList(event.getBlock()), event.getBlock().getType(), event.getEntity(), event);
event.setCancelled(allowed.isEmpty());
break;
/*
* Protect campfires from SplashWaterBottles. Uses a destroy test.
*/
case SPLASH_POTION:

/* Protect campfires from SplashWaterBottles. Uses a destroy test. */
case "SPLASH_POTION":
if (event.getBlock().getType() != Material.CAMPFIRE && ((ThrownPotion) event.getEntity()).getShooter() instanceof Player)
return;
event.setCancelled(!TownyActionEventExecutor.canDestroy((Player) ((ThrownPotion) event.getEntity()).getShooter(), event.getBlock().getLocation(), Material.CAMPFIRE));
Expand Down Expand Up @@ -656,7 +669,7 @@ public void onHangingBreak(HangingBreakEvent event) {
if (!TownyAPI.getInstance().isTownyWorld(event.getEntity().getWorld()))
return;

Entity hanging = event.getEntity();
Entity hanging = event.getEntity();
TownyWorld townyWorld = TownyAPI.getInstance().getTownyWorld(hanging.getWorld().getName());

// Prevent an item_frame or painting from breaking if it is attached to something which will be regenerated.
Expand Down

0 comments on commit 4ef476a

Please sign in to comment.