forked from Upstream/mmocore
Support for cobblestone generator (mining profession exp)
This commit is contained in:
parent
1596f7e964
commit
b50b365a30
@ -1,6 +1,5 @@
|
||||
package net.Indyuce.mmocore.listener;
|
||||
|
||||
import net.mmogroup.mmolib.UtilityMethods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@ -13,9 +12,11 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
@ -24,6 +25,7 @@ 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.mmogroup.mmolib.UtilityMethods;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
private static final BlockFace[] order = { BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH };
|
||||
@ -91,18 +93,21 @@ public class BlockListener implements Listener {
|
||||
CustomBlockMineEvent called = new CustomBlockMineEvent(PlayerData.get(player), block, info, canBreak);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
|
||||
if(called.isCancelled() || !called.canBreak()) {
|
||||
if (called.isCancelled() || !called.canBreak()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove vanilla drops if needed
|
||||
* Remove vanilla drops if needed and casts an ItemDamageEvent to handle
|
||||
* MMOItems durability. It does not apply specific durability loss based
|
||||
* on block/tool broken yet simple compatibility stuff
|
||||
*/
|
||||
if (!info.hasVanillaDrops()) {
|
||||
// event.setDropItems(false); // May not work
|
||||
event.setCancelled(true);
|
||||
event.getBlock().setType(Material.AIR);
|
||||
Bukkit.getPluginManager().callEvent(new PlayerItemDamageEvent(player, item, 1));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -137,13 +142,13 @@ public class BlockListener implements Listener {
|
||||
event.getBlock().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void blockPistonExtend(BlockPistonExtendEvent event) {
|
||||
Block movedBlock = event.getBlock();
|
||||
if (!movedBlock.hasMetadata("player_placed"))
|
||||
return;
|
||||
BlockFace direction = event.getDirection();
|
||||
//movedBlock = movedBlock.getRelative(direction, 2);
|
||||
// movedBlock = movedBlock.getRelative(direction, 2);
|
||||
|
||||
for (Block b : event.getBlocks())
|
||||
if (b.hasMetadata("player_placed")) {
|
||||
@ -152,7 +157,7 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void blockPistonRetract(BlockPistonRetractEvent event) {
|
||||
BlockFace direction = event.getDirection();
|
||||
Block movedBlock = event.getBlock().getRelative(direction);
|
||||
@ -164,6 +169,17 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Allows to mark cobblestone generated by cobblestone generators so that
|
||||
* exp is not gained by these blocks
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void cobblestoneGeneratorHandling(BlockFormEvent event) {
|
||||
if (event.getBlock().getType() == Material.WATER || event.getBlock().getType() == Material.LAVA)
|
||||
if (event.getNewState().getType() == Material.COBBLESTONE || event.getNewState().getType() == Material.OBSIDIAN)
|
||||
event.getNewState().setMetadata("player_placed", new FixedMetadataValue(MMOCore.plugin, true));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void handlePlayerStatistics(CustomBlockMineEvent event) {
|
||||
if (event.getBlockInfo().getBlock() instanceof VanillaBlockType)
|
||||
|
Loading…
Reference in New Issue
Block a user