mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-29 23:17:41 +02:00
Extend by convenience methods.
This commit is contained in:
parent
e6cc1bad05
commit
4ab4ebd331
@ -8,8 +8,10 @@ import fr.neatmonster.nocheatplus.components.registry.event.IHandle;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience for providing several checks with a lazy-init handle for fetching
|
* Convenience for providing several checks with a lazy-init handle for fetching
|
||||||
* queued flying packets. Future concept should be somehow linking follow-up
|
* queued flying packets. Typical use means only fetching this, if really
|
||||||
* packets (flying->dig) to each other...
|
* necessary, so isFlyingQueueFetched() returns false, if a default or current
|
||||||
|
* position/look has passed checks. Future concept should be somehow linking
|
||||||
|
* follow-up packets (flying->dig) to each other...
|
||||||
*
|
*
|
||||||
* @author asofold
|
* @author asofold
|
||||||
*
|
*
|
||||||
@ -31,8 +33,57 @@ public class FlyingQueueHandle implements IHandle<DataPacketFlying[]> {
|
|||||||
return queue;
|
return queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if the queue has been fetched.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public boolean isFlyingQueueFetched() {
|
public boolean isFlyingQueueFetched() {
|
||||||
return queue != null;
|
return queue != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the first index where the element is not null, if not fetched or no
|
||||||
|
* non-null element is found, -1 is returned.
|
||||||
|
*
|
||||||
|
* @return -1 if the queue has not been fetched yet or if all elements are
|
||||||
|
* null, otherwise the lowest index of a non null element is
|
||||||
|
* returned.
|
||||||
|
*/
|
||||||
|
public int getFirstIndexWithContentIfFetched() {
|
||||||
|
if (queue == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (int i = 0; i < queue.length; i++) {
|
||||||
|
if (queue[i] != null) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the element at the given index, only if fetched.
|
||||||
|
*
|
||||||
|
* @param index
|
||||||
|
* @return If already feteched, the element at the index is returned,
|
||||||
|
* otherwiese null is returned.
|
||||||
|
* @throws ArrayIndexOutOfBoundsException
|
||||||
|
* If the index is out of range.
|
||||||
|
*/
|
||||||
|
public DataPacketFlying getIfFetched(final int index) {
|
||||||
|
return queue == null ? null : queue[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the queue size only if fetched - otherwise -1 is returned.
|
||||||
|
*
|
||||||
|
* @return Size of the queue if fetched, -1 otherwise.
|
||||||
|
*/
|
||||||
|
public int sizeIfFetched() {
|
||||||
|
return queue == null ? -1 : queue.length;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user