Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Merged branch 'master' from 'https://github.com/SpigotMC/BungeeCord'
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Apr 14, 2019
1 parent 4d50148 commit 268f916
Show file tree
Hide file tree
Showing 35 changed files with 385 additions and 239 deletions.
7 changes: 6 additions & 1 deletion api/src/main/java/net/md_5/bungee/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ public static InetSocketAddress getAddr(String hostline)
uri = new URI( "tcp://" + hostline );
} catch ( URISyntaxException ex )
{
throw new IllegalArgumentException( "Bad hostline", ex );
throw new IllegalArgumentException( "Bad hostline: " + hostline, ex );
}

if ( uri.getHost() == null )
{
throw new IllegalArgumentException( "Invalid host/address: " + hostline );
}

return new InetSocketAddress( uri.getHost(), ( uri.getPort() ) == -1 ? DEFAULT_PORT : uri.getPort() );
Expand Down
16 changes: 16 additions & 0 deletions api/src/main/java/net/md_5/bungee/api/config/ServerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ public interface ServerInfo
*/
String getMotd();

/**
* Whether this server is restricted and therefore only players with the
* given permission can access it.
*
* @return if restricted
*/
boolean isRestricted();

/**
* Get the permission required to access this server. Only enforced when the
* server is restricted.
*
* @return access permission
*/
String getPermission();

/**
* Whether the player can access this server. It will only return false when
* the player has no permission and this server is restricted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public enum MainHand
* @param target the new server to connect to
* @param callback the method called when the connection is complete, or
* when an exception is encountered. The boolean parameter denotes success
* or failure.
* (true) or failure (false).
*/
void connect(ServerInfo target, Callback<Boolean> callback);

Expand All @@ -119,7 +119,7 @@ public enum MainHand
* @param target the new server to connect to
* @param callback the method called when the connection is complete, or
* when an exception is encountered. The boolean parameter denotes success
* or failure.
* (true) or failure (false).
* @param reason the reason for connecting to the new server
*/
void connect(ServerInfo target, Callback<Boolean> callback, ServerConnectEvent.Reason reason);
Expand Down
32 changes: 22 additions & 10 deletions api/src/main/java/net/md_5/bungee/api/event/AsyncEvent.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package net.md_5.bungee.api.event;

import com.google.common.base.Preconditions;
import java.util.Collections;
import java.util.Set;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.plugin.Event;
Expand All @@ -19,13 +20,14 @@
* @param <T> Type of this event
*/
@Data
@Getter(AccessLevel.NONE)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class AsyncEvent<T> extends Event
{

private final Callback<T> done;
private final Set<Plugin> intents = Collections.newSetFromMap( new ConcurrentHashMap<Plugin, Boolean>() );
private final Map<Plugin, AtomicInteger> intents = new ConcurrentHashMap<>();
private final AtomicBoolean fired = new AtomicBoolean();
private final AtomicInteger latch = new AtomicInteger();

Expand All @@ -43,30 +45,40 @@ public void postCall()
/**
* Register an intent that this plugin will continue to perform work on a
* background task, and wishes to let the event proceed once the registered
* background task has completed.
* background task has completed. Multiple intents can be registered by a
* plugin, but the plugin must complete the same amount of intents for the
* event to proceed.
*
* @param plugin the plugin registering this intent
*/
public void registerIntent(Plugin plugin)
{
Preconditions.checkState( !fired.get(), "Event %s has already been fired", this );
Preconditions.checkState( !intents.contains( plugin ), "Plugin %s already registered intent for event %s", plugin, this );

intents.add( plugin );
AtomicInteger intentCount = intents.get( plugin );
if ( intentCount == null )
{
intents.put( plugin, new AtomicInteger( 1 ) );
} else
{
intentCount.incrementAndGet();
}
latch.incrementAndGet();
}

/**
* Notifies this event that this plugin has done all its required processing
* and wishes to let the event proceed.
* Notifies this event that this plugin has completed an intent and wishes
* to let the event proceed once all intents have been completed.
*
* @param plugin a plugin which has an intent registered for this event
*/
@SuppressWarnings("unchecked")
public void completeIntent(Plugin plugin)
{
Preconditions.checkState( intents.contains( plugin ), "Plugin %s has not registered intent for event %s", plugin, this );
intents.remove( plugin );
AtomicInteger intentCount = intents.get( plugin );
Preconditions.checkState( intentCount != null && intentCount.get() > 0, "Plugin %s has not registered intents for event %s", plugin, this );

intentCount.decrementAndGet();
if ( fired.get() )
{
if ( latch.decrementAndGet() == 0 )
Expand Down
24 changes: 24 additions & 0 deletions api/src/main/java/net/md_5/bungee/api/event/ChatEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.Connection;
import net.md_5.bungee.api.plugin.Cancellable;
import net.md_5.bungee.api.plugin.PluginManager;

/**
* Event called when a player sends a message to a server.
Expand Down Expand Up @@ -39,4 +42,25 @@ public boolean isCommand()
{
return message.length() > 0 && message.charAt( 0 ) == '/';
}

/**
* Checks whether this message is run on this proxy server.
*
* @return if this command runs on the proxy
* @see PluginManager#isExecutableCommand(java.lang.String,
* net.md_5.bungee.api.CommandSender)
*/
public boolean isProxyCommand()
{
if ( !isCommand() )
{
return false;
}

int index = message.indexOf( " " );
String commandName = ( index == -1 ) ? message.substring( 1 ) : message.substring( 1, index );
CommandSender sender = ( getSender() instanceof CommandSender ) ? (CommandSender) getSender() : null;

return ProxyServer.getInstance().getPluginManager().isExecutableCommand( commandName, sender );
}
}
33 changes: 27 additions & 6 deletions api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,32 @@ public void unregisterCommands(Plugin plugin)
}
}

