Compare commits
6 Commits
for-pandac
...
2a19bfb6d3
Author | SHA1 | Date | |
---|---|---|---|
2a19bfb6d3 | |||
451068694a | |||
e7e77e2731 | |||
d6bf6a13f4 | |||
8dd77af343 | |||
fb9e1b0499 |
4
.github/workflows/maven.yml
vendored
4
.github/workflows/maven.yml
vendored
@@ -4,12 +4,12 @@ on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-24.04
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
java: [8, 11, 17, 21, 25]
|
||||
java: [8, 11, 17, 21]
|
||||
|
||||
name: Java ${{ matrix.java }}
|
||||
|
||||
|
16
api/pom.xml
16
api/pom.xml
@@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-API</name>
|
||||
@@ -30,12 +30,6 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-dialog</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-event</artifactId>
|
||||
@@ -74,12 +68,6 @@
|
||||
<!-- not part of the API proper -->
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-commons</artifactId>
|
||||
<version>9.8</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
|
@@ -1,77 +0,0 @@
|
||||
package net.md_5.bungee.api;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* Represents a server link which may be sent to the client.
|
||||
*/
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class ServerLink
|
||||
{
|
||||
|
||||
/**
|
||||
* The links type.
|
||||
*
|
||||
* Note: This value is nullable, if null, label is non-null.
|
||||
*/
|
||||
private final LinkType type;
|
||||
|
||||
/**
|
||||
* The label for the link.
|
||||
*
|
||||
* Note: This value is nullable, if null, type is non-null.
|
||||
*/
|
||||
private final BaseComponent label;
|
||||
|
||||
/**
|
||||
* The URL that is displayed.
|
||||
*/
|
||||
@NonNull
|
||||
private final String url;
|
||||
|
||||
/**
|
||||
* Creates a link with a specified type and URL.
|
||||
*
|
||||
* @param type the type of the link
|
||||
* @param url the URL to be displayed
|
||||
*/
|
||||
public ServerLink(@NonNull LinkType type, @NonNull String url)
|
||||
{
|
||||
this.type = type;
|
||||
this.label = null;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a link with a label and URL.
|
||||
*
|
||||
* @param label the label to be displayed
|
||||
* @param url the URL to be displayed
|
||||
*/
|
||||
public ServerLink(@NonNull BaseComponent label, @NonNull String url)
|
||||
{
|
||||
this.type = null;
|
||||
this.label = label;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public enum LinkType
|
||||
{
|
||||
|
||||
REPORT_BUG,
|
||||
COMMUNITY_GUIDELINES,
|
||||
SUPPORT,
|
||||
STATUS,
|
||||
FEEDBACK,
|
||||
COMMUNITY,
|
||||
WEBSITE,
|
||||
FORUMS,
|
||||
NEWS,
|
||||
ANNOUNCEMENTS;
|
||||
}
|
||||
}
|
@@ -87,10 +87,8 @@ public interface Connection
|
||||
|
||||
/**
|
||||
* Queue a packet to this connection.
|
||||
*
|
||||
* If the packet is not registered for the connections current encoder
|
||||
* protocol, it will be queued until it is, otherwise it will be sent
|
||||
* immediately.
|
||||
* If the packet is not registered for the connections current encoder protocol, it will be queued until it is,
|
||||
* otherwise it will be sent immediately.
|
||||
*
|
||||
* @param packet the packet to be queued
|
||||
* @throws UnsupportedOperationException if used for a PendingConnection
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package net.md_5.bungee.api.connection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -9,12 +8,10 @@ import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ServerConnectRequest;
|
||||
import net.md_5.bungee.api.ServerLink;
|
||||
import net.md_5.bungee.api.SkinConfiguration;
|
||||
import net.md_5.bungee.api.Title;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.dialog.Dialog;
|
||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||
import net.md_5.bungee.api.score.Scoreboard;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -385,44 +382,4 @@ public interface ProxiedPlayer extends Connection, CommandSender
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
void transfer(String host, int port);
|
||||
|
||||
/**
|
||||
* Gets the client brand of this player.
|
||||
*
|
||||
* If the player has not sent a brand packet yet, it will return null.
|
||||
*
|
||||
* @return the brand of the client, or null if not received yet
|
||||
*/
|
||||
String getClientBrand();
|
||||
|
||||
/**
|
||||
* Clear the player's open dialog.
|
||||
*
|
||||
* @throws IllegalStateException if the players version is not at least
|
||||
* 1.21.6
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
void clearDialog();
|
||||
|
||||
/**
|
||||
* Show a dialog to the player.
|
||||
*
|
||||
* @param dialog the dialog to show
|
||||
* @throws IllegalStateException if the players version is not at least
|
||||
* 1.21.6
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
void showDialog(Dialog dialog);
|
||||
|
||||
/**
|
||||
* Sends server links to the player.
|
||||
*
|
||||
* Note: The links already sent to the player will be overwritten. Also, the
|
||||
* backend server is able to override links sent by the proxy.
|
||||
*
|
||||
* @param serverLinks the server links to send
|
||||
* @throws IllegalStateException if the player's version is not at least
|
||||
* 1.21
|
||||
*/
|
||||
void sendServerLinks(List<ServerLink> serverLinks);
|
||||
}
|
||||
|
@@ -1,39 +0,0 @@
|
||||
package net.md_5.bungee.api.event;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Called after a {@link ProxiedPlayer} runs a custom action from a chat event
|
||||
* or form submission.
|
||||
*/
|
||||
@Data
|
||||
@ToString(callSuper = false)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiStatus.Experimental
|
||||
public class CustomClickEvent extends Event implements Cancellable
|
||||
{
|
||||
|
||||
/**
|
||||
* Player who clicked.
|
||||
*/
|
||||
private final ProxiedPlayer player;
|
||||
/**
|
||||
* Custom action ID.
|
||||
*/
|
||||
private final String id;
|
||||
/**
|
||||
* The data as submitted.
|
||||
*/
|
||||
private final JsonElement data;
|
||||
/**
|
||||
* Cancelled state.
|
||||
*/
|
||||
private boolean cancelled;
|
||||
}
|
@@ -35,7 +35,6 @@ import org.eclipse.aether.transport.http.HttpTransporterFactory;
|
||||
class LibraryLoader
|
||||
{
|
||||
|
||||
private static final String REPOSITORY_PROPERTY = "net.md_5.bungee.api.plugin.centralURL";
|
||||
private final Logger logger;
|
||||
private final RepositorySystem repository;
|
||||
private final DefaultRepositorySystemSession session;
|
||||
@@ -69,7 +68,7 @@ class LibraryLoader
|
||||
session.setSystemProperties( System.getProperties() );
|
||||
session.setReadOnly();
|
||||
|
||||
this.repositories = repository.newResolutionRepositories( session, Arrays.asList( new RemoteRepository.Builder( "central", "default", System.getProperty( REPOSITORY_PROPERTY, "https://repo.maven.apache.org/maven2" ) ).build() ) );
|
||||
this.repositories = repository.newResolutionRepositories( session, Arrays.asList( new RemoteRepository.Builder( "central", "default", "https://repo.maven.apache.org/maven2" ).build() ) );
|
||||
}
|
||||
|
||||
public ClassLoader createLoader(PluginDescription desc)
|
||||
|
@@ -11,7 +11,6 @@ import lombok.Getter;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ConfigurationAdapter;
|
||||
import net.md_5.bungee.api.scheduler.GroupedThreadFactory;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Represents any Plugin that may be loaded at runtime to enhance existing
|
||||
@@ -109,14 +108,7 @@ public class Plugin
|
||||
//
|
||||
private ExecutorService service;
|
||||
|
||||
/**
|
||||
* Returns the executor service associated with this plugin.
|
||||
*
|
||||
* @return the executor service for this plugin
|
||||
* @deprecated internal API. Use {@link ProxyServer#getScheduler()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
@ApiStatus.Internal
|
||||
public ExecutorService getExecutorService()
|
||||
{
|
||||
if ( service == null )
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package net.md_5.bungee.api.plugin;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -10,20 +9,13 @@ import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.security.CodeSigner;
|
||||
import java.security.CodeSource;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.commons.ClassRemapper;
|
||||
import org.objectweb.asm.commons.SimpleRemapper;
|
||||
|
||||
@ToString(of = "desc")
|
||||
final class PluginClassloader extends URLClassLoader
|
||||
@@ -129,15 +121,6 @@ final class PluginClassloader extends URLClassLoader
|
||||
throw new ClassNotFoundException( name, ex );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
classBytes = remap( classBytes );
|
||||
} catch ( Exception ex )
|
||||
{
|
||||
Logger logger = ( plugin != null ) ? plugin.getLogger() : proxy.getLogger();
|
||||
logger.log( Level.SEVERE, "Error trying to remap class " + path, ex );
|
||||
}
|
||||
|
||||
int dot = name.lastIndexOf( '.' );
|
||||
if ( dot != -1 )
|
||||
{
|
||||
@@ -172,27 +155,6 @@ final class PluginClassloader extends URLClassLoader
|
||||
return super.findClass( name );
|
||||
}
|
||||
|
||||
private static final Map<String, String> MAPPINGS = ImmutableMap.of(
|
||||
"net/md_5/bungee/protocol/ChatChain", "net/md_5/bungee/protocol/data/ChatChain",
|
||||
"net/md_5/bungee/protocol/Location", "net/md_5/bungee/protocol/data/Location",
|
||||
"net/md_5/bungee/protocol/NumberFormat", "net/md_5/bungee/protocol/data/NumberFormat",
|
||||
"net/md_5/bungee/protocol/PlayerPublicKey", "net/md_5/bungee/protocol/data/PlayerPublicKey",
|
||||
"net/md_5/bungee/protocol/Property", "net/md_5/bungee/protocol/data/Property",
|
||||
"net/md_5/bungee/protocol/SeenMessages", "net/md_5/bungee/protocol/data/SeenMessages",
|
||||
"net/md_5/bungee/protocol/Either", "net/md_5/bungee/protocol/util/Either",
|
||||
"net/md_5/bungee/protocol/TagUtil", "net/md_5/bungee/protocol/util/TagUtil"
|
||||
);
|
||||
|
||||
private static byte[] remap(byte[] b)
|
||||
{
|
||||
ClassReader cr = new ClassReader( b );
|
||||
ClassWriter cw = new ClassWriter( cr, 0 );
|
||||
|
||||
cr.accept( new ClassRemapper( cw, new SimpleRemapper( MAPPINGS ) ), 0 );
|
||||
|
||||
return cw.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
|
@@ -30,7 +30,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Level;
|
||||
import lombok.Locked;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
@@ -99,15 +98,21 @@ public final class PluginManager
|
||||
* @param plugin the plugin owning this command
|
||||
* @param command the command to register
|
||||
*/
|
||||
@Locked.Write("commandsLock")
|
||||
public void registerCommand(Plugin plugin, Command command)
|
||||
{
|
||||
commandMap.put( command.getName().toLowerCase( Locale.ROOT ), command );
|
||||
for ( String alias : command.getAliases() )
|
||||
commandsLock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
commandMap.put( alias.toLowerCase( Locale.ROOT ), command );
|
||||
commandMap.put( command.getName().toLowerCase( Locale.ROOT ), command );
|
||||
for ( String alias : command.getAliases() )
|
||||
{
|
||||
commandMap.put( alias.toLowerCase( Locale.ROOT ), command );
|
||||
}
|
||||
commandsByPlugin.put( plugin, command );
|
||||
} finally
|
||||
{
|
||||
commandsLock.writeLock().unlock();
|
||||
}
|
||||
commandsByPlugin.put( plugin, command );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,11 +120,17 @@ public final class PluginManager
|
||||
*
|
||||
* @param command the command to unregister
|
||||
*/
|
||||
@Locked.Write("commandsLock")
|
||||
public void unregisterCommand(Command command)
|
||||
{
|
||||
while ( commandMap.values().remove( command ) );
|
||||
commandsByPlugin.values().remove( command );
|
||||
commandsLock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
while ( commandMap.values().remove( command ) );
|
||||
commandsByPlugin.values().remove( command );
|
||||
} finally
|
||||
{
|
||||
commandsLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,14 +138,20 @@ public final class PluginManager
|
||||
*
|
||||
* @param plugin the plugin to register the commands of
|
||||
*/
|
||||
@Locked.Write("commandsLock")
|
||||
public void unregisterCommands(Plugin plugin)
|
||||
{
|
||||
for ( Iterator<Command> it = commandsByPlugin.get( plugin ).iterator(); it.hasNext(); )
|
||||
commandsLock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
Command command = it.next();
|
||||
while ( commandMap.values().remove( command ) );
|
||||
it.remove();
|
||||
for ( Iterator<Command> it = commandsByPlugin.get( plugin ).iterator(); it.hasNext(); )
|
||||
{
|
||||
Command command = it.next();
|
||||
while ( commandMap.values().remove( command ) );
|
||||
it.remove();
|
||||
}
|
||||
} finally
|
||||
{
|
||||
commandsLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,15 +467,22 @@ public final class PluginManager
|
||||
* @param plugin the owning plugin
|
||||
* @param listener the listener to register events for
|
||||
*/
|
||||
@Locked("listenersLock")
|
||||
public void registerListener(Plugin plugin, Listener listener)
|
||||
{
|
||||
for ( Method method : listener.getClass().getDeclaredMethods() )
|
||||
listenersLock.lock();
|
||||
try
|
||||
{
|
||||
Preconditions.checkArgument( !method.isAnnotationPresent( Subscribe.class ), "Listener %s has registered using deprecated subscribe annotation! Please update to @EventHandler.", listener );
|
||||
for ( Method method : listener.getClass().getDeclaredMethods() )
|
||||
{
|
||||
Preconditions.checkArgument( !method.isAnnotationPresent( Subscribe.class ),
|
||||
"Listener %s has registered using deprecated subscribe annotation! Please update to @EventHandler.", listener );
|
||||
}
|
||||
eventBus.register( listener );
|
||||
listenersByPlugin.put( plugin, listener );
|
||||
} finally
|
||||
{
|
||||
listenersLock.unlock();
|
||||
}
|
||||
eventBus.register( listener );
|
||||
listenersByPlugin.put( plugin, listener );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -466,11 +490,17 @@ public final class PluginManager
|
||||
*
|
||||
* @param listener the listener to unregister
|
||||
*/
|
||||
@Locked("listenersLock")
|
||||
public void unregisterListener(Listener listener)
|
||||
{
|
||||
eventBus.unregister( listener );
|
||||
listenersByPlugin.values().remove( listener );
|
||||
listenersLock.lock();
|
||||
try
|
||||
{
|
||||
eventBus.unregister( listener );
|
||||
listenersByPlugin.values().remove( listener );
|
||||
} finally
|
||||
{
|
||||
listenersLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -478,13 +508,19 @@ public final class PluginManager
|
||||
*
|
||||
* @param plugin target plugin
|
||||
*/
|
||||
@Locked("listenersLock")
|
||||
public void unregisterListeners(Plugin plugin)
|
||||
{
|
||||
for ( Iterator<Listener> it = listenersByPlugin.get( plugin ).iterator(); it.hasNext(); )
|
||||
listenersLock.lock();
|
||||
try
|
||||
{
|
||||
eventBus.unregister( it.next() );
|
||||
it.remove();
|
||||
for ( Iterator<Listener> it = listenersByPlugin.get( plugin ).iterator(); it.hasNext(); )
|
||||
{
|
||||
eventBus.unregister( it.next() );
|
||||
it.remove();
|
||||
}
|
||||
} finally
|
||||
{
|
||||
listenersLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -493,10 +529,16 @@ public final class PluginManager
|
||||
*
|
||||
* @return commands
|
||||
*/
|
||||
@Locked.Read("commandsLock")
|
||||
public Collection<Map.Entry<String, Command>> getCommands()
|
||||
{
|
||||
return Collections.unmodifiableCollection( commandMap.entrySet() );
|
||||
commandsLock.readLock().lock();
|
||||
try
|
||||
{
|
||||
return Collections.unmodifiableCollection( commandMap.entrySet() );
|
||||
} finally
|
||||
{
|
||||
commandsLock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
boolean isTransitiveDepend(PluginDescription plugin, PluginDescription depend)
|
||||
|
@@ -1,37 +1,22 @@
|
||||
package net.md_5.bungee.util;
|
||||
|
||||
import it.unimi.dsi.fastutil.Hash;
|
||||
import gnu.trove.strategy.HashingStrategy;
|
||||
import java.util.Locale;
|
||||
|
||||
class CaseInsensitiveHashingStrategy implements Hash.Strategy<String>
|
||||
class CaseInsensitiveHashingStrategy implements HashingStrategy
|
||||
{
|
||||
|
||||
static final CaseInsensitiveHashingStrategy INSTANCE = new CaseInsensitiveHashingStrategy();
|
||||
|
||||
@Override
|
||||
public int hashCode(String object)
|
||||
public int computeHashCode(Object object)
|
||||
{
|
||||
if ( object == null )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return object.toLowerCase( Locale.ROOT ).hashCode();
|
||||
return ( (String) object ).toLowerCase( Locale.ROOT ).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(String o1, String o2)
|
||||
public boolean equals(Object o1, Object o2)
|
||||
{
|
||||
if ( o1 == o2 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( o1 == null || o2 == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return o1.equals( o2 ) || o1.toLowerCase( Locale.ROOT ).equals( o2.toLowerCase( Locale.ROOT ) );
|
||||
return o1.equals( o2 ) || ( o1 instanceof String && o2 instanceof String && ( (String) o1 ).toLowerCase( Locale.ROOT ).equals( ( (String) o2 ).toLowerCase( Locale.ROOT ) ) );
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package net.md_5.bungee.util;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
|
||||
import gnu.trove.map.hash.TCustomHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CaseInsensitiveMap<V> extends Object2ObjectOpenCustomHashMap<String, V>
|
||||
public class CaseInsensitiveMap<V> extends TCustomHashMap<String, V>
|
||||
{
|
||||
|
||||
public CaseInsensitiveMap()
|
||||
@@ -13,6 +13,6 @@ public class CaseInsensitiveMap<V> extends Object2ObjectOpenCustomHashMap<String
|
||||
|
||||
public CaseInsensitiveMap(Map<? extends String, ? extends V> map)
|
||||
{
|
||||
super( map, CaseInsensitiveHashingStrategy.INSTANCE );
|
||||
super( CaseInsensitiveHashingStrategy.INSTANCE, map );
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package net.md_5.bungee.util;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;
|
||||
import gnu.trove.set.hash.TCustomHashSet;
|
||||
import java.util.Collection;
|
||||
|
||||
public class CaseInsensitiveSet extends ObjectOpenCustomHashSet<String>
|
||||
public class CaseInsensitiveSet extends TCustomHashSet<String>
|
||||
{
|
||||
|
||||
public CaseInsensitiveSet()
|
||||
@@ -13,6 +13,6 @@ public class CaseInsensitiveSet extends ObjectOpenCustomHashSet<String>
|
||||
|
||||
public CaseInsensitiveSet(Collection<? extends String> collection)
|
||||
{
|
||||
super( collection, CaseInsensitiveHashingStrategy.INSTANCE );
|
||||
super( CaseInsensitiveHashingStrategy.INSTANCE, collection );
|
||||
}
|
||||
}
|
||||
|
@@ -13,12 +13,12 @@ public class CaseInsensitiveTest
|
||||
CaseInsensitiveMap<Object> map = new CaseInsensitiveMap<>();
|
||||
|
||||
map.put( "FOO", obj );
|
||||
assertTrue( map.containsKey( "foo" ) ); // Assert that contains is case insensitive
|
||||
assertTrue( map.contains( "foo" ) ); // Assert that contains is case insensitive
|
||||
assertTrue( map.entrySet().iterator().next().getKey().equals( "FOO" ) ); // Assert that case is preserved
|
||||
|
||||
// Assert that remove is case insensitive
|
||||
map.remove( "FoO" );
|
||||
assertFalse( map.containsKey( "foo" ) );
|
||||
assertFalse( map.contains( "foo" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -6,19 +6,18 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-bootstrap</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Bootstrap</name>
|
||||
<description>Java 1.6 loader for BungeeCord</description>
|
||||
|
||||
<properties>
|
||||
<skipPublishing>true</skipPublishing>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||
<maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format>
|
||||
@@ -46,7 +45,6 @@
|
||||
<Main-Class>net.md_5.bungee.Bootstrap</Main-Class>
|
||||
<Implementation-Version>${describe}</Implementation-Version>
|
||||
<Specification-Version>${maven.build.timestamp}</Specification-Version>
|
||||
<Enable-Native-Access>ALL-UNNAMED</Enable-Native-Access>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
|
@@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Chat</name>
|
||||
|
@@ -4,7 +4,6 @@ import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -313,9 +312,8 @@ public abstract class BaseComponent
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shadow color of this component. This uses the parent's shadow
|
||||
* color if this component doesn't have one. null is returned if no shadow
|
||||
* color is found.
|
||||
* Returns the shadow color of this component. This uses the parent's shadow color if this
|
||||
* component doesn't have one. null is returned if no shadow color is found.
|
||||
*
|
||||
* @return the shadow color of this component
|
||||
*/
|
||||
@@ -679,11 +677,11 @@ public abstract class BaseComponent
|
||||
public String toPlainText()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
toPlainText( new LimitedStringVisitor( builder, Short.MAX_VALUE ) );
|
||||
toPlainText( builder );
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
void toPlainText(StringVisitor builder)
|
||||
void toPlainText(StringBuilder builder)
|
||||
{
|
||||
if ( extra != null )
|
||||
{
|
||||
@@ -703,11 +701,11 @@ public abstract class BaseComponent
|
||||
public String toLegacyText()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
toLegacyText( new LimitedStringVisitor( builder, Short.MAX_VALUE ) );
|
||||
toLegacyText( builder );
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
void toLegacyText(StringVisitor builder)
|
||||
void toLegacyText(StringBuilder builder)
|
||||
{
|
||||
if ( extra != null )
|
||||
{
|
||||
@@ -718,7 +716,7 @@ public abstract class BaseComponent
|
||||
}
|
||||
}
|
||||
|
||||
void addFormat(StringVisitor builder)
|
||||
void addFormat(StringBuilder builder)
|
||||
{
|
||||
builder.append( getColor() );
|
||||
if ( isBold() )
|
||||
@@ -742,35 +740,4 @@ public abstract class BaseComponent
|
||||
builder.append( ChatColor.MAGIC );
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
protected static interface StringVisitor
|
||||
{
|
||||
|
||||
void append(String s);
|
||||
|
||||
default void append(Object obj)
|
||||
{
|
||||
append( String.valueOf( obj ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
protected static class LimitedStringVisitor implements StringVisitor
|
||||
{
|
||||
|
||||
private final StringBuilder builder;
|
||||
private final int maxLength;
|
||||
|
||||
@Override
|
||||
public void append(String s)
|
||||
{
|
||||
if ( builder.length() >= maxLength )
|
||||
{
|
||||
throw new IllegalArgumentException( "String exceeded maximum length " + maxLength );
|
||||
}
|
||||
|
||||
builder.append( s );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,14 +4,12 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@RequiredArgsConstructor
|
||||
@ApiStatus.NonExtendable
|
||||
public class ClickEvent
|
||||
public final class ClickEvent
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -54,19 +52,11 @@ public class ClickEvent
|
||||
* {@link net.md_5.bungee.api.chat.ClickEvent#value} in a book.
|
||||
*/
|
||||
CHANGE_PAGE,
|
||||
/**
|
||||
* Must use subclass ShowDialogClickEvent.
|
||||
*/
|
||||
SHOW_DIALOG,
|
||||
/**
|
||||
* Copy the string given by
|
||||
* {@link net.md_5.bungee.api.chat.ClickEvent#value} into the player's
|
||||
* clipboard.
|
||||
*/
|
||||
COPY_TO_CLIPBOARD,
|
||||
/**
|
||||
* Must use subclass {@link ClickEventCustom}.
|
||||
*/
|
||||
CUSTOM,
|
||||
COPY_TO_CLIPBOARD
|
||||
}
|
||||
}
|
||||
|
@@ -1,30 +0,0 @@
|
||||
package net.md_5.bungee.api.chat;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Click event which sends a custom payload to the server.
|
||||
*/
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ClickEventCustom extends ClickEvent
|
||||
{
|
||||
|
||||
/**
|
||||
* The custom payload.
|
||||
*/
|
||||
private final String payload;
|
||||
|
||||
/**
|
||||
* @param id identifier for the event (lower case, no special characters)
|
||||
* @param payload custom payload
|
||||
*/
|
||||
public ClickEventCustom(String id, String payload)
|
||||
{
|
||||
super( ClickEvent.Action.CUSTOM, id );
|
||||
this.payload = payload;
|
||||
}
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
package net.md_5.bungee.api.chat;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
@@ -352,19 +351,6 @@ public final class ComponentBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the shadow color of the current part.
|
||||
*
|
||||
* @param color the new shadow color
|
||||
* @return this ComponentBuilder for chaining
|
||||
* @since Minecraft 1.21.4-pre1
|
||||
*/
|
||||
public ComponentBuilder shadowColor(Color color)
|
||||
{
|
||||
getCurrentComponent().setShadowColor( color );
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the font of the current part.
|
||||
*
|
||||
|
@@ -13,6 +13,7 @@ import net.md_5.bungee.api.chat.hover.content.Content;
|
||||
import net.md_5.bungee.api.chat.hover.content.Entity;
|
||||
import net.md_5.bungee.api.chat.hover.content.Item;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import net.md_5.bungee.chat.VersionedComponentSerializer;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@Getter
|
||||
@@ -72,6 +73,22 @@ public final class HoverEvent
|
||||
this.legacy = true;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BaseComponent[] getValue()
|
||||
{
|
||||
Content content = contents.get( 0 );
|
||||
if ( content instanceof Text && ( (Text) content ).getValue() instanceof BaseComponent[] )
|
||||
{
|
||||
return (BaseComponent[]) ( (Text) content ).getValue();
|
||||
}
|
||||
|
||||
TextComponent component = new TextComponent( VersionedComponentSerializer.getDefault().toString( content ) );
|
||||
return new BaseComponent[]
|
||||
{
|
||||
component
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a content to this hover event.
|
||||
*
|
||||
|
@@ -50,14 +50,14 @@ public final class KeybindComponent extends BaseComponent
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toPlainText(StringVisitor builder)
|
||||
protected void toPlainText(StringBuilder builder)
|
||||
{
|
||||
builder.append( getKeybind() );
|
||||
super.toPlainText( builder );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toLegacyText(StringVisitor builder)
|
||||
protected void toLegacyText(StringBuilder builder)
|
||||
{
|
||||
addFormat( builder );
|
||||
builder.append( getKeybind() );
|
||||
|
@@ -1,73 +0,0 @@
|
||||
package net.md_5.bungee.api.chat;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import net.md_5.bungee.api.chat.objects.ChatObject;
|
||||
|
||||
/**
|
||||
* An object component that can be used to display objects.
|
||||
* <p>
|
||||
* It can either display a player's head or an object by a specific sprite and
|
||||
* an atlas.
|
||||
* <p>
|
||||
* Note: this was added in Minecraft 1.21.9.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public final class ObjectComponent extends BaseComponent
|
||||
{
|
||||
|
||||
private ChatObject object;
|
||||
|
||||
/**
|
||||
* Creates a ObjectComponent from a given ChatObject.
|
||||
*
|
||||
* See {@link net.md_5.bungee.api.chat.objects.PlayerObject} and
|
||||
* {@link net.md_5.bungee.api.chat.objects.SpriteObject}.
|
||||
*
|
||||
* @param object the ChatObject
|
||||
*/
|
||||
public ObjectComponent(@NonNull ChatObject object)
|
||||
{
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an object component from the original to clone it.
|
||||
*
|
||||
* @param original the original for the new score component
|
||||
*/
|
||||
public ObjectComponent(ObjectComponent original)
|
||||
{
|
||||
super( original );
|
||||
setObject( original.object );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectComponent duplicate()
|
||||
{
|
||||
return new ObjectComponent( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toPlainText(StringVisitor builder)
|
||||
{
|
||||
// I guess we cannot convert this to plain text
|
||||
// builder.append( this.value );
|
||||
super.toPlainText( builder );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toLegacyText(StringVisitor builder)
|
||||
{
|
||||
addFormat( builder );
|
||||
// Same here...
|
||||
// builder.append( this.value );
|
||||
super.toLegacyText( builder );
|
||||
}
|
||||
}
|
@@ -85,14 +85,14 @@ public final class ScoreComponent extends BaseComponent
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toPlainText(StringVisitor builder)
|
||||
protected void toPlainText(StringBuilder builder)
|
||||
{
|
||||
builder.append( this.value );
|
||||
super.toPlainText( builder );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toLegacyText(StringVisitor builder)
|
||||
protected void toLegacyText(StringBuilder builder)
|
||||
{
|
||||
addFormat( builder );
|
||||
builder.append( this.value );
|
||||
|
@@ -69,14 +69,14 @@ public final class SelectorComponent extends BaseComponent
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toPlainText(StringVisitor builder)
|
||||
protected void toPlainText(StringBuilder builder)
|
||||
{
|
||||
builder.append( this.selector );
|
||||
super.toPlainText( builder );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toLegacyText(StringVisitor builder)
|
||||
protected void toLegacyText(StringBuilder builder)
|
||||
{
|
||||
addFormat( builder );
|
||||
builder.append( this.selector );
|
||||
|
@@ -170,7 +170,7 @@ public final class TextComponent extends BaseComponent
|
||||
}
|
||||
continue;
|
||||
}
|
||||
int pos = indexOfSpecial( message, i );
|
||||
int pos = message.indexOf( ' ', i );
|
||||
if ( pos == -1 )
|
||||
{
|
||||
pos = message.length();
|
||||
@@ -205,20 +205,6 @@ public final class TextComponent extends BaseComponent
|
||||
appender.accept( component );
|
||||
}
|
||||
|
||||
private static int indexOfSpecial(String message, int pos)
|
||||
{
|
||||
for ( int i = pos; i < message.length(); i++ )
|
||||
{
|
||||
char c = message.charAt( i );
|
||||
|
||||
if ( c == ' ' || Character.isISOControl( c ) )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal compatibility method to transform an array of components to a
|
||||
* single component.
|
||||
@@ -294,14 +280,14 @@ public final class TextComponent extends BaseComponent
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toPlainText(StringVisitor builder)
|
||||
protected void toPlainText(StringBuilder builder)
|
||||
{
|
||||
builder.append( text );
|
||||
super.toPlainText( builder );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toLegacyText(StringVisitor builder)
|
||||
protected void toLegacyText(StringBuilder builder)
|
||||
{
|
||||
addFormat( builder );
|
||||
builder.append( text );
|
||||
|
@@ -156,20 +156,20 @@ public final class TranslatableComponent extends BaseComponent
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toPlainText(StringVisitor builder)
|
||||
protected void toPlainText(StringBuilder builder)
|
||||
{
|
||||
convert( builder, false );
|
||||
super.toPlainText( builder );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toLegacyText(StringVisitor builder)
|
||||
protected void toLegacyText(StringBuilder builder)
|
||||
{
|
||||
convert( builder, true );
|
||||
super.toLegacyText( builder );
|
||||
}
|
||||
|
||||
private void convert(StringVisitor builder, boolean applyFormat)
|
||||
private void convert(StringBuilder builder, boolean applyFormat)
|
||||
{
|
||||
String trans = TranslationRegistry.INSTANCE.translate( translate );
|
||||
|
||||
|
@@ -1,5 +0,0 @@
|
||||
package net.md_5.bungee.api.chat.objects;
|
||||
|
||||
public interface ChatObject
|
||||
{
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
package net.md_5.bungee.api.chat.objects;
|
||||
|
||||
import java.util.UUID;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import net.md_5.bungee.api.chat.player.Profile;
|
||||
import net.md_5.bungee.api.chat.player.Property;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public final class PlayerObject implements ChatObject
|
||||
{
|
||||
|
||||
/**
|
||||
* The profile of the player.
|
||||
*/
|
||||
@NonNull
|
||||
private Profile profile;
|
||||
/**
|
||||
* If true, a hat layer will be rendered on the head. (default: true)
|
||||
*/
|
||||
private Boolean hat;
|
||||
|
||||
public PlayerObject(@NonNull String name)
|
||||
{
|
||||
this.profile = new Profile( name );
|
||||
}
|
||||
|
||||
public PlayerObject(@NonNull UUID uuid)
|
||||
{
|
||||
this.profile = new Profile( uuid );
|
||||
}
|
||||
|
||||
public PlayerObject(@NonNull Property[] properties)
|
||||
{
|
||||
this.profile = new Profile( properties );
|
||||
}
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package net.md_5.bungee.api.chat.objects;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public final class SpriteObject implements ChatObject
|
||||
{
|
||||
|
||||
/**
|
||||
* The namespaced ID of a sprite atlas, default value: minecraft:blocks.
|
||||
*/
|
||||
private String atlas;
|
||||
/**
|
||||
* The namespaced ID of a sprite in atlas, for example item/porkchop.
|
||||
*/
|
||||
@NonNull
|
||||
private String sprite;
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
package net.md_5.bungee.api.chat.player;
|
||||
|
||||
import java.util.UUID;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Profile
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the profile. Can be null.
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* The UUID of the profile. Can be null.
|
||||
*/
|
||||
private UUID uuid;
|
||||
/**
|
||||
* The properties of the profile. Can be null.
|
||||
*/
|
||||
private Property[] properties;
|
||||
|
||||
public Profile(@NonNull String name)
|
||||
{
|
||||
this( name, null, null );
|
||||
}
|
||||
|
||||
public Profile(@NonNull UUID uuid)
|
||||
{
|
||||
this( null, uuid, null );
|
||||
}
|
||||
|
||||
public Profile(@NonNull Property[] properties)
|
||||
{
|
||||
this( null, null, properties );
|
||||
}
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
package net.md_5.bungee.api.chat.player;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Property
|
||||
{
|
||||
|
||||
@NonNull
|
||||
private String name;
|
||||
@NonNull
|
||||
private String value;
|
||||
private String signature;
|
||||
|
||||
public Property(@NonNull String name, @NonNull String value)
|
||||
{
|
||||
this( name, value, null );
|
||||
}
|
||||
}
|
@@ -12,6 +12,7 @@ import java.util.IdentityHashMap;
|
||||
import java.util.Locale;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentStyle;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Content;
|
||||
@@ -41,12 +42,30 @@ public class BaseComponentSerializer
|
||||
}
|
||||
if ( clickEvent != null )
|
||||
{
|
||||
ClickEvent.Action action = ClickEvent.Action.valueOf( clickEvent.get( "action" ).getAsString().toUpperCase( Locale.ROOT ) );
|
||||
if ( newClickEvent )
|
||||
{
|
||||
component.setClickEvent( ClickEventSerializer.NEW.deserialize( clickEvent, context ) );
|
||||
switch ( action )
|
||||
{
|
||||
case OPEN_URL:
|
||||
component.setClickEvent( new ClickEvent( action, clickEvent.get( "url" ).getAsString() ) );
|
||||
break;
|
||||
case RUN_COMMAND:
|
||||
case SUGGEST_COMMAND:
|
||||
component.setClickEvent( new ClickEvent( action, clickEvent.get( "command" ).getAsString() ) );
|
||||
break;
|
||||
case CHANGE_PAGE:
|
||||
int page = clickEvent.get( "page" ).getAsInt();
|
||||
Preconditions.checkArgument( page >= 0, "Page number has to be positive" );
|
||||
component.setClickEvent( new ClickEvent( action, Integer.toString( page ) ) );
|
||||
break;
|
||||
default:
|
||||
component.setClickEvent( new ClickEvent( action, ( clickEvent.has( "value" ) ) ? clickEvent.get( "value" ).getAsString() : "" ) );
|
||||
break;
|
||||
}
|
||||
} else
|
||||
{
|
||||
component.setClickEvent( ClickEventSerializer.OLD.deserialize( clickEvent, context ) );
|
||||
component.setClickEvent( new ClickEvent( action, ( clickEvent.has( "value" ) ) ? clickEvent.get( "value" ).getAsString() : "" ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,17 +163,39 @@ public class BaseComponentSerializer
|
||||
//Events
|
||||
if ( component.getClickEvent() != null )
|
||||
{
|
||||
JsonObject clickEvent = new JsonObject();
|
||||
String actionName = component.getClickEvent().getAction().toString().toLowerCase( Locale.ROOT );
|
||||
clickEvent.addProperty( "action", actionName.toLowerCase( Locale.ROOT ) );
|
||||
switch ( serializer.getVersion() )
|
||||
{
|
||||
case V1_21_5:
|
||||
object.add( "click_event", ClickEventSerializer.NEW.serialize( component.getClickEvent(), context ) );
|
||||
ClickEvent.Action action = ClickEvent.Action.valueOf( actionName.toUpperCase( Locale.ROOT ) );
|
||||
switch ( action )
|
||||
{
|
||||
case OPEN_URL:
|
||||
clickEvent.addProperty( "url", component.getClickEvent().getValue() );
|
||||
break;
|
||||
case RUN_COMMAND:
|
||||
case SUGGEST_COMMAND:
|
||||
clickEvent.addProperty( "command", component.getClickEvent().getValue() );
|
||||
break;
|
||||
case CHANGE_PAGE:
|
||||
clickEvent.addProperty( "page", Integer.parseInt( component.getClickEvent().getValue() ) );
|
||||
break;
|
||||
default:
|
||||
clickEvent.addProperty( "value", component.getClickEvent().getValue() );
|
||||
break;
|
||||
}
|
||||
object.add( "click_event", clickEvent );
|
||||
break;
|
||||
case V1_16:
|
||||
object.add( "clickEvent", ClickEventSerializer.OLD.serialize( component.getClickEvent(), context ) );
|
||||
clickEvent.addProperty( "value", component.getClickEvent().getValue() );
|
||||
object.add( "clickEvent", clickEvent );
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException( "Unknown version " + serializer.getVersion() );
|
||||
}
|
||||
|
||||
}
|
||||
if ( component.getHoverEvent() != null )
|
||||
{
|
@@ -17,7 +17,6 @@ import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentStyle;
|
||||
import net.md_5.bungee.api.chat.ItemTag;
|
||||
import net.md_5.bungee.api.chat.KeybindComponent;
|
||||
import net.md_5.bungee.api.chat.ObjectComponent;
|
||||
import net.md_5.bungee.api.chat.ScoreComponent;
|
||||
import net.md_5.bungee.api.chat.SelectorComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
@@ -29,12 +28,6 @@ import net.md_5.bungee.api.chat.hover.content.Item;
|
||||
import net.md_5.bungee.api.chat.hover.content.ItemSerializer;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import net.md_5.bungee.api.chat.hover.content.TextSerializer;
|
||||
import net.md_5.bungee.api.dialog.Dialog;
|
||||
import net.md_5.bungee.api.dialog.action.Action;
|
||||
import net.md_5.bungee.api.dialog.chat.ShowDialogClickEvent;
|
||||
import net.md_5.bungee.serializer.dialog.DialogActionSerializer;
|
||||
import net.md_5.bungee.serializer.dialog.DialogSerializer;
|
||||
import net.md_5.bungee.serializer.dialog.ShowDialogClickEventSerializer;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
@@ -47,14 +40,10 @@ public class VersionedComponentSerializer implements JsonDeserializer<BaseCompon
|
||||
@Getter
|
||||
@ApiStatus.Internal
|
||||
private final ChatVersion version;
|
||||
@Getter
|
||||
@ApiStatus.Internal
|
||||
private final DialogSerializer dialogSerializer;
|
||||
|
||||
public VersionedComponentSerializer(ChatVersion version)
|
||||
{
|
||||
this.version = version;
|
||||
this.dialogSerializer = new DialogSerializer( this );
|
||||
this.gson = new GsonBuilder().
|
||||
registerTypeAdapter( BaseComponent.class, this ).
|
||||
registerTypeAdapter( TextComponent.class, new TextComponentSerializer( this ) ).
|
||||
@@ -62,16 +51,11 @@ public class VersionedComponentSerializer implements JsonDeserializer<BaseCompon
|
||||
registerTypeAdapter( KeybindComponent.class, new KeybindComponentSerializer( this ) ).
|
||||
registerTypeAdapter( ScoreComponent.class, new ScoreComponentSerializer( this ) ).
|
||||
registerTypeAdapter( SelectorComponent.class, new SelectorComponentSerializer( this ) ).
|
||||
registerTypeAdapter( ObjectComponent.class, new ObjectComponentSerializer( this ) ).
|
||||
registerTypeAdapter( ComponentStyle.class, new ComponentStyleSerializer() ).
|
||||
registerTypeAdapter( Entity.class, new EntitySerializer( this ) ).
|
||||
registerTypeAdapter( Text.class, new TextSerializer() ).
|
||||
registerTypeAdapter( Item.class, new ItemSerializer() ).
|
||||
registerTypeAdapter( ItemTag.class, new ItemTag.Serializer() ).
|
||||
// Dialogs
|
||||
registerTypeAdapter( Dialog.class, dialogSerializer ).
|
||||
registerTypeAdapter( ShowDialogClickEvent.class, new ShowDialogClickEventSerializer() ).
|
||||
registerTypeAdapter( Action.class, new DialogActionSerializer() ).
|
||||
create();
|
||||
}
|
||||
|
||||
@@ -263,18 +247,6 @@ public class VersionedComponentSerializer implements JsonDeserializer<BaseCompon
|
||||
{
|
||||
return new TextComponent( json.getAsString() );
|
||||
}
|
||||
|
||||
if ( json.isJsonArray() )
|
||||
{
|
||||
JsonArray arr = json.getAsJsonArray();
|
||||
BaseComponent[] components = new BaseComponent[ arr.size() ];
|
||||
for ( int i = 0; i < arr.size(); i++ )
|
||||
{
|
||||
components[i] = deserialize( arr.get( i ), BaseComponent.class, context );
|
||||
}
|
||||
return TextComponent.fromArray( components );
|
||||
}
|
||||
|
||||
JsonObject object = json.getAsJsonObject();
|
||||
if ( object.has( "translate" ) )
|
||||
{
|
||||
@@ -292,10 +264,6 @@ public class VersionedComponentSerializer implements JsonDeserializer<BaseCompon
|
||||
{
|
||||
return context.deserialize( json, SelectorComponent.class );
|
||||
}
|
||||
if ( object.has( "player" ) || object.has( "sprite" ) )
|
||||
{
|
||||
return context.deserialize( json, ObjectComponent.class );
|
||||
}
|
||||
return context.deserialize( json, TextComponent.class );
|
||||
}
|
||||
}
|
@@ -562,22 +562,6 @@ public class ComponentsTest
|
||||
assertNotNull( url2 );
|
||||
assertTrue( url2.getAction() == ClickEvent.Action.OPEN_URL );
|
||||
assertEquals( "http://google.com/test", url2.getValue() );
|
||||
|
||||
BaseComponent[] test3 = TextComponent.fromLegacyText( "Text\nhttp://google.com\n newline3" );
|
||||
ClickEvent url3 = test3[1].getClickEvent();
|
||||
assertNotNull( url3 );
|
||||
assertTrue( url3.getAction() == ClickEvent.Action.OPEN_URL );
|
||||
assertEquals( "http://google.com", url3.getValue() );
|
||||
assertEquals( "\n newline3", BaseComponent.toPlainText( test3[2] ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLong()
|
||||
{
|
||||
BaseComponent test = ComponentSerializer.deserialize( "{\"translate\":\"%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s\",\"with\":[{\"translate\":\"%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s\",\"with\":[{\"translate\":\"%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s\",\"with\":[{\"translate\":\"%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s\",\"with\":[{\"translate\":\"%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s\",\"with\":[{\"translate\":\"%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s\",\"with\":[{\"translate\":\"%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s\",\"with\":[{\"translate\":\"%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s\",\"with\":[{\"translate\":\"%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s\",\"with\":[{\"translate\":\"%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s%1$s\",\"with\":[\"Test\"]}]}]}]}]}]}]}]}]}]}" );
|
||||
|
||||
assertThrows( RuntimeException.class, test::toLegacyText );
|
||||
assertThrows( RuntimeException.class, test::toPlainText );
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -884,11 +868,4 @@ public class ComponentsTest
|
||||
{
|
||||
return BaseComponent.toLegacyText( TextComponent.fromLegacyText( legacyText ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayParsing()
|
||||
{
|
||||
assertEquals( "Outfluencer is very cool bdfg28dhzcathisisacoolcomponent",
|
||||
ComponentSerializer.deserialize( "[Outfluencer,[\" \",is,[\" very\",\" cool \",[b,dfg28dhz,[c,[a,thisisacoolcomponent]]]]]]" ).toPlainText() );
|
||||
}
|
||||
}
|
@@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-config</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Config</name>
|
||||
|
@@ -1,28 +0,0 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2025, SpigotMC Pty. Ltd.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -1,38 +0,0 @@
|
||||
BungeeCord-Dialog
|
||||
=================
|
||||
|
||||
Highly experimental API, subject to breakage. All contributions welcome, including major refactors/design changes.
|
||||
|
||||
Sample Plugin
|
||||
-------------
|
||||
|
||||
```java
|
||||
private class TestCommand extends Command
|
||||
{
|
||||
|
||||
public TestCommand()
|
||||
{
|
||||
super( "btest" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args)
|
||||
{
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
|
||||
Dialog notice = new NoticeDialog( new DialogBase( new ComponentBuilder( "Hello" ).color( ChatColor.RED ).build() ) );
|
||||
player.showDialog( notice );
|
||||
|
||||
notice = new NoticeDialog(
|
||||
new DialogBase( new ComponentBuilder( "Hello" ).color( ChatColor.RED ).build() )
|
||||
.inputs(
|
||||
Arrays.asList( new TextInput( "first", new ComponentBuilder( "First" ).build() ),
|
||||
new TextInput( "second", new ComponentBuilder( "Second" ).build() )
|
||||
)
|
||||
) )
|
||||
.action( new ActionButton( new ComponentBuilder( "Submit Button" ).build(), new CustomClickAction( "customform" ) ) );
|
||||
|
||||
player.sendMessage( new ComponentBuilder( "click me" ).event( new ShowDialogClickEvent( notice ) ).build() );
|
||||
}
|
||||
}
|
||||
```
|
@@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-shared-configuration>
|
||||
<!--
|
||||
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||
The configuration is intended to be shared among all the users of project and
|
||||
therefore it is assumed to be part of version control checkout.
|
||||
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||
-->
|
||||
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||
<!--
|
||||
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||
-->
|
||||
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>
|
||||
</properties>
|
||||
</project-shared-configuration>
|
@@ -1,35 +0,0 @@
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-dialog</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Dialog</name>
|
||||
<description>Minecraft dialog API intended for use with BungeeCord</description>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>BSD-3-Clause</name>
|
||||
<url>https://github.com/SpigotMC/BungeeCord/blob/master/dialog/LICENSE</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,39 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.dialog.action.ActionButton;
|
||||
|
||||
/**
|
||||
* Represents a simple dialog with text and two actions at the bottom (default:
|
||||
* "yes", "no").
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
@Accessors(fluent = true)
|
||||
public final class ConfirmationDialog implements Dialog
|
||||
{
|
||||
|
||||
@NonNull
|
||||
@Accessors(fluent = false)
|
||||
private DialogBase base;
|
||||
/**
|
||||
* The "yes" click action / bottom (appears on the left).
|
||||
*/
|
||||
private ActionButton yes;
|
||||
/**
|
||||
* The "no" click action / bottom (appears on the right).
|
||||
*/
|
||||
private ActionButton no;
|
||||
|
||||
public ConfirmationDialog(@NonNull DialogBase base)
|
||||
{
|
||||
this( base, null, null );
|
||||
}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Represents a dialog GUI.
|
||||
*/
|
||||
public interface Dialog
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets the dialog base which contains the dialog title and other options
|
||||
* common to all types of dialogs.
|
||||
*
|
||||
* @return mutable reference to the dialog base
|
||||
*/
|
||||
DialogBase getBase();
|
||||
|
||||
/**
|
||||
* Sets the dialog base.
|
||||
* <br>
|
||||
* For internal use only as this is mandatory and should be specified in the
|
||||
* constructor.
|
||||
*
|
||||
* @param base the new dialog base
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
void setBase(DialogBase base);
|
||||
}
|
@@ -1,84 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.dialog.body.DialogBody;
|
||||
import net.md_5.bungee.api.dialog.input.DialogInput;
|
||||
|
||||
/**
|
||||
* Represents the title and other options common to all dialogs.
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Accessors(fluent = true)
|
||||
public final class DialogBase
|
||||
{
|
||||
|
||||
/**
|
||||
* The mandatory dialog title.
|
||||
*/
|
||||
@NonNull
|
||||
private BaseComponent title;
|
||||
/**
|
||||
* The name which is used for any buttons leading to this dialog (eg from a
|
||||
* {@link DialogListDialog}). Otherwise defaults to {@link #title}.
|
||||
*/
|
||||
@SerializedName("external_title")
|
||||
private BaseComponent externalTitle;
|
||||
/**
|
||||
* The inputs to the dialog.
|
||||
*/
|
||||
private List<DialogInput> inputs;
|
||||
/**
|
||||
* The body elements which make up this dialog.
|
||||
*/
|
||||
private List<DialogBody> body;
|
||||
/**
|
||||
* Whether this dialog can be closed with the escape key (default: true).
|
||||
*/
|
||||
@SerializedName("can_close_with_escape")
|
||||
private Boolean canCloseWithEscape;
|
||||
/**
|
||||
* Whether this dialog should pause the game in single-player mode (default:
|
||||
* true).
|
||||
*/
|
||||
private Boolean pause;
|
||||
/**
|
||||
* Action to take after the a click or submit action is performed on the
|
||||
* dialog (default: close).
|
||||
*/
|
||||
@SerializedName("after_action")
|
||||
private AfterAction afterAction;
|
||||
|
||||
public DialogBase(@NonNull BaseComponent title)
|
||||
{
|
||||
this( title, null, null, null, null, null, null );
|
||||
}
|
||||
|
||||
/**
|
||||
* Types of action which may be taken after the dialog.
|
||||
*/
|
||||
public enum AfterAction
|
||||
{
|
||||
/**
|
||||
* Close the dialog.
|
||||
*/
|
||||
@SerializedName("close")
|
||||
CLOSE,
|
||||
/**
|
||||
* Do nothing.
|
||||
*/
|
||||
@SerializedName("none")
|
||||
NONE,
|
||||
/**
|
||||
* Show a waiting for response screen.
|
||||
*/
|
||||
@SerializedName("wait_for_response")
|
||||
WAIT_FOR_RESPONSE;
|
||||
}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.dialog.action.ActionButton;
|
||||
|
||||
/**
|
||||
* Represents a dialog which contains buttons that link to other dialogs.
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@Accessors(fluent = true)
|
||||
public final class DialogListDialog implements Dialog
|
||||
{
|
||||
|
||||
@NonNull
|
||||
@Accessors(fluent = false)
|
||||
private DialogBase base;
|
||||
/**
|
||||
* The child dialogs behind each button.
|
||||
*/
|
||||
private List<Dialog> dialogs;
|
||||
/**
|
||||
* The {@link ActionButton} activated when the dialog is exited.
|
||||
*/
|
||||
@SerializedName("exit_action")
|
||||
private ActionButton exitAction;
|
||||
/**
|
||||
* The number of columns for the dialog buttons (default: 2).
|
||||
*/
|
||||
private Integer columns;
|
||||
/**
|
||||
* The width of the dialog buttons (default: 150, minimum: 1, maximum:
|
||||
* 1024).
|
||||
*/
|
||||
@SerializedName("button_width")
|
||||
private Integer buttonWidth;
|
||||
|
||||
public DialogListDialog(@NonNull DialogBase base, Dialog... dialogs)
|
||||
{
|
||||
this( base, Arrays.asList( dialogs ), null, null, null );
|
||||
}
|
||||
|
||||
public DialogListDialog(@NonNull DialogBase base, List<Dialog> dialogs, ActionButton exitAction, Integer columns, Integer buttonWidth)
|
||||
{
|
||||
this.base = base;
|
||||
this.dialogs = dialogs;
|
||||
this.exitAction = exitAction;
|
||||
columns( columns );
|
||||
buttonWidth( buttonWidth );
|
||||
}
|
||||
|
||||
public DialogListDialog columns(Integer columns)
|
||||
{
|
||||
Preconditions.checkArgument( columns == null || columns > 0, "At least one column is required" );
|
||||
this.columns = columns;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DialogListDialog buttonWidth(Integer buttonWidth)
|
||||
{
|
||||
Preconditions.checkArgument( buttonWidth == null || ( buttonWidth >= 1 && buttonWidth <= 1024 ), "buttonWidth must be between 1 and 1024" );
|
||||
this.buttonWidth = buttonWidth;
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -1,64 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.dialog.action.ActionButton;
|
||||
|
||||
/**
|
||||
* Represents a dialog with text a list of action buttons grouped into columns
|
||||
* and scrollable if necessary.
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@Accessors(fluent = true)
|
||||
public final class MultiActionDialog implements Dialog
|
||||
{
|
||||
|
||||
@NonNull
|
||||
@Accessors(fluent = false)
|
||||
private DialogBase base;
|
||||
/**
|
||||
* The action buttons in the dialog. At least one must be provided.
|
||||
*/
|
||||
@NonNull
|
||||
private List<ActionButton> actions;
|
||||
/**
|
||||
* The number of columns for the dialog buttons (default: 2).
|
||||
*/
|
||||
private Integer columns;
|
||||
/**
|
||||
* The {@link ActionButton} activated when the dialog is exited.
|
||||
*/
|
||||
@SerializedName("exit_action")
|
||||
private ActionButton exitAction;
|
||||
|
||||
public MultiActionDialog(@NonNull DialogBase base, @NonNull ActionButton... actions)
|
||||
{
|
||||
this( base, Arrays.asList( actions ), null, null );
|
||||
}
|
||||
|
||||
public MultiActionDialog(@NonNull DialogBase base, @NonNull List<ActionButton> actions, Integer columns, ActionButton exitAction)
|
||||
{
|
||||
Preconditions.checkArgument( !actions.isEmpty(), "At least one action must be provided" );
|
||||
|
||||
this.base = base;
|
||||
this.actions = actions;
|
||||
columns( columns );
|
||||
this.exitAction = exitAction;
|
||||
}
|
||||
|
||||
public MultiActionDialog columns(Integer columns)
|
||||
{
|
||||
Preconditions.checkArgument( columns == null || columns > 0, "At least one column is required" );
|
||||
this.columns = columns;
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.dialog.action.ActionButton;
|
||||
|
||||
/**
|
||||
* Represents a simple dialog with text and one action at the bottom (default:
|
||||
* "OK").
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
@Accessors(fluent = true)
|
||||
public final class NoticeDialog implements Dialog
|
||||
{
|
||||
|
||||
@NonNull
|
||||
@Accessors(fluent = false)
|
||||
private DialogBase base;
|
||||
/**
|
||||
* The "OK" action button for the dialog.
|
||||
*/
|
||||
private ActionButton action;
|
||||
|
||||
public NoticeDialog(DialogBase base)
|
||||
{
|
||||
this( base, null );
|
||||
}
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.dialog.action.ActionButton;
|
||||
|
||||
/**
|
||||
* Represents a dialog which shows the links configured/sent from the server.
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@Accessors(fluent = true)
|
||||
public final class ServerLinksDialog implements Dialog
|
||||
{
|
||||
|
||||
@NonNull
|
||||
@Accessors(fluent = false)
|
||||
private DialogBase base;
|
||||
/**
|
||||
* The optional {@link ActionButton} for this dialog.
|
||||
*/
|
||||
@SerializedName("action")
|
||||
private ActionButton action;
|
||||
/**
|
||||
* The {@link ActionButton} activated when the dialog is exited.
|
||||
*/
|
||||
@SerializedName("exit_action")
|
||||
private ActionButton exitAction;
|
||||
/**
|
||||
* The number of columns for the dialog buttons (default: 2).
|
||||
*/
|
||||
private Integer columns;
|
||||
/**
|
||||
* The width of the dialog buttons (default: 150, minimum: 1, maximum:
|
||||
* 1024).
|
||||
*/
|
||||
@SerializedName("button_width")
|
||||
private Integer buttonWidth;
|
||||
|
||||
public ServerLinksDialog(@NonNull DialogBase base)
|
||||
{
|
||||
this( base, null, null, null );
|
||||
}
|
||||
|
||||
public ServerLinksDialog(@NonNull DialogBase base, ActionButton action, Integer columns, Integer buttonWidth)
|
||||
{
|
||||
this.base = base;
|
||||
this.action = action;
|
||||
columns( columns );
|
||||
buttonWidth( buttonWidth );
|
||||
}
|
||||
|
||||
public ServerLinksDialog columns(Integer columns)
|
||||
{
|
||||
Preconditions.checkArgument( columns == null || columns > 0, "At least one column is required" );
|
||||
this.columns = columns;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerLinksDialog buttonWidth(Integer buttonWidth)
|
||||
{
|
||||
Preconditions.checkArgument( buttonWidth == null || ( buttonWidth >= 1 && buttonWidth <= 1024 ), "buttonWidth must be between 1 and 1024" );
|
||||
this.buttonWidth = buttonWidth;
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.action;
|
||||
|
||||
public interface Action
|
||||
{
|
||||
|
||||
}
|
@@ -1,54 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.action;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* Represents a dialog action which will usually appear as a button.
|
||||
*/
|
||||
@Data
|
||||
@Accessors(fluent = true)
|
||||
public class ActionButton
|
||||
{
|
||||
|
||||
/**
|
||||
* The text label of the button, mandatory.
|
||||
*/
|
||||
@NonNull
|
||||
private BaseComponent label;
|
||||
/**
|
||||
* The hover tooltip of the button.
|
||||
*/
|
||||
private BaseComponent tooltip;
|
||||
/**
|
||||
* The width of the button (default: 150, minimum: 1, maximum: 1024).
|
||||
*/
|
||||
private Integer width;
|
||||
/**
|
||||
* The action to take.
|
||||
*/
|
||||
@NonNull
|
||||
private Action action;
|
||||
|
||||
public ActionButton(@NonNull BaseComponent label, BaseComponent tooltip, Integer width, @NonNull Action action)
|
||||
{
|
||||
this.label = label;
|
||||
this.tooltip = tooltip;
|
||||
setWidth( width );
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public ActionButton(@NonNull BaseComponent label, @NonNull Action action)
|
||||
{
|
||||
this( label, null, null, action );
|
||||
}
|
||||
|
||||
public void setWidth(Integer width)
|
||||
{
|
||||
Preconditions.checkArgument( width == null || ( width >= 1 && width <= 1024 ), "width must be between 1 and 1024" );
|
||||
this.width = width;
|
||||
}
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.action;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* Submits the dialog with the given ID and values as a payload.
|
||||
*/
|
||||
@Data
|
||||
@Accessors(fluent = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CustomClickAction implements Action
|
||||
{
|
||||
|
||||
/**
|
||||
* The namespaced key of the submission.
|
||||
*/
|
||||
@NonNull
|
||||
private String id;
|
||||
/**
|
||||
* Fields to be added to the submission payload.
|
||||
*/
|
||||
private JsonElement additions;
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.action;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* Executes a command. If the command requires a permission higher than 0, a
|
||||
* confirmation dialog will be shown by the client.
|
||||
*/
|
||||
@Data
|
||||
@Accessors(fluent = true)
|
||||
@ToString(callSuper = true)
|
||||
public class RunCommandAction implements Action
|
||||
{
|
||||
|
||||
/**
|
||||
* The template to be applied, where variables of the form
|
||||
* <code>$(key)</code> will be replaced by their
|
||||
* {@link net.md_5.bungee.api.dialog.input.DialogInput#key} value.
|
||||
*/
|
||||
@NonNull
|
||||
private String template;
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.action;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
|
||||
/**
|
||||
* Represents a static dialog action.
|
||||
*/
|
||||
@Data
|
||||
@Accessors(fluent = true)
|
||||
@ToString(callSuper = true)
|
||||
public class StaticAction implements Action
|
||||
{
|
||||
|
||||
@NonNull
|
||||
private ClickEvent clickEvent;
|
||||
}
|
@@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Contains the different actions/buttons for a {@link net.md_5.bungee.api.dialog.Dialog}.
|
||||
*/
|
||||
package net.md_5.bungee.api.dialog.action;
|
@@ -1,20 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.body;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Represents the body content of a {@link net.md_5.bungee.api.dialog.Dialog}.
|
||||
*/
|
||||
@Data
|
||||
public abstract class DialogBody
|
||||
{
|
||||
|
||||
/**
|
||||
* The internal body type.
|
||||
*/
|
||||
@NonNull
|
||||
@ApiStatus.Internal
|
||||
private final String type;
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.body;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* Represents a dialog body which consists of text constrained to a certain
|
||||
* width.
|
||||
*/
|
||||
@Data
|
||||
@Accessors(fluent = true)
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class PlainMessageBody extends DialogBody
|
||||
{
|
||||
|
||||
/**
|
||||
* The text body.
|
||||
*/
|
||||
@NonNull
|
||||
private BaseComponent contents;
|
||||
/**
|
||||
* The maximum width (default: 200, minimum: 1, maximum: 1024).
|
||||
*/
|
||||
private Integer width;
|
||||
|
||||
public PlainMessageBody(@NonNull BaseComponent contents)
|
||||
{
|
||||
this( contents, null );
|
||||
}
|
||||
|
||||
public PlainMessageBody(@NonNull BaseComponent contents, Integer width)
|
||||
{
|
||||
super( "minecraft:plain_message" );
|
||||
this.contents = contents;
|
||||
width( width );
|
||||
}
|
||||
|
||||
public void width(Integer width)
|
||||
{
|
||||
Preconditions.checkArgument( width == null || ( width >= 1 && width <= 1024 ), "width must be between 1 and 1024" );
|
||||
this.width = width;
|
||||
}
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
/**
|
||||
* Contains the different {@link net.md_5.bungee.api.dialog.Dialog} body content
|
||||
* types.
|
||||
*/
|
||||
package net.md_5.bungee.api.dialog.body;
|
@@ -1,42 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.chat;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.dialog.Dialog;
|
||||
|
||||
/**
|
||||
* Click event which displays either a pre-existing dialog by key or a custom
|
||||
* dialog.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ShowDialogClickEvent extends ClickEvent
|
||||
{
|
||||
|
||||
/**
|
||||
* Key for a pre-existing dialog to show.
|
||||
*/
|
||||
private String reference;
|
||||
/**
|
||||
* Dialog to show.
|
||||
*/
|
||||
private Dialog dialog;
|
||||
|
||||
public ShowDialogClickEvent(String reference)
|
||||
{
|
||||
this( reference, null );
|
||||
}
|
||||
|
||||
public ShowDialogClickEvent(Dialog dialog)
|
||||
{
|
||||
this( null, dialog );
|
||||
}
|
||||
|
||||
private ShowDialogClickEvent(String reference, Dialog dialog)
|
||||
{
|
||||
super( Action.SHOW_DIALOG, null );
|
||||
this.reference = reference;
|
||||
this.dialog = dialog;
|
||||
}
|
||||
}
|
@@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Contains dialog extensions to the chat API.
|
||||
*/
|
||||
package net.md_5.bungee.api.dialog.chat;
|
@@ -1,54 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.input;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* Represents a checkbox input control.
|
||||
*/
|
||||
@Data
|
||||
@Accessors(fluent = true)
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class BooleanInput extends DialogInput
|
||||
{
|
||||
|
||||
/**
|
||||
* The input label.
|
||||
*/
|
||||
@NonNull
|
||||
private BaseComponent label;
|
||||
/**
|
||||
* The initial value (default: false/unchecked).
|
||||
*/
|
||||
private Boolean initial;
|
||||
/**
|
||||
* The string value to be submitted when true/checked (default: "true").
|
||||
*/
|
||||
@SerializedName("on_true")
|
||||
private String onTrue;
|
||||
/**
|
||||
* The string value to be submitted when false/unchecked (default: "false").
|
||||
*/
|
||||
@SerializedName("on_false")
|
||||
private String onFalse;
|
||||
|
||||
public BooleanInput(@NonNull String key, @NonNull BaseComponent label)
|
||||
{
|
||||
this( key, label, null, "true", "false" );
|
||||
}
|
||||
|
||||
public BooleanInput(@NonNull String key, @NonNull BaseComponent label, Boolean initial, String onTrue, String onFalse)
|
||||
{
|
||||
super( "minecraft:boolean", key );
|
||||
this.label = label;
|
||||
this.initial = initial;
|
||||
this.onTrue = onTrue;
|
||||
this.onFalse = onFalse;
|
||||
}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.input;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Represents a type of input which may be displayed/submitted with a form
|
||||
* dialog.
|
||||
*/
|
||||
@Data
|
||||
@Accessors(fluent = true)
|
||||
public class DialogInput
|
||||
{
|
||||
|
||||
/**
|
||||
* The internal input type.
|
||||
*/
|
||||
@NonNull
|
||||
@ApiStatus.Internal
|
||||
private final String type;
|
||||
/**
|
||||
* The key corresponding to this input and associated with the value
|
||||
* submitted.
|
||||
*/
|
||||
@NonNull
|
||||
private final String key;
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.input;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* Represents an option choice which may form part of a
|
||||
* {@link SingleOptionInput}.
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Accessors(fluent = true)
|
||||
public class InputOption
|
||||
{
|
||||
|
||||
/**
|
||||
* The string value associated with this option, to be submitted when
|
||||
* selected.
|
||||
*/
|
||||
@NonNull
|
||||
private String id;
|
||||
/**
|
||||
* The text to display for this option.
|
||||
*/
|
||||
private BaseComponent display;
|
||||
/**
|
||||
* Whether this option is the one initially selected. Only one option may
|
||||
* have this value as true (default: first option).
|
||||
*/
|
||||
private Boolean initial;
|
||||
|
||||
public InputOption(@NonNull String id)
|
||||
{
|
||||
this( id, null, null );
|
||||
}
|
||||
}
|
@@ -1,103 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.input;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* Represents a number slider input.
|
||||
*/
|
||||
@Data
|
||||
@Accessors(fluent = true)
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class NumberRangeInput extends DialogInput
|
||||
{
|
||||
|
||||
/**
|
||||
* The width of the input (default: 200, minimum: 1, maximum: 1024).
|
||||
*/
|
||||
private Integer width;
|
||||
/**
|
||||
* The label of the slider.
|
||||
*/
|
||||
@NonNull
|
||||
private BaseComponent label;
|
||||
/**
|
||||
* A translate key used to display the label value (default:
|
||||
* options.generic_value).
|
||||
*/
|
||||
private String labelFormat;
|
||||
/**
|
||||
* The start position of the slider (leftmost position).
|
||||
*/
|
||||
private float start;
|
||||
/**
|
||||
* The end position of the slider (rightmost position).
|
||||
*/
|
||||
private float end;
|
||||
/**
|
||||
* The steps in which the input will be increased or decreased, or null if
|
||||
* no specific steps.
|
||||
*/
|
||||
private Float step;
|
||||
/**
|
||||
* The initial value of number input, or null to fall back to the middle.
|
||||
*/
|
||||
private Float initial;
|
||||
|
||||
public NumberRangeInput(@NonNull String key, @NonNull BaseComponent label, float start, float end)
|
||||
{
|
||||
this( key, null, label, "options.generic_value", start, end, null, null );
|
||||
}
|
||||
|
||||
public NumberRangeInput(@NonNull String key, @NonNull BaseComponent label, float start, float end, Float step)
|
||||
{
|
||||
this( key, null, label, "options.generic_value", start, end, step, null );
|
||||
}
|
||||
|
||||
public NumberRangeInput(@NonNull String key, @NonNull BaseComponent label, float start, float end, Float step, Float initial)
|
||||
{
|
||||
this( key, null, label, "options.generic_value", start, end, step, initial );
|
||||
}
|
||||
|
||||
public NumberRangeInput(@NonNull String key, Integer width, @NonNull BaseComponent label, String labelFormat, float start, float end, Float step, Float initial)
|
||||
{
|
||||
super( "minecraft:number_range", key );
|
||||
width( width );
|
||||
this.label = label;
|
||||
this.labelFormat = labelFormat;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
step( step );
|
||||
initial( initial );
|
||||
}
|
||||
|
||||
public NumberRangeInput width(Integer width)
|
||||
{
|
||||
Preconditions.checkArgument( width == null || ( width >= 1 && width <= 1024 ), "with must be between 1 and 1024" );
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NumberRangeInput step(Float step)
|
||||
{
|
||||
Preconditions.checkArgument( step == null || step > 0, "step must be null or greater than zero" );
|
||||
this.step = step;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NumberRangeInput initial(Float initial)
|
||||
{
|
||||
// we need to calculate if the initial value is between start and end, regardless of the order
|
||||
float min = Math.min( start, end );
|
||||
float max = Math.max( start, end );
|
||||
Preconditions.checkArgument( initial == null || ( initial >= min && initial <= max ), "initial must be null or between start and end" );
|
||||
this.initial = initial;
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.input;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* Represents a single option (dropdown) input.
|
||||
*/
|
||||
@Data
|
||||
@Accessors(fluent = true)
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SingleOptionInput extends DialogInput
|
||||
{
|
||||
|
||||
/**
|
||||
* The width of the input (default: 200, minimum: 1, maximum: 1024).
|
||||
*/
|
||||
private Integer width;
|
||||
/**
|
||||
* The input label.
|
||||
*/
|
||||
@NonNull
|
||||
private BaseComponent label;
|
||||
/**
|
||||
* Whether the label is visible (default: true).
|
||||
*/
|
||||
@SerializedName("label_visible")
|
||||
private Boolean labelVisible;
|
||||
/**
|
||||
* The non-empty list of options to be selected from.
|
||||
*/
|
||||
@NonNull
|
||||
private List<InputOption> options;
|
||||
|
||||
public SingleOptionInput(@NonNull String key, @NonNull BaseComponent label, @NonNull InputOption... options)
|
||||
{
|
||||
this( key, null, label, null, Arrays.asList( options ) );
|
||||
}
|
||||
|
||||
public SingleOptionInput(@NonNull String key, Integer width, @NonNull BaseComponent label, Boolean labelVisible, @NonNull List<InputOption> options)
|
||||
{
|
||||
super( "minecraft:single_option", key );
|
||||
Preconditions.checkArgument( !options.isEmpty(), "At least one option must be provided" );
|
||||
|
||||
width( width );
|
||||
this.label = label;
|
||||
this.labelVisible = labelVisible;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public SingleOptionInput width(Integer width)
|
||||
{
|
||||
Preconditions.checkArgument( width == null || ( width >= 1 && width <= 1024 ), "width must be between 1 and 1024" );
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -1,110 +0,0 @@
|
||||
package net.md_5.bungee.api.dialog.input;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* Represents a textbox input.
|
||||
*/
|
||||
@Data
|
||||
@Accessors(fluent = true)
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class TextInput extends DialogInput
|
||||
{
|
||||
|
||||
/**
|
||||
* The width of this text input (default: 200, minimum: 1, maximum: 1024).
|
||||
*/
|
||||
private Integer width;
|
||||
/**
|
||||
* The label of this text input.
|
||||
*/
|
||||
@NonNull
|
||||
private BaseComponent label;
|
||||
/**
|
||||
* The visibility of this text input's label.
|
||||
*/
|
||||
@SerializedName("label_visible")
|
||||
private Boolean labelVisible;
|
||||
/**
|
||||
* The initial value of this text input.
|
||||
*/
|
||||
private String initial;
|
||||
/**
|
||||
* The maximum length of the input (default: 32).
|
||||
*/
|
||||
@SerializedName("max_length")
|
||||
private Integer maxLength;
|
||||
/**
|
||||
* If present, allows users to input multiple lines.
|
||||
*/
|
||||
private Multiline multiline;
|
||||
|
||||
public TextInput(@NonNull String key, @NonNull BaseComponent label)
|
||||
{
|
||||
this( key, null, label, null, null, null, null );
|
||||
}
|
||||
|
||||
public TextInput(@NonNull String key, Integer width, @NonNull BaseComponent label, Boolean labelVisible, String initial, Integer maxLength)
|
||||
{
|
||||
this( key, width, label, labelVisible, initial, maxLength, null );
|
||||
}
|
||||
|
||||
public TextInput(@NonNull String key, Integer width, @NonNull BaseComponent label, Boolean labelVisible, String initial, Integer maxLength, Multiline multiline)
|
||||
{
|
||||
super( "minecraft:text", key );
|
||||
width( width );
|
||||
this.label = label;
|
||||
this.labelVisible = labelVisible;
|
||||
this.initial = initial;
|
||||
this.maxLength = maxLength;
|
||||
this.multiline = multiline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration data for a multiline input.
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Accessors(fluent = true)
|
||||
public static class Multiline
|
||||
{
|
||||
|
||||
/**
|
||||
* The maximum length of input, or null to disable any limits.
|
||||
*/
|
||||
@SerializedName("max_lines")
|
||||
private Integer maxLines;
|
||||
/**
|
||||
* The height of this input (default: 32, minimum: 1, maximum: 512).
|
||||
*/
|
||||
private Integer height;
|
||||
|
||||
public Multiline(Integer maxLines, Integer height)
|
||||
{
|
||||
height( height ).maxLines( maxLines );
|
||||
}
|
||||
|
||||
public Multiline height(Integer height)
|
||||
{
|
||||
Preconditions.checkArgument( height == null || height >= 1 && height <= 512, "height must null or be between 1 and 512" );
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public TextInput width(Integer width)
|
||||
{
|
||||
Preconditions.checkArgument( width == null || ( width >= 1 && width <= 1024 ), "width must be between 1 and 1024" );
|
||||
this.width = width;
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Represents the various input controls which may be present on form dialogs.
|
||||
*/
|
||||
package net.md_5.bungee.api.dialog.input;
|
@@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Contains the core classes for the display of a {@link net.md_5.bungee.api.dialog.Dialog}.
|
||||
*/
|
||||
package net.md_5.bungee.api.dialog;
|
@@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-event</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Event</name>
|
||||
|
@@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-log</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Log</name>
|
||||
@@ -19,9 +19,9 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jline</groupId>
|
||||
<groupId>jline</groupId>
|
||||
<artifactId>jline</artifactId>
|
||||
<version>3.30.4</version>
|
||||
<version>2.12.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@@ -1,18 +1,26 @@
|
||||
package net.md_5.bungee.log;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import org.jline.reader.LineReader;
|
||||
import jline.console.ConsoleReader;
|
||||
|
||||
public class BungeeLogger extends Logger
|
||||
{
|
||||
|
||||
private final LogDispatcher dispatcher = new LogDispatcher( this );
|
||||
|
||||
public BungeeLogger(String loggerName, String filePattern, LineReader reader)
|
||||
// CHECKSTYLE:OFF
|
||||
@SuppressWarnings(
|
||||
{
|
||||
"CallToPrintStackTrace", "CallToThreadStartDuringObjectConstruction"
|
||||
})
|
||||
// CHECKSTYLE:ON
|
||||
@SuppressFBWarnings("SC_START_IN_CTOR")
|
||||
public BungeeLogger(String loggerName, String filePattern, ConsoleReader reader)
|
||||
{
|
||||
super( loggerName, null );
|
||||
setLevel( Level.ALL );
|
||||
|
@@ -1,15 +1,15 @@
|
||||
package net.md_5.bungee.log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.regex.Pattern;
|
||||
import jline.console.ConsoleReader;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.jline.jansi.Ansi;
|
||||
import org.jline.reader.LineReader;
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.fusesource.jansi.Ansi.Erase;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class ColouredWriter extends Handler
|
||||
{
|
||||
|
||||
@@ -52,7 +52,12 @@ public class ColouredWriter extends Handler
|
||||
compile( ChatColor.RESET, Ansi.ansi().a( Ansi.Attribute.RESET ).toString() ),
|
||||
};
|
||||
//
|
||||
private final LineReader console;
|
||||
private final ConsoleReader console;
|
||||
|
||||
public ColouredWriter(ConsoleReader console)
|
||||
{
|
||||
this.console = console;
|
||||
}
|
||||
|
||||
public void print(String s)
|
||||
{
|
||||
@@ -60,7 +65,14 @@ public class ColouredWriter extends Handler
|
||||
{
|
||||
s = replacement.pattern.matcher( s ).replaceAll( replacement.replacement );
|
||||
}
|
||||
console.printAbove( s + Ansi.ansi().reset().toString() );
|
||||
try
|
||||
{
|
||||
console.print( Ansi.ansi().eraseLine( Erase.ALL ).toString() + ConsoleReader.RESET_LINE + s + Ansi.ansi().reset().toString() );
|
||||
console.drawLine();
|
||||
console.flush();
|
||||
} catch ( IOException ex )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -18,6 +18,7 @@ public class ConciseFormatter extends Formatter
|
||||
private final boolean coloured;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("ThrowableResultIgnored")
|
||||
public String format(LogRecord record)
|
||||
{
|
||||
StringBuilder formatted = new StringBuilder();
|
||||
|
@@ -6,12 +6,12 @@
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-native</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<version>1.21-R0.3-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Native</name>
|
||||
|
@@ -1,8 +1,6 @@
|
||||
package net.md_5.bungee.jni;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -95,31 +93,7 @@ public final class NativeCode<T>
|
||||
return loaded;
|
||||
}
|
||||
|
||||
public static boolean hasDirectBuffers()
|
||||
{
|
||||
ByteBuf directBuffer = null;
|
||||
boolean hasMemoryAddress = false;
|
||||
try
|
||||
{
|
||||
directBuffer = Unpooled.directBuffer();
|
||||
hasMemoryAddress = directBuffer.hasMemoryAddress();
|
||||
} finally
|
||||
{
|
||||
if ( directBuffer != null )
|
||||
{
|
||||
directBuffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
return hasMemoryAddress;
|
||||
}
|
||||
|
||||
public static boolean isSupported()
|
||||
{
|
||||
return isSupportedPlatformAndArch() && hasDirectBuffers();
|
||||
}
|
||||
|
||||
private static boolean isSupportedPlatformAndArch()
|
||||
{
|
||||
return "Linux".equals( System.getProperty( "os.name" ) ) && ( isAmd64() || isAarch64() );
|
||||
}
|
||||
|
28
nbt/LICENSE
28
nbt/LICENSE
@@ -1,28 +0,0 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2025, SpigotMC Pty. Ltd.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -1,4 +0,0 @@
|
||||
BungeeCord-NBT
|
||||
=================
|
||||
|
||||
Minimal implementation of NBT for use in BungeeCord
|
@@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-shared-configuration>
|
||||
<!--
|
||||
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||
The configuration is intended to be shared among all the users of project and
|
||||
therefore it is assumed to be part of version control checkout.
|
||||
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||
-->
|
||||
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||
<!--
|
||||
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||
-->
|
||||
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>
|
||||
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>
|
||||
</properties>
|
||||
</project-shared-configuration>
|
26
nbt/pom.xml
26
nbt/pom.xml
@@ -1,26 +0,0 @@
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>bungeecord-nbt</artifactId>
|
||||
<version>1.21-R0.5-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-NBT</name>
|
||||
<description>Minimal implementation of NBT for use in BungeeCord</description>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>BSD-3-Clause</name>
|
||||
<url>https://github.com/SpigotMC/BungeeCord/blob/master/nbt/LICENSE</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
@@ -1,52 +0,0 @@
|
||||
package net.md_5.bungee.nbt;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.nbt.limit.NBTLimiter;
|
||||
import net.md_5.bungee.nbt.type.CompoundTag;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class NamedTag implements Tag
|
||||
{
|
||||
|
||||
private String name;
|
||||
private TypedTag tag;
|
||||
|
||||
/**
|
||||
* Reads the data of the {@link DataInput} and parses it into this
|
||||
* {@link NamedTag}.
|
||||
*
|
||||
* @param input input to read from
|
||||
* @param limiter limitation of the read data
|
||||
*/
|
||||
@Override
|
||||
public void read(DataInput input, NBTLimiter limiter) throws IOException
|
||||
{
|
||||
byte type = input.readByte();
|
||||
name = CompoundTag.readString( input, limiter );
|
||||
tag = Tag.readById( type, input, limiter );
|
||||
}
|
||||
|
||||
/**
|
||||
* Write this {@link NamedTag} into a {@link DataOutput}.
|
||||
*
|
||||
* @param output the output to write to
|
||||
*/
|
||||
@Override
|
||||
public void write(DataOutput output) throws IOException
|
||||
{
|
||||
Preconditions.checkNotNull( name, "name cannot be null" );
|
||||
Preconditions.checkNotNull( tag, "tag cannot be null" );
|
||||
|
||||
output.writeByte( tag.getId() );
|
||||
CompoundTag.writeString( name, output );
|
||||
tag.write( output );
|
||||
}
|
||||
}
|
@@ -1,166 +0,0 @@
|
||||
package net.md_5.bungee.nbt;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.function.Supplier;
|
||||
import net.md_5.bungee.nbt.exception.NBTFormatException;
|
||||
import net.md_5.bungee.nbt.limit.NBTLimiter;
|
||||
import net.md_5.bungee.nbt.type.ByteArrayTag;
|
||||
import net.md_5.bungee.nbt.type.ByteTag;
|
||||
import net.md_5.bungee.nbt.type.CompoundTag;
|
||||
import net.md_5.bungee.nbt.type.DoubleTag;
|
||||
import net.md_5.bungee.nbt.type.EndTag;
|
||||
import net.md_5.bungee.nbt.type.FloatTag;
|
||||
import net.md_5.bungee.nbt.type.IntArrayTag;
|
||||
import net.md_5.bungee.nbt.type.IntTag;
|
||||
import net.md_5.bungee.nbt.type.ListTag;
|
||||
import net.md_5.bungee.nbt.type.LongArrayTag;
|
||||
import net.md_5.bungee.nbt.type.LongTag;
|
||||
import net.md_5.bungee.nbt.type.ShortTag;
|
||||
import net.md_5.bungee.nbt.type.StringTag;
|
||||
|
||||
public interface Tag
|
||||
{
|
||||
|
||||
int OBJECT_HEADER = 8;
|
||||
int ARRAY_HEADER = 12;
|
||||
int STRING_SIZE = 28;
|
||||
int OBJECT_REFERENCE = 4;
|
||||
|
||||
Supplier<? extends TypedTag>[] CONSTRUCTORS = new Supplier[]
|
||||
{
|
||||
EndTag::new,
|
||||
ByteTag::new,
|
||||
ShortTag::new,
|
||||
IntTag::new,
|
||||
LongTag::new,
|
||||
FloatTag::new,
|
||||
DoubleTag::new,
|
||||
ByteArrayTag::new,
|
||||
StringTag::new,
|
||||
ListTag::new,
|
||||
CompoundTag::new,
|
||||
IntArrayTag::new,
|
||||
LongArrayTag::new
|
||||
};
|
||||
|
||||
byte END = 0;
|
||||
byte BYTE = 1;
|
||||
byte SHORT = 2;
|
||||
byte INT = 3;
|
||||
byte LONG = 4;
|
||||
byte FLOAT = 5;
|
||||
byte DOUBLE = 6;
|
||||
byte BYTE_ARRAY = 7;
|
||||
byte STRING = 8;
|
||||
byte LIST = 9;
|
||||
byte COMPOUND = 10;
|
||||
byte INT_ARRAY = 11;
|
||||
byte LONG_ARRAY = 12;
|
||||
|
||||
/**
|
||||
* Reads the data into this tag.
|
||||
*
|
||||
* @param input the input to read from
|
||||
* @param limiter the limiter for this read operation
|
||||
* @throws IOException if an exception occurs during io operations
|
||||
*/
|
||||
void read(DataInput input, NBTLimiter limiter) throws IOException;
|
||||
|
||||
/**
|
||||
* Writes this tag into a {@link DataOutput}.
|
||||
*
|
||||
* @param output the output to write to
|
||||
* @throws IOException if an exception occurs during io operations
|
||||
*/
|
||||
void write(DataOutput output) throws IOException;
|
||||
|
||||
/**
|
||||
* Reads a {@link Tag} from the given {@link DataInput}, based on the
|
||||
* specified tag type, with limitations of the {@link NBTLimiter}.
|
||||
*
|
||||
* @param id the nbt type
|
||||
* @param input the input to read from
|
||||
* @param limiter the limiter for this read operation
|
||||
* @return the deserialized {@link Tag}
|
||||
* @throws IOException if an exception occurs during io operations
|
||||
*/
|
||||
static TypedTag readById(byte id, DataInput input, NBTLimiter limiter) throws IOException
|
||||
{
|
||||
if ( id < END || id > LONG_ARRAY )
|
||||
{
|
||||
throw new NBTFormatException( "Invalid tag id: " + id );
|
||||
}
|
||||
|
||||
TypedTag tag = CONSTRUCTORS[id].get();
|
||||
tag.read( input, limiter );
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a {@link NamedTag} from the given {@link DataInput}, with
|
||||
* limitations of the {@link NBTLimiter}.
|
||||
*
|
||||
* @param input the data input to read from
|
||||
* @param limiter the limiter for this read operation
|
||||
* @return the deserialized {@link NamedTag}
|
||||
* @throws IOException if an exception occurs during io operations
|
||||
*/
|
||||
static NamedTag readNamedTag(DataInput input, NBTLimiter limiter) throws IOException
|
||||
{
|
||||
NamedTag namedTag = new NamedTag();
|
||||
namedTag.read( input, limiter );
|
||||
return namedTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the given {@link TypedTag} into a byte array. This is the
|
||||
* inverse operation of {@link #fromByteArray(byte[])}.
|
||||
*
|
||||
* @param tag the tag to convert
|
||||
* @return the serialized byte array
|
||||
* @throws IOException if an exception occurs during io operations
|
||||
*/
|
||||
static byte[] toByteArray(TypedTag tag) throws IOException
|
||||
{
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
DataOutputStream dataOutputStream = new DataOutputStream( byteArrayOutputStream );
|
||||
dataOutputStream.writeByte( tag.getId() );
|
||||
tag.write( dataOutputStream );
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the given byte array into a {@link TypedTag}. This is the
|
||||
* inverse operation of {@link #toByteArray(TypedTag)}.
|
||||
*
|
||||
* @param data the byte array to read from
|
||||
* @return the deserialized {@link TypedTag}
|
||||
* @throws IOException if an exception occurs during io operations
|
||||
*/
|
||||
static TypedTag fromByteArray(byte[] data) throws IOException
|
||||
{
|
||||
return fromByteArray( data, NBTLimiter.unlimitedSize() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the given byte array into a {@link TypedTag}, with
|
||||
* limitations of the {@link NBTLimiter}.
|
||||
*
|
||||
* @param data the byte array to read from
|
||||
* @param limiter the limiter for this read operation
|
||||
* @return the deserialized {@link TypedTag}
|
||||
* @throws IOException if an exception occurs during io operations
|
||||
*/
|
||||
static TypedTag fromByteArray(byte[] data, NBTLimiter limiter) throws IOException
|
||||
{
|
||||
DataInputStream stream = new DataInputStream( new ByteArrayInputStream( data ) );
|
||||
byte type = stream.readByte();
|
||||
return readById( type, stream, limiter );
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
package net.md_5.bungee.nbt;
|
||||
|
||||
public interface TypedTag extends Tag
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets the id of this tag's type.
|
||||
*
|
||||
* @return the id related to this tag's type
|
||||
*/
|
||||
byte getId();
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
package net.md_5.bungee.nbt.exception;
|
||||
|
||||
public class NBTException extends RuntimeException
|
||||
{
|
||||
|
||||
public NBTException(String message)
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
package net.md_5.bungee.nbt.exception;
|
||||
|
||||
public class NBTFormatException extends NBTException
|
||||
{
|
||||
|
||||
public NBTFormatException(String message)
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
package net.md_5.bungee.nbt.exception;
|
||||
|
||||
public class NBTLimitException extends NBTException
|
||||
{
|
||||
|
||||
public NBTLimitException(String message)
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
package net.md_5.bungee.nbt.limit;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.nbt.exception.NBTLimitException;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class NBTLimiter
|
||||
{
|
||||
|
||||
private static final int MAX_STACK_DEPTH = 512;
|
||||
//
|
||||
private final long maxBytes;
|
||||
private final int maxDepth;
|
||||
|
||||
public static NBTLimiter unlimitedSize()
|
||||
{
|
||||
return new NBTLimiter( Long.MAX_VALUE, MAX_STACK_DEPTH );
|
||||
}
|
||||
|
||||
public NBTLimiter(long maxBytes)
|
||||
{
|
||||
this( maxBytes, MAX_STACK_DEPTH );
|
||||
}
|
||||
|
||||
private long usedBytes;
|
||||
private int depth;
|
||||
|
||||
public void countBytes(long amount)
|
||||
{
|
||||
if ( amount < 0 )
|
||||
{
|
||||
throw new NBTLimitException( "NBT limiter tried to count negative byte amount" );
|
||||
}
|
||||
|
||||
if ( ( usedBytes = Math.addExact( usedBytes, amount ) ) > maxBytes )
|
||||
{
|
||||
throw new NBTLimitException( "NBT tag is to big, bytes > " + maxBytes );
|
||||
}
|
||||
}
|
||||
|
||||
public void countBytes(long amount, long factor)
|
||||
{
|
||||
if ( amount < 0 || factor < 0 )
|
||||
{
|
||||
throw new NBTLimitException( "NBT limiter tried to count negative byte amount" );
|
||||
}
|
||||
|
||||
countBytes( Math.multiplyExact( amount, factor ) );
|
||||
}
|
||||
|
||||
public void push()
|
||||
{
|
||||
if ( ( depth = Math.addExact( depth, 1 ) ) > maxDepth )
|
||||
{
|
||||
throw new NBTLimitException( "NBT tag is to complex, depth > " + maxDepth );
|
||||
}
|
||||
}
|
||||
|
||||
public void pop()
|
||||
{
|
||||
if ( --depth < 0 )
|
||||
{
|
||||
throw new NBTLimitException( "NBT limiter tried to pop depth 0" );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
package net.md_5.bungee.nbt.type;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.nbt.Tag;
|
||||
import net.md_5.bungee.nbt.TypedTag;
|
||||
import net.md_5.bungee.nbt.limit.NBTLimiter;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ByteArrayTag implements TypedTag
|
||||
{
|
||||
|
||||
private byte[] value;
|
||||
|
||||
@Override
|
||||
public void read(DataInput input, NBTLimiter limiter) throws IOException
|
||||
{
|
||||
limiter.countBytes( OBJECT_HEADER + ARRAY_HEADER + Integer.BYTES );
|
||||
int length = input.readInt();
|
||||
limiter.countBytes( length, Byte.BYTES );
|
||||
input.readFully( value = new byte[ length ] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput output) throws IOException
|
||||
{
|
||||
Preconditions.checkNotNull( value, "byte array value cannot be null" );
|
||||
output.writeInt( value.length );
|
||||
output.write( value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getId()
|
||||
{
|
||||
return Tag.BYTE_ARRAY;
|
||||
}
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
package net.md_5.bungee.nbt.type;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.nbt.Tag;
|
||||
import net.md_5.bungee.nbt.TypedTag;
|
||||
import net.md_5.bungee.nbt.limit.NBTLimiter;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ByteTag implements TypedTag
|
||||
{
|
||||
|
||||
private byte value;
|
||||
|
||||
@Override
|
||||
public void read(DataInput input, NBTLimiter limiter) throws IOException
|
||||
{
|
||||
limiter.countBytes( OBJECT_HEADER + Byte.BYTES );
|
||||
value = input.readByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput output) throws IOException
|
||||
{
|
||||
output.write( value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getId()
|
||||
{
|
||||
return Tag.BYTE;
|
||||
}
|
||||
}
|
@@ -1,99 +0,0 @@
|
||||
package net.md_5.bungee.nbt.type;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.nbt.Tag;
|
||||
import net.md_5.bungee.nbt.TypedTag;
|
||||
import net.md_5.bungee.nbt.exception.NBTFormatException;
|
||||
import net.md_5.bungee.nbt.limit.NBTLimiter;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CompoundTag implements TypedTag
|
||||
{
|
||||
|
||||
private static final int MAP_SIZE_IN_BYTES = 48;
|
||||
private static final int MAP_ENTRY_SIZE_IN_BYTES = 32;
|
||||
//
|
||||
private Map<String, TypedTag> value;
|
||||
|
||||
@Override
|
||||
public void read(DataInput input, NBTLimiter limiter) throws IOException
|
||||
{
|
||||
limiter.push();
|
||||
limiter.countBytes( MAP_SIZE_IN_BYTES );
|
||||
Map<String, TypedTag> map = new LinkedHashMap<>();
|
||||
for ( byte type; ( type = input.readByte() ) != Tag.END; )
|
||||
{
|
||||
String name = readString( input, limiter );
|
||||
TypedTag tag = Tag.readById( type, input, limiter );
|
||||
if ( map.put( name, tag ) == null )
|
||||
{
|
||||
limiter.countBytes( MAP_ENTRY_SIZE_IN_BYTES + OBJECT_REFERENCE );
|
||||
}
|
||||
}
|
||||
limiter.pop();
|
||||
value = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput output) throws IOException
|
||||
{
|
||||
Preconditions.checkNotNull( value, "compound tag map cannot be null" );
|
||||
for ( Map.Entry<String, TypedTag> entry : value.entrySet() )
|
||||
{
|
||||
String name = entry.getKey();
|
||||
TypedTag tag = entry.getValue();
|
||||
output.writeByte( tag.getId() );
|
||||
if ( tag.getId() == Tag.END )
|
||||
{
|
||||
throw new NBTFormatException( "invalid end tag in compound tag" );
|
||||
}
|
||||
writeString( name, output );
|
||||
tag.write( output );
|
||||
}
|
||||
output.writeByte( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getId()
|
||||
{
|
||||
return Tag.COMPOUND;
|
||||
}
|
||||
|
||||
public static String readString(DataInput input, NBTLimiter limiter) throws IOException
|
||||
{
|
||||
limiter.countBytes( STRING_SIZE );
|
||||
String string = input.readUTF();
|
||||
limiter.countBytes( string.length(), Character.BYTES );
|
||||
return string;
|
||||
}
|
||||
|
||||
public static void writeString(String string, DataOutput output) throws IOException
|
||||
{
|
||||
output.writeUTF( string );
|
||||
}
|
||||
|
||||
public TypedTag get(String key)
|
||||
{
|
||||
return value.get( key );
|
||||
}
|
||||
|
||||
public void put(String key, TypedTag tag)
|
||||
{
|
||||
value.put( key, tag );
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return value.size();
|
||||
}
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
package net.md_5.bungee.nbt.type;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.nbt.Tag;
|
||||
import net.md_5.bungee.nbt.TypedTag;
|
||||
import net.md_5.bungee.nbt.limit.NBTLimiter;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DoubleTag implements TypedTag
|
||||
{
|
||||
|
||||
private double value;
|
||||
|
||||
@Override
|
||||
public void read(DataInput input, NBTLimiter limiter) throws IOException
|
||||
{
|
||||
limiter.countBytes( OBJECT_HEADER + Double.BYTES );
|
||||
value = input.readDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput output) throws IOException
|
||||
{
|
||||
output.writeDouble( value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getId()
|
||||
{
|
||||
return Tag.DOUBLE;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user