new diclaimer message

This commit is contained in:
mohammed jasem alaajel 2023-03-25 14:22:01 +04:00
parent 6c1699b2c5
commit 43c3edf5c6
No known key found for this signature in database
5 changed files with 40 additions and 7 deletions

View File

@ -3,8 +3,8 @@ package net.limework.gal.utils;
/** /**
* @since 1.0.0 * @since 1.0.0
* *
* @// TODO: 12/14/21 move the messages into A Config file in yaml or json
*/ */
@Deprecated
public class Messages { public class Messages {
// //
public final static String FAILED_CONNECTION = """ public final static String FAILED_CONNECTION = """

View File

@ -15,6 +15,8 @@ public interface Configuration {
String getOnlineModeDomain(); String getOnlineModeDomain();
String[] getDisclaimerMessage();

View File

@ -7,5 +7,13 @@
"max-connections": 590, "max-connections": 590,
"reset": 10 "reset": 10
}, },
"online-mode-domain": "p.limework.net" "online-mode-domain": "p.limework.net",
"disclaimer-message": [
"§e=======================================",
"§eHi there, welcome to §a§LGovindas Limework",
"§eYou are logged in As Offline player and identified as %player-name%",
"§eif this a mistake please disconnect and connect to",
"§ep.limework.net",
"§e======================================="
]
} }

View File

@ -8,6 +8,7 @@ import net.limework.gal.utils.config.Configuration;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class ConfigLoader implements Configuration { public class ConfigLoader implements Configuration {
@ -19,6 +20,8 @@ public class ConfigLoader implements Configuration {
private final AntiBot antiBot; private final AntiBot antiBot;
private final String onlineModeDomain; private final String onlineModeDomain;
private final String[] disclaimerMessage;
public ConfigLoader(File file) throws FileNotFoundException { public ConfigLoader(File file) throws FileNotFoundException {
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject(); JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
this.crackedChar = (jsonObject.get("default-cracked-char").getAsString().charAt(0)); this.crackedChar = (jsonObject.get("default-cracked-char").getAsString().charAt(0));
@ -28,6 +31,11 @@ public class ConfigLoader implements Configuration {
JsonObject antiBotJson = jsonObject.getAsJsonObject("simple-anti-bot"); JsonObject antiBotJson = jsonObject.getAsJsonObject("simple-anti-bot");
this.antiBot = new AntiBot(antiBotJson.get("max-connections").getAsInt(), antiBotJson.get("reset").getAsLong(), TimeUnit.MINUTES); this.antiBot = new AntiBot(antiBotJson.get("max-connections").getAsInt(), antiBotJson.get("reset").getAsLong(), TimeUnit.MINUTES);
this.onlineModeDomain = jsonObject.get("online-mode-domain").getAsString(); this.onlineModeDomain = jsonObject.get("online-mode-domain").getAsString();
ArrayList<String> message = new ArrayList<>();
jsonObject.getAsJsonArray("disclaimer-message").forEach((element) -> {
message.add(element.getAsString());
});
disclaimerMessage = message.toArray(new String[0]);
} }
@Override @Override
@ -65,4 +73,8 @@ public class ConfigLoader implements Configuration {
return this.onlineModeDomain; return this.onlineModeDomain;
} }
@Override
public String[] getDisclaimerMessage() {
return this.disclaimerMessage;
}
} }

View File

@ -1,6 +1,7 @@
package net.limework.gal; package net.limework.gal;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.internal.Messages;
import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.PostLoginEvent; import com.velocitypowered.api.event.connection.PostLoginEvent;
@ -12,7 +13,8 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.GameProfile;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.limework.gal.utils.Messages; import net.kyori.adventure.text.ComponentBuilder;
import net.kyori.adventure.text.TextComponent;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -20,9 +22,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.*;
import java.util.Objects;
import java.util.UUID;
import java.util.logging.Logger; import java.util.logging.Logger;
import static net.limework.gal.utils.PlayerUUIDUtils.*; import static net.limework.gal.utils.PlayerUUIDUtils.*;
@ -94,9 +94,20 @@ public class VelocityGalPlugin {
@Subscribe @Subscribe
public void onPostLoginEvent(PostLoginEvent event) { public void onPostLoginEvent(PostLoginEvent event) {
if (isCrackedPlayer(event.getPlayer().getUsername(), this.config)) { if (isCrackedPlayer(event.getPlayer().getUsername(), this.config)) {
event.getPlayer().sendMessage(Component.text(Messages.cracked_disclaimer)); event.getPlayer().sendMessage(getDisclaimerMessage(event.getPlayer().getUsername()));
} }
} }
private Component getDisclaimerMessage(String playerName) {
List<String> messages = Arrays.stream(config.getDisclaimerMessage()).toList();
Component component = Component.text("");
for (String message : messages) {
message = message.replace("%player-name%", playerName);
System.out.println(message);
component = component.append(Component.text(message)).append(Component.newline());
}
return component;
}
public ProxyServer getProxyServer() { public ProxyServer getProxyServer() {
return proxyServer; return proxyServer;
} }