Initial commit

This commit is contained in:
ajgeiss0702
2020-05-04 15:01:31 -07:00
commit 947eb195a3
34 changed files with 681 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ajQueue</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
+15
View File
@@ -0,0 +1,15 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.7
+4
View File
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
+116
View File
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>us.ajg0702</groupId>
<artifactId>ajQueue</artifactId>
<name>ajQueue</name>
<version>1.0.7</version>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>us.ajg0702.queue</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.14-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bungeecord-chat</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-config</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-event</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-protocol</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.14-SNAPSHOT</version>
<type>javadoc</type>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bungeecord-chat</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-config</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-event</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-protocol</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
+87
View File
@@ -0,0 +1,87 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>us.ajg0702</groupId>
<artifactId>ajQueue</artifactId>
<version>1.0.7</version>
<name>ajQueue</name>
<repositories>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.14-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.14-SNAPSHOT</version>
<type>javadoc</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bungeecord</artifactId>
<version>1.7</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<!-- Do not include the <configuration>...</configuration> part if you are using Sponge! -->
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<!-- Replace this with your package! -->
<shadedPattern>us.ajg0702.queue</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
+241
View File
@@ -0,0 +1,241 @@
package us.ajg0702.queue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.bstats.bungeecord.Metrics;
import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.ServerSwitchEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.event.EventHandler;
import us.ajg0702.queue.utils.BungeeMessages;
public class Main extends Plugin implements Listener {
int timeBetweenPlayers = 5;
int offlineSecs = 120;
Metrics metrics;
BungeeMessages msgs;
@Override
public void onEnable() {
msgs = BungeeMessages.getInstance(this);
this.getProxy().getPluginManager().registerCommand(this, new MoveCommand(this));
//this.getProxy().getPluginManager().registerCommand(this, new QueueCommand(this));
//this.getProxy().getPluginManager().registerCommand(this, new ServerCommand(this));
this.getProxy().getPluginManager().registerListener(this, this);
updateOnlineServers();
getProxy().getScheduler().schedule(this, new Runnable() {
public void run() {
updateOnlineServers();
sendPlayers();
}
}, 5, timeBetweenPlayers, TimeUnit.SECONDS);
metrics = new Metrics(this, 7404);
}
public static BaseComponent[] formatMessage(String text) {
return TextComponent.fromLegacyText(net.md_5.bungee.api.ChatColor.translateAlternateColorCodes('&', text));
}
HashMap<String, Integer> offlineTime = new HashMap<>();
boolean notif = false;
public void sendPlayers(String sv) {
for(String server : queues.keySet()) {
if(sv != null && !server.equalsIgnoreCase(sv)) continue;
List<ProxiedPlayer> plys = queues.get(server);
if(plys.size() <= 0) continue;
while(!plys.get(0).isConnected()) {
plys.remove(0);
if(plys.size() <= 0) break;
}
if(plys.size() <= 0) continue;
ProxiedPlayer p = plys.get(0);
if(!servers.get(server)) {
int ot;
if(!offlineTime.containsKey(server)) {
ot = timeBetweenPlayers;
} else {
ot = offlineTime.get(server)+timeBetweenPlayers;
}
offlineTime.put(server, ot);
for(ProxiedPlayer ply : plys) {
int pos = plys.indexOf(ply)+1;
int len = plys.size();
if(notif) {
String or = msgs.get("status.offline.restarting");
if(ot > offlineSecs) {
or = msgs.get("status.offline.offline");
} else {
//ply.sendMessage(formatMessage(ot + " <= "+offlineSecs));
}
ply.sendMessage(formatMessage(
msgs.get("status.offline.base")
.replaceAll("\\{STATUS\\}", or)
.replaceAll("\\{POS\\}", pos+"")
.replaceAll("\\{LEN\\}", len+"")
));
}
}
if(!notif) {
notif = true;
} else {
notif = false;
}
continue;
} else {
offlineTime.put(server, 0);
ServerInfo target = ProxyServer.getInstance().getServerInfo(server);
p.connect(target);
//plys.remove(p);
}
for(ProxiedPlayer ply : plys) {
int pos = plys.indexOf(ply)+1;
int len = plys.size();
if(notif) {
ply.sendMessage(formatMessage(
msgs.get("status.online.base")
.replaceAll("\\{POS\\}", pos+"")
.replaceAll("\\{LEN\\}", len+"")
));
}
}
if(!notif) {
notif = true;
} else {
notif = false;
}
}
}
public void sendPlayers() {
sendPlayers(null);
}
@EventHandler
public void moveServer(ServerSwitchEvent e) {
ProxiedPlayer p = e.getPlayer();
String queue = getPlayerInQueue(p);
if(queue != null) {
queues.get(queue).remove(p);
}
}
@EventHandler
public void onLeave(PlayerDisconnectEvent e) {
ProxiedPlayer p = e.getPlayer();
String queue = getPlayerInQueue(p);
if(queue != null) {
queues.get(queue).remove(p);
}
}
HashMap<String, Boolean> servers = new HashMap<>();
public void updateOnlineServers() {
for(final String server : getProxy().getServers().keySet()) {
if(!servers.containsKey(server)) {
servers.put(server, false);
}
getProxy().getServers().get(server).ping(new Callback<ServerPing>() {
@Override
public void done(ServerPing result, Throwable error) {
servers.put(server, error == null);
}
});
}
}
HashMap<String, List<ProxiedPlayer>> queues = new HashMap<>();
public void addToQueue(ProxiedPlayer p, String server) {
if(!servers.containsKey(server)) {
p.sendMessage(msgs.getBC("errors.server-not-exist"));
return;
}
if(!queues.containsKey(server)) {
queues.put(server, new ArrayList<ProxiedPlayer>());
}
if(p.getServer().getInfo().getName().equals(server)) {
p.sendMessage(msgs.getBC("errors.already-connected"));
return;
}
String currentQueued = getPlayerInQueue(p);
List<ProxiedPlayer> list = queues.get(server);
if(list.indexOf(p) != -1) {
int pos = list.indexOf(p)+1;
int len = list.size();
p.sendMessage(formatMessage(
msgs.get("errors.already-queued")
.replaceAll("\\{POS\\}", pos+"")
.replaceAll("\\{LEN\\}", len+"")
));
return;
}
if(currentQueued != null) {
queues.get(currentQueued).remove(p);
p.sendMessage(msgs.getBC("status.left-last-queue"));
}
if(p.hasPermission("ajqueue.priority") && list.size() > 0) {
int i = 0;
for(ProxiedPlayer ply : list) {
if(!ply.hasPermission("ajqueue.priority")) {
list.add(i, p);
break;
}
i++;
}
} else {
list.add(p);
}
int pos = list.indexOf(p)+1;
int len = list.size();
p.sendMessage(formatMessage(
msgs.get("status.now-in-queue")
.replaceAll("\\{POS\\}", pos+"")
.replaceAll("\\{LEN\\}", len+"")
));
if(list.size() == 1) {
sendPlayers(server);
}
}
public String getPlayerInQueue(ProxiedPlayer p) {
for(String server : queues.keySet()) {
if(queues.get(server).indexOf(p) != -1) {
return server;
}
}
return null;
}
}
@@ -0,0 +1,42 @@
package us.ajg0702.queue;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import us.ajg0702.queue.utils.BungeeMessages;
public class MoveCommand extends Command {
Main plugin;
BungeeMessages msgs;
public MoveCommand(Main pl) {
super("move", null, "queue", "server");
this.plugin = pl;
msgs = BungeeMessages.getInstance();
}
@Override
public void execute(CommandSender sender, String[] args) {
if(!(sender instanceof ProxiedPlayer)) {
sender.sendMessage(msgs.getBC("errors.player-only"));
return;
}
ProxiedPlayer p = (ProxiedPlayer) sender;
if(args.length > 0) {
if(args[0].equalsIgnoreCase("reload")) {
if(!sender.hasPermission("ajqueue.reload")) {
sender.sendMessage(msgs.getBC("noperm"));
return;
}
msgs.reload();
return;
}
plugin.addToQueue(p, args[0]);
} else if(args.length == 0) {
String queue = plugin.getPlayerInQueue((ProxiedPlayer) sender);
if(queue != null) {
plugin.queues.get(queue).remove(p);
p.sendMessage(msgs.getBC("commands.leave-queue"));
}
}
}
}
@@ -0,0 +1,99 @@
package us.ajg0702.queue.utils;
import java.io.File;
import java.io.IOException;
import java.util.LinkedHashMap;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
public class BungeeMessages {
static BungeeMessages INSTANCE = null;
public static BungeeMessages getInstance() {
return INSTANCE;
}
public static BungeeMessages getInstance(Plugin pl) {
if(INSTANCE == null) {
INSTANCE = new BungeeMessages(pl);
}
return INSTANCE;
}
Plugin pl;
ConfigurationProvider cv = ConfigurationProvider.getProvider(YamlConfiguration.class);
Configuration msgs;
File msgFile;
private BungeeMessages(Plugin pl) {
this.pl = pl;
loadMessagesFile();
}
private void loadMessagesFile() {
msgFile = new File(pl.getDataFolder(), "messages.yml");
if(!msgFile.exists()) {
try {
pl.getDataFolder().mkdirs();
msgFile.createNewFile();
} catch (IOException e) {
pl.getLogger().severe("Unable to create messages file:");
e.printStackTrace();
}
}
try {
msgs = cv.load(msgFile);
} catch (IOException e) {
pl.getLogger().severe("Unable to load messages file:");
e.printStackTrace();
return;
}
LinkedHashMap<String, String> d = new LinkedHashMap<>();
d.put("status.offline.base", "&cThe server you are queued for is {STATUS}. &7You are in position &f{POS}&7 of &f{LEN}&7.");
d.put("status.offline.offline", "offline");
d.put("status.offline.restarting", "restarting");
d.put("status.online.base", "&7You are in position &f{POS}&7 of &f{LEN}&7.");
d.put("status.left-last-queue", "&aYou left the last queue you were in.");
d.put("status.now-in-queue", "&aYou are now queued! &7You are in position &f{POS}&7 of &f{LEN}&7.");
d.put("errors.server-not-exist", "&cThat server does not exist!");
d.put("errors.already-queued", "&cYou are already queued! &7You are in position &f{POS}&7 of &f{LEN}&7.");
d.put("errors.player-only", "&cThis command can only be executed as a player!");
d.put("errors.already-connected", "&cYou are already connected to this server!");
d.put("commands.leave-queue", "&aYou left the queue!");
d.put("noperm", "&cYou do not have permission to do this!");
for(String k : d.keySet()) {
if(!msgs.contains(k)) {
msgs.set(k, d.get(k));
}
}
try {
cv.save(msgs, msgFile);
} catch (IOException e) {
pl.getLogger().severe("Unable to save messages file:");
e.printStackTrace();
}
}
public String get(String key) {
String msg = msgs.get(key, "&cMessage '"+key+"' does not exist!");
msg = net.md_5.bungee.api.ChatColor.translateAlternateColorCodes('&', msg);
return msg;
}
public BaseComponent[] getBC(String key) {
String m = get(key);
return TextComponent.fromLegacyText(m);
}
public void reload() {
loadMessagesFile();
}
}
+4
View File
@@ -0,0 +1,4 @@
name: ajQueue
version: ${project.version}
main: us.ajg0702.queue.Main
author: ajgeiss0702
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4
View File
@@ -0,0 +1,4 @@
name: ajQueue
version: 1.0.7
main: us.ajg0702.queue.Main
author: ajgeiss0702
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
#Generated by Maven
#Mon May 04 14:52:04 MST 2020
version=1.0.7
groupId=us.ajg0702
artifactId=ajQueue
@@ -0,0 +1,3 @@
/home/aiden/eclipse-workspace/ajQueue/src/main/java/us/ajg0702/queue/Main.java
/home/aiden/eclipse-workspace/ajQueue/src/main/java/us/ajg0702/queue/MoveCommand.java
/home/aiden/eclipse-workspace/ajQueue/src/main/java/us/ajg0702/queue/utils/BungeeMessages.java
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.