From 726d21cc7fed09320254c61c8504f2b66ff88a88 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sat, 2 May 2020 13:21:01 +0200 Subject: [PATCH] Block regen now increments player statistics --- .../api/event/CustomBlockMineEvent.java | 24 ++++++++++++------- .../mmocore/listener/BlockListener.java | 16 +++++++++---- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/event/CustomBlockMineEvent.java b/src/main/java/net/Indyuce/mmocore/api/event/CustomBlockMineEvent.java index a72228d6..f73bb1ea 100644 --- a/src/main/java/net/Indyuce/mmocore/api/event/CustomBlockMineEvent.java +++ b/src/main/java/net/Indyuce/mmocore/api/event/CustomBlockMineEvent.java @@ -16,6 +16,7 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable private static final HandlerList handlers = new HandlerList(); private final Block block; + private final BlockInfo info; private final List drops; private final ExperienceInfo experience; @@ -23,12 +24,25 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable public CustomBlockMineEvent(PlayerData player, Block block, BlockInfo info) { super(player); - + this.block = block; + this.info = info; this.drops = info.collectDrops(new LootBuilder(player, 0)); this.experience = info.hasExperience() ? info.getExperience().newInfo() : null; } + public Block getBlock() { + return block; + } + + public List getDrops() { + return drops; + } + + public BlockInfo getBlockInfo() { + return info; + } + public boolean hasGainedExperience() { return experience != null; } @@ -47,14 +61,6 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable cancelled = value; } - public Block getBlock() { - return block; - } - - public List getDrops() { - return drops; - } - @Override public HandlerList getHandlers() { return handlers; diff --git a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java index fbbdbc01..8b75b615 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java @@ -4,6 +4,7 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Statistic; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; @@ -19,6 +20,7 @@ import org.bukkit.metadata.FixedMetadataValue; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.block.BlockInfo; +import net.Indyuce.mmocore.api.block.VanillaBlockType; import net.Indyuce.mmocore.api.event.CustomBlockMineEvent; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.manager.RestrictionManager.BlockPermissions; @@ -28,7 +30,7 @@ public class BlockListener implements Listener { private static final BlockFace[] order = { BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH }; @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void a(BlockBreakEvent event) { + public void onCustomBreak(BlockBreakEvent event) { Player player = event.getPlayer(); if (player.getGameMode() == GameMode.CREATIVE) return; @@ -123,12 +125,12 @@ public class BlockListener implements Listener { } @EventHandler(priority = EventPriority.HIGH) - public void b(BlockPlaceEvent event) { + public void registerPlayerPlacedBlocksTag(BlockPlaceEvent event) { event.getBlock().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true)); } @EventHandler - public void c1(BlockPistonExtendEvent event) { + public void blockPistonExtend(BlockPistonExtendEvent event) { Block movedBlock = event.getBlock(); if (!movedBlock.hasMetadata("player_placed")) return; @@ -143,7 +145,7 @@ public class BlockListener implements Listener { } @EventHandler - public void c2(BlockPistonRetractEvent event) { + public void blockPistonRetract(BlockPistonRetractEvent event) { BlockFace direction = event.getDirection(); Block movedBlock = event.getBlock().getRelative(direction); movedBlock.setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true)); @@ -154,6 +156,12 @@ public class BlockListener implements Listener { } } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void handlePlayerStatistics(CustomBlockMineEvent event) { + if (event.getBlockInfo().getBlock() instanceof VanillaBlockType) + event.getPlayer().incrementStatistic(Statistic.MINE_BLOCK, ((VanillaBlockType) event.getBlockInfo().getBlock()).getType()); + } + private Location getSafeDropLocation(Block block, boolean self) { if (block.getType() == Material.AIR && self) return block.getLocation();