Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding proxy allow-only-slash-servers-for-queueing config option #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/src/main/java/us/ajg0702/queue/api/Implementation.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public interface Implementation {
default void unregisterCommand(IBaseCommand command) {
unregisterCommand(command.getName());
}
void reload();
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void execute(ICommandSender sender, String[] args) {
main.getQueueManager().reloadServers();
main.getMessages().reload();
main.getSlashServerManager().reload();
main.getImplementation().reload();

main.getUpdater().setEnabled(main.getConfig().getBoolean("enable-updater"));

Expand Down
9 changes: 8 additions & 1 deletion common/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ remove-player-on-server-switch: false
# Default: false
enable-server-command: false

# When set: /queue and its aliases are not registered, making slash-servers commands the only way for players
# to queue-up.
# Warning: This setting only effects the proxy commands, if the plugin is also installed on your Bukkit server
# the queue command will still be available.
# Default: false
allow-only-slash-servers-for-queueing: false

# What servers should we make slash server commands for?
# For example, if survival is in this list, then if a player executes /survival
# then they will be put in the queue for survival
Expand Down Expand Up @@ -411,7 +418,7 @@ debug: false


# Don't touch this number please
config-version: 47
config-version: 48


# This is ONLY here so that they can be moved to messages.yml. Please edit these in messages.yml!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ public void onEnable() {
commands.add(new SendAlias(main));
}

for(IBaseCommand command : commands) {
registerCommand(command);
int i = main.getConfig().getBoolean("allow-only-slash-servers-for-queueing") ? 1 : 0;
for(; i < commands.size(); i++) {
registerCommand(commands.get(i));
}


Expand Down Expand Up @@ -185,6 +186,20 @@ public void registerCommand(IBaseCommand command) {
.registerCommand(this, bungeeCommand);
}

@Override
public void reload() {
boolean wantQueueCommandRegistered = !main.getConfig().getBoolean("allow-only-slash-servers-for-queueing");
if (wantQueueCommandRegistered != commandMap.containsKey(commands.get(0).getName())) {
if (!wantQueueCommandRegistered) {
main.getLogger().warn("Reload is unregistering /queue command");
unregisterCommand(commands.get(0).getName());
} else {
main.getLogger().warn("Reload is registering /queue command");
registerCommand(commands.get(0));
}
}
}

public QueueMain getMain() {
return main;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public VelocityQueue(ProxyServer proxyServer, Logger logger, @DataDirectory Path

List<IBaseCommand> commands;

private boolean isQueueCommandRegistered;

CommandManager commandManager;

@Subscribe
Expand Down Expand Up @@ -103,9 +105,10 @@ public void onProxyInit(ProxyInitializeEvent e) {
proxyServer.getChannelRegistrar().register(MinecraftChannelIdentifier.create("ajqueue", "tospigot"));
proxyServer.getChannelRegistrar().register(MinecraftChannelIdentifier.from("ajqueue:toproxy"));


for(IBaseCommand command : commands) {
registerCommand(command);
isQueueCommandRegistered = !main.getConfig().getBoolean("allow-only-slash-servers-for-queueing");
int i = isQueueCommandRegistered ? 0 : 1;
for(; i < commands.size(); i++) {
registerCommand(commands.get(i));
}


Expand Down Expand Up @@ -206,6 +209,22 @@ public void registerCommand(IBaseCommand command) {
);
}

@Override
public void reload() {
boolean wantQueueCommandRegistered = !main.getConfig().getBoolean("allow-only-slash-servers-for-queueing");
if (wantQueueCommandRegistered != isQueueCommandRegistered) {
if (!wantQueueCommandRegistered) {
main.getLogger().warn("Reload is unregistering /queue command");
unregisterCommand(commands.get(0).getName());
isQueueCommandRegistered = false;
} else {
main.getLogger().warn("Reload is registering /queue command");
registerCommand(commands.get(0));
isQueueCommandRegistered = true;
}
}
}

public QueueMain getMain() {
return main;
}
Expand Down