Skip to content

Commit bf41f89

Browse files
authored
Merge pull request #24 from ElCholoGamer/feature-login-commands
Login commands
2 parents 1c7309f + 6bc38c8 commit bf41f89

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/main/java/com/elchologamer/userlogin/ULPlayer.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
import com.elchologamer.userlogin.util.Utils;
88
import org.bukkit.Location;
99
import org.bukkit.configuration.ConfigurationSection;
10+
import org.bukkit.configuration.file.FileConfiguration;
1011
import org.bukkit.entity.Player;
1112

1213
import java.net.InetSocketAddress;
1314
import java.util.HashMap;
15+
import java.util.List;
1416
import java.util.Map;
1517
import java.util.UUID;
1618

@@ -99,16 +101,17 @@ public void onQuit() {
99101

100102
public void onAuthenticate(AuthType type) {
101103
Player player = getPlayer();
104+
FileConfiguration config = plugin.getConfig();
102105

103-
ConfigurationSection teleports = plugin.getConfig().getConfigurationSection("teleports");
106+
ConfigurationSection teleports = config.getConfigurationSection("teleports");
104107
assert teleports != null;
105108

106109
// Call event
107110
AuthenticationEvent event;
108111

109-
boolean bungeeEnabled = plugin.getConfig().getBoolean("bungeeCord.enabled");
112+
boolean bungeeEnabled = config.getBoolean("bungeeCord.enabled");
110113
if (bungeeEnabled) {
111-
String targetServer = plugin.getConfig().getString("bungeeCord.spawnServer");
114+
String targetServer = config.getString("bungeeCord.spawnServer");
112115
event = new AuthenticationEvent(player, type, targetServer);
113116
} else {
114117
Location target = null;
@@ -130,7 +133,7 @@ public void onAuthenticate(AuthType type) {
130133
cancelPreLoginTasks();
131134

132135
// Save IP address
133-
if (plugin.getConfig().getBoolean("ipRecords.enabled")) {
136+
if (config.getBoolean("ipRecords.enabled")) {
134137
InetSocketAddress addr = player.getAddress();
135138
if (addr != null) ip = addr.getHostString();
136139
}
@@ -149,6 +152,15 @@ public void onAuthenticate(AuthType type) {
149152

150153
loggedIn = true;
151154

155+
// Run login commands
156+
List<String> loginCommands = config.getStringList("loginCommands");
157+
for (String command : loginCommands) {
158+
plugin.getServer().dispatchCommand(
159+
plugin.getServer().getConsoleSender(),
160+
command.replace("{player}", player.getName()).replaceFirst("^/", "")
161+
);
162+
}
163+
152164
// Teleport to destination
153165
if (bungeeEnabled && event.getTargetServer() != null) {
154166
Utils.sendPluginMessage(player, "BungeeCord", "Connect", event.getTargetServer());

src/main/resources/config.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ enabledCommands:
3434
# Custom command aliases
3535
# (Changes will only take effect on a server restart)
3636
commandAliases:
37-
userlogin: ['ul']
38-
register: []
39-
login: []
40-
changepassword: []
37+
userlogin: [ 'ul' ]
38+
register: [ ]
39+
login: [ ]
40+
changepassword: [ ]
41+
42+
# A list of commands that will be executed when a player
43+
# logs in, useful for adding extra functionality
44+
loginCommands: [ ]
4145

4246
timeout:
4347

0 commit comments

Comments
 (0)