use of org.bukkit.Chunk in project TotalFreedomMod by TotalFreedom.
the class EntityWiper method wipeEntities.
public int wipeEntities(World world, boolean force) {
int removed = 0;
boolean wipeExpl = ConfigEntry.ALLOW_EXPLOSIONS.getBoolean();
Iterator<Entity> entities = world.getEntities().iterator();
// Organise the entities in the world
Map<Chunk, List<Entity>> cem = new HashMap<>();
while (entities.hasNext()) {
final Entity entity = entities.next();
// Explosives
if (wipeExpl && Explosive.class.isAssignableFrom(entity.getClass())) {
entity.remove();
removed++;
}
// Only wipeable entities can be wiped (duh!)
if (!isWipeable(entity)) {
continue;
}
Chunk c = entity.getLocation().getChunk();
List<Entity> cel = cem.get(c);
if (cel == null) {
cem.put(c, new ArrayList<>(Arrays.asList(entity)));
} else {
cel.add(entity);
}
}
// Now purge the entities if necessary
for (Chunk c : cem.keySet()) {
List<Entity> cel = cem.get(c);
if (!force && cel.size() < CHUNK_ENTITY_MAX) {
continue;
}
// Too many entities in this chunk, wipe them all
for (Entity e : cel) {
e.remove();
}
}
return removed;
}
use of org.bukkit.Chunk in project RedProtect by FabioZumbi12.
the class RPCommands method handleMyChunk.
private static boolean handleMyChunk() {
if (!RedProtect.get().MyChunk) {
return false;
}
Set<LiteChunk> allchunks = new HashSet<>();
for (World w : RedProtect.get().serv.getWorlds()) {
Set<LiteChunk> chunks = MyChunkChunk.getChunks(w);
allchunks.addAll(chunks);
}
if (allchunks.size() != 0) {
int i = 0;
for (LiteChunk c : allchunks) {
List<String> leaders = new ArrayList<>();
String admin = RPUtil.PlayerToUUID(c.getOwner());
leaders.add(admin.toString());
World w = RedProtect.get().serv.getWorld(c.getWorldName());
Chunk chunk = w.getChunkAt(c.getX(), c.getZ());
int x = chunk.getBlock(7, 50, 7).getX();
int z = chunk.getBlock(7, 50, 7).getZ();
String regionName = "";
int in = 0;
while (true) {
int is = String.valueOf(in).length();
if (RPUtil.UUIDtoPlayer(admin).length() > 13) {
regionName = RPUtil.UUIDtoPlayer(admin).substring(0, 14 - is) + "_" + in;
} else {
regionName = RPUtil.UUIDtoPlayer(admin) + "_" + in;
}
if (RedProtect.get().rm.getRegion(regionName, w) == null) {
break;
}
++in;
}
Region r = new Region(regionName, new ArrayList<>(), new ArrayList<>(), leaders, new int[] { x + 8, x + 8, x - 7, x - 7 }, new int[] { z + 8, z + 8, z - 7, z - 7 }, 0, w.getMaxHeight(), 0, c.getWorldName(), RPUtil.DateNow(), RPConfig.getDefFlagsValues(), "", 0, null, true);
MyChunkChunk.unclaim(chunk);
RedProtect.get().rm.add(r, w);
RedProtect.get().logger.warning("Region converted and named to " + r.getName());
i++;
}
RedProtect.get().logger.sucess(i + " MyChunk regions converted!");
return true;
} else {
return false;
}
}
use of org.bukkit.Chunk in project VoxelGamesLibv2 by VoxelGamesLib.
the class MapScanner method searchForMarkers.
/**
* Searches the map for "markers". Most of the time these are implemented as tile entities (skulls)
*
* @param map the map to scan
* @param center the center location
* @param range the range in where to scan
*/
public void searchForMarkers(@Nonnull Map map, @Nonnull Vector3D center, int range, @Nonnull UUID gameid) {
World world = Bukkit.getWorld(map.getLoadedName(gameid));
if (world == null) {
throw new MapException("Could not find world " + map.getLoadedName(gameid) + "(" + map.getInfo().getName() + ")" + ". Is it loaded?");
}
List<Marker> markers = new ArrayList<>();
List<ChestMarker> chestMarkers = new ArrayList<>();
int startX = (int) center.getX();
int startY = (int) center.getZ();
int minX = Math.min(startX - range, startX + range);
int minZ = Math.min(startY - range, startY + range);
int maxX = Math.max(startX - range, startX + range);
int maxZ = Math.max(startY - range, startY + range);
for (int x = minX; x <= maxX; x += 16) {
for (int z = minZ; z <= maxZ; z += 16) {
Chunk chunk = world.getChunkAt(x >> 4, z >> 4);
for (BlockState te : chunk.getTileEntities()) {
if (te.getType() == Material.SKULL) {
Skull skull = (Skull) te;
if (skull.getSkullType() == SkullType.PLAYER) {
String markerData = getMarkerData(skull);
if (markerData == null)
continue;
MarkerDefinition markerDefinition = mapHandler.createMarkerDefinition(markerData);
markers.add(new Marker(new Vector3D(skull.getX(), skull.getY(), skull.getZ()), DirectionUtil.directionToYaw(skull.getRotation()), markerData, markerDefinition));
}
} else if (te.getType() == Material.CHEST) {
Chest chest = (Chest) te;
String name = chest.getBlockInventory().getName();
ItemStack[] items = new ItemStack[chest.getBlockInventory().getStorageContents().length];
for (int i = 0; i < items.length; i++) {
ItemStack is = chest.getBlockInventory().getItem(i);
if (is == null) {
items[i] = new ItemStack(Material.AIR);
} else {
items[i] = is;
}
}
chestMarkers.add(new ChestMarker(new Vector3D(chest.getX(), chest.getY(), chest.getZ()), name, items));
}
}
}
}
map.setMarkers(markers);
map.setChestMarkers(chestMarkers);
}
use of org.bukkit.Chunk in project MagicPlugin by elBukkit.
the class TeleportTask method run.
@Override
public void run() {
Chunk chunk = location.getBlock().getChunk();
if (!chunk.isLoaded()) {
chunk.load(true);
if (retryCount > 0) {
retryCount--;
Plugin plugin = controller.getPlugin();
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, this, TELEPORT_RETRY_INTERVAL);
}
return;
}
Location targetLocation = location;
if (context != null) {
targetLocation = context.findPlaceToStand(location, verticalSearchDistance);
}
if (targetLocation == null && !preventFall) {
Block block = location.getBlock();
Block blockOneUp = block.getRelative(BlockFace.UP);
if (!safe || (context.isOkToStandIn(blockOneUp) && context.isOkToStandIn(block))) {
targetLocation = location;
}
}
if (targetLocation != null) {
targetLocation.setX(location.getX() - location.getBlockX() + targetLocation.getBlockX());
targetLocation.setZ(location.getZ() - location.getBlockZ() + targetLocation.getBlockZ());
if (context != null) {
context.registerMoved(entity);
}
// Hacky double-teleport to work-around vanilla suffocation checks
boolean isWorldChange = !targetLocation.getWorld().equals(entity.getWorld());
entity.teleport(targetLocation);
if (isWorldChange) {
entity.teleport(targetLocation);
}
if (context != null) {
context.setTargetLocation(targetLocation);
context.sendMessageKey("teleport");
context.playEffects("teleport");
}
} else if (context != null) {
context.sendMessageKey("teleport_failed");
context.playEffects("teleport_failed");
}
}
use of org.bukkit.Chunk in project MagicPlugin by elBukkit.
the class RecallSpell method tryTeleport.
protected boolean tryTeleport(final Player player, final Location targetLocation) {
if (targetLocation == null) {
sendMessage(failMessage);
return false;
}
if (!allowCrossWorld && !mage.getLocation().getWorld().equals(targetLocation.getWorld())) {
sendMessage(getMessage("cross_world_disallowed"));
return false;
}
Chunk chunk = targetLocation.getBlock().getChunk();
if (!chunk.isLoaded()) {
chunk.load(true);
if (retryCount < MAX_RETRY_COUNT) {
Plugin plugin = controller.getPlugin();
final RecallSpell me = this;
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
me.tryTeleport(player, targetLocation);
}
}, RETRY_INTERVAL);
return true;
}
}
registerMoved(player);
Location playerLocation = player.getLocation();
targetLocation.setYaw(playerLocation.getYaw());
targetLocation.setPitch(playerLocation.getPitch());
player.teleport(tryFindPlaceToStand(targetLocation));
castMessage(castMessage);
return true;
}
Aggregations