Skip to content

Commit 3e6c671

Browse files
committed
Now the paste helper only pastes one time per plugin load (prevent limit)
1 parent c0e08f5 commit 3e6c671

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.jaimemartz.playerbalancer.configuration.ConfigEntries;
77
import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry;
88
import com.jaimemartz.playerbalancer.listener.*;
9+
import com.jaimemartz.playerbalancer.manager.PasteHelper;
910
import com.jaimemartz.playerbalancer.manager.PlayerLocker;
1011
import com.jaimemartz.playerbalancer.ping.StatusManager;
1112
import com.jaimemartz.playerbalancer.section.SectionManager;
@@ -22,6 +23,7 @@
2223

2324
import java.io.IOException;
2425
import java.util.logging.Level;
26+
import java.util.stream.Stream;
2527

2628
public class PlayerBalancer extends Plugin {
2729
private static final int LAST_VER_CONFIG_UPDATE = 20950000;
@@ -111,6 +113,8 @@ private void enable() {
111113

112114
getProxy().registerChannel("PlayerBalancer");
113115

116+
Stream.of(PasteHelper.values()).forEach(a -> a.setUrl(null));
117+
114118
if (ConfigEntries.RECONNECT_KICK_ENABLED.get()) {
115119
kickListener = new ServerKickListener(this);
116120
getProxy().getPluginManager().registerListener(this, kickListener);

src/main/java/com/jaimemartz/playerbalancer/manager/PasteHelper.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
import com.jaimemartz.playerbalancer.PlayerBalancer;
55
import com.jaimemartz.playerbalancer.utils.GuestPaste;
66
import com.jaimemartz.playerbalancer.utils.GuestPaste.PasteException;
7+
import lombok.Getter;
8+
import lombok.Setter;
79
import net.md_5.bungee.api.ChatColor;
810
import net.md_5.bungee.api.CommandSender;
911
import net.md_5.bungee.api.chat.ClickEvent;
1012
import net.md_5.bungee.api.chat.ComponentBuilder;
1113
import net.md_5.bungee.api.connection.ProxiedPlayer;
12-
import net.md_5.bungee.api.scheduler.ScheduledTask;
1314

1415
import java.io.File;
1516
import java.io.FileInputStream;
1617
import java.io.InputStreamReader;
1718
import java.net.URL;
18-
import java.util.concurrent.TimeUnit;
1919
import java.util.function.BiConsumer;
2020

2121
public enum PasteHelper {
@@ -89,24 +89,19 @@ public URL paste(PlayerBalancer plugin) throws Exception {
8989
}
9090
};
9191

92+
@Getter @Setter
9293
private URL url;
93-
private ScheduledTask task = null;
9494

9595
private final BiConsumer<CommandSender, URL> consumer;
9696
PasteHelper(BiConsumer<CommandSender, URL> consumer) {
9797
this.consumer = consumer;
9898
}
9999

100100
public void send(PlayerBalancer plugin, CommandSender sender) {
101+
boolean cached = url != null;
101102
if (url == null) {
102103
try {
103104
url = paste(plugin);
104-
if (task != null) {
105-
task.cancel();
106-
}
107-
task = plugin.getProxy().getScheduler().schedule(plugin, () -> {
108-
url = null;
109-
}, 5, TimeUnit.MINUTES);
110105
} catch (PasteException e) {
111106
sender.sendMessage(new ComponentBuilder("An pastebin exception occurred: " + e.getMessage())
112107
.color(ChatColor.RED)
@@ -123,7 +118,12 @@ public void send(PlayerBalancer plugin, CommandSender sender) {
123118
}
124119

125120
if (url != null) {
126-
consumer.accept(sender, url);
121+
if (cached) {
122+
sender.sendMessage(new ComponentBuilder("This is a cached link, reload the plugin for it to refresh!")
123+
.color(ChatColor.RED)
124+
.create()
125+
);
126+
}
127127
}
128128
}
129129

0 commit comments

Comments
 (0)