mirror of
https://github.com/Eaglercraft-Archive/Eaglercraftx-1.8.8-src.git
synced 2025-06-27 18:38:14 -05:00
Update #0 - First Release
This commit is contained in:
@ -0,0 +1,34 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.futures;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class CancellationException extends IllegalStateException {
|
||||
|
||||
public CancellationException() {
|
||||
|
||||
}
|
||||
|
||||
public CancellationException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
public CancellationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public CancellationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.futures;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ExecutionException extends RuntimeException {
|
||||
|
||||
public ExecutionException() {
|
||||
}
|
||||
|
||||
public ExecutionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ExecutionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ExecutionException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.futures;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class Executors {
|
||||
|
||||
public static <T> Callable<T> callable(Runnable task, T result) {
|
||||
if (task == null)
|
||||
throw new NullPointerException();
|
||||
return new RunnableAdapter<T>(task, result);
|
||||
}
|
||||
|
||||
public static Callable<Object> callable(Runnable task) {
|
||||
if (task == null)
|
||||
throw new NullPointerException();
|
||||
return new RunnableAdapter<Object>(task, null);
|
||||
}
|
||||
|
||||
static final class RunnableAdapter<T> implements Callable<T> {
|
||||
final Runnable task;
|
||||
final T result;
|
||||
|
||||
RunnableAdapter(Runnable task, T result) {
|
||||
this.task = task;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public T call() {
|
||||
task.run();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.futures;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public interface Future<V> {
|
||||
|
||||
boolean cancel(boolean mayInterruptIfRunning);
|
||||
|
||||
boolean isCancelled();
|
||||
|
||||
boolean isDone();
|
||||
|
||||
V get() throws InterruptedException, ExecutionException;
|
||||
|
||||
V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException;
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.futures;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class FutureTask<V> implements RunnableFuture<V> {
|
||||
|
||||
private boolean cancelled;
|
||||
private boolean completed;
|
||||
private V result;
|
||||
private Callable<V> callable;
|
||||
|
||||
public FutureTask(Callable<V> callable) {
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
if(!cancelled) {
|
||||
cancelled = true;
|
||||
if(!completed) {
|
||||
done();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return cancelled || completed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() throws InterruptedException, ExecutionException {
|
||||
if(!completed) {
|
||||
if(!cancelled) {
|
||||
try {
|
||||
result = callable.call();
|
||||
}catch(Throwable t) {
|
||||
throw new ExecutionException(t);
|
||||
}finally {
|
||||
completed = true;
|
||||
done();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException {
|
||||
return get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
get();
|
||||
} catch (ExecutionException t) {
|
||||
throw t;
|
||||
} catch (Throwable t) {
|
||||
throw new ExecutionException(t);
|
||||
}
|
||||
}
|
||||
|
||||
protected void done() {
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.futures;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class Futures {
|
||||
|
||||
private abstract static class ImmediateFuture<V> implements ListenableFuture<V> {
|
||||
|
||||
private static final Logger log = LogManager.getLogger(ImmediateFuture.class.getName());
|
||||
|
||||
@Override
|
||||
public void addListener(Runnable listener, Executor executor) {
|
||||
checkNotNull(listener, "Runnable was null.");
|
||||
checkNotNull(executor, "Executor was null.");
|
||||
try {
|
||||
executor.execute(listener);
|
||||
} catch (RuntimeException e) {
|
||||
log.error("RuntimeException while executing runnable " + listener + " with executor " + executor, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract V get() throws ExecutionException;
|
||||
|
||||
@Override
|
||||
public V get(long timeout, TimeUnit unit) throws ExecutionException {
|
||||
checkNotNull(unit);
|
||||
return get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ImmediateSuccessfulFuture<V> extends ImmediateFuture<V> {
|
||||
|
||||
@Nullable
|
||||
private final V value;
|
||||
|
||||
ImmediateSuccessfulFuture(@Nullable V value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ImmediateFailedFuture<V> extends ImmediateFuture<V> {
|
||||
|
||||
private final Throwable thrown;
|
||||
|
||||
ImmediateFailedFuture(Throwable thrown) {
|
||||
this.thrown = thrown;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() throws ExecutionException {
|
||||
throw new ExecutionException(thrown);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ImmediateCancelledFuture<V> extends ImmediateFuture<V> {
|
||||
|
||||
private final CancellationException thrown;
|
||||
|
||||
ImmediateCancelledFuture() {
|
||||
this.thrown = new CancellationException("Immediate cancelled future.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() {
|
||||
throw new CancellationException("Task was cancelled.", thrown);
|
||||
}
|
||||
}
|
||||
|
||||
public static <V> ListenableFuture<V> immediateFuture(@Nullable V value) {
|
||||
return new ImmediateSuccessfulFuture<V>(value);
|
||||
}
|
||||
|
||||
public static <V> ListenableFuture<V> immediateFailedFuture(Throwable throwable) {
|
||||
checkNotNull(throwable);
|
||||
return new ImmediateFailedFuture<V>(throwable);
|
||||
}
|
||||
|
||||
public static <V> ListenableFuture<V> immediateCancelledFuture() {
|
||||
return new ImmediateCancelledFuture<V>();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.futures;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public interface ListenableFuture<V> extends Future<V> {
|
||||
|
||||
static final Logger futureExceptionLogger = LogManager.getLogger("ListenableFuture");
|
||||
|
||||
void addListener(Runnable listener, Executor executor);
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.futures;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ListenableFutureTask<V> extends FutureTask<V> implements ListenableFuture<V> {
|
||||
|
||||
private final List<Runnable> listeners = new ArrayList();
|
||||
|
||||
public ListenableFutureTask(Callable<V> callable) {
|
||||
super(callable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(final Runnable listener, final Executor executor) {
|
||||
listeners.add(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
executor.execute(listener); // so dumb
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
protected void done() {
|
||||
for(Runnable r : listeners) {
|
||||
try {
|
||||
r.run();
|
||||
}catch(Throwable t) {
|
||||
ListenableFuture.futureExceptionLogger.error("Exception caught running future listener!");
|
||||
ListenableFuture.futureExceptionLogger.error(t);
|
||||
}
|
||||
}
|
||||
listeners.clear();
|
||||
}
|
||||
|
||||
public static <V> ListenableFutureTask<V> create(Callable<V> callableToSchedule) {
|
||||
return new ListenableFutureTask(callableToSchedule);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.futures;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public interface RunnableFuture<V> extends Runnable, Future<V> {
|
||||
void run();
|
||||
}
|
Reference in New Issue
Block a user