alexmcs
/
ServerStopper
Archived
0
0
Fork 0

More progress on 1.1

Notably, take a look at the new yaml files in resources!
master
(someone) 8 years ago
parent 8558c89871
commit 8c87b9f830

@ -3,7 +3,6 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/ServerStopper.iml" filepath="$PROJECT_DIR$/ServerStopper.iml" />
<module fileurl="file://$PROJECT_DIR$/ServerStopper-maven.iml" filepath="$PROJECT_DIR$/ServerStopper-maven.iml" />
</modules>
</component>
</project>

@ -21,7 +21,7 @@
</plugin>
</plugins>
</build>
<repositories>
<!-- Spigot repo -->

@ -1,10 +1,14 @@
package net.alexmcs.bukkit.serverstopper;
import org.bukkit.Bukkit;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
/**
* ServerStopper
@ -13,9 +17,31 @@ import java.io.File;
*/
public class ConfigManager {
// ConfigManager can locate the plugin from a static context with this. I'm not sure if this is really the best place for this, but I also don't really give a fuck.
static Plugin thisPlugin = Bukkit.getPluginManager().getPlugin("ServerStopper");
static void loadConfiguration() {
thisPlugin.getDataFolder().mkdirs(); // This creates the config directory if it doesn't already exist. Using an if like done below for config.yml is probably more proper, but this works fine and I'm lazy.
File config = new File(thisPlugin.getDataFolder(), "config.yml");
// The ability to focus is something I do not possess.
// If the configuration does not exist, create it.
if (!config.exists()) {
thisPlugin.getLogger().warning("The config does not exist. Creating it.");
try {
config.createNewFile();
InputStream defaultConfig = (thisPlugin.getResource("/bukkit-config.yml"));
Files.copy(defaultConfig, config.getAbsoluteFile().toPath());
} catch (IOException e) {
throw new RuntimeException("Unable to write config", e);
}
}
// Load translations
Translations.loadTranslations();
}
}

@ -22,7 +22,10 @@ public class MainClass extends JavaPlugin implements Listener {
this.getCommand("serverstopper").setExecutor(new CommandServerstopper());
// see apiDetector()
apiDetector();
// apiDetector(); // Move this to ConfigManager
// What could possibly go wrong??????????????????
ConfigManager.loadConfiguration();
// Informational
getLogger().info("Enabled ServerStopper");
@ -43,7 +46,7 @@ public class MainClass extends JavaPlugin implements Listener {
// This method is in charge of detecting the other available APIs that the plugin supports and setting the plugin up for them.
// This should probably be moved to ConfigManager so it can be easily reloaded.
// This should probably be moved to ConfigManager so it can be easily reloaded.
// Yes, yes it should.
private void apiDetector() {
// BossBarAPI

@ -62,7 +62,7 @@ class StopManager {
// Issue the "minecraft:stop" command from the console.
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "minecraft:stop");
}
}.runTask(Bukkit.getPluginManager().getPlugin("ServerStopper"));
}.runTask(ConfigManager.thisPlugin);
break;
}
// Subtract one from the clock...
@ -107,7 +107,7 @@ class StopManager {
// Call the stopLoop() method to get the while loop started.
StopManager.stopLoop();
}
}.runTaskAsynchronously(Bukkit.getPluginManager().getPlugin("ServerStopper"));
}.runTaskAsynchronously(ConfigManager.thisPlugin);
}
}
@ -121,7 +121,7 @@ class StopManager {
// Do a broadcast. :)
Bukkit.broadcastMessage(broadcastPrefix + preNumberTranslation + numberColor + Integer.toString(remain) + postNumberTranslation);
}
}.runTask(Bukkit.getPluginManager().getPlugin("ServerStopper"));
}.runTask(ConfigManager.thisPlugin);
}
}

