use of org.bukkit.Chunk in project Denizen-For-Bukkit by DenizenScript.
the class ChunkLoadCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
Element action = scriptEntry.getElement("action");
dLocation chunkloc = (dLocation) scriptEntry.getObject("location");
Duration length = (Duration) scriptEntry.getObject("duration");
dB.report(scriptEntry, getName(), action.debug() + chunkloc.debug() + length.debug());
Chunk chunk = chunkloc.getChunk();
String chunkString = chunk.getX() + ", " + chunk.getZ();
switch(Action.valueOf(action.asString())) {
case ADD:
if (length.getSeconds() != 0) {
chunkDelays.put(chunkString, System.currentTimeMillis() + length.getMillis());
} else {
chunkDelays.put(chunkString, (long) 0);
}
dB.echoDebug(scriptEntry, "...added chunk " + chunk.getX() + ", " + chunk.getZ() + " with a delay of " + length.getSeconds() + " seconds.");
if (!chunk.isLoaded()) {
chunk.load();
}
break;
case REMOVE:
if (chunkDelays.containsKey(chunkString)) {
chunkDelays.remove(chunkString);
dB.echoDebug(scriptEntry, "...allowing unloading of chunk " + chunk.getX() + ", " + chunk.getZ());
} else {
dB.echoError("Chunk was not on the load list!");
}
break;
case REMOVEALL:
dB.echoDebug(scriptEntry, "...allowing unloading of all stored chunks");
chunkDelays.clear();
break;
}
}
use of org.bukkit.Chunk in project BKCommonLib by bergerhealer.
the class BlockStateConversion method tileEntityToBlockState.
public static BlockState tileEntityToBlockState(Block block, Object nmsTileEntity) {
// Store and restore old state in case of recursive calls to this function
// This could happen if inside BlockState construction a chunk is loaded anyway
// Would be bad, but its best to assume the worst
TileState old_state = input_state;
try {
input_state = new TileState(block, nmsTileEntity);
BlockState result = proxy_block.getState();
// Internal BlockState needs to have all proxy field instances replaced with what it should be
BlockStateCache cache = BlockStateCache.get(result.getClass());
for (SafeField<World> worldField : cache.worldFields) {
worldField.set(result, input_state.block.getWorld());
}
for (SafeField<Chunk> chunkField : cache.chunkFields) {
chunkField.set(result, input_state.block.getChunk());
}
// All done!
return result;
} catch (Throwable t) {
Logging.LOGGER_CONVERSION.once(Level.SEVERE, "Failed to convert " + nmsTileEntity.getClass().getName() + " to CraftBlockState", t);
return CraftBlockStateHandle.createNew(input_state.block);
} finally {
input_state = old_state;
}
}
use of org.bukkit.Chunk in project Essentials by drtshock.
the class Commandremove method removeHandler.
private void removeHandler(CommandSource sender, List<String> types, List<String> customTypes, World world, int radius) {
int removed = 0;
if (radius > 0) {
radius *= radius;
}
ArrayList<ToRemove> removeTypes = new ArrayList<>();
ArrayList<Mob> customRemoveTypes = new ArrayList<>();
for (String s : types) {
removeTypes.add(ToRemove.valueOf(s));
}
boolean warnUser = false;
for (String s : customTypes) {
Mob mobType = Mob.fromName(s);
if (mobType == null) {
warnUser = true;
} else {
customRemoveTypes.add(mobType);
}
}
if (warnUser) {
sender.sendMessage(tl("invalidMob"));
}
for (Chunk chunk : world.getLoadedChunks()) {
for (Entity e : chunk.getEntities()) {
if (radius > 0) {
if (sender.getPlayer().getLocation().distanceSquared(e.getLocation()) > radius) {
continue;
}
}
if (e instanceof HumanEntity) {
continue;
}
for (ToRemove toRemove : removeTypes) {
// We should skip any TAMED animals unless we are specifially targetting them.
if (e instanceof Tameable && ((Tameable) e).isTamed() && !removeTypes.contains(ToRemove.TAMED)) {
continue;
}
// We should skip any NAMED animals unless we are specifially targetting them.
if (e instanceof LivingEntity && e.getCustomName() != null && !removeTypes.contains(ToRemove.NAMED)) {
continue;
}
switch(toRemove) {
case TAMED:
if (e instanceof Tameable && ((Tameable) e).isTamed()) {
e.remove();
removed++;
}
break;
case NAMED:
if (e instanceof LivingEntity && e.getCustomName() != null) {
e.remove();
removed++;
}
break;
case DROPS:
if (e instanceof Item) {
e.remove();
removed++;
}
break;
case ARROWS:
if (e instanceof Projectile) {
e.remove();
removed++;
}
break;
case BOATS:
if (e instanceof Boat) {
e.remove();
removed++;
}
break;
case MINECARTS:
if (e instanceof Minecart) {
e.remove();
removed++;
}
break;
case XP:
if (e instanceof ExperienceOrb) {
e.remove();
removed++;
}
break;
case PAINTINGS:
if (e instanceof Painting) {
e.remove();
removed++;
}
break;
case ITEMFRAMES:
if (e instanceof ItemFrame) {
e.remove();
removed++;
}
break;
case ENDERCRYSTALS:
if (e instanceof EnderCrystal) {
e.remove();
removed++;
}
break;
case AMBIENT:
if (e instanceof Flying) {
e.remove();
removed++;
}
break;
case HOSTILE:
case MONSTERS:
if (e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime) {
e.remove();
removed++;
}
break;
case PASSIVE:
case ANIMALS:
if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Ambient) {
e.remove();
removed++;
}
break;
case MOBS:
if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime || e instanceof Ambient) {
e.remove();
removed++;
}
break;
case ENTITIES:
case ALL:
if (e instanceof Entity) {
e.remove();
removed++;
}
break;
case CUSTOM:
for (Mob type : customRemoveTypes) {
if (e.getType() == type.getType()) {
e.remove();
removed++;
}
}
break;
}
}
}
}
sender.sendMessage(tl("removed", removed));
}
use of org.bukkit.Chunk in project MagicPlugin by elBukkit.
the class RegenerateBatch method process.
@Override
public int process(int maxBlocks) {
int processedBlocks = 0;
if (state == RegenerateState.SAVING && expand && !spell.isUndoable()) {
state = RegenerateState.REGENERATING;
}
switch(state) {
case SAVING:
while (processedBlocks <= maxBlocks && ix < absx) {
while (processedBlocks <= maxBlocks && blockY < 256) {
Chunk chunk = world.getChunkAt(x + ix * dx, z + iz * dz);
if (!chunk.isLoaded()) {
chunk.load();
return processedBlocks;
}
Block block = chunk.getBlock(blockX, blockY, blockZ);
if (!spell.hasBuildPermission(block) || !spell.hasBreakPermission(block)) {
spell.sendMessage(spell.getMessage("insufficient_permission"));
finish();
return processedBlocks;
}
if (!expand && !bounds.contains(block.getLocation().toVector())) {
restoredBlocks.add(block);
} else {
registerForUndo(block);
}
processedBlocks++;
blockX++;
if (blockX > 15) {
blockX = 0;
blockZ++;
if (blockZ > 15) {
blockZ = 0;
blockY++;
}
}
}
if (blockY >= 256) {
blockX = 0;
blockZ = 0;
blockY = 0;
iz++;
if (iz >= absz) {
iz = 0;
ix++;
}
}
}
if (ix >= absx) {
state = RegenerateState.REGENERATING;
ix = 0;
iz = 0;
}
break;
case REGENERATING:
while (processedBlocks <= maxBlocks && ix < absx) {
Chunk chunk = world.getChunkAt(x + ix * dx, z + iz * dz);
if (!chunk.isLoaded()) {
chunk.load();
return processedBlocks;
}
// Note that we've already done permissions checks for every block in this chunk.
processedBlocks += 256 * 16 * 16;
world.regenerateChunk(chunk.getX(), chunk.getZ());
iz++;
if (iz >= absz) {
iz = 0;
ix++;
}
}
if (ix >= absx) {
restoreBlocks = restoredBlocks.toArray(template);
if (expand && !spell.isUndoable()) {
finish();
} else {
state = RegenerateState.RESTORING;
}
}
break;
case RESTORING:
while (restoreBlocks != null && processedBlocks < maxBlocks && restoringIndex < restoreBlocks.length) {
restoreBlocks[restoringIndex].restore();
restoringIndex++;
processedBlocks++;
}
if (restoreBlocks == null || restoringIndex >= restoredBlocks.size()) {
finish();
}
break;
}
return processedBlocks;
}
use of org.bukkit.Chunk in project MagicPlugin by elBukkit.
the class WandCleanupRunnable method run.
@Override
public void run() {
if (lostWands.isEmpty()) {
finish();
return;
}
LostWand lostWand = lostWands.getFirst();
Location location = lostWand.getLocation();
if (world != null && !location.getWorld().getName().equals(world.getName())) {
lostWands.removeFirst();
return;
}
String lostWandOwner = lostWand.getOwner();
lostWandOwner = lostWandOwner == null ? "" : lostWandOwner;
if (!removeAll) {
// If no owner was specified, skip wands that have any owner
if (owner.length() == 0 && lostWandOwner.length() > 0) {
lostWands.removeFirst();
return;
}
// Skip wands that don't match the specified owner
if (owner.length() > 0 && !lostWandOwner.equals(owner)) {
lostWands.removeFirst();
return;
}
}
Chunk chunk = location.getChunk();
if (!chunk.isLoaded()) {
chunk.load();
return;
}
Entity[] entities = chunk.getEntities();
for (Entity entity : entities) {
if (!(entity instanceof Item))
continue;
Item item = (Item) entity;
ItemStack itemStack = item.getItemStack();
if (api.isWand(itemStack)) {
String lostId = Wand.getWandId(itemStack);
if (lostId != null && lostWand.getId().equals(lostId)) {
String description = check ? "Found" : "Removed";
logger.info(description + " lost wand " + lostWand.getName() + " (" + lostWand.getOwner() + "), id " + lostWand.getId() + " in " + location.getWorld().getName() + " at " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ());
if (check) {
if (lostWand instanceof com.elmakers.mine.bukkit.wand.LostWand) {
((com.elmakers.mine.bukkit.wand.LostWand) lostWand).setLocation(entity.getLocation());
}
} else {
api.removeLostWand(lostWand.getId());
item.remove();
}
lostWands.removeFirst();
return;
}
}
}
lostWands.removeFirst();
api.removeLostWand(lostWand.getId());
logger.info("Could not find wand " + lostWand.getName() + " (" + lostWand.getOwner() + "), id " + lostWand.getId() + ", removing from list");
}
Aggregations