use of org.bukkit.Location in project Prism-Bukkit by prism.
the class Preview method moveEntitiesToSafety.
/**
*
*/
protected void moveEntitiesToSafety() {
if (parameters.getWorld() != null && player != null) {
final List<Entity> entities = player.getNearbyEntities(parameters.getRadius(), parameters.getRadius(), parameters.getRadius());
entities.add(player);
for (final Entity entity : entities) {
if (entity instanceof LivingEntity) {
int add = 0;
if (EntityUtils.inCube(parameters.getPlayerLocation(), parameters.getRadius(), entity.getLocation())) {
final Location l = entity.getLocation();
while (!EntityUtils.playerMayPassThrough(l.getBlock().getType())) {
add++;
if (l.getY() >= 256)
break;
l.setY(l.getY() + 1);
}
if (add > 0) {
entities_moved.put(entity, add);
entity.teleport(l);
}
}
}
}
}
}
use of org.bukkit.Location in project Prism-Bukkit by prism.
the class PrismWorldEditLogger method onBlockChange.
@Override
protected void onBlockChange(Vector pt, BaseBlock newBlock) {
if (!Prism.config.getBoolean("prism.tracking.world-edit"))
return;
BaseBlock oldBlock = getBlock(pt);
Location loc = new Location(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
RecordingQueue.addToQueue(ActionFactory.createBlockChange("world-edit", loc, oldBlock.getId(), (byte) oldBlock.getData(), newBlock.getId(), (byte) newBlock.getData(), player.getName()));
}
use of org.bukkit.Location in project Prism-Bukkit by prism.
the class BlockUtils method removeMaterialsFromRadius.
/**
*
* @param materials
* @param loc
* @param radius
*/
public static ArrayList<BlockStateChange> removeMaterialsFromRadius(Material[] materials, Location loc, int radius) {
final ArrayList<BlockStateChange> blockStateChanges = new ArrayList<BlockStateChange>();
if (loc != null && radius > 0 && materials != null && materials.length > 0) {
final int x1 = loc.getBlockX();
final int y1 = loc.getBlockY();
final int z1 = loc.getBlockZ();
final World world = loc.getWorld();
for (int x = x1 - radius; x <= x1 + radius; x++) {
for (int y = y1 - radius; y <= y1 + radius; y++) {
for (int z = z1 - radius; z <= z1 + radius; z++) {
loc = new Location(world, x, y, z);
final Block b = loc.getBlock();
if (b.getType().equals(Material.AIR))
continue;
if (Arrays.asList(materials).contains(loc.getBlock().getType())) {
final BlockState originalBlock = loc.getBlock().getState();
loc.getBlock().setType(Material.AIR);
final BlockState newBlock = loc.getBlock().getState();
blockStateChanges.add(new BlockStateChange(originalBlock, newBlock));
}
}
}
}
}
return blockStateChanges;
}
use of org.bukkit.Location in project Prism-Bukkit by prism.
the class PrismInventoryEvents method onInventoryClick.
/**
* Handle inventory transfers
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent event) {
if (!plugin.getConfig().getBoolean("prism.tracking.item-insert") && !plugin.getConfig().getBoolean("prism.tracking.item-remove"))
return;
Location containerLoc = null;
// Store some info
final Player player = (Player) event.getWhoClicked();
final ItemStack currentitem = event.getCurrentItem();
final ItemStack cursoritem = event.getCursor();
// Get location
if (event.getInventory().getHolder() instanceof BlockState) {
final BlockState b = (BlockState) event.getInventory().getHolder();
containerLoc = b.getLocation();
} else if (event.getInventory().getHolder() instanceof Entity) {
final Entity e = (Entity) event.getInventory().getHolder();
containerLoc = e.getLocation();
} else if (event.getInventory().getHolder() instanceof DoubleChest) {
final DoubleChest chest = (DoubleChest) event.getInventory().getHolder();
containerLoc = chest.getLocation();
}
// Double chests report 27 default size, though they actually
// have 6 rows of 9 for 54 slots
int defaultSize = event.getView().getType().getDefaultSize();
if (event.getInventory().getHolder() instanceof DoubleChest) {
defaultSize = event.getView().getType().getDefaultSize() * 2;
}
// slot count of the inventory. At that point, they represent the player inv.
if (event.getSlot() == event.getRawSlot() && event.getRawSlot() <= defaultSize) {
ItemStack addStack = null;
ItemStack removeStack = null;
if (currentitem != null && !currentitem.getType().equals(Material.AIR) && cursoritem != null && !cursoritem.getType().equals(Material.AIR)) {
if (currentitem.isSimilar(cursoritem)) {
// Items are similar enough to stack
int amount = cursoritem.getAmount();
if (event.isRightClick()) {
amount = 1;
}
int remaining = (currentitem.getMaxStackSize() - currentitem.getAmount());
int inserted = (amount <= remaining) ? amount : remaining;
if (inserted > 0) {
addStack = cursoritem.clone();
addStack.setAmount(inserted);
}
} else {
// Items are not similar
addStack = cursoritem.clone();
removeStack = currentitem.clone();
}
} else if (currentitem != null && !currentitem.getType().equals(Material.AIR)) {
removeStack = currentitem.clone();
} else if (cursoritem != null && !cursoritem.getType().equals(Material.AIR)) {
addStack = cursoritem.clone();
}
// Record events
if (addStack != null) {
recordInvAction(player, containerLoc, addStack, event.getRawSlot(), "item-insert", event);
}
if (removeStack != null) {
recordInvAction(player, containerLoc, removeStack, event.getRawSlot(), "item-remove", event);
}
return;
}
if (event.isShiftClick() && cursoritem != null && cursoritem.getType().equals(Material.AIR)) {
recordInvAction(player, containerLoc, currentitem, -1, "item-insert", event);
}
}
use of org.bukkit.Location in project Prism-Bukkit by prism.
the class PrismInventoryMoveItemEvent method onInventoryMoveItem.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryMoveItem(final InventoryMoveItemEvent event) {
// Hopper inserted
if (Prism.getIgnore().event("item-insert") && event.getDestination() != null) {
// Get container
final InventoryHolder ih = event.getDestination().getHolder();
Location containerLoc = null;
if (ih instanceof BlockState) {
final BlockState eventChest = (BlockState) ih;
containerLoc = eventChest.getLocation();
}
if (containerLoc == null)
return;
if (event.getSource().getType().equals(InventoryType.HOPPER)) {
RecordingQueue.addToQueue(ActionFactory.createItemStack("item-insert", event.getItem(), event.getItem().getAmount(), 0, null, containerLoc, "hopper"));
}
}
// Hopper removed
if (Prism.getIgnore().event("item-remove") && event.getSource() != null) {
// Get container
final InventoryHolder ih = event.getSource().getHolder();
Location containerLoc = null;
if (ih instanceof BlockState) {
final BlockState eventChest = (BlockState) ih;
containerLoc = eventChest.getLocation();
}
if (containerLoc == null)
return;
if (event.getDestination().getType().equals(InventoryType.HOPPER)) {
RecordingQueue.addToQueue(ActionFactory.createItemStack("item-remove", event.getItem(), event.getItem().getAmount(), 0, null, containerLoc, "hopper"));
}
}
}
Aggregations