added the config file

This commit is contained in:
FeuSalamander 2022-09-30 17:17:50 +02:00
parent 28b8895675
commit 5993af255b
4 changed files with 62 additions and 16 deletions

View File

@ -4,4 +4,5 @@ Ever wanted to have your messages sent globally across your Velocity proxy? Here
- No Setup, just Drag & Drop!
- LuckPerms Prefix Support
- Velocity Support
- (thanks @JosTheDude for the description)
- (thanks @JosTheDude for the description)
- You can also check my Bukkit plugin https://github.com/FeuSalamander/MiniWalls

14
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>Vmessage</groupId>
<artifactId>Vmessage</artifactId>
<version>1.0</version>
<version>1.1</version>
<packaging>jar</packaging>
<name>Vmessage</name>
@ -160,11 +160,11 @@
<version>3.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,9 +1,11 @@
package me.feusalamander.vmessage;
import com.google.inject.Inject;
import com.moandjiezana.toml.Toml;
import com.velocitypowered.api.event.player.PlayerChatEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.RegisteredServer;
@ -12,16 +14,20 @@ import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.model.user.User;
import org.slf4j.Logger;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
@Plugin(
id = "vmessage",
name = "Vmessage",
version = "1.0",
version = "1.1",
description = "A velocity plugin that creates a multi server chat for the network",
authors = {"FeuSalamander"}
)
public class vmessage {
@Inject
private final ProxyServer proxy;
@Inject
@ -29,31 +35,63 @@ public class vmessage {
@Inject
private final Metrics.Factory metricsFactory;
@Inject
public vmessage(ProxyServer proxy, Logger logger, Metrics.Factory metricsFactory) {
private final @DataDirectory Path dataDirectory;
@Inject
public vmessage(ProxyServer proxy, Logger logger, Metrics.Factory metricsFactory, @DataDirectory Path dataDirectory) {
this.proxy = proxy;
this.logger = logger;
this.metricsFactory = metricsFactory;
this.dataDirectory = dataDirectory;
}
public String message = "";
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
logger.info("Vmessage by FeuSalamander is working !");
Metrics metrics = metricsFactory.make(this, 16527);
createconfig();
message = getmessage("Message-format.format");
}
@Subscribe
public void onMessage(PlayerChatEvent e){
proxy.getAllServers().stream().forEach(registeredServer -> sendMessage(registeredServer, e.getPlayer(), e.getMessage()));
}
public void sendMessage(RegisteredServer s, Player p, String m){
private void sendMessage(RegisteredServer s, Player p, String m){
message = message.replaceAll("#player#", p.getUsername());
message = message.replaceAll("#message#",m);
message = message.replaceAll("#server#",p.getCurrentServer().get().getServerInfo().getName());
message = message.replaceAll("&", "§");
if(!(Objects.equals(p.getCurrentServer().get().getServerInfo().getName(), s.getServerInfo().getName()))){
if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){
LuckPerms api = LuckPermsProvider.get();
User user = api.getPlayerAdapter(Player.class).getUser(p);
String f = user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§");
s.sendMessage(Component.text("§a("+p.getCurrentServer().get().getServerInfo().getName()+") "+f+" "+p.getUsername()+" §8§l> §r"+m));
message = message.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§"));
s.sendMessage(Component.text(message));
message = getmessage("Message-format.format");
}else{
s.sendMessage(Component.text("§a("+p.getCurrentServer().get().getServerInfo().getName()+") "+"§r "+p.getUsername()+" §8§l> §r"+m));
s.sendMessage(Component.text(message));
message = getmessage("Message-format.format");
}
}
}
private void createconfig(){
File dataDirectoryFile = this.dataDirectory.toFile();
if (!dataDirectoryFile.exists()){
dataDirectoryFile.mkdir();
}
File f = new File(dataDirectoryFile, "config.toml");
if(!(f.exists())){
try{
InputStream file = this.getClass().getResourceAsStream("/config.toml");
Files.copy(file, f.toPath());
}catch (IOException e){
e.printStackTrace();
}
}
}
private String getmessage(String s){
File directory = dataDirectory.toFile();
File f = new File(directory, "config.toml");
Toml config = new Toml().read(f);
return config.getString(s);
}
}

View File

@ -0,0 +1,7 @@
[Message-format]
#place holders:
#- "#player#" : return the player name
#- "#prefix#" : return the player's luckperms prefix (don't place it if you don't have luckperms on your server)
#- "#message#" : return the player's message
#- "#server#" : return the player's server name
format = "§a(#server#) #prefix# #player# §8§l> §r#message#"