premium logic finished
This commit is contained in:
@@ -6,16 +6,17 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
SpigotMain pl;
|
||||
final SpigotMain pl;
|
||||
public Commands(SpigotMain pl) {
|
||||
this.pl = pl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
Player player = null;
|
||||
if(sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
@@ -51,6 +52,7 @@ public class Commands implements CommandExecutor {
|
||||
if(pl.config.getBoolean("send-queue-commands-in-batches")) {
|
||||
pl.queuebatch.put(player, srvname);
|
||||
} else {
|
||||
assert player != null;
|
||||
pl.sendMessage(player, "queue", srvname);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ import java.io.PrintWriter;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class Config {
|
||||
File f;
|
||||
YamlConfiguration yml;
|
||||
final File f;
|
||||
final YamlConfiguration yml;
|
||||
|
||||
JavaPlugin pl;
|
||||
final JavaPlugin pl;
|
||||
|
||||
|
||||
public boolean getBoolean(String key) {
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.Iterator;
|
||||
*/
|
||||
public class Placeholders extends PlaceholderExpansion {
|
||||
|
||||
private SpigotMain plugin;
|
||||
private final SpigotMain plugin;
|
||||
|
||||
/**
|
||||
* Since we register the expansion inside our own plugin, we
|
||||
@@ -89,7 +89,7 @@ public class Placeholders extends PlaceholderExpansion {
|
||||
return plugin.getDescription().getVersion();
|
||||
}
|
||||
|
||||
HashMap<Player, HashMap<String, String>> responseCache = new HashMap<>();
|
||||
final HashMap<Player, HashMap<String, String>> responseCache = new HashMap<>();
|
||||
|
||||
public void cleanCache() {
|
||||
Iterator<Player> it = responseCache.keySet().iterator();
|
||||
@@ -135,31 +135,25 @@ public class Placeholders extends PlaceholderExpansion {
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
public void run() {
|
||||
HashMap<String, String> playerCache;
|
||||
if(responseCache.containsKey(player)) {
|
||||
playerCache = responseCache.get(player);
|
||||
} else {
|
||||
playerCache = new HashMap<String, String>();
|
||||
}
|
||||
if(playerCache.size() > 75) {
|
||||
try {
|
||||
playerCache.remove(playerCache.keySet().toArray()[0]);
|
||||
} catch(ConcurrentModificationException e) {
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
playerCache.remove(playerCache.keySet().toArray()[0]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
String resp = parsePlaceholder(player, identifier);
|
||||
if(resp == null) return;
|
||||
playerCache.put(identifier, resp);
|
||||
responseCache.put(player, playerCache);
|
||||
}
|
||||
});
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
HashMap<String, String> playerCache;
|
||||
if(responseCache.containsKey(player)) {
|
||||
playerCache = responseCache.get(player);
|
||||
} else {
|
||||
playerCache = new HashMap<>();
|
||||
}
|
||||
if(playerCache.size() > 75) {
|
||||
try {
|
||||
playerCache.remove(playerCache.keySet().toArray()[0]);
|
||||
} catch(ConcurrentModificationException e) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> playerCache.remove(playerCache.keySet().toArray()[0]));
|
||||
}
|
||||
}
|
||||
String resp = parsePlaceholder(player, identifier);
|
||||
if(resp == null) return;
|
||||
playerCache.put(identifier, resp);
|
||||
responseCache.put(player, playerCache);
|
||||
});
|
||||
|
||||
|
||||
if(responseCache.containsKey(player)) {
|
||||
@@ -189,23 +183,18 @@ public class Placeholders extends PlaceholderExpansion {
|
||||
private String parsePlaceholder(Player player, String identifier) {
|
||||
if(identifier.equalsIgnoreCase("queued")) {
|
||||
plugin.sendMessage(player, "queuename", "");
|
||||
return null;
|
||||
}
|
||||
if(identifier.equalsIgnoreCase("position")) {
|
||||
plugin.sendMessage(player, "position", "");
|
||||
return null;
|
||||
}
|
||||
if(identifier.equalsIgnoreCase("of")) {
|
||||
plugin.sendMessage(player, "positionof", "");
|
||||
return null;
|
||||
}
|
||||
if(identifier.equalsIgnoreCase("inqueue")) {
|
||||
plugin.sendMessage(player, "inqueue", "");
|
||||
return null;
|
||||
}
|
||||
if(identifier.matches("queuedfor_*.*")) {
|
||||
plugin.sendMessage(player, "queuedfor", identifier.split("_")[1]);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,11 +3,12 @@ package us.ajg0702.queue.spigot;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class QueueScoreboardActivator extends Event {
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@@ -15,7 +16,7 @@ public class QueueScoreboardActivator extends Event {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
Player ply;
|
||||
final Player ply;
|
||||
|
||||
public QueueScoreboardActivator(Player p) {
|
||||
this.ply = p;
|
||||
|
||||
@@ -11,10 +11,10 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import us.ajg0702.queue.spigot.utils.VersionSupport;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class SpigotMain extends JavaPlugin implements PluginMessageListener,Listener {
|
||||
|
||||
boolean papi = false;
|
||||
@@ -22,6 +22,7 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List
|
||||
|
||||
Config config;
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void onEnable() {
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this, "ajqueue:tospigot", this);
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "ajqueue:toproxy");
|
||||
@@ -39,20 +40,18 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List
|
||||
getLogger().info("Registered PlaceholderAPI placeholders");
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
|
||||
public void run() {
|
||||
if(Bukkit.getOnlinePlayers().size() <= 0 || queuebatch.size() <= 0) return;
|
||||
String msg = "";
|
||||
for(Player p : queuebatch.keySet()) {
|
||||
if(p == null || !p.isOnline()) continue;
|
||||
msg += p.getName()+":"+queuebatch.get(p)+",";
|
||||
}
|
||||
if(msg.length() > 1) {
|
||||
msg = msg.substring(0, msg.length()-1);
|
||||
}
|
||||
queuebatch.clear();
|
||||
sendMessage("massqueue", msg);
|
||||
Bukkit.getScheduler().runTaskTimer(this, () -> {
|
||||
if(Bukkit.getOnlinePlayers().size() <= 0 || queuebatch.size() <= 0) return;
|
||||
StringBuilder msg = new StringBuilder();
|
||||
for(Player p : queuebatch.keySet()) {
|
||||
if(p == null || !p.isOnline()) continue;
|
||||
msg.append(p.getName()).append(":").append(queuebatch.get(p)).append(",");
|
||||
}
|
||||
if(msg.length() > 1) {
|
||||
msg = new StringBuilder(msg.substring(0, msg.length() - 1));
|
||||
}
|
||||
queuebatch.clear();
|
||||
sendMessage("massqueue", msg.toString());
|
||||
}, 2*20, 20);
|
||||
|
||||
config = new Config(this);
|
||||
@@ -60,10 +59,10 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List
|
||||
getLogger().info("Spigot side enabled! v"+getDescription().getVersion());
|
||||
}
|
||||
|
||||
HashMap<Player, String> queuebatch = new HashMap<>();
|
||||
final HashMap<Player, String> queuebatch = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
|
||||
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte[] message) {
|
||||
if (!channel.equals("ajqueue:tospigot")) return;
|
||||
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(message);
|
||||
@@ -133,7 +132,7 @@ public class SpigotMain extends JavaPlugin implements PluginMessageListener,List
|
||||
if(p == null) return;
|
||||
if(!p.isOnline()) return;
|
||||
|
||||
int number = Integer.valueOf(in.readUTF());
|
||||
int number = Integer.parseInt(in.readUTF());
|
||||
HashMap<String, String> phs = placeholders.responseCache.get(p);
|
||||
if(phs == null) phs = new HashMap<>();
|
||||
phs.put("queuedfor_"+queuename, number+"");
|
||||
|
||||
@@ -12,18 +12,15 @@ import java.lang.reflect.Method;
|
||||
*
|
||||
*/
|
||||
public class ActionBar {
|
||||
|
||||
private static String version;
|
||||
private static boolean old;
|
||||
|
||||
public static void send(Player player, String message) {
|
||||
public static void send(Player player, String message) {
|
||||
if(player == null) return;
|
||||
if(!player.isOnline()) return;
|
||||
|
||||
version = Bukkit.getServer().getClass().getPackage().getName();
|
||||
|
||||
String version = Bukkit.getServer().getClass().getPackage().getName();
|
||||
version = version.substring(version.lastIndexOf(".") + 1);
|
||||
|
||||
old = version.equalsIgnoreCase("v1_8_R1") || version.startsWith("v1_7_");
|
||||
boolean old = version.equalsIgnoreCase("v1_8_R1") || version.startsWith("v1_7_");
|
||||
|
||||
try {
|
||||
Class<?> craftPlayerClass = Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftPlayer");
|
||||
|
||||
Reference in New Issue
Block a user