Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
}
}
}
}