Skip to content

Commit 0555ba9

Browse files
committed
C:/Program Files/Git/queue on | off Now working
1 parent a026563 commit 0555ba9

7 files changed

Lines changed: 493 additions & 29 deletions

File tree

LICENSE

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<p align="center">
2+
<img width="460" height="300" src="https://cdn3.iconfinder.com/data/icons/jobless-claim/323/jobless-claim-001-512.png">
3+
</p>
4+
5+
# AdvancedBungeeQueue [![GitHub issues](https://img.shields.io/github/issues/CustomEntity/CustomCore)](https://github.com/CustomEntity/AdvancedBungeeQueue/issues) [![GitHub forks](https://img.shields.io/github/forks/CustomEntity/CustomCore)](https://github.com/CustomEntity/AdvancedBungeeQueue/network) [![GitHub stars](https://img.shields.io/github/stars/CustomEntity/CustomCore?color=yellow)](https://github.com/CustomEntity/AdvancedBungeeQueue/stargazers) [![GitHub license](https://img.shields.io/github/license/CustomEntity/CustomCore?color=GREEN)](https://github.com/CustomEntity/AdvancedBungeeQueue/blob/master/LICENSE)
6+
7+
Optimize your servers using this [queuing system](https://github.com/CustomEntity/AdvancedBungeeQueue/).
8+
9+
## Disclaimer
10+
AdvancedBungeeQueue is currently in pre-release. It is very likely that you will encounter bugs there. Please report any issue on GitHub.
11+
12+
<!-- TABLE OF CONTENTS -->
13+
## Table of Contents
14+
15+
* [About the Project](#about-the-project)
16+
* [Getting Started](#getting-started)
17+
* [Prerequisites](#prerequisites)
18+
* [Installation](#installation)
19+
* [Contributing](#contributing)
20+
* [License](#license)
21+
* [Contact](#contact)
22+
23+
24+
25+
<!-- ABOUT THE PROJECT -->
26+
## About The Project
27+
28+
<p align="center">
29+
<img src="https://pbs.twimg.com/media/EmZsbShWMAET2rj?format=png&name=small">
30+
</p>
31+
32+
AdvancedBungeeQueue is a queuing plugin that prevents a ton of players from connecting to one of your servers and causing lags. Compared to other plugins, it is very optimized and has many useful new features.
33+
34+
35+
36+
<!-- GETTING STARTED -->
37+
## Getting Started
38+
39+
40+
### Prerequisites
41+
42+
* A BungeeCord server
43+
* One or more spigot servers
44+
45+
### Installation
46+
47+
1. Get the .jar in the releases
48+
2. Allocate a special port for the queue if you have a firewall
49+
3. Configure the plugin to your liking
50+
4. Now enjoy it !
51+
52+
<!-- CONTRIBUTING -->
53+
## Contributing
54+
55+
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.
56+
57+
<!-- LICENSE -->
58+
## License
59+
60+
Distributed under the GPL License. See `LICENSE` for more information.
61+
62+
<!-- CONTACT -->
63+
## Contact
64+
65+
<img width="50" height="50" src="https://www.freepnglogos.com/uploads/discord-logo-png/concours-discord-cartes-voeux-fortnite-france-6.png"> **CustomEntity#6437**
66+
67+
<img width="50" height="50" src="https://assets.stickpng.com/thumbs/580b57fcd9996e24bc43c53e.png"> [**@EntityCustom**](https://twitter.com/EntityCustom)

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import org.apache.tools.ant.filters.ReplaceTokens
33
apply plugin: 'java'
44

55
group = 'fr.customentity'
6-
version = '1.0-SNAPSHOT'
6+
version = '0.1'
77

88
sourceCompatibility = '1.8'
99
targetCompatibility = '1.8'

src/main/java/fr/customentity/advancedbungeequeue/bungee/AdvancedBungeeQueue.java

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
import net.md_5.bungee.config.ConfigurationProvider;
1515
import net.md_5.bungee.config.YamlConfiguration;
1616

17-
import java.io.File;
18-
import java.io.IOException;
17+
import java.io.*;
18+
import java.net.URL;
19+
import java.net.URLConnection;
1920
import java.nio.file.Files;
2021
import java.util.*;
2122
import java.util.concurrent.TimeUnit;
@@ -65,6 +66,55 @@ public I18n getI18n() {
6566
return i18n;
6667
}
6768

69+
private InputStream getResource(String filename) {
70+
if (filename == null) {
71+
throw new IllegalArgumentException("Filename cannot be null");
72+
}
73+
74+
try {
75+
URL url = this.getClass().getClassLoader().getResource(filename);
76+
77+
if (url == null) {
78+
return null;
79+
}
80+
81+
URLConnection connection = url.openConnection();
82+
connection.setUseCaches(false);
83+
return connection.getInputStream();
84+
} catch (IOException ex) {
85+
return null;
86+
}
87+
}
88+
89+
public void saveResource(String resourcePath, boolean replace) {
90+
if (resourcePath == null || resourcePath.equals("")) return;
91+
92+
resourcePath = resourcePath.replace('\\', '/');
93+
InputStream in = getResource(resourcePath);
94+
if (in == null) return;
95+
96+
File outFile = new File(this.getDataFolder(), resourcePath);
97+
int lastIndex = resourcePath.lastIndexOf('/');
98+
File outDir = new File(this.getDataFolder(), resourcePath.substring(0, Math.max(lastIndex, 0)));
99+
100+
if (!outDir.exists()) {
101+
outDir.mkdirs();
102+
}
103+
104+
try {
105+
if (!outFile.exists() || replace) {
106+
OutputStream out = new FileOutputStream(outFile);
107+
byte[] buf = new byte[1024];
108+
int len;
109+
while ((len = in.read(buf)) > 0) {
110+
out.write(buf, 0, len);
111+
}
112+
out.close();
113+
in.close();
114+
}
115+
} catch (IOException ignore) { }
116+
}
117+
68118
private void saveDefaultConfig() {
69119
try {
70120
if (!this.getDataFolder().exists())

src/main/java/fr/customentity/advancedbungeequeue/bungee/command/QueueCommand.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void execute(CommandSender sender, String[] args) {
2121
plugin.sendConfigMessage(sender, "help");
2222
} else {
2323
if (args[0].equalsIgnoreCase("join")) {
24-
if(!sender.hasPermission(plugin.getConfigFile().getString("permissions.join-queue-command"))) {
24+
if (!sender.hasPermission(plugin.getConfigFile().getString("permissions.join-queue-command"))) {
2525
plugin.sendConfigMessage(sender, "commands.no-permission");
2626
return;
2727
}
@@ -39,45 +39,45 @@ public void execute(CommandSender sender, String[] args) {
3939
}
4040

4141
plugin.getQueueManager().addPlayerInQueue(proxiedPlayer, serverInfo);
42-
} else if(args[0].equalsIgnoreCase("on")) {
43-
if(!sender.hasPermission(plugin.getConfigFile().getString("permissions.on-queue-command"))) {
42+
} else if (args[0].equalsIgnoreCase("on")) {
43+
if (!sender.hasPermission(plugin.getConfigFile().getString("permissions.on-queue-command"))) {
4444
plugin.sendConfigMessage(sender, "commands.no-permission");
4545
return;
4646
}
47-
if(plugin.getQueueManager().isEnabled()) {
47+
if (plugin.getQueueManager().isEnabled()) {
4848
plugin.sendConfigMessage(sender, "commands.on.error");
4949
return;
5050
}
5151
plugin.getQueueManager().setEnabled(true);
5252
plugin.sendConfigMessage(sender, "commands.on.success");
53-
} else if(args[0].equalsIgnoreCase("off")) {
54-
if(!sender.hasPermission(plugin.getConfigFile().getString("permissions.off-queue-command"))) {
53+
} else if (args[0].equalsIgnoreCase("off")) {
54+
if (!sender.hasPermission(plugin.getConfigFile().getString("permissions.off-queue-command"))) {
5555
plugin.sendConfigMessage(sender, "commands.no-permission");
5656
return;
5757
}
58-
if(!plugin.getQueueManager().isEnabled()) {
58+
if (!plugin.getQueueManager().isEnabled()) {
5959
plugin.sendConfigMessage(sender, "commands.off.error");
6060
return;
6161
}
6262
plugin.getQueueManager().setEnabled(false);
6363
plugin.sendConfigMessage(sender, "commands.off.success");
64-
} else if(args[0].equalsIgnoreCase("pause")) {
65-
if(!sender.hasPermission(plugin.getConfigFile().getString("permissions.pause-queue-command"))) {
64+
} else if (args[0].equalsIgnoreCase("pause")) {
65+
if (!sender.hasPermission(plugin.getConfigFile().getString("permissions.pause-queue-command"))) {
6666
plugin.sendConfigMessage(sender, "commands.no-permission");
6767
return;
6868
}
69-
if(plugin.getQueueManager().isPaused()) {
69+
if (plugin.getQueueManager().isPaused()) {
7070
plugin.sendConfigMessage(sender, "commands.pause.error");
7171
return;
7272
}
7373
plugin.getQueueManager().setPaused(true);
7474
plugin.sendConfigMessage(sender, "commands.pause.success");
75-
}else if(args[0].equalsIgnoreCase("unpause")) {
76-
if(!sender.hasPermission(plugin.getConfigFile().getString("permissions.unpause-queue-command"))) {
75+
} else if (args[0].equalsIgnoreCase("unpause")) {
76+
if (!sender.hasPermission(plugin.getConfigFile().getString("permissions.unpause-queue-command"))) {
7777
plugin.sendConfigMessage(sender, "commands.no-permission");
7878
return;
7979
}
80-
if(!plugin.getQueueManager().isPaused()) {
80+
if (!plugin.getQueueManager().isPaused()) {
8181
plugin.sendConfigMessage(sender, "commands.unpause.error");
8282
return;
8383
}

src/main/java/fr/customentity/advancedbungeequeue/bungee/i18n/YamlResourceBundle.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
import net.md_5.bungee.config.ConfigurationProvider;
77
import net.md_5.bungee.config.YamlConfiguration;
88

9-
import java.io.File;
10-
import java.io.FileInputStream;
11-
import java.io.IOException;
12-
import java.io.InputStreamReader;
9+
import java.io.*;
10+
import java.net.URL;
11+
import java.net.URLConnection;
1312
import java.nio.file.Files;
1413
import java.util.Collections;
1514
import java.util.List;
1615
import java.util.Locale;
1716
import java.util.concurrent.ConcurrentHashMap;
1817
import java.util.concurrent.ConcurrentMap;
18+
import java.util.logging.Level;
1919

2020
public class YamlResourceBundle {
2121

@@ -50,7 +50,7 @@ private void setupYamlResource() {
5050
try {
5151
yamlFile = new File(plugin.getDataFolder(), this.fileName);
5252
if (!yamlFile.exists()) {
53-
Files.copy(plugin.getResourceAsStream(this.fileName), yamlFile.toPath());
53+
plugin.saveResource(this.fileName, true);
5454
}
5555
yamlConfig = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new InputStreamReader(new FileInputStream(yamlFile), Charsets.UTF_8));
5656
} catch (IOException e) {

src/main/java/fr/customentity/advancedbungeequeue/bungee/manager/QueueManager.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111

1212
import java.net.InetSocketAddress;
1313
import java.util.*;
14-
import java.util.concurrent.ConcurrentHashMap;
15-
import java.util.concurrent.ScheduledExecutorService;
16-
import java.util.concurrent.ScheduledThreadPoolExecutor;
17-
import java.util.concurrent.TimeUnit;
14+
import java.util.concurrent.*;
1815
import java.util.logging.Level;
1916

2017
public class QueueManager {
@@ -23,17 +20,24 @@ public class QueueManager {
2320

2421
private ConcurrentHashMap<ServerInfo, List<QueuedPlayer>> queue;
2522
private ScheduledExecutorService scheduledExecutorService;
23+
private List<ScheduledFuture<?>> scheduledFutures;
24+
2625
private boolean paused = false;
2726
private boolean enabled = true;
2827

2928
public QueueManager(AdvancedBungeeQueue plugin) {
3029
this.plugin = plugin;
3130
this.queue = new ConcurrentHashMap<>();
3231
this.scheduledExecutorService = new ScheduledThreadPoolExecutor(plugin.getConfigFile().getInt("thread-pool-size"));
32+
this.scheduledFutures = new ArrayList<>();
33+
34+
this.startQueue();
35+
}
3336

37+
public void startQueue() {
3438
this.loadServersQueue();
3539
for (ServerInfo serverInfo : queue.keySet()) {
36-
this.scheduledExecutorService.scheduleAtFixedRate(new ConnectRunnable(plugin, serverInfo), this.plugin.getConfigFile().getLong("queue-speed"), this.plugin.getConfigFile().getLong("queue-speed"), TimeUnit.MILLISECONDS);
40+
this.scheduledFutures.add(this.scheduledExecutorService.scheduleAtFixedRate(new ConnectRunnable(plugin, serverInfo), this.plugin.getConfigFile().getLong("queue-speed"), this.plugin.getConfigFile().getLong("queue-speed"), TimeUnit.MILLISECONDS));
3741
}
3842
}
3943

@@ -46,8 +50,12 @@ public boolean isEnabled() {
4650
}
4751

4852
public void setEnabled(boolean enabled) {
49-
if (!enabled) queue.clear();
50-
else loadServersQueue();
53+
if (!enabled) {
54+
queue.clear();
55+
this.scheduledFutures.forEach(scheduledFuture -> scheduledFuture.cancel(true));
56+
} else {
57+
this.startQueue();
58+
}
5159
this.enabled = enabled;
5260
}
5361

@@ -136,7 +144,7 @@ public void connectNextPlayers(ServerInfo serverInfo) {
136144
}
137145
queuedPlayer.setConnecting(true);
138146
queuedPlayer.getProxiedPlayer().connect(serverInfo, (result, error) -> {
139-
if(!result) {
147+
if (!result) {
140148
queuedPlayer.setConnecting(false);
141149
}
142150
}, ServerConnectEvent.Reason.PLUGIN);

0 commit comments

Comments
 (0)