added the config file
This commit is contained in:
parent
28b8895675
commit
5993af255b
@ -4,4 +4,5 @@ Ever wanted to have your messages sent globally across your Velocity proxy? Here
|
|||||||
- No Setup, just Drag & Drop!
|
- No Setup, just Drag & Drop!
|
||||||
- LuckPerms Prefix Support
|
- LuckPerms Prefix Support
|
||||||
- Velocity 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
14
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>Vmessage</groupId>
|
<groupId>Vmessage</groupId>
|
||||||
<artifactId>Vmessage</artifactId>
|
<artifactId>Vmessage</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>Vmessage</name>
|
<name>Vmessage</name>
|
||||||
@ -160,11 +160,11 @@
|
|||||||
<version>3.1.1</version>
|
<version>3.1.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.luckperms</groupId>
|
<groupId>net.luckperms</groupId>
|
||||||
<artifactId>api</artifactId>
|
<artifactId>api</artifactId>
|
||||||
<version>5.4</version>
|
<version>5.4</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package me.feusalamander.vmessage;
|
package me.feusalamander.vmessage;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.moandjiezana.toml.Toml;
|
||||||
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
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.LuckPermsProvider;
|
||||||
import net.luckperms.api.model.user.User;
|
import net.luckperms.api.model.user.User;
|
||||||
import org.slf4j.Logger;
|
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;
|
import java.util.Objects;
|
||||||
@Plugin(
|
@Plugin(
|
||||||
id = "vmessage",
|
id = "vmessage",
|
||||||
name = "Vmessage",
|
name = "Vmessage",
|
||||||
version = "1.0",
|
version = "1.1",
|
||||||
description = "A velocity plugin that creates a multi server chat for the network",
|
description = "A velocity plugin that creates a multi server chat for the network",
|
||||||
authors = {"FeuSalamander"}
|
authors = {"FeuSalamander"}
|
||||||
)
|
)
|
||||||
public class vmessage {
|
public class vmessage {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private final ProxyServer proxy;
|
private final ProxyServer proxy;
|
||||||
@Inject
|
@Inject
|
||||||
@ -29,31 +35,63 @@ public class vmessage {
|
|||||||
@Inject
|
@Inject
|
||||||
private final Metrics.Factory metricsFactory;
|
private final Metrics.Factory metricsFactory;
|
||||||
@Inject
|
@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.proxy = proxy;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.metricsFactory = metricsFactory;
|
this.metricsFactory = metricsFactory;
|
||||||
|
this.dataDirectory = dataDirectory;
|
||||||
}
|
}
|
||||||
|
public String message = "";
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
logger.info("Vmessage by FeuSalamander is working !");
|
logger.info("Vmessage by FeuSalamander is working !");
|
||||||
Metrics metrics = metricsFactory.make(this, 16527);
|
Metrics metrics = metricsFactory.make(this, 16527);
|
||||||
|
createconfig();
|
||||||
|
message = getmessage("Message-format.format");
|
||||||
}
|
}
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onMessage(PlayerChatEvent e){
|
public void onMessage(PlayerChatEvent e){
|
||||||
proxy.getAllServers().stream().forEach(registeredServer -> sendMessage(registeredServer, e.getPlayer(), e.getMessage()));
|
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(!(Objects.equals(p.getCurrentServer().get().getServerInfo().getName(), s.getServerInfo().getName()))){
|
||||||
if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){
|
if(proxy.getPluginManager().getPlugin("luckperms").isPresent()){
|
||||||
LuckPerms api = LuckPermsProvider.get();
|
LuckPerms api = LuckPermsProvider.get();
|
||||||
User user = api.getPlayerAdapter(Player.class).getUser(p);
|
User user = api.getPlayerAdapter(Player.class).getUser(p);
|
||||||
String f = user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§");
|
message = message.replaceAll("#prefix#", user.getCachedData().getMetaData().getPrefix().replaceAll("&", "§"));
|
||||||
s.sendMessage(Component.text("§a("+p.getCurrentServer().get().getServerInfo().getName()+") "+f+" "+p.getUsername()+" §8§l> §r"+m));
|
s.sendMessage(Component.text(message));
|
||||||
|
message = getmessage("Message-format.format");
|
||||||
}else{
|
}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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
7
src/main/resources/config.toml
Normal file
7
src/main/resources/config.toml
Normal 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#"
|
Loading…
Reference in New Issue
Block a user