Skip to content

Commit bafa6e7

Browse files
authored
Merge pull request #36 from ElCholoGamer/develop
v2.13.0
2 parents 2ef7f72 + cef01cf commit bafa6e7

File tree

13 files changed

+224
-74
lines changed

13 files changed

+224
-74
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.elchologamer</groupId>
88
<artifactId>UserLogin</artifactId>
9-
<version>2.12.1</version>
9+
<version>2.13.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>UserLogin</name>
@@ -121,7 +121,7 @@
121121
<dependency>
122122
<groupId>org.mongodb</groupId>
123123
<artifactId>mongo-java-driver</artifactId>
124-
<version>3.12.0</version>
124+
<version>3.12.10</version>
125125
<scope>provided</scope>
126126
</dependency>
127127
</dependencies>

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

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void onJoin(boolean fromOtherServer) {
5353
Player player = getPlayer();
5454

5555
// Teleport to login position
56-
if (plugin.getConfig().getBoolean("teleports.toLogin")) {
56+
if (plugin.getConfig().getBoolean("teleports.toLogin", plugin.getConfig().getBoolean("teleports.preLogin", true))) {
5757
player.teleport(plugin.getLocations().getLocation("login", player.getWorld().getSpawnLocation()));
5858
}
5959

@@ -62,20 +62,23 @@ public void onJoin(boolean fromOtherServer) {
6262
return;
6363
}
6464

65+
if (ipForgor != -1) {
66+
plugin.getServer().getScheduler().cancelTask(ipForgor);
67+
ipForgor = -1;
68+
}
69+
6570
// Bypass if IP is registered
66-
if (plugin.getConfig().getBoolean("ipRecords.enabled")) {
67-
if (ip != null) {
68-
InetSocketAddress addr = player.getAddress();
69-
if (addr != null && addr.getHostString().equals(ip)) {
70-
onAuthenticate(AuthType.LOGIN);
71-
return;
72-
}
73-
}
71+
if (ip != null) {
72+
boolean ret = false;
73+
InetSocketAddress addr = player.getAddress();
7474

75-
if (ipForgor != -1) {
76-
plugin.getServer().getScheduler().cancelTask(ipForgor);
77-
ipForgor = -1;
75+
if (addr != null && addr.getHostString().equals(ip)) {
76+
onAuthenticate(AuthType.LOGIN);
77+
ret = true;
7878
}
79+
80+
ip = null;
81+
if (ret) return;
7982
}
8083

8184
schedulePreLoginTasks();
@@ -92,14 +95,28 @@ public void onQuit() {
9295
plugin.getLocations().savePlayerLocation(getPlayer());
9396
}
9497

98+
long rememberIp = -1;
99+
100+
if (plugin.getConfig().isConfigurationSection("ipRecords")) {
101+
if (plugin.getConfig().getBoolean("ipRecords.enabled")) {
102+
rememberIp = plugin.getConfig().getLong("ipRecords.delay");
103+
}
104+
} else {
105+
rememberIp = plugin.getConfig().getLong("ipCache");
106+
}
107+
95108
// Store IP address if enabled
96-
if (plugin.getConfig().getBoolean("ipRecords.enabled")) {
109+
if (rememberIp >= 0) {
97110
// Schedule IP deletion
98-
ipForgor = plugin.getServer().getScheduler().scheduleSyncDelayedTask(
99-
plugin,
100-
() -> ip = null,
101-
plugin.getConfig().getLong("ipRecords.delay", 10) * 20
102-
);
111+
InetSocketAddress addr = getPlayer().getAddress();
112+
if (addr != null) {
113+
ip = addr.getHostString();
114+
ipForgor = plugin.getServer().getScheduler().scheduleSyncDelayedTask(
115+
plugin,
116+
() -> ip = null,
117+
rememberIp * 20
118+
);
119+
}
103120
}
104121
}
105122
}
@@ -116,15 +133,15 @@ public void onAuthenticate(AuthType type) {
116133

117134
boolean bungeeEnabled = config.getBoolean("bungeeCord.enabled");
118135
if (bungeeEnabled) {
119-
String targetServer = config.getString("bungeeCord.spawnServer");
136+
String targetServer = config.getString("bungeeCord.targetServer", config.getString("bungeeCord.spawnServer"));
120137
event = new AuthenticationEvent(player, type, targetServer);
121138
} else {
122139
Location target = null;
123140
Location spawn = player.getWorld().getSpawnLocation();
124141

125142
if (teleports.getBoolean("savePosition")) {
126143
target = plugin.getLocations().getPlayerLocation(player, spawn);
127-
} else if (teleports.getBoolean("toSpawn", true)) {
144+
} else if (teleports.getBoolean("postLogin", teleports.getBoolean("toSpawn", true))) {
128145
target = plugin.getLocations().getLocation("spawn", spawn);
129146
}
130147

@@ -196,8 +213,16 @@ public void schedulePreLoginTasks() {
196213
Player player = getPlayer();
197214

198215
// Timeout
199-
if (plugin.getConfig().getBoolean("timeout.enabled", true)) {
200-
long timeoutDelay = plugin.getConfig().getLong("timeout.time");
216+
long timeoutDelay = -1;
217+
if (plugin.getConfig().isConfigurationSection("timeout")) {
218+
if (plugin.getConfig().getBoolean("timeout.enabled")) {
219+
timeoutDelay = plugin.getConfig().getLong("timeout.time");
220+
}
221+
} else {
222+
timeoutDelay = plugin.getConfig().getLong("timeout");
223+
}
224+
225+
if (timeoutDelay >= 0) {
201226
timeout = player.getServer().getScheduler().scheduleSyncDelayedTask(
202227
plugin,
203228
() -> player.kickPlayer(plugin.getLang().getMessage("messages.timeout")),
@@ -207,12 +232,12 @@ public void schedulePreLoginTasks() {
207232

208233

209234
// Repeating welcome message
210-
long interval = plugin.getConfig().getLong("repeatingWelcomeMsg", -1) * 20;
235+
long interval = plugin.getConfig().getLong("repeatWelcomeMessage", plugin.getConfig().getLong("repeatingWelcomeMsg", -1));
211236
if (interval > 0) {
212237
welcomeMessage = player.getServer().getScheduler().scheduleSyncRepeatingTask(
213238
plugin,
214239
this::sendWelcomeMessage,
215-
interval, interval
240+
interval * 20, interval * 20
216241
);
217242
}
218243
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.elchologamer.userlogin.util.Metrics;
2020
import com.elchologamer.userlogin.util.Metrics.SimplePie;
2121
import com.elchologamer.userlogin.util.Utils;
22+
import org.bukkit.entity.Player;
2223
import org.bukkit.event.Listener;
2324
import org.bukkit.plugin.java.JavaPlugin;
2425

@@ -45,6 +46,8 @@ public void onEnable() {
4546

4647
reloadPlugin();
4748

49+
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
50+
4851
// Register FastLogin hook
4952
if (getServer().getPluginManager().isPluginEnabled("FastLogin")) {
5053
new FastLoginHook().register();
@@ -75,6 +78,7 @@ public void onEnable() {
7578
registerEvents(new ItemDropRestriction());
7679
registerEvents(new AttackRestriction());
7780
registerEvents(new ReceiveDamageRestriction());
81+
registerEvents(new InventoryClickRestriction());
7882

7983
// Register Item Pickup restriction if class exists
8084
try {
@@ -171,6 +175,14 @@ private void registerEvents(Listener listener) {
171175

172176
@Override
173177
public void onDisable() {
178+
if (getConfig().getBoolean("teleports.savePosition")) {
179+
for (Player player : getServer().getOnlinePlayers()) {
180+
if (ULPlayer.get(player).isLoggedIn()) {
181+
locationsManager.savePlayerLocation(player);
182+
}
183+
}
184+
}
185+
174186
if (db != null) {
175187
try {
176188
db.disconnect();

src/main/java/com/elchologamer/userlogin/command/AuthCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import com.elchologamer.userlogin.ULPlayer;
44
import com.elchologamer.userlogin.UserLogin;
55
import com.elchologamer.userlogin.api.types.AuthType;
6+
import com.elchologamer.userlogin.command.base.AsyncCommand;
67
import com.elchologamer.userlogin.command.base.BaseCommand;
78
import org.bukkit.command.CommandSender;
89
import org.bukkit.entity.Player;
910

10-
public abstract class AuthCommand extends BaseCommand {
11+
public abstract class AuthCommand extends AsyncCommand {
1112

1213
private final AuthType type;
1314
private final int minArgs;
@@ -26,7 +27,7 @@ public UserLogin getPlugin() {
2627
}
2728

2829
@Override
29-
public final boolean run(CommandSender sender, String label, String[] args) {
30+
public final boolean asyncRun(CommandSender sender, String label, String[] args) {
3031
ULPlayer ulPlayer = ULPlayer.get((Player) sender);
3132

3233
// Check if player is already logged in
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.elchologamer.userlogin.command.base;
2+
3+
import org.bukkit.command.CommandSender;
4+
5+
public abstract class AsyncCommand extends BaseCommand {
6+
7+
public AsyncCommand(String name) {
8+
super(name);
9+
}
10+
11+
public AsyncCommand(String name, boolean playerOnly) {
12+
super(name, playerOnly);
13+
}
14+
15+
@Override
16+
public final boolean run(CommandSender sender, String label, String[] args) {
17+
getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), () -> {
18+
boolean success = asyncRun(sender, label, args);
19+
if (!success) sender.sendMessage(getUsage());
20+
});
21+
return true;
22+
}
23+
24+
public abstract boolean asyncRun(CommandSender sender, String label, String[] args);
25+
}

src/main/java/com/elchologamer/userlogin/command/sub/SetCommand.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ public boolean run(CommandSender sender, String[] args) {
2424
if (args.length == 0) return false;
2525

2626
String type = args[0].toLowerCase();
27-
if (!type.equals("spawn") && !type.equals("login")) return false;
27+
if (!type.equals("spawn") && !type.equals("login") && !type.equals("prelogin") && !type.equals("postlogin"))
28+
return false;
29+
30+
if (type.equals("prelogin")) {
31+
type = "login";
32+
} else if (type.equals("postlogin")) {
33+
type = "spawn";
34+
}
2835

2936
ULPlayer ulPlayer = ULPlayer.get((Player) sender);
3037
Player player = ulPlayer.getPlayer();
@@ -36,7 +43,7 @@ public boolean run(CommandSender sender, String[] args) {
3643
// Send message
3744
ulPlayer.sendMessage(
3845
"commands.set",
39-
new QuickMap<>("type", (Object) type)
46+
new QuickMap<>("type", (Object) args[0].toLowerCase())
4047
.set("x", (int) loc.getX())
4148
.set("y", (int) loc.getY())
4249
.set("z", (int) loc.getZ())
@@ -53,8 +60,8 @@ public List<String> tabComplete(CommandSender sender, String alias, String[] arg
5360
List<String> options = new ArrayList<>();
5461

5562
if (args.length == 1) {
56-
options.add("login");
57-
options.add("spawn");
63+
options.add("prelogin");
64+
options.add("postlogin");
5865
}
5966

6067
return options;

src/main/java/com/elchologamer/userlogin/listener/JoinQuitListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class JoinQuitListener implements Listener {
1111

1212
@EventHandler
1313
public void onPlayerJoin(PlayerJoinEvent event) {
14-
if (UserLogin.getPlugin().getConfig().getBoolean("disableVanillaJoinMessages")) {
14+
if (!UserLogin.getPlugin().getConfig().getBoolean("vanillaJoinMessages", !UserLogin.getPlugin().getConfig().getBoolean("disableVanillaJoinMessages", true))) {
1515
event.setJoinMessage(null);
1616
}
1717
ULPlayer.get(event.getPlayer()).onJoin(false);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.elchologamer.userlogin.listener.restriction;
2+
3+
import org.bukkit.entity.HumanEntity;
4+
import org.bukkit.entity.Player;
5+
import org.bukkit.event.EventHandler;
6+
import org.bukkit.event.inventory.InventoryClickEvent;
7+
8+
public class InventoryClickRestriction extends BaseRestriction<InventoryClickEvent> {
9+
public InventoryClickRestriction() {
10+
super("inventoryClick");
11+
}
12+
13+
@EventHandler
14+
public void handle(InventoryClickEvent event) {
15+
if (shouldRestrict(event)) event.setCancelled(true);
16+
}
17+
18+
@Override
19+
protected Player getEventPlayer(InventoryClickEvent event) {
20+
HumanEntity entity = event.getWhoClicked();
21+
22+
if (!(entity instanceof Player)) return null;
23+
return (Player) entity;
24+
}
25+
}

src/main/java/com/elchologamer/userlogin/manager/LangManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void createDefault() {
2222
File folder = new File(plugin.getDataFolder(), "lang");
2323
folder.mkdirs();
2424

25-
String[] langs = {"en_US", "es_ES"};
25+
String[] langs = {"en_US", "es_ES", "pt_BR"};
2626

2727
for (String lang : langs) {
2828
try {

0 commit comments

Comments
 (0)