mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
FaweAPI
This commit is contained in:
parent
f500b5e056
commit
1dcb18ae20
@ -1,20 +1,18 @@
|
|||||||
package com.boydti.fawe;
|
package com.boydti.fawe;
|
||||||
|
|
||||||
|
import com.boydti.fawe.beta.IQueueExtent;
|
||||||
import com.boydti.fawe.config.BBC;
|
import com.boydti.fawe.config.BBC;
|
||||||
import com.boydti.fawe.config.Settings;
|
import com.boydti.fawe.config.Settings;
|
||||||
import com.boydti.fawe.example.NMSMappedFaweQueue;
|
|
||||||
import com.boydti.fawe.example.NMSRelighter;
|
|
||||||
import com.boydti.fawe.object.FawePlayer;
|
import com.boydti.fawe.object.FawePlayer;
|
||||||
import com.boydti.fawe.object.FaweQueue;
|
|
||||||
import com.boydti.fawe.object.RegionWrapper;
|
import com.boydti.fawe.object.RegionWrapper;
|
||||||
import com.boydti.fawe.object.changeset.DiskStorageHistory;
|
import com.boydti.fawe.object.changeset.DiskStorageHistory;
|
||||||
import com.boydti.fawe.object.exception.FaweException;
|
import com.boydti.fawe.object.exception.FaweException;
|
||||||
|
import com.boydti.fawe.object.extent.LightingExtent;
|
||||||
import com.boydti.fawe.object.schematic.Schematic;
|
import com.boydti.fawe.object.schematic.Schematic;
|
||||||
import com.boydti.fawe.regions.FaweMaskManager;
|
import com.boydti.fawe.regions.FaweMaskManager;
|
||||||
import com.boydti.fawe.util.EditSessionBuilder;
|
import com.boydti.fawe.util.EditSessionBuilder;
|
||||||
import com.boydti.fawe.util.MainUtil;
|
import com.boydti.fawe.util.MainUtil;
|
||||||
import com.boydti.fawe.util.MemUtil;
|
import com.boydti.fawe.util.MemUtil;
|
||||||
import com.boydti.fawe.util.SetQueue;
|
|
||||||
import com.boydti.fawe.util.TaskManager;
|
import com.boydti.fawe.util.TaskManager;
|
||||||
import com.boydti.fawe.util.WEManager;
|
import com.boydti.fawe.util.WEManager;
|
||||||
import com.boydti.fawe.wrappers.WorldWrapper;
|
import com.boydti.fawe.wrappers.WorldWrapper;
|
||||||
@ -148,7 +146,7 @@ public class FaweAPI {
|
|||||||
* @param aliases The aliases to give the command (or none)
|
* @param aliases The aliases to give the command (or none)
|
||||||
*/
|
*/
|
||||||
public static void registerCommands(Object clazz, String... aliases) {
|
public static void registerCommands(Object clazz, String... aliases) {
|
||||||
PlatformCommandManager.getInstance().registerCommands(clazz, aliases);
|
// PlatformCommandManager.getInstance().registerCommands(clazz, aliases); TODO NOT IMPLEMENTED
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,23 +164,23 @@ public class FaweAPI {
|
|||||||
return FawePlayer.wrap(obj);
|
return FawePlayer.wrap(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FaweQueue createQueue(String worldName, boolean autoqueue) {
|
|
||||||
return SetQueue.IMP.getNewQueue(worldName, true, autoqueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You can either use a FaweQueue or an EditSession to change blocks<br>
|
* You can either use a IQueueExtent or an EditSession to change blocks<br>
|
||||||
* - The FaweQueue skips a bit of overhead so it's faster<br>
|
* - The IQueueExtent skips a bit of overhead so it's marginally faster<br>
|
||||||
* - The WorldEdit EditSession can do a lot more<br>
|
* - The WorldEdit EditSession can do a lot more<br>
|
||||||
* Remember to enqueue it when you're done!<br>
|
* Remember to commit when you're done!<br>
|
||||||
*
|
*
|
||||||
* @param world The name of the world
|
* @param world The name of the world
|
||||||
* @param autoqueue If it should start dispatching before you enqueue it.
|
* @param autoqueue If it should start dispatching before you enqueue it.
|
||||||
* @return
|
* @return
|
||||||
* @see FaweQueue#enqueue()
|
* @see FaweQueue#enqueue()
|
||||||
*/
|
*/
|
||||||
public static FaweQueue createQueue(World world, boolean autoqueue) {
|
public static IQueueExtent createQueue(World world, boolean autoqueue) {
|
||||||
return SetQueue.IMP.getNewQueue(world, true, autoqueue);
|
IQueueExtent queue = Fawe.get().getQueueHandler().getQueue(world);
|
||||||
|
if (!autoqueue) {
|
||||||
|
queue.disableQueue();
|
||||||
|
}
|
||||||
|
return queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static World getWorld(String worldName) {
|
public static World getWorld(String worldName) {
|
||||||
@ -416,19 +414,10 @@ public class FaweAPI {
|
|||||||
return (version[0] > major) || ((version[0] == major) && (version[1] > minor)) || ((version[0] == major) && (version[1] == minor) && (version[2] >= minor2));
|
return (version[0] > major) || ((version[0] == major) && (version[1] > minor)) || ((version[0] == major) && (version[1] == minor) && (version[2] >= minor2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static int fixLighting(String world, Region selection) {
|
|
||||||
return fixLighting(world, selection, FaweQueue.RelightMode.ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static int fixLighting(String world, Region selection, final FaweQueue.RelightMode mode) {
|
public static int fixLighting(World world, Region selection) {
|
||||||
return fixLighting(world, selection, null, mode);
|
return fixLighting(world, selection, null);
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static int fixLighting(String world, Region selection, @Nullable FaweQueue queue, final FaweQueue.RelightMode mode) {
|
|
||||||
return fixLighting(getWorld(world), selection, queue, mode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -441,7 +430,7 @@ public class FaweAPI {
|
|||||||
* @param selection (assumes cuboid)
|
* @param selection (assumes cuboid)
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static int fixLighting(World world, Region selection, @Nullable FaweQueue queue, final FaweQueue.RelightMode mode) {
|
public static int fixLighting(World world, Region selection, @Nullable IQueueExtent queue) {
|
||||||
final BlockVector3 bot = selection.getMinimumPoint();
|
final BlockVector3 bot = selection.getMinimumPoint();
|
||||||
final BlockVector3 top = selection.getMaximumPoint();
|
final BlockVector3 top = selection.getMaximumPoint();
|
||||||
|
|
||||||
@ -452,42 +441,22 @@ public class FaweAPI {
|
|||||||
final int maxZ = top.getBlockZ() >> 4;
|
final int maxZ = top.getBlockZ() >> 4;
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if (queue == null) {
|
if (queue == null) queue = createQueue(world, false);
|
||||||
queue = SetQueue.IMP.getNewQueue(world, true, false);
|
|
||||||
}
|
|
||||||
// Remove existing lighting first
|
// Remove existing lighting first
|
||||||
if (queue instanceof NMSMappedFaweQueue) {
|
if (queue instanceof LightingExtent) {
|
||||||
final NMSMappedFaweQueue nmsQueue = (NMSMappedFaweQueue) queue;
|
LightingExtent relighter = (LightingExtent) queue;
|
||||||
NMSRelighter relighter = new NMSRelighter(nmsQueue);
|
|
||||||
for (int x = minX; x <= maxX; x++) {
|
for (int x = minX; x <= maxX; x++) {
|
||||||
for (int z = minZ; z <= maxZ; z++) {
|
for (int z = minZ; z <= maxZ; z++) {
|
||||||
relighter.addChunk(x, z, null, 65535);
|
relighter.relightChunk(x, z);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mode != FaweQueue.RelightMode.NONE) {
|
} else {
|
||||||
boolean sky = nmsQueue.hasSky();
|
throw new UnsupportedOperationException("Queue is not " + LightingExtent.class);
|
||||||
if (sky) {
|
|
||||||
relighter.fixSkyLighting();
|
|
||||||
}
|
|
||||||
relighter.fixBlockLighting();
|
|
||||||
} else {
|
|
||||||
relighter.removeLighting();
|
|
||||||
}
|
|
||||||
relighter.sendChunks();
|
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a task to run when the global queue (SetQueue class) is empty
|
|
||||||
*
|
|
||||||
* @param whenDone
|
|
||||||
*/
|
|
||||||
public static void addTask(final Runnable whenDone) {
|
|
||||||
SetQueue.IMP.addEmptyTask(whenDone);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Have a task run when the server is low on memory (configured threshold)
|
* Have a task run when the server is low on memory (configured threshold)
|
||||||
*
|
*
|
||||||
|
@ -4,7 +4,6 @@ import com.boydti.fawe.Fawe;
|
|||||||
import com.boydti.fawe.object.FaweInputStream;
|
import com.boydti.fawe.object.FaweInputStream;
|
||||||
import com.boydti.fawe.object.FaweOutputStream;
|
import com.boydti.fawe.object.FaweOutputStream;
|
||||||
import com.boydti.fawe.object.FawePlayer;
|
import com.boydti.fawe.object.FawePlayer;
|
||||||
import com.boydti.fawe.object.FaweQueue;
|
|
||||||
import com.boydti.fawe.object.Metadatable;
|
import com.boydti.fawe.object.Metadatable;
|
||||||
import com.boydti.fawe.object.RunnableVal2;
|
import com.boydti.fawe.object.RunnableVal2;
|
||||||
import com.boydti.fawe.object.brush.visualization.VirtualWorld;
|
import com.boydti.fawe.object.brush.visualization.VirtualWorld;
|
||||||
@ -21,7 +20,6 @@ import com.boydti.fawe.object.schematic.Schematic;
|
|||||||
import com.boydti.fawe.util.CachedTextureUtil;
|
import com.boydti.fawe.util.CachedTextureUtil;
|
||||||
import com.boydti.fawe.util.RandomTextureUtil;
|
import com.boydti.fawe.util.RandomTextureUtil;
|
||||||
import com.boydti.fawe.util.ReflectionUtils;
|
import com.boydti.fawe.util.ReflectionUtils;
|
||||||
import com.boydti.fawe.util.SetQueue;
|
|
||||||
import com.boydti.fawe.util.TaskManager;
|
import com.boydti.fawe.util.TaskManager;
|
||||||
import com.boydti.fawe.util.TextureUtil;
|
import com.boydti.fawe.util.TextureUtil;
|
||||||
import com.boydti.fawe.util.image.Drawable;
|
import com.boydti.fawe.util.image.Drawable;
|
||||||
@ -745,22 +743,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTile(int x, int y, int z, CompoundTag tag) {
|
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
||||||
// Not implemented
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEntity(int x, int y, int z, CompoundTag tag) {
|
|
||||||
// Not implemented
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeEntity(int x, int y, int z, UUID uuid) {
|
|
||||||
// Not implemented
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setBiome(int x, int z, BiomeType biome) {
|
|
||||||
int index = z * getWidth() + x;
|
int index = z * getWidth() + x;
|
||||||
if (index < 0 || index >= getArea()) return false;
|
if (index < 0 || index >= getArea()) return false;
|
||||||
biomes.setByte(index, (byte) biome.getInternalId());
|
biomes.setByte(index, (byte) biome.getInternalId());
|
||||||
|
@ -119,31 +119,31 @@ public abstract class FawePlayer<T> extends Metadatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int cancel(boolean close) {
|
public int cancel(boolean close) {
|
||||||
Collection<FaweQueue> queues = SetQueue.IMP.getAllQueues();
|
// Collection<FaweQueue> queues = SetQueue.IMP.getAllQueues(); TODO NOT IMPLEMENTED
|
||||||
int cancelled = 0;
|
int cancelled = 0;
|
||||||
clearActions();
|
// clearActions();
|
||||||
for (FaweQueue queue : queues) {
|
// for (FaweQueue queue : queues) {
|
||||||
Collection<EditSession> sessions = queue.getEditSessions();
|
// Collection<EditSession> sessions = queue.getEditSessions();
|
||||||
for (EditSession session : sessions) {
|
// for (EditSession session : sessions) {
|
||||||
FawePlayer currentPlayer = session.getPlayer();
|
// FawePlayer currentPlayer = session.getPlayer();
|
||||||
if (currentPlayer == this) {
|
// if (currentPlayer == this) {
|
||||||
if (session.cancel()) {
|
// if (session.cancel()) {
|
||||||
cancelled++;
|
// cancelled++;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
VirtualWorld world = getSession().getVirtualWorld();
|
// VirtualWorld world = getSession().getVirtualWorld();
|
||||||
if (world != null) {
|
// if (world != null) {
|
||||||
if (close) {
|
// if (close) {
|
||||||
try {
|
// try {
|
||||||
world.close(false);
|
// world.close(false);
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else world.clear();
|
// else world.clear();
|
||||||
}
|
// }
|
||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,4 +12,6 @@ public interface LightingExtent extends Extent {
|
|||||||
int getOpacity(int x, int y, int z);
|
int getOpacity(int x, int y, int z);
|
||||||
|
|
||||||
int getBrightness(int x, int y, int z);
|
int getBrightness(int x, int y, int z);
|
||||||
|
|
||||||
|
public void relightChunk(int chunkX, int chunkZ);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user