more implemtaions
This commit is contained in:
parent
4d19f68a28
commit
a5d0613c69
@ -0,0 +1,28 @@
|
||||
package net.limework.gal.utils;
|
||||
|
||||
import net.limework.gal.utils.config.Configuration;
|
||||
|
||||
public class PlayerNamesUtils {
|
||||
|
||||
|
||||
public static boolean isCrackedPlayer(String username, Configuration configuration) {
|
||||
if (configuration.useTheContainMethod()) {
|
||||
return username.contains(configuration.getCrackedCharString());
|
||||
} else {
|
||||
return username.charAt(0) == configuration.getCrackedChar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getCorrectCrackedUsername(String username, Configuration configuration) {
|
||||
if (configuration.doReplaceSpacesWithUnderscore()) {
|
||||
username = username.replace(" ", "_");
|
||||
}
|
||||
if (username.length() >= 16) {
|
||||
username = username.substring(0, 15);
|
||||
}
|
||||
return username;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package net.limework.gal.utils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerUUIDUtils {
|
||||
|
||||
// source -> https://www.spigotmc.org/threads/how-uuid-is-generated-for-offline-mode-nicknames.347835/
|
||||
public static UUID getCrackedPlayerUUIDByName(String name) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
}
|
@ -2,8 +2,12 @@ package net.limework.gal.utils.config;
|
||||
|
||||
public interface Configuration {
|
||||
|
||||
String getCrackedChar();
|
||||
char getCrackedChar();
|
||||
String getCrackedCharString();
|
||||
|
||||
boolean doReplaceSpacesWithUnderscore();
|
||||
|
||||
boolean useTheContainMethod();
|
||||
|
||||
AntiBot getAntiBot();
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
{
|
||||
"default-cracked-char": "-",
|
||||
"replace-spaces-with-underscore": true,
|
||||
"use-the-contain-method": false,
|
||||
"simple-anti-bot": {
|
||||
"max-connections": 590,
|
||||
"reset": 10
|
||||
|
@ -4,13 +4,34 @@
|
||||
# Ham1255 is a cracked player want to join mc.limework.net
|
||||
# when system checks if he is cracked then if the name does not contain -
|
||||
# system will replace the name to -Ham1255
|
||||
# Default: "-"
|
||||
# Warning: if you put more than 1 character it will use the first one and the rest is ignored.
|
||||
default-cracked-char: "-"
|
||||
|
||||
|
||||
# if the cracked player name is like this
|
||||
# Ham 1255 system will convert it to Ham_1255
|
||||
# Default: true
|
||||
replace-spaces-with-underscore: true
|
||||
|
||||
|
||||
# Notice:
|
||||
# I don't recommend using this. -ham1255
|
||||
# Example:
|
||||
# true: when joining it checks the whole username if it has Cracked character or not!
|
||||
# so Players who has - in middle or else like this:
|
||||
# [ Ham-1255 Ham1255- Ha-m1255 -Ham1255 ] will work
|
||||
# in java syntax: .contains(DEFAULT_CRACKED_CHAR)
|
||||
# false: when joining it checks the first character if its
|
||||
use-the-contain-method: false
|
||||
|
||||
# Just simple anti bot
|
||||
# example:
|
||||
# when a player joins a server it makes request to mojang api which has 600 per 10 mins
|
||||
# when a player joins a server it makes request to mojang api which has 600 per 10 minutes
|
||||
# if the server reach's the limits players can no longer join + possibility of getting banned by mojang api for a day!
|
||||
# default:
|
||||
# max: 590
|
||||
# reset: 10
|
||||
simple-anti-bot:
|
||||
max-connections: 590
|
||||
reset: 10
|
||||
|
@ -18,6 +18,27 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -12,21 +12,40 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ConfigLoader implements Configuration {
|
||||
|
||||
private final String crackedChar;
|
||||
private final char crackedChar;
|
||||
private final boolean replaceSpacesWithUnderscore;
|
||||
private final boolean useTheContainMethod;
|
||||
private final AntiBot antiBot;
|
||||
|
||||
public ConfigLoader(File file) throws FileNotFoundException {
|
||||
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
|
||||
this.crackedChar = jsonObject.get("default-cracked-char").getAsString();
|
||||
this.crackedChar = (jsonObject.get("default-cracked-char").getAsString().charAt(0));
|
||||
this.replaceSpacesWithUnderscore = jsonObject.get("replace-spaces-with-underscore").getAsBoolean();
|
||||
this.useTheContainMethod = jsonObject.get("use-the-contain-method").getAsBoolean();
|
||||
JsonObject antiBotJson = jsonObject.getAsJsonObject("simple-anti-bot");
|
||||
this.antiBot = new AntiBot(antiBotJson.get("max-connections").getAsInt(), antiBotJson.get("reset").getAsLong(), TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCrackedChar() {
|
||||
public char getCrackedChar() {
|
||||
return this.crackedChar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCrackedCharString() {
|
||||
return String.valueOf(this.crackedChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doReplaceSpacesWithUnderscore() {
|
||||
return this.replaceSpacesWithUnderscore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useTheContainMethod() {
|
||||
return this.useTheContainMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AntiBot getAntiBot() {
|
||||
return this.antiBot;
|
||||
|
@ -1,19 +1,31 @@
|
||||
package net.limework.gal;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Continuation;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.PreLoginEvent;
|
||||
import com.velocitypowered.api.event.player.GameProfileRequestEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import net.limework.gal.utils.config.Configuration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static net.limework.gal.utils.PlayerUUIDUtils.*;
|
||||
import static net.limework.gal.utils.PlayerNamesUtils.*;
|
||||
@Plugin(name = "GreenAppleLogin", id = "greenapplelogin", version = "1.0.0", description = "Plugin that handle cracked + premium")
|
||||
public class VelocityGalPlugin {
|
||||
|
||||
@ -49,6 +61,31 @@ public class VelocityGalPlugin {
|
||||
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitializeEvent(ProxyInitializeEvent event) {
|
||||
//this.proxyServer.getEventManager().register(this, this);
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onPreLoginEvent(PreLoginEvent event) {
|
||||
if (isCrackedPlayer(event.getUsername(), config)){
|
||||
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
|
||||
}else {
|
||||
event.setResult(PreLoginEvent.PreLoginComponentResult.forceOnlineMode());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameProfileRequestEvent(GameProfileRequestEvent event) {
|
||||
if (!event.isOnlineMode()) {
|
||||
logger.info("handling " + event.getUsername());
|
||||
String username = getCorrectCrackedUsername(event.getUsername(), config);
|
||||
logger.info("new username -> " + username);
|
||||
List<GameProfile.Property> properties = event.getGameProfile().getProperties();
|
||||
UUID uuid = getCrackedPlayerUUIDByName(username);
|
||||
event.setGameProfile(new GameProfile(uuid, username, properties));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ProxyServer getProxyServer() {
|
||||
|
Loading…
Reference in New Issue
Block a user