diff --git a/pom.xml b/pom.xml
index ba04db8..d675622 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.nitnelave.CreeperHeal
CreeperHeal
- 7.0.5
+ 8.0.0
CreeperHeal
@@ -172,10 +172,10 @@
- org.spigotmc
- spigot-api
- 1.11-R0.1-SNAPSHOT
- provided
+ org.spigotmc
+ spigot-api
+ 1.16.3-R0.1-SNAPSHOT
+ provided
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/BlockId.java b/src/main/java/com/nitnelave/CreeperHeal/block/BlockId.java
index dd46835..1e85740 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/block/BlockId.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/block/BlockId.java
@@ -1,66 +1,34 @@
package com.nitnelave.CreeperHeal.block;
import org.bukkit.block.Block;
+import org.bukkit.Material;
/**
* A utility class to represent a block type along with optional data.
- *
+ *
* @author nitnelave
- *
+ *
*/
public class BlockId
{
- private int id;
- private byte data;
- private boolean hasData;
+ private Material type;
/**
* Only id is specified, data comparison accepts any value.
- *
+ *
* @param id
* The block id.
*/
- public BlockId(int id)
+ public BlockId(Material type)
{
- this(id, (byte) -1);
- }
-
- /**
- * Id and data are specified. If data == -1, then it is considered as
- * unspecified.
- *
- * @param id
- * The block id.
- * @param data
- * The block data.
- */
- public BlockId(int id, byte data)
- {
- this(id, data, data != -1);
- }
-
- /**
- * Id and data are specified, and hasData specifies if the data is used.
- *
- * @param id
- * The block id.
- * @param data
- * The block data.
- * @param hasData
- * Whether the data should be used in comparing.
- */
- public BlockId(int id, byte data, boolean hasData)
- {
- this.id = id;
- this.data = data;
- this.hasData = hasData && data != -1;
+ this.type = type;
}
/**
* Constructor from string. The string is parsed in an attempt to get the
* info. The string format accepted is a simple number for just the id, or
* id:data for both.
- *
+ *
* @param str
* The string to be parsed.
* @throws NumberFormatException
@@ -68,84 +36,39 @@ public BlockId(int id, byte data, boolean hasData)
*/
public BlockId(String str) throws NumberFormatException
{
- String res = str.trim();
- try
- {
- id = Integer.parseInt(res);
- data = -1;
- hasData = false;
- } catch (NumberFormatException e)
- {
- String[] split = res.split(":");
- if (split.length == 2)
- {
- id = Integer.parseInt(split[0]);
- data = Byte.parseByte(split[1]);
- hasData = true;
- }
- else
- throw new NumberFormatException();
- }
+ type = Material.valueOf(str.trim());
}
/**
* Get the id and data from a block.
- *
+ *
* @param block
* The block.
*/
public BlockId(Block block)
{
- this(block.getTypeId(), block.getData());
+ this(block.getType());
}
- /**
- * Get the id stored.
- *
- * @return The id stored.
- */
- public int getId()
- {
- return id;
- }
-
- /**
- * Get the block data. Check for hasData first.
- *
- * @return The block data.
- */
- public byte getData()
+ public Material getType()
{
- return data;
- }
-
- /**
- * Whether the block's data is used in comparing.
- *
- * @return Whether the block's data is used in comparing.
- */
- public boolean hasData()
- {
- return hasData;
+ return type;
}
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
- String str = String.valueOf(id);
- if (hasData)
- str += ":" + String.valueOf(data);
- return str;
+ return getType().toString();
}
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -158,23 +81,17 @@ public boolean equals(Object obj)
return false;
BlockId block = (BlockId) obj;
- if (block.id != id)
- return false;
- //same id
- if (!(block.hasData && hasData))
- return true;
- //both have data
- return block.data == data;
+ return block.type == type;
}
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode()
{
- return id;
+ return type.hashCode();
}
}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperBanner.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperBanner.java
deleted file mode 100644
index 7d46ed6..0000000
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperBanner.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.nitnelave.CreeperHeal.block;
-
-import com.nitnelave.CreeperHeal.config.CreeperConfig;
-import org.bukkit.Bukkit;
-import org.bukkit.block.Banner;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.meta.BannerMeta;
-
-/**
- * Banner implementation of CreeperBlock.
- *
- * @author drexplosionpd
- */
-public class CreeperBanner extends CreeperBlock
-{
-
- /*
- * Constructor.
- */
- CreeperBanner(Banner banner)
- {
- super(banner);
- }
-
- /*
- * @see com.nitnelave.CreeperHeal.block.Replaceable#drop(boolean)
- */
- @Override
- public boolean drop(boolean forced)
- {
- if (forced || CreeperConfig.shouldDrop())
- {
- ItemStack itemStack = new ItemStack(blockState.getType());
- BannerMeta bannerMeta = ((BannerMeta) Bukkit.getItemFactory().getItemMeta(blockState.getType()));
- bannerMeta.setPatterns(((Banner) blockState).getPatterns());
- itemStack.setItemMeta(bannerMeta);
- blockState.getWorld().dropItemNaturally(blockState.getLocation().add(0.5, 0.5, 0.5), itemStack);
- return true;
- }
- return false;
- }
-
-}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperBed.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperBed.java
index 12571c8..1fb7453 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperBed.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperBed.java
@@ -4,83 +4,42 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
-import org.bukkit.material.Bed;
+import org.bukkit.block.data.type.Bed;
import java.util.ArrayList;
import java.util.List;
/**
* Bed implementation of CreeperBlock.
- *
+ *
* @author nitnelave
- *
+ *
*/
-class CreeperBed extends CreeperBlock
+class CreeperBed extends CreeperMultiblock
{
-
- /*
- * The direction the bed is facing.
- */
- private final BlockFace orientation;
-
+ private final Bed bedData;
/*
* Constructor.
*/
CreeperBed(BlockState blockState)
{
super(blockState);
- Bed bedData = castData(blockState, Bed.class);
- orientation = bedData.getFacing();
+ Bed bedData = (Bed) blockData;
Block block = blockState.getBlock();
- if (!bedData.isHeadOfBed())
- block = block.getRelative(orientation);
+ if (bedData.getPart() == Bed.Part.FOOT) {
+ addDependent(block.getState());
+ block = block.getRelative(bedData.getFacing());
+ } else {
+ addDependent(block.getRelative(bedData.getFacing().getOppositeFace()).getState());
+ }
this.blockState = block.getState();
- }
-
- /**
- * The blockstate is always the head of the bed, this gets the foot.
- *
- * @return the foot of the bed.
- */
- public Block getFoot()
- {
- return getBlock().getRelative(orientation.getOppositeFace());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.nitnelave.CreeperHeal.block.CreeperBlock#update()
- */
- @Override
- public void update()
- {
- super.update();
- Block foot = getFoot();
- foot.setType(Material.BED_BLOCK, false);
- BlockState fs = foot.getState();
- Bed d = castData(blockState, Bed.class);
- d.setHeadOfBed(false);
- d.setFacingDirection(orientation);
- fs.setData(d);
- fs.update(true, false);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.nitnelave.CreeperHeal.block.CreeperBlock#remove()
- */
- @Override
- public void remove()
- {
- getFoot().setType(Material.AIR, false);
- getBlock().setType(Material.AIR, false);
+ this.blockData = block.getState().getBlockData();
+ this.bedData = (Bed)this.blockData;
}
/*
* (non-Javadoc)
- *
+ *
* @see com.nitnelave.CreeperHeal.block.CreeperBlock#getNeighbors()
*/
@Override
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperDoor.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperBisected.java
similarity index 55%
rename from src/main/java/com/nitnelave/CreeperHeal/block/CreeperDoor.java
rename to src/main/java/com/nitnelave/CreeperHeal/block/CreeperBisected.java
index d2fd86f..6a52fc8 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperDoor.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperBisected.java
@@ -3,45 +3,39 @@
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.material.Door;
+import org.bukkit.block.data.Bisected;
import java.util.ArrayList;
import java.util.List;
/**
- * Door implementation of the CreeperBlock.
+ * Bisected block implementation of the CreeperBlock.
*
* @author nitnelave
*
*/
-class CreeperDoor extends CreeperMultiblock
+class CreeperBisected extends CreeperMultiblock
{
/*
* Constructor.
*/
- CreeperDoor(BlockState blockState)
+ CreeperBisected(BlockState blockState, Bisected bisected)
{
super(blockState);
- Door data = castData(blockState, Door.class);
-
- if (data.isTopHalf())
+
+ if (bisected.getHalf() == Bisected.Half.TOP)
{
BlockState bottom = blockState.getBlock().getRelative(BlockFace.DOWN).getState();
- if (bottom.getData() instanceof Door && !((Door) bottom.getData()).isTopHalf())
- {
- this.blockState = bottom;
- this.dependents.add(blockState);
- }
+ this.blockState = bottom;
+ this.blockData = bottom.getBlockData();
+ addDependent(blockState);
}
else
{
BlockState top = blockState.getBlock().getRelative(BlockFace.UP).getState();
- if (top.getData() instanceof Door && ((Door) top.getData()).isTopHalf())
- {
- this.blockState = blockState;
- this.dependents.add(top);
- }
-
+ addDependent(top);
+
}
}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperBlock.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperBlock.java
index 2cfd413..4a06701 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperBlock.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperBlock.java
@@ -11,9 +11,10 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
+import org.bukkit.block.data.BlockData;
+import org.bukkit.block.data.Bisected;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.Jukebox;
-import org.bukkit.block.NoteBlock;
import org.bukkit.block.ShulkerBox;
import org.bukkit.block.Sign;
import org.bukkit.inventory.InventoryHolder;
@@ -40,41 +41,187 @@ public class CreeperBlock implements Replaceable
/*
* Blocks a player can breathe in and that are replaced by other blocks.
*/
- private final static Set EMPTY_BLOCKS =
- CreeperUtils.createFinalHashSet(Material.AIR, Material.WATER, Material.STATIONARY_WATER,
- Material.LAVA, Material.STATIONARY_LAVA, Material.FIRE, Material.SNOW);
+ private final static Set EMPTY_BLOCKS = CreeperUtils.createFinalHashSet(Material.AIR,
+ Material.WATER, Material.LAVA, Material.FIRE, Material.SNOW);
/*
* These blocks (may) need a block under them not to drop.
*/
private final static Set DEPENDENT_DOWN_BLOCKS =
- CreeperUtils.createFinalHashSet(Material.SAPLING, Material.BED_BLOCK, Material.POWERED_RAIL,
- Material.DETECTOR_RAIL, Material.LONG_GRASS, Material.DEAD_BUSH,
- Material.YELLOW_FLOWER, Material.RED_ROSE, Material.BROWN_MUSHROOM,
+ CreeperUtils.createFinalHashSet(
+ Material.ACACIA_SAPLING,
+ Material.BAMBOO_SAPLING,
+ Material.BIRCH_SAPLING,
+ Material.DARK_OAK_SAPLING,
+ Material.JUNGLE_SAPLING,
+ Material.OAK_SAPLING,
+ Material.SPRUCE_SAPLING,
+ Material.POWERED_RAIL,
+
+ Material.WHITE_CARPET,
+ Material.ORANGE_CARPET,
+ Material.MAGENTA_CARPET,
+ Material.LIGHT_BLUE_CARPET,
+ Material.YELLOW_CARPET,
+ Material.LIME_CARPET,
+ Material.PINK_CARPET,
+ Material.GRAY_CARPET,
+ Material.LIGHT_GRAY_CARPET,
+ Material.CYAN_CARPET,
+ Material.PURPLE_CARPET,
+ Material.BLUE_CARPET,
+ Material.BROWN_CARPET,
+ Material.GREEN_CARPET,
+ Material.RED_CARPET,
+ Material.BLACK_CARPET,
+
+ Material.WHITE_BANNER,
+ Material.ORANGE_BANNER,
+ Material.MAGENTA_BANNER,
+ Material.LIGHT_BLUE_BANNER,
+ Material.YELLOW_BANNER,
+ Material.LIME_BANNER,
+ Material.PINK_BANNER,
+ Material.GRAY_BANNER,
+ Material.LIGHT_GRAY_BANNER,
+ Material.CYAN_BANNER,
+ Material.PURPLE_BANNER,
+ Material.BLUE_BANNER,
+ Material.BROWN_BANNER,
+ Material.GREEN_BANNER,
+ Material.RED_BANNER,
+ Material.BLACK_BANNER,
+
+ Material.DANDELION,
+ Material.POPPY,
+ Material.BLUE_ORCHID,
+ Material.ALLIUM,
+ Material.AZURE_BLUET,
+ Material.RED_TULIP,
+ Material.ORANGE_TULIP,
+ Material.WHITE_TULIP,
+ Material.PINK_TULIP,
+ Material.OXEYE_DAISY,
+ Material.CORNFLOWER,
+ Material.LILY_OF_THE_VALLEY,
+ Material.WITHER_ROSE,
+ Material.SUNFLOWER,
+ Material.LILAC,
+ Material.ROSE_BUSH,
+ Material.PEONY,
+
+ Material.ACACIA_SIGN,
+ Material.BIRCH_SIGN,
+ Material.DARK_OAK_SIGN,
+ Material.JUNGLE_SIGN,
+ Material.OAK_SIGN,
+ Material.SPRUCE_SIGN,
+ Material.WARPED_SIGN,
+ Material.CRIMSON_SIGN,
+
+ Material.ACACIA_PRESSURE_PLATE,
+ Material.BIRCH_PRESSURE_PLATE,
+ Material.DARK_OAK_PRESSURE_PLATE,
+ Material.JUNGLE_PRESSURE_PLATE,
+ Material.OAK_PRESSURE_PLATE,
+ Material.SPRUCE_PRESSURE_PLATE,
+ Material.WARPED_PRESSURE_PLATE,
+ Material.CRIMSON_PRESSURE_PLATE,
+
+ Material.ACACIA_DOOR,
+ Material.BIRCH_DOOR,
+ Material.DARK_OAK_DOOR,
+ Material.JUNGLE_DOOR,
+ Material.OAK_DOOR,
+ Material.SPRUCE_DOOR,
+ Material.WARPED_DOOR,
+ Material.CRIMSON_DOOR,
+ Material.DETECTOR_RAIL, Material.TALL_GRASS, Material.DEAD_BUSH,
+ Material.BROWN_MUSHROOM,
Material.RED_MUSHROOM, Material.REDSTONE_WIRE, Material.WHEAT,
- Material.SIGN_POST, Material.WOODEN_DOOR,
- Material.RAILS, Material.STONE_PLATE,
- Material.IRON_DOOR_BLOCK, Material.WOOD_PLATE, Material.SNOW,
- Material.CACTUS, Material.SUGAR_CANE, Material.SUGAR_CANE_BLOCK,
- Material.DIODE_BLOCK_OFF, Material.DIODE_BLOCK_ON, Material.PUMPKIN_STEM,
- Material.MELON_STEM, Material.WATER_LILY, Material.NETHER_WART_BLOCK,
- Material.NETHER_WARTS,
+
+ Material.RAIL, Material.POLISHED_BLACKSTONE_PRESSURE_PLATE, Material.STONE_PRESSURE_PLATE,
+ Material.IRON_DOOR, Material.SNOW,
+ Material.CACTUS, Material.SUGAR_CANE,
+ Material.REPEATER, Material.PUMPKIN_STEM,
+ Material.MELON_STEM, Material.LILY_PAD, Material.NETHER_WART_BLOCK,
+ Material.NETHER_WART,
Material.BREWING_STAND, Material.TRIPWIRE, Material.FLOWER_POT,
- Material.CARROT, Material.POTATO, Material.GOLD_PLATE, Material.IRON_PLATE,
- Material.REDSTONE_COMPARATOR_OFF, Material.REDSTONE_COMPARATOR_ON,
- Material.ACTIVATOR_RAIL, Material.CARPET, Material.DOUBLE_PLANT,
- Material.STANDING_BANNER, Material.SPRUCE_DOOR, Material.BIRCH_DOOR,
- Material.JUNGLE_DOOR, Material.ACACIA_DOOR, Material.DARK_OAK_DOOR,
+ Material.CARROT, Material.POTATO, Material.HEAVY_WEIGHTED_PRESSURE_PLATE, Material.LIGHT_WEIGHTED_PRESSURE_PLATE,
+ Material.COMPARATOR,
+ Material.ACTIVATOR_RAIL,
+
Material.CHORUS_PLANT, Material.CHORUS_FLOWER,
- Material.BEETROOT_BLOCK);
+ Material.BEETROOTS);
/*
* These blocks are dependent on another block
*/
private final static Set DEPENDENT_BLOCKS =
- CreeperUtils.createFinalHashSet(Material.TORCH, Material.LADDER, Material.WALL_SIGN, Material.LEVER,
- Material.REDSTONE_TORCH_OFF, Material.REDSTONE_TORCH_ON,
- Material.STONE_BUTTON, Material.TRAP_DOOR, Material.VINE, Material.COCOA,
- Material.TRIPWIRE_HOOK, Material.WOOD_BUTTON, Material.IRON_TRAPDOOR,
- Material.WALL_BANNER);
+ CreeperUtils.createFinalHashSet(Material.TORCH, Material.LADDER, Material.LEVER,
+ Material.REDSTONE_TORCH,
+ Material.STONE_BUTTON, Material.VINE, Material.COCOA,
+ Material.ACACIA_TRAPDOOR,
+ Material.BIRCH_TRAPDOOR,
+ Material.DARK_OAK_TRAPDOOR,
+ Material.JUNGLE_TRAPDOOR,
+ Material.OAK_TRAPDOOR,
+ Material.SPRUCE_TRAPDOOR,
+ Material.WARPED_TRAPDOOR,
+ Material.CRIMSON_TRAPDOOR,
+
+ Material.WHITE_BED,
+ Material.ORANGE_BED,
+ Material.MAGENTA_BED,
+ Material.LIGHT_BLUE_BED,
+ Material.YELLOW_BED,
+ Material.LIME_BED,
+ Material.PINK_BED,
+ Material.GRAY_BED,
+ Material.LIGHT_GRAY_BED,
+ Material.CYAN_BED,
+ Material.PURPLE_BED,
+ Material.BLUE_BED,
+ Material.BROWN_BED,
+ Material.GREEN_BED,
+ Material.RED_BED,
+ Material.BLACK_BED,
+
+ Material.ACACIA_WALL_SIGN,
+ Material.BIRCH_WALL_SIGN,
+ Material.DARK_OAK_WALL_SIGN,
+ Material.JUNGLE_WALL_SIGN,
+ Material.OAK_WALL_SIGN,
+ Material.SPRUCE_WALL_SIGN,
+ Material.WARPED_WALL_SIGN,
+ Material.CRIMSON_WALL_SIGN,
+ Material.ACACIA_BUTTON,
+ Material.BIRCH_BUTTON,
+ Material.DARK_OAK_BUTTON,
+ Material.JUNGLE_BUTTON,
+ Material.OAK_BUTTON,
+ Material.SPRUCE_BUTTON,
+ Material.WARPED_BUTTON,
+ Material.CRIMSON_BUTTON,
+
+ Material.WHITE_WALL_BANNER,
+ Material.ORANGE_WALL_BANNER,
+ Material.MAGENTA_WALL_BANNER,
+ Material.LIGHT_BLUE_WALL_BANNER,
+ Material.YELLOW_WALL_BANNER,
+ Material.LIME_WALL_BANNER,
+ Material.PINK_WALL_BANNER,
+ Material.GRAY_WALL_BANNER,
+ Material.LIGHT_GRAY_WALL_BANNER,
+ Material.CYAN_WALL_BANNER,
+ Material.PURPLE_WALL_BANNER,
+ Material.BLUE_WALL_BANNER,
+ Material.BROWN_WALL_BANNER,
+ Material.GREEN_WALL_BANNER,
+ Material.RED_WALL_BANNER,
+ Material.BLACK_WALL_BANNER,
+
+ Material.PISTON_HEAD,
+
+ Material.TRIPWIRE_HOOK, Material.IRON_TRAPDOOR);
public final static BlockFace[] CARDINALS = { BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST,
BlockFace.NORTH, BlockFace.UP, BlockFace.DOWN };
@@ -85,6 +232,7 @@ public class CreeperBlock implements Replaceable
* The block represented.
*/
BlockState blockState;
+ BlockData blockData;
/**
* Create a new CreeperBlock of the right class. Factory method that should
@@ -100,65 +248,56 @@ public static CreeperBlock newBlock(BlockState state)
if (state instanceof ShulkerBox)
return new CreeperShulkerBox((ShulkerBox) state);
if (state instanceof InventoryHolder)
- return new CreeperContainer(state);
- if (state instanceof Jukebox)
- return new CreeperJukebox((Jukebox) state);
+ return new CreeperContainer((InventoryHolder)state);
+ //if (state instanceof Jukebox)
+ // return new CreeperJukebox((Jukebox) state);
+ if (state.getBlockData() instanceof Bisected)
+ return new CreeperBisected(state, (Bisected) state.getBlockData());
if (state.getType().hasGravity())
return new CreeperPhysicsBlock(state);
switch (state.getType())
{
- case BED_BLOCK:
+ case WHITE_BED:
+ case ORANGE_BED:
+ case MAGENTA_BED:
+ case LIGHT_BLUE_BED:
+ case YELLOW_BED:
+ case LIME_BED:
+ case PINK_BED:
+ case GRAY_BED:
+ case LIGHT_GRAY_BED:
+ case CYAN_BED:
+ case PURPLE_BED:
+ case BLUE_BED:
+ case BROWN_BED:
+ case GREEN_BED:
+ case RED_BED:
+ case BLACK_BED:
return new CreeperBed(state);
- case DOUBLE_PLANT:
- return new CreeperFlower(state);
- case RAILS:
- case POWERED_RAIL:
- case DETECTOR_RAIL:
- return new CreeperRail(state);
- case SKULL:
- return new CreeperHead(state);
- case PISTON_BASE:
- case PISTON_STICKY_BASE:
- case PISTON_EXTENSION:
- return new CreeperPiston(state);
- case WOODEN_DOOR:
- case ACACIA_DOOR:
- case BIRCH_DOOR:
- case DARK_OAK_DOOR:
- case JUNGLE_DOOR:
- case SPRUCE_DOOR:
- case IRON_DOOR_BLOCK:
- return new CreeperDoor(state);
- case NOTE_BLOCK:
- return new CreeperNoteBlock((NoteBlock) state);
- case SIGN_POST:
- case WALL_SIGN:
- return new CreeperSign((Sign) state);
- case MOB_SPAWNER:
- return new CreeperMonsterSpawner((CreatureSpawner) state);
- case WOOD_PLATE:
- case GOLD_PLATE:
- case IRON_PLATE:
- case STONE_PLATE:
- return new CreeperPlate(state);
- case GRASS:
- return new CreeperGrass(state);
- case SMOOTH_BRICK:
- case SMOOTH_STAIRS:
- return new CreeperBrick(state);
- case WOOD_BUTTON:
- case STONE_BUTTON:
- return new CreeperButton(state);
- case FIRE:
- case AIR:
- return null;
- case STANDING_BANNER:
- case WALL_BANNER:
- return new CreeperBanner((Banner) state);
- case STONE:
- return new CreeperStone(state);
- default:
- return new CreeperBlock(state);
+ case RAIL:
+ case POWERED_RAIL:
+ case DETECTOR_RAIL:
+ return new CreeperRail(state);
+ case PISTON:
+ case PISTON_HEAD:
+ case STICKY_PISTON:
+ return new CreeperPiston(state);
+ case GRASS:
+ return new CreeperGrass(state);
+
+ /*
+ case SMOOTH_BRICK:
+ case SMOOTH_STAIRS:
+ return new CreeperBrick(state);
+ */
+ case STONE:
+ return new CreeperStone(state);
+ case FIRE:
+ case AIR:
+ case TNT:
+ return null;
+ default:
+ return new CreeperBlock(state);
}
}
@@ -168,6 +307,7 @@ public static CreeperBlock newBlock(BlockState state)
CreeperBlock(BlockState blockState)
{
this.blockState = blockState;
+ this.blockData = blockState.getBlockData();
}
/*
@@ -176,7 +316,7 @@ public static CreeperBlock newBlock(BlockState state)
*/
static boolean isEmpty(Material type)
{
- return EMPTY_BLOCKS.contains(type);
+ return type.isAir() || EMPTY_BLOCKS.contains(type);
}
/*
@@ -253,9 +393,19 @@ public static boolean isDependent(Material type)
* Replace the block in the world.
*/
public void update()
+ {
+ update(true);
+ }
+
+ protected void update(boolean physics) {
+ update(blockData, physics);
+ }
+
+ protected void update(BlockData blockData, boolean physics)
{
getLocation().getChunk().load();
- blockState.update(true, false);
+ getBlock().setBlockData(blockData, physics);
+ if (physics) getBlock().getState().update(true);
getWorld().playSound(getLocation(), CreeperConfig.getSound(), CreeperConfig.getInt(CfgVal.SOUND_VOLUME) / 10F, random.nextFloat() * 2);
}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperButton.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperButton.java
deleted file mode 100644
index 4f115d9..0000000
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperButton.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.nitnelave.CreeperHeal.block;
-
-import org.bukkit.block.BlockState;
-
-public class CreeperButton extends CreeperBlock
-{
-
- protected CreeperButton(BlockState b)
- {
- super(b);
-
- b.setRawData((byte) (b.getRawData() & 7));
- }
-}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperContainer.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperContainer.java
index b45ae69..bfd1046 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperContainer.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperContainer.java
@@ -21,11 +21,11 @@ class CreeperContainer extends CreeperMultiblock
private ItemStack[] storedInventory, neighborInventory = null;
- CreeperContainer(BlockState blockState)
+ CreeperContainer(InventoryHolder blockState)
{
- super(blockState);
+ super((BlockState)blockState);
- Inventory inv = ((InventoryHolder) blockState).getInventory();
+ Inventory inv = blockState.getInventory();
storedInventory = inv.getContents();
if ((inv instanceof DoubleChestInventory))
@@ -37,7 +37,7 @@ class CreeperContainer extends CreeperMultiblock
// Left side is primary chest inventory
this.blockState = doubleChest.getLeftSide().getLocation().getBlock().getState();
- this.dependents.add(right);
+ addDependent(right);
this.storedInventory = doubleChest.getLeftSide().getContents();
this.neighborInventory = doubleChest.getRightSide().getContents();
@@ -58,7 +58,7 @@ public void remove()
}
((InventoryHolder) blockState).getInventory().clear();
- for (BlockState dependent : dependents)
+ for (BlockStateAndData dependent : getDependents())
if (dependent instanceof InventoryHolder)
((InventoryHolder) dependent).getInventory().clear();
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperExplosion.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperExplosion.java
index ffc9d61..af3c853 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperExplosion.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperExplosion.java
@@ -19,9 +19,9 @@
/**
* Represents an explosion, with the list of blocks destroyed, the time of the
* explosion, and the radius.
- *
+ *
* @author nitnelave
- *
+ *
*/
public class CreeperExplosion
{
@@ -38,7 +38,7 @@ public class CreeperExplosion
/**
* Constructor.
- *
+ *
* @param loc
* The location of the explosion.
*/
@@ -54,7 +54,7 @@ public CreeperExplosion(Location loc)
/**
* Add blocks to an explosion, and reset the timer to the time of the last
* explosion.
- *
+ *
* @param blocks
* The list of blocks to add.
*/
@@ -79,7 +79,7 @@ public void addBlocks(List blocks, Location newLoc)
/**
* Get the time of the explosion.
- *
+ *
* @return The time of the explosion.
*/
public Date getTime()
@@ -103,7 +103,7 @@ private double computeRadius()
/**
* Get the location of the explosion.
- *
+ *
* @return The location of the explosion.
*/
public Location getLocation()
@@ -114,7 +114,7 @@ public Location getLocation()
/**
* Get the radius of the explosion (i.e. the distance between the location
* and the furthest block).
- *
+ *
* @return The radius of the explosion.
*/
public double getRadius()
@@ -164,7 +164,7 @@ private void replace_one_block()
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -182,7 +182,7 @@ public boolean equals(Object o)
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#hashCode()
*/
@Override
@@ -243,24 +243,24 @@ private void checkForObsidian()
private boolean isObsidianLike(Material m, boolean table)
{
return m == Material.OBSIDIAN
- || (table && (m == Material.ENCHANTMENT_TABLE || m == Material.ENDER_CHEST));
+ || (table && (m == Material.ENCHANTING_TABLE || m == Material.ENDER_CHEST));
}
/**
* Record one block and remove it. If it is protected, add to the
* replace-immediately list. Check for dependent blocks around.
- *
+ *
* @param block
* The block to record.
*/
public void recordBlock(Block block)
{
- if (block.getType() == Material.PORTAL || checked.contains(new ShortLocation(block)))
+ if (block.getType() == Material.NETHER_PORTAL || block.getType() == Material.END_PORTAL || checked.contains(new ShortLocation(block)))
return;
CreeperBlock creeperBlock = CreeperBlock.newBlock(block.getState());
- if (creeperBlock == null || creeperBlock.getType() == Material.PORTAL)
+ if (creeperBlock == null)
return;
ShortLocation location = new ShortLocation(creeperBlock.getLocation());
@@ -316,7 +316,7 @@ public void recordEntity(Replaceable replaceable)
/**
* Check if the explosion has blocks to repair, and repair them (or one of
* them in case of block per block).
- *
+ *
* @return False if the explosion has not started its replacements yet
* because it is not time.
*/
@@ -339,7 +339,7 @@ public boolean checkReplace()
/**
* Get whether the explosion has started replacing (only in block per block
* mode).
- *
+ *
* @return True if the explosion has started replacing blocks
*/
public boolean hasStartedReplacing()
@@ -351,7 +351,7 @@ public boolean hasStartedReplacing()
/**
* Get whether the list of blocks to be replaced is empty.
- *
+ *
* @return Whether the list is empty.
*/
public boolean isEmpty()
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperFlower.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperFlower.java
index 8e18230..d4f56d3 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperFlower.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperFlower.java
@@ -22,12 +22,12 @@ class CreeperFlower extends CreeperMultiblock
this.blockState = block.getState();
BlockState relative = block.getRelative(BlockFace.UP).getState();
if ((relative.getRawData() & 1) == 0)
- this.dependents.add(relative);
+ addDependent(relative);
}
/*
* (non-Javadoc)
- *
+ *
* @see com.nitnelave.CreeperHeal.block.CreeperBlock#getNeighbors()
*/
@Override
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperHead.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperHead.java
deleted file mode 100644
index 3dfe76f..0000000
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperHead.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package com.nitnelave.CreeperHeal.block;
-
-import com.nitnelave.CreeperHeal.config.CreeperConfig;
-import org.bukkit.Location;
-import org.bukkit.Material;
-import org.bukkit.World;
-import org.bukkit.block.BlockState;
-import org.bukkit.block.Skull;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.meta.SkullMeta;
-
-/**
- * Skull implementation of CreeperBlock, to store and replace the orientation,
- * the owner, etc...
- *
- * @author nitnelave
- *
- */
-class CreeperHead extends CreeperBlock
-{
-
- /*
- * Constructor.
- */
- protected CreeperHead(BlockState blockState)
- {
- super(blockState);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.nitnelave.CreeperHeal.block.CreeperBlock#update(boolean)
- */
- @Override
- public void update()
- {
- super.update();
- Skull skull = (Skull) blockState;
- Skull newSkull = ((Skull) blockState.getBlock().getState());
- newSkull.setRotation(skull.getRotation());
- newSkull.setSkullType(skull.getSkullType());
- if (skull.hasOwner())
- // Should be newSkull.setOwningPlayer(skull.getOwningPlayer()) instead of newSkull.setOwner(skull.getOwner())
- // but skull.getOwningPlayer() somehow always returns null, so we need to use the deprecated method
- newSkull.setOwner(skull.getOwner());
- newSkull.update(true);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.nitnelave.CreeperHeal.block.CreeperBlock#drop(boolean)
- */
- @Override
- public boolean drop(boolean forced)
- {
- if (forced || CreeperConfig.shouldDrop())
- {
- Location loc = blockState.getBlock().getLocation();
- World w = loc.getWorld();
-
- Skull skull = (Skull) blockState;
- ItemStack s = new ItemStack(Material.SKULL_ITEM);
- SkullMeta m = (SkullMeta) s.getItemMeta();
- if (skull.hasOwner())
- // Should be skull.getOwningPlayer().getName() instead of skull.getOwner()
- // but skull.getOwningPlayer() somehow always returns null, so we need to use the deprecated method
- m.setOwner(skull.getOwner());
- s.setItemMeta(m);
- s.setDurability((short) skull.getSkullType().ordinal());
-
- w.dropItemNaturally(loc, s);
-
- return true;
- }
- return false;
- }
-
-}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperJukebox.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperJukebox.java
deleted file mode 100644
index f1874ff..0000000
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperJukebox.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package com.nitnelave.CreeperHeal.block;
-
-import com.nitnelave.CreeperHeal.CreeperHeal;
-import com.nitnelave.CreeperHeal.config.CreeperConfig;
-import com.nitnelave.CreeperHeal.config.WCfgVal;
-import org.bukkit.Bukkit;
-import org.bukkit.Material;
-import org.bukkit.block.Jukebox;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.HandlerList;
-import org.bukkit.event.Listener;
-import org.bukkit.event.entity.ItemSpawnEvent;
-
-/**
- * Jukebox implementation of CreeperBlock.
- *
- * @author Jikoo
- */
-public class CreeperJukebox extends CreeperBlock
-{
-
- /*
- * Constructor.
- */
- CreeperJukebox(Jukebox blockState)
- {
- super(blockState);
-
- }
-
- /*
- * In Minecraft 1.13, discs inserted into jukeboxes preserve item meta. Craftbukkit does not properly handle this.
- * The only way to "prevent" the disc dropping is to remove it immediately after it spawns.
- *
- * @see com.nitnelave.CreeperHeal.block.Replaceable#remove()
- */
- @Override
- public void remove()
- {
- Jukebox jukebox = ((Jukebox) blockState);
-
- Listener recordDropListener = null;
-
- if (!CreeperConfig.getWorld(getWorld()).getBool(WCfgVal.DROP_CHEST_CONTENTS))
- {
- recordDropListener = new RecordDropListener(jukebox.getPlaying());
- Bukkit.getPluginManager().registerEvents(recordDropListener, CreeperHeal.getInstance());
- }
-
- super.remove();
-
- if (recordDropListener != null) {
- HandlerList.unregisterAll(recordDropListener);
- }
- }
-
- /*
- * @see com.nitnelave.CreeperHeal.block.Replaceable#update()
- */
- @Override
- public void update()
- {
- if (CreeperConfig.getWorld(getWorld()).getBool(WCfgVal.DROP_CHEST_CONTENTS))
- blockState.getBlock().setType(Material.JUKEBOX);
- else
- super.update();
- }
-
- private class RecordDropListener implements Listener {
-
- private final Material record;
-
- private RecordDropListener(Material record) {
- this.record = record;
- }
-
- @EventHandler(ignoreCancelled = true)
- public void onItemSpawn(ItemSpawnEvent event) {
- if (event.getEntity().getItemStack().getType() == record) {
- event.setCancelled(true);
- }
- }
- }
-
-}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperMonsterSpawner.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperMonsterSpawner.java
deleted file mode 100644
index 2558d89..0000000
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperMonsterSpawner.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.nitnelave.CreeperHeal.block;
-
-import org.bukkit.block.CreatureSpawner;
-
-/**
- * MonsterSpawner implementation of CreeperBlock, to save the type of monster.
- *
- * @author nitnelave
- *
- */
-class CreeperMonsterSpawner extends CreeperBlock
-{
-
- /*
- * Constructor.
- */
- protected CreeperMonsterSpawner(CreatureSpawner blockState)
- {
- super(blockState);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.nitnelave.CreeperHeal.block.CreeperBlock#update(boolean)
- */
- @Override
- public void update()
- {
- super.update();
- ((CreatureSpawner) getBlock().getState()).setCreatureTypeByName(((CreatureSpawner) blockState).getCreatureTypeName());
- }
-}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperMultiblock.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperMultiblock.java
index c2aaae5..cdca672 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperMultiblock.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperMultiblock.java
@@ -5,6 +5,7 @@
import com.nitnelave.CreeperHeal.utils.ShortLocation;
import org.bukkit.Material;
import org.bukkit.block.Block;
+import org.bukkit.block.data.BlockData;
import org.bukkit.block.BlockState;
import java.util.Collection;
@@ -19,20 +20,44 @@
public abstract class CreeperMultiblock extends CreeperBlock
{
- final Set dependents;
+ protected class BlockStateAndData {
+ public final BlockState state;
+ public final BlockData data;
+ public BlockStateAndData(BlockState state, BlockData data) {
+ this.state = state;
+ this.data = data.clone();
+ }
+ }
+
+ private final Set dependents;
+
CreeperMultiblock(BlockState blockState)
{
super(blockState);
- this.dependents = new HashSet();
+ this.dependents = new HashSet();
+ }
+
+ public void addDependent(BlockState state) {
+ dependents.add(new BlockStateAndData(state, state.getBlockData()));
+ }
+
+ protected Set getDependents() {
+ return dependents;
+ }
+
+ public void addDependent(BlockState state, BlockData data) {
+ dependents.add(new BlockStateAndData(state, data));
}
@Override
public void update()
{
super.update();
- for (BlockState dependent : dependents)
- dependent.update(true, false);
+ for (BlockStateAndData dependent : dependents)
+ dependent.state.getBlock().setBlockData(dependent.data, false);
+ for (BlockStateAndData dependent : dependents)
+ dependent.state.getBlock().setBlockData(dependent.data, true);
}
@Override
@@ -41,8 +66,8 @@ protected boolean checkForDrop()
if (checkForDependentDrop(getBlock()))
return true;
- for (BlockState dependent : dependents)
- if (checkForDependentDrop(dependent.getBlock()))
+ for (BlockStateAndData dependent : dependents)
+ if (checkForDependentDrop(dependent.state.getBlock()))
return true;
return false;
@@ -74,15 +99,15 @@ private boolean checkForDependentDrop(Block block)
public void remove()
{
this.blockState.getBlock().setType(Material.AIR, false);
- for (BlockState dependent : dependents)
- dependent.getBlock().setType(Material.AIR, false);
+ for (BlockStateAndData dependent : dependents)
+ dependent.state.getBlock().setType(Material.AIR, false);
}
@Override
void record(Collection checked)
{
super.record(checked);
- for (BlockState dependent : dependents)
- checked.add(new ShortLocation(dependent.getLocation()));
+ for (BlockStateAndData dependent : dependents)
+ checked.add(new ShortLocation(dependent.state.getLocation()));
}
}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperNoteBlock.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperNoteBlock.java
deleted file mode 100644
index e6eec5c..0000000
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperNoteBlock.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.nitnelave.CreeperHeal.block;
-
-import org.bukkit.block.NoteBlock;
-
-/**
- * NoteBlock implementation of CreeperBlock, to hold the note.
- *
- * @author nitnelave
- *
- */
-class CreeperNoteBlock extends CreeperBlock
-{
-
- /*
- * Constructor.
- */
- protected CreeperNoteBlock(NoteBlock blockState)
- {
- super(blockState);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.nitnelave.CreeperHeal.block.CreeperBlock#update(boolean)
- */
- @Override
- public void update()
- {
- super.update();
- ((NoteBlock) getBlock().getState()).setRawNote(((NoteBlock) blockState).getRawNote());
- }
-
-}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperPiston.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperPiston.java
index 551d3dc..f1f3b38 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperPiston.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperPiston.java
@@ -4,21 +4,19 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
-import org.bukkit.material.PistonBaseMaterial;
-import org.bukkit.material.PistonExtensionMaterial;
+import org.bukkit.block.data.type.Piston;
+import org.bukkit.block.data.type.PistonHead;
/**
* Piston implementation of CreeperBlock.
- *
+ *
* @author nitnelave
- *
+ *
*/
class CreeperPiston extends CreeperBlock
{
- private final BlockFace orientation;
- private final boolean extended;
-
+ private final Piston pistonData;
/*
* Constructor.
*/
@@ -26,30 +24,34 @@ class CreeperPiston extends CreeperBlock
{
super(blockState);
Block block = blockState.getBlock();
- if (blockState.getType().equals(Material.PISTON_EXTENSION))
- block = block.getRelative(castData(blockState, PistonExtensionMaterial.class).getAttachedFace());
+ if (blockState.getType().equals(Material.PISTON_HEAD))
+ block = block.getRelative(((PistonHead)blockData).getFacing().getOppositeFace());
this.blockState = block.getState();
- PistonBaseMaterial data = castData(this.blockState, PistonBaseMaterial.class);
- orientation = data.getFacing();
- Block extension_block = block.getRelative(orientation);
- extended = extension_block.getType().equals(Material.PISTON_EXTENSION) &&
- castData(extension_block.getState(), PistonExtensionMaterial.class).getFacing().equals(orientation);
- PistonBaseMaterial newdata = data.clone();
- newdata.setPowered(false);
- this.blockState.setData(newdata);
+ blockData = block.getState().getBlockData();
+ pistonData = (Piston) blockData.clone();
+ pistonData.setExtended(false);
+ this.blockState.setBlockData(pistonData);
+ }
+
+ private boolean isExtended() {
+ return ((Piston)blockData).isExtended();
}
+ @Override
+ public void update()
+ {
+ super.update(pistonData, true);
+ }
/*
* (non-Javadoc)
- *
+ *
* @see com.nitnelave.CreeperHeal.block.CreeperBlock#remove()
*/
@Override
public void remove()
{
getBlock().setType(Material.AIR);
- if (extended)
- getBlock().getRelative(orientation).setType(Material.AIR);
+ if (isExtended())
+ getBlock().getRelative(pistonData.getFacing()).setType(Material.AIR);
}
-
}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperPlate.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperPlate.java
deleted file mode 100644
index 6640c4e..0000000
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperPlate.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.nitnelave.CreeperHeal.block;
-
-import org.bukkit.block.BlockState;
-
-class CreeperPlate extends CreeperBlock
-{
-
- protected CreeperPlate(BlockState blockState)
- {
- super(blockState);
- blockState.setRawData((byte) 0);
- }
-
-}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperRail.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperRail.java
index 0857c91..f44e7a4 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperRail.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperRail.java
@@ -5,15 +5,15 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
-import org.bukkit.material.Rails;
+import org.bukkit.block.data.Rail;
import java.util.Set;
/**
* Rail implementation of CreeperBlock.
- *
+ *
* @author nitnelave
- *
+ *
*/
class CreeperRail extends CreeperBlock
{
@@ -22,12 +22,12 @@ class CreeperRail extends CreeperBlock
private static final BlockFace[] UP_DOWN = { BlockFace.DOWN, BlockFace.SELF, BlockFace.UP };
public static final Set RAIL_TYPES =
- CreeperUtils.createFinalHashSet(Material.RAILS,
+ CreeperUtils.createFinalHashSet(Material.RAIL,
Material.ACTIVATOR_RAIL,
Material.DETECTOR_RAIL,
Material.POWERED_RAIL);
- private final Rails data;
+ private final Rail data;
/*
* Constructor.
@@ -35,19 +35,19 @@ class CreeperRail extends CreeperBlock
CreeperRail(BlockState blockState)
{
super(blockState);
- data = castData(blockState, Rails.class);
+ data = (Rail)blockState.getBlockData();
}
/*
* (non-Javadoc)
- *
+ *
* @see com.nitnelave.CreeperHeal.block.CreeperBlock#update()
*/
@Override
public void update()
{
- Rails[][] railData = new Rails[3][4];
+ Rail[][] railData = new Rail[3][4];
Block block = getBlock();
for (int i = 0; i < 3; i++)
{
@@ -56,11 +56,10 @@ public void update()
{
Block tmpBlock = upBlock.getRelative(FACES[j]);
if (RAIL_TYPES.contains(tmpBlock.getType()))
- railData[i][j] = castData(tmpBlock.getState(), Rails.class);
+ railData[i][j] = (Rail)(tmpBlock.getState().getBlockData());
}
}
super.update();
- block.getState().setData(data);
for (int i = 0; i < 3; i++)
{
Block upBlock = block.getRelative(UP_DOWN[i]);
@@ -68,31 +67,48 @@ public void update()
{
Block tmpBlock = upBlock.getRelative(FACES[j]);
if (RAIL_TYPES.contains(tmpBlock.getType()))
- tmpBlock.getState().setData(railData[i][j]);
+ tmpBlock.getState().setBlockData(railData[i][j]);
}
}
}
/*
* (non-Javadoc)
- *
+ *
* @see com.nitnelave.CreeperHeal.block.CreeperBlock#getAttachingFace()
*/
@Override
public BlockFace getAttachingFace()
{
- if (data.isOnSlope())
- return data.getDirection();
- return BlockFace.DOWN;
+ switch (data.getShape()) {
+ case ASCENDING_EAST:
+ return BlockFace.EAST;
+ case ASCENDING_WEST:
+ return BlockFace.WEST;
+ case ASCENDING_NORTH:
+ return BlockFace.NORTH;
+ case ASCENDING_SOUTH:
+ return BlockFace.SOUTH;
+ default:
+ return BlockFace.DOWN;
+ }
}
/**
* Checks if the rail is ascending.
- *
+ *
* @return True, if it is ascending
*/
public boolean isAscending()
{
- return data.isOnSlope();
+ switch (data.getShape()) {
+ case ASCENDING_EAST:
+ case ASCENDING_WEST:
+ case ASCENDING_NORTH:
+ case ASCENDING_SOUTH:
+ return true;
+ default:
+ return false;
+ }
}
}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperSign.java b/src/main/java/com/nitnelave/CreeperHeal/block/CreeperSign.java
deleted file mode 100644
index 7d5f538..0000000
--- a/src/main/java/com/nitnelave/CreeperHeal/block/CreeperSign.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.nitnelave.CreeperHeal.block;
-
-import org.bukkit.block.Sign;
-
-/**
- * Sign implementation of CreeperBlock.
- *
- * @author nitnelave
- *
- */
-class CreeperSign extends CreeperBlock
-{
-
- /*
- * Constructor.
- */
- CreeperSign(Sign sign)
- {
- super(sign);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.nitnelave.CreeperHeal.block.CreeperBlock#update()
- */
- @Override
- public void update()
- {
- super.update();
- Sign state = (Sign) getBlock().getState();
- Sign sign = (Sign) blockState;
- for (int k = 0; k < 4; k++)
- state.setLine(k, sign.getLine(k));
-
- state.setData(sign.getData());
- state.update(true);
- }
-
-}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/config/BlockIdListValue.java b/src/main/java/com/nitnelave/CreeperHeal/config/BlockIdListValue.java
index 3b43aad..f72216d 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/config/BlockIdListValue.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/config/BlockIdListValue.java
@@ -20,19 +20,18 @@ protected void load()
HashSet set = new HashSet();
String tmp_str1 = config.getString(getKey(), "").trim();
String[] split = tmp_str1.split(",");
- try
+ for (String elem : split)
{
- for (String elem : split)
+ try
{
BlockId bId = new BlockId(elem);
- if (bId.getId() != 0)
- set.add(bId);
+ set.add(bId);
+ } catch (IllegalArgumentException e)
+ {
+ System.err.printf("Invalid material: %s\n", elem);
}
- setValue(set);
- } catch (NumberFormatException e)
- {
- setValue(getDefaultValue());
}
+ setValue(set);
}
@Override
diff --git a/src/main/java/com/nitnelave/CreeperHeal/config/WorldConfigImporter.java b/src/main/java/com/nitnelave/CreeperHeal/config/WorldConfigImporter.java
index cefb7c4..0aab8b0 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/config/WorldConfigImporter.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/config/WorldConfigImporter.java
@@ -116,19 +116,18 @@ private static HashSet loadList(YamlConfiguration config, String key)
HashSet set = new HashSet();
String tmp_str1 = config.getString(key, "").trim();
String[] split = tmp_str1.split(",");
- try
+ for (String elem : split)
{
- for (String elem : split)
+ try
{
BlockId bId = new BlockId(elem);
- if (bId.getId() != 0)
- set.add(bId);
+ set.add(bId);
+ } catch (NumberFormatException e)
+ {
+ System.err.printf("Invalid material: %s\n", elem);
}
- return set;
- } catch (NumberFormatException e)
- {
- return new HashSet();
}
+ return set;
}
protected static WorldConfig importFrom(String name, int version)
diff --git a/src/main/java/com/nitnelave/CreeperHeal/listeners/CreeperListener.java b/src/main/java/com/nitnelave/CreeperHeal/listeners/CreeperListener.java
index 6edfaf1..de601e2 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/listeners/CreeperListener.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/listeners/CreeperListener.java
@@ -31,9 +31,9 @@
/**
* Listener for the entity events.
- *
+ *
* @author nitnelave
- *
+ *
*/
public class CreeperListener implements Listener
{
@@ -41,7 +41,7 @@ public class CreeperListener implements Listener
/**
* Listener for the EntityExplodeEvent. Record when appropriate the
* explosion for later replacement.
- *
+ *
* @param event
* The EntityExplode event.
*/
@@ -89,7 +89,7 @@ public void onBlockExplode(BlockExplodeEvent event)
/**
* Listener for the HangingBreakEvent. If appropriate, the hanging is
* recorded to be replaced later on.
- *
+ *
* @param event
* The HangingBreakEvent.
*/
@@ -116,7 +116,7 @@ public void onHangingBreak(HangingBreakEvent event)
/**
* Listener for the EntityChangeBlockEvent. Check for Endermen picking up
* blocks.
- *
+ *
* @param event
* The EntityChangeBlock event.
*/
@@ -125,7 +125,7 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event)
{
CreeperLog.debug("Entity change block event");
if (event.getEntityType() == EntityType.SILVERFISH
- && event.getBlock().getType() == Material.MONSTER_EGGS
+ && event.getBlock().getType().toString().startsWith("INFESTED_BLOCK")
&& CreeperConfig.getBool(CfgVal.REPLACE_SILVERFISH_BLOCKS))
Bukkit.getScheduler().runTask(CreeperHeal.getInstance(), new ReplaceSilverfishBlock(event.getBlock()));
else if (event.getEntity().getType() == EntityType.ENDERMAN)
@@ -159,7 +159,7 @@ public void onEntityDamagedByEntity(EntityDamageByEntityEvent event)
/**
* Listener for the EntityBreakDoorEvent. Record doors broken by zombies.
- *
+ *
* @param event
* The EntityBreakDoor event.
*/
@@ -181,17 +181,16 @@ private class ReplaceSilverfishBlock implements Runnable
ReplaceSilverfishBlock(Block block)
{
- //noinspection deprecation
- switch (block.getData())
+ switch (block.getType())
{
- case 0:
- type = Material.STONE;
- break;
- case 1:
- type = Material.COBBLESTONE;
- break;
- default:
- type = Material.SMOOTH_BRICK;
+ case INFESTED_CHISELED_STONE_BRICKS: type = Material.CHISELED_STONE_BRICKS; break;
+ case INFESTED_COBBLESTONE: type = Material.COBBLESTONE; break;
+ case INFESTED_CRACKED_STONE_BRICKS: type = Material.CRACKED_STONE_BRICKS; break;
+ case INFESTED_MOSSY_STONE_BRICKS: type = Material.MOSSY_STONE_BRICKS; break;
+ case INFESTED_STONE: type = Material.STONE; break;
+ case INFESTED_STONE_BRICKS: type = Material.STONE_BRICKS; break;
+ default:
+ type = Material.AIR; break;
}
this.block = block;
}
diff --git a/src/main/java/com/nitnelave/CreeperHeal/listeners/GriefListener.java b/src/main/java/com/nitnelave/CreeperHeal/listeners/GriefListener.java
index 7a379cb..f25f099 100644
--- a/src/main/java/com/nitnelave/CreeperHeal/listeners/GriefListener.java
+++ b/src/main/java/com/nitnelave/CreeperHeal/listeners/GriefListener.java
@@ -183,7 +183,7 @@ public void onPlayerInteract(PlayerInteractEvent event)
Player player = event.getPlayer();
WorldConfig world = CreeperConfig.getWorld(player.getWorld());
- if (item.getType() == Material.MONSTER_EGG
+ if (item.getType().toString().endsWith("_SPAWN_EGG")
&& !CreeperPermissionManager.checkPermissions(player, true, "bypass.spawnEgg"))
{
String entityType = EntityType.fromId(event.getItem().getData().getData()).getName();
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 251e93e..9f13611 100755
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -5,6 +5,7 @@ author: nitnelave
authors: [Jikoo]
description: Replaces terrain destroyed by creeper explosions
softdepend: [LWC, MobArena, Factions]
+api-version: 1.16
commands:
CreeperHeal: