Fix async/login event
This commit is contained in:
@@ -15,14 +15,16 @@ import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Represents an event which depends on the result of asynchronous operations.
|
||||
*
|
||||
* @param <T> Type of this event
|
||||
*/
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class AsyncEvent extends Event
|
||||
public class AsyncEvent<T> extends Event
|
||||
{
|
||||
|
||||
private final Callback done;
|
||||
private final Callback<T> done;
|
||||
private final Set<Plugin> intents = Collections.newSetFromMap( new ConcurrentHashMap<Plugin, Boolean>() );
|
||||
private final AtomicBoolean fired = new AtomicBoolean();
|
||||
private final AtomicInteger latch = new AtomicInteger();
|
||||
@@ -34,7 +36,7 @@ public class AsyncEvent extends Event
|
||||
fired.set( true );
|
||||
if ( latch.get() == 0 )
|
||||
{
|
||||
done.done( this, null );
|
||||
done.done( (T) this, null );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +68,7 @@ public class AsyncEvent extends Event
|
||||
intents.remove( plugin );
|
||||
if ( latch.decrementAndGet() == 0 )
|
||||
{
|
||||
done.done( this, null );
|
||||
done.done( (T) this, null );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,9 +3,9 @@ package net.md_5.bungee.api.event;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
/**
|
||||
* Event called to represent a player logging in.
|
||||
@@ -13,7 +13,7 @@ import net.md_5.bungee.api.plugin.Event;
|
||||
@Data
|
||||
@ToString(callSuper = false)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class LoginEvent extends Event implements Cancellable
|
||||
public class LoginEvent extends AsyncEvent<LoginEvent> implements Cancellable
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -28,4 +28,10 @@ public class LoginEvent extends Event implements Cancellable
|
||||
* Connection attempting to login.
|
||||
*/
|
||||
private final PendingConnection connection;
|
||||
|
||||
public LoginEvent(PendingConnection connection, Callback<LoginEvent> done)
|
||||
{
|
||||
super( done );
|
||||
this.connection = connection;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user