Extract bungee plugin message channel to constant
This commit is contained in:
@@ -22,19 +22,21 @@ import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
public class PluginMessage extends DefinedPacket
|
||||
{
|
||||
|
||||
public static final String BUNGEE_CHANNEL_LEGACY = "BungeeCord";
|
||||
public static final String BUNGEE_CHANNEL_MODERN = "bungeecord:main";
|
||||
public static final Function<String, String> MODERNISE = new Function<String, String>()
|
||||
{
|
||||
@Override
|
||||
public String apply(String tag)
|
||||
{
|
||||
// Transform as per Bukkit
|
||||
if ( tag.equals( "BungeeCord" ) )
|
||||
if ( tag.equals( PluginMessage.BUNGEE_CHANNEL_LEGACY ) )
|
||||
{
|
||||
return "bungeecord:main";
|
||||
return PluginMessage.BUNGEE_CHANNEL_MODERN;
|
||||
}
|
||||
if ( tag.equals( "bungeecord:main" ) )
|
||||
if ( tag.equals( PluginMessage.BUNGEE_CHANNEL_MODERN ) )
|
||||
{
|
||||
return "BungeeCord";
|
||||
return PluginMessage.BUNGEE_CHANNEL_LEGACY;
|
||||
}
|
||||
|
||||
// Code that gets to here is UNLIKELY to be viable on the Bukkit side of side things,
|
||||
|
@@ -9,8 +9,8 @@ public class PluginMessageTest
|
||||
@Test
|
||||
public void testModerniseChannel()
|
||||
{
|
||||
assertEquals( "bungeecord:main", PluginMessage.MODERNISE.apply( "BungeeCord" ) );
|
||||
assertEquals( "BungeeCord", PluginMessage.MODERNISE.apply( "bungeecord:main" ) );
|
||||
assertEquals( PluginMessage.BUNGEE_CHANNEL_MODERN, PluginMessage.MODERNISE.apply( PluginMessage.BUNGEE_CHANNEL_LEGACY ) );
|
||||
assertEquals( PluginMessage.BUNGEE_CHANNEL_LEGACY, PluginMessage.MODERNISE.apply( PluginMessage.BUNGEE_CHANNEL_MODERN ) );
|
||||
assertEquals( "legacy:foo", PluginMessage.MODERNISE.apply( "FoO" ) );
|
||||
assertEquals( "foo:bar", PluginMessage.MODERNISE.apply( "foo:bar" ) );
|
||||
}
|
||||
|
Reference in New Issue
Block a user