Skip to content

Commit 4ab24db

Browse files
authored
Merge pull request #34 from RagingTech/dev
3.4.0
2 parents 22981bb + 703c5be commit 4ab24db

10 files changed

Lines changed: 132 additions & 29 deletions

File tree

build.gradle.kts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@ repositories {
3131
// Elytrium
3232
maven("https://maven.elytrium.net/repo/")
3333
// SayanDevelopment
34-
maven("https://repo.sayandev.org/snapshots") {
34+
// Invalid SSL certificate local jar file utilized for the time being
35+
flatDir {
36+
dirs("libs")
3537
content {
3638
includeGroup("org.sayandev")
3739
}
3840
}
41+
// maven("https://repo.sayandev.org/snapshots") {
42+
// content {
43+
// includeGroup("org.sayandev")
44+
// }
45+
// }
3946
}
4047

4148
dependencies {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Project metadata
22
group=xyz.earthcow.networkjoinmessages
3-
version=3.3.0
3+
version=3.4.0
44
description=A plugin handling join, leave and swap messages for proxy servers.
55

66
# Plugin.yml metadata
32.2 MB
Binary file not shown.

src/main/java/xyz/earthcow/networkjoinmessages/bungee/BungeeMain.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ public void runTaskAsync(Runnable task) {
201201
getProxy().getScheduler().runAsync(this, task);
202202
}
203203

204+
@Override
205+
public int runTaskAsyncLater(Runnable task, int timeInMillisecondsLater) {
206+
return getProxy().getScheduler().schedule(this, task, timeInMillisecondsLater, TimeUnit.MILLISECONDS).getId();
207+
}
208+
204209
@Override
205210
public boolean isPluginLoaded(String pluginName) {
206211
return getProxy().getPluginManager().getPlugin(pluginName) != null;

src/main/java/xyz/earthcow/networkjoinmessages/common/Storage.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public final class Storage {
8888
@Getter
8989
private int leaveCacheDuration;
9090

91+
@Getter
92+
private int leaveJoinBufferDuration;
93+
9194
/**
9295
* The default silent state of a player joining with the networkjoinmessages.silent permission
9396
* Default: true - Someone joining with the permission will be silent (not send a join message)
@@ -147,6 +150,8 @@ public final class Storage {
147150
private boolean PVSpoofJoinMessageOnShow;
148151
@Getter
149152
private boolean PVSpoofLeaveMessageOnHide;
153+
@Getter
154+
private boolean PVTreatVanishedOnJoin;
150155
// LimboAPI
151156
@Getter
152157
private boolean shouldSuppressLimboSwap;
@@ -217,6 +222,7 @@ public void setUpDefaultValuesFromConfig() {
217222
/// Settings
218223

219224
this.leaveCacheDuration = config.getInt("Settings.LeaveNetworkMessageCacheDuration");
225+
this.leaveJoinBufferDuration = config.getInt("Settings.LeaveJoinBufferDuration");
220226

221227
this.silentJoinDefaultState = config.getBoolean("Settings.SilentJoinDefaultState");
222228

@@ -258,6 +264,7 @@ public void setUpDefaultValuesFromConfig() {
258264
this.PVRemoveVanishedPlayersFromPlayerCount = config.getBoolean("OtherPlugins.PremiumVanish.RemoveVanishedPlayersFromPlayerCount");
259265
this.PVSpoofJoinMessageOnShow = config.getBoolean("OtherPlugins.PremiumVanish.SpoofJoinMessageOnShow");
260266
this.PVSpoofLeaveMessageOnHide = config.getBoolean("OtherPlugins.PremiumVanish.SpoofLeaveMessageOnHide");
267+
this.PVTreatVanishedOnJoin = config.getBoolean("OtherPlugins.PremiumVanish.TreatVanishedOnJoin");
261268

262269
this.shouldSuppressLimboSwap = config.getBoolean("OtherPlugins.LimboAPI.SuppressSwapMessages");
263270
this.shouldSuppressLimboJoin = config.getBoolean("OtherPlugins.LimboAPI.SuppressJoinMessages");
@@ -292,6 +299,16 @@ public void setUpDefaultValuesFromConfig() {
292299
);
293300
this.leaveCacheDuration = 0;
294301
}
302+
303+
// Verify leave join buffer duration
304+
if (leaveJoinBufferDuration < 0) {
305+
plugin.getCoreLogger()
306+
.info(
307+
"Setting error: Settings.LeaveJoinBufferDuration " +
308+
"requires a non-negative value. Defaulting to 0."
309+
);
310+
this.leaveJoinBufferDuration = 0;
311+
}
295312
}
296313

297314
public boolean getSilentMessageState(CorePlayer player) {
@@ -692,6 +709,7 @@ public Collection<CustomChart> getCustomCharts() {
692709

693710
customCharts.add(new SimplePie("premium_vanish_vanished_are_silent", () -> String.valueOf(PVTreatVanishedPlayersAsSilent)));
694711
customCharts.add(new SimplePie("premium_vanish_remove_vanished_from_player_count", () -> String.valueOf(PVRemoveVanishedPlayersFromPlayerCount)));
712+
customCharts.add(new SimplePie("premium_vanish_treat_vanished_on_join", () -> String.valueOf(PVTreatVanishedOnJoin)));
695713

696714
customCharts.add(new SimplePie("limbo_api_suppress_swap", () -> String.valueOf(shouldSuppressLimboSwap)));
697715
customCharts.add(new SimplePie("limbo_api_suppress_join", () -> String.valueOf(shouldSuppressLimboJoin)));

src/main/java/xyz/earthcow/networkjoinmessages/common/abstraction/CorePlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public interface CorePlugin {
2929
void cancelTask(int taskId);
3030
int runTaskRepeatedly(Runnable task, int timeInSecondsLater);
3131
void runTaskAsync(Runnable task);
32+
int runTaskAsyncLater(Runnable task, int timeInMillisecondsLater);
3233

3334
boolean isPluginLoaded(String pluginName);
3435

src/main/java/xyz/earthcow/networkjoinmessages/common/listeners/CorePlayerListener.java

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
import xyz.earthcow.networkjoinmessages.common.util.H2PlayerJoinTracker;
1515
import xyz.earthcow.networkjoinmessages.common.util.MessageType;
1616

17+
import java.util.Map;
18+
import java.util.UUID;
19+
import java.util.concurrent.ConcurrentHashMap;
20+
1721
public class CorePlayerListener {
1822

1923
private final CorePlugin plugin;
@@ -22,11 +26,15 @@ public class CorePlayerListener {
2226

2327
private H2PlayerJoinTracker firstJoinTracker;
2428

29+
private final Map<UUID, Integer> leaveJoinBuffer;
30+
2531
@Nullable
2632
private final SayanVanishHook sayanVanishHook;
2733

2834
@Nullable
2935
private final PremiumVanish premiumVanish;
36+
37+
private final String PVJoinVanishedPerm = "pv.joinvanished";
3038

3139
public CorePlayerListener(CorePlugin plugin, Storage storage, MessageHandler messageHandler, @Nullable SayanVanishHook sayanVanishHook, @Nullable PremiumVanish premiumVanish) {
3240
this.plugin = plugin;
@@ -42,6 +50,8 @@ public CorePlayerListener(CorePlugin plugin, Storage storage, MessageHandler mes
4250
plugin.getCoreLogger().debug("Exception: " + ex);
4351
}
4452

53+
this.leaveJoinBuffer = new ConcurrentHashMap<>();
54+
4555
}
4656

4757
/**
@@ -51,13 +61,14 @@ public CorePlayerListener(CorePlugin plugin, Storage storage, MessageHandler mes
5161
*/
5262
private boolean isSilentEvent(@NotNull CorePlayer player) {
5363
// Event is silent if, the player has a silent message state OR
54-
// premiumVanish is present, the treat vanished players as silent option is true, and the player is vanished
64+
// premiumVanish is present, the treat vanished players as silent option is true, and the player is vanished or
65+
// the TreatVanishedOnJoin option is enabled and the player has the pv.joinvanished permission
5566
plugin.getCoreLogger().debug("Checking if the event for player " + player.getName() + " should been silent:");
5667
plugin.getCoreLogger().debug(String.format(
5768
"silent message state: %s,%n" +
5869
"SayanVanish hook is NOT null: %s, SVTreatVanishedPlayersAsSilent: %s, SayanVanish player is vanished: %s,%n" +
5970
"PremiumVanish hook is NOT null: %s, PVTreatVanishedPlayersAsSilent: %s, PremiumVanish player is vanished: %s,%n" +
60-
"PremiumVanish event hidden: %s"
71+
"PremiumVanish event hidden: %s, PVTreatVanishedOnJoin: %s, Player has pv.joinvanished permission: %s"
6172
,
6273
storage.getSilentMessageState(player),
6374
sayanVanishHook != null,
@@ -66,12 +77,18 @@ private boolean isSilentEvent(@NotNull CorePlayer player) {
6677
premiumVanish != null,
6778
storage.isPVTreatVanishedPlayersAsSilent(),
6879
premiumVanish != null ? premiumVanish.isVanished(player.getUniqueId()) : "NA",
69-
player.getPremiumVanishHidden()
80+
player.getPremiumVanishHidden(),
81+
storage.isPVTreatVanishedOnJoin(),
82+
player.hasPermission(PVJoinVanishedPerm)
7083
));
84+
if (storage.isPVTreatVanishedOnJoin() && player.hasPermission(PVJoinVanishedPerm)) {
85+
player.setPremiumVanishHidden(true);
86+
}
7187
return storage.getSilentMessageState(player) ||
7288
(sayanVanishHook != null && storage.isSVTreatVanishedPlayersAsSilent() && sayanVanishHook.isVanished(player))
7389
||
74-
(premiumVanish != null && storage.isPVTreatVanishedPlayersAsSilent() && (premiumVanish.isVanished(player.getUniqueId()) || player.getPremiumVanishHidden()));
90+
(premiumVanish != null && storage.isPVTreatVanishedPlayersAsSilent()
91+
&& (premiumVanish.isVanished(player.getUniqueId()) || player.getPremiumVanishHidden()));
7592
}
7693

7794
private boolean shouldNotBroadcast(@NotNull CorePlayer player, @NotNull MessageType type) {
@@ -135,6 +152,14 @@ private boolean shouldNotBroadcast(@NotNull CorePlayer player, @NotNull MessageT
135152
" - suppress limbo join");
136153
return true;
137154
}
155+
156+
Integer leaveJoinBufferTaskId = leaveJoinBuffer.remove(player.getUniqueId());
157+
if (leaveJoinBufferTaskId != null) {
158+
plugin.cancelTask(leaveJoinBufferTaskId);
159+
plugin.getCoreLogger().debug("Skipping " + player.getName() +
160+
" - returned within LeaveJoinBufferDuration");
161+
return true;
162+
}
138163
}
139164
case LEAVE -> {
140165
if (!storage.isConnected(player) || !storage.isLeaveNetworkMessageEnabled() || storage.isBlacklisted(player)) {
@@ -149,6 +174,17 @@ private boolean shouldNotBroadcast(@NotNull CorePlayer player, @NotNull MessageT
149174
" - suppress limbo leave");
150175
return true;
151176
}
177+
178+
if (storage.getLeaveJoinBufferDuration() > 0 && leaveJoinBuffer.get(player.getUniqueId()) == null) {
179+
leaveJoinBuffer.put(player.getUniqueId(), plugin.runTaskAsyncLater(() -> {
180+
this.broadcastLeaveMessage(player);
181+
leaveJoinBuffer.remove(player.getUniqueId());
182+
},
183+
storage.getLeaveJoinBufferDuration()));
184+
plugin.getCoreLogger().debug("Skipping " + player.getName() +
185+
" - allotting buffer time to rejoin before broadcasting leave message");
186+
return true;
187+
}
152188
}
153189
}
154190
return false;
@@ -301,6 +337,14 @@ public void onDisconnect(@NotNull CorePlayer player) {
301337
return;
302338
}
303339

340+
broadcastLeaveMessage(player);
341+
342+
plugin.getPlayerManager().removePlayer(player.getUniqueId());
343+
storage.setConnected(player, false);
344+
messageHandler.stopLeaveCacheTaskForPlayer(player);
345+
}
346+
347+
private void broadcastLeaveMessage(@NotNull CorePlayer player) {
304348
String message = player.getCachedLeaveMessage();
305349

306350
// Silent
@@ -312,18 +356,14 @@ public void onDisconnect(@NotNull CorePlayer player) {
312356
Component formattedMessage = Formatter.deserialize(message);
313357
// Call the custom NetworkLeaveEvent
314358
NetworkLeaveEvent networkLeaveEvent = new NetworkLeaveEvent(
315-
player,
316-
player.getCurrentServer().getName(),
317-
storage.getServerDisplayName(player.getCurrentServer().getName()),
318-
isSilent,
319-
Formatter.serialize(formattedMessage),
320-
Formatter.sanitize(formattedMessage)
359+
player,
360+
player.getCurrentServer().getName(),
361+
storage.getServerDisplayName(player.getCurrentServer().getName()),
362+
isSilent,
363+
Formatter.serialize(formattedMessage),
364+
Formatter.sanitize(formattedMessage)
321365
);
322366
plugin.fireEvent(networkLeaveEvent);
323-
324-
plugin.getPlayerManager().removePlayer(player.getUniqueId());
325-
storage.setConnected(player, false);
326-
messageHandler.stopLeaveCacheTaskForPlayer(player);
327367
}
328368

329369
public H2PlayerJoinTracker getPlayerJoinTracker() {

src/main/java/xyz/earthcow/networkjoinmessages/common/listeners/CorePremiumVanishListener.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public CorePremiumVanishListener(@NotNull CoreLogger logger, @NotNull Storage st
1818
}
1919

2020
public void handlePremiumVanishShow(@NotNull CorePlayer p) {
21+
if (!p.getPremiumVanishHidden()) {
22+
return;
23+
}
2124
logger.debug("Setting PremiumVanishHidden to FALSE for player " + p.getName());
2225
p.setPremiumVanishHidden(false);
2326
if (storage.isPVSpoofJoinMessageOnShow()) {
@@ -26,6 +29,9 @@ public void handlePremiumVanishShow(@NotNull CorePlayer p) {
2629
}
2730

2831
public void handlePremiumVanishHide(@NotNull CorePlayer p) {
32+
if (p.getPremiumVanishHidden()) {
33+
return;
34+
}
2935
logger.debug("Setting PremiumVanishHidden to TRUE for player " + p.getName());
3036
p.setPremiumVanishHidden(true);
3137
if (storage.isPVSpoofLeaveMessageOnHide()) {

src/main/java/xyz/earthcow/networkjoinmessages/velocity/VelocityMain.java

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@
3030

3131
import java.io.File;
3232
import java.nio.file.Path;
33-
import java.util.ArrayList;
34-
import java.util.List;
35-
import java.util.Optional;
36-
import java.util.UUID;
33+
import java.util.*;
34+
import java.util.concurrent.ConcurrentHashMap;
3735
import java.util.concurrent.TimeUnit;
36+
import java.util.concurrent.atomic.AtomicInteger;
3837
import java.util.stream.Collectors;
3938

4039
@Plugin(
@@ -72,7 +71,8 @@ public class VelocityMain implements CorePlugin {
7271

7372
private VelocityDiscordListener velocityDiscordListener = null;
7473

75-
private final List<ScheduledTask> tasks = new ArrayList<>();
74+
private final AtomicInteger nextTaskId = new AtomicInteger(0);
75+
private final Map<Integer, ScheduledTask> tasks = new ConcurrentHashMap<>();
7676

7777
@Inject
7878
public VelocityMain(ProxyServer proxy, Logger logger, @DataDirectory Path dataDirectory, Metrics.Factory metricsFactory) {
@@ -181,26 +181,44 @@ public void unregisterDiscordListener() {
181181

182182
@Override
183183
public void cancelTask(int taskId) {
184-
try {
185-
tasks.get(taskId).cancel();
186-
} catch (IndexOutOfBoundsException ignored) {
184+
ScheduledTask task = tasks.remove(taskId);
185+
if (task != null) {
186+
task.cancel();
187187
}
188188
}
189189

190190
@Override
191191
public int runTaskRepeatedly(Runnable task, int timeInSecondsLater) {
192-
tasks.add(
193-
proxy.getScheduler().buildTask(this, task)
194-
.delay(timeInSecondsLater, TimeUnit.SECONDS).repeat(timeInSecondsLater, TimeUnit.SECONDS).schedule()
192+
int taskId = nextTaskId.getAndIncrement();
193+
tasks.put(taskId, proxy.getScheduler().buildTask(this, task)
194+
.delay(timeInSecondsLater, TimeUnit.SECONDS)
195+
.repeat(timeInSecondsLater, TimeUnit.SECONDS)
196+
.schedule()
195197
);
196-
return tasks.size() - 1;
198+
return taskId;
197199
}
198200

199201
@Override
200202
public void runTaskAsync(Runnable task) {
201203
proxy.getScheduler().buildTask(this, task).schedule();
202204
}
203205

206+
@Override
207+
public int runTaskAsyncLater(Runnable task, int timeInMillisecondsLater) {
208+
int taskId = nextTaskId.getAndIncrement();
209+
tasks.put(
210+
taskId,
211+
proxy.getScheduler().buildTask(this, () -> {
212+
try {
213+
task.run();
214+
} finally {
215+
this.cancelTask(taskId);
216+
}
217+
}).delay(timeInMillisecondsLater, TimeUnit.MILLISECONDS).schedule()
218+
);
219+
return taskId;
220+
}
221+
204222
@Override
205223
public boolean isPluginLoaded(String pluginName) {
206224
return proxy.getPluginManager().isLoaded(pluginName.toLowerCase());

src/main/resources/config.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ Settings:
118118
# server swap.
119119
LeaveNetworkMessageCacheDuration: 45
120120

121+
# Designate how long, in milliseconds, the plugin will wait before sending the leave network message for a player.
122+
# This allows them to rejoin with no join message and cancel the sending of the leave network message altogether.
123+
# Helps prevent spam from players with a weak internet connection. 1500 is recommended.
124+
LeaveJoinBufferDuration: 0
125+
121126
# Should players with the networkjoinmessages.silent permission be silenced by default?
122127
# It will be set to this for all players after a reboot. They can toggle it for themselves with the /njoinspoof toggle command
123128
SilentJoinDefaultState: true
@@ -210,6 +215,9 @@ OtherPlugins:
210215
SpoofJoinMessageOnShow: true
211216
# Spoof a leave message automatically when a player vanishes (hides)
212217
SpoofLeaveMessageOnHide: true
218+
# Treats a player with the permission pv.joinvanished as vanished on join (permission must be set on the proxy)
219+
# This is to be used in conjunction with the PremiumVanish 'AutoVanishOnJoin' option
220+
TreatVanishedOnJoin: false
213221
LimboAPI:
214222
# No swap messages for players swapping to or from limbo servers
215223
SuppressSwapMessages: true
@@ -220,4 +228,4 @@ OtherPlugins:
220228

221229
debug: false
222230
# Do not touch this
223-
config-version: 11
231+
config-version: 12

0 commit comments

Comments
 (0)