More changes. API is going well, but struggling to break it up into sensible classes whilst allowing for the fact that in the future we will have:
- Player to Proxy - Proxy to Proxy - Player to Internal Server Connections.
This commit is contained in:
21
api/src/main/java/net/md_5/bungee/api/CommandSender.java
Normal file
21
api/src/main/java/net/md_5/bungee/api/CommandSender.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package net.md_5.bungee.api;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface CommandSender
|
||||
{
|
||||
|
||||
public String getName();
|
||||
|
||||
public void sendMessage(String message);
|
||||
|
||||
public Collection<String> getGroups();
|
||||
|
||||
public void addGroups(String... groups);
|
||||
|
||||
public void removeGroups(String... groups);
|
||||
|
||||
public boolean hasPermission(String permission);
|
||||
|
||||
public boolean setPermission(String permission, boolean value);
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
package net.md_5.bungee.api;
|
||||
|
||||
/**
|
||||
* Represents a player physically connected to the world hosted on this server.
|
||||
*/
|
||||
public interface ConnectedPlayer extends ProxiedPlayer
|
||||
{
|
||||
}
|
@@ -7,7 +7,7 @@ import java.net.InetSocketAddress;
|
||||
* It should expose information about the remote peer, however not be specific
|
||||
* to a type of connection, whether server or player.
|
||||
*/
|
||||
public abstract class ProxyConnection
|
||||
public interface Connection
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -15,5 +15,5 @@ public abstract class ProxyConnection
|
||||
*
|
||||
* @return the remote address
|
||||
*/
|
||||
public abstract InetSocketAddress getAddress();
|
||||
public InetSocketAddress getAddress();
|
||||
}
|
9
api/src/main/java/net/md_5/bungee/api/ProxiedPlayer.java
Normal file
9
api/src/main/java/net/md_5/bungee/api/ProxiedPlayer.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package net.md_5.bungee.api;
|
||||
|
||||
/**
|
||||
* Represents a player who's connection is being connected to somewhere else,
|
||||
* whether it be a remote or embedded server.
|
||||
*/
|
||||
public interface ProxiedPlayer extends Connection, CommandSender
|
||||
{
|
||||
}
|
@@ -5,21 +5,12 @@ import com.google.common.base.Preconditions;
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Logger;
|
||||
import lombok.Getter;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
public abstract class ProxyServer
|
||||
{
|
||||
|
||||
@Getter
|
||||
private static ProxyServer instance;
|
||||
private ThreadLocal<Yaml> yaml = new ThreadLocal<Yaml>()
|
||||
{
|
||||
@Override
|
||||
protected Yaml initialValue()
|
||||
{
|
||||
return new Yaml();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the proxy instance. This method may only be called once per an
|
||||
@@ -34,16 +25,6 @@ public abstract class ProxyServer
|
||||
ProxyServer.instance = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a reusable, thread safe {@link Yaml} instance.
|
||||
*
|
||||
* @return an {@link Yaml} instance
|
||||
*/
|
||||
public Yaml getYaml()
|
||||
{
|
||||
return yaml.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the currently running proxy software.
|
||||
*
|
||||
@@ -71,7 +52,7 @@ public abstract class ProxyServer
|
||||
*
|
||||
* @return all networked users
|
||||
*/
|
||||
public abstract Collection<ProxyConnection> getConnections();
|
||||
public abstract Collection<Connection> getConnections();
|
||||
|
||||
/**
|
||||
* Get the {@link PluginManager} associated with loading plugins and
|
||||
|
@@ -7,7 +7,7 @@ import lombok.RequiredArgsConstructor;
|
||||
* Represents a destination which this proxy might connect to.
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public abstract class RemoteServer extends ProxyConnection
|
||||
public abstract class Server implements Connection
|
||||
{
|
||||
|
||||
@Getter
|
28
api/src/main/java/net/md_5/bungee/api/event/ChatEvent.java
Normal file
28
api/src/main/java/net/md_5/bungee/api/event/ChatEvent.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package net.md_5.bungee.api.event;
|
||||
|
||||
import lombok.Data;
|
||||
import net.md_5.bungee.api.Connection;
|
||||
import net.md_5.bungee.api.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
|
||||
@Data
|
||||
public class ChatEvent implements Cancellable
|
||||
{
|
||||
|
||||
/**
|
||||
* Cancelled state.
|
||||
*/
|
||||
private boolean cancelled;
|
||||
/**
|
||||
* Where this message is being sent to.
|
||||
*/
|
||||
private final Connection destination;
|
||||
/**
|
||||
* User involved with sending or receiving this message.
|
||||
*/
|
||||
private final ProxiedPlayer player;
|
||||
/**
|
||||
* Text contained in this chat.
|
||||
*/
|
||||
private String message;
|
||||
}
|
34
api/src/main/java/net/md_5/bungee/api/event/LoginEvent.java
Normal file
34
api/src/main/java/net/md_5/bungee/api/event/LoginEvent.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package net.md_5.bungee.api.event;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import lombok.Data;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
|
||||
/**
|
||||
* Event called to represent a player logging in.
|
||||
*/
|
||||
@Data
|
||||
public class LoginEvent implements Cancellable
|
||||
{
|
||||
|
||||
/**
|
||||
* Cancelled state.
|
||||
*/
|
||||
private boolean cancelled;
|
||||
/**
|
||||
* Message to use when kicking if this event is canceled.
|
||||
*/
|
||||
private String cancelReason;
|
||||
/**
|
||||
* Username which the player wishes to use.
|
||||
*/
|
||||
private final String username;
|
||||
/**
|
||||
* IP address of the remote connection.
|
||||
*/
|
||||
private final InetAddress address;
|
||||
/**
|
||||
* Hostname which the user tried to connect to.
|
||||
*/
|
||||
private final String hostname;
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package net.md_5.bungee.api.event;
|
||||
|
||||
import lombok.Data;
|
||||
import net.md_5.bungee.api.Connection;
|
||||
import net.md_5.bungee.api.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
|
||||
/**
|
||||
* Event called when a plugin message is sent to the client or server.
|
||||
*/
|
||||
@Data
|
||||
public class PluginMessageEvent implements Cancellable
|
||||
{
|
||||
|
||||
/**
|
||||
* Cancelled state.
|
||||
*/
|
||||
private boolean cancelled;
|
||||
/**
|
||||
* Dispatcher of this message.
|
||||
*/
|
||||
private final Connection sender;
|
||||
/**
|
||||
* Player involved with sending or receiving this message.
|
||||
*/
|
||||
private final ProxiedPlayer player;
|
||||
/**
|
||||
* Tag specified for this plugin message.
|
||||
*/
|
||||
private String tag;
|
||||
/**
|
||||
* Data contained in this plugin message.
|
||||
*/
|
||||
private byte[] data;
|
||||
}
|
@@ -14,6 +14,7 @@ import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Level;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
/**
|
||||
* Class to manage bridging between plugin duties and implementation duties, for
|
||||
@@ -22,6 +23,7 @@ import net.md_5.bungee.api.ProxyServer;
|
||||
public class PluginManager
|
||||
{
|
||||
|
||||
private final Yaml yaml = new Yaml();
|
||||
private final EventBus eventBus = new EventBus();
|
||||
private final Map<String, Plugin> plugins = new HashMap<>();
|
||||
|
||||
@@ -63,7 +65,7 @@ public class PluginManager
|
||||
JarEntry pdf = jar.getJarEntry("plugin.yml");
|
||||
try (InputStream in = jar.getInputStream(pdf))
|
||||
{
|
||||
PluginDescription desc = ProxyServer.getInstance().getYaml().loadAs(in, PluginDescription.class);
|
||||
PluginDescription desc = yaml.loadAs(in, PluginDescription.class);
|
||||
URLClassLoader loader = new URLClassLoader(new URL[]
|
||||
{
|
||||
file.toURI().toURL()
|
||||
|
Reference in New Issue
Block a user