@ -0,0 +1,87 @@
package net.alexmcs.bukkit.serverstopper;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
/**
* ServerStopper
* net.alexmcs.bukkit.serverstopper.Translations
* An extension of ConfigManager that does the same thing, but for translations.
* This is in a separate class mostly just to make it easier to call from other classes to get strings.
*/
public class Translations {
// Wow! Look at all those strings!
// See the comments in the bukkit-translations.yml resource for the commented key for information on each String.
static String broadcastPrefix; // chat-broadcast.prefix
static String broadcastWarning; // chat-broadcast.warning
static String broadcastNotify; // chat-broadcast.notify
static String broadcastCancel; // chat-broadcast.cancel
static String bossbarWarning; // bossbar-warning
static String tmActionbarWarning; // titles.actionbar-warning
static String tmSubtitleWarning; // titles.subtitle-warning
static String tmTitleWarning; // titles.title-warning
static String tmTabFooterWarning; // titles.tabfoot-warning
static String errorPrefix; // error.prefix
static String errorPermission; // error.permission-generic
static String errorPermissionStop; // error.permission-stop
static String errorPermissionNow; // error.permission-now
static String errorPermissionCancel; // error.permission-cancel
static String errorUnknownCommand; // error.unknown-command
static String errorNotImplemented; // error.not-implemented
static String help1; // help.1
static String help2; // help.2
static String help3; // help.3
static String help4; // help.4
static String help5; // help.5
static String help6; // help.6
static String help7; // help.7
static String help8; // help.8
static String help9; // help.9
static String help10; // help.10
static String aboutTranslator; // about.translator
static String aboutHelp; // about.help
static String aboutUri; // about.uri
// Store these values in ProxyHelper class?
static String phBossbarWarning; // bungeecord.bossbar-warning
static String phTmTitlebarWarning; // bungeecord.titlebar-warning
static String phTmSubtitleWarning; // bungeecord.subtitle-warning
static String phTmTitleWarning; // bungeecord.title-warning
static String phTmTabFooterWarning; // bungeecord.tabfoot-warning
// Load up those bitches!
static void loadTranslations() {
// thisPlugin.getDataFolder().mkdirs(); // This is called long after ConfigManager does this. No need.
File config = new File(ConfigManager.thisPlugin.getDataFolder(), "translations.yml");
// The ability to focus is something I do not possess.
// If the configuration does not exist, create it.
if (!config.exists()) {
ConfigManager.thisPlugin.getLogger().warning("The config does not exist. Creating it.");
try {
config.createNewFile();
InputStream defaultConfig = (ConfigManager.thisPlugin.getResource("/bukkit-translations.yml"));
Files.copy(defaultConfig, config.getAbsoluteFile().toPath());
} catch (IOException e) {
throw new RuntimeException("Unable to write config", e);
}
}
}
}

@ -0,0 +1,83 @@
# ServerStopper for Bukkit/Spigot/Paper
# Main configuration file (config.yml)
# Default shutdown delay in seconds when calling /stop
delay: 60
# Default time units when calling /stop <integer> in multiples of seconds. (1 for seconds, 60 for minutes, 3600 for hours)
timeunits: 60
# Minimum delay in seconds. Any attempt to stop with a delay lower than this will not be processed. Does not apply to /stop now
min-delay: 30
# Use generic permissions errors for all permission fails.
generic-permission-errors: false
# Simple chat warnings
warnings:
# Chat warning intervals in seconds
intervals: [3600,1800,900,600,300,60,30,15]
# This is the final countdown in seconds. All integers lower than this (and higher than 0) will be announced.
countdown: 10
# BossBarAPI support
bossbar:
# Set enabled: false if you do not want to use BossBarAPI to show the shutdown warnings.
enabled: true
# The BossBar mode. Supports "simple" or "colorshift". For help on using the "colorshift" mode, see <insert link>
mode: "simple"
# Countdown in seconds. The bossbar will show and count down from this to 0 before a shutdown.
simple-countdown: 60
# TitleManager API support
titles:
# Set enabled: false if you do not want to use TitleManager API to show the shutdown warnings.
enabled: true
# Action bar intervals. The action bar will appear briefly at these intervals in seconds.
actionbar-intervals: [3600,1800,900,600]
# Action bar countdown. The action bar will appear and count down from max to min in seconds.
actionbar-countdown-max: 60
actionbar-countdown-min: 16
# Subtitle intervals. The subtitle will appear briefly at these intervals in seconds.
subtitle-intervals: [300, 60, 30]
# Subtitle countdown. The subtitle will appear and count down from max to min in seconds.
subtitle-max: 15
subtitle-min: 0
# Main title countdown. The main title will appear and count down from max to min in seconds. I recommend making title-min and subtitle-min the same due to the limited space on the main title.
title-max: 10
title-min: 0
# Display countdown in tab footer? This will be always-on if the server is stopping.
tabfoot: true
# These features currently support TitleManager by Puharesource. If your favourite title manager plugin is not supported and has an API, let me know and I'll attempt to add it!
# ProxyStopper integration (requires ProxyStopper v1.1+ and ServerStopper v1.2+)
bungeecord:
# Set enabled: true if you are using ProxyStopper for BungeeCord and want ServerStopper to handle bossbar and titles for it.
enabled: false
# The bossbar settings, if enabled, are shared with this instance of ServerStopper
bossbar: true
# The titles settings, if enabled, are shared with this instance of ServerStopper, excepting tabfoot.
titles: true
# Display proxy countdown in tab footer? Requires titles: true above.
tabfoot: true
# DANGER ZONE! Untested options. Don't change if you're not prepared for things to break.
# Notify everyone with a broadcast when a restart is first initialized?
notify: true # Disabling this option might be a little buggy right now. I haven't properly tested it.
# If true, time units like hours, minutes, seconds, or now will be calculated. Otherwise, all time will be displayed in seconds.
timeunits: false # This option might be a little buggy right now. I haven't properly tested it.
# These options may have been stablized and moved into the above secion in a later version of ProxyStopper. Check the wiki page for more information.
# config-version is used internally. DO NOT ALTER.
config-version: "SNAPSHOT"

