Skip to content

Commit

Permalink
support velocity 3
Browse files Browse the repository at this point in the history
  • Loading branch information
weaondara committed Oct 21, 2021
1 parent 205a996 commit b14e36d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 37 deletions.
58 changes: 57 additions & 1 deletion pom.xml
Expand Up @@ -91,6 +91,56 @@
<url>file://${project.basedir}/lib/repository/</url>
</repository>
</repositories>
<profiles>
<profile>
<id>java9plus</id>
<activation>
<jdk>[1.9,)</jdk>
</activation>
<properties>
<maven.compiler.release>8</maven.compiler.release>
</properties>
</profile>
<profile>
<id>java11plus</id>
<activation>
<jdk>[1.11,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<fork>true</fork>
<compilerArgs>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<argLine>
--illegal-access=permit
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<finalName>${build.name}</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
Expand Down Expand Up @@ -327,7 +377,7 @@
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down Expand Up @@ -387,5 +437,11 @@
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.8.1</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
Expand Up @@ -21,11 +21,11 @@
import net.alpenblock.bungeeperms.BungeePerms;
import net.alpenblock.bungeeperms.ChatColor;
import net.alpenblock.bungeeperms.platform.MessageEncoder;
import net.kyori.text.Component;
import net.kyori.text.ComponentBuilder;
import net.kyori.text.TextComponent;
import net.kyori.text.format.TextColor;
import net.kyori.text.format.TextDecoration;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentBuilder;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;

public class VelocityMessageEncoder extends MessageEncoder
{
Expand All @@ -42,7 +42,7 @@ public static BaseComponent[] convert(Component components)

public static Component convert(BaseComponent[] components)
{
Component ret = TextComponent.empty();
Component ret = Component.text("");
List<Component> children = new ArrayList(components.length);
for (int i = 0; i < components.length; i++)
{
Expand Down Expand Up @@ -80,7 +80,7 @@ public VelocityMessageEncoder(String text)
super(text);
if (BungeePerms.getInstance().getPlugin().isChatApiPresent())
{
builder = TextComponent.builder(text);
builder = Component.text().content(text);
}

list = new ArrayList<>();
Expand All @@ -93,7 +93,7 @@ public MessageEncoder append(String text)
if (BungeePerms.getInstance().getPlugin().isChatApiPresent())
{
cache = null;
builder = builder.append(text);
builder = builder.append(Component.text(text));
}

list.add(current);
Expand All @@ -108,7 +108,7 @@ public MessageEncoder color(ChatColor color)
if (BungeePerms.getInstance().getPlugin().isChatApiPresent())
{
cache = null;
builder = builder.color(TextColor.valueOf(color.name()));
builder = builder.color(NamedTextColor.NAMES.value(color.name()));
}

current = color + current;
Expand Down Expand Up @@ -230,8 +230,8 @@ public MessageEncoder event(ClickEvent clickEvent)
else
{
cache = null;
net.kyori.text.event.ClickEvent.Action action = net.kyori.text.event.ClickEvent.Action.valueOf(clickEvent.getAction().name());
builder = builder.clickEvent(net.kyori.text.event.ClickEvent.of(action, clickEvent.getValue()));
net.kyori.adventure.text.event.ClickEvent.Action action = net.kyori.adventure.text.event.ClickEvent.Action.valueOf(clickEvent.getAction().name());
builder = builder.clickEvent(net.kyori.adventure.text.event.ClickEvent.clickEvent(action, clickEvent.getValue()));
}
}

Expand All @@ -250,8 +250,8 @@ public MessageEncoder event(HoverEvent hoverEvent)
else
{
cache = null;
net.kyori.text.event.HoverEvent.Action action = net.kyori.text.event.HoverEvent.Action.valueOf(hoverEvent.getAction().name());
builder = builder.hoverEvent(net.kyori.text.event.HoverEvent.of(action, convert(hoverEvent.getValue().create())));
net.kyori.adventure.text.event.HoverEvent.Action action = net.kyori.adventure.text.event.HoverEvent.Action.NAMES.value(hoverEvent.getAction().name());
builder = builder.hoverEvent(net.kyori.adventure.text.event.HoverEvent.hoverEvent(action, convert(hoverEvent.getValue().create())));
}
}

Expand Down
Expand Up @@ -24,7 +24,8 @@
import net.alpenblock.bungeeperms.PermissionsChecker;
import net.alpenblock.bungeeperms.User;
import net.alpenblock.bungeeperms.platform.proxy.ProxyConfig;
import net.kyori.text.TextComponent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;

@AllArgsConstructor
public class VelocityPermissionsChecker extends PermissionsChecker
Expand Down Expand Up @@ -195,14 +196,14 @@ public boolean has(CommandSource sender, String perm, boolean msg)
boolean isperm = (hasPerm(sender, perm));
if (!isperm && msg)
{
TextComponent t = TextComponent.builder().content(Lang.translate(Lang.MessageType.NO_PERM)).build();
Component t = Component.text(Lang.translate(Lang.MessageType.NO_PERM));
sender.sendMessage(t);
}
return isperm;
}
else
{
TextComponent t = TextComponent.builder().content(Lang.translate(Lang.MessageType.NO_PERM)).build();
Component t = Component.text(Lang.translate(Lang.MessageType.NO_PERM));
sender.sendMessage(t);
return false;
}
Expand All @@ -221,7 +222,7 @@ public boolean hasOrConsole(CommandSource sender, String perm, boolean msg)
boolean isperm = hasPerm(sender, perm) || new VelocitySender(sender).isConsole();
if (!isperm && msg)
{
TextComponent t = TextComponent.builder().content(Lang.translate(Lang.MessageType.NO_PERM)).build();
Component t = Component.text(Lang.translate(Lang.MessageType.NO_PERM));
sender.sendMessage(t);
}
return isperm;
Expand All @@ -242,14 +243,14 @@ public boolean hasOnServer(CommandSource sender, String perm, boolean msg)
boolean isperm = hasPermOnServer(sender, perm);
if (!isperm && msg)
{
TextComponent t = TextComponent.builder().content(Lang.translate(Lang.MessageType.NO_PERM)).build();
Component t = Component.text(Lang.translate(Lang.MessageType.NO_PERM));
sender.sendMessage(t);
}
return isperm;
}
else
{
TextComponent t = TextComponent.builder().content(Lang.translate(Lang.MessageType.NO_PERM)).build();
Component t = Component.text(Lang.translate(Lang.MessageType.NO_PERM));
sender.sendMessage(t);
return false;
}
Expand All @@ -268,7 +269,7 @@ public boolean hasOrConsoleOnServer(CommandSource sender, String perm, boolean m
boolean isperm = hasPermOnServer(sender, perm) || new VelocitySender(sender).isConsole();
if (!isperm && msg)
{
TextComponent t = TextComponent.builder().content(Lang.translate(Lang.MessageType.NO_PERM)).build();
Component t = Component.text(Lang.translate(Lang.MessageType.NO_PERM));
sender.sendMessage(t);
}
return isperm;
Expand All @@ -289,14 +290,14 @@ public boolean hasOnServerInWorld(CommandSource sender, String perm, boolean msg
boolean isperm = hasPermOnServerInWorld(sender, perm);
if (!isperm && msg)
{
TextComponent t = TextComponent.builder().content(Lang.translate(Lang.MessageType.NO_PERM)).build();
Component t = Component.text(Lang.translate(Lang.MessageType.NO_PERM));
sender.sendMessage(t);
}
return isperm;
}
else
{
TextComponent t = TextComponent.builder().content(Lang.translate(Lang.MessageType.NO_PERM)).build();
Component t = Component.text(Lang.translate(Lang.MessageType.NO_PERM));
sender.sendMessage(t);
return false;
}
Expand All @@ -315,7 +316,7 @@ public boolean hasOrConsoleOnServerInWorld(CommandSource sender, String perm, bo
boolean isperm = hasPermOnServerInWorld(sender, perm) || new VelocitySender(sender).isConsole();
if (!isperm && msg)
{
TextComponent t = TextComponent.builder().content(Lang.translate(Lang.MessageType.NO_PERM)).build();
Component t = Component.text(Lang.translate(Lang.MessageType.NO_PERM));
sender.sendMessage(t);
}
return isperm;
Expand Down
Expand Up @@ -19,6 +19,7 @@
import com.google.inject.Inject;
import com.velocitypowered.api.command.Command;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
Expand All @@ -34,12 +35,10 @@
import java.io.File;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import net.alpenblock.bungeeperms.BungeePerms;
import net.alpenblock.bungeeperms.Color;
import net.alpenblock.bungeeperms.Config;
Expand All @@ -53,7 +52,7 @@
import net.alpenblock.bungeeperms.platform.ScheduledTask;
import net.alpenblock.bungeeperms.platform.Sender;
import net.alpenblock.bungeeperms.platform.proxy.ProxyConfig;
import net.kyori.text.TextComponent;
import net.kyori.adventure.text.Component;

@Plugin(id = "bungeeperms", name = "BungeePerms", version = "@version@", authors =
{
Expand Down Expand Up @@ -164,7 +163,7 @@ public List<String> onTabComplete(CommandSource sender, Command cmd, String labe
private void loadcmds()
{
CmdExec cmd = new CmdExec("bungeeperms", null, config.isAliasCommand() ? Statics.array("bp") : new String[0]);
proxyServer.getCommandManager().register(cmd, config.isAliasCommand() ? Statics.array("bp") : new String[0]);
proxyServer.getCommandManager().register("bungeeperms", cmd, config.isAliasCommand() ? Statics.array("bp") : new String[0]);
}

//plugin info
Expand Down Expand Up @@ -308,24 +307,24 @@ private void startMetrics()
}
}

private class CmdExec implements Command
private class CmdExec implements SimpleCommand
{

public CmdExec(String name, String permission, String... aliases)
{
}

@Override
public void execute(final CommandSource sender, final String[] args)
public void execute(Invocation invocation)
{
final Command cmd = this;
Runnable r = new Runnable()
{
@Override
public void run()
{
if (!VelocityPlugin.this.onCommand(sender, cmd, "", args))
sender.sendMessage(TextComponent.of(Color.Error + "[BungeePerms] " + Lang.translate(Lang.MessageType.COMMAND_NOT_FOUND)));
if (!VelocityPlugin.this.onCommand(invocation.source(), cmd, "", invocation.arguments()))
invocation.source().sendMessage(Component.text(Color.Error + "[BungeePerms] " + Lang.translate(Lang.MessageType.COMMAND_NOT_FOUND)));
}
};
if (config.isAsyncCommands())
Expand All @@ -335,9 +334,9 @@ public void run()
}

@Override
public List<String> suggest(CommandSource sender, String[] args)
public List<String> suggest(Invocation invocation)
{
return VelocityPlugin.this.onTabComplete(sender, this, "", args);
return VelocityPlugin.this.onTabComplete(invocation.source(), this, "", invocation.arguments());
}
}

Expand Down
Expand Up @@ -25,8 +25,7 @@
import net.alpenblock.bungeeperms.BungeePerms;
import net.alpenblock.bungeeperms.platform.MessageEncoder;
import net.alpenblock.bungeeperms.platform.Sender;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.adventure.text.Component;

@Getter
@AllArgsConstructor
Expand All @@ -40,7 +39,7 @@ public void sendMessage(String message)
{
if (message.replaceAll("&.", "").replaceAll("§.", "").trim().isEmpty())
return;
TextComponent t = TextComponent.builder().content(message).build();
Component t = Component.text(message);
sender.sendMessage(t);
}

Expand Down

0 comments on commit b14e36d

Please sign in to comment.