Prevent snow and ice from melting in arenas.

The block fade event is called when a block fades from one state to another, such as when snow melts and becomes air, or ice melts and becomes water. Cancelling it solves the issue of snow and ice melting in arenas.

Fixes #249.
This commit is contained in:
Andreas Troelsen 2018-07-19 02:01:41 +02:00
parent e484583b7e
commit 85687c86b5
2 changed files with 24 additions and 0 deletions

View File

@ -43,6 +43,7 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockEvent; import org.bukkit.event.block.BlockEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockIgniteEvent;
@ -334,6 +335,21 @@ public class ArenaListener
arena.addBlock(event.getBlock()); arena.addBlock(event.getBlock());
} }
public void onBlockFade(BlockFadeEvent event) {
if (!protect) {
return;
}
if (!arena.getRegion().contains(event.getBlock().getLocation())) {
return;
}
switch (event.getBlock().getType()) {
case ICE:
case SNOW:
event.setCancelled(true);
break;
}
}
/* /*
* TODO: Figure out a solution to this problem with soft-restore. * TODO: Figure out a solution to this problem with soft-restore.
* *

View File

@ -14,6 +14,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
@ -105,6 +106,13 @@ public class MAGlobalListener implements Listener
// arena.getEventListener().onBlockFromTo(event); // arena.getEventListener().onBlockFromTo(event);
// } // }
@EventHandler(priority = EventPriority.NORMAL)
public void blockFade(BlockFadeEvent event) {
for (Arena arena : am.getArenas()) {
arena.getEventListener().onBlockFade(event);
}
}
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void blockIgnite(BlockIgniteEvent event) { public void blockIgnite(BlockIgniteEvent event) {
for (Arena arena : am.getArenas()) for (Arena arena : am.getArenas())