@ -0,0 +1,84 @@
# ServerStopper for Bukkit/Spigot/Paper
# Translation file (translation.yml)
# You can change this file if you want to translate ServerStopper to a different language, or just customize the strings.
# Make sure to leave trailing spaces intact where present in the original file to avoid things getting squished together.
# Main chat broadcast translations
chat-broadcast:
# The prefix used for all chat broadcasts. The default mimics Essentials' /broadcast format
prefix: "&6[&4Broadcast&6]&a "
# The warning broadcast at scheduled intervals and during countdown.
warning: "&4&lATTENTION&a: The server will be restarting in &6&l{count}&a {timeunits}."
# The initial notification when someone initiates a restart.
notify: "{displayname}&a has initiated a server restart. The server will restart in &6&l{timecount}&a {timeunits}."
# The restart cancelation notification.
cancel: "{displayname}&a has canceled the server restart. The server will not restart."
# BossBarAPI translation
bossbar-warning: "&aThe server will be restarting in &6&l{count}&a {timeunits}."
# TitleManager translations, not to be confused with the titles section of config.yml
titles:
# Action bar text
actionbar-warning: "&aThe server will be restarting in &6&l{count}&a {timeunits}."
# Subtitle text
subtitle-warning: "&aThe server will be restarting in &6&l{count}&a {timeunits}."
# Title text
title-warning: "&aServer restart: &6&l{count}&a {timeunits}"
# Tab footer text
tabfoot-warning: "&aServer restart: &6&l{count}&a {timeunits}"
# Error handling
error:
prefix: "&4&lERROR&r: "
permission-generic: "You do not have permission to do that."
permission-stop: "You do not have permission to stop the server."
permission-now: "You do not have permission to stop the server immediately."
permission-cancel: "You do not have permission to cancel a server stop."
unknown-command: "Unknown argument(s). See /serverstopper help"
not-implemented: "This feature is not implemented yet."
# Help (the first line with the version string cannot be changed from here)
help:
1: "&cTo stop the server, use &b&l/stop"
2: "&cTo stop the server immediately, use &b&l/stop now"
3: "&cTo cancel a pending server stop, use &b&l/stop cancel"
4: "&cTo stop the server in a certain amount of time, use &b&l/stop <time> [units]"
5: "&cTo learn more about ServerStopper, use &b&l/serverstopper info"
6: "&cTo reload the ServerStopper configuration, use /serverstopper reload"
# Supports up to ten lines. Leave extra unneeded lines blank. All lines after the first blank line will be skipped.
7: ""
8: ""
9: ""
10: ""
# Adjustable about fields. You cannot change the version or author lines from here.
about:
# translator line will be added below the author line. Leave blank to disable. Use for "Translated by Yourname" or "Yournetwork Edition" messages.
translator: ""
help: "&aTo learn how to use ServerStopper, do &b&l/serverstopper help&a."
uri: "&cMore information: &9http://gitlab.com/AlexMCS/ServerStopper/"
# Translations for ProxyStopper integration, not to be confused with the bungeecord section of config.yml
# All other ProxyStopper translations should be done in the ProxyStopper configuration.
bungeecord:
# BossBarAPI Proxy translation
bossbar-warning: "&aThe proxy will be restarting in &6&l{count}&a {timeunits}."
# Action bar text
actionbar-warning: "&aThe proxy will be restarting in &6&l{count}&a {timeunits}."
# Subtitle text
subtitle-warning: "&aThe proxy will be restarting in &6&l{count}&a {timeunits}."
# Title text
title-warning: "&aProxy restart: &6&l{count}&a {timeunits}"
# Tab footer text
tabfoot-warning: "&aProxy restart: &6&l{count}&a {timeunits}"
# You're all done here. If you've translated ServerStopper to another language and you want to contribute your translations for others to use, see <insert link>
# translation-version is used internally. DO NOT ALTER!
translation-version: "SNAPSHOT"