mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-03-10 12:59:05 +01:00
Block regen now increments player statistics
This commit is contained in:
parent
3e8a83ba5c
commit
726d21cc7f
@ -16,6 +16,7 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
|
|||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
private final Block block;
|
private final Block block;
|
||||||
|
private final BlockInfo info;
|
||||||
private final List<ItemStack> drops;
|
private final List<ItemStack> drops;
|
||||||
private final ExperienceInfo experience;
|
private final ExperienceInfo experience;
|
||||||
|
|
||||||
@ -23,12 +24,25 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
|
|||||||
|
|
||||||
public CustomBlockMineEvent(PlayerData player, Block block, BlockInfo info) {
|
public CustomBlockMineEvent(PlayerData player, Block block, BlockInfo info) {
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
this.block = block;
|
this.block = block;
|
||||||
|
this.info = info;
|
||||||
this.drops = info.collectDrops(new LootBuilder(player, 0));
|
this.drops = info.collectDrops(new LootBuilder(player, 0));
|
||||||
this.experience = info.hasExperience() ? info.getExperience().newInfo() : null;
|
this.experience = info.hasExperience() ? info.getExperience().newInfo() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Block getBlock() {
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ItemStack> getDrops() {
|
||||||
|
return drops;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockInfo getBlockInfo() {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasGainedExperience() {
|
public boolean hasGainedExperience() {
|
||||||
return experience != null;
|
return experience != null;
|
||||||
}
|
}
|
||||||
@ -47,14 +61,6 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
|
|||||||
cancelled = value;
|
cancelled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Block getBlock() {
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ItemStack> getDrops() {
|
|
||||||
return drops;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Statistic;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -19,6 +20,7 @@ import org.bukkit.metadata.FixedMetadataValue;
|
|||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.block.BlockInfo;
|
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.event.CustomBlockMineEvent;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.manager.RestrictionManager.BlockPermissions;
|
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 };
|
private static final BlockFace[] order = { BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH };
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void a(BlockBreakEvent event) {
|
public void onCustomBreak(BlockBreakEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.getGameMode() == GameMode.CREATIVE)
|
if (player.getGameMode() == GameMode.CREATIVE)
|
||||||
return;
|
return;
|
||||||
@ -123,12 +125,12 @@ public class BlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void b(BlockPlaceEvent event) {
|
public void registerPlayerPlacedBlocksTag(BlockPlaceEvent event) {
|
||||||
event.getBlock().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true));
|
event.getBlock().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void c1(BlockPistonExtendEvent event) {
|
public void blockPistonExtend(BlockPistonExtendEvent event) {
|
||||||
Block movedBlock = event.getBlock();
|
Block movedBlock = event.getBlock();
|
||||||
if (!movedBlock.hasMetadata("player_placed"))
|
if (!movedBlock.hasMetadata("player_placed"))
|
||||||
return;
|
return;
|
||||||
@ -143,7 +145,7 @@ public class BlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void c2(BlockPistonRetractEvent event) {
|
public void blockPistonRetract(BlockPistonRetractEvent event) {
|
||||||
BlockFace direction = event.getDirection();
|
BlockFace direction = event.getDirection();
|
||||||
Block movedBlock = event.getBlock().getRelative(direction);
|
Block movedBlock = event.getBlock().getRelative(direction);
|
||||||
movedBlock.setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true));
|
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) {
|
private Location getSafeDropLocation(Block block, boolean self) {
|
||||||
if (block.getType() == Material.AIR && self)
|
if (block.getType() == Material.AIR && self)
|
||||||
return block.getLocation();
|
return block.getLocation();
|
||||||
|
Loading…
Reference in New Issue
Block a user