Permalink
Browse files

Remove a lot of deprecated usages

  • Loading branch information...
me4502 committed Oct 4, 2018
1 parent 51f0e7a commit 6b214caffebfcbeadad636ab520205c4c63a640d
@@ -35,6 +35,9 @@
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Directional;
import org.bukkit.block.data.Powerable;
import org.bukkit.block.data.type.RedstoneWire;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -49,9 +52,6 @@
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.material.Attachable;
import org.bukkit.material.Directional;
import org.bukkit.material.PressureSensor;
import java.util.HashSet;
import java.util.Set;
@@ -140,14 +140,9 @@ private static void checkBlockChange(Player player, Block block, boolean build)
case REDSTONE_WIRE:
if(CraftBookPlugin.inst().getConfiguration().pedanticBlockChecks && !ProtectionUtil.canBuild(player, block.getLocation(), build))
break;
if(block.getData() > 0)
handleRedstoneForBlock(block, block.getData(), 0);
break;
case LEVER:
if(CraftBookPlugin.inst().getConfiguration().pedanticBlockChecks && !ProtectionUtil.canBuild(player, block.getLocation(), build))
break;
if(((org.bukkit.material.Lever) block.getState().getData()).isPowered())
handleRedstoneForBlock(block, build ? 0 : 15, build ? 15 : 0);
RedstoneWire wire = (RedstoneWire) block.getBlockData();
if(wire.getPower() > 0)
handleRedstoneForBlock(block, wire.getPower(), 0);
break;
case ACACIA_BUTTON:
case BIRCH_BUTTON:
@@ -156,11 +151,7 @@ private static void checkBlockChange(Player player, Block block, boolean build)
case OAK_BUTTON:
case SPRUCE_BUTTON:
case STONE_BUTTON:
if(CraftBookPlugin.inst().getConfiguration().pedanticBlockChecks && !ProtectionUtil.canBuild(player, block.getLocation(), build))
break;
if(((org.bukkit.material.Button) block.getState().getData()).isPowered())
handleRedstoneForBlock(block, build ? 0 : 15, build ? 15 : 0);
break;
case LEVER:
case STONE_PRESSURE_PLATE:
case ACACIA_PRESSURE_PLATE:
case BIRCH_PRESSURE_PLATE:
@@ -173,7 +164,8 @@ private static void checkBlockChange(Player player, Block block, boolean build)
case DETECTOR_RAIL:
if(CraftBookPlugin.inst().getConfiguration().pedanticBlockChecks && !ProtectionUtil.canBuild(player, block.getLocation(), build))
break;
if(block.getState().getData() instanceof PressureSensor && ((PressureSensor) block.getState().getData()).isPressed())
Powerable powerable = (Powerable) block.getBlockData();
if(powerable.isPowered())
handleRedstoneForBlock(block, build ? 0 : 15, build ? 15 : 0);
break;
default:
@@ -280,7 +272,7 @@ private static void handleRedstoneForBlock(Block block, int oldLevel, int newLev
return;
case REPEATER:
case COMPARATOR:
Directional diode = (Directional) block.getState().getData();
Directional diode = (Directional) block.getBlockData();
BlockFace f = diode.getFacing();
handleDirectWireInput(x + f.getModX(), y, z + f.getModZ(), block, oldLevel, newLevel);
if(block.getRelative(f).getType() != Material.AIR) {
@@ -300,9 +292,9 @@ private static void handleRedstoneForBlock(Block block, int oldLevel, int newLev
case SPRUCE_BUTTON:
case STONE_BUTTON:
case LEVER:
Attachable button = (Attachable) block.getState().getData();
Directional button = (Directional) block.getBlockData();
if(button != null) {
BlockFace face = button.getAttachedFace();
BlockFace face = button.getFacing().getOppositeFace();
if(face != null)
handleDirectWireInput(x + face.getModX()*2, y + face.getModY()*2, z + face.getModZ()*2, block, oldLevel, newLevel);
}
@@ -28,6 +28,8 @@
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@@ -39,7 +41,6 @@
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.material.Directional;
import java.util.ArrayList;
import java.util.List;
@@ -248,8 +249,9 @@ public void onRightClick(PlayerInteractEvent event) {
Location chairLoc = event.getClickedBlock().getLocation().add(0.5,0,0.5);
if(chairFacing && event.getClickedBlock().getState().getData() instanceof Directional) {
BlockFace direction = ((Directional) event.getClickedBlock().getState().getData()).getFacing();
BlockData blockData = event.getClickedBlock().getBlockData();
if(chairFacing && blockData instanceof Directional) {
BlockFace direction = ((Directional) blockData).getFacing();
double dx = direction.getModX();
double dy = direction.getModY();
@@ -18,13 +18,13 @@
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Directional;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.material.Button;
/**
* Teleporter Mechanism. Based off Elevator
@@ -97,9 +97,9 @@ public void onCommonClick(PlayerInteractEvent event) {
}
trigger = event.getClickedBlock();
} else if (Tag.BUTTONS.isTagged(event.getClickedBlock().getType())) {
Button b = (Button) event.getClickedBlock().getState().getData();
if(b == null || b.getAttachedFace() == null) return;
Block sign = event.getClickedBlock().getRelative(b.getAttachedFace(), 2);
Directional b = (Directional) event.getClickedBlock().getBlockData();
if(b == null || b.getFacing() == null) return;
Block sign = event.getClickedBlock().getRelative(b.getFacing().getOppositeFace(), 2);
if (SignUtil.isSign(sign)) {
ChangedSign s = CraftBookBukkitUtil.toChangedSign(sign);
if (!s.getLine(1).equals("[Teleporter]")) return;
@@ -166,8 +166,8 @@ private void makeItSo(CraftBookPlayer player, Block trigger) {
return;
}
} else if (Tag.BUTTONS.isTagged(location.getType())) {
Button b = (Button) location.getState().getData();
Block sign = location.getRelative(b.getAttachedFace()).getRelative(b.getAttachedFace());
Directional b = (Directional) location.getBlockData();
Block sign = location.getRelative(b.getFacing(), 2);
if (!checkTeleportSign(player, sign)) {
return;
}
@@ -2,8 +2,10 @@
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Dispenser;
import org.bukkit.block.data.Directional;
import org.bukkit.block.data.type.Dispenser;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.block.BlockDispenseEvent;
@@ -26,12 +28,11 @@ public Cannon() {
}
@Override
public boolean doAction(Dispenser dis, ItemStack item, Vector velocity, BlockDispenseEvent event) {
org.bukkit.material.Dispenser disp = (org.bukkit.material.Dispenser) dis.getData();
public boolean doAction(Block block, ItemStack item, Vector velocity, BlockDispenseEvent event) {
Directional disp = (Directional) block.getBlockData();
BlockFace face = disp.getFacing();
Location location = dis.getBlock().getRelative(face).getLocation().add(0.5, 0.5, 0.5);
TNTPrimed a = (TNTPrimed) dis.getWorld().spawnEntity(location, EntityType.PRIMED_TNT);
Location location = block.getRelative(face).getLocation().add(0.5, 0.5, 0.5);
TNTPrimed a = (TNTPrimed) block.getWorld().spawnEntity(location, EntityType.PRIMED_TNT);
a.setVelocity(velocity.normalize().multiply(2));
return true;
}
@@ -1,25 +1,22 @@
package com.sk89q.craftbook.mechanics.dispenser;
import com.sk89q.craftbook.util.EntityUtil;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Dispenser;
import org.bukkit.block.data.type.Dispenser;
import org.bukkit.entity.Entity;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.DirectionalContainer;
import org.bukkit.material.MaterialData;
import org.bukkit.util.Vector;
import com.sk89q.craftbook.util.EntityUtil;
/**
* @author Me4502
*/
public class Fan extends Recipe {
public Fan(Material[] recipe) {
super(recipe);
}
@@ -32,14 +29,13 @@ public Fan() {
}
@Override
public boolean doAction(Dispenser dis, ItemStack item, Vector velocity, BlockDispenseEvent event) {
MaterialData d = dis.getBlock().getState().getData();
public boolean doAction(Block block, ItemStack item, Vector velocity, BlockDispenseEvent event) {
Dispenser d = (Dispenser) block.getBlockData();
BlockFace face = ((org.bukkit.material.Dispenser) d).getFacing();
Location dispenserLoc = dis.getBlock().getRelative(face).getLocation();
for (Entity e : dis.getWorld().getChunkAt(dispenserLoc).getEntities()) {
Location dispenserLoc = block.getRelative(face).getLocation();
for (Entity e : block.getWorld().getChunkAt(dispenserLoc).getEntities()) {
if (EntityUtil.isEntityInBlock(e, dispenserLoc.getBlock())) {
Vector dir = new Vector(((DirectionalContainer) dis.getData()).getFacing().getModX(),((DirectionalContainer) dis.getData()).getFacing().getModY(),((DirectionalContainer) dis.getData()).getFacing().getModZ());
Vector dir = new Vector(d.getFacing().getModX(), d.getFacing().getModY(), d.getFacing().getModZ());
e.setVelocity(e.getVelocity().add(dir).normalize().multiply(10));
}
}
@@ -2,8 +2,9 @@
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Dispenser;
import org.bukkit.block.data.type.Dispenser;
import org.bukkit.entity.Arrow;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.inventory.ItemStack;
@@ -29,12 +30,11 @@ public FireArrows() {
}
@Override
public boolean doAction(Dispenser dis, ItemStack item, Vector velocity, BlockDispenseEvent event) {
org.bukkit.material.Dispenser disp = (org.bukkit.material.Dispenser) dis.getData();
public boolean doAction(Block block, ItemStack item, Vector velocity, BlockDispenseEvent event) {
Dispenser disp = (Dispenser) block.getBlockData();
BlockFace face = disp.getFacing();
Location location = dis.getBlock().getRelative(face).getLocation().add(0.5, 0.5, 0.5);
Arrow a = dis.getWorld().spawnArrow(location, velocity, 1.0f, 0.0f);
Location location = block.getRelative(face).getLocation().add(0.5, 0.5, 0.5);
Arrow a = block.getWorld().spawnArrow(location, velocity, 1.0f, 0.0f);
a.setFireTicks(5000);
return true;
}
@@ -1,7 +1,7 @@
package com.sk89q.craftbook.mechanics.dispenser;
import org.bukkit.Material;
import org.bukkit.block.Dispenser;
import org.bukkit.block.Block;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
@@ -17,8 +17,7 @@ public ItemShooter(Material id, Material[] materials) {
}
@Override
public boolean doAction(Dispenser dis, ItemStack item, Vector velocity, BlockDispenseEvent event) {
public boolean doAction(Block block, ItemStack item, Vector velocity, BlockDispenseEvent event) {
event.setItem(new ItemStack(itemId, 1));
return false;
}
@@ -3,6 +3,7 @@
import java.util.Arrays;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Dispenser;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.inventory.ItemStack;
@@ -23,14 +24,14 @@ public Recipe(Material[] materials) {
/**
* Does the recipe action.
*
* @param dis the dispenser firing the item
* @param block the dispenser firing the item
* @param item the original item to be fired
* @param velocity the velocity the item is to be fired at
* @param event the BlockDispenseEvent
*
* @return true if event needs to be cancelled.
*/
public abstract boolean doAction(Dispenser dis, ItemStack item, Vector velocity, BlockDispenseEvent event);
public abstract boolean doAction(Block block, ItemStack item, Vector velocity, BlockDispenseEvent event);
/**
* Gets the contents of this recipe as a 9-element array representing the 3x3 dispenser grid.
@@ -11,8 +11,8 @@
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.material.Attachable;
import org.bukkit.material.Vine;
import org.bukkit.block.data.Directional;
import org.bukkit.block.data.MultipleFacing;
/**
* <p>
@@ -83,11 +83,11 @@ public static CartMechanismBlocks findByRail(Block rail) throws InvalidMechanism
BlockFace face = BlockFace.DOWN;
if (rail.getType() == Material.LADDER)
face = ((Attachable) rail.getState().getData()).getAttachedFace();
face = ((Directional) rail.getBlockData()).getFacing().getOppositeFace();
else if (rail.getType() == Material.VINE) {
Vine vine = (Vine) rail.getState().getData();
MultipleFacing vine = (MultipleFacing) rail.getBlockData();
for(BlockFace test : LocationUtil.getDirectFaces()) {
if(vine.isOnFace(test)) {
if(vine.hasFace(test.getOppositeFace())) {
face = test;
break;
}

0 comments on commit 6b214ca

Please sign in to comment.