diff --git a/README.md b/README.md index bbbaef68..8769201e 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ Now even lighter and faster than before! - 20+ supported languages and more to come # Installation +Tested with java-17-openjdk + ```shell script git clone https://github.com/lenis0012/LoginSecurity-2.git LoginSecurity cd LoginSecurity diff --git a/src/main/java/com/lenis0012/bukkit/loginsecurity/LoginSecurityConfig.java b/src/main/java/com/lenis0012/bukkit/loginsecurity/LoginSecurityConfig.java index dbc1c276..5eaad09e 100644 --- a/src/main/java/com/lenis0012/bukkit/loginsecurity/LoginSecurityConfig.java +++ b/src/main/java/com/lenis0012/bukkit/loginsecurity/LoginSecurityConfig.java @@ -61,6 +61,12 @@ public class LoginSecurityConfig extends AbstractConfig { }) @ConfigKey(path = "join.hide-inventory-safe") private boolean hideInventory = false; + @ConfigHeader({ + "Teleport player that have just issued a valid registeration command to a specific location. Leave empty to disable.", + "Example valid value is \"-123.3,75,34.3\" expressed as x,y,z coordinates", + }) + @ConfigKey(path = "join.register.location") + private String joinRegisterLocation = ""; /** * Username settings. diff --git a/src/main/java/com/lenis0012/bukkit/loginsecurity/commands/CommandRegister.java b/src/main/java/com/lenis0012/bukkit/loginsecurity/commands/CommandRegister.java index 16fe886e..f1763495 100644 --- a/src/main/java/com/lenis0012/bukkit/loginsecurity/commands/CommandRegister.java +++ b/src/main/java/com/lenis0012/bukkit/loginsecurity/commands/CommandRegister.java @@ -11,11 +11,14 @@ import com.lenis0012.bukkit.loginsecurity.session.action.RegisterAction; import com.lenis0012.pluginutils.command.Command; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.entity.Player; import static com.lenis0012.bukkit.loginsecurity.LoginSecurity.translate; import static com.lenis0012.bukkit.loginsecurity.modules.language.LanguageKeys.*; +import java.util.logging.Level; + public class CommandRegister extends Command { private final LoginSecurity plugin; @@ -61,20 +64,22 @@ public void execute() { CaptchaManager captcha = plugin.getModule(CaptchaManager.class); captcha.giveMapItem(player, () -> { AuthAction action = new RegisterAction(AuthService.PLAYER, player, password); - session.performActionAsync(action, new RegisterCallback(CommandRegister.this, player)); + session.performActionAsync(action, new RegisterCallback(this.plugin, CommandRegister.this, player)); }); reply(true, translate(REGISTER_CAPTCHA)); } else { AuthAction action = new RegisterAction(AuthService.PLAYER, player, password); - session.performActionAsync(action, new RegisterCallback(this, player)); + session.performActionAsync(action, new RegisterCallback(this.plugin, this, player)); } } private static final class RegisterCallback implements ActionCallback { + private final LoginSecurity plugin; private final CommandRegister command; private final Player player; - private RegisterCallback(CommandRegister command, Player player) { + private RegisterCallback(LoginSecurity plugin, CommandRegister command, Player player) { + this.plugin = plugin; this.command = command; this.player = player; } @@ -87,6 +92,24 @@ public void call(ActionResponse response) { } command.reply(player, true, translate(REGISTER_SUCCESS)); + + /** If enabled in the config, upon register we teleport the player */ + LoginSecurityConfig config = LoginSecurity.getConfiguration(); + String rawLocation = config.getJoinRegisterLocation(); // example valid value "-123.3,75,34.3" + // If empty we should do nothing + if (rawLocation != null && !rawLocation.isEmpty()) { + String[] coords = rawLocation.split(","); + try { + // Parse the x, y, z coordinates + double x = Double.parseDouble(coords[0]); + double y = Double.parseDouble(coords[1]); + double z = Double.parseDouble(coords[2]); + + player.teleport(new Location(player.getWorld(), x, y, z)); + } catch (Exception e) { + plugin.getLogger().log(Level.SEVERE, "Error while teleporting just registered player", e); + } + } } } }