Minor API changes

This commit is contained in:
Jesse Boyd 2016-08-02 17:00:01 +10:00
parent 7c06899111
commit 39acae08aa
2 changed files with 127 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import com.boydti.fawe.object.changeset.FaweStreamChangeSet;
import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.WEManager;
import com.boydti.fawe.wrappers.FakePlayer;
@ -32,6 +33,8 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@ -101,6 +104,7 @@ public abstract class FawePlayer<T> {
return Fawe.imp().wrap(obj);
}
@Deprecated
public FawePlayer(final T parent) {
this.parent = parent;
Fawe.get().register(this);
@ -126,6 +130,10 @@ public abstract class FawePlayer<T> {
}
}
/**
* Loads any history items from disk:
* - Should already be called if history on disk is enabled
*/
public void loadClipboardFromDisk() {
File file = new File(Fawe.imp().getDirectory(), "clipboard" + File.separator + getUUID() + ".bd");
try {
@ -214,6 +222,9 @@ public abstract class FawePlayer<T> {
*/
public abstract void sendTitle(String head, String sub);
/**
* Remove the title
*/
public abstract void resetTitle();
/**
@ -312,6 +323,10 @@ public abstract class FawePlayer<T> {
this.getSession().setRegionSelector(player.getWorld(), selector);
}
/**
* Set the player's WorldEdit selection
* @param selector
*/
public void setSelection(final RegionSelector selector) {
this.getSession().setRegionSelector(getPlayer().getWorld(), selector);
}
@ -416,6 +431,11 @@ public abstract class FawePlayer<T> {
return WorldEdit.getInstance().getEditSessionFactory().getEditSession(getWorld(), -1, getPlayer());
}
/**
* Run a task if the player has no currently running action
* @param run
* @return If the task was run
*/
public boolean runIfFree(Runnable run) {
if (getMeta("fawe_action") != null) {
return false;
@ -436,6 +456,11 @@ public abstract class FawePlayer<T> {
return true;
}
/**
* Run an async task if the player has no currently running action
* @param run
* @return If the task was run
*/
public boolean runAsyncIfFree(final Runnable run) {
if (getMeta("fawe_action") != null) {
return false;
@ -460,4 +485,37 @@ public abstract class FawePlayer<T> {
});
return true;
}
/**
* Get the tracked EditSession(s) for this player<br>
* - Queued or autoqueued EditSessions are considered tracked
* @param requiredStage
* @return
*/
public Map<EditSession, SetQueue.QueueStage> getTrackedSessions(SetQueue.QueueStage requiredStage) {
Map<EditSession, SetQueue.QueueStage> map = new ConcurrentHashMap<>();
if (requiredStage == null || requiredStage == SetQueue.QueueStage.ACTIVE) {
for (FaweQueue queue : SetQueue.IMP.getActiveQueues()) {
Set<EditSession> sessions = queue.getEditSessions();
for (EditSession session : sessions) {
FawePlayer currentPlayer = session.getPlayer();
if (currentPlayer == this) {
map.put(session, SetQueue.QueueStage.ACTIVE);
}
}
}
}
if (requiredStage == null || requiredStage == SetQueue.QueueStage.INACTIVE) {
for (FaweQueue queue : SetQueue.IMP.getInactiveQueues()) {
Set<EditSession> sessions = queue.getEditSessions();
for (EditSession session : sessions) {
FawePlayer currentPlayer = session.getPlayer();
if (currentPlayer == this) {
map.put(session, SetQueue.QueueStage.INACTIVE);
}
}
}
}
return map;
}
}

View File

@ -160,6 +160,7 @@ public class EditSession implements Extent {
private HistoryExtent history;
private Extent bypassHistory;
private Extent bypassAll;
private FaweLimit originalLimit;
private FaweLimit limit;
private FawePlayer player;
private FaweChangeSet changeTask;
@ -204,7 +205,7 @@ public class EditSession implements Extent {
}
if (limit == null) {
if (player == null) {
limit = FaweLimit.MAX.copy();
limit = FaweLimit.MAX;
} else {
limit = player.getLimit();
}
@ -245,7 +246,8 @@ public class EditSession implements Extent {
throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_NO_REGION);
}
this.blockBag = blockBag;
this.limit = limit;
this.originalLimit = limit;
this.limit = limit.copy();
this.queue = SetQueue.IMP.getNewQueue(Fawe.imp().getWorldName(world), fastmode, autoQueue);
queue.addEditSession(this);
this.bypassAll = wrapExtent(new FastWorldEditExtent(world, queue), bus, event, Stage.BEFORE_CHANGE);
@ -305,13 +307,49 @@ public class EditSession implements Extent {
this(world, null, null, null, null, true, null, null, null, blockBag, eventBus, event);
}
/**
* The limit for this specific edit (blocks etc)
* @return
*/
public FaweLimit getLimit() {
return originalLimit;
}
/**
* Returns a new limit representing how much of this edit's limit has been used so far
* @return
*/
public FaweLimit getLimitUsed() {
FaweLimit newLimit = new FaweLimit();
newLimit.MAX_CHANGES = originalLimit.MAX_CHANGES - limit.MAX_CHANGES;
newLimit.MAX_FAILS = originalLimit.MAX_FAILS - limit.MAX_FAILS;
newLimit.MAX_CHECKS = originalLimit.MAX_CHECKS - limit.MAX_CHECKS;
newLimit.MAX_ITERATIONS = originalLimit.MAX_ITERATIONS - limit.MAX_ITERATIONS;
newLimit.MAX_BLOCKSTATES = originalLimit.MAX_BLOCKSTATES - limit.MAX_BLOCKSTATES;
newLimit.MAX_ENTITIES = originalLimit.MAX_ENTITIES - limit.MAX_ENTITIES;
newLimit.MAX_HISTORY = limit.MAX_HISTORY;
return newLimit;
}
/**
* Returns the remaining limits
* @return
*/
public FaweLimit getLimitLeft() {
return limit;
}
/**
* The region extent restricts block placements to allowed regions
* @return FaweRegionExtent (may be null)
*/
public FaweRegionExtent getRegionExtent() {
ExtentTraverser<FaweRegionExtent> traverser = new ExtentTraverser(this.extent).find(FaweRegionExtent.class);
return traverser == null ? null : traverser.get();
}
/**
* Get the actor
* Get the FawePlayer or null
* @return
*/
@Nullable
@ -337,26 +375,45 @@ public class EditSession implements Extent {
return true;
}
/**
* Remove this EditSession from the queue<br>
* - This doesn't necessarily stop it from being queued again
*/
public void dequeue() {
if (queue != null) {
SetQueue.IMP.dequeue(queue);
}
}
/**
* Add a task to run when this EditSession is done dispatching
* @param whenDone
*/
public void addNotifyTask(Runnable whenDone) {
if (queue != null) {
queue.addNotifyTask(whenDone);
}
}
/**
* Send a debug message to the Actor responsible for this EditSession (or Console)
* @param message
* @param args
*/
public void debug(BBC message, Object... args) {
message.send(player, args);
}
/**
* Get the FaweQueue this EditSession uses to queue the changes<br>
* - Note: All implementation queues for FAWE are instances of NMSMappedFaweQueue
* @return
*/
public FaweQueue getQueue() {
return queue;
}
@Deprecated
private Extent wrapExtent(final Extent extent, final EventBus eventBus, EditSessionEvent event, final Stage stage) {
event = event.clone(stage);
event.setExtent(extent);
@ -396,7 +453,12 @@ public class EditSession implements Extent {
return history != null ? history.getChangeSet() : changeTask;
}
public void setChangeSet(FaweChangeSet set) {
/**
* Change the ChangeSet being used for this EditSession
* - If history is disabled, no changeset can be set
* @param set (null = remove the changeset)
*/
public void setChangeSet(@Nullable FaweChangeSet set) {
if (set == null) {
disableHistory(true);
} else {
@ -411,13 +473,12 @@ public class EditSession implements Extent {
}
/**
* Get the maximum number of blocks that can be changed. -1 will be returned
* if it the limit disabled.
*
* @see #getLimit()
* @return the limit (&gt;= 0) or -1 for no limit
*/
@Deprecated
public int getBlockChangeLimit() {
return -1;
return originalLimit.MAX_CHANGES;
}
/**