private Command getCommandIfEnabled(String commandName, CommandSender sender)
{
String commandLower = commandName.toLowerCase( Locale.ROOT );

// Check if command is disabled when a player sent the command
if ( ( sender instanceof ProxiedPlayer ) && proxy.getDisabledCommands().contains( commandLower ) )
{
return null;
}

return commandMap.get( commandLower );
}

/**
* Checks if the command is registered and can possibly be executed by the
* sender (without taking permissions into account).
*
* @param commandName the name of the command
* @param sender the sender executing the command
* @return whether the command will be handled
*/
public boolean isExecutableCommand(String commandName, CommandSender sender)
{
return getCommandIfEnabled( commandName, sender ) != null;
}

public boolean dispatchCommand(CommandSender sender, String commandLine)
{
return dispatchCommand( sender, commandLine, null );
Expand All @@ -133,12 +159,7 @@ public boolean dispatchCommand(CommandSender sender, String commandLine, List<St
return false;
}

String commandName = split[0].toLowerCase( Locale.ROOT );
if ( sender instanceof ProxiedPlayer && proxy.getDisabledCommands().contains( commandName ) )
{
return false;
}
Command command = commandMap.get( commandName );
Command command = getCommandIfEnabled( split[0], sender );
if ( command == null )
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,23 @@ public String getMotd()
}

@Override
public boolean canAccess(CommandSender sender)
public boolean isRestricted()
{
return false;
}

@Override
public String getPermission()
{
return null;
}

@Override
public boolean canAccess(CommandSender sender)
{
return true;
}

@Override
public void sendData(String channel, byte[] data)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

import java.util.ArrayList;
import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import net.md_5.bungee.api.chat.ComponentBuilder.FormatRetention;

@Setter
@ToString(exclude = "parent")
@EqualsAndHashCode
@NoArgsConstructor
public abstract class BaseComponent
{
Expand Down
2 changes: 2 additions & 0 deletions chat/src/main/java/net/md_5/bungee/api/chat/ClickEvent.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package net.md_5.bungee.api.chat;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@Getter
@ToString
@EqualsAndHashCode
@RequiredArgsConstructor
public final class ClickEvent
{
Expand Down
13 changes: 13 additions & 0 deletions chat/src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ public ComponentBuilder append(String text)
return append( text, FormatRetention.ALL );
}

/**
* Parse text to BaseComponent[] with colors and format, appends the text to
* the builder and makes it the current target for formatting. The component
* will have all the formatting from previous part.
*
* @param text the text to append
* @return this ComponentBuilder for chaining
*/
public ComponentBuilder appendLegacy(String text)
{
return append( TextComponent.fromLegacyText( text ) );
}

/**
* Appends the text to the builder and makes it the current target for
* formatting. You can specify the amount of formatting retained from
Expand Down
2 changes: 2 additions & 0 deletions chat/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package net.md_5.bungee.api.chat;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@Getter
@ToString
@EqualsAndHashCode
@RequiredArgsConstructor
public final class HoverEvent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.md_5.bungee.api.chat;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -10,6 +11,7 @@
@Setter
@ToString
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public final class KeybindComponent extends BaseComponent
{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.md_5.bungee.api.chat;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
Expand All @@ -26,6 +27,7 @@
@Setter
@ToString
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public final class ScoreComponent extends BaseComponent
{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.md_5.bungee.api.chat;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
Expand All @@ -22,6 +23,7 @@
@Setter
@ToString
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public final class SelectorComponent extends BaseComponent
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.EqualsAndHashCode;

@Getter
@Setter
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public final class TextComponent extends BaseComponent
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import net.md_5.bungee.chat.TranslationRegistry;

@Getter
@Setter
@ToString
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public final class TranslatableComponent extends BaseComponent
{

Expand Down
Loading

0 comments on commit 268f916

Please sign in to comment.