Skip to content

Commit

Permalink
added the commands
Browse files Browse the repository at this point in the history
  • Loading branch information
FeuSalamander committed May 10, 2023
1 parent c0d3bc7 commit 75da02b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 33 deletions.
18 changes: 4 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>Vmessage</groupId>
<artifactId>Vmessage</artifactId>
<version>1.5.3</version>
<version>1.5.4</version>
<packaging>jar</packaging>

<name>Vmessage</name>
Expand All @@ -25,7 +25,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -38,7 +38,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.1</version>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down Expand Up @@ -141,7 +141,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version>
<version>3.2.0</version>
</plugin>
</plugins>
</reporting>
Expand All @@ -151,10 +151,6 @@
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -170,11 +166,5 @@
<version>5.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.william278</groupId>
<artifactId>PAPIProxyBridge</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
27 changes: 27 additions & 0 deletions src/main/java/me/feusalamander/vmessage/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;

public final class Configuration {
Expand All @@ -21,6 +22,10 @@ public final class Configuration {
private boolean all;
private Toml config;
private static File file;
private List<String> messagecmd;
private List<String> joincmd;
private List<String> leavecmd;
private List<String> changecmd;

Configuration(Toml config) {
messageFormat = config.getString("Message.format", "");
Expand All @@ -33,6 +38,11 @@ public final class Configuration {
leaveEnabled = config.getBoolean("Leave.enabled", false);
changeEnabled = config.getBoolean("Server-change.enabled", false);

messagecmd = config.getList("Message.commands");
joincmd = config.getList("Join.commands");
leavecmd = config.getList("Leave.commands");
changecmd = config.getList("Server-change.commands");

minimessage = config.getBoolean("Message-format.minimessage");
all = config.getBoolean("Message.all", false);
this.config = config;
Expand Down Expand Up @@ -103,6 +113,18 @@ public boolean isMinimessageEnabled(){
public boolean isAllEnabled(){
return this.all;
}
public List<String> getMessagecmd(){
return this.messagecmd;
}
public List<String> getJoincmd(){
return this.joincmd;
}
public List<String> getLeavecmd(){
return this.leavecmd;
}
public List<String> getChangecmd(){
return this.changecmd;
}
void reload(){
config = config.read(file);
this.messageFormat = config.getString("Message.format");
Expand All @@ -115,6 +137,11 @@ void reload(){
this.leaveEnabled = config.getBoolean("Leave.enabled");
this.changeEnabled = config.getBoolean("Server-change.enabled");

messagecmd = config.getList("Message.commands");
joincmd = config.getList("Join.commands");
leavecmd = config.getList("Leave.commands");
changecmd = config.getList("Server-change.commands");

this.minimessage = config.getBoolean("Message-format.minimessage");
all = config.getBoolean("Message.all", false);
}
Expand Down
22 changes: 4 additions & 18 deletions src/main/java/me/feusalamander/vmessage/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.cacheddata.CachedMetaData;
import net.william278.papiproxybridge.api.PlaceholderAPI;
import net.william278.papiproxybridge.user.OnlineUser;

import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;

@SuppressWarnings({"UnstableApiUsage", "deprecation"})
public final class Listeners {
Expand All @@ -30,17 +26,13 @@ public final class Listeners {
.build();
public static final MiniMessage mm = MiniMessage.miniMessage();
private LuckPerms luckPermsAPI;
private PlaceholderAPI placeholderAPI;
private final Configuration configuration;
private final ProxyServer proxyServer;

Listeners(final ProxyServer proxyServer, final Configuration configuration) {
if (proxyServer.getPluginManager().getPlugin("luckperms").isPresent()) {
this.luckPermsAPI = LuckPermsProvider.get();
}
if (proxyServer.getPluginManager().getPlugin("papiproxybridge").isPresent()) {
this.placeholderAPI = PlaceholderAPI.getInstance();
}
this.configuration = configuration;
this.proxyServer = proxyServer;
}
Expand All @@ -59,13 +51,13 @@ private void onLeave(final DisconnectEvent e) {
if (!configuration.isLeaveEnabled()) {
return;
}
if(!configuration.getLeavecmd().isEmpty())for(String s : configuration.getLeavecmd()){proxyServer.getCommandManager().executeAsync(proxyServer.getConsoleCommandSource(), s);}
final Player p = e.getPlayer();
final Optional<ServerConnection> server = p.getCurrentServer();
if (server.isEmpty()) {
return;
}
String message = configuration.getLeaveFormat();
message = placeholder(message, p);
message = message
.replace("#player#", p.getUsername())
.replace("#oldserver#", server.get().getServerInfo().getName());
Expand All @@ -91,9 +83,9 @@ private void onChange(final ServerPostConnectEvent e) {
if (!configuration.isChangeEnabled()) {
return;
}
if(!configuration.getChangecmd().isEmpty())for(String s : configuration.getChangecmd()){proxyServer.getCommandManager().executeAsync(proxyServer.getConsoleCommandSource(), s);}
final ServerConnection actual = serverConnection.get();
String message = configuration.getChangeFormat();
message = placeholder(message, p);
message = message
.replace("#player#", p.getUsername())
.replace("#oldserver#", pre.getServerInfo().getName())
Expand All @@ -110,8 +102,8 @@ private void onChange(final ServerPostConnectEvent e) {
if (!configuration.isJoinEnabled()) {
return;
}
if(!configuration.getJoincmd().isEmpty())for(String s : configuration.getJoincmd()){proxyServer.getCommandManager().executeAsync(proxyServer.getConsoleCommandSource(), s);}
String message = configuration.getJoinFormat();
message = placeholder(message, p);
message = message
.replace("#player#", p.getUsername())
.replace("#server#", serverConnection.get().getServerInfo().getName());
Expand All @@ -138,16 +130,10 @@ private String luckperms(String message, final Player p) {
message = message.replace("#prefix#", "").replace("#suffix#", "");
return message;
}
private String placeholder(String message, final Player player){
if(placeholderAPI == null)return message;
UUID p = player.getUniqueId();
placeholderAPI.formatPlaceholders("Hello %player_name%!", p).thenAccept(formatedd -> {proxyServer.sendMessage(Component.text("test: "+formatedd));});
return message;
}
public void message(final Player p, final String m) {
if(!configuration.getMessagecmd().isEmpty())for(String s : configuration.getMessagecmd()){proxyServer.getCommandManager().executeAsync(proxyServer.getConsoleCommandSource(), s);}
final boolean permission = p.hasPermission("vmessage.minimessage");
String message = configuration.getMessageFormat();
message = placeholder(message, p);
message = message
.replace("#player#", p.getUsername())
.replace("#server#", p.getCurrentServer().orElseThrow().getServerInfo().getName());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/feusalamander/vmessage/VMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Plugin(
id = "vmessage",
name = "Vmessage",
version = "1.5.3",
version = "1.5.4",
description = "A velocity plugin that creates a multi server chat for the network",
authors = {"FeuSalamander"},
dependencies = {
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ minimessage = false
#- "#server#" : return the player's server name
format = "&a(#server#) #prefix# #player# &8&l> &r#message#"
all = false #if the formated message is sent even in the server where the player is located (can cause some issues with other plugins)
commands = []
enabled = true
[Join]
#place holders:
Expand All @@ -19,6 +20,7 @@ enabled = true
#- "#prefix#" : return the player's luckperms prefix
#- "#suffix#" : return the player's luckperms suffix
format = "&7#prefix# #player# &ejoined &7#server#"
commands = [] #The proxy commands which are executed (no / in the commands)
enabled = true
[Leave]
#place holders:
Expand All @@ -27,6 +29,7 @@ enabled = true
#- "#prefix#" : return the player's luckperms prefix
#- "#suffix#" : return the player's luckperms suffix
format = "#&7prefix# #player# &eleft &7#oldserver#"
commands = []
enabled = true
[Server-change]
#place holders:
Expand All @@ -36,4 +39,5 @@ enabled = true
#- "#oldserver#" : return the previous player's server name
#- "#server#" : return the new player's server name
format = "&7#prefix# #player# &eleft &c#oldserver# &eto join &a#server#"
commands = []
enabled = true

0 comments on commit 75da02b

Please sign in to comment.