mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-05 16:08:14 +01:00
Rewrote TargetBlock
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1589 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
parent
c038751c0b
commit
4bbc2aa8d5
@ -1,36 +1,44 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
/**
|
|
||||||
* @author toi
|
|
||||||
* Thanks to Raphfrk for optimization of this class.
|
|
||||||
*/
|
|
||||||
public class TargetBlock {
|
|
||||||
|
|
||||||
private Location loc;
|
|
||||||
private double viewHeight;
|
/**
|
||||||
private int maxDistance;
|
* Original authors: toi & Raphfrk
|
||||||
private int[] blockToIgnore;
|
*/
|
||||||
private double checkDistance, curDistance;
|
public class TargetBlock
|
||||||
private double xRotation, yRotation;
|
{
|
||||||
private Vector targetPos = new Vector();
|
private transient final Location location;
|
||||||
private Vector targetPosDouble = new Vector();
|
private transient final double viewHeight;
|
||||||
private Vector prevPos = new Vector();
|
private transient final int maxDistance;
|
||||||
private final Vector offset = new Vector();
|
private transient final int[] blockToIgnore;
|
||||||
|
private transient final double checkDistance;
|
||||||
|
private transient double curDistance;
|
||||||
|
private transient double targetPositionX;
|
||||||
|
private transient double targetPositionY;
|
||||||
|
private transient double targetPositionZ;
|
||||||
|
private transient int itargetPositionX;
|
||||||
|
private transient int itargetPositionY;
|
||||||
|
private transient int itargetPositionZ;
|
||||||
|
private transient int prevPositionX;
|
||||||
|
private transient int prevPositionY;
|
||||||
|
private transient int prevPositionZ;
|
||||||
|
private transient final double offsetX;
|
||||||
|
private transient final double offsetY;
|
||||||
|
private transient final double offsetZ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor requiring a player, uses default values
|
* Constructor requiring a player, uses default values
|
||||||
*
|
*
|
||||||
* @param player Player to work with
|
* @param player Player to work with
|
||||||
*/
|
*/
|
||||||
public TargetBlock(Player player)
|
public TargetBlock(final Player player)
|
||||||
{
|
{
|
||||||
this.setValues(player.getLocation(), 300, 1.65, 0.2, null);
|
this(player.getLocation(), 300, 1.65, 0.2, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,9 +46,9 @@ public class TargetBlock {
|
|||||||
*
|
*
|
||||||
* @param loc Location to work with
|
* @param loc Location to work with
|
||||||
*/
|
*/
|
||||||
public TargetBlock(Location loc)
|
public TargetBlock(final Location loc)
|
||||||
{
|
{
|
||||||
this.setValues(loc, 300, 0, 0.2, null);
|
this(loc, 300, 0, 0.2, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,9 +58,9 @@ public class TargetBlock {
|
|||||||
* @param maxDistance How far it checks for blocks
|
* @param maxDistance How far it checks for blocks
|
||||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||||
*/
|
*/
|
||||||
public TargetBlock(Player player, int maxDistance, double checkDistance)
|
public TargetBlock(final Player player, final int maxDistance, final double checkDistance)
|
||||||
{
|
{
|
||||||
this.setValues(player.getLocation(), maxDistance, 1.65, checkDistance, null);
|
this(player.getLocation(), maxDistance, 1.65, checkDistance, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,8 +70,9 @@ public class TargetBlock {
|
|||||||
* @param maxDistance How far it checks for blocks
|
* @param maxDistance How far it checks for blocks
|
||||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||||
*/
|
*/
|
||||||
public TargetBlock(Location loc, int maxDistance, double checkDistance) {
|
public TargetBlock(final Location loc, final int maxDistance, final double checkDistance)
|
||||||
this.setValues(loc, maxDistance, 0, checkDistance, null);
|
{
|
||||||
|
this(loc, maxDistance, 0, checkDistance, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,9 +83,9 @@ public class TargetBlock {
|
|||||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||||
* @param blocksToIgnore Integer array of what block ids to ignore while checking for viable targets
|
* @param blocksToIgnore Integer array of what block ids to ignore while checking for viable targets
|
||||||
*/
|
*/
|
||||||
public TargetBlock (Player player, int maxDistance, double checkDistance, int[] blocksToIgnore)
|
public TargetBlock(final Player player, final int maxDistance, final double checkDistance, final int[] blocksToIgnore)
|
||||||
{
|
{
|
||||||
this.setValues(player.getLocation(), maxDistance, 1.65, checkDistance, blocksToIgnore);
|
this(player.getLocation(), maxDistance, 1.65, checkDistance, blocksToIgnore);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,9 +96,9 @@ public class TargetBlock {
|
|||||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||||
* @param blocksToIgnore Array of what block ids to ignore while checking for viable targets
|
* @param blocksToIgnore Array of what block ids to ignore while checking for viable targets
|
||||||
*/
|
*/
|
||||||
public TargetBlock (Location loc, int maxDistance, double checkDistance, int[] blocksToIgnore)
|
public TargetBlock(final Location loc, final int maxDistance, final double checkDistance, final int[] blocksToIgnore)
|
||||||
{
|
{
|
||||||
this.setValues(loc, maxDistance, 0, checkDistance, blocksToIgnore);
|
this(loc, maxDistance, 0, checkDistance, blocksToIgnore);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,10 +109,9 @@ public class TargetBlock {
|
|||||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||||
* @param blocksToIgnore String ArrayList of what block ids to ignore while checking for viable targets
|
* @param blocksToIgnore String ArrayList of what block ids to ignore while checking for viable targets
|
||||||
*/
|
*/
|
||||||
public TargetBlock (Player player, int maxDistance, double checkDistance, ArrayList<String> blocksToIgnore)
|
public TargetBlock(final Player player, final int maxDistance, final double checkDistance, final List<String> blocksToIgnore)
|
||||||
{
|
{
|
||||||
int[] bti = this.convertStringArraytoIntArray(blocksToIgnore);
|
this(player.getLocation(), maxDistance, 1.65, checkDistance, TargetBlock.convertStringArraytoIntArray(blocksToIgnore));
|
||||||
this.setValues(player.getLocation(), maxDistance, 1.65, checkDistance, bti);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,10 +122,9 @@ public class TargetBlock {
|
|||||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||||
* @param blocksToIgnore String ArrayList of what block ids to ignore while checking for viable targets
|
* @param blocksToIgnore String ArrayList of what block ids to ignore while checking for viable targets
|
||||||
*/
|
*/
|
||||||
public TargetBlock (Location loc, int maxDistance, double checkDistance, ArrayList<String> blocksToIgnore)
|
public TargetBlock(final Location loc, final int maxDistance, final double checkDistance, final List<String> blocksToIgnore)
|
||||||
{
|
{
|
||||||
int[] bti = this.convertStringArraytoIntArray(blocksToIgnore);
|
this(loc, maxDistance, 0, checkDistance, TargetBlock.convertStringArraytoIntArray(blocksToIgnore));
|
||||||
this.setValues(loc, maxDistance, 0, checkDistance, bti);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,35 +136,47 @@ public class TargetBlock {
|
|||||||
* @param checkDistance How often to check for blocks, the smaller the more precise
|
* @param checkDistance How often to check for blocks, the smaller the more precise
|
||||||
* @param blocksToIgnore Ids of blocks to ignore while checking for viable targets
|
* @param blocksToIgnore Ids of blocks to ignore while checking for viable targets
|
||||||
*/
|
*/
|
||||||
private void setValues(Location loc, int maxDistance, double viewHeight, double checkDistance, int[] blocksToIgnore)
|
private TargetBlock(final Location loc, final int maxDistance, final double viewHeight, final double checkDistance, final int[] blocksToIgnore)
|
||||||
{
|
{
|
||||||
this.loc = loc;
|
this.location = loc;
|
||||||
this.maxDistance = maxDistance;
|
this.maxDistance = maxDistance;
|
||||||
this.viewHeight = viewHeight;
|
this.viewHeight = viewHeight;
|
||||||
this.checkDistance = checkDistance;
|
this.checkDistance = checkDistance;
|
||||||
this.blockToIgnore = blocksToIgnore;
|
if (blocksToIgnore == null || blocksToIgnore.length == 0)
|
||||||
this.curDistance = 0;
|
{
|
||||||
xRotation = (loc.getYaw() + 90) % 360;
|
this.blockToIgnore = new int[0];
|
||||||
yRotation = loc.getPitch() * -1;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.blockToIgnore = new int[blocksToIgnore.length];
|
||||||
|
System.arraycopy(blocksToIgnore, 0, this.blockToIgnore, 0, this.blockToIgnore.length);
|
||||||
|
}
|
||||||
|
|
||||||
double h = (checkDistance * Math.cos(Math.toRadians(yRotation)));
|
final double xRotation = (loc.getYaw() + 90) % 360;
|
||||||
offset.setY((checkDistance * Math.sin(Math.toRadians(yRotation))));
|
final double yRotation = loc.getPitch() * -1;
|
||||||
offset.setX((h * Math.cos(Math.toRadians(xRotation))));
|
|
||||||
offset.setZ((h * Math.sin(Math.toRadians(xRotation))));
|
|
||||||
|
|
||||||
targetPosDouble = new Vector(loc.getX(), loc.getY() + viewHeight, loc.getZ());
|
final double hypotenuse = (checkDistance * Math.cos(Math.toRadians(yRotation)));
|
||||||
targetPos = new Vector( targetPosDouble.getBlockX(), targetPosDouble.getBlockY(), targetPosDouble.getBlockZ());
|
offsetX = hypotenuse * Math.cos(Math.toRadians(xRotation));
|
||||||
prevPos = targetPos.clone();
|
offsetY = checkDistance * Math.sin(Math.toRadians(yRotation));
|
||||||
|
offsetZ = hypotenuse * Math.sin(Math.toRadians(xRotation));
|
||||||
|
|
||||||
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this to reset checking position to allow you to check for a new target with the same TargetBlock instance.
|
* Call this to reset checking position to allow you to check for a new target with the same TargetBlock instance.
|
||||||
*/
|
*/
|
||||||
public void reset()
|
public final void reset()
|
||||||
{
|
{
|
||||||
targetPosDouble = new Vector(loc.getX(), loc.getY() + viewHeight, loc.getZ());
|
targetPositionX = location.getX();
|
||||||
targetPos = new Vector( targetPosDouble.getBlockX(), targetPosDouble.getBlockY(), targetPosDouble.getBlockZ());
|
targetPositionY = location.getY() + viewHeight;
|
||||||
prevPos = targetPos.clone();
|
targetPositionZ = location.getZ();
|
||||||
|
itargetPositionX = (int)Math.floor(targetPositionX);
|
||||||
|
itargetPositionY = (int)Math.floor(targetPositionY);
|
||||||
|
itargetPositionZ = (int)Math.floor(targetPositionZ);
|
||||||
|
prevPositionX = itargetPositionX;
|
||||||
|
prevPositionY = itargetPositionY;
|
||||||
|
prevPositionZ = itargetPositionZ;
|
||||||
this.curDistance = 0;
|
this.curDistance = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,17 +188,16 @@ public class TargetBlock {
|
|||||||
*/
|
*/
|
||||||
public double getDistanceToBlock()
|
public double getDistanceToBlock()
|
||||||
{
|
{
|
||||||
Vector blockUnderPlayer = new Vector(
|
final double blockUnderPlayerX = Math.floor(location.getX() + 0.5);
|
||||||
(int) Math.floor(loc.getX() + 0.5),
|
final double blockUnderPlayerY = Math.floor(location.getY() - 0.5);
|
||||||
(int) Math.floor(loc.getY() - 0.5),
|
final double blockUnderPlayerZ = Math.floor(location.getZ() + 0.5);
|
||||||
(int) Math.floor(loc.getZ() + 0.5));
|
|
||||||
|
|
||||||
Block blk = getTargetBlock();
|
final Block block = getTargetBlock();
|
||||||
double x = blk.getX() - blockUnderPlayer.getBlockX();
|
final double distX = block.getX() - blockUnderPlayerX;
|
||||||
double y = blk.getY() - blockUnderPlayer.getBlockY();
|
final double distY = block.getY() - blockUnderPlayerY;
|
||||||
double z = blk.getZ() - blockUnderPlayer.getBlockZ();
|
final double distZ = block.getZ() - blockUnderPlayerZ;
|
||||||
|
|
||||||
return Math.sqrt((Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)));
|
return Math.sqrt(distX*distX + distY*distY + distZ*distZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -190,17 +208,7 @@ public class TargetBlock {
|
|||||||
*/
|
*/
|
||||||
public int getDistanceToBlockRounded()
|
public int getDistanceToBlockRounded()
|
||||||
{
|
{
|
||||||
Vector blockUnderPlayer = new Vector(
|
return (int)Math.round(getDistanceToBlock());
|
||||||
(int) Math.floor(loc.getX() + 0.5),
|
|
||||||
(int) Math.floor(loc.getY() - 0.5),
|
|
||||||
(int) Math.floor(loc.getZ() + 0.5));
|
|
||||||
|
|
||||||
Block blk = getTargetBlock();
|
|
||||||
double x = blk.getX() - blockUnderPlayer.getBlockX();
|
|
||||||
double y = blk.getY() - blockUnderPlayer.getBlockY();
|
|
||||||
double z = blk.getZ() - blockUnderPlayer.getBlockZ();
|
|
||||||
|
|
||||||
return (int) Math.round((Math.sqrt((Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2)))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -210,8 +218,7 @@ public class TargetBlock {
|
|||||||
*/
|
*/
|
||||||
public int getXDistanceToBlock()
|
public int getXDistanceToBlock()
|
||||||
{
|
{
|
||||||
this.reset();
|
return (int)Math.floor(getTargetBlock().getX() - location.getBlockX() + 0.5);
|
||||||
return (int) Math.floor(getTargetBlock().getX() - loc.getBlockX() + 0.5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,8 +228,7 @@ public class TargetBlock {
|
|||||||
*/
|
*/
|
||||||
public int getYDistanceToBlock()
|
public int getYDistanceToBlock()
|
||||||
{
|
{
|
||||||
this.reset();
|
return (int)Math.floor(getTargetBlock().getY() - location.getBlockY() + viewHeight);
|
||||||
return (int) Math.floor(getTargetBlock().getY() - loc.getBlockY() + viewHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -232,8 +238,7 @@ public class TargetBlock {
|
|||||||
*/
|
*/
|
||||||
public int getZDistanceToBlock()
|
public int getZDistanceToBlock()
|
||||||
{
|
{
|
||||||
this.reset();
|
return (int)Math.floor(getTargetBlock().getZ() - location.getBlockZ() + 0.5);
|
||||||
return (int) Math.floor(getTargetBlock().getZ() - loc.getBlockZ() + 0.5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -241,12 +246,17 @@ public class TargetBlock {
|
|||||||
*
|
*
|
||||||
* @return Block
|
* @return Block
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("empty-statement")
|
|
||||||
public Block getTargetBlock()
|
public Block getTargetBlock()
|
||||||
{
|
{
|
||||||
this.reset();
|
this.reset();
|
||||||
while ((getNextBlock() != null) && ((getCurrentBlock().getTypeId() == 0) || this.blockToIgnoreHasValue(getCurrentBlock().getTypeId())));
|
Block block;
|
||||||
return getCurrentBlock();
|
do
|
||||||
|
{
|
||||||
|
block = getNextBlock();
|
||||||
|
}
|
||||||
|
while (block != null && ((block.getTypeId() == 0) || this.blockIsIgnored(block.getTypeId())));
|
||||||
|
|
||||||
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -255,21 +265,9 @@ public class TargetBlock {
|
|||||||
* @param typeID ID of type to set the block to
|
* @param typeID ID of type to set the block to
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("empty-statement")
|
public boolean setTargetBlock(final int typeID)
|
||||||
public boolean setTargetBlock(int typeID)
|
|
||||||
{
|
{
|
||||||
if (Material.getMaterial(typeID) != null)
|
return setTargetBlock(Material.getMaterial(typeID));
|
||||||
{
|
|
||||||
this.reset();
|
|
||||||
while (getNextBlock() != null && getCurrentBlock().getTypeId() == 0);
|
|
||||||
if (getCurrentBlock() != null)
|
|
||||||
{
|
|
||||||
Block blk = loc.getWorld().getBlockAt(targetPos.getBlockX(), targetPos.getBlockY(), targetPos.getBlockZ());
|
|
||||||
blk.setTypeId(typeID);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -279,14 +277,16 @@ public class TargetBlock {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("empty-statement")
|
@SuppressWarnings("empty-statement")
|
||||||
public boolean setTargetBlock(Material type)
|
public boolean setTargetBlock(final Material type)
|
||||||
{
|
{
|
||||||
this.reset();
|
if (type == null)
|
||||||
while ((getNextBlock() != null) && ((getCurrentBlock().getTypeId() == 0) || this.blockToIgnoreHasValue(getCurrentBlock().getTypeId())));
|
|
||||||
if (getCurrentBlock() != null)
|
|
||||||
{
|
{
|
||||||
Block blk = loc.getWorld().getBlockAt(targetPos.getBlockX(), targetPos.getBlockY(), targetPos.getBlockZ());
|
return false;
|
||||||
blk.setType(type);
|
}
|
||||||
|
final Block block = getTargetBlock();
|
||||||
|
if (block != null)
|
||||||
|
{
|
||||||
|
block.setType(type);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -299,22 +299,9 @@ public class TargetBlock {
|
|||||||
* @param type Name of type to set the block to
|
* @param type Name of type to set the block to
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("empty-statement")
|
public boolean setTargetBlock(final String type)
|
||||||
public boolean setTargetBlock(String type)
|
|
||||||
{
|
{
|
||||||
Material mat = Material.valueOf(type);
|
return setTargetBlock(Material.valueOf(type));
|
||||||
if (mat != null)
|
|
||||||
{
|
|
||||||
this.reset();
|
|
||||||
while ((getNextBlock() != null) && ((getCurrentBlock().getTypeId() == 0) || this.blockToIgnoreHasValue(getCurrentBlock().getTypeId())));
|
|
||||||
if (getCurrentBlock() != null)
|
|
||||||
{
|
|
||||||
Block blk = loc.getWorld().getBlockAt(targetPos.getBlockX(), targetPos.getBlockY(), targetPos.getBlockZ());
|
|
||||||
blk.setType(mat);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -322,18 +309,14 @@ public class TargetBlock {
|
|||||||
*
|
*
|
||||||
* @return Block
|
* @return Block
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("empty-statement")
|
|
||||||
public Block getFaceBlock()
|
public Block getFaceBlock()
|
||||||
{
|
{
|
||||||
while ((getNextBlock() != null) && ((getCurrentBlock().getTypeId() == 0) || this.blockToIgnoreHasValue(getCurrentBlock().getTypeId())));
|
final Block block = getTargetBlock();
|
||||||
if (getCurrentBlock() != null)
|
if (block == null)
|
||||||
{
|
|
||||||
return getPreviousBlock();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return getPreviousBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -342,18 +325,9 @@ public class TargetBlock {
|
|||||||
* @param typeID
|
* @param typeID
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public boolean setFaceBlock(int typeID)
|
public boolean setFaceBlock(final int typeID)
|
||||||
{
|
{
|
||||||
if (Material.getMaterial(typeID) != null)
|
return setFaceBlock(Material.getMaterial(typeID));
|
||||||
{
|
|
||||||
if (getCurrentBlock() != null)
|
|
||||||
{
|
|
||||||
Block blk = loc.getWorld().getBlockAt(prevPos.getBlockX(), prevPos.getBlockY(), prevPos.getBlockZ());
|
|
||||||
blk.setTypeId(typeID);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -362,11 +336,15 @@ public class TargetBlock {
|
|||||||
* @param type
|
* @param type
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public boolean setFaceBlock(Material type)
|
public boolean setFaceBlock(final Material type)
|
||||||
{
|
{
|
||||||
|
if (type == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (getCurrentBlock() != null)
|
if (getCurrentBlock() != null)
|
||||||
{
|
{
|
||||||
Block blk = loc.getWorld().getBlockAt(prevPos.getBlockX(), prevPos.getBlockY(), prevPos.getBlockZ());
|
final Block blk = location.getWorld().getBlockAt(prevPositionX, prevPositionY, prevPositionZ);
|
||||||
blk.setType(type);
|
blk.setType(type);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -380,19 +358,9 @@ public class TargetBlock {
|
|||||||
* @param type
|
* @param type
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public boolean setFaceBlock(String type)
|
public boolean setFaceBlock(final String type)
|
||||||
{
|
{
|
||||||
Material mat = Material.valueOf(type);
|
return setFaceBlock(Material.valueOf(type));
|
||||||
if (mat != null)
|
|
||||||
{
|
|
||||||
if (getCurrentBlock() != null)
|
|
||||||
{
|
|
||||||
Block blk = loc.getWorld().getBlockAt(prevPos.getBlockX(), prevPos.getBlockY(), prevPos.getBlockZ());
|
|
||||||
blk.setType(mat);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -402,23 +370,27 @@ public class TargetBlock {
|
|||||||
*/
|
*/
|
||||||
public Block getNextBlock()
|
public Block getNextBlock()
|
||||||
{
|
{
|
||||||
prevPos = targetPos.clone();
|
prevPositionX = itargetPositionX;
|
||||||
|
prevPositionY = itargetPositionY;
|
||||||
|
prevPositionZ = itargetPositionZ;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
curDistance += checkDistance;
|
curDistance += checkDistance;
|
||||||
|
|
||||||
targetPosDouble.setX(offset.getX() + targetPosDouble.getX());
|
targetPositionX += offsetX;
|
||||||
targetPosDouble.setY(offset.getY() + targetPosDouble.getY());
|
targetPositionY += offsetY;
|
||||||
targetPosDouble.setZ(offset.getZ() + targetPosDouble.getZ());
|
targetPositionZ += offsetZ;
|
||||||
targetPos = new Vector( targetPosDouble.getBlockX(), targetPosDouble.getBlockY(), targetPosDouble.getBlockZ());
|
itargetPositionX = (int)Math.floor(targetPositionX);
|
||||||
|
itargetPositionY = (int)Math.floor(targetPositionY);
|
||||||
|
itargetPositionZ = (int)Math.floor(targetPositionZ);
|
||||||
}
|
}
|
||||||
while (curDistance <= maxDistance && targetPos.getBlockX() == prevPos.getBlockX() && targetPos.getBlockY() == prevPos.getBlockY() && targetPos.getBlockZ() == prevPos.getBlockZ());
|
while (curDistance <= maxDistance && itargetPositionX == prevPositionX && itargetPositionY == prevPositionY && itargetPositionZ == prevPositionZ);
|
||||||
if (curDistance > maxDistance)
|
if (curDistance > maxDistance)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.loc.getWorld().getBlockAt(this.targetPos.getBlockX(), this.targetPos.getBlockY(), this.targetPos.getBlockZ());
|
return this.location.getWorld().getBlockAt(itargetPositionX, itargetPositionY, itargetPositionZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -428,14 +400,16 @@ public class TargetBlock {
|
|||||||
*/
|
*/
|
||||||
public Block getCurrentBlock()
|
public Block getCurrentBlock()
|
||||||
{
|
{
|
||||||
if (curDistance > maxDistance)
|
Block block;
|
||||||
|
if (curDistance <= maxDistance)
|
||||||
{
|
{
|
||||||
return null;
|
block = this.location.getWorld().getBlockAt(itargetPositionX, itargetPositionY, itargetPositionZ);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return this.loc.getWorld().getBlockAt(this.targetPos.getBlockX(), this.targetPos.getBlockY(), this.targetPos.getBlockZ());
|
block = null;
|
||||||
}
|
}
|
||||||
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -443,18 +417,9 @@ public class TargetBlock {
|
|||||||
*
|
*
|
||||||
* @param typeID
|
* @param typeID
|
||||||
*/
|
*/
|
||||||
public boolean setCurrentBlock(int typeID)
|
public boolean setCurrentBlock(final int typeID)
|
||||||
{
|
{
|
||||||
if (Material.getMaterial(typeID) != null)
|
return setCurrentBlock(Material.getMaterial(typeID));
|
||||||
{
|
|
||||||
Block blk = getCurrentBlock();
|
|
||||||
if (blk != null)
|
|
||||||
{
|
|
||||||
blk.setTypeId(typeID);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -462,10 +427,10 @@ public class TargetBlock {
|
|||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public boolean setCurrentBlock(Material type)
|
public boolean setCurrentBlock(final Material type)
|
||||||
{
|
{
|
||||||
Block blk = getCurrentBlock();
|
final Block blk = getCurrentBlock();
|
||||||
if (blk != null)
|
if (blk != null && type != null)
|
||||||
{
|
{
|
||||||
blk.setType(type);
|
blk.setType(type);
|
||||||
return true;
|
return true;
|
||||||
@ -479,19 +444,9 @@ public class TargetBlock {
|
|||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public boolean setCurrentBlock(String type)
|
public boolean setCurrentBlock(final String type)
|
||||||
{
|
{
|
||||||
Material mat = Material.valueOf(type);
|
return setCurrentBlock(Material.valueOf(type));
|
||||||
if (mat != null)
|
|
||||||
{
|
|
||||||
Block blk = getCurrentBlock();
|
|
||||||
if (blk != null)
|
|
||||||
{
|
|
||||||
blk.setType(mat);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -501,7 +456,7 @@ public class TargetBlock {
|
|||||||
*/
|
*/
|
||||||
public Block getPreviousBlock()
|
public Block getPreviousBlock()
|
||||||
{
|
{
|
||||||
return this.loc.getWorld().getBlockAt(prevPos.getBlockX(), prevPos.getBlockY(), prevPos.getBlockZ());
|
return this.location.getWorld().getBlockAt(prevPositionX, prevPositionY, prevPositionZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -509,18 +464,9 @@ public class TargetBlock {
|
|||||||
*
|
*
|
||||||
* @param typeID
|
* @param typeID
|
||||||
*/
|
*/
|
||||||
public boolean setPreviousBlock(int typeID)
|
public boolean setPreviousBlock(final int typeID)
|
||||||
{
|
{
|
||||||
if (Material.getMaterial(typeID) != null)
|
return setPreviousBlock(Material.getMaterial(typeID));
|
||||||
{
|
|
||||||
Block blk = getPreviousBlock();
|
|
||||||
if (blk != null)
|
|
||||||
{
|
|
||||||
blk.setTypeId(typeID);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -528,10 +474,10 @@ public class TargetBlock {
|
|||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public boolean setPreviousBlock(Material type)
|
public boolean setPreviousBlock(final Material type)
|
||||||
{
|
{
|
||||||
Block blk = getPreviousBlock();
|
final Block blk = getPreviousBlock();
|
||||||
if (blk != null)
|
if (blk != null && type != null)
|
||||||
{
|
{
|
||||||
blk.setType(type);
|
blk.setType(type);
|
||||||
return true;
|
return true;
|
||||||
@ -545,27 +491,15 @@ public class TargetBlock {
|
|||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public boolean setPreviousBlock(String type)
|
public boolean setPreviousBlock(final String type)
|
||||||
{
|
{
|
||||||
Material mat = Material.valueOf(type);
|
return setPreviousBlock(Material.valueOf(type));
|
||||||
if (mat != null)
|
|
||||||
{
|
|
||||||
Block blk = getPreviousBlock();
|
|
||||||
if (blk != null)
|
|
||||||
{
|
|
||||||
blk.setType(mat);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] convertStringArraytoIntArray(ArrayList<String> array)
|
private static int[] convertStringArraytoIntArray(final List<String> array)
|
||||||
{
|
{
|
||||||
if (array != null)
|
final int intarray[] = new int[array == null ? 0 : array.size()];
|
||||||
{
|
for (int i = 0; i < intarray.length; i++)
|
||||||
int intarray[] = new int[array.size()];
|
|
||||||
for (int i = 0; i < array.size(); i++)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -573,27 +507,20 @@ public class TargetBlock {
|
|||||||
}
|
}
|
||||||
catch (NumberFormatException nfe)
|
catch (NumberFormatException nfe)
|
||||||
{
|
{
|
||||||
intarray[i] = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return intarray;
|
return intarray;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean blockToIgnoreHasValue(int value)
|
private boolean blockIsIgnored(final int value)
|
||||||
{
|
|
||||||
if (this.blockToIgnore != null)
|
|
||||||
{
|
|
||||||
if (this.blockToIgnore.length > 0)
|
|
||||||
{
|
{
|
||||||
for (int i : this.blockToIgnore)
|
for (int i : this.blockToIgnore)
|
||||||
{
|
{
|
||||||
if (i == value)
|
if (i == value)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user