Skip to content
This repository has been archived by the owner on Aug 31, 2019. It is now read-only.

Commit

Permalink
Implement minecraft-api
Browse files Browse the repository at this point in the history
  • Loading branch information
jedediah committed Feb 18, 2016
1 parent e6af488 commit 676e5a4
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 72 deletions.
5 changes: 5 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<description>API implemented by the Elastic Portal Suite</description>

<dependencies>
<dependency>
<groupId>tc.oc</groupId>
<artifactId>minecraft-api</artifactId>
<version>1.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>tc.oc</groupId>
<artifactId>bungeecord-chat</artifactId>
Expand Down
41 changes: 1 addition & 40 deletions api/src/main/java/net/md_5/bungee/api/CommandSender.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
package net.md_5.bungee.api;

import net.md_5.bungee.api.chat.BaseComponent;

import java.util.Collection;

public interface CommandSender
public interface CommandSender extends tc.oc.minecraft.api.command.CommandSender
{

/**
* Get the unique name of this command sender.
*
* @return the senders username
*/
public String getName();

/**
* Send a message to this sender.
*
* @param message the message to send
*/
@Deprecated
public void sendMessage(String message);

/**
* Send several messages to this sender. Each message will be sent
* separately.
Expand All @@ -31,20 +14,6 @@ public interface CommandSender
@Deprecated
public void sendMessages(String... messages);

/**
* Send a message to this sender.
*
* @param message the message to send
*/
public void sendMessage(BaseComponent... message);

/**
* Send a message to this sender.
*
* @param message the message to send
*/
public void sendMessage(BaseComponent message);

/**
* Get all groups this user is part of. This returns an unmodifiable
* collection.
Expand All @@ -67,14 +36,6 @@ public interface CommandSender
*/
public void removeGroups(String... groups);

/**
* Checks if this user has the specified permission node.
*
* @param permission the node to check
* @return whether they have this node
*/
public boolean hasPermission(String permission);

/**
* Set a permission node for this user.
*
Expand Down
14 changes: 13 additions & 1 deletion api/src/main/java/net/md_5/bungee/api/ProxyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.scheduler.TaskScheduler;

public abstract class ProxyServer
public abstract class ProxyServer implements tc.oc.minecraft.api.server.LocalServer
{

@Getter
Expand Down Expand Up @@ -87,6 +87,18 @@ public static void setInstance(ProxyServer instance)
*/
public abstract ProxiedPlayer getPlayer(UUID uuid);

@Override
public ProxiedPlayer getPlayerExact(String name)
{
return getPlayer( name );
}

@Override
public Collection<ProxiedPlayer> getOnlinePlayers()
{
return getPlayers();
}

/**
* Return all servers registered to this proxy, keyed by name. Unlike the
* methods in {@link ConfigurationAdapter#getServers()}, this will not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Class used to represent a server to connect to.
*/
public interface ServerInfo
public interface ServerInfo extends tc.oc.minecraft.api.server.Server
{

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Locale;
import java.util.Map;
import java.util.UUID;

import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.CommandSender;
Expand All @@ -14,24 +14,9 @@
* 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
public interface ProxiedPlayer extends Connection, CommandSender, tc.oc.minecraft.api.entity.Player
{

/**
* Gets this player's display name.
*
* @return the players current display name
*/
String getDisplayName();

/**
* Sets this players display name to be used as their nametag and tab list
* name.
*
* @param name the name to set
*/
void setDisplayName(String name);

/**
* Send a message to the specified screen position of this player.
*
Expand Down Expand Up @@ -128,13 +113,6 @@ public interface ProxiedPlayer extends Connection, CommandSender
@Deprecated
String getUUID();

/**
* Get this connection's UUID, if set.
*
* @return the UUID
*/
UUID getUniqueId();

/**
* Gets this player's locale.
*
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/net/md_5/bungee/api/plugin/Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
/**
* Dummy interface which all event subscribers and listeners must implement.
*/
public interface Listener
public interface Listener extends tc.oc.minecraft.api.event.Listener
{
}
14 changes: 13 additions & 1 deletion api/src/main/java/net/md_5/bungee/api/plugin/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Represents any Plugin that may be loaded at runtime to enhance existing
* functionality.
*/
public class Plugin
public class Plugin implements tc.oc.minecraft.api.plugin.Plugin
{

@Getter
Expand Down Expand Up @@ -50,6 +50,12 @@ public void onDisable()
{
}

@Override
public ProxyServer getServer()
{
return getProxy();
}

/**
* Gets the data folder where this plugin may store arbitrary data. It will
* be a child of {@link ProxyServer#getPluginsFolder()}.
Expand All @@ -61,6 +67,12 @@ public final File getDataFolder()
return new File( getProxy().getPluginsFolder(), getDescription().getName() );
}

@Override
public InputStream getResource(String name)
{
return getResourceAsStream( name );
}

/**
* Get a resource from within this plugins jar or container. Care must be
* taken to close the returned stream.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package net.md_5.bungee.api.plugin;

import java.io.File;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.google.common.collect.ImmutableList;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -13,7 +17,7 @@
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PluginDescription
public class PluginDescription implements tc.oc.minecraft.api.plugin.PluginDescription
{

/**
Expand Down Expand Up @@ -48,4 +52,22 @@ public class PluginDescription
* Optional description.
*/
private String description = null;

@Override
public List<String> getAuthors()
{
return Collections.singletonList( author );
}

@Override
public List<String> getDepend()
{
return ImmutableList.copyOf( getDepends() );
}

@Override
public List<String> getSoftDepend()
{
return ImmutableList.copyOf( getSoftDepends() );
}
}
26 changes: 25 additions & 1 deletion api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* example event handling and plugin management.
*/
@RequiredArgsConstructor
public class PluginManager
public class PluginManager implements tc.oc.minecraft.api.plugin.PluginManager
{

private static final Pattern argsSplit = Pattern.compile( " " );
Expand Down Expand Up @@ -185,6 +185,12 @@ public Collection<Plugin> getPlugins()
return plugins.values();
}

@Override
public Collection<? extends Plugin> getAllPlugins()
{
return getPlugins();
}

/**
* Returns a loaded plugin identified by the specified name.
*
Expand Down Expand Up @@ -378,6 +384,24 @@ public <T extends Event> T callEvent(T event)
return event;
}

@Override
public void registerListener(tc.oc.minecraft.api.plugin.Plugin plugin, tc.oc.minecraft.api.event.Listener listener)
{
registerListener( (Plugin) plugin, (Listener) listener );
}

@Override
public void unregisterListener(tc.oc.minecraft.api.event.Listener listener)
{
unregisterListener( (Listener) listener );
}

@Override
public void unregisterListeners(tc.oc.minecraft.api.plugin.Plugin plugin)
{
unregisterListeners( (Plugin) plugin );
}

/**
* Register a {@link Listener} for receiving called events. Methods in this
* Object which wish to receive events must be annotated with the
Expand Down
6 changes: 6 additions & 0 deletions config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
<description>Generic java configuration API intended for use with BungeeCord</description>

<dependencies>
<dependency>
<groupId>tc.oc</groupId>
<artifactId>minecraft-api</artifactId>
<version>1.8-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
import java.util.List;
import java.util.Map;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
public final class Configuration
public final class Configuration implements tc.oc.minecraft.api.configuration.Configuration
{

private static final char SEPARATOR = '.';
final Map<String, Object> self;
@Getter
private final Configuration defaults;

public Configuration()
Expand Down
8 changes: 8 additions & 0 deletions proxy/src/main/java/net/md_5/bungee/BungeeCord.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.md_5.bungee.api.Favicon;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.Title;
import net.md_5.bungee.command.ConsoleCommandSender;
import net.md_5.bungee.module.ModuleManager;
import com.google.common.io.ByteStreams;
import net.md_5.bungee.api.chat.BaseComponent;
Expand Down Expand Up @@ -81,6 +82,7 @@
import net.md_5.bungee.query.RemoteQuery;
import net.md_5.bungee.util.CaseInsensitiveMap;
import org.fusesource.jansi.AnsiConsole;
import tc.oc.minecraft.api.command.*;

/**
* Main BungeeCord proxy class.
Expand Down Expand Up @@ -595,6 +597,12 @@ public ServerInfo constructServerInfo(String name, InetSocketAddress address, St
return new BungeeServerInfo( name, address, motd, restricted );
}

@Override
public tc.oc.minecraft.api.command.ConsoleCommandSender getConsoleSender()
{
return ConsoleCommandSender.getInstance();
}

@Override
public CommandSender getConsole()
{
Expand Down
28 changes: 28 additions & 0 deletions proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.UUID;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Synchronized;
Expand Down Expand Up @@ -69,6 +71,32 @@ public Collection<ProxiedPlayer> getPlayers()
return Collections.unmodifiableCollection( new HashSet( players ) );
}

@Override
public Collection<? extends ProxiedPlayer> getOnlinePlayers()
{
return getPlayers();
}

@Override
public ProxiedPlayer getPlayerExact(String name)
{
for(ProxiedPlayer player : getPlayers())
{
if(name.equalsIgnoreCase(player.getName())) return player;
}
return null;
}

@Override
public ProxiedPlayer getPlayer(UUID id)
{
for(ProxiedPlayer player : getPlayers())
{
if(id.equals(player.getUniqueId())) return player;
}
return null;
}

@Override
public boolean canAccess(CommandSender player)
{
Expand Down
Loading

0 comments on commit 676e5a4

Please sign in to comment.