Now the paste helper only pastes one time per plugin load (prevent limit)

This commit is contained in:
Jaime Martinez Rincon 2017-08-09 13:31:16 +02:00
parent c0e08f5db4
commit 3e6c671cce
2 changed files with 14 additions and 10 deletions

View File

@ -6,6 +6,7 @@ import com.jaimemartz.playerbalancer.commands.ManageCommand;
import com.jaimemartz.playerbalancer.configuration.ConfigEntries; import com.jaimemartz.playerbalancer.configuration.ConfigEntries;
import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry; import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry;
import com.jaimemartz.playerbalancer.listener.*; import com.jaimemartz.playerbalancer.listener.*;
import com.jaimemartz.playerbalancer.manager.PasteHelper;
import com.jaimemartz.playerbalancer.manager.PlayerLocker; import com.jaimemartz.playerbalancer.manager.PlayerLocker;
import com.jaimemartz.playerbalancer.ping.StatusManager; import com.jaimemartz.playerbalancer.ping.StatusManager;
import com.jaimemartz.playerbalancer.section.SectionManager; import com.jaimemartz.playerbalancer.section.SectionManager;
@ -22,6 +23,7 @@ import org.inventivetalent.update.bungee.BungeeUpdater;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Stream;
public class PlayerBalancer extends Plugin { public class PlayerBalancer extends Plugin {
private static final int LAST_VER_CONFIG_UPDATE = 20950000; private static final int LAST_VER_CONFIG_UPDATE = 20950000;
@ -111,6 +113,8 @@ public class PlayerBalancer extends Plugin {
getProxy().registerChannel("PlayerBalancer"); getProxy().registerChannel("PlayerBalancer");
Stream.of(PasteHelper.values()).forEach(a -> a.setUrl(null));
if (ConfigEntries.RECONNECT_KICK_ENABLED.get()) { if (ConfigEntries.RECONNECT_KICK_ENABLED.get()) {
kickListener = new ServerKickListener(this); kickListener = new ServerKickListener(this);
getProxy().getPluginManager().registerListener(this, kickListener); getProxy().getPluginManager().registerListener(this, kickListener);

View File

@ -4,18 +4,18 @@ import com.google.common.io.CharStreams;
import com.jaimemartz.playerbalancer.PlayerBalancer; import com.jaimemartz.playerbalancer.PlayerBalancer;
import com.jaimemartz.playerbalancer.utils.GuestPaste; import com.jaimemartz.playerbalancer.utils.GuestPaste;
import com.jaimemartz.playerbalancer.utils.GuestPaste.PasteException; import com.jaimemartz.playerbalancer.utils.GuestPaste.PasteException;
import lombok.Getter;
import lombok.Setter;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.scheduler.ScheduledTask;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
public enum PasteHelper { public enum PasteHelper {
@ -89,8 +89,8 @@ public enum PasteHelper {
} }
}; };
@Getter @Setter
private URL url; private URL url;
private ScheduledTask task = null;
private final BiConsumer<CommandSender, URL> consumer; private final BiConsumer<CommandSender, URL> consumer;
PasteHelper(BiConsumer<CommandSender, URL> consumer) { PasteHelper(BiConsumer<CommandSender, URL> consumer) {
@ -98,15 +98,10 @@ public enum PasteHelper {
} }
public void send(PlayerBalancer plugin, CommandSender sender) { public void send(PlayerBalancer plugin, CommandSender sender) {
boolean cached = url != null;
if (url == null) { if (url == null) {
try { try {
url = paste(plugin); url = paste(plugin);
if (task != null) {
task.cancel();
}
task = plugin.getProxy().getScheduler().schedule(plugin, () -> {
url = null;
}, 5, TimeUnit.MINUTES);
} catch (PasteException e) { } catch (PasteException e) {
sender.sendMessage(new ComponentBuilder("An pastebin exception occurred: " + e.getMessage()) sender.sendMessage(new ComponentBuilder("An pastebin exception occurred: " + e.getMessage())
.color(ChatColor.RED) .color(ChatColor.RED)
@ -123,7 +118,12 @@ public enum PasteHelper {
} }
if (url != null) { if (url != null) {
consumer.accept(sender, url); if (cached) {
sender.sendMessage(new ComponentBuilder("This is a cached link, reload the plugin for it to refresh!")
.color(ChatColor.RED)
.create()
);
}
} }
} }