QUOTE: Be the change, make a difference.

Added block remove detection - poppy - A feature-rich Minecraft plugin which enhances gaming experience

poppy

A feature-rich Minecraft plugin which enhances gaming experience
git clone git://192.168.2.2/poppy
Log | Files | Refs | README

commit 960ec323e91e6d3129de29c93cbb69e6fe0a7abb
parent 68a8793325f2028e6f012c89d26d1776baec1c1e
Author: typable <typable.dev@gmail.com>
Date:   Sat,  5 Dec 2020 22:56:13 +0100

Added block remove detection
Diffstat:
Msrc/de/typable/minecrafthub/event/ChairListener.java | 41+++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+), 0 deletions(-)

diff --git a/src/de/typable/minecrafthub/event/ChairListener.java b/src/de/typable/minecrafthub/event/ChairListener.java @@ -1,5 +1,9 @@ package de.typable.minecrafthub.event; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -12,6 +16,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.util.Vector; import org.spigotmc.event.entity.EntityDismountEvent; @@ -21,6 +26,8 @@ public class ChairListener implements Listener { private static final Material[] CHAIR_TYPE = new Material[] { Material.OAK_STAIRS, Material.SPRUCE_STAIRS, Material.BIRCH_STAIRS, Material.JUNGLE_STAIRS, Material.ACACIA_STAIRS, Material.DARK_OAK_STAIRS, Material.ACACIA_STAIRS, Material.CRIMSON_STAIRS, Material.WARPED_STAIRS }; + private Map<Block, Arrow> blockMap = new HashMap<>(); + @SuppressWarnings("deprecation") @EventHandler public void onPlayerInteract(PlayerInteractEvent event) @@ -33,6 +40,11 @@ public class ChairListener implements Listener if(isChair(block.getType())) { + if(blockMap.containsKey(block)) + { + return; + } + Block upperBlock = block.getWorld().getBlockAt(block.getLocation().add(0, 1, 0)); if(upperBlock != null && upperBlock.getType() == Material.AIR) @@ -50,6 +62,8 @@ public class ChairListener implements Listener arrow.setPassenger((Entity) event.getPlayer()); event.setCancelled(true); + + blockMap.put(block, arrow); } } } @@ -66,11 +80,38 @@ public class ChairListener implements Listener if(entity != null && entity instanceof Arrow) { + if(blockMap.containsValue(entity)) + { + for(Entry<Block, Arrow> entry : blockMap.entrySet()) + { + if(entry.getValue() == entity) + { + blockMap.remove(entry.getKey()); + + break; + } + } + } + entity.remove(); } } } + @EventHandler + public void onBlockBreak(BlockBreakEvent event) + { + Block block = event.getBlock(); + + if(blockMap.containsKey(block)) + { + Arrow arrow = blockMap.get(block); + arrow.eject(); + + blockMap.remove(block); + } + } + private boolean isChair(Material material) { for(Material chair : CHAIR_TYPE)