Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29d9fa2ec8 | ||
|
|
ef2ce99746 | ||
|
|
aa5437605f | ||
|
|
22e1d53f81 | ||
|
|
1359684c72 | ||
|
|
22c53bd4ff | ||
|
|
c0e2586684 | ||
|
|
2f095f32ca | ||
|
|
e1e4926f83 | ||
|
|
55b5bf2714 | ||
|
|
5f8f885530 | ||
|
|
fc40b0230d | ||
|
|
6fb79d7051 | ||
|
|
7bc522c1d3 | ||
|
|
8d0d97c220 | ||
|
|
e7c8430909 | ||
|
|
1646d4e417 | ||
|
|
f8384f4f99 | ||
|
|
4fd6ba33ff | ||
|
|
94c146d0e9 | ||
|
|
c624b18b8e | ||
|
|
18a00f9054 | ||
|
|
9778a900a7 | ||
|
|
21fa6a3b7f | ||
|
|
c7980cbc86 | ||
|
|
cdb6715744 | ||
|
|
d868f069cc | ||
|
|
c58b29a78f | ||
|
|
5fb4f06f4c | ||
|
|
8a3afdd1a8 | ||
|
|
36e561c413 | ||
|
|
4739176e9b | ||
|
|
9546cc7b74 | ||
|
|
740051dda5 | ||
|
|
e53f4f2518 | ||
|
|
03390d7be9 | ||
|
|
039c5a3d04 | ||
|
|
4360eb03e3 | ||
|
|
89691e8064 | ||
|
|
8f4860ad56 | ||
|
|
b8b231ce78 | ||
|
|
fd8b47a9f5 | ||
|
|
10c0b5bab3 | ||
|
|
cece2b5813 | ||
|
|
aa9a686b8a | ||
|
|
f29b38989c | ||
|
|
ad9c989213 | ||
|
|
f01e96a32a | ||
|
|
e247f4ef10 | ||
|
|
b8e0f84d54 | ||
|
|
424617c602 | ||
|
|
21ed266d3d | ||
|
|
a409ec5d66 | ||
|
|
66cba12fd3 | ||
|
|
f6d178d8d1 | ||
|
|
d04749c835 | ||
|
|
eebbc4d532 | ||
|
|
335fe303b5 | ||
|
|
1c4b5e62a4 | ||
|
|
d41fa5ab24 | ||
|
|
7fd486ef40 | ||
|
|
d0b10f2524 | ||
|
|
865df5e20a | ||
|
|
469e8eb57b | ||
|
|
368ac37099 | ||
|
|
0db4d77c10 | ||
|
|
ca4c711103 | ||
|
|
f4a5f288ca | ||
|
|
0a37bfdefe | ||
|
|
3a30dba011 | ||
|
|
111a229d48 | ||
|
|
7e948fbe52 | ||
|
|
355aa20244 | ||
|
|
6bc54d1812 | ||
|
|
0042ce3ccd | ||
|
|
beb0e52371 | ||
|
|
4774ec2f2a | ||
|
|
34115f443e | ||
|
|
c8f0c1699e | ||
|
|
f22be77023 | ||
|
|
730a8dbeea | ||
|
|
0548e0c447 | ||
|
|
da0a757c5e | ||
|
|
ac19bac11c | ||
|
|
1de926bb28 | ||
|
|
94308cde7c | ||
|
|
d863c709e1 | ||
|
|
741914283a | ||
|
|
64902d90ff | ||
|
|
d3b4c7c87b | ||
|
|
390b65a70e | ||
|
|
7cff908aae | ||
|
|
d1f049c3e5 | ||
|
|
8d552dbe33 | ||
|
|
d3a933d21d | ||
|
|
a4d87dabf5 | ||
|
|
c3b579e86c | ||
|
|
b75d2337df | ||
|
|
b3e83c5c2e | ||
|
|
b6f447aded | ||
|
|
9febdfc140 | ||
|
|
90bc30d701 | ||
|
|
843ba4ac86 | ||
|
|
032fd7d582 | ||
|
|
9a0f680177 | ||
|
|
415d5f3807 | ||
|
|
33c96de5fb | ||
|
|
d141b40190 | ||
|
|
77e1444dba | ||
|
|
915b43d897 | ||
|
|
adc06e3486 | ||
|
|
cc7f5c2d11 | ||
|
|
0bb54ffc5d | ||
|
|
15ee2e6074 | ||
|
|
89abab36f8 | ||
|
|
e0bb1336b0 | ||
|
|
888ffd301a | ||
|
|
3a55dd3280 | ||
|
|
61c47ba2fa | ||
|
|
b97e69a71f | ||
|
|
75c940d089 | ||
|
|
849fa2a720 | ||
|
|
7e249faa99 | ||
|
|
c8272b39d5 | ||
|
|
b3c561ae26 | ||
|
|
af24c5a331 | ||
|
|
4cc162f00d | ||
|
|
02610fd904 | ||
|
|
bccd1bb936 | ||
|
|
c08dd5d430 | ||
|
|
1104a50882 | ||
|
|
56898d7b40 | ||
|
|
4be31a6dd4 | ||
|
|
190a063d49 | ||
|
|
6e4591d45b | ||
|
|
86c556e841 | ||
|
|
404e14ee94 | ||
|
|
b8c0e3a799 | ||
|
|
10d798acd4 | ||
|
|
be057f4b3b | ||
|
|
eea7a595c9 | ||
|
|
bf4bf79b23 | ||
|
|
686535228e | ||
|
|
8b645b6f79 | ||
|
|
4d97293a8c | ||
|
|
c746a83f5f | ||
|
|
eb7e6e3f0b | ||
|
|
f5ce41853f | ||
|
|
e67cde591c | ||
|
|
39682635c6 | ||
|
|
efee532742 | ||
|
|
0aee3a8fd6 | ||
|
|
f79b6caccb | ||
|
|
73fd80b456 | ||
|
|
ad1a7eb420 | ||
|
|
bfa9b52497 | ||
|
|
ff4b5b0d2e | ||
|
|
b8e73062fa | ||
|
|
863a9b3beb | ||
|
|
fe64936ddf | ||
|
|
0c524b227a | ||
|
|
35deabf5a3 | ||
|
|
694cbb729f | ||
|
|
57047c519e | ||
|
|
fc8018c530 | ||
|
|
73707e2c3a | ||
|
|
ac92851e3d | ||
|
|
4e29a98a32 | ||
|
|
54d1c90795 | ||
|
|
6780914550 | ||
|
|
5ab5d11aed | ||
|
|
94378ca1fa | ||
|
|
4c0c425ba0 | ||
|
|
efea58e665 | ||
|
|
e15a7dd0ed | ||
|
|
2f327b9ce9 | ||
|
|
38d0f9de6d | ||
|
|
75f7330cc3 | ||
|
|
25bf7a3747 | ||
|
|
f8f0a23ede | ||
|
|
b4d7ed59de | ||
|
|
f64d07c1e8 | ||
|
|
4dc31a4635 | ||
|
|
cb243e1c04 | ||
|
|
bb5bdfe0c7 | ||
|
|
be144df5de | ||
|
|
a6f68810fc | ||
|
|
3ac01c9f1b | ||
|
|
c9d496e251 | ||
|
|
be31fdeb0a | ||
|
|
1ced445742 | ||
|
|
e52fffbe75 | ||
|
|
25b4cfe3f2 | ||
|
|
bc8453a96e | ||
|
|
0379b0c62c | ||
|
|
cdf34b76b8 | ||
|
|
d3cc9eb989 | ||
|
|
3048483b0c | ||
|
|
f16a5800e5 | ||
|
|
672f1f0ff3 | ||
|
|
a3ddfbefe3 | ||
|
|
e548a9a94b | ||
|
|
80d3069ffb | ||
|
|
fad9824e4d | ||
|
|
2bb7e3023d | ||
|
|
105f76d8f4 | ||
|
|
8e7874b691 | ||
|
|
710a69543a | ||
|
|
8b180342d0 | ||
|
|
1a62c596cb | ||
|
|
2b8e2c90c3 | ||
|
|
dcb9c97d0a | ||
|
|
74ed8783a8 | ||
|
|
0d07e6aed3 | ||
|
|
49fa7a6ff7 | ||
|
|
f40df14d03 | ||
|
|
6bc63e3fde | ||
|
|
c0b6e8ff40 | ||
|
|
0a4a1ce0cf | ||
|
|
35fd75aebb | ||
|
|
59e8dc057a | ||
|
|
91cd767dd7 | ||
|
|
57ca1ff88c | ||
|
|
15dd00fdcc | ||
|
|
10b14de218 | ||
|
|
66899564e8 | ||
|
|
6e8d8319f7 | ||
|
|
3ad8be9d3e | ||
|
|
b7c175060d | ||
|
|
ba6043e654 | ||
|
|
4bfd3339a2 | ||
|
|
c03d8d45e0 | ||
|
|
b150db8047 | ||
|
|
197ff4f813 | ||
|
|
fc6a5f8747 | ||
|
|
a4a37b39e5 | ||
|
|
b057b88e26 | ||
|
|
2dd383a640 | ||
|
|
d6526ae64e | ||
|
|
8be8b831ba | ||
|
|
ff1ded1fda | ||
|
|
bcc77cf3e0 | ||
|
|
4213d0824f | ||
|
|
729722259a | ||
|
|
6c408d823a | ||
|
|
9b7ec9d8bf | ||
|
|
3cce54a62d | ||
|
|
40119254a7 | ||
|
|
4b33e69d11 | ||
|
|
90d08d651e | ||
|
|
11b73a05c8 | ||
|
|
b68c8dd0d8 | ||
|
|
8933caa51f | ||
|
|
e82b1f760a | ||
|
|
dc97079967 | ||
|
|
2e44decaa9 | ||
|
|
244f7efe21 | ||
|
|
d299db678d | ||
|
|
0e558af1f1 | ||
|
|
a6cd5978e3 | ||
|
|
24c893bb1d | ||
|
|
8a80446c8c | ||
|
|
a88cc02f9a | ||
|
|
df442063ea | ||
|
|
40c49ba3ee | ||
|
|
9135f817d1 | ||
|
|
07fc9894b1 | ||
|
|
930612b5bb | ||
|
|
29a87c831a | ||
|
|
722340140a | ||
|
|
96d4834f83 | ||
|
|
308b42948a | ||
|
|
8e304bb09d | ||
|
|
7f2c23e69e | ||
|
|
1d68c4fee0 | ||
|
|
3d808ea718 | ||
|
|
79f1933b9a | ||
|
|
4089e75f2d | ||
|
|
a2d4e12ca6 | ||
|
|
72e5d596fc | ||
|
|
4f2dea5036 | ||
|
|
915dc25284 | ||
|
|
13e4468e93 | ||
|
|
ca23f0d546 | ||
|
|
53c450170a | ||
|
|
348521cc3e | ||
|
|
f4ce887d24 | ||
|
|
5e176dc10e | ||
|
|
00cd9a8bb1 | ||
|
|
0166aeadb2 | ||
|
|
864c22c3ed | ||
|
|
910b88d663 | ||
|
|
4a56c28a0d | ||
|
|
1c13465bf4 | ||
|
|
f4d46f03aa | ||
|
|
5b3e3ef179 | ||
|
|
392b12e592 | ||
|
|
e99f7772e6 | ||
|
|
54d20e9e50 | ||
|
|
fd0e361474 | ||
|
|
551e38f882 | ||
|
|
d18f04c010 | ||
|
|
3b7f3043f1 | ||
|
|
faf2a8d083 | ||
|
|
42071e3bad | ||
|
|
978d32e947 | ||
|
|
fe670cb3e2 | ||
|
|
d2f4a7d9a5 | ||
|
|
b162ce1825 | ||
|
|
fbdcce3c3b | ||
|
|
2d939f095c | ||
|
|
034e2f2b98 | ||
|
|
f429ab0a60 | ||
|
|
5578d0879b | ||
|
|
8b1e6244ea | ||
|
|
49c7b9c775 | ||
|
|
da1c724464 | ||
|
|
de15150a04 | ||
|
|
0d1fb2b260 | ||
|
|
55d0779a33 | ||
|
|
8f41d464e1 | ||
|
|
1db2b6c934 | ||
|
|
aa58f76057 | ||
|
|
1def0a1061 | ||
|
|
3b4a66b04e | ||
|
|
7384b2e55c | ||
|
|
f8eaed445a | ||
|
|
dfef9190ca | ||
|
|
7ce61834c2 | ||
|
|
240a7ab242 | ||
|
|
b3de59bfba | ||
|
|
5d5de39845 | ||
|
|
59af774d09 | ||
|
|
18828207c0 | ||
|
|
5c67922996 | ||
|
|
af50a45e65 | ||
|
|
7ccd265a30 | ||
|
|
e76f22f071 | ||
|
|
3c03b719d2 | ||
|
|
cd71531766 | ||
|
|
282c116d02 | ||
|
|
820171916b | ||
|
|
136fbb0ba8 | ||
|
|
4f0c05c357 | ||
|
|
0377838a26 | ||
|
|
b72ff1b772 | ||
|
|
287488f1b6 | ||
|
|
9ffb67db1f | ||
|
|
a563c0a8a8 | ||
|
|
234086444f | ||
|
|
a93b0834a2 | ||
|
|
b5550dfe82 | ||
|
|
d99300ecac | ||
|
|
1c0688a172 | ||
|
|
ff3b117189 | ||
|
|
aaed1b32cd | ||
|
|
38c8e1d2c3 | ||
|
|
1e1792d132 |
No files matched your search
@@ -0,0 +1,239 @@
|
||||
# Maintenance Changelog
|
||||
This file contains update logs for this project. The top may contain a `Unreleased` section, gathering update logs for a future update during development.
|
||||
|
||||
---
|
||||
## 3.0.6 - February 17th 2021
|
||||
### Changed
|
||||
* Updated the Velocity version to be compatible with Velocity 1.1.0 (use Maintenance 3.0.5 if you use an older version of Velocity)
|
||||
* Added `maintenance schedule <minutes> <duration> command`
|
||||
* This starts a timer for maintenance to be enabled, after which another timer will be started to disable it again (in contrast to `starttimer` and `endtimer`, which each only do one of)
|
||||
* On proxies, you can use `maintenance schedule [server] <minutes> <duration> command` to schedule maintenance on a proxied server
|
||||
* Added command alias `mt` for the Maintenance command
|
||||
* Added secret argument to the whitelist add command: You can use `maintenance add <uuid> <name>` to add offline entries per command
|
||||
* The maintenance's base command is now properly registered with a permission on each platform, so that it is excluded from tabcomplection to unauthorized players
|
||||
* Some improvements to the French language file (thanks to @Aurelien30000)
|
||||
* API addition: Added MaintenanceReloadedEvent
|
||||
* If you are using the MaintenancePlaceholderAddon, you need to [update it to 1.0.4](https://github.com/KennyTV/MaintenanceAddon/releases)
|
||||
### Fixed
|
||||
* Fixed not setting custom singleserver kickmessages throwing warnings
|
||||
* Bungee: Fixed linebreaks in the playercount hovermessage for 1.16+ clients
|
||||
---
|
||||
## 3.0.5 - June 17th 2020
|
||||
### Changed
|
||||
* The plugin identifiers are now `Maintenance` instead of the previous `MaintenanceSpigot` and `MaintenanceBungee`,
|
||||
and `maintenance` instead of `maintenancesponge` and `maintenancevelocity`
|
||||
* The plugin directory will automatically be renamed accordingly when starting the server
|
||||
* If you are using the MaintenancePlaceholderAddon, you need to [update it to 1.0.3](https://github.com/KennyTV/MaintenanceAddon/releases)
|
||||
* Bungee/Velocity: The `fallback` field can now also be set as a list to define multiple fallback servers
|
||||
* Bungee/Velocity: Added language fields to choose custom kickmessages for individual proxied servers
|
||||
* See [**HERE**](https://github.com/KennyTV/Maintenance/wiki/Configuration#language-file) for an example setting
|
||||
* Added Chinese language file (thanks to Spigot user yeban)
|
||||
* Added Italian language file (thanks to @TheViperShow)
|
||||
* Updated Russian language file (thanks to Spigot user En_0t_S)
|
||||
* Removed automated config migration from 2.x->3.0
|
||||
* See [**HERE**](https://github.com/KennyTV/Maintenance/wiki/Updates#updating-from-2x) on how to do that manually - virtually noone should be using such old versions anymore
|
||||
### Fixed
|
||||
* Fixed the `use-ssl` option being inverted
|
||||
* Fixed disabling the playercount-message still hiding online/max players
|
||||
* Fixed config parsing with multi line strings
|
||||
* Bungee: Fixed compatibility with other motd changing plugins using the 'HIGHEST' ping listener priority
|
||||
---
|
||||
## 3.0.4 - March 17th 2020
|
||||
### Changed
|
||||
* Bungee/Velocity: Added config option `waiting-server` to send players to a waiting server when global maintenance is enabled (instead of kicking them)
|
||||
* Bungee/Velocity: Added config option `use-ssl` in the `mysql` section to disable SSL connections
|
||||
* Added Russian language file (thanks to Spigot user En_0t_S)
|
||||
* Updated missing translations in Portuguese language file (thanks to Spigot user JoaoPinto)
|
||||
* Updated bStats metrics
|
||||
### Fixed
|
||||
* Fixed singleserver timers using input as seconds instead of minutes (by mxs42)
|
||||
* Fixed singleserver timers broadcasting globally
|
||||
* Fixed language updating with an unknown/self-translated language file
|
||||
* Fixed Velocity server autocompletion in the maintenance command
|
||||
---
|
||||
## 3.0.3 - September 17th 2019
|
||||
### Changed
|
||||
* Bungee/Velocity: Added `maintenance.singleserver.bypass.<server>` permission to give individual bypasses for proxied servers (`maintenance.bypass` will still bypass everything as the super-perm)
|
||||
* Added the messages of the help command into the language files
|
||||
* Added config option `kick-online-players` to disable the kicks when maintenance is enabled (new connections will still be blocked)... not sure why you'd want that, but you can :p
|
||||
* The language file will now be automatically updated as well, so no need to delete and recreate it anymore, yay!
|
||||
* Updated missing and new translations in French language file (thanks to Spigot user Zendrique)
|
||||
* Updated missing and new translations in Spanish language file (thanks to Spigot user Vixo_Ulises)
|
||||
### Fixed
|
||||
* Bungee/Velocity: Fixed the join-notifications being sent twice if both global and server maintenance are enabled, as well as when just a server has maintenance in some cases
|
||||
* Bungee: Fixed players being kicked *after* the initial connection and thus triggering a join and leave message before being kicked
|
||||
* Bungee: Fixed the kickmessage not being displayed in some cases
|
||||
* Paper: Fixed the playercount message not being displayed on Paper servers with ViaVersion
|
||||
* Paper: Fixed the motd not being changed at all on Paper servers with ProtocolSupport (-> ProtocolLib listener used, since ProtocolSupport does not fire Paper's ping event)
|
||||
* Fixed the config autoupdater when the config contained strings broken over multiple lines
|
||||
---
|
||||
## 3.0.2 - May 17th 2019
|
||||
### Changed
|
||||
* Added config option `timerspecific-pingmessages` to have specific pingmessages shown when endtimers are run
|
||||
* You can also set them ingame by using `/maintenance setmotd timer <index> ...` instead of `/maintenance setmotd <index> ...`, along with `/maintenance removemotd timer <index>` and `/maintenance motd timer`
|
||||
* Made dumps a little prettier
|
||||
* Support Sponge 8.0.0-SNAPSHOT
|
||||
* Support latest text/Velocity (now only supports Velocity builds from May 7th upwards)
|
||||
---
|
||||
## 3.0.1 - April 17th 2019
|
||||
### Changed
|
||||
* Created an addon to have PlaceholderAPI placeholders on Spigot when running the Maintenance plugin on Bungee (see [**here**](https://github.com/KennyTV/Maintenance/wiki/MaintenanceAddon))
|
||||
* Spigot version: If running on Paper 1.12.2 or higher, ProtocolLib will not be needed anymore
|
||||
* The universal jar now only includes Bungee and Spigot (whereas before Sponge and Velocity as well) and has been further minimized in size
|
||||
* To use the plugin on the other platforms, use the `MaintenanceSponge.jar` or `MaintenanceVelocity.jar` respectively
|
||||
* Added config option `continue-endtimer-after-restart` to have endtimers continued, even if the server restarts during its runtime
|
||||
* Added custom eventsystem to the API
|
||||
* Removed bStats metrics from Sponge module
|
||||
### Fixed
|
||||
* Actually fixed compatibility to other plugins using the same MySQL library (such as LuckPerms) in the Bungee version
|
||||
* Fixed an issue with executing the maintenance change with MySQL enabled on connected proxies
|
||||
* Fixed an occasional error on pings of non clients in the Spigot version
|
||||
* Fixed 1.13 clients on sub 1.13 servers not showing the playercountmessage in the Spigot version
|
||||
* Minor fixes/changes to Spanish and Portuguese language files
|
||||
---
|
||||
## 3.0 - February 17th 2019
|
||||
### Changed
|
||||
* This plugin now also supports the platforms Sponge and Velocity!
|
||||
* Added tabcompletion for maintenance commands on all platforms
|
||||
* This plugin now uses a custom config system, which means comments won't vanish after saving them and the different configs have been unified
|
||||
* You can now also add and remove (offline) players to/from the maintenance whitelist by using their uuid (i.e. `/maintenance add <uuid>`)
|
||||
* The %TIMER% variable can now also be used in the playercount-, playercounthover- and kickmessages
|
||||
* To make life easier for people running on Bungee without an extra permission plugin: the `maintenance.admin` permission gives access to all subcommands
|
||||
* Made bug reports a little easier with the new `/maintenance dump` command
|
||||
* Added a config option to disable update checks (not recommended)
|
||||
* Moved `kickmessage` field from config to language file and added its default translations
|
||||
* Changed permissions nodes for the Bungee part (`from: to`):
|
||||
* `maintenance.toggleserver`: `maintenance.singleserver.toggle`
|
||||
* `maintenance.servertimer`: `maintenance.singleserver.timer`
|
||||
* `maintenance.status`: `maintenance.singleserver.status`
|
||||
* The command `/maintenance timer abort` has been renamed to `/maintenance aborttimer`
|
||||
* Added additional aliases: `/maintenance end` for `/maintenance endtimer`, `start` for `starttimer`, `abort` for `aborttimer`
|
||||
* On false command syntax usage, the reply will be the specific help message for that command, not the entire help window as it was before
|
||||
* Improved update checks and updater
|
||||
* Many many other runtime improvements and some major internal refactoring
|
||||
### Fixed
|
||||
* Fixed a startup issue with other plugins using the same MySQL library on Bungee (for example some versions of LuckPerms)
|
||||
* Fixed an error on Bungee when single servers are set to maintenance with no fallbackserver set
|
||||
* Fixed a rare problem with adding and removing players to/from the maintenance whitelist
|
||||
* Fixed an issue with starting server timers while also running a global maintenance timer
|
||||
* Fixed the `/maintenance status` not appearing in the help overview
|
||||
---
|
||||
## 2.5.2 - December 17th 2018
|
||||
### Changed
|
||||
* Added French `fr` (thanks to Zendrique) and Portuguese `pt` (thanks to JoaoPinto) translations!
|
||||
* Improvements to MySQL stuff on the Bungee part
|
||||
* If enabled, single servers (on the Bungee part) that are under maintenance are now saved into the given database as well!
|
||||
### Fixed
|
||||
* Fixed the maintenance value only loading on the first server ping, not on startup
|
||||
* Fixed an error while setting maintenance to single servers, when the executor is something other than a player
|
||||
* Fixed the maintenance-icon not loading on 1.13+ Spigot servers with ProtocolLib
|
||||
* Some other general improvements and a small message fix
|
||||
---
|
||||
## 2.5.1 - November 17th 2018
|
||||
### Fixed
|
||||
* Fixed an occasional file loading error on startup
|
||||
---
|
||||
## 2.5 - November 17th 2018
|
||||
### Changed
|
||||
* Added the possibility on BungeeCord to also enable maintenance on Spigot servers managed by the proxy
|
||||
* `/maintenance <on/off> <servername>` will now set maintenance to a proxied Spigot server
|
||||
* `/maintenance <starttimer/endtimer> <server> <minutes>` works analog to the normal timer commands
|
||||
* `/maintenance status` shows proxied servers that have maintenance enabled
|
||||
* new permissions are `maintenance.toggleserver`, `maintenance.servertimer` and `maintenance.status`
|
||||
* Added a multiple-language-support system! It's currently not that big tho, with the only language added being de/German
|
||||
* If you like this plugin, know French or Spanish (or any other language that isn't yet supported by the plugin) and want to contribute a bit to it, translations of the default language.yml are greatly appreciated!
|
||||
* Note: There will be a new 'language-en.yml' file created, so if you changed any messages before, you have to do it again in the new file
|
||||
* Made the help message a little fancier
|
||||
* Some API changes
|
||||
### Fixed
|
||||
* Fixed a bug with starttimers not being able to start properly
|
||||
---
|
||||
## 2.4 - September 17th 2018
|
||||
### Changed
|
||||
* Edit nearly every message to your hearts content with the now introduced language.yml file!
|
||||
* Added `/maintenance removemotd <index>` command to remove a motd via an ingame command (if you have multiple ones)
|
||||
* You can now include the `%TIMER%` variable into your maintenance motd - **If using the maintenance endtimer**, it will display the time left until maintenance will be disabled!
|
||||
* Simply shows `-` if maintenance is on without any timer
|
||||
* A nice integration could be `&cExpected to come back in: &6%TIMER%`
|
||||
* You can now choose to show the normal playercount during maintenance instead of a custom message by changing the `enable-playercountmessage` value in the config
|
||||
* You can also include the playercount in a custom playercountmessage by using the 2 variables `%ONLINE%` and `%MAX%`
|
||||
* If there's a new update available, the update notification will no longer be sent on every single login, but rather just on the first one after startup
|
||||
* Removing players from the maintenance whitelist now accepts uncapitalized names
|
||||
---
|
||||
## 2.3.1 - August 17th 2018
|
||||
### Changed
|
||||
* When a string in the config is missing, the plugin doesn't cancel the current process and throws an error anymore, but rather gives a soft warning in the console and returns a backup string
|
||||
* If MySQL is enabled, the plugin will only make a database request at least x seconds after the last request, whereas you can define the value in the config under `mysql.update-interval`
|
||||
* Example: If a first player pings the server after startup, the value will be updated -> No update in the next x seconds even if a player pings -> After elapsed, as soon as the next player pings the server again
|
||||
* Especially helpful as well as recommended for servers with many players
|
||||
* Another improvement for MySQL support: After enabling maintenance on one proxy, the other connected ones will then also kick all non permitted players and switch their ServerListPlus state!
|
||||
* The `/maintenance` helppage now only shows the commands the player actually has permission to execute
|
||||
---
|
||||
## 2.3 - July 17th 2018
|
||||
### Changed
|
||||
* Added the possibility to have multiple pingmessages, of which one will be randomly chosen on each ping when maintenance is enabled (you can also just keep it at one)!
|
||||
* Added permissions per subcommand
|
||||
* `maintenance.command` required to use any of the commands
|
||||
* `maintenance.toggle` to use /maintenance <on/off>
|
||||
* `maintenance.reload` to use /maintenance reload
|
||||
* `maintenance.update` to use /maintenance <update/forceupdate>
|
||||
* `maintenance.timer` to use /maintenance <starttimer/endtimer> <minutes>
|
||||
* `maintenance.whitelist.add` to use /maintenance add <player>
|
||||
* `maintenance.whitelist.remove` to use /maintenance remove <player>
|
||||
* `maintenance.whitelist.list` to use /maintenance whitelist
|
||||
* `maintenance.setmotd` to use /maintenance setmotd <index> <1/2> <message>
|
||||
* `maintenance.motd` to use /maintenance motd
|
||||
* Added `/maintenance motd` command to list all set maintenance pingmessages
|
||||
* `/maintenance whitelist` now also shows the UUID connected to each name
|
||||
### Fixed
|
||||
* Reworked/fixed the `/maintenance setmotd` command
|
||||
* Some typo and description fixes
|
||||
---
|
||||
## 2.2.2 - June 17th 2018
|
||||
### Changed
|
||||
* Changed the loading of the maintenance icon to be more predictable: It will load directly on startup and can now be reloaded by using the `/maintenance reload` command as well
|
||||
* Changed the reload message to read the proper reload changes
|
||||
* Removed an obsolete config comment
|
||||
* You can now hook into the plugin with the integrated API
|
||||
---
|
||||
## 2.2.1 - April 17th 2018
|
||||
### Changed
|
||||
* Added `/maintenance setmotd <1/2> <message>` command to edit the maintenance mode motd via a command
|
||||
* The Bungee version of the plugin will now automatically create a MySQL table if it is enabled, so you won't have to manually create one anymore
|
||||
### Fixed
|
||||
* Fixed the ServerListPlus motd only changing on using the command, but not on the server startup
|
||||
* Fixed an error with canceling the start-/endtimer in the Bungee version
|
||||
* Fixed an error with removing players from the whitelist in the Spigot version
|
||||
---
|
||||
## 2.2 - March 17th 2018
|
||||
### Changed
|
||||
* Great update for the Spigot version of the plugin as well as performance improvements and bugfixes in both versions
|
||||
* If you have ProtocolLib installed, you can set a custom server icon while maintenance is enabled, also the playercount-message and the playercount-hover-message are now available (as it has already been in the Bungee version)!
|
||||
* In the BungeeCord version of the plugin, the `/maintenance remove <player>` command now also works for offline players
|
||||
* Removed the plugin's prefix from some messages
|
||||
* General performance improvements
|
||||
### Fixed
|
||||
* The Spigot version should be much more compatible with other motd-changing plugins, such as SexyMotd
|
||||
* Fixed some other issues with the ProtocolLib integration
|
||||
* Minor textfix for the updatemessage in the Spigot version
|
||||
---
|
||||
## 2.1 - February 17th 2018
|
||||
### Changed
|
||||
* Massive code cleanup for both the Bungee and Spigot version of the plugin
|
||||
* Minor performance improvements
|
||||
### Fixed
|
||||
* Fixed start- and endtimers not being cancelled properly
|
||||
* Fixed an error for the update command in the Spigot version
|
||||
* Fixed an error regarding the ServerListPlus integration in the Spigot version
|
||||
---
|
||||
## 2.0 - February 15th 2018
|
||||
### Changed
|
||||
* You can now put the plugin not only inside your Bungee plugins folder, but also your Spigot/Bukkit one! Both will have the same feautures, but simply on their own platform. However, the Spigot version doesn't have MySQL support (as you would normally use BungeeCord for connecting multiple Spigot/Bukkit servers) and you can't use playercount-message, besides this, it has all its main features.
|
||||
* On BungeeCord you can make your own custom messages for the playercount
|
||||
* On Spigot you will see `N/0` (N being the actual count). If you also have ProtocolLib on your server, `0/0` will be displayed.
|
||||
* As many of you asked me: Maintenance now supports the plugin ServerListPlus
|
||||
* Performance improvements
|
||||
### Fixed
|
||||
* Fixed some permission and message bugs
|
||||
* Fixed problems with adding and removing players from the maintenance whitelist
|
||||
* Fixed update checks
|
||||
@@ -0,0 +1,5 @@
|
||||
# Contribution
|
||||
As I'm just a random guy making this plugin as a fun side-project, it will never be "perfect".
|
||||
Any improvement is welcome, as long as it fits with the general style of code, that should become apparent when looking at some of the other classes. :)
|
||||
|
||||
Generally, the used formatting is the default formatting of IntelliJ (Ctrl+Alt+L).
|
||||
@@ -0,0 +1,14 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Report a bug to have it fixed
|
||||
|
||||
---
|
||||
|
||||
## Bug reproducibility
|
||||
**How does the problem occur/what are the steps to reproduce it?**
|
||||
|
||||
## Error
|
||||
**Is there an error? Save it via https://pastebin.com/ and link paste the link.**
|
||||
|
||||
## Server information
|
||||
**Type '/maintenance dump' and paste the given link here**
|
||||
@@ -0,0 +1,35 @@
|
||||
name: Build
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions/cache@v2.1.1
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: ${{ runner.os }}-maven-
|
||||
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
|
||||
- name: Upload a Build Artifact
|
||||
uses: actions/upload-artifact@v2.1.4
|
||||
with:
|
||||
name: MaintenanceFiles
|
||||
path: |
|
||||
**/Maintenance.jar
|
||||
**/MaintenanceSpigot.jar
|
||||
**/MaintenanceBungee.jar
|
||||
**/MaintenanceVelocity.jar
|
||||
**/MaintenanceSponge.jar
|
||||
+3
-2
@@ -1,5 +1,4 @@
|
||||
.metadata
|
||||
dependencies/
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
@@ -91,4 +90,6 @@ $RECYCLE.BIN/
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
*.lnk
|
||||
*.lnk
|
||||
!MaintenanceAPI.jar
|
||||
**/src/test/resources/
|
||||
@@ -0,0 +1,7 @@
|
||||
language: java
|
||||
jdk:
|
||||
- oraclejdk8
|
||||
dist: trusty
|
||||
cache:
|
||||
directories:
|
||||
- '$HOME/.m2/repository'
|
||||
@@ -1,13 +0,0 @@
|
||||
## Issue
|
||||
Include here how the problem occured and how it's reproduceable.
|
||||
If present, also paste the entire error message from the console, preferably via a https://hastebin.com/ link.
|
||||
|
||||
## Necessary server information
|
||||
**Running on**: <BungeeCord/Bukkit>
|
||||
|
||||
**Maintenance version**: <>
|
||||
|
||||
## Other information
|
||||
**Other motd changing plugins**: <>
|
||||
|
||||
**ProtocolLib version**: <>
|
||||
Binary file not shown.
@@ -1,40 +0,0 @@
|
||||
package eu.kennytv.maintenance.api;
|
||||
|
||||
/**
|
||||
* @author KennyTV
|
||||
* @since 2.1
|
||||
*/
|
||||
public interface IMaintenance {
|
||||
|
||||
/**
|
||||
* Enables/disables maintenance mode.
|
||||
* If enabled, all non-permitted players will be kicked.
|
||||
* <p>
|
||||
* If using the BungeeCord version and MySQL is enabled,
|
||||
* it will also be written into the database.
|
||||
* </p>
|
||||
*
|
||||
* @param maintenance true to enable, false to disable maintenance mode
|
||||
*/
|
||||
void setMaintenance(boolean maintenance);
|
||||
|
||||
/**
|
||||
* @return true if maintenance is currently enabled
|
||||
*/
|
||||
boolean isMaintenance();
|
||||
|
||||
/**
|
||||
* @return true if a start- or endtimer task is currently running
|
||||
*/
|
||||
boolean isTaskRunning();
|
||||
|
||||
/**
|
||||
* @return version of the plugin
|
||||
*/
|
||||
String getVersion();
|
||||
|
||||
/**
|
||||
* @return {@link ISettings} for options regarding configuration files
|
||||
*/
|
||||
ISettings getSettings();
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package eu.kennytv.maintenance.api;
|
||||
|
||||
/**
|
||||
* @author KennyTV
|
||||
* @since 2.2.2
|
||||
*/
|
||||
public interface IMaintenanceBase {
|
||||
|
||||
/**
|
||||
* Returns API instance of IMaintenance.
|
||||
*
|
||||
* @return {@link IMaintenance} instance
|
||||
*/
|
||||
IMaintenance getApi();
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package eu.kennytv.maintenance.api;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Utility class to get the {@link IMaintenance} instance for the BungeeCord version of the plugin.
|
||||
* <p>
|
||||
* Only access this class if you're running the plugin on a BungeeCord server!
|
||||
* </p>
|
||||
*
|
||||
* @author KennyTV
|
||||
* @since 2.1
|
||||
*/
|
||||
public final class MaintenanceBungeeAPI {
|
||||
|
||||
/**
|
||||
* Returns API instance of IMaintenance.
|
||||
*
|
||||
* @return {@link IMaintenance} instance
|
||||
*/
|
||||
public static IMaintenance getAPI() {
|
||||
final Plugin maintenance = ProxyServer.getInstance().getPluginManager().getPlugin("MaintenanceBungee");
|
||||
if (maintenance == null)
|
||||
ProxyServer.getInstance().getLogger().warning("Could not get instance of MaintenanceBungee!");
|
||||
|
||||
return ((IMaintenanceBase) maintenance).getApi();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package eu.kennytv.maintenance.api;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Utility class to get the {@link IMaintenance} instance for the Spigot version of the plugin.
|
||||
* <p>
|
||||
* Only access this class if you're running the plugin on a Spigot server!
|
||||
* </p>
|
||||
*
|
||||
* @author KennyTV
|
||||
* @since 2.1
|
||||
*/
|
||||
public final class MaintenanceSpigotAPI {
|
||||
|
||||
/**
|
||||
* Returns API instance of IMaintenance.
|
||||
*
|
||||
* @return {@link IMaintenance} instance
|
||||
*/
|
||||
public static IMaintenance getAPI() {
|
||||
final Plugin maintenance = Bukkit.getPluginManager().getPlugin("MaintenanceSpigot");
|
||||
if (maintenance == null)
|
||||
Bukkit.getLogger().warning("Could not get instance of MaintenanceSpigot!");
|
||||
|
||||
return ((IMaintenanceBase) maintenance).getApi();
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>maintenance-base</artifactId>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<version>2.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-bungee</artifactId>
|
||||
<name>MaintenanceBungee</name>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<artifactId>maintenance-core</artifactId>
|
||||
<version>${parent.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.13-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.minecrell</groupId>
|
||||
<artifactId>ServerListPlus</artifactId>
|
||||
<version>3.4.8</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
package eu.kennytv.maintenance.bungee;
|
||||
|
||||
import eu.kennytv.maintenance.api.IMaintenance;
|
||||
import eu.kennytv.maintenance.api.IMaintenanceBase;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public final class MaintenanceBungeeBase extends Plugin implements IMaintenanceBase {
|
||||
private IMaintenance maintenance;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
maintenance = new MaintenanceBungeePlugin(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMaintenance getApi() {
|
||||
return maintenance;
|
||||
}
|
||||
|
||||
File getPluginFile() {
|
||||
return getFile();
|
||||
}
|
||||
}
|
||||
-122
@@ -1,122 +0,0 @@
|
||||
package eu.kennytv.maintenance.bungee;
|
||||
|
||||
import eu.kennytv.maintenance.api.IMaintenance;
|
||||
import eu.kennytv.maintenance.api.ISettings;
|
||||
import eu.kennytv.maintenance.api.MaintenanceBungeeAPI;
|
||||
import eu.kennytv.maintenance.bungee.command.MaintenanceBungeeCommand;
|
||||
import eu.kennytv.maintenance.bungee.command.MaintenanceBungeeCommandBase;
|
||||
import eu.kennytv.maintenance.bungee.listener.PostLoginListener;
|
||||
import eu.kennytv.maintenance.bungee.metrics.MetricsLite;
|
||||
import eu.kennytv.maintenance.core.MaintenanceModePlugin;
|
||||
import eu.kennytv.maintenance.core.hook.ServerListPlusHook;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.plugin.PluginManager;
|
||||
import net.minecrell.serverlistplus.core.plugin.ServerListPlusPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author KennyTV
|
||||
* @since 1.0
|
||||
*/
|
||||
public final class MaintenanceBungeePlugin extends MaintenanceModePlugin {
|
||||
private final MaintenanceBungeeBase plugin;
|
||||
private final SettingsBungee settings;
|
||||
|
||||
MaintenanceBungeePlugin(final MaintenanceBungeeBase plugin) {
|
||||
super("§8[§eMaintenanceBungee§8] ", plugin.getDescription().getVersion());
|
||||
|
||||
this.plugin = plugin;
|
||||
plugin.getLogger().info("Plugin by KennyTV");
|
||||
|
||||
settings = new SettingsBungee(this, plugin);
|
||||
|
||||
final PluginManager pm = getProxy().getPluginManager();
|
||||
pm.registerListener(plugin, new PostLoginListener(this, settings));
|
||||
final MaintenanceBungeeCommand maintenanceCommand = new MaintenanceBungeeCommand(this, settings);
|
||||
pm.registerCommand(plugin, new MaintenanceBungeeCommandBase(maintenanceCommand));
|
||||
|
||||
new MetricsLite(plugin);
|
||||
|
||||
// ServerListPlus integration
|
||||
final Plugin serverListPlus = pm.getPlugin("ServerListPlus");
|
||||
if (serverListPlus != null) {
|
||||
serverListPlusHook = new ServerListPlusHook(((ServerListPlusPlugin) serverListPlus).getCore());
|
||||
serverListPlusHook.setEnabled(!settings.isMaintenance());
|
||||
plugin.getLogger().info("Enabled ServerListPlus integration!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaintenance(final boolean maintenance) {
|
||||
if (settings.getMySQL() != null) {
|
||||
settings.setMaintenanceToSQL(maintenance);
|
||||
} else {
|
||||
settings.setMaintenance(maintenance);
|
||||
settings.setToConfig("enable-maintenance-mode", maintenance);
|
||||
settings.saveConfig();
|
||||
settings.reloadConfigs();
|
||||
}
|
||||
|
||||
serverActions(maintenance);
|
||||
|
||||
if (isTaskRunning())
|
||||
cancelTask();
|
||||
}
|
||||
|
||||
void serverActions(final boolean maintenance) {
|
||||
if (serverListPlusHook != null)
|
||||
serverListPlusHook.setEnabled(!maintenance);
|
||||
|
||||
if (maintenance) {
|
||||
getProxy().getPlayers().stream()
|
||||
.filter(p -> !p.hasPermission("maintenance.bypass") && !settings.getWhitelistedPlayers().containsKey(p.getUniqueId()))
|
||||
.forEach(p -> p.disconnect(settings.getKickMessage().replace("%NEWLINE%", "\n")));
|
||||
getProxy().broadcast(settings.getMessage("maintenanceActivated"));
|
||||
} else
|
||||
getProxy().broadcast(settings.getMessage("maintenanceDeactivated"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int startMaintenanceRunnable(final Runnable runnable) {
|
||||
return getProxy().getScheduler().schedule(plugin, runnable, 0, 1, TimeUnit.SECONDS).getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void async(final Runnable runnable) {
|
||||
getProxy().getScheduler().runAsync(plugin, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTask() {
|
||||
getProxy().getScheduler().cancel(taskId);
|
||||
runnable = null;
|
||||
taskId = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISettings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getPluginFile() {
|
||||
return plugin.getPluginFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(final String message) {
|
||||
getProxy().broadcast(message);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static IMaintenance getAPI() {
|
||||
return MaintenanceBungeeAPI.getAPI();
|
||||
}
|
||||
|
||||
public ProxyServer getProxy() {
|
||||
return plugin.getProxy();
|
||||
}
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
package eu.kennytv.maintenance.bungee;
|
||||
|
||||
import eu.kennytv.maintenance.bungee.listener.ProxyPingListener;
|
||||
import eu.kennytv.maintenance.bungee.mysql.MySQL;
|
||||
import eu.kennytv.maintenance.core.Settings;
|
||||
import eu.kennytv.maintenance.core.listener.IPingListener;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.plugin.PluginManager;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class SettingsBungee extends Settings {
|
||||
private final String updateQuery;
|
||||
private final String maintenanceQuery;
|
||||
private final MySQL mySQL;
|
||||
|
||||
private final MaintenanceBungeePlugin maintenancePlugin;
|
||||
private final MaintenanceBungeeBase plugin;
|
||||
private final IPingListener pingListener;
|
||||
private Configuration config;
|
||||
private Configuration language;
|
||||
private Configuration whitelist;
|
||||
|
||||
private long millisecondsToCheck;
|
||||
private long lastMySQLCheck;
|
||||
|
||||
SettingsBungee(final MaintenanceBungeePlugin maintenancePlugin, final MaintenanceBungeeBase plugin) {
|
||||
super(maintenancePlugin);
|
||||
this.maintenancePlugin = maintenancePlugin;
|
||||
this.plugin = plugin;
|
||||
|
||||
final PluginManager pm = plugin.getProxy().getPluginManager();
|
||||
final ProxyPingListener listener = new ProxyPingListener(plugin, this);
|
||||
pm.registerListener(plugin, listener);
|
||||
pingListener = listener;
|
||||
|
||||
if (!plugin.getDataFolder().exists())
|
||||
plugin.getDataFolder().mkdirs();
|
||||
createFile("bungee-config.yml");
|
||||
createFile("language.yml");
|
||||
createFile("WhitelistedPlayers.yml");
|
||||
|
||||
reloadConfigs();
|
||||
|
||||
final Configuration mySQLSection = config.getSection("mysql");
|
||||
if (mySQLSection.getBoolean("use-mysql", false)) {
|
||||
plugin.getLogger().info("Trying to open database connection...");
|
||||
mySQL = new MySQL(mySQLSection.getString("host"),
|
||||
mySQLSection.getInt("port"),
|
||||
mySQLSection.getString("username"),
|
||||
mySQLSection.getString("password"),
|
||||
mySQLSection.getString("database"));
|
||||
|
||||
// Varchar as the value regarding the possibility of saving stuff like the motd as well in future updates
|
||||
final String mySQLTable = mySQLSection.getString("table");
|
||||
mySQL.executeUpdate("CREATE TABLE IF NOT EXISTS " + mySQLTable + " (setting VARCHAR(16) PRIMARY KEY, value VARCHAR(255))");
|
||||
updateQuery = "INSERT INTO " + mySQLTable + " (setting, value) VALUES (?, ?) ON DUPLICATE KEY UPDATE value = ?";
|
||||
maintenanceQuery = "SELECT * FROM " + mySQLTable + " WHERE setting = ?";
|
||||
plugin.getLogger().info("Done!");
|
||||
} else {
|
||||
mySQL = null;
|
||||
updateQuery = null;
|
||||
maintenanceQuery = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void createFile(final String name) {
|
||||
final File file = new File(plugin.getDataFolder(), name);
|
||||
if (!file.exists()) {
|
||||
try (final InputStream in = plugin.getResourceAsStream(name)) {
|
||||
Files.copy(in, file.toPath());
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("Unable to create " + name + " file for MaintenanceBungee", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateExtraConfig() {
|
||||
// 2.3.1 mysql.update-interval
|
||||
if (!configContains("mysql.update-interval")) {
|
||||
setToConfig("mysql.update-interval", 15);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfigs() {
|
||||
try {
|
||||
config = YamlConfiguration.getProvider(YamlConfiguration.class)
|
||||
.load(new InputStreamReader(new FileInputStream(new File(plugin.getDataFolder(), "bungee-config.yml")), StandardCharsets.UTF_8));
|
||||
language = YamlConfiguration.getProvider(YamlConfiguration.class)
|
||||
.load(new InputStreamReader(new FileInputStream(new File(plugin.getDataFolder(), "language.yml")), StandardCharsets.UTF_8));
|
||||
whitelist = YamlConfiguration.getProvider(YamlConfiguration.class).load(new File(plugin.getDataFolder(), "WhitelistedPlayers.yml"));
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("Unable to load Maintenance files!", e);
|
||||
}
|
||||
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveConfig() {
|
||||
final File file = new File(plugin.getDataFolder(), "bungee-config.yml");
|
||||
try {
|
||||
YamlConfiguration.getProvider(YamlConfiguration.class).save(config, new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("Unable to save bungee-config.yml!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveWhitelistedPlayers() {
|
||||
final File file = new File(plugin.getDataFolder(), "WhitelistedPlayers.yml");
|
||||
try {
|
||||
YamlConfiguration.getProvider(YamlConfiguration.class).save(whitelist, file);
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("Unable to save WhitelistedPlayers.yml!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadExtraSettings() {
|
||||
whitelistedPlayers.clear();
|
||||
whitelist.getKeys().forEach(key -> whitelistedPlayers.put(UUID.fromString(key), whitelist.getString(key)));
|
||||
if (mySQL != null) {
|
||||
final long configValue = config.getInt("mysql.update-interval");
|
||||
millisecondsToCheck = configValue > 0 ? configValue * 1000 : -1;
|
||||
lastMySQLCheck = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhitelist(final String uuid, final String s) {
|
||||
whitelist.set(uuid, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigString(final String path) {
|
||||
final String s = config.getString(path);
|
||||
if (s == null) {
|
||||
plugin.getLogger().warning("The config is missing the following string: " + path);
|
||||
return "null";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage(final String path) {
|
||||
final String s = language.getString(path);
|
||||
if (s == null) {
|
||||
plugin.getLogger().warning("The language file is missing the following string: " + path);
|
||||
return "null";
|
||||
}
|
||||
return ChatColor.translateAlternateColorCodes('&', s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getConfigBoolean(final String path) {
|
||||
return config.getBoolean(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getConfigIntList(final String path) {
|
||||
return config.getIntList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getConfigList(final String path) {
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setToConfig(final String path, final Object var) {
|
||||
config.set(path, var);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configContains(final String path) {
|
||||
return config.contains(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColoredString(final String message) {
|
||||
return ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMaintenance() {
|
||||
if (mySQL != null && (millisecondsToCheck == -1 || System.currentTimeMillis() - lastMySQLCheck > millisecondsToCheck)) {
|
||||
mySQL.executeQuery(maintenanceQuery, rs -> {
|
||||
try {
|
||||
if (rs.next()) {
|
||||
final boolean databaseValue = Boolean.parseBoolean(rs.getString("value"));
|
||||
if (databaseValue != maintenance)
|
||||
maintenancePlugin.serverActions(maintenance);
|
||||
|
||||
maintenance = databaseValue;
|
||||
}
|
||||
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, "maintenance");
|
||||
if (millisecondsToCheck != -1)
|
||||
lastMySQLCheck = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
return maintenance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reloadMaintenanceIcon() {
|
||||
return pingListener.loadIcon();
|
||||
}
|
||||
|
||||
public void setMaintenanceToSQL(final boolean maintenance) {
|
||||
plugin.getProxy().getScheduler().runAsync(plugin, () -> {
|
||||
final String s = String.valueOf(maintenance);
|
||||
mySQL.executeUpdate(updateQuery, "maintenance", s, s);
|
||||
if (millisecondsToCheck != -1)
|
||||
lastMySQLCheck = System.currentTimeMillis();
|
||||
});
|
||||
this.maintenance = maintenance;
|
||||
}
|
||||
|
||||
public MySQL getMySQL() {
|
||||
return mySQL;
|
||||
}
|
||||
}
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
package eu.kennytv.maintenance.bungee.command;
|
||||
|
||||
import eu.kennytv.maintenance.bungee.MaintenanceBungeePlugin;
|
||||
import eu.kennytv.maintenance.bungee.SettingsBungee;
|
||||
import eu.kennytv.maintenance.bungee.util.ProxiedSenderInfo;
|
||||
import eu.kennytv.maintenance.core.command.MaintenanceCommand;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
public final class MaintenanceBungeeCommand extends MaintenanceCommand {
|
||||
|
||||
public MaintenanceBungeeCommand(final MaintenanceBungeePlugin plugin, final SettingsBungee settings) {
|
||||
super(plugin, settings, "MaintenanceBungee");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addPlayerToWhitelist(final SenderInfo sender, final String name) {
|
||||
final ProxiedPlayer selected = ProxyServer.getInstance().getPlayer(name);
|
||||
if (selected == null) {
|
||||
sender.sendMessage(settings.getMessage("playerNotOnline"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (settings.addWhitelistedPlayer(selected.getUniqueId(), selected.getName()))
|
||||
sender.sendMessage(settings.getMessage("whitelistAdded").replace("%PLAYER%", selected.getName()));
|
||||
else
|
||||
sender.sendMessage(settings.getMessage("whitelistAlreadyAdded").replace("%PLAYER%", selected.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removePlayerFromWhitelist(final SenderInfo sender, final String name) {
|
||||
final ProxiedPlayer selected = ProxyServer.getInstance().getPlayer(name);
|
||||
if (selected == null) {
|
||||
if (settings.removeWhitelistedPlayer(name))
|
||||
sender.sendMessage(settings.getMessage("whitelistRemoved").replace("%PLAYER%", name));
|
||||
else
|
||||
sender.sendMessage(settings.getMessage("whitelistNotFound"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (settings.removeWhitelistedPlayer(selected.getUniqueId()))
|
||||
sender.sendMessage(settings.getMessage("whitelistRemoved").replace("%PLAYER%", selected.getName()));
|
||||
else
|
||||
sender.sendMessage(settings.getMessage("whitelistNotFound"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkForUpdate(final SenderInfo sender) {
|
||||
if (plugin.updateAvailable()) {
|
||||
sender.sendMessage(plugin.getPrefix() + "§cNewest version available: §aVersion " + plugin.getNewestVersion() + "§c, you're on §a" + plugin.getVersion());
|
||||
sender.sendMessage(plugin.getPrefix() + "§c§lWARNING: §cYou will have to restart the proxy to prevent further issues and to complete the update!" +
|
||||
" If you can't do that, don't update!");
|
||||
final TextComponent tc = new TextComponent("§6× §8[§aUpdate§8]");
|
||||
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/maintenance forceupdate"));
|
||||
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§aClick here to update the plugin")));
|
||||
tc.addExtra(" §8< §7Or use the command §c/maintenance forceupdate");
|
||||
|
||||
((ProxiedSenderInfo) sender).sendMessage(tc);
|
||||
} else
|
||||
sender.sendMessage(plugin.getPrefix() + "§aYou already have the latest version of the plugin!");
|
||||
}
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package eu.kennytv.maintenance.bungee.command;
|
||||
|
||||
import eu.kennytv.maintenance.bungee.util.ProxiedSenderInfo;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public final class MaintenanceBungeeCommandBase extends Command {
|
||||
private final MaintenanceBungeeCommand command;
|
||||
|
||||
public MaintenanceBungeeCommandBase(final MaintenanceBungeeCommand command) {
|
||||
super("maintenance", "", "maintenancebungee");
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final String[] args) {
|
||||
command.execute(new ProxiedSenderInfo(sender), args);
|
||||
}
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
package eu.kennytv.maintenance.bungee.listener;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import eu.kennytv.maintenance.bungee.MaintenanceBungeePlugin;
|
||||
import eu.kennytv.maintenance.bungee.SettingsBungee;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class PostLoginListener implements Listener {
|
||||
private final MaintenanceBungeePlugin plugin;
|
||||
private final SettingsBungee settings;
|
||||
private final Set<UUID> notifiedPlayers = Sets.newHashSet();
|
||||
|
||||
public PostLoginListener(final MaintenanceBungeePlugin plugin, final SettingsBungee settings) {
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void postLogin(final PostLoginEvent event) {
|
||||
final ProxiedPlayer p = event.getPlayer();
|
||||
if (p.getUniqueId().toString().equals("a8179ff3-c201-4a75-bdaa-9d14aca6f83f"))
|
||||
p.sendMessage("§6MaintenanceBungee §aVersion " + plugin.getVersion());
|
||||
else if (settings.isMaintenance()) {
|
||||
if (!p.hasPermission("maintenance.bypass") && !settings.getWhitelistedPlayers().containsKey(p.getUniqueId())) {
|
||||
p.disconnect(settings.getKickMessage().replace("%NEWLINE%", "\n"));
|
||||
|
||||
if (settings.isJoinNotifications())
|
||||
plugin.getProxy().getPlayers().stream().filter(player -> player.hasPermission("maintenance.joinnotification"))
|
||||
.forEach(player -> player.sendMessage(settings.getMessage("joinNotification").replace("%PLAYER%", p.getName())));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!p.hasPermission("maintenance.admin") || notifiedPlayers.contains(p.getUniqueId())) return;
|
||||
|
||||
plugin.async(() -> {
|
||||
if (plugin.updateAvailable()) {
|
||||
p.sendMessage(plugin.getPrefix() + "§cThere is a newer version available: §aVersion " + plugin.getNewestVersion() + "§c, you're on §a" + plugin.getVersion());
|
||||
notifiedPlayers.add(p.getUniqueId());
|
||||
|
||||
final TextComponent tc1 = new TextComponent(TextComponent.fromLegacyText(plugin.getPrefix() + " "));
|
||||
final TextComponent tc2 = new TextComponent(TextComponent.fromLegacyText("§cDownload it at: §6https://www.spigotmc.org/resources/maintenancemode.40699/"));
|
||||
final TextComponent click = new TextComponent(TextComponent.fromLegacyText(" §7§l§o(CLICK ME)"));
|
||||
click.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/maintenancemode.40699/"));
|
||||
click.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aDownload the latest version").create()));
|
||||
tc1.addExtra(tc2);
|
||||
tc1.addExtra(click);
|
||||
|
||||
p.sendMessage(tc1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
package eu.kennytv.maintenance.bungee.listener;
|
||||
|
||||
import eu.kennytv.maintenance.bungee.MaintenanceBungeeBase;
|
||||
import eu.kennytv.maintenance.bungee.SettingsBungee;
|
||||
import eu.kennytv.maintenance.core.listener.IPingListener;
|
||||
import net.md_5.bungee.api.Favicon;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ProxyPingListener implements Listener, IPingListener {
|
||||
private final MaintenanceBungeeBase plugin;
|
||||
private final SettingsBungee settings;
|
||||
private Favicon favicon;
|
||||
|
||||
public ProxyPingListener(final MaintenanceBungeeBase plugin, final SettingsBungee settings) {
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void proxyPing(final ProxyPingEvent event) {
|
||||
if (!settings.isMaintenance()) return;
|
||||
|
||||
final ServerPing ping = event.getResponse();
|
||||
if (settings.hasCustomPlayerCountMessage()) {
|
||||
ping.getVersion().setProtocol(1);
|
||||
ping.getVersion().setName(settings.getPlayerCountMessage()
|
||||
.replace("%ONLINE%", Integer.toString(ping.getPlayers().getOnline()))
|
||||
.replace("%MAX%", Integer.toString(ping.getPlayers().getMax())));
|
||||
}
|
||||
|
||||
ping.setDescription(settings.getRandomPingMessage());
|
||||
ping.getPlayers().setOnline(0);
|
||||
ping.getPlayers().setMax(0);
|
||||
ping.getPlayers().setSample(new ServerPing.PlayerInfo[]{
|
||||
new ServerPing.PlayerInfo(settings.getPlayerCountHoverMessage().replace("%NEWLINE%", "\n"), "")
|
||||
});
|
||||
|
||||
if (settings.hasCustomIcon() && favicon != null)
|
||||
ping.setFavicon(favicon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadIcon() {
|
||||
try {
|
||||
favicon = Favicon.create(ImageIO.read(new File("maintenance-icon.png")));
|
||||
} catch (final IOException | IllegalArgumentException e) {
|
||||
plugin.getLogger().warning("§4Could not load 'maintenance-icon.png' - did you create one in your Bungee folder (not the plugins folder)?");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package eu.kennytv.maintenance.bungee.util;
|
||||
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ProxiedSenderInfo extends SenderInfo {
|
||||
private final CommandSender sender;
|
||||
|
||||
public ProxiedSenderInfo(final CommandSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUuid() {
|
||||
return sender instanceof ProxiedPlayer ? ((ProxiedPlayer) sender).getUniqueId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return sender.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String permission) {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(final String message) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
public void sendMessage(final TextComponent textComponent) {
|
||||
sender.sendMessage(textComponent);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
# MaintenanceBungee Plugin by KennyTV
|
||||
# Version ${project.version}
|
||||
|
||||
# Enables maintenance-mode.
|
||||
enable-maintenance-mode: false
|
||||
|
||||
# The message shown in the multiplayer server list motd.
|
||||
# If you put in multiple entries, one of them will be chosen randomly on every ping.
|
||||
pingmessages:
|
||||
- "&cMaintenance mode!%NEWLINE%&6We will be back soon!"
|
||||
#- "Another entry"
|
||||
|
||||
# If set to true, the message below will be shown at the top right corner of the server in the serverlist,
|
||||
# where the playercount would normally be displayed.
|
||||
# If set to false, the normal playercount will be shown.
|
||||
# Alternatively you can use '%ONLINE%' and '%MAX% if you want to include the playercount in a custom message (e.g. '&cMaintenance &7%ONLINE%&8/&7%MAX%').
|
||||
enable-playercountmessage: true
|
||||
playercountmessage: "&4Maintenance"
|
||||
|
||||
# Is shown when you move your mouse above the text at the top right corner of the server in the serverlist,
|
||||
# where the playercount would normally be displayed.
|
||||
playercounthovermessage: "&cCurrently under%NEWLINE%&cmaintenance"
|
||||
|
||||
# Is shown when a player tries to join while maintenance is enabled and they don't have the permission to bypass it.
|
||||
kickmessage: "&cThe server is currently under maintenance!%NEWLINE%Try again later!"
|
||||
|
||||
# If using the timer command: In what intervalls before enabling/disabling maintenance there will be a broadcast.
|
||||
timer-broadcast-for-seconds: [1200, 900, 600, 300, 120, 60, 30, 20, 10, 5, 4, 3, 2, 1]
|
||||
|
||||
# If set to true, players with the maintenance.joinnotification permission will receive a message,
|
||||
# that a player tried to join the server while maintenance is enabled.
|
||||
send-join-notification: false
|
||||
|
||||
# If set to true, the server icon will be changed to maintenance-icon.png in the Bungee main/base-folder.
|
||||
custom-maintenance-icon: false
|
||||
|
||||
# Only enable MySQL if you really know what you are doing.
|
||||
mysql:
|
||||
use-mysql: false
|
||||
host: host
|
||||
port: 3306
|
||||
database: database
|
||||
username: username
|
||||
password: password
|
||||
# A new table with this name will be created on first startup when 'use-mysql' is set to true.
|
||||
table: maintenance_settings
|
||||
# Requests to the database will only be made at least x seconds after the last request,
|
||||
# so there won't be a request on every single ping on a server with many players.
|
||||
# Set this to 0 to make a database request on every single ping.
|
||||
update-interval: 15
|
||||
@@ -1,6 +0,0 @@
|
||||
name: ${project.name}
|
||||
version: ${project.version}
|
||||
main: eu.kennytv.maintenance.bungee.MaintenanceBungeeBase
|
||||
author: KennyTV
|
||||
softDepends: [ServerListPlus]
|
||||
website: https://www.spigotmc.org/resources/maintenancemode.40699/
|
||||
-133
@@ -1,133 +0,0 @@
|
||||
package eu.kennytv.maintenance.core;
|
||||
|
||||
import eu.kennytv.maintenance.api.IMaintenance;
|
||||
import eu.kennytv.maintenance.core.hook.ServerListPlusHook;
|
||||
import eu.kennytv.maintenance.core.runnable.MaintenanceRunnable;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public abstract class MaintenanceModePlugin implements IMaintenance {
|
||||
protected final String version;
|
||||
protected ServerListPlusHook serverListPlusHook;
|
||||
protected MaintenanceRunnable runnable;
|
||||
protected int taskId;
|
||||
private final String prefix;
|
||||
private String newestVersion;
|
||||
|
||||
protected MaintenanceModePlugin(final String prefix, final String version) {
|
||||
this.prefix = prefix;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMaintenance() {
|
||||
return getSettings().isMaintenance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTaskRunning() {
|
||||
return taskId != 0 && runnable != null;
|
||||
}
|
||||
|
||||
public void startMaintenanceRunnable(final int minutes, final boolean enable) {
|
||||
runnable = new MaintenanceRunnable(this, (Settings) getSettings(), minutes, enable);
|
||||
taskId = startMaintenanceRunnable(runnable);
|
||||
}
|
||||
|
||||
public String getNewestVersion() {
|
||||
return newestVersion;
|
||||
}
|
||||
|
||||
public abstract int startMaintenanceRunnable(Runnable runnable);
|
||||
|
||||
public abstract void async(Runnable runnable);
|
||||
|
||||
public abstract void cancelTask();
|
||||
|
||||
public abstract File getPluginFile();
|
||||
|
||||
public abstract void broadcast(String message);
|
||||
|
||||
public MaintenanceRunnable getRunnable() {
|
||||
return runnable;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public String formatedTimer() {
|
||||
if (!isTaskRunning()) return "-";
|
||||
final int preHours = runnable.getSecondsLeft() / 60;
|
||||
final int minutes = preHours % 60;
|
||||
final int seconds = runnable.getSecondsLeft() % 60;
|
||||
return String.format("%02d:%02d:%02d", preHours / 60, minutes, seconds);
|
||||
}
|
||||
|
||||
public boolean updateAvailable() {
|
||||
try {
|
||||
final HttpURLConnection c = (HttpURLConnection) new URL("https://api.spigotmc.org/legacy/update.php?resource=40699").openConnection();
|
||||
final String newVersion = new BufferedReader(new InputStreamReader(c.getInputStream())).readLine().replaceAll("[a-zA-Z -]", "");
|
||||
|
||||
final boolean available = !newVersion.equals(version);
|
||||
if (available)
|
||||
newestVersion = newVersion;
|
||||
|
||||
return available;
|
||||
} catch (final Exception ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean installUpdate() {
|
||||
try {
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL("https://github.com/KennyTV/Maintenance/releases/download/" + newestVersion + "/Maintenance.jar");
|
||||
} catch (final MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
final URLConnection conn = url.openConnection();
|
||||
final InputStream is = new BufferedInputStream(conn.getInputStream());
|
||||
final OutputStream os = new BufferedOutputStream(new FileOutputStream("plugins/Maintenance.tmp"));
|
||||
final byte[] chunk = new byte[1024];
|
||||
int chunkSize;
|
||||
while ((chunkSize = is.read(chunk)) != -1) {
|
||||
os.write(chunk, 0, chunkSize);
|
||||
}
|
||||
os.close();
|
||||
final File newfile = new File("plugins/Maintenance.tmp");
|
||||
final long newlength = newfile.length();
|
||||
if (newlength <= 10000) {
|
||||
newfile.delete();
|
||||
return false;
|
||||
} else {
|
||||
final FileInputStream is2 = new FileInputStream(new File("plugins/Maintenance.tmp"));
|
||||
final OutputStream os2 = new BufferedOutputStream(new FileOutputStream(getPluginFile()));
|
||||
final byte[] chunk2 = new byte[1024];
|
||||
int chunkSize2;
|
||||
while ((chunkSize2 = is2.read(chunk2)) != -1)
|
||||
os2.write(chunk2, 0, chunkSize2);
|
||||
is2.close();
|
||||
os2.close();
|
||||
|
||||
final File tmp = new File("plugins/Maintenance.tmp");
|
||||
tmp.delete();
|
||||
return true;
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
package eu.kennytv.maintenance.core;
|
||||
|
||||
import eu.kennytv.maintenance.api.ISettings;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class Settings implements ISettings {
|
||||
private static final Random RANDOM = new Random();
|
||||
protected final Map<UUID, String> whitelistedPlayers = new HashMap<>();
|
||||
private final MaintenanceModePlugin plugin;
|
||||
protected boolean maintenance;
|
||||
private Set<Integer> broadcastIntervalls;
|
||||
private List<String> pingMessages;
|
||||
private String playerCountMessage;
|
||||
private String playerCountHoverMessage;
|
||||
private String kickMessage;
|
||||
private boolean customPlayerCountMessage;
|
||||
private boolean customMaintenanceIcon;
|
||||
private boolean joinNotifications;
|
||||
|
||||
protected Settings(final MaintenanceModePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
protected void loadSettings() {
|
||||
updateConfig();
|
||||
|
||||
pingMessages = getConfigList("pingmessages");
|
||||
maintenance = getConfigBoolean("enable-maintenance-mode");
|
||||
customPlayerCountMessage = getConfigBoolean("enable-playercountmessage");
|
||||
customMaintenanceIcon = getConfigBoolean("custom-maintenance-icon");
|
||||
joinNotifications = getConfigBoolean("send-join-notification");
|
||||
broadcastIntervalls = new HashSet<>(getConfigIntList("timer-broadcast-for-seconds"));
|
||||
playerCountMessage = getColoredString(getConfigString("playercountmessage"));
|
||||
playerCountHoverMessage = getColoredString(getConfigString("playercounthovermessage"));
|
||||
kickMessage = getColoredString(getConfigString("kickmessage"));
|
||||
if (customMaintenanceIcon)
|
||||
reloadMaintenanceIcon();
|
||||
|
||||
loadExtraSettings();
|
||||
}
|
||||
|
||||
private void updateConfig() {
|
||||
boolean fileChanged = false;
|
||||
|
||||
// 2.3 pingmessage -> pingmessages
|
||||
if (configContains("pingmessage")) {
|
||||
final List<String> list = new ArrayList<>();
|
||||
list.add(getConfigString("pingmessage"));
|
||||
setToConfig("pingmessages", list);
|
||||
setToConfig("pingmessage", null);
|
||||
fileChanged = true;
|
||||
}
|
||||
// 2.4 enable-playercountmessage
|
||||
if (!configContains("enable-playercountmessage")) {
|
||||
setToConfig("enable-playercountmessage", true);
|
||||
fileChanged = true;
|
||||
}
|
||||
// 2.4. timer-broadcasts-for-minutes -> timer-broadcast-for-seconds
|
||||
if (configContains("timer-broadcasts-for-minutes") || !configContains("timer-broadcast-for-seconds")) {
|
||||
setToConfig("timer-broadcast-for-seconds", Arrays.asList(1200, 900, 600, 300, 120, 60, 30, 20, 10, 5, 4, 3, 2, 1));
|
||||
setToConfig("timer-broadcasts-for-minutes", null);
|
||||
fileChanged = true;
|
||||
}
|
||||
|
||||
if (updateExtraConfig() || fileChanged) {
|
||||
saveConfig();
|
||||
reloadConfigs();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateExtraConfig() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract void saveWhitelistedPlayers();
|
||||
|
||||
public abstract String getConfigString(String path);
|
||||
|
||||
public abstract String getMessage(String path);
|
||||
|
||||
public abstract boolean getConfigBoolean(String path);
|
||||
|
||||
public abstract List<Integer> getConfigIntList(String path);
|
||||
|
||||
public abstract List<String> getConfigList(String path);
|
||||
|
||||
public abstract void loadExtraSettings();
|
||||
|
||||
public abstract void setWhitelist(String uuid, String s);
|
||||
|
||||
public abstract void saveConfig();
|
||||
|
||||
public abstract void reloadConfigs();
|
||||
|
||||
public abstract void setToConfig(String path, Object var);
|
||||
|
||||
public abstract boolean configContains(String path);
|
||||
|
||||
public abstract String getColoredString(String s);
|
||||
|
||||
public List<String> getPingMessages() {
|
||||
return pingMessages;
|
||||
}
|
||||
|
||||
public Set<Integer> getBroadcastIntervalls() {
|
||||
return broadcastIntervalls;
|
||||
}
|
||||
|
||||
public String getPlayerCountMessage() {
|
||||
return playerCountMessage;
|
||||
}
|
||||
|
||||
public String getPlayerCountHoverMessage() {
|
||||
return playerCountHoverMessage;
|
||||
}
|
||||
|
||||
public String getKickMessage() {
|
||||
return kickMessage;
|
||||
}
|
||||
|
||||
public void setMaintenance(final boolean maintenance) {
|
||||
this.maintenance = maintenance;
|
||||
}
|
||||
|
||||
public String getRandomPingMessage() {
|
||||
if (pingMessages.isEmpty()) return "";
|
||||
final String s = pingMessages.size() > 1 ? pingMessages.get(RANDOM.nextInt(pingMessages.size())) : pingMessages.get(0);
|
||||
return getColoredString(s.replace("%NEWLINE%", "\n").replace("%TIMER%", plugin.formatedTimer()));
|
||||
}
|
||||
|
||||
public boolean hasCustomPlayerCountMessage() {
|
||||
return customPlayerCountMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMaintenance() {
|
||||
return maintenance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJoinNotifications() {
|
||||
return joinNotifications;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomIcon() {
|
||||
return customMaintenanceIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID, String> getWhitelistedPlayers() {
|
||||
return whitelistedPlayers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeWhitelistedPlayer(final UUID uuid) {
|
||||
if (!whitelistedPlayers.containsKey(uuid)) return false;
|
||||
whitelistedPlayers.remove(uuid);
|
||||
setWhitelist(uuid.toString(), null);
|
||||
saveWhitelistedPlayers();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean removeWhitelistedPlayer(final String name) {
|
||||
final Map.Entry<UUID, String> entry = whitelistedPlayers.entrySet().stream().filter(e -> e.getValue().equalsIgnoreCase(name)).findAny().orElse(null);
|
||||
if (entry == null) return false;
|
||||
|
||||
final UUID uuid = entry.getKey();
|
||||
whitelistedPlayers.remove(uuid);
|
||||
setWhitelist(uuid.toString(), null);
|
||||
saveWhitelistedPlayers();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addWhitelistedPlayer(final UUID uuid, final String name) {
|
||||
final boolean contains = !whitelistedPlayers.containsKey(uuid);
|
||||
whitelistedPlayers.put(uuid, name);
|
||||
setWhitelist(uuid.toString(), name);
|
||||
saveWhitelistedPlayers();
|
||||
return contains;
|
||||
}
|
||||
}
|
||||
-274
@@ -1,274 +0,0 @@
|
||||
package eu.kennytv.maintenance.core.command;
|
||||
|
||||
import eu.kennytv.maintenance.core.MaintenanceModePlugin;
|
||||
import eu.kennytv.maintenance.core.Settings;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class MaintenanceCommand {
|
||||
protected final MaintenanceModePlugin plugin;
|
||||
protected final Settings settings;
|
||||
private final String name;
|
||||
|
||||
protected MaintenanceCommand(final MaintenanceModePlugin plugin, final Settings settings, final String name) {
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void execute(final SenderInfo sender, final String[] args) {
|
||||
if (checkPermission(sender, "command")) return;
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("on") || args[0].equalsIgnoreCase("off")) {
|
||||
if (checkPermission(sender, "toggle")) return;
|
||||
|
||||
final boolean maintenance = args[0].equalsIgnoreCase("on");
|
||||
if (maintenance == plugin.isMaintenance()) {
|
||||
sender.sendMessage(settings.getMessage(maintenance ? "alreadyEnabled" : "alreadyDisabled"));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.setMaintenance(maintenance);
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (checkPermission(sender, "reload")) return;
|
||||
settings.reloadConfigs();
|
||||
sender.sendMessage(settings.getMessage("reload"));
|
||||
} else if (args[0].equalsIgnoreCase("update")) {
|
||||
if (checkPermission(sender, "update")) return;
|
||||
checkForUpdate(sender);
|
||||
} else if (args[0].equals("forceupdate")) {
|
||||
if (checkPermission(sender, "update")) return;
|
||||
sender.sendMessage(settings.getMessage("updateDownloading"));
|
||||
|
||||
if (plugin.installUpdate())
|
||||
sender.sendMessage(settings.getMessage("updateFinished"));
|
||||
else
|
||||
sender.sendMessage(settings.getMessage("updateFailed"));
|
||||
} else if (args[0].equalsIgnoreCase("whitelist")) {
|
||||
if (checkPermission(sender, "whitelist.list")) return;
|
||||
final Map<UUID, String> players = settings.getWhitelistedPlayers();
|
||||
if (players.isEmpty()) {
|
||||
sender.sendMessage(settings.getMessage("whitelistEmtpy"));
|
||||
} else if (players.size() == 1 && players.containsKey(UUID.fromString("a8179ff3-c201-4a75-bdaa-9d14aca6f83f"))) {
|
||||
sender.sendMessage(settings.getMessage("whitelistEmptyDefault"));
|
||||
} else {
|
||||
sender.sendMessage(settings.getMessage("whitelistedPlayers"));
|
||||
final String format = settings.getMessage("whitelistedPlayersFormat");
|
||||
players.forEach((key, value) -> sender.sendMessage(format.replace("%NAME%", value).replace("%UUID%", key.toString())));
|
||||
sender.sendMessage("");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("motd")) {
|
||||
if (checkPermission(sender, "motd")) return;
|
||||
sender.sendMessage(settings.getMessage("motdList"));
|
||||
for (int i = 0; i < settings.getPingMessages().size(); i++) {
|
||||
sender.sendMessage("§b" + (i + 1) + "§8§m---------");
|
||||
for (final String motd : settings.getColoredString(settings.getPingMessages().get(i)).split("%NEWLINE%")) {
|
||||
sender.sendMessage(motd);
|
||||
}
|
||||
}
|
||||
sender.sendMessage("§8§m----------");
|
||||
} else
|
||||
sendUsage(sender);
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("endtimer")) {
|
||||
if (checkPermission(sender, "timer")) return;
|
||||
if (!isNumeric(args[1])) {
|
||||
sender.sendMessage(settings.getMessage("endtimerUsage"));
|
||||
return;
|
||||
}
|
||||
if (plugin.isTaskRunning()) {
|
||||
sender.sendMessage(settings.getMessage("timerAlreadyRunning"));
|
||||
return;
|
||||
}
|
||||
|
||||
final int minutes = Integer.parseInt(args[1]);
|
||||
if (minutes > 40320) {
|
||||
sender.sendMessage(settings.getMessage("timerTooLong"));
|
||||
return;
|
||||
}
|
||||
if (minutes < 1) {
|
||||
sender.sendMessage("§8§o[KennyTV whispers to you] §c§oThink about running a timer for a negative amount of minutes. Doesn't work §lthat §c§owell.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.isMaintenance())
|
||||
plugin.setMaintenance(true);
|
||||
plugin.startMaintenanceRunnable(minutes, false);
|
||||
sender.sendMessage(settings.getMessage("endtimerStarted").replace("%TIME%", plugin.getRunnable().getTime()));
|
||||
} else if (args[0].equalsIgnoreCase("starttimer")) {
|
||||
if (checkPermission(sender, "timer")) return;
|
||||
if (!isNumeric(args[1])) {
|
||||
sender.sendMessage(settings.getMessage("starttimerUsage"));
|
||||
return;
|
||||
}
|
||||
if (plugin.isMaintenance()) {
|
||||
sender.sendMessage(settings.getMessage("alreadyEnabled"));
|
||||
return;
|
||||
}
|
||||
if (plugin.isTaskRunning()) {
|
||||
sender.sendMessage(settings.getMessage("timerAlreadyRunning"));
|
||||
return;
|
||||
}
|
||||
|
||||
final int minutes = Integer.parseInt(args[1]);
|
||||
if (minutes > 40320) {
|
||||
sender.sendMessage(settings.getMessage("timerTooLong"));
|
||||
return;
|
||||
}
|
||||
if (minutes < 1) {
|
||||
sender.sendMessage("§8§o[KennyTV whispers to you] §c§oThink about running a timer for a negative amount of minutes. Doesn't work §lthat §c§owell.");
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(settings.getMessage("starttimerStarted").replace("%TIME%", plugin.getRunnable().getTime()));
|
||||
plugin.startMaintenanceRunnable(minutes, true);
|
||||
} else if (args[0].equalsIgnoreCase("timer")) {
|
||||
if (args[1].equalsIgnoreCase("abort") || args[1].equalsIgnoreCase("stop") || args[1].equalsIgnoreCase("cancel")) {
|
||||
if (checkPermission(sender, "timer")) return;
|
||||
if (!plugin.isTaskRunning()) {
|
||||
sender.sendMessage(settings.getMessage("timerNotRunning"));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.cancelTask();
|
||||
sender.sendMessage(settings.getMessage("timerCancelled"));
|
||||
} else
|
||||
sendUsage(sender);
|
||||
} else if (args[0].equalsIgnoreCase("add")) {
|
||||
if (checkPermission(sender, "whitelist.add")) return;
|
||||
addPlayerToWhitelist(sender, args[1]);
|
||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
||||
if (checkPermission(sender, "whitelist.remove")) return;
|
||||
removePlayerFromWhitelist(sender, args[1]);
|
||||
} else if (args[0].equalsIgnoreCase("removemotd")) {
|
||||
if (checkPermission(sender, "setmotd")) return;
|
||||
if (!isNumeric(args[1])) {
|
||||
sender.sendMessage(settings.getMessage("removeMotdUsage"));
|
||||
return;
|
||||
}
|
||||
if (settings.getPingMessages().size() < 2) {
|
||||
sender.sendMessage(settings.getMessage("removeMotdError"));
|
||||
return;
|
||||
}
|
||||
|
||||
final int index = Integer.parseInt(args[1]);
|
||||
if (index > settings.getPingMessages().size()) {
|
||||
sender.sendMessage(settings.getMessage("setMotdIndexError").replace("%MOTDS%", Integer.toString(settings.getPingMessages().size()))
|
||||
.replace("%NEWAMOUNT%", Integer.toString(settings.getPingMessages().size())));
|
||||
return;
|
||||
}
|
||||
|
||||
settings.getPingMessages().remove(index - 1);
|
||||
settings.setToConfig("pingmessages", settings.getPingMessages());
|
||||
settings.saveConfig();
|
||||
settings.reloadConfigs();
|
||||
sender.sendMessage(settings.getMessage("removedMotd").replace("%INDEX%", args[1]));
|
||||
} else
|
||||
sendUsage(sender);
|
||||
} else if (args.length > 3 && args[0].equalsIgnoreCase("setmotd")) {
|
||||
if (checkPermission(sender, "setmotd")) return;
|
||||
if (!isNumeric(args[1])) {
|
||||
sender.sendMessage(settings.getMessage("setMotdUsage"));
|
||||
return;
|
||||
}
|
||||
|
||||
final int index = Integer.parseInt(args[1]);
|
||||
if (index < 1 || index > settings.getPingMessages().size() + 1) {
|
||||
sender.sendMessage(settings.getMessage("setMotdIndexError").replace("%MOTDS%", Integer.toString(settings.getPingMessages().size()))
|
||||
.replace("%NEWAMOUNT%", Integer.toString(settings.getPingMessages().size() + 1)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isNumeric(args[2])) {
|
||||
sender.sendMessage(settings.getMessage("setMotdLineError"));
|
||||
return;
|
||||
}
|
||||
|
||||
final int line = Integer.parseInt(args[2]);
|
||||
if (line != 1 && line != 2) {
|
||||
sender.sendMessage(settings.getMessage("setMotdLineError"));
|
||||
return;
|
||||
}
|
||||
|
||||
final String message = String.join(" ", Arrays.copyOfRange(args, 3, args.length));
|
||||
final String oldMessage = index > settings.getPingMessages().size() ? "" : settings.getPingMessages().get(index - 1);
|
||||
final String newMessage;
|
||||
if (line == 1)
|
||||
newMessage = oldMessage.contains("%NEWLINE%") ?
|
||||
message + "%NEWLINE%" + oldMessage.split("%NEWLINE%", 2)[1] : message;
|
||||
else
|
||||
newMessage = oldMessage.contains("%NEWLINE%") ?
|
||||
oldMessage.split("%NEWLINE%", 2)[0] + "%NEWLINE%" + message : oldMessage + "%NEWLINE%" + message;
|
||||
|
||||
if (index > settings.getPingMessages().size())
|
||||
settings.getPingMessages().add(newMessage);
|
||||
else
|
||||
settings.getPingMessages().set(index - 1, newMessage);
|
||||
settings.setToConfig("pingmessages", settings.getPingMessages());
|
||||
settings.saveConfig();
|
||||
settings.reloadConfigs();
|
||||
sender.sendMessage(settings.getMessage("setMotd").replace("%LINE%", args[2]).replace("%INDEX%", args[1])
|
||||
.replace("%MOTD%", "§f" + settings.getColoredString(message)));
|
||||
} else
|
||||
sendUsage(sender);
|
||||
}
|
||||
|
||||
private void sendUsage(final SenderInfo sender) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage("§8===========[ §e" + name + " §8| §eVersion: §e" + plugin.getVersion() + " §8]===========");
|
||||
if (sender.hasPermission("maintenance.reload"))
|
||||
sender.sendMessage("§6/maintenance reload §7(Reloads the config file, whitelist file and the server-icon)");
|
||||
if (sender.hasPermission("maintenance.toggle")) {
|
||||
sender.sendMessage("§6/maintenance on §7(Enables maintenance mode");
|
||||
sender.sendMessage("§6/maintenance off §7(Disables maintenance mode)");
|
||||
}
|
||||
if (sender.hasPermission("maintenance.timer")) {
|
||||
sender.sendMessage("§6/maintenance starttimer <minutes> §7(After the given time in minutes, maintenance mode will be enabled)");
|
||||
sender.sendMessage("§6/maintenance endtimer <minutes> §7(Enables maintenance mode. After the given time in minutes, maintenance mode will be disabled)");
|
||||
sender.sendMessage("§6/maintenance timer abort §7(If running, the current timer will be aborted)");
|
||||
}
|
||||
if (sender.hasPermission("maintenance.whitelist.list"))
|
||||
sender.sendMessage("§6/maintenance whitelist §7(Shows all whitelisted players for the maintenance mode)");
|
||||
if (sender.hasPermission("maintenance.whitelist.add"))
|
||||
sender.sendMessage("§6/maintenance add <player> §7(Adds the player to the maintenance whitelist, so they can join the server even though maintenance is enabled)");
|
||||
if (sender.hasPermission("maintenance.whitelist.remove"))
|
||||
sender.sendMessage("§6/maintenance remove <player> §7(Removes the player from the maintenance whitelist)");
|
||||
if (sender.hasPermission("maintenance.setmotd")) {
|
||||
sender.sendMessage("§6/maintenance setmotd <index> <1/2> <message> §7(Sets a motd for maintenance mode)");
|
||||
sender.sendMessage("§6/maintenance removemotd <index> §7(Removes a maintenance motd)");
|
||||
}
|
||||
if (sender.hasPermission("maintenance.motd"))
|
||||
sender.sendMessage("§6/maintenance motd §7(Lists the currently set maintenance motds)");
|
||||
if (sender.hasPermission("maintenance.update"))
|
||||
sender.sendMessage("§6/maintenance update §7(Remotely downloads the newest version of the plugin onto your server)");
|
||||
sender.sendMessage("§8× §7Created by §bKennyTV");
|
||||
sender.sendMessage("§8===========[ §e" + name + " §8| §eVersion: §e" + plugin.getVersion() + " §8]===========");
|
||||
sender.sendMessage("");
|
||||
}
|
||||
|
||||
private boolean checkPermission(final SenderInfo sender, final String permission) {
|
||||
if (!sender.hasPermission("maintenance." + permission)) {
|
||||
sender.sendMessage(settings.getMessage("noPermission"));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isNumeric(final String string) {
|
||||
try {
|
||||
Integer.parseInt(string);
|
||||
} catch (final NumberFormatException nfe) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void addPlayerToWhitelist(SenderInfo sender, String name);
|
||||
|
||||
protected abstract void removePlayerFromWhitelist(SenderInfo sender, String name);
|
||||
|
||||
protected abstract void checkForUpdate(SenderInfo sender);
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package eu.kennytv.maintenance.core.hook;
|
||||
|
||||
import net.minecrell.serverlistplus.core.ServerListPlusCore;
|
||||
|
||||
public final class ServerListPlusHook {
|
||||
private final ServerListPlusCore serverListPlusCore;
|
||||
|
||||
public ServerListPlusHook(final ServerListPlusCore serverListPlusCore) {
|
||||
this.serverListPlusCore = serverListPlusCore;
|
||||
}
|
||||
|
||||
public void setEnabled(final boolean enable) {
|
||||
serverListPlusCore.getProfiles().setEnabled(enable);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package eu.kennytv.maintenance.core.listener;
|
||||
|
||||
public interface IPingListener {
|
||||
|
||||
boolean loadIcon();
|
||||
}
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
package eu.kennytv.maintenance.core.runnable;
|
||||
|
||||
import eu.kennytv.maintenance.core.MaintenanceModePlugin;
|
||||
import eu.kennytv.maintenance.core.Settings;
|
||||
|
||||
public final class MaintenanceRunnable implements Runnable {
|
||||
private final MaintenanceModePlugin plugin;
|
||||
private final Settings settings;
|
||||
private final boolean enable;
|
||||
private int seconds;
|
||||
|
||||
public MaintenanceRunnable(final MaintenanceModePlugin plugin, final Settings settings, final int minutes, final boolean enable) {
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
this.seconds = minutes * 60;
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (seconds == 0) {
|
||||
plugin.setMaintenance(enable);
|
||||
if (plugin.isTaskRunning())
|
||||
plugin.cancelTask();
|
||||
} else if (settings.getBroadcastIntervalls().contains(seconds)) {
|
||||
if (enable)
|
||||
plugin.broadcast(settings.getMessage("starttimerBroadcast").replaceAll("%TIME%", getTime()));
|
||||
else
|
||||
plugin.broadcast(settings.getMessage("endtimerBroadcast").replaceAll("%TIME%", getTime()));
|
||||
}
|
||||
|
||||
seconds--;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
final int preHours = this.seconds / 60;
|
||||
final int minutes = preHours % 60;
|
||||
final int seconds = this.seconds % 60;
|
||||
|
||||
final StringBuilder buider = new StringBuilder();
|
||||
append(buider, "hour", preHours / 60);
|
||||
append(buider, "minute", minutes);
|
||||
append(buider, "second", seconds);
|
||||
return buider.toString();
|
||||
}
|
||||
|
||||
private void append(final StringBuilder builder, final String timeUnit, final int time) {
|
||||
if (time == 0) return;
|
||||
if (builder.length() != 0)
|
||||
builder.append(" ");
|
||||
builder.append(time).append(" ").append(settings.getMessage(time == 1 ? timeUnit : timeUnit + "s"));
|
||||
}
|
||||
|
||||
public int getSecondsLeft() {
|
||||
return seconds;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package eu.kennytv.maintenance.core.util;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class SenderInfo {
|
||||
|
||||
public abstract UUID getUuid();
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract boolean hasPermission(String permission);
|
||||
|
||||
public abstract void sendMessage(String message);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
a8179ff3-c201-4a75-bdaa-9d14aca6f83f: KennyTV
|
||||
@@ -1,48 +0,0 @@
|
||||
# Maintenance Plugin by KennyTV
|
||||
# Don't remove words inbetween the '%' if you don't exactly know why you're doing it
|
||||
|
||||
noPermission: "&cYou do not have the permission to execute that command."
|
||||
reload: "&8[&eMaintenance&8] &aReloaded config, whitelistedplayers, language file and the maintenance icon."
|
||||
alreadyEnabled: "&8[&eMaintenance&8] &cMaintenance already is enabled!"
|
||||
alreadyDisabled: "&8[&eMaintenance&8] &cMaintenance already is disabled!"
|
||||
maintenanceActivated: "&8[&eMaintenance&8] &6Maintenance mode is now activated."
|
||||
maintenanceDeactivated: "&8[&eMaintenance&8] &6Maintenance mode is now deactivated."
|
||||
starttimerUsage: "&8[&eMaintenance&8] &c/maintenance starttimer <minutes>"
|
||||
starttimerStarted: "&8[&eMaintenance&8] &aStarted timer: &7Maintenance mode will be activated in &6%TIME%&7."
|
||||
starttimerBroadcast: "&8[&eMaintenance&8] &7Maintenance mode will be enabled in &6%TIME%&7."
|
||||
endtimerUsage: "&8[&eMaintenance&8] &c/maintenance endtimer <minutes>"
|
||||
endtimerStarted: "&8[&eMaintenance&8] &aStarted timer: &7Maintenance mode will be deactivated in &6%TIME%&7."
|
||||
endtimerBroadcast: "&8[&eMaintenance&8] &7Maintenance mode will be disabled in &6%TIME%&7."
|
||||
timerTooLong: "&8[&eMaintenance&8] &cThe number has to be less than 40320 (28 days)!"
|
||||
timerAlreadyRunning: "&8[&eMaintenance&8] &cThere's already a starttimer scheduled!"
|
||||
timerNotRunning: "&8[&eMaintenance&8] &cThere's currently no running timer."
|
||||
timerCancelled: "&8[&eMaintenance&8] &cThe current timer has been disabled."
|
||||
joinNotification: "&8[&eMaintenance&8] &e%PLAYER% &ctried to join the server."
|
||||
updateDownloading: "&8[&eMaintenance&8] &c&lDownloading update..."
|
||||
updateFinished: "&8[&eMaintenance&8] &a&lThe update was successful! To prevent issues with tasks and to complete the update, you have to restart the server!"
|
||||
updateFailed: "&8[&eMaintenance&8] &4&lUpdate failed!"
|
||||
setMotdUsage: "&8[&eMaintenance&8] &c/maintenance setmotd <index> <1/2> <message>"
|
||||
setMotdLineError: "&8[&eMaintenance&8] &cThe second argument has to be the line number (1 or 2)!"
|
||||
setMotdIndexError: "&8[&eMaintenance&8] §cYou currently have %MOTDS% motds, so you have to pick a number between 1 and %NEWAMOUNT%."
|
||||
setMotd: "&8[&eMaintenance&8] &aSet line %LINE% of the %INDEX%. maintenance motd to %MOTD%"
|
||||
removeMotdUsage: "&8[&eMaintenance&8] &c/maintenance removemotd <index>"
|
||||
removeMotdError: "&8[&eMaintenance&8] &cYou only have one motd, so you can't remove any!"
|
||||
removedMotd: "&8[&eMaintenance&8] &aRemoved motd number %INDEX%."
|
||||
motdList: "&8[&eMaintenance&8] &7List of your maintenance motds:"
|
||||
whitelistEmtpy: "&8[&eMaintenance&8] &cThe maintenance whitelist is empty! Use '/maintenance add <player>' to add someone!"
|
||||
whitelistEmptyDefault: "&8[&eMaintenance&8] &cUse '/maintenance add <player>' to add someone. Alternatively, you can add the uuid of a player to the WhitelistedPlayers.yml as seen in the example in the file!"
|
||||
whitelistedPlayers: "&8[&eMaintenance&8] &6Whitelisted players for maintenance:"
|
||||
whitelistedPlayersFormat: "&8- &e%NAME% &8(&7%UUID%&8)"
|
||||
whitelistNotFound: "&8[&eMaintenance&8] &cThis player is not in the maintenance whitelist!"
|
||||
whitelistAlreadyAdded: "&8[&eMaintenance&8] &b%PLAYER% &calready is in the maintenance whitelist!"
|
||||
whitelistAdded: "&8[&eMaintenance&8] &aAdded &b%PLAYER% &ato the maintenance whitelist!"
|
||||
whitelistRemoved: "&8[&eMaintenance&8] &aRemoved &b%PLAYER% &afrom the maintenance whitelist!"
|
||||
playerNotOnline: "&8[&eMaintenance&8] &cThere's no player online with that name."
|
||||
playerNotFound: "&8[&eMaintenance&8] &cNo player with this name has played on this server before."
|
||||
|
||||
second: "second"
|
||||
seconds: "seconds"
|
||||
minute: "minute"
|
||||
minutes: "minutes"
|
||||
hour: "hour"
|
||||
hours: "hours"
|
||||
@@ -1,35 +0,0 @@
|
||||
<?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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>maintenance-base</artifactId>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<version>2.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-parent</artifactId>
|
||||
<name>Maintenance</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<artifactId>maintenance-core</artifactId>
|
||||
<version>${parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<artifactId>maintenance-bungee</artifactId>
|
||||
<version>${parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<artifactId>maintenance-spigot</artifactId>
|
||||
<version>${parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,52 +0,0 @@
|
||||
<?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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>maintenance-base</artifactId>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<version>2.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-spigot</artifactId>
|
||||
<name>MaintenanceSpigot</name>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dmulloy2-repo</id>
|
||||
<url>http://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<artifactId>maintenance-core</artifactId>
|
||||
<version>${parent.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.13.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.minecrell</groupId>
|
||||
<artifactId>ServerListPlus</artifactId>
|
||||
<version>3.4.8</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib-API</artifactId>
|
||||
<version>4.4.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
package eu.kennytv.maintenance.spigot;
|
||||
|
||||
import eu.kennytv.maintenance.api.IMaintenance;
|
||||
import eu.kennytv.maintenance.api.IMaintenanceBase;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public final class MaintenanceSpigotBase extends JavaPlugin implements IMaintenanceBase {
|
||||
private IMaintenance maintenance;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
maintenance = new MaintenanceSpigotPlugin(this);
|
||||
}
|
||||
|
||||
File getPluginFile() {
|
||||
return getFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMaintenance getApi() {
|
||||
return maintenance;
|
||||
}
|
||||
}
|
||||
-111
@@ -1,111 +0,0 @@
|
||||
package eu.kennytv.maintenance.spigot;
|
||||
|
||||
import eu.kennytv.maintenance.api.IMaintenance;
|
||||
import eu.kennytv.maintenance.api.ISettings;
|
||||
import eu.kennytv.maintenance.api.MaintenanceSpigotAPI;
|
||||
import eu.kennytv.maintenance.core.MaintenanceModePlugin;
|
||||
import eu.kennytv.maintenance.core.hook.ServerListPlusHook;
|
||||
import eu.kennytv.maintenance.spigot.command.MaintenanceSpigotCommand;
|
||||
import eu.kennytv.maintenance.spigot.listener.PlayerLoginListener;
|
||||
import eu.kennytv.maintenance.spigot.metrics.MetricsLite;
|
||||
import net.minecrell.serverlistplus.core.plugin.ServerListPlusPlugin;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author KennyTV
|
||||
* @since 2.0
|
||||
*/
|
||||
public final class MaintenanceSpigotPlugin extends MaintenanceModePlugin {
|
||||
private final MaintenanceSpigotBase plugin;
|
||||
private final SettingsSpigot settings;
|
||||
|
||||
MaintenanceSpigotPlugin(final MaintenanceSpigotBase plugin) {
|
||||
super("§8[§eMaintenanceSpigot§8] ", plugin.getDescription().getVersion());
|
||||
|
||||
this.plugin = plugin;
|
||||
settings = new SettingsSpigot(this, plugin);
|
||||
|
||||
plugin.getLogger().info("Plugin by KennyTV");
|
||||
plugin.getCommand("maintenancespigot").setExecutor(new MaintenanceSpigotCommand(this, settings));
|
||||
|
||||
final PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvents(new PlayerLoginListener(this, settings), plugin);
|
||||
|
||||
new MetricsLite(plugin);
|
||||
|
||||
// ServerListPlus integration
|
||||
final Plugin serverListPlus = pm.getPlugin("ServerListPlus");
|
||||
if (serverListPlus != null) {
|
||||
serverListPlusHook = new ServerListPlusHook(((ServerListPlusPlugin) serverListPlus).getCore());
|
||||
serverListPlusHook.setEnabled(!settings.isMaintenance());
|
||||
plugin.getLogger().info("Enabled ServerListPlus integration!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaintenance(final boolean maintenance) {
|
||||
settings.setMaintenance(maintenance);
|
||||
settings.setToConfig("enable-maintenance-mode", maintenance);
|
||||
settings.saveConfig();
|
||||
settings.reloadConfigs();
|
||||
|
||||
if (isTaskRunning())
|
||||
cancelTask();
|
||||
|
||||
if (serverListPlusHook != null)
|
||||
serverListPlusHook.setEnabled(!maintenance);
|
||||
|
||||
if (maintenance) {
|
||||
getServer().getOnlinePlayers().stream()
|
||||
.filter(p -> !p.hasPermission("maintenance.bypass") && !settings.getWhitelistedPlayers().containsKey(p.getUniqueId()))
|
||||
.forEach(p -> p.kickPlayer(settings.getKickMessage().replace("%NEWLINE%", "\n")));
|
||||
getServer().broadcastMessage(settings.getMessage("maintenanceActivated"));
|
||||
} else
|
||||
getServer().broadcastMessage(settings.getMessage("maintenanceDeactivated"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int startMaintenanceRunnable(final Runnable runnable) {
|
||||
return getServer().getScheduler().scheduleSyncRepeatingTask(plugin, runnable, 0, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void async(final Runnable runnable) {
|
||||
getServer().getScheduler().runTaskAsynchronously(plugin, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTask() {
|
||||
getServer().getScheduler().cancelTask(taskId);
|
||||
runnable = null;
|
||||
taskId = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISettings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getPluginFile() {
|
||||
return plugin.getPluginFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(final String message) {
|
||||
getServer().broadcastMessage(message);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static IMaintenance getAPI() {
|
||||
return MaintenanceSpigotAPI.getAPI();
|
||||
}
|
||||
|
||||
public Server getServer() {
|
||||
return plugin.getServer();
|
||||
}
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
package eu.kennytv.maintenance.spigot;
|
||||
|
||||
import eu.kennytv.maintenance.core.Settings;
|
||||
import eu.kennytv.maintenance.core.listener.IPingListener;
|
||||
import eu.kennytv.maintenance.spigot.listener.PacketListener;
|
||||
import eu.kennytv.maintenance.spigot.listener.ServerListPingListener;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class SettingsSpigot extends Settings {
|
||||
private final MaintenanceSpigotBase plugin;
|
||||
private final IPingListener pingListener;
|
||||
private FileConfiguration config;
|
||||
private FileConfiguration language;
|
||||
private FileConfiguration whitelist;
|
||||
|
||||
SettingsSpigot(final MaintenanceSpigotPlugin pl, final MaintenanceSpigotBase plugin) {
|
||||
super(pl);
|
||||
this.plugin = plugin;
|
||||
|
||||
final PluginManager pm = plugin.getServer().getPluginManager();
|
||||
if (pm.getPlugin("ProtocolLib") != null) {
|
||||
pingListener = new PacketListener(plugin, this);
|
||||
} else {
|
||||
final ServerListPingListener listener = new ServerListPingListener(plugin, this);
|
||||
pm.registerEvents(listener, plugin);
|
||||
pingListener = listener;
|
||||
}
|
||||
|
||||
if (!plugin.getDataFolder().exists())
|
||||
plugin.getDataFolder().mkdirs();
|
||||
createFile("spigot-config.yml");
|
||||
createFile("language.yml");
|
||||
createFile("WhitelistedPlayers.yml");
|
||||
|
||||
reloadConfigs();
|
||||
}
|
||||
|
||||
private void createFile(final String name) {
|
||||
final File file = new File(plugin.getDataFolder(), name);
|
||||
if (!file.exists()) {
|
||||
try (final InputStream in = plugin.getResource(name)) {
|
||||
Files.copy(in, file.toPath());
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("Unable to create " + name + " file for Maintenance!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveConfig() {
|
||||
try {
|
||||
config.save(new File(plugin.getDataFolder(), "spigot-config.yml"));
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveWhitelistedPlayers() {
|
||||
try {
|
||||
whitelist.save(new File(plugin.getDataFolder(), "WhitelistedPlayers.yml"));
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfigs() {
|
||||
try {
|
||||
final File file = new File(plugin.getDataFolder(), "spigot-config.yml");
|
||||
config = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
|
||||
final File languageFile = new File(plugin.getDataFolder(), "language.yml");
|
||||
language = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(languageFile), StandardCharsets.UTF_8));
|
||||
whitelist = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "WhitelistedPlayers.yml"));
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("Unable to load Maintenance files!", e);
|
||||
}
|
||||
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadExtraSettings() {
|
||||
whitelistedPlayers.clear();
|
||||
whitelist.getKeys(false).forEach(key -> whitelistedPlayers.put(UUID.fromString(key), whitelist.getString(key)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhitelist(final String uuid, final String s) {
|
||||
whitelist.set(uuid, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigString(final String path) {
|
||||
final String s = config.getString(path);
|
||||
if (s == null) {
|
||||
plugin.getLogger().warning("The config is missing the following string: " + path);
|
||||
return "null";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage(final String path) {
|
||||
final String s = language.getString(path);
|
||||
if (s == null) {
|
||||
plugin.getLogger().warning("The language file is missing the following string: " + path);
|
||||
return "null";
|
||||
}
|
||||
return ChatColor.translateAlternateColorCodes('&', s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getConfigBoolean(final String path) {
|
||||
return config.getBoolean(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getConfigIntList(final String path) {
|
||||
return config.getIntegerList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getConfigList(final String path) {
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setToConfig(final String path, final Object var) {
|
||||
config.set(path, var);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configContains(final String path) {
|
||||
return config.contains(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColoredString(final String message) {
|
||||
return ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reloadMaintenanceIcon() {
|
||||
return pingListener.loadIcon();
|
||||
}
|
||||
}
|
||||
-83
@@ -1,83 +0,0 @@
|
||||
package eu.kennytv.maintenance.spigot.command;
|
||||
|
||||
import eu.kennytv.maintenance.core.command.MaintenanceCommand;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
import eu.kennytv.maintenance.spigot.MaintenanceSpigotPlugin;
|
||||
import eu.kennytv.maintenance.spigot.SettingsSpigot;
|
||||
import eu.kennytv.maintenance.spigot.util.BukkitSenderInfo;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public final class MaintenanceSpigotCommand extends MaintenanceCommand implements CommandExecutor {
|
||||
|
||||
public MaintenanceSpigotCommand(final MaintenanceSpigotPlugin plugin, final SettingsSpigot settings) {
|
||||
super(plugin, settings, "MaintenanceSpigot");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String s, final String[] args) {
|
||||
execute(new BukkitSenderInfo(sender), args);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addPlayerToWhitelist(final SenderInfo sender, final String name) {
|
||||
final Player selected = Bukkit.getPlayer(name);
|
||||
if (selected != null) {
|
||||
if (settings.addWhitelistedPlayer(selected.getUniqueId(), selected.getName()))
|
||||
sender.sendMessage(settings.getMessage("whitelistAdded").replace("%PLAYER%", selected.getName()));
|
||||
else
|
||||
sender.sendMessage(settings.getMessage("whitelistAlreadyAdded").replace("%PLAYER%", selected.getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
sender.sendMessage(settings.getMessage("playerNotFound"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (settings.addWhitelistedPlayer(offlinePlayer.getUniqueId(), offlinePlayer.getName()))
|
||||
sender.sendMessage(settings.getMessage("whitelistAdded").replace("%PLAYER%", offlinePlayer.getName()));
|
||||
else
|
||||
sender.sendMessage(settings.getMessage("whitelistAlreadyAdded").replace("%PLAYER%", offlinePlayer.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void removePlayerFromWhitelist(final SenderInfo sender, final String name) {
|
||||
final Player selected = Bukkit.getPlayer(name);
|
||||
if (selected != null) {
|
||||
if (settings.removeWhitelistedPlayer(selected.getUniqueId()))
|
||||
sender.sendMessage(settings.getMessage("whitelistRemoved").replace("%PLAYER%", selected.getName()));
|
||||
else
|
||||
sender.sendMessage(settings.getMessage("whitelistNotFound"));
|
||||
return;
|
||||
}
|
||||
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
sender.sendMessage(settings.getMessage("playerNotFound"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (settings.removeWhitelistedPlayer(offlinePlayer.getUniqueId()))
|
||||
sender.sendMessage(settings.getMessage("whitelistRemoved").replace("%PLAYER%", offlinePlayer.getName()));
|
||||
else
|
||||
sender.sendMessage(settings.getMessage("whitelistNotFound"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkForUpdate(final SenderInfo sender) {
|
||||
if (plugin.updateAvailable()) {
|
||||
sender.sendMessage(plugin.getPrefix() + "§cNewest version available: §aVersion " + plugin.getNewestVersion() + "§c, you're on §a" + plugin.getVersion());
|
||||
sender.sendMessage(plugin.getPrefix() + "§c§lWARNING: §cYou will have to restart the server to prevent further issues and to complete the update!" +
|
||||
" If you can't do that, don't update!");
|
||||
sender.sendMessage(plugin.getPrefix() + "§eUse §c§l/maintenance forceupdate §eto update!");
|
||||
} else
|
||||
sender.sendMessage(plugin.getPrefix() + "§aYou already have the latest version of the plugin!");
|
||||
}
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
package eu.kennytv.maintenance.spigot.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.comphenix.protocol.wrappers.WrappedServerPing;
|
||||
import com.google.common.collect.Lists;
|
||||
import eu.kennytv.maintenance.core.listener.IPingListener;
|
||||
import eu.kennytv.maintenance.spigot.MaintenanceSpigotBase;
|
||||
import eu.kennytv.maintenance.spigot.SettingsSpigot;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class PacketListener implements IPingListener {
|
||||
private final MaintenanceSpigotBase pl;
|
||||
private WrappedServerPing.CompressedImage image;
|
||||
|
||||
public PacketListener(final MaintenanceSpigotBase base, final SettingsSpigot settings) {
|
||||
this.pl = base;
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(base, ListenerPriority.HIGHEST,
|
||||
PacketType.Status.Server.SERVER_INFO) {
|
||||
@Override
|
||||
public void onPacketSending(final PacketEvent event) {
|
||||
if (!settings.isMaintenance()) return;
|
||||
|
||||
final WrappedServerPing ping = event.getPacket().getServerPings().read(0);
|
||||
ping.setMotD(settings.getRandomPingMessage());
|
||||
|
||||
if (settings.hasCustomPlayerCountMessage()) {
|
||||
ping.setVersionProtocol(0);
|
||||
ping.setVersionName(settings.getPlayerCountMessage()
|
||||
.replace("%ONLINE%", Integer.toString(pl.getServer().getOnlinePlayers().size()))
|
||||
.replace("%MAX%", Integer.toString(pl.getServer().getMaxPlayers())));
|
||||
}
|
||||
|
||||
final List<WrappedGameProfile> players = Lists.newArrayList();
|
||||
for (final String string : settings.getPlayerCountHoverMessage().split("%NEWLINE%"))
|
||||
players.add(new WrappedGameProfile(UUID.randomUUID(), string));
|
||||
ping.setPlayers(players);
|
||||
|
||||
if (settings.hasCustomIcon() && image != null)
|
||||
ping.setFavicon(image);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadIcon() {
|
||||
try {
|
||||
image = WrappedServerPing.CompressedImage.fromPng(ImageIO.read(new File("maintenance-icon.png")));
|
||||
} catch (final Exception e) {
|
||||
pl.getLogger().warning("§4Could not load 'maintenance-icon.png' - did you create one in your Spigot folder (not the plugins folder)?");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
-70
@@ -1,70 +0,0 @@
|
||||
package eu.kennytv.maintenance.spigot.listener;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import eu.kennytv.maintenance.spigot.MaintenanceSpigotPlugin;
|
||||
import eu.kennytv.maintenance.spigot.SettingsSpigot;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class PlayerLoginListener implements Listener {
|
||||
private final MaintenanceSpigotPlugin plugin;
|
||||
private final SettingsSpigot settings;
|
||||
private final Set<UUID> notifiedPlayers = Sets.newHashSet();
|
||||
|
||||
public PlayerLoginListener(final MaintenanceSpigotPlugin plugin, final SettingsSpigot settings) {
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void postLogin(final PlayerLoginEvent event) {
|
||||
final Player p = event.getPlayer();
|
||||
if (p.getUniqueId().toString().equals("a8179ff3-c201-4a75-bdaa-9d14aca6f83f"))
|
||||
p.sendMessage("§6MaintenanceSpigot §aVersion " + plugin.getVersion());
|
||||
else if (settings.isMaintenance()) {
|
||||
if (!p.hasPermission("maintenance.bypass") && !settings.getWhitelistedPlayers().containsKey(p.getUniqueId())) {
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
event.setKickMessage(settings.getKickMessage().replace("%NEWLINE%", "\n"));
|
||||
|
||||
if (settings.isJoinNotifications())
|
||||
Bukkit.getOnlinePlayers().stream().filter(player -> player.hasPermission("maintenance.joinnotification"))
|
||||
.forEach(player -> player.sendMessage(settings.getMessage("joinNotification").replace("%PLAYER%", p.getName())));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!p.hasPermission("maintenance.admin") || notifiedPlayers.contains(p.getUniqueId())) return;
|
||||
|
||||
plugin.async(() -> {
|
||||
if (plugin.updateAvailable()) {
|
||||
p.sendMessage(plugin.getPrefix() + "§cThere is a newer version available: §aVersion " + plugin.getNewestVersion() + "§c, you're on §a" + plugin.getVersion());
|
||||
notifiedPlayers.add(p.getUniqueId());
|
||||
|
||||
try {
|
||||
final TextComponent tc1 = new TextComponent(TextComponent.fromLegacyText(plugin.getPrefix()));
|
||||
final TextComponent tc2 = new TextComponent(TextComponent.fromLegacyText("§cDownload it at: §6https://www.spigotmc.org/resources/maintenancemode.40699/"));
|
||||
final TextComponent click = new TextComponent(TextComponent.fromLegacyText(" §7§l§o(CLICK ME)"));
|
||||
click.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/maintenancemode.40699/"));
|
||||
click.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aDownload the latest version").create()));
|
||||
tc1.addExtra(tc2);
|
||||
tc1.addExtra(click);
|
||||
|
||||
p.spigot().sendMessage(tc1);
|
||||
} catch (final Exception e) {
|
||||
p.sendMessage(plugin.getPrefix() + "§cDownload it at: §6https://www.spigotmc.org/resources/maintenancemode.40699/");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package eu.kennytv.maintenance.spigot.listener;
|
||||
|
||||
import eu.kennytv.maintenance.core.listener.IPingListener;
|
||||
import eu.kennytv.maintenance.spigot.MaintenanceSpigotBase;
|
||||
import eu.kennytv.maintenance.spigot.SettingsSpigot;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.File;
|
||||
|
||||
public final class ServerListPingListener implements Listener, IPingListener {
|
||||
private final MaintenanceSpigotBase plugin;
|
||||
private final SettingsSpigot settings;
|
||||
private CachedServerIcon serverIcon;
|
||||
|
||||
public ServerListPingListener(final MaintenanceSpigotBase plugin, final SettingsSpigot settings) {
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void serverListPing(final ServerListPingEvent event) {
|
||||
if (!settings.isMaintenance()) return;
|
||||
|
||||
event.setMaxPlayers(0);
|
||||
event.setMotd(settings.getRandomPingMessage());
|
||||
|
||||
if (settings.hasCustomIcon() && serverIcon != null)
|
||||
event.setServerIcon(serverIcon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadIcon() {
|
||||
try {
|
||||
serverIcon = plugin.getServer().loadServerIcon(ImageIO.read(new File("maintenance-icon.png")));
|
||||
} catch (final Exception e) {
|
||||
plugin.getLogger().warning("§4Could not load 'maintenance-icon.png' - did you create one in your Spigot folder (not the plugins folder)?");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package eu.kennytv.maintenance.spigot.util;
|
||||
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class BukkitSenderInfo extends SenderInfo {
|
||||
private final CommandSender sender;
|
||||
|
||||
public BukkitSenderInfo(final CommandSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUuid() {
|
||||
return sender instanceof Player ? ((Player) sender).getUniqueId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return sender.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String permission) {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(final String message) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
name: ${project.name}
|
||||
version: ${project.version}
|
||||
main: eu.kennytv.maintenance.spigot.MaintenanceSpigotBase
|
||||
author: KennyTV
|
||||
softdepend: [ProtocolLib, ServerListPlus]
|
||||
website: https://www.spigotmc.org/resources/maintenancemode.40699/
|
||||
|
||||
commands:
|
||||
maintenance:
|
||||
description: Maintenance main-command
|
||||
aliases: [maintenancespigot]
|
||||
@@ -1,36 +0,0 @@
|
||||
# MaintenanceSpigot Plugin by KennyTV
|
||||
# Version ${project.version}
|
||||
# Important note: To use this plugin to its full extend, it requires the plugin 'ProtocolLib'
|
||||
|
||||
# Enables maintenance-mode.
|
||||
enable-maintenance-mode: false
|
||||
|
||||
# The message shown in the multiplayer server list motd.
|
||||
# If you put in multiple entries, one of them will be chosen randomly on every ping.
|
||||
pingmessages:
|
||||
- "&cMaintenance mode!%NEWLINE%&6We will be back soon!"
|
||||
#- "Another entry"
|
||||
|
||||
# If set to true, the message below will be shown at the top right corner of the server in the serverlist,
|
||||
# where the playercount would normally be displayed.
|
||||
# If set to false, the normal playercount will be shown.
|
||||
# Alternatively you can use '%ONLINE%' and '%MAX% if you want to include the playercount in a custom message (e.g. '&cMaintenance &7%ONLINE%&8/&7%MAX%').
|
||||
enable-playercountmessage: true
|
||||
playercountmessage: "&4Maintenance"
|
||||
|
||||
# Is shown when you move your mouse above the text at the top right corner of the server in the serverlist,
|
||||
# where the playercount would normally be displayed.
|
||||
playercounthovermessage: "&cCurrently under%NEWLINE%&cmaintenance"
|
||||
|
||||
# Is shown when a player tries to join while maintenance is enabled and they don't have the permission to bypass it.
|
||||
kickmessage: "&cThe server is currently under maintenance!%NEWLINE%Try again later!"
|
||||
|
||||
# If using the timer command: In what intervalls before enabling/disabling maintenance there will be a broadcast.
|
||||
timer-broadcast-for-seconds: [1200, 900, 600, 300, 120, 60, 30, 20, 10, 5, 4, 3, 2, 1]
|
||||
|
||||
# If set to true, players with the maintenance.joinnotification permission will receive a message,
|
||||
# that a player tried to join the server while maintenance is enabled.
|
||||
send-join-notification: false
|
||||
|
||||
# If set to true, the server icon will be changed to maintenance-icon.png in the Bungee main/base-folder.
|
||||
custom-maintenance-icon: false
|
||||
Binary file not shown.
@@ -1,16 +1,37 @@
|
||||
This repo is mainly for reporting bugs in the issues section. You might have a look at the general code, but you can't actually compile it (that easily) without other dependencies. You may not copy the code or distribute it as your own.
|
||||
# Maintenance
|
||||
[](https://github.com/KennyTV/Maintenance/releases)
|
||||

|
||||
[](https://github.com/KennyTV/Maintenance/releases)
|
||||
[](https://discord.gg/vGCUzHq)
|
||||
[](https://twitter.com/KennyTVN)
|
||||
Maintenance is probably the most customizable free maintenance plugin for your Minecraft server you can find. It runs on Spigot, BungeeCord, Sponge, as well as Velocity.
|
||||
|
||||
# MaintenanceMode-Issues
|
||||
Its features include:
|
||||
* A custom motd as well as server icon, that will be shown during maintenance
|
||||
* Start- and endtimers, which will enable/disable maintenance mode after the time is up
|
||||
* A '%TIMER%' variable usable in the pingmessage, to show the time until a running endtimer finishes (other variables and tricks are explained in the configuration file's comments)
|
||||
* A maintenance whitelist, to grant specific players the ability to join while you're working on your server
|
||||
* Nearly all messages are editable via the language file, given in a multitude of different languages
|
||||
* Features specifically for Bungee/Velocity
|
||||
* Only want to enable maintenance on a single server? You can also do so by using the `/maintenance <on/off> <servername>` command
|
||||
* Link multiple proxy instances through a MySQL database connection, so you don't have to change maintenance on each proxy by hand
|
||||
* Use PlaceholderAPI placeholders with the [**MaintenanceAddon**](https://github.com/KennyTV/Maintenance/wiki/MaintenanceAddon) (only for Bungee)
|
||||
|
||||
When creating an issue, please include the following information.
|
||||
- MaintenanceMode version
|
||||
- Whether you are using the plugin on a Spigot or a BungeeCord server
|
||||
- Explanation of how to reproduce the issue
|
||||
- The entire error message (!) if present
|
||||
A full list of commands, permissions and configuration options can be found in the wiki listed below.
|
||||
* [Wiki](https://github.com/KennyTV/Maintenance/wiki) (configuration, permissions, API usage)
|
||||
* [Downloads](https://github.com/KennyTV/Maintenance/releases) (GitHub)
|
||||
* [Changelogs](https://github.com/KennyTV/Maintenance/blob/master/.github/CHANGELOG.md)
|
||||
* [Issue tracker/bug reports](https://github.com/KennyTV/Maintenance/issues)
|
||||
* [Discord](https://discord.gg/vGCUzHq)
|
||||
* [PlaceholderAPI addon](https://github.com/KennyTV/Maintenance/wiki/MaintenanceAddon)
|
||||
|
||||
Issues can be created here: https://github.com/KennyTV/Maintenance/issues
|
||||
Other forum threads
|
||||
* [Spigot forums](https://www.spigotmc.org/resources/maintenance.40699/)
|
||||
* [Ore/Sponge Forums](https://ore.spongepowered.org/KennyTV/Maintenance)
|
||||
* [Velocity forums](https://forums.velocitypowered.com/t/maintenance/129)
|
||||
|
||||
### MaintenanceMode API
|
||||
## Compiling
|
||||
To create a working jar yourself, simply clone the project and compile it with maven (by using `mvn clean package` in your IDE console).
|
||||
|
||||
There's no official maven repo, yet, but you can manually add the Maintenance-API.jar file to your library (can be downloaded in the code section, https://github.com/KennyTV/Maintenance/raw/master/Maintenance-API.jar).
|
||||
By using MaintenanceBungeeAPI#getAPI or MaintenanceSpigotAPI#getAPI (depending on what server you are using the plugin) you can get some base methods. A rough documentation can be found here https://github.com/KennyTV/Maintenance/tree/master/Maintenance-API/src/main/java/eu/kennytv/maintenance/api
|
||||
## Licence
|
||||
When modifying the project's code, do that on a public repository while also keeping it under the same license (see [GNU General Public License](http://www.gnu.org/licenses/gpl-3.0)).
|
||||
@@ -4,25 +4,31 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>maintenance-base</artifactId>
|
||||
<groupId>eu.kennytv</groupId>
|
||||
<version>2.4</version>
|
||||
<groupId>eu.kennytv.maintenance</groupId>
|
||||
<artifactId>maintenance-parent</artifactId>
|
||||
<version>3.0.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-api</artifactId>
|
||||
<name>Maintenance-API</name>
|
||||
<name>MaintenanceAPI</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.13-SNAPSHOT</version>
|
||||
<version>1.15-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>7.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api;
|
||||
|
||||
import eu.kennytv.maintenance.api.event.manager.IEventManager;
|
||||
|
||||
/**
|
||||
* @author KennyTV
|
||||
* @since 2.1
|
||||
*/
|
||||
public interface IMaintenance {
|
||||
|
||||
/**
|
||||
* Enables/disables maintenance mode.
|
||||
* If enabled, all non-permitted players will be kicked.
|
||||
* <p>
|
||||
* If using the BungeeCord version and MySQL is enabled,
|
||||
* it will also be written into the database.
|
||||
* </p>
|
||||
*
|
||||
* @param maintenance true to enable, false to disable maintenance mode
|
||||
*/
|
||||
void setMaintenance(boolean maintenance);
|
||||
|
||||
/**
|
||||
* @return true if maintenance is currently enabled
|
||||
*/
|
||||
boolean isMaintenance();
|
||||
|
||||
/**
|
||||
* @return true if a start- or endtimer task is currently running
|
||||
*/
|
||||
boolean isTaskRunning();
|
||||
|
||||
/**
|
||||
* @return version of the plugin
|
||||
*/
|
||||
String getVersion();
|
||||
|
||||
/**
|
||||
* Returns the {@link ISettings} instance, which gives further insight into settings set in the config files.
|
||||
*
|
||||
* @return {@link ISettings} instance
|
||||
*/
|
||||
ISettings getSettings();
|
||||
|
||||
/**
|
||||
* Returns the {@link IEventManager} instance to register listeners to maintenance events.
|
||||
*
|
||||
* @return {@link IEventManager} instance
|
||||
*/
|
||||
IEventManager getEventManager();
|
||||
|
||||
/**
|
||||
* @return true if debug mode is enabled, currently only implemented on Bungee
|
||||
*/
|
||||
boolean isDebug();
|
||||
|
||||
/**
|
||||
* Sets the debug mode.
|
||||
*
|
||||
* @param debug debug state
|
||||
*/
|
||||
void setDebug(boolean debug);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api;
|
||||
|
||||
/**
|
||||
* @author KennyTV
|
||||
* @since 2.2.2
|
||||
*/
|
||||
public interface IMaintenanceBase {
|
||||
|
||||
/**
|
||||
* This method is used internally when getting the api instance.
|
||||
*
|
||||
* @return {@link IMaintenance} instance
|
||||
*/
|
||||
IMaintenance getApi();
|
||||
}
|
||||
+40
-6
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -17,20 +35,31 @@ public interface ISettings {
|
||||
boolean isMaintenance();
|
||||
|
||||
/**
|
||||
* @return true if "send-join-notification" is set to true in the config
|
||||
* @return value of the 'send-join-notification' config field
|
||||
*/
|
||||
boolean isJoinNotifications();
|
||||
|
||||
/**
|
||||
* @return true if "custom-maintenance-icon" is set to true in the config
|
||||
* @return value of the 'custom-maintenance-icon' config field
|
||||
*/
|
||||
boolean hasCustomIcon();
|
||||
|
||||
/**
|
||||
* Returns a map of the currently maintenance-whitelisted players as their uuid mapped to their saved name.
|
||||
* Note that the names might be incorrect/outdated.
|
||||
*
|
||||
* @return map of uuids of whitelisted players with their given names
|
||||
*/
|
||||
Map<UUID, String> getWhitelistedPlayers();
|
||||
|
||||
/**
|
||||
* Returns whether the uuid is whitelisted.
|
||||
*
|
||||
* @param uuid uuid of the player to check
|
||||
* @return true if the uuid is whitelisted
|
||||
*/
|
||||
boolean isWhitelisted(UUID uuid);
|
||||
|
||||
/**
|
||||
* Removes a player from the maintenance whitelist.
|
||||
*
|
||||
@@ -60,9 +89,14 @@ public interface ISettings {
|
||||
boolean addWhitelistedPlayer(UUID uuid, String name);
|
||||
|
||||
/**
|
||||
* Reloads the maintenance-icon.png image from the server folder.
|
||||
*
|
||||
* @return true if loading the image was successful
|
||||
* Reloads maintenance-icon, config, language file and WhitelistedPlayers.
|
||||
*/
|
||||
boolean reloadMaintenanceIcon();
|
||||
void reloadConfigs();
|
||||
|
||||
/**
|
||||
* This indicates if the optional 'debug' value in the config is set to true.
|
||||
*
|
||||
* @return true if debug is enabled
|
||||
*/
|
||||
boolean debugEnabled();
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api.bungee;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import eu.kennytv.maintenance.api.IMaintenanceBase;
|
||||
import eu.kennytv.maintenance.api.proxy.IMaintenanceProxy;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Utility class to get the {@link IMaintenanceProxy} instance for the BungeeCord version of the plugin.
|
||||
* <p>
|
||||
* Only access this class if you're running the plugin on a BungeeCord server!
|
||||
* </p>
|
||||
*
|
||||
* @author KennyTV
|
||||
* @since 2.5
|
||||
*/
|
||||
public final class MaintenanceBungeeAPI {
|
||||
|
||||
/**
|
||||
* Returns API instance of the Maintenance plugin.
|
||||
*
|
||||
* @return {@link IMaintenanceProxy} instance
|
||||
* @throws IllegalArgumentException if using a custom (or broken?) version of the plugin, that can't be identified
|
||||
*/
|
||||
public static IMaintenanceProxy getAPI() {
|
||||
final Plugin maintenance = ProxyServer.getInstance().getPluginManager().getPlugin("Maintenance");
|
||||
Preconditions.checkNotNull(maintenance, "Could not get instance of Maintenance! Broken/custom build of the plugin?");
|
||||
return (IMaintenanceProxy) ((IMaintenanceBase) maintenance).getApi();
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api.event;
|
||||
|
||||
import eu.kennytv.maintenance.api.event.manager.MaintenanceEvent;
|
||||
|
||||
/**
|
||||
* Notification event fired when maintenance mode has been changed.
|
||||
*
|
||||
* @author KennyTV
|
||||
* @since 3.0.1
|
||||
*/
|
||||
public final class MaintenanceChangedEvent implements MaintenanceEvent {
|
||||
private final boolean maintenance;
|
||||
|
||||
public MaintenanceChangedEvent(final boolean maintenance) {
|
||||
this.maintenance = maintenance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if maintenance has been enabled, false otherwise
|
||||
*/
|
||||
public boolean isMaintenance() {
|
||||
return maintenance;
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api.event;
|
||||
|
||||
import eu.kennytv.maintenance.api.IMaintenance;
|
||||
import eu.kennytv.maintenance.api.event.manager.MaintenanceEvent;
|
||||
import eu.kennytv.maintenance.api.proxy.IMaintenanceProxy;
|
||||
|
||||
/**
|
||||
* Notification event fired when Maintenance configuration is reloaded.
|
||||
*
|
||||
* @author KennyTV
|
||||
* @see IMaintenance#isMaintenance() for the new maintenance status
|
||||
* @see IMaintenanceProxy#getMaintenanceServers() for the new list of servers under maintenance
|
||||
* @since 3.0.6
|
||||
*/
|
||||
public final class MaintenanceReloadedEvent implements MaintenanceEvent {
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api.event.manager;
|
||||
|
||||
/**
|
||||
* Abstract class representing a maintenance eventlistener.
|
||||
*
|
||||
* @param <T> event to be listened to
|
||||
* @author KennyTV
|
||||
* @since 3.0.1
|
||||
*/
|
||||
public abstract class EventListener<T extends MaintenanceEvent> {
|
||||
|
||||
/**
|
||||
* This method is to be overwritten and is called on the given event.
|
||||
*
|
||||
* @param event fired event
|
||||
*/
|
||||
public abstract void onEvent(final T event);
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api.event.manager;
|
||||
|
||||
/**
|
||||
* @author KennyTV
|
||||
* @since 3.0.1
|
||||
*/
|
||||
public interface IEventManager {
|
||||
|
||||
/**
|
||||
* Registers an eventlistener for the given maintenance event.
|
||||
*
|
||||
* @param listener listener to register
|
||||
* @param eventClass class of the event that should be registered
|
||||
*/
|
||||
void registerListener(EventListener listener, Class<? extends MaintenanceEvent> eventClass);
|
||||
|
||||
/**
|
||||
* Fires a maintenance event.
|
||||
*
|
||||
* @param event event to fire
|
||||
*/
|
||||
void callEvent(MaintenanceEvent event);
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api.event.manager;
|
||||
|
||||
/**
|
||||
* Dummy interface representing a maintenance event.
|
||||
*
|
||||
* @author KennyTV
|
||||
* @since 3.0.1
|
||||
*/
|
||||
public interface MaintenanceEvent {
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api.event.proxy;
|
||||
|
||||
import eu.kennytv.maintenance.api.event.manager.MaintenanceEvent;
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
|
||||
/**
|
||||
* Notification event fired when maintenance mode has been changed on a proxied server.
|
||||
*
|
||||
* @author KennyTV
|
||||
* @since 3.0.1
|
||||
*/
|
||||
public final class ServerMaintenanceChangedEvent implements MaintenanceEvent {
|
||||
private final Server server;
|
||||
private final boolean maintenance;
|
||||
|
||||
public ServerMaintenanceChangedEvent(final Server server, final boolean maintenance) {
|
||||
this.server = server;
|
||||
this.maintenance = maintenance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns wrapped server object for the server.
|
||||
* <br>
|
||||
* This does not necessarily have to be an existing server:
|
||||
* If maintenance is disabled on a *previously* registered server, see {@link Server#isRegisteredServer()}.
|
||||
*
|
||||
* @return wrapped server object for the server
|
||||
*/
|
||||
public Server getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if maintenance has been enabled on the server, false otherwise
|
||||
*/
|
||||
public boolean isMaintenance() {
|
||||
return maintenance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api.proxy;
|
||||
|
||||
import eu.kennytv.maintenance.api.IMaintenance;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author KennyTV
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface IMaintenanceProxy extends IMaintenance {
|
||||
|
||||
/**
|
||||
* Enables/disables maintenance mode on a proxied server.
|
||||
* If enabled, all non-permitted players will be kicked.
|
||||
* If MySQL is enabled, it will also be written into the database.
|
||||
*
|
||||
* @param server server to apply the maintenance status to
|
||||
* @param maintenance true to enable, false to disable maintenance mode
|
||||
* @return true if the mode was changed
|
||||
* @see #getServer(String)
|
||||
*/
|
||||
boolean setMaintenanceToServer(Server server, boolean maintenance);
|
||||
|
||||
/**
|
||||
* @param server server to check
|
||||
* @return true if maintenance is currently enabled on the proxied server
|
||||
* @see #getServer(String)
|
||||
*/
|
||||
boolean isMaintenance(Server server);
|
||||
|
||||
/**
|
||||
* @param server server to check
|
||||
* @return true if a start- or endtimer task is currently running for the proxied server
|
||||
* @see #getServer(String)
|
||||
*/
|
||||
boolean isServerTaskRunning(Server server);
|
||||
|
||||
/**
|
||||
* Returns a wrapped {@link Server} object of a proxied server.
|
||||
*
|
||||
* @param server name of the proxied server
|
||||
* @return wrapped server object if present, else null
|
||||
*/
|
||||
@Nullable
|
||||
Server getServer(String server);
|
||||
|
||||
/**
|
||||
* @return immutable set with names of all proxied server that are currently under maintenance
|
||||
*/
|
||||
Set<String> getMaintenanceServers();
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api.proxy;
|
||||
|
||||
/**
|
||||
* Wrapper for a proxied server.
|
||||
* Use {@link IMaintenanceProxy#getServer(String)} to get a server instance.
|
||||
*
|
||||
* @author KennyTV
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface Server {
|
||||
|
||||
/**
|
||||
* @return name of the server
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* @return true if there are players on the server
|
||||
*/
|
||||
boolean hasPlayers();
|
||||
|
||||
/**
|
||||
* Sends a message to all players on the server.
|
||||
*
|
||||
* @param message message to be broadcasted
|
||||
*/
|
||||
void broadcast(String message);
|
||||
|
||||
/**
|
||||
* Returns whether the server is registered under the proxy.
|
||||
* This will only ever be false if maintenance is disabled on a *previously* registered server.
|
||||
*
|
||||
* @return whether the server is registered under the proxy
|
||||
*/
|
||||
boolean isRegisteredServer();
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api.spigot;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import eu.kennytv.maintenance.api.IMaintenance;
|
||||
import eu.kennytv.maintenance.api.IMaintenanceBase;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Utility class to get the {@link IMaintenance} instance for the Spigot version of the plugin.
|
||||
* <p>
|
||||
* Only access this class if you're running the plugin on a Spigot server!
|
||||
* </p>
|
||||
*
|
||||
* @author KennyTV
|
||||
* @since 2.5
|
||||
*/
|
||||
public final class MaintenanceSpigotAPI {
|
||||
|
||||
/**
|
||||
* Returns API instance of the Maintenance plugin.
|
||||
*
|
||||
* @return {@link IMaintenance} instance
|
||||
* @throws IllegalArgumentException if using a custom (or broken?) version of the plugin, that can't be identified
|
||||
*/
|
||||
public static IMaintenance getAPI() {
|
||||
final Plugin maintenance = Bukkit.getPluginManager().getPlugin("Maintenance");
|
||||
Preconditions.checkNotNull(maintenance, "Could not get instance of Maintenance! Broken/custom build of the plugin?");
|
||||
return ((IMaintenanceBase) maintenance).getApi();
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.api.sponge;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import eu.kennytv.maintenance.api.IMaintenance;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.plugin.PluginContainer;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Utility class to get the {@link IMaintenance} instance for the Sponge version of the plugin.
|
||||
* <p>
|
||||
* Only access this class if you're running the plugin on a Sponge server!
|
||||
* </p>
|
||||
*
|
||||
* @author KennyTV
|
||||
* @since 3.0
|
||||
*/
|
||||
public final class MaintenanceSpongeAPI {
|
||||
|
||||
/**
|
||||
* Returns API instance of the Maintenance plugin.
|
||||
*
|
||||
* @return {@link IMaintenance} instance
|
||||
* @throws IllegalArgumentException if using a custom (or broken?) version of the plugin, that can't be identified
|
||||
*/
|
||||
public static IMaintenance getAPI() {
|
||||
final Optional<PluginContainer> container = Sponge.getPluginManager().getPlugin("maintenance");
|
||||
Preconditions.checkArgument(container.isPresent() && container.get().getInstance().isPresent(),
|
||||
"Could not get instance of Maintenance! Broken/custom build of the plugin?");
|
||||
return (IMaintenance) container.get().getInstance().get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>eu.kennytv.maintenance</groupId>
|
||||
<artifactId>maintenance-parent</artifactId>
|
||||
<version>3.0.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-build</artifactId>
|
||||
<name>Maintenance</name>
|
||||
|
||||
<dependencies>
|
||||
<!-- Also includes maintenance-core and maintenance-core-proxy modules -->
|
||||
<dependency>
|
||||
<groupId>eu.kennytv.maintenance</groupId>
|
||||
<artifactId>maintenance-bungee</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>eu.kennytv.maintenance</groupId>
|
||||
<artifactId>maintenance-spigot</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Don't include Sponge and Velocity in main jar anymore, counters relocation errors and minimizes shading -->
|
||||
</dependencies>
|
||||
|
||||
<!-- Needed to relocate stuff in Bungee module, but not in the core one -->
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.slf4j</pattern>
|
||||
<shadedPattern>eu.kennytv.lib.slf4j</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.zaxxer.hikari</pattern>
|
||||
<shadedPattern>eu.kennytv.lib.hikari</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>eu.kennytv.maintenance</groupId>
|
||||
<artifactId>maintenance-parent</artifactId>
|
||||
<version>3.0.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-bungee</artifactId>
|
||||
<name>MaintenanceBungee</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>eu.kennytv.maintenance</groupId>
|
||||
<artifactId>maintenance-core-proxy</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Only compile slf4j on Bungee (not Velocity) to prevent relocation errors -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.30</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.16-R0.4-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<!-- Needed to relocate stuff in Bungee module, but not in the core one -->
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.slf4j</pattern>
|
||||
<shadedPattern>eu.kennytv.lib.slf4j</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.zaxxer.hikari</pattern>
|
||||
<shadedPattern>eu.kennytv.lib.hikari</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.bungee;
|
||||
|
||||
import eu.kennytv.maintenance.api.IMaintenance;
|
||||
import eu.kennytv.maintenance.api.IMaintenanceBase;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public final class MaintenanceBungeeBase extends Plugin implements IMaintenanceBase {
|
||||
private MaintenanceBungeePlugin maintenance;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
maintenance = new MaintenanceBungeePlugin(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
maintenance.disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMaintenance getApi() {
|
||||
return maintenance;
|
||||
}
|
||||
|
||||
File getPluginFile() {
|
||||
return getFile();
|
||||
}
|
||||
}
|
||||
+266
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.bungee;
|
||||
|
||||
import eu.kennytv.maintenance.api.bungee.MaintenanceBungeeAPI;
|
||||
import eu.kennytv.maintenance.api.proxy.IMaintenanceProxy;
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.bungee.command.MaintenanceBungeeCommand;
|
||||
import eu.kennytv.maintenance.bungee.command.MaintenanceBungeeCommandBase;
|
||||
import eu.kennytv.maintenance.bungee.listener.ProxyPingListener;
|
||||
import eu.kennytv.maintenance.bungee.listener.ServerConnectListener;
|
||||
import eu.kennytv.maintenance.bungee.metrics.MetricsLite;
|
||||
import eu.kennytv.maintenance.bungee.util.BungeeSenderInfo;
|
||||
import eu.kennytv.maintenance.bungee.util.BungeeServer;
|
||||
import eu.kennytv.maintenance.bungee.util.BungeeTask;
|
||||
import eu.kennytv.maintenance.core.dump.PluginDump;
|
||||
import eu.kennytv.maintenance.core.hook.ServerListPlusHook;
|
||||
import eu.kennytv.maintenance.core.proxy.MaintenanceProxyPlugin;
|
||||
import eu.kennytv.maintenance.core.proxy.SettingsProxy;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
import eu.kennytv.maintenance.core.util.ServerType;
|
||||
import eu.kennytv.maintenance.core.util.Task;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.Favicon;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
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.plugin.Plugin;
|
||||
import net.md_5.bungee.api.plugin.PluginManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author KennyTV
|
||||
* @since 1.0
|
||||
*/
|
||||
public final class MaintenanceBungeePlugin extends MaintenanceProxyPlugin {
|
||||
private final MaintenanceBungeeBase plugin;
|
||||
private Favicon favicon;
|
||||
|
||||
MaintenanceBungeePlugin(final MaintenanceBungeeBase plugin) {
|
||||
super(plugin.getDescription().getVersion(), ServerType.BUNGEE);
|
||||
this.plugin = plugin;
|
||||
|
||||
settingsProxy = new SettingsProxy(this);
|
||||
settings = settingsProxy;
|
||||
|
||||
sendEnableMessage();
|
||||
|
||||
final PluginManager pm = getProxy().getPluginManager();
|
||||
pm.registerListener(plugin, new ProxyPingListener(this, settingsProxy));
|
||||
pm.registerListener(plugin, new ServerConnectListener(this, settingsProxy));
|
||||
commandManager = new MaintenanceBungeeCommand(this, settingsProxy);
|
||||
pm.registerCommand(plugin, new MaintenanceBungeeCommandBase(commandManager));
|
||||
|
||||
continueLastEndtimer();
|
||||
new MetricsLite(plugin);
|
||||
|
||||
// ServerListPlus integration
|
||||
final Plugin serverListPlus = pm.getPlugin("ServerListPlus");
|
||||
if (serverListPlus != null) {
|
||||
serverListPlusHook = new ServerListPlusHook(serverListPlus);
|
||||
serverListPlusHook.setEnabled(!settingsProxy.isMaintenance());
|
||||
plugin.getLogger().info("Enabled ServerListPlus integration!");
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static IMaintenanceProxy getAPI() {
|
||||
return MaintenanceBungeeAPI.getAPI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendUpdateNotification(final SenderInfo sender) {
|
||||
final TextComponent tc1 = new TextComponent(TextComponent.fromLegacyText(getPrefix()));
|
||||
final TextComponent tc2 = new TextComponent(TextComponent.fromLegacyText("§cDownload it at: §6https://www.spigotmc.org/resources/maintenance.40699/"));
|
||||
final TextComponent click = new TextComponent(TextComponent.fromLegacyText(" §7§l§o(CLICK ME)"));
|
||||
click.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/maintenance.40699/"));
|
||||
click.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aDownload the latest version").create()));
|
||||
tc1.addExtra(tc2);
|
||||
tc1.addExtra(click);
|
||||
((BungeeSenderInfo) sender).sendMessage(tc1);
|
||||
}
|
||||
|
||||
public boolean isMaintenance(final ServerInfo serverInfo) {
|
||||
return settingsProxy.isMaintenance(serverInfo.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void kickPlayersFromProxy() {
|
||||
for (final ProxiedPlayer p : getProxy().getPlayers()) {
|
||||
if (!hasPermission(p, "bypass") && !settingsProxy.isWhitelisted(p.getUniqueId())) {
|
||||
p.disconnect(settingsProxy.getKickMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void kickPlayers(final Server server, final Server fallback) {
|
||||
// Kick players from a proxied server
|
||||
final ServerInfo fallbackServer = fallback != null ? ((BungeeServer) fallback).getServer() : null;
|
||||
final boolean checkForFallback = fallbackServer != null && !isMaintenance(fallback);
|
||||
for (final ProxiedPlayer player : ((BungeeServer) server).getServer().getPlayers()) {
|
||||
if (!hasPermission(player, "bypass") && !settingsProxy.isWhitelisted(player.getUniqueId())) {
|
||||
if (checkForFallback && fallbackServer.canAccess(player)) {
|
||||
player.sendMessage(settingsProxy.getMessage("singleMaintenanceActivated").replace("%SERVER%", server.getName()));
|
||||
player.connect(fallbackServer);
|
||||
} else {
|
||||
player.disconnect(settingsProxy.getFullServerKickMessage(server.getName()));
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(settingsProxy.getMessage("singleMaintenanceActivated").replace("%SERVER%", server.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void kickPlayersTo(final Server server) {
|
||||
// Kick all players to a single waiting server
|
||||
final ServerInfo serverInfo = ((BungeeServer) server).getServer();
|
||||
// Notifications done in global method
|
||||
for (final ProxiedPlayer player : getProxy().getPlayers()) {
|
||||
if (hasPermission(player, "bypass") || settingsProxy.isWhitelisted(player.getUniqueId())) continue;
|
||||
if (player.getServer() != null && player.getServer().getInfo().getName().equals(serverInfo.getName()))
|
||||
continue;
|
||||
if (serverInfo.canAccess(player) && !isMaintenance(serverInfo)) {
|
||||
player.sendMessage(settingsProxy.getMessage("sentToWaitingServer").replace("%SERVER%", server.getName()));
|
||||
player.connect(serverInfo);
|
||||
} else {
|
||||
player.disconnect(settingsProxy.getKickMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task startMaintenanceRunnable(final Runnable runnable) {
|
||||
return new BungeeTask(getProxy().getScheduler().schedule(plugin, runnable, 0, 1, TimeUnit.SECONDS).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Server getServer(final String server) {
|
||||
final ServerInfo serverInfo = getProxy().getServerInfo(server);
|
||||
return serverInfo != null ? new BungeeServer(serverInfo) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public SenderInfo getOfflinePlayer(final String name) {
|
||||
final ProxiedPlayer player = getProxy().getPlayer(name);
|
||||
return player != null ? new BungeeSenderInfo(player) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public SenderInfo getOfflinePlayer(final UUID uuid) {
|
||||
final ProxiedPlayer player = getProxy().getPlayer(uuid);
|
||||
return player != null ? new BungeeSenderInfo(player) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getServerNameOf(final SenderInfo sender) {
|
||||
final ProxiedPlayer player = getProxy().getPlayer(sender.getUuid());
|
||||
if (player == null || player.getServer() == null) return null;
|
||||
return player.getServer().getInfo().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void async(final Runnable runnable) {
|
||||
getProxy().getScheduler().runAsync(plugin, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(final String message) {
|
||||
getProxy().broadcast(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
return plugin.getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getPluginFile() {
|
||||
return plugin.getPluginFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getOnlinePlayers() {
|
||||
return getProxy().getOnlineCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxPlayers() {
|
||||
return getProxy().getConfig().getPlayerLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResource(final String name) {
|
||||
return plugin.getResourceAsStream(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return plugin.getLogger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerVersion() {
|
||||
return getProxy().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PluginDump> getPlugins() {
|
||||
return getProxy().getPluginManager().getPlugins().stream().map(plugin ->
|
||||
new PluginDump(plugin.getDescription().getName(), plugin.getDescription().getVersion(), Arrays.asList(plugin.getDescription().getAuthor()))).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadIcon(final File file) throws IOException {
|
||||
favicon = Favicon.create(ImageIO.read(file));
|
||||
}
|
||||
|
||||
public boolean hasPermission(final CommandSender sender, final String permission) {
|
||||
return sender.hasPermission("maintenance." + permission) || sender.hasPermission("maintenance.admin");
|
||||
}
|
||||
|
||||
public ProxyServer getProxy() {
|
||||
return plugin.getProxy();
|
||||
}
|
||||
|
||||
public Favicon getFavicon() {
|
||||
return favicon;
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.bungee.command;
|
||||
|
||||
import eu.kennytv.maintenance.bungee.MaintenanceBungeePlugin;
|
||||
import eu.kennytv.maintenance.bungee.util.BungeeSenderInfo;
|
||||
import eu.kennytv.maintenance.core.proxy.SettingsProxy;
|
||||
import eu.kennytv.maintenance.core.proxy.command.MaintenanceProxyCommand;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class MaintenanceBungeeCommand extends MaintenanceProxyCommand {
|
||||
private final MaintenanceBungeePlugin plugin;
|
||||
|
||||
public MaintenanceBungeeCommand(final MaintenanceBungeePlugin plugin, final SettingsProxy settings) {
|
||||
super(plugin, settings);
|
||||
this.plugin = plugin;
|
||||
registerCommands();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendUpdateMessage(final SenderInfo sender) {
|
||||
final TextComponent tc = new TextComponent("§6× §8[§aUpdate§8]");
|
||||
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/maintenance forceupdate"));
|
||||
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§aClick here to update the plugin")));
|
||||
tc.addExtra(" §8< §7Or use the command §c/maintenance forceupdate");
|
||||
((BungeeSenderInfo) sender).sendMessage(tc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getServersCompletion(final String s) {
|
||||
final List<String> list = new ArrayList<>();
|
||||
for (final Map.Entry<String, ServerInfo> entry : plugin.getProxy().getServers().entrySet()) {
|
||||
final String serverName = entry.getValue().getName();
|
||||
if (entry.getKey().toLowerCase().startsWith(s) && !plugin.getSettingsProxy().getMaintenanceServers().contains(serverName)) {
|
||||
list.add(serverName);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendDumpMessage(final SenderInfo sender, final String url) {
|
||||
final BungeeSenderInfo bungeeSender = ((BungeeSenderInfo) sender);
|
||||
final TextComponent clickText = new TextComponent(plugin.getPrefix() + "§7Click here to copy the link");
|
||||
clickText.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, url));
|
||||
clickText.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§aClick here to copy the link")));
|
||||
bungeeSender.sendMessage(clickText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPlayersCompletion() {
|
||||
final List<String> list = new ArrayList<>();
|
||||
for (final ProxiedPlayer p : plugin.getProxy().getPlayers()) {
|
||||
list.add(p.getName());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.bungee.command;
|
||||
|
||||
import eu.kennytv.maintenance.bungee.util.BungeeSenderInfo;
|
||||
import eu.kennytv.maintenance.core.command.MaintenanceCommand;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
|
||||
public final class MaintenanceBungeeCommandBase extends Command implements TabExecutor {
|
||||
private final MaintenanceCommand command;
|
||||
|
||||
public MaintenanceBungeeCommandBase(final MaintenanceCommand command) {
|
||||
super("maintenance", "maintenance.command", "maintenancebungee", "mt");
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final CommandSender sender) {
|
||||
return sender.hasPermission("maintenance.admin") || sender.hasPermission("maintenance.command");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final String[] args) {
|
||||
command.execute(new BungeeSenderInfo(sender), args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> onTabComplete(final CommandSender sender, final String[] args) {
|
||||
return command.getSuggestions(new BungeeSenderInfo(sender), args);
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.bungee.listener;
|
||||
|
||||
import eu.kennytv.maintenance.bungee.MaintenanceBungeePlugin;
|
||||
import eu.kennytv.maintenance.core.proxy.SettingsProxy;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
public final class ProxyPingListener implements Listener {
|
||||
private final MaintenanceBungeePlugin plugin;
|
||||
private final SettingsProxy settings;
|
||||
|
||||
public ProxyPingListener(final MaintenanceBungeePlugin plugin, final SettingsProxy settings) {
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@EventHandler(priority = 80)
|
||||
public void proxyPing(final ProxyPingEvent event) {
|
||||
if (!settings.isMaintenance()) return;
|
||||
|
||||
final ServerPing ping = event.getResponse();
|
||||
ServerPing.Players players = ping.getPlayers();
|
||||
if (players == null) {
|
||||
ping.setPlayers(players = new ServerPing.Players(0, 0, null));
|
||||
}
|
||||
|
||||
if (settings.hasCustomPlayerCountMessage()) {
|
||||
ping.setVersion(new ServerPing.Protocol(settings.getPlayerCountMessage()
|
||||
.replace("%ONLINE%", Integer.toString(players.getOnline()))
|
||||
.replace("%MAX%", Integer.toString(players.getMax())), 1));
|
||||
}
|
||||
|
||||
ping.setDescription(settings.getRandomPingMessage());
|
||||
|
||||
final String[] split = settings.getPlayerCountHoverMessage().split("\n");
|
||||
final ServerPing.PlayerInfo[] samplePlayers = new ServerPing.PlayerInfo[split.length];
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
samplePlayers[i] = new ServerPing.PlayerInfo(split[i], "");
|
||||
}
|
||||
players.setSample(samplePlayers);
|
||||
|
||||
if (settings.hasCustomIcon() && plugin.getFavicon() != null) {
|
||||
ping.setFavicon(plugin.getFavicon());
|
||||
}
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.bungee.listener;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.bungee.MaintenanceBungeePlugin;
|
||||
import eu.kennytv.maintenance.bungee.util.BungeeSenderInfo;
|
||||
import eu.kennytv.maintenance.bungee.util.BungeeServer;
|
||||
import eu.kennytv.maintenance.core.proxy.SettingsProxy;
|
||||
import eu.kennytv.maintenance.core.proxy.listener.ProxyJoinListenerBase;
|
||||
import eu.kennytv.maintenance.core.proxy.util.ServerConnectResult;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
public final class ServerConnectListener extends ProxyJoinListenerBase implements Listener {
|
||||
private final MaintenanceBungeePlugin plugin;
|
||||
|
||||
public ServerConnectListener(final MaintenanceBungeePlugin plugin, final SettingsProxy settings) {
|
||||
super(plugin, settings);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void initialServerConnect(final ServerConnectEvent event) {
|
||||
// Global maintenance check
|
||||
if (event.isCancelled() || event.getReason() != ServerConnectEvent.Reason.JOIN_PROXY) return;
|
||||
|
||||
final BungeeSenderInfo sender = new BungeeSenderInfo(event.getPlayer());
|
||||
if (plugin.isDebug()) {
|
||||
plugin.getLogger().info("Join permission check for " + event.getPlayer().getName()
|
||||
+ " - Permission: " + sender.hasMaintenancePermission("bypass") + ", whitelist: " + settings.isWhitelisted(sender.getUuid()));
|
||||
}
|
||||
|
||||
if (shouldKick(sender)) {
|
||||
final Server waitingServer = shouldConnectToWaitingServer(sender);
|
||||
if (waitingServer != null) {
|
||||
event.setTarget(((BungeeServer) waitingServer).getServer());
|
||||
sender.sendMessage(settings.getMessage("sentToWaitingServer"));
|
||||
|
||||
if (plugin.isDebug()) {
|
||||
plugin.getLogger().info("Join to waiting server for " + event.getPlayer().getName());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().disconnect(settings.getKickMessage());
|
||||
if (settings.isJoinNotifications()) {
|
||||
broadcastJoinNotification(sender.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void serverConnect(final ServerConnectEvent event) {
|
||||
// Server specific maintenance check
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
final ProxiedPlayer player = event.getPlayer();
|
||||
final boolean normalServerConnect = event.getReason() != ServerConnectEvent.Reason.JOIN_PROXY && event.getReason() != ServerConnectEvent.Reason.KICK_REDIRECT
|
||||
&& event.getReason() != ServerConnectEvent.Reason.LOBBY_FALLBACK && event.getReason() != ServerConnectEvent.Reason.SERVER_DOWN_REDIRECT;
|
||||
final ServerConnectResult connectResult = serverConnect(new BungeeSenderInfo(player), new BungeeServer(event.getTarget()), normalServerConnect);
|
||||
if (plugin.isDebug()) {
|
||||
plugin.getLogger().info("Connectresult for " + player.getName() + " to " + event.getTarget().getName() + ": " + connectResult);
|
||||
}
|
||||
|
||||
if (connectResult.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
|
||||
// Player has no server to connect to
|
||||
if (player.getServer() == null) {
|
||||
player.disconnect(settings.getKickMessage());
|
||||
}
|
||||
} else if (connectResult.getTarget() != null) {
|
||||
event.setTarget(((BungeeServer) connectResult.getTarget()).getServer());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void broadcastJoinNotification(final String name) {
|
||||
sendJoinMessage(ProxyServer.getInstance().getPlayers(), name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void broadcastJoinNotification(final String name, final Server server) {
|
||||
sendJoinMessage(((BungeeServer) server).getServer().getPlayers(), name);
|
||||
}
|
||||
|
||||
private void sendJoinMessage(final Iterable<ProxiedPlayer> players, final String name) {
|
||||
final BaseComponent[] message = TextComponent.fromLegacyText(settings.getMessage("joinNotification").replace("%PLAYER%", name));
|
||||
for (final ProxiedPlayer player : players) {
|
||||
if (plugin.hasPermission(player, "joinnotification")) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+55
-58
@@ -3,7 +3,6 @@ package eu.kennytv.maintenance.bungee.metrics;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.scheduler.TaskScheduler;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
@@ -14,33 +13,24 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public final class MetricsLite {
|
||||
|
||||
static {
|
||||
final String defaultPackage = new String(new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'});
|
||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||
if (MetricsLite.class.getPackage().getName().equals(defaultPackage) || MetricsLite.class.getPackage().getName().equals(examplePackage)) {
|
||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
}
|
||||
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
|
||||
private static final int PLUGIN_ID = 742;
|
||||
private static final String URL = "https://bStats.org/submitData/bungeecord";
|
||||
|
||||
private final Plugin plugin;
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
private String serverUUID;
|
||||
|
||||
private boolean logFailedRequests;
|
||||
|
||||
private static boolean logSentData;
|
||||
private static boolean logResponseStatusText;
|
||||
private static final List<Object> knownMetricsInstances = new ArrayList<>();
|
||||
|
||||
public MetricsLite(final Plugin plugin) {
|
||||
@@ -67,7 +57,7 @@ public final class MetricsLite {
|
||||
} else {
|
||||
try {
|
||||
usedMetricsClass.getMethod("linkMetrics", Object.class).invoke(null, this);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
} catch (final NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Failed to link to first metrics class " + usedMetricsClass.getName() + "!", e);
|
||||
}
|
||||
@@ -75,6 +65,10 @@ public final class MetricsLite {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public static void linkMetrics(final Object metrics) {
|
||||
knownMetricsInstances.add(metrics);
|
||||
}
|
||||
@@ -82,10 +76,12 @@ public final class MetricsLite {
|
||||
public JsonObject getPluginData() {
|
||||
final JsonObject data = new JsonObject();
|
||||
|
||||
final String pluginName = plugin.getDescription().getName();
|
||||
//final String pluginName = plugin.getDescription().getName();
|
||||
final String pluginName = "MaintenanceBungee"; // I cut off the suffix, not sure how bStats would like the name change
|
||||
final String pluginVersion = plugin.getDescription().getVersion();
|
||||
|
||||
data.addProperty("pluginName", pluginName);
|
||||
data.addProperty("id", PLUGIN_ID);
|
||||
data.addProperty("pluginVersion", pluginVersion);
|
||||
|
||||
final JsonArray customCharts = new JsonArray();
|
||||
@@ -95,19 +91,11 @@ public final class MetricsLite {
|
||||
}
|
||||
|
||||
private void startSubmitting() {
|
||||
final Timer timer = new Timer(true);
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
final TaskScheduler scheduler = plugin.getProxy().getScheduler();
|
||||
scheduler.schedule(plugin, () -> submitData(), 0L, TimeUnit.SECONDS);
|
||||
}
|
||||
}, 1000 * 60 * 2, 1000 * 60 * 30);
|
||||
plugin.getProxy().getScheduler().schedule(plugin, this::submitData, 2, 30, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
private JsonObject getServerData() {
|
||||
int playerAmount = plugin.getProxy().getOnlineCount();
|
||||
playerAmount = playerAmount > 500 ? 500 : playerAmount;
|
||||
final int playerAmount = Math.min(plugin.getProxy().getOnlineCount(), 500);
|
||||
final int onlineMode = plugin.getProxy().getConfig().isOnlineMode() ? 1 : 0;
|
||||
final String bungeecordVersion = plugin.getProxy().getVersion();
|
||||
final int managedServers = plugin.getProxy().getServers().size();
|
||||
@@ -146,27 +134,25 @@ public final class MetricsLite {
|
||||
if (plugin instanceof JsonObject) {
|
||||
pluginData.add((JsonObject) plugin);
|
||||
}
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
|
||||
} catch (final NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
data.add("plugins", pluginData);
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
sendData(data);
|
||||
} catch (Exception e) {
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats!", e);
|
||||
}
|
||||
try {
|
||||
sendData(plugin, data);
|
||||
} catch (final Exception e) {
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats!", e);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfig() throws IOException {
|
||||
final Path configPath = plugin.getDataFolder().toPath().getParent().resolve("bStats");
|
||||
configPath.toFile().mkdirs();
|
||||
final File configFile = new File(configPath.toFile(), "config.yml");
|
||||
final File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||
bStatsFolder.mkdirs();
|
||||
final File configFile = new File(bStatsFolder, "config.yml");
|
||||
if (!configFile.exists()) {
|
||||
writeFile(configFile,
|
||||
"#bStats collects some data for plugin authors like how many servers are using their plugins.",
|
||||
@@ -175,7 +161,9 @@ public final class MetricsLite {
|
||||
"#Check out https://bStats.org/ to learn more :)",
|
||||
"enabled: true",
|
||||
"serverUuid: \"" + UUID.randomUUID() + "\"",
|
||||
"logFailedRequests: false");
|
||||
"logFailedRequests: false",
|
||||
"logSentData: false",
|
||||
"logResponseStatusText: false");
|
||||
}
|
||||
|
||||
final Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||
@@ -183,6 +171,8 @@ public final class MetricsLite {
|
||||
enabled = configuration.getBoolean("enabled", true);
|
||||
serverUUID = configuration.getString("serverUuid");
|
||||
logFailedRequests = configuration.getBoolean("logFailedRequests", false);
|
||||
logSentData = configuration.getBoolean("logSentData", false);
|
||||
logResponseStatusText = configuration.getBoolean("logResponseStatusText", false);
|
||||
}
|
||||
|
||||
private Class<?> getFirstBStatsClass() {
|
||||
@@ -212,10 +202,7 @@ public final class MetricsLite {
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
try (
|
||||
FileReader fileReader = new FileReader(file);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
) {
|
||||
try (final BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
|
||||
return bufferedReader.readLine();
|
||||
}
|
||||
}
|
||||
@@ -224,10 +211,7 @@ public final class MetricsLite {
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
try (
|
||||
FileWriter fileWriter = new FileWriter(file);
|
||||
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)
|
||||
) {
|
||||
try (final BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file))) {
|
||||
for (final String line : lines) {
|
||||
bufferedWriter.write(line);
|
||||
bufferedWriter.newLine();
|
||||
@@ -235,10 +219,13 @@ public final class MetricsLite {
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendData(final JsonObject data) throws Exception {
|
||||
private static void sendData(final Plugin plugin, final JsonObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data);
|
||||
}
|
||||
|
||||
final HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
@@ -253,12 +240,22 @@ public final class MetricsLite {
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
connection.setDoOutput(true);
|
||||
final DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
|
||||
outputStream.write(compressedData);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
try (final DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||
outputStream.write(compressedData);
|
||||
}
|
||||
|
||||
connection.getInputStream().close();
|
||||
if (logResponseStatusText) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
try (final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
}
|
||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
|
||||
} else {
|
||||
connection.getInputStream().close();
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
@@ -266,9 +263,9 @@ public final class MetricsLite {
|
||||
return null;
|
||||
}
|
||||
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
final GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
gzip.close();
|
||||
try (final GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.bungee.util;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.core.proxy.util.ProxySenderInfo;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.Connection;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class BungeeSenderInfo implements ProxySenderInfo {
|
||||
private final CommandSender sender;
|
||||
|
||||
public BungeeSenderInfo(final CommandSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUuid() {
|
||||
return sender instanceof ProxiedPlayer ? ((ProxiedPlayer) sender).getUniqueId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return sender.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String permission) {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(final String message) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayer() {
|
||||
return sender instanceof ProxiedPlayer;
|
||||
}
|
||||
|
||||
public void sendMessage(final TextComponent textComponent) {
|
||||
sender.sendMessage(textComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccess(final Server server) {
|
||||
return ((BungeeServer) server).getServer().canAccess(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(final String message) {
|
||||
if (sender instanceof Connection) {
|
||||
((Connection) sender).disconnect(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.bungee.util;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
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;
|
||||
|
||||
public final class BungeeServer implements Server {
|
||||
private final ServerInfo server;
|
||||
|
||||
public BungeeServer(final ServerInfo server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return server.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPlayers() {
|
||||
return !server.getPlayers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(final String message) {
|
||||
final BaseComponent[] s = TextComponent.fromLegacyText(message);
|
||||
for (final ProxiedPlayer p : server.getPlayers()) {
|
||||
p.sendMessage(s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegisteredServer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ServerInfo getServer() {
|
||||
return server;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.bungee.util;
|
||||
|
||||
import eu.kennytv.maintenance.core.util.Task;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
public final class BungeeTask implements Task {
|
||||
private final int id;
|
||||
|
||||
public BungeeTask(final int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
ProxyServer.getInstance().getScheduler().cancel(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
name: Maintenance
|
||||
version: ${project.version}
|
||||
main: eu.kennytv.maintenance.bungee.MaintenanceBungeeBase
|
||||
author: KennyTV
|
||||
description: Enable maintenance mode with a custom maintenance motd and icon.
|
||||
softDepends: [ServerListPlus]
|
||||
website: https://www.spigotmc.org/resources/maintenance.40699/
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>eu.kennytv.maintenance</groupId>
|
||||
<artifactId>maintenance-parent</artifactId>
|
||||
<version>3.0.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-core-proxy</artifactId>
|
||||
<name>MaintenanceCoreProxy</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>eu.kennytv.maintenance</groupId>
|
||||
<artifactId>maintenance-core</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>3.4.2</version>
|
||||
<scope>compile</scope>
|
||||
<!-- Shade slf4j specifically and only in the Bungee module to prevent issues -->
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy;
|
||||
|
||||
import eu.kennytv.maintenance.api.event.proxy.ServerMaintenanceChangedEvent;
|
||||
import eu.kennytv.maintenance.api.proxy.IMaintenanceProxy;
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.core.MaintenancePlugin;
|
||||
import eu.kennytv.maintenance.core.proxy.command.MaintenanceProxyCommand;
|
||||
import eu.kennytv.maintenance.core.proxy.runnable.SingleMaintenanceRunnable;
|
||||
import eu.kennytv.maintenance.core.proxy.runnable.SingleMaintenanceScheduleRunnable;
|
||||
import eu.kennytv.maintenance.core.runnable.MaintenanceRunnableBase;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
import eu.kennytv.maintenance.core.util.ServerType;
|
||||
import eu.kennytv.maintenance.core.util.Task;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author KennyTV
|
||||
* @since 3.0
|
||||
*/
|
||||
public abstract class MaintenanceProxyPlugin extends MaintenancePlugin implements IMaintenanceProxy {
|
||||
private final Map<String, Task> serverTasks = new HashMap<>();
|
||||
protected SettingsProxy settingsProxy;
|
||||
|
||||
protected MaintenanceProxyPlugin(final String version, final ServerType serverType) {
|
||||
super(version, serverType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
super.disable();
|
||||
if (settingsProxy.getMySQL() != null) {
|
||||
settingsProxy.getMySQL().close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaintenance(final boolean maintenance) {
|
||||
if (settingsProxy.hasMySQL()) {
|
||||
settingsProxy.setMaintenanceToSQL(maintenance);
|
||||
}
|
||||
super.setMaintenance(maintenance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMaintenance(final Server server) {
|
||||
return settingsProxy.isMaintenance(server.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMaintenanceToServer(final Server server, final boolean maintenance) {
|
||||
if (maintenance) {
|
||||
if (!settingsProxy.addMaintenanceServer(server.getName())) return false;
|
||||
} else {
|
||||
if (!settingsProxy.removeMaintenanceServer(server.getName())) return false;
|
||||
}
|
||||
serverActions(server, maintenance);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void serverActions(final Server server, final boolean maintenance) {
|
||||
if (server == null) return;
|
||||
|
||||
// Skip to the even fire for dummy servers
|
||||
if (server.isRegisteredServer()) {
|
||||
if (maintenance) {
|
||||
final Server fallback = settingsProxy.getFallbackServer();
|
||||
if (fallback == null) {
|
||||
if (server.hasPlayers()) {
|
||||
getLogger().warning("The set fallback could not be found! Instead kicking players from that server off the network!");
|
||||
}
|
||||
}
|
||||
kickPlayers(server, fallback);
|
||||
} else {
|
||||
server.broadcast(settingsProxy.getMessage("singleMaintenanceDeactivated").replace("%SERVER%", server.getName()));
|
||||
}
|
||||
|
||||
cancelSingleTask(server);
|
||||
}
|
||||
|
||||
eventManager.callEvent(new ServerMaintenanceChangedEvent(server, maintenance));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isServerTaskRunning(final Server server) {
|
||||
return serverTasks.containsKey(server.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getMaintenanceServers() {
|
||||
return Collections.unmodifiableSet(settingsProxy.getMaintenanceServers());
|
||||
}
|
||||
|
||||
public void cancelSingleTask(final Server server) {
|
||||
final Task task = serverTasks.remove(server.getName());
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public MaintenanceRunnableBase startSingleMaintenanceRunnable(final Server server, final long duration, final TimeUnit unit, final boolean enable) {
|
||||
final MaintenanceRunnableBase runnable = new SingleMaintenanceRunnable(this, settingsProxy, (int) unit.toSeconds(duration), enable, server);
|
||||
serverTasks.put(server.getName(), runnable.getTask());
|
||||
return runnable;
|
||||
}
|
||||
|
||||
public MaintenanceRunnableBase scheduleSingleMaintenanceRunnable(final Server server, final long duration, final long maintenanceDuration, final TimeUnit unit) {
|
||||
final MaintenanceRunnableBase runnable = new SingleMaintenanceScheduleRunnable(this, settingsProxy,
|
||||
(int) unit.toSeconds(duration), (int) unit.toSeconds(maintenanceDuration), server);
|
||||
serverTasks.put(server.getName(), runnable.getTask());
|
||||
return runnable;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<String> getMaintenanceServersDump() {
|
||||
final List<String> list = new ArrayList<>();
|
||||
if (isMaintenance()) {
|
||||
list.add("global");
|
||||
}
|
||||
list.addAll(settingsProxy.getMaintenanceServers());
|
||||
return list.isEmpty() ? null : list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaintenanceProxyCommand getCommandManager() {
|
||||
return (MaintenanceProxyCommand) commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void kickPlayers() {
|
||||
// Send players to waiting server is set
|
||||
if (settingsProxy.getWaitingServer() != null) {
|
||||
final Server waitingServer = getServer(settingsProxy.getWaitingServer());
|
||||
if (waitingServer != null) {
|
||||
kickPlayersTo(waitingServer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If not set, kick players from proxy
|
||||
kickPlayersFromProxy();
|
||||
}
|
||||
|
||||
public SettingsProxy getSettingsProxy() {
|
||||
return settingsProxy;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract String getServerNameOf(SenderInfo sender);
|
||||
|
||||
protected abstract void kickPlayers(Server server, Server fallback);
|
||||
|
||||
protected abstract void kickPlayersTo(Server server);
|
||||
|
||||
protected abstract void kickPlayersFromProxy();
|
||||
}
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.core.Settings;
|
||||
import eu.kennytv.maintenance.core.config.ConfigSection;
|
||||
import eu.kennytv.maintenance.core.proxy.mysql.MySQL;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public final class SettingsProxy extends Settings {
|
||||
private final MaintenanceProxyPlugin proxyPlugin;
|
||||
private Set<String> maintenanceServers;
|
||||
private List<String> fallbackServers;
|
||||
private String waitingServer;
|
||||
|
||||
private String mySQLTable;
|
||||
private String serverTable;
|
||||
private String maintenanceQuery;
|
||||
private String serverQuery;
|
||||
private MySQL mySQL;
|
||||
|
||||
private long millisecondsToCheck;
|
||||
private long lastMySQLCheck;
|
||||
private long lastServerCheck;
|
||||
|
||||
public SettingsProxy(final MaintenanceProxyPlugin plugin) {
|
||||
super(plugin);
|
||||
this.proxyPlugin = plugin;
|
||||
}
|
||||
|
||||
private void setupMySQL() throws Exception {
|
||||
plugin.getLogger().info("Trying to open database connection... (also, you can simply ignore the SLF4J soft-warning if it shows up)");
|
||||
final ConfigSection section = config.getSection("mysql");
|
||||
if (section == null) {
|
||||
plugin.getLogger().warning("Section missing: mysql");
|
||||
return;
|
||||
}
|
||||
|
||||
mySQL = new MySQL(plugin.getLogger(),
|
||||
section.getString("host"),
|
||||
section.getInt("port"),
|
||||
section.getString("username"),
|
||||
section.getString("password"),
|
||||
section.getString("database"),
|
||||
section.getBoolean("use-ssl", true));
|
||||
|
||||
// Varchar as the value regarding the possibility of saving stuff like the motd as well in future updates
|
||||
mySQLTable = section.getString("table", "maintenance_settings");
|
||||
serverTable = section.getString("servertable", "maintenance_servers");
|
||||
mySQL.executeUpdate("CREATE TABLE IF NOT EXISTS " + mySQLTable + " (setting VARCHAR(16) PRIMARY KEY, value VARCHAR(255))");
|
||||
mySQL.executeUpdate("CREATE TABLE IF NOT EXISTS " + serverTable + " (server VARCHAR(64) PRIMARY KEY)");
|
||||
maintenanceQuery = "SELECT * FROM " + mySQLTable + " WHERE setting = ?";
|
||||
serverQuery = "SELECT * FROM " + serverTable;
|
||||
plugin.getLogger().info("Done!");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadExtraSettings() {
|
||||
// Open database connection if enabled and not already done
|
||||
if (!hasMySQL() && config.getBoolean("mysql.use-mysql")) {
|
||||
try {
|
||||
setupMySQL();
|
||||
} catch (final Exception e) {
|
||||
mySQL = null;
|
||||
plugin.getLogger().warning("Error while trying do open database connection!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
final Object fallback = config.getObject("fallback");
|
||||
fallbackServers = fallback instanceof String ? Collections.singletonList((String) fallback) : config.getStringList("fallback");
|
||||
|
||||
waitingServer = config.getString("waiting-server", "");
|
||||
if (waitingServer.isEmpty() || waitingServer.equalsIgnoreCase("none")) {
|
||||
waitingServer = null;
|
||||
}
|
||||
|
||||
if (hasMySQL()) {
|
||||
maintenance = loadMaintenance();
|
||||
maintenanceServers = loadMaintenanceServersFromSQL();
|
||||
|
||||
final long configValue = config.getInt("mysql.update-interval");
|
||||
// Even if set to 0, only check every 500 millis
|
||||
millisecondsToCheck = configValue > 0 ? configValue * 1000 : 500;
|
||||
lastMySQLCheck = System.currentTimeMillis();
|
||||
lastServerCheck = System.currentTimeMillis();
|
||||
} else {
|
||||
final List<String> list = config.getStringList("proxied-maintenance-servers");
|
||||
maintenanceServers = list == null ? new HashSet<>() : new HashSet<>(list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMaintenance() {
|
||||
if (hasMySQL() && System.currentTimeMillis() - lastMySQLCheck > millisecondsToCheck) {
|
||||
final boolean databaseValue = loadMaintenance();
|
||||
if (databaseValue != maintenance) {
|
||||
maintenance = databaseValue;
|
||||
plugin.serverActions(maintenance);
|
||||
}
|
||||
lastMySQLCheck = System.currentTimeMillis();
|
||||
}
|
||||
return maintenance;
|
||||
}
|
||||
|
||||
public boolean isMaintenance(final String serverName) {
|
||||
if (hasMySQL() && System.currentTimeMillis() - lastServerCheck > millisecondsToCheck) {
|
||||
final Set<String> databaseValue = loadMaintenanceServersFromSQL();
|
||||
if (!maintenanceServers.equals(databaseValue)) {
|
||||
// Enable maintenance on yet unlisted servers
|
||||
for (final String s : databaseValue) {
|
||||
if (!maintenanceServers.contains(s)) {
|
||||
proxyPlugin.serverActions(proxyPlugin.getServer(s), true);
|
||||
}
|
||||
}
|
||||
// Disable maintenance on now unlisted servers
|
||||
for (final String s : maintenanceServers) {
|
||||
if (!databaseValue.contains(s)) {
|
||||
proxyPlugin.serverActions(proxyPlugin.getServer(s), false);
|
||||
}
|
||||
}
|
||||
maintenanceServers = databaseValue;
|
||||
}
|
||||
lastServerCheck = System.currentTimeMillis();
|
||||
}
|
||||
return maintenanceServers.contains(serverName);
|
||||
}
|
||||
|
||||
public String getServerKickMessage(final String server) {
|
||||
String message = language.getString("singleMaintenanceKicks." + server);
|
||||
if (message == null) {
|
||||
message = getMessage("singleMaintenanceKick");
|
||||
}
|
||||
return plugin.replacePingVariables(message).replace("%SERVER%", server);
|
||||
}
|
||||
|
||||
// Full = being kicked from the proxy, not just a proxied server
|
||||
public String getFullServerKickMessage(final String server) {
|
||||
String message = language.getString("singleMaintenanceKicksComplete." + server);
|
||||
if (message == null) {
|
||||
message = getMessage("singleMaintenanceKickComplete");
|
||||
}
|
||||
return plugin.replacePingVariables(message).replace("%SERVER%", server);
|
||||
}
|
||||
|
||||
public boolean hasMySQL() {
|
||||
return mySQL != null;
|
||||
}
|
||||
|
||||
void setMaintenanceToSQL(final boolean maintenance) {
|
||||
plugin.async(() -> {
|
||||
final String s = String.valueOf(maintenance);
|
||||
mySQL.executeUpdate("INSERT INTO " + mySQLTable + " (setting, value) VALUES (?, ?) ON DUPLICATE KEY UPDATE value = ?", "maintenance", s, s);
|
||||
lastMySQLCheck = System.currentTimeMillis();
|
||||
});
|
||||
}
|
||||
|
||||
boolean addMaintenanceServer(final String server) {
|
||||
if (hasMySQL()) {
|
||||
maintenanceServers = loadMaintenanceServersFromSQL();
|
||||
if (!maintenanceServers.add(server)) return false;
|
||||
plugin.async(() -> mySQL.executeUpdate("INSERT INTO " + serverTable + " (server) VALUES (?)", server));
|
||||
lastServerCheck = System.currentTimeMillis();
|
||||
} else {
|
||||
if (!maintenanceServers.add(server)) return false;
|
||||
saveServersToConfig();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean removeMaintenanceServer(final String server) {
|
||||
if (hasMySQL()) {
|
||||
maintenanceServers = loadMaintenanceServersFromSQL();
|
||||
if (!maintenanceServers.remove(server)) return false;
|
||||
|
||||
plugin.async(() -> mySQL.executeUpdate("DELETE FROM " + serverTable + " WHERE server = ?", server));
|
||||
lastServerCheck = System.currentTimeMillis();
|
||||
} else {
|
||||
if (!maintenanceServers.remove(server)) return false;
|
||||
|
||||
saveServersToConfig();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private Set<String> loadMaintenanceServersFromSQL() {
|
||||
final Set<String> maintenanceServers = new HashSet<>();
|
||||
mySQL.executeQuery(serverQuery, rs -> {
|
||||
try {
|
||||
while (rs.next()) {
|
||||
maintenanceServers.add(rs.getString("server"));
|
||||
}
|
||||
} catch (final SQLException e) {
|
||||
plugin.getLogger().warning("An error occured while trying to get the list of single servers with maintenance!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
return maintenanceServers;
|
||||
}
|
||||
|
||||
private boolean loadMaintenance() {
|
||||
final boolean[] databaseValue = {false};
|
||||
mySQL.executeQuery(maintenanceQuery, rs -> {
|
||||
try {
|
||||
if (rs.next()) {
|
||||
databaseValue[0] = Boolean.parseBoolean(rs.getString("value"));
|
||||
}
|
||||
} catch (final SQLException e) {
|
||||
plugin.getLogger().warning("An error occured while trying to get the maintenance value from the database!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, "maintenance");
|
||||
return databaseValue[0];
|
||||
}
|
||||
|
||||
private void saveServersToConfig() {
|
||||
config.set("proxied-maintenance-servers", new ArrayList<>(maintenanceServers));
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public Set<String> getMaintenanceServers() {
|
||||
return maintenanceServers;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Server getFallbackServer() {
|
||||
for (final String fallbackServer : fallbackServers) {
|
||||
final Server server = proxyPlugin.getServer(fallbackServer);
|
||||
if (server != null && !isMaintenance(server.getName())) {
|
||||
return server;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getWaitingServer() {
|
||||
return waitingServer;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
MySQL getMySQL() {
|
||||
return mySQL;
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.command;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.core.command.MaintenanceCommand;
|
||||
import eu.kennytv.maintenance.core.proxy.MaintenanceProxyPlugin;
|
||||
import eu.kennytv.maintenance.core.proxy.SettingsProxy;
|
||||
import eu.kennytv.maintenance.core.proxy.command.subcommand.*;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class MaintenanceProxyCommand extends MaintenanceCommand {
|
||||
private final MaintenanceProxyPlugin plugin;
|
||||
private final SettingsProxy settingsBungee;
|
||||
|
||||
protected MaintenanceProxyCommand(final MaintenanceProxyPlugin plugin, final SettingsProxy settings) {
|
||||
super(plugin, settings);
|
||||
this.plugin = plugin;
|
||||
settingsBungee = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addToggleAndTimerCommands() {
|
||||
add(new SingleToggleCommand(plugin), "on", "off");
|
||||
add(new StatusCommand(plugin), "status");
|
||||
|
||||
add(new SingleStarttimerCommand(plugin), "starttimer", "start");
|
||||
add(new SingleEndtimerCommand(plugin), "endtimer", "end");
|
||||
add(new SingleScheduleTimerCommand(plugin), "scheduletimer", "schedule");
|
||||
add(new AbortSingleTimerCommand(plugin), "aborttimer", "abort");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMaintenanceServersCompletion(final String s) {
|
||||
final List<String> list = new ArrayList<>();
|
||||
for (final String server : settingsBungee.getMaintenanceServers()) {
|
||||
if (server.toLowerCase().startsWith(s)) {
|
||||
list.add(server);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public Server checkSingleTimerServerArg(final SenderInfo sender, final String serverName) {
|
||||
final Server server = plugin.getServer(serverName);
|
||||
if (server == null) {
|
||||
sender.sendMessage(settings.getMessage("serverNotFound"));
|
||||
return null;
|
||||
}
|
||||
if (plugin.isServerTaskRunning(server)) {
|
||||
sender.sendMessage(settings.getMessage("singleTimerAlreadyRunning"));
|
||||
return null;
|
||||
}
|
||||
return server;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.command;
|
||||
|
||||
import eu.kennytv.maintenance.core.command.CommandInfo;
|
||||
import eu.kennytv.maintenance.core.proxy.MaintenanceProxyPlugin;
|
||||
import eu.kennytv.maintenance.core.proxy.SettingsProxy;
|
||||
|
||||
public abstract class ProxyCommandInfo extends CommandInfo {
|
||||
protected final MaintenanceProxyPlugin plugin;
|
||||
|
||||
protected ProxyCommandInfo(final MaintenanceProxyPlugin plugin, final String permission) {
|
||||
super(plugin, permission);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SettingsProxy getSettings() {
|
||||
return plugin.getSettingsProxy();
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.command.subcommand;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.core.proxy.MaintenanceProxyPlugin;
|
||||
import eu.kennytv.maintenance.core.proxy.command.ProxyCommandInfo;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class AbortSingleTimerCommand extends ProxyCommandInfo {
|
||||
|
||||
public AbortSingleTimerCommand(final MaintenanceProxyPlugin plugin) {
|
||||
super(plugin, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final SenderInfo sender) {
|
||||
return sender.hasMaintenancePermission("timer") || sender.hasPermission("maintenance.singleserver.timer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final SenderInfo sender, final String[] args) {
|
||||
if (args.length == 1) {
|
||||
if (checkPermission(sender, "timer")) return;
|
||||
if (!plugin.isTaskRunning()) {
|
||||
sender.sendMessage(getMessage("timerNotRunning"));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.cancelTask();
|
||||
sender.sendMessage(getMessage("timerCancelled"));
|
||||
} else if (args.length == 2) {
|
||||
if (checkPermission(sender, "singleserver.timer")) return;
|
||||
final Server server = plugin.getServer(args[1]);
|
||||
if (server == null) {
|
||||
sender.sendMessage(getMessage("serverNotFound"));
|
||||
return;
|
||||
}
|
||||
if (!plugin.isServerTaskRunning(server)) {
|
||||
sender.sendMessage(getMessage("singleTimerNotRunning"));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.cancelSingleTask(server);
|
||||
sender.sendMessage(getMessage("singleTimerCancelled"));
|
||||
} else
|
||||
sender.sendMessage(getHelpMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletion(final SenderInfo sender, final String[] args) {
|
||||
return args.length == 2 && sender.hasMaintenancePermission("singleserver.timer") ? plugin.getCommandManager().getServersCompletion(args[1]) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.command.subcommand;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.core.proxy.MaintenanceProxyPlugin;
|
||||
import eu.kennytv.maintenance.core.proxy.command.ProxyCommandInfo;
|
||||
import eu.kennytv.maintenance.core.runnable.MaintenanceRunnableBase;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class SingleEndtimerCommand extends ProxyCommandInfo {
|
||||
|
||||
public SingleEndtimerCommand(final MaintenanceProxyPlugin plugin) {
|
||||
super(plugin, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final SenderInfo sender) {
|
||||
return sender.hasMaintenancePermission("timer") || sender.hasPermission("maintenance.singleserver.timer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final SenderInfo sender, final String[] args) {
|
||||
if (args.length == 2) {
|
||||
if (checkPermission(sender, "timer")) return;
|
||||
if (plugin.getCommandManager().checkTimerArgs(sender, args[1])) {
|
||||
sender.sendMessage(getHelpMessage());
|
||||
return;
|
||||
}
|
||||
if (!plugin.isMaintenance()) {
|
||||
sender.sendMessage(getMessage("alreadyDisabled"));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.startMaintenanceRunnable(Integer.parseInt(args[1]), TimeUnit.MINUTES, false);
|
||||
sender.sendMessage(getMessage("endtimerStarted").replace("%TIME%", plugin.getRunnable().getTime()));
|
||||
} else if (args.length == 3) {
|
||||
if (checkPermission(sender, "singleserver.timer")) return;
|
||||
if (plugin.getCommandManager().checkTimerArgs(sender, args[2], false)) {
|
||||
sender.sendMessage(getHelpMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
final Server server = plugin.getCommandManager().checkSingleTimerServerArg(sender, args[1]);
|
||||
if (server == null) return;
|
||||
if (!plugin.isMaintenance(server)) {
|
||||
sender.sendMessage(getMessage("singleServerAlreadyDisabled").replace("%SERVER%", server.getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
final MaintenanceRunnableBase runnable = plugin.startSingleMaintenanceRunnable(server, Integer.parseInt(args[2]), TimeUnit.MINUTES, false);
|
||||
sender.sendMessage(getMessage("endtimerStarted").replace("%TIME%", runnable.getTime()));
|
||||
} else {
|
||||
sender.sendMessage(getHelpMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletion(final SenderInfo sender, final String[] args) {
|
||||
return args.length == 2 && sender.hasMaintenancePermission("singleserver.timer") ? plugin.getCommandManager().getMaintenanceServersCompletion(args[1].toLowerCase()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.command.subcommand;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.core.proxy.MaintenanceProxyPlugin;
|
||||
import eu.kennytv.maintenance.core.proxy.command.ProxyCommandInfo;
|
||||
import eu.kennytv.maintenance.core.runnable.MaintenanceRunnableBase;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class SingleScheduleTimerCommand extends ProxyCommandInfo {
|
||||
|
||||
public SingleScheduleTimerCommand(final MaintenanceProxyPlugin plugin) {
|
||||
super(plugin, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final SenderInfo sender) {
|
||||
return sender.hasMaintenancePermission("timer") || sender.hasPermission("maintenance.singleserver.timer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final SenderInfo sender, final String[] args) {
|
||||
if (args.length == 3) {
|
||||
if (checkPermission(sender, "timer")) return;
|
||||
if (plugin.getCommandManager().checkTimerArgs(sender, args[1])
|
||||
|| plugin.getCommandManager().checkTimerArgs(sender, args[2], false)) {
|
||||
sender.sendMessage(getHelpMessage());
|
||||
return;
|
||||
}
|
||||
if (plugin.isMaintenance()) {
|
||||
sender.sendMessage(getMessage("alreadyEnabled"));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.scheduleMaintenanceRunnable(Integer.parseInt(args[1]), Integer.parseInt(args[2]), TimeUnit.MINUTES);
|
||||
sender.sendMessage(getMessage("starttimerStarted").replace("%TIME%", plugin.getRunnable().getTime()));
|
||||
} else if (args.length == 4) {
|
||||
if (checkPermission(sender, "singleserver.timer")) return;
|
||||
if (plugin.getCommandManager().checkTimerArgs(sender, args[2], false)
|
||||
|| plugin.getCommandManager().checkTimerArgs(sender, args[3], false)) {
|
||||
sender.sendMessage(getHelpMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
final Server server = plugin.getCommandManager().checkSingleTimerServerArg(sender, args[1]);
|
||||
if (server == null) return;
|
||||
if (plugin.isMaintenance(server)) {
|
||||
sender.sendMessage(getMessage("singleServerAlreadyEnabled").replace("%SERVER%", server.getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
final MaintenanceRunnableBase runnable = plugin.scheduleSingleMaintenanceRunnable(server, Integer.parseInt(args[2]), Integer.parseInt(args[3]), TimeUnit.MINUTES);
|
||||
sender.sendMessage(getMessage("starttimerStarted").replace("%TIME%", runnable.getTime()));
|
||||
} else {
|
||||
sender.sendMessage(getHelpMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletion(final SenderInfo sender, final String[] args) {
|
||||
return args.length == 2 && sender.hasMaintenancePermission("singleserver.timer") ? plugin.getCommandManager().getServersCompletion(args[1].toLowerCase()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.command.subcommand;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.core.proxy.MaintenanceProxyPlugin;
|
||||
import eu.kennytv.maintenance.core.proxy.command.ProxyCommandInfo;
|
||||
import eu.kennytv.maintenance.core.runnable.MaintenanceRunnableBase;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class SingleStarttimerCommand extends ProxyCommandInfo {
|
||||
|
||||
public SingleStarttimerCommand(final MaintenanceProxyPlugin plugin) {
|
||||
super(plugin, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final SenderInfo sender) {
|
||||
return sender.hasMaintenancePermission("timer") || sender.hasPermission("maintenance.singleserver.timer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final SenderInfo sender, final String[] args) {
|
||||
if (args.length == 2) {
|
||||
if (checkPermission(sender, "timer")) return;
|
||||
if (plugin.getCommandManager().checkTimerArgs(sender, args[1])) {
|
||||
sender.sendMessage(getHelpMessage());
|
||||
return;
|
||||
}
|
||||
if (plugin.isMaintenance()) {
|
||||
sender.sendMessage(getMessage("alreadyEnabled"));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.startMaintenanceRunnable(Integer.parseInt(args[1]), TimeUnit.MINUTES, true);
|
||||
sender.sendMessage(getMessage("starttimerStarted").replace("%TIME%", plugin.getRunnable().getTime()));
|
||||
} else if (args.length == 3) {
|
||||
if (checkPermission(sender, "singleserver.timer")) return;
|
||||
if (plugin.getCommandManager().checkTimerArgs(sender, args[2], false)) {
|
||||
sender.sendMessage(getHelpMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
final Server server = plugin.getCommandManager().checkSingleTimerServerArg(sender, args[1]);
|
||||
if (server == null) return;
|
||||
if (plugin.isMaintenance(server)) {
|
||||
sender.sendMessage(getMessage("singleServerAlreadyEnabled").replace("%SERVER%", server.getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
final MaintenanceRunnableBase runnable = plugin.startSingleMaintenanceRunnable(server, Integer.parseInt(args[2]), TimeUnit.MINUTES, true);
|
||||
sender.sendMessage(getMessage("starttimerStarted").replace("%TIME%", runnable.getTime()));
|
||||
} else {
|
||||
sender.sendMessage(getHelpMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletion(final SenderInfo sender, final String[] args) {
|
||||
return args.length == 2 && sender.hasMaintenancePermission("singleserver.timer") ? plugin.getCommandManager().getServersCompletion(args[1].toLowerCase()) : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.command.subcommand;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.core.proxy.MaintenanceProxyPlugin;
|
||||
import eu.kennytv.maintenance.core.proxy.command.ProxyCommandInfo;
|
||||
import eu.kennytv.maintenance.core.proxy.server.DummyServer;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class SingleToggleCommand extends ProxyCommandInfo {
|
||||
|
||||
public SingleToggleCommand(final MaintenanceProxyPlugin plugin) {
|
||||
super(plugin, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final SenderInfo sender) {
|
||||
return sender.hasMaintenancePermission("toggle") || sender.hasPermission("maintenance.singleserver.toggle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final SenderInfo sender, final String[] args) {
|
||||
if (args.length == 1) {
|
||||
if (checkPermission(sender, "toggle")) return;
|
||||
final boolean maintenance = args[0].equalsIgnoreCase("on");
|
||||
if (maintenance == plugin.isMaintenance()) {
|
||||
sender.sendMessage(getMessage(maintenance ? "alreadyEnabled" : "alreadyDisabled"));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.setMaintenance(maintenance);
|
||||
} else if (args.length == 2) {
|
||||
if (checkPermission(sender, "singleserver.toggle")) return;
|
||||
final boolean maintenance = args[0].equalsIgnoreCase("on");
|
||||
Server server = plugin.getServer(args[1]);
|
||||
if (server == null) {
|
||||
if (maintenance) {
|
||||
sender.sendMessage(getMessage("serverNotFound"));
|
||||
return;
|
||||
}
|
||||
// Let servers be removed from the maintenance list, even if they don't exist on the proxy
|
||||
server = new DummyServer(args[1]);
|
||||
if (!plugin.isMaintenance(server)) {
|
||||
sender.sendMessage(getMessage("serverNotFound"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.setMaintenanceToServer(server, maintenance)) {
|
||||
if (!sender.isPlayer() || !server.getName().equals(plugin.getServerNameOf(sender))) {
|
||||
sender.sendMessage(getMessage(maintenance ? "singleMaintenanceActivated" : "singleMaintenanceDeactivated").replace("%SERVER%", server.getName()));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(getMessage(maintenance ? "singleServerAlreadyEnabled" : "singleServerAlreadyDisabled").replace("%SERVER%", server.getName()));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(getHelpMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletion(final SenderInfo sender, final String[] args) {
|
||||
if (args.length != 2 || !sender.hasMaintenancePermission("singleserver.toggle")) return Collections.emptyList();
|
||||
return args[0].equalsIgnoreCase("off") ? plugin.getCommandManager().getMaintenanceServersCompletion(args[1].toLowerCase())
|
||||
: plugin.getCommandManager().getServersCompletion(args[1].toLowerCase());
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.command.subcommand;
|
||||
|
||||
import eu.kennytv.maintenance.core.proxy.MaintenanceProxyPlugin;
|
||||
import eu.kennytv.maintenance.core.proxy.command.ProxyCommandInfo;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
|
||||
public final class StatusCommand extends ProxyCommandInfo {
|
||||
|
||||
public StatusCommand(final MaintenanceProxyPlugin plugin) {
|
||||
super(plugin, "singleserver.status");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final SenderInfo sender, final String[] args) {
|
||||
if (getSettings().getMaintenanceServers().isEmpty()) {
|
||||
sender.sendMessage(getMessage("singleServerMaintenanceListEmpty"));
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(getMessage("singleServerMaintenanceList"));
|
||||
for (final String server : getSettings().getMaintenanceServers()) {
|
||||
sender.sendMessage("§8- §b" + server);
|
||||
}
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.listener;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.core.listener.JoinListenerBase;
|
||||
import eu.kennytv.maintenance.core.proxy.MaintenanceProxyPlugin;
|
||||
import eu.kennytv.maintenance.core.proxy.SettingsProxy;
|
||||
import eu.kennytv.maintenance.core.proxy.util.ProxySenderInfo;
|
||||
import eu.kennytv.maintenance.core.proxy.util.ServerConnectResult;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class ProxyJoinListenerBase extends JoinListenerBase {
|
||||
private static final ServerConnectResult ALLOWED = new ServerConnectResult(false);
|
||||
private static final ServerConnectResult DENIED = new ServerConnectResult(true);
|
||||
protected final MaintenanceProxyPlugin plugin;
|
||||
protected final SettingsProxy settings;
|
||||
private boolean warned;
|
||||
|
||||
protected ProxyJoinListenerBase(final MaintenanceProxyPlugin plugin, final SettingsProxy settings) {
|
||||
super(plugin, settings);
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sender joined player
|
||||
* @param target target server
|
||||
* @param normalServerConnect true if normal server connect, false if initial proxy join or kick
|
||||
* @return connect result with data for further handling
|
||||
*/
|
||||
protected ServerConnectResult serverConnect(final ProxySenderInfo sender, final Server target, final boolean normalServerConnect) {
|
||||
// Check waiting server for global maintenance
|
||||
if (settings.isMaintenance()) {
|
||||
if (sender.hasMaintenancePermission("bypass") || settings.isWhitelisted(sender.getUuid())) return ALLOWED;
|
||||
|
||||
final Server waitingServer = shouldConnectToWaitingServer(sender);
|
||||
// Should never be null, but just in case
|
||||
if (waitingServer == null) return DENIED;
|
||||
|
||||
// Player is connecting to the waiting server
|
||||
if (target.getName().equals(waitingServer.getName())) return ALLOWED;
|
||||
|
||||
// Player already is on the waiting server
|
||||
final String currentServer = plugin.getServerNameOf(sender);
|
||||
if (waitingServer.getName().equals(currentServer)) {
|
||||
sender.sendMessage(settings.getMessage("forceWaitingServer"));
|
||||
return DENIED;
|
||||
}
|
||||
|
||||
sender.sendMessage(settings.getMessage("sentToWaitingServer"));
|
||||
return new ServerConnectResult(waitingServer);
|
||||
}
|
||||
|
||||
// Single server maintenance
|
||||
if (!settings.isMaintenance(target.getName())) return ALLOWED;
|
||||
if (sender.hasMaintenancePermission("bypass") || settings.isWhitelisted(sender.getUuid())
|
||||
|| sender.hasMaintenancePermission("singleserver.bypass." + target.getName().toLowerCase())) {
|
||||
return ALLOWED;
|
||||
}
|
||||
|
||||
if (settings.isJoinNotifications()) {
|
||||
broadcastJoinNotification(sender.getName(), target);
|
||||
}
|
||||
|
||||
if (normalServerConnect) {
|
||||
sender.sendMessage(settings.getServerKickMessage(target.getName()));
|
||||
return DENIED;
|
||||
}
|
||||
|
||||
// If it's the initial proxy join or a kick from another server, go back to fallback server
|
||||
final Server fallback = settings.getFallbackServer();
|
||||
if (fallback == null || !sender.canAccess(fallback)) {
|
||||
// Nothing to redirect to, player has to be kicked from the proxy
|
||||
sender.disconnect(settings.getFullServerKickMessage(target.getName()));
|
||||
if (!warned) {
|
||||
plugin.getLogger().warning("Could not send player to the set fallback server; instead kicking player off the network!");
|
||||
warned = true;
|
||||
}
|
||||
return DENIED;
|
||||
} else {
|
||||
return new ServerConnectResult(fallback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To be called after {@link #shouldKick(SenderInfo, boolean)} to get the waiting server if present.
|
||||
* Does not do any permission checks, they should be done separately!
|
||||
*
|
||||
* @param sender sender
|
||||
* @return waiting server, null if player should be kicked
|
||||
*/
|
||||
@Nullable
|
||||
protected Server shouldConnectToWaitingServer(final ProxySenderInfo sender) {
|
||||
if (settings.getWaitingServer() == null) return null;
|
||||
|
||||
final Server waitingServer = plugin.getServer(settings.getWaitingServer());
|
||||
if (waitingServer == null) return null;
|
||||
if (!sender.canAccess(waitingServer) || settings.isMaintenance(waitingServer.getName())) return null;
|
||||
|
||||
return waitingServer;
|
||||
}
|
||||
|
||||
protected abstract void broadcastJoinNotification(String name, Server server);
|
||||
}
|
||||
+39
-7
@@ -1,4 +1,22 @@
|
||||
package eu.kennytv.maintenance.bungee.mysql;
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.mysql;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
@@ -8,19 +26,29 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class MySQL {
|
||||
private final Logger logger;
|
||||
private final HikariDataSource hikariDataSource;
|
||||
|
||||
// Excuse me and everything to do with the MySQL stuff, I have little to no idea of how to use databases
|
||||
public MySQL(final String hostname, final int port, final String username, final String password, final String database) {
|
||||
public MySQL(final Logger logger, final String hostname, final int port, final String username, final String password, final String database, final boolean useSSL) {
|
||||
this.logger = logger;
|
||||
|
||||
final HikariConfig hikariConfig = new HikariConfig();
|
||||
hikariConfig.setMaximumPoolSize(10);
|
||||
hikariConfig.addDataSourceProperty("serverName", hostname);
|
||||
hikariConfig.addDataSourceProperty("user", username);
|
||||
hikariConfig.addDataSourceProperty("password", password);
|
||||
hikariConfig.addDataSourceProperty("url", "jdbc:mysql://" + hostname + ":" + port + "/" + database);
|
||||
hikariConfig.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database);
|
||||
|
||||
String urlProperty = "jdbc:mysql://" + hostname + ":" + port + "/" + database;
|
||||
if (!useSSL) {
|
||||
urlProperty += "?useSSL=false";
|
||||
}
|
||||
hikariConfig.addDataSourceProperty("url", urlProperty);
|
||||
|
||||
hikariConfig.setJdbcUrl(urlProperty);
|
||||
hikariConfig.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
|
||||
hikariDataSource = new HikariDataSource(hikariConfig);
|
||||
}
|
||||
@@ -37,7 +65,7 @@ public final class MySQL {
|
||||
callback.accept(preparedStatement.executeUpdate());
|
||||
}
|
||||
} catch (final SQLException e) {
|
||||
System.out.println("Error while executing update method: " + query);
|
||||
logger.log(Level.SEVERE, "Error while executing update method: " + query);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -56,7 +84,7 @@ public final class MySQL {
|
||||
resultSet.close();
|
||||
}
|
||||
} catch (final SQLException e) {
|
||||
System.out.println("Error while executing query method: " + query);
|
||||
logger.log(Level.SEVERE, "Error while executing query method: " + query);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -65,4 +93,8 @@ public final class MySQL {
|
||||
executeUpdate(query, res -> {
|
||||
}, objects);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
hikariDataSource.close();
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.runnable;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.IMaintenanceProxy;
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.core.MaintenancePlugin;
|
||||
import eu.kennytv.maintenance.core.Settings;
|
||||
import eu.kennytv.maintenance.core.runnable.MaintenanceRunnableBase;
|
||||
|
||||
public class SingleMaintenanceRunnable extends MaintenanceRunnableBase {
|
||||
protected final Server server;
|
||||
|
||||
public SingleMaintenanceRunnable(final MaintenancePlugin plugin, final Settings settings, final int seconds, final boolean enable, final Server server) {
|
||||
super(plugin, settings, seconds, enable);
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void broadcast(final String message) {
|
||||
server.broadcast(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finish() {
|
||||
((IMaintenanceProxy) plugin).setMaintenanceToServer(server, enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getStartMessage() {
|
||||
return settings.getMessage("singleStarttimerBroadcast").replace("%TIME%", getTime()).replace("%SERVER%", server.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getEndMessage() {
|
||||
return settings.getMessage("singleEndtimerBroadcast").replace("%TIME%", getTime()).replace("%SERVER%", server.getName());
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.runnable;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.core.MaintenancePlugin;
|
||||
import eu.kennytv.maintenance.core.Settings;
|
||||
import eu.kennytv.maintenance.core.proxy.MaintenanceProxyPlugin;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class SingleMaintenanceScheduleRunnable extends SingleMaintenanceRunnable {
|
||||
private final int maintenanceDuration;
|
||||
|
||||
public SingleMaintenanceScheduleRunnable(final MaintenancePlugin plugin, final Settings settings, final int seconds, final int maintenanceDuration, final Server server) {
|
||||
super(plugin, settings, seconds, true, server);
|
||||
this.maintenanceDuration = maintenanceDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finish() {
|
||||
super.finish();
|
||||
((MaintenanceProxyPlugin) plugin).startSingleMaintenanceRunnable(server, maintenanceDuration, TimeUnit.SECONDS, false);
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.server;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
|
||||
public final class DummyServer implements Server {
|
||||
private final String name;
|
||||
|
||||
public DummyServer(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPlayers() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(final String s) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegisteredServer() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.util;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
|
||||
public interface ProxySenderInfo extends SenderInfo {
|
||||
|
||||
boolean canAccess(Server server);
|
||||
|
||||
void disconnect(String message);
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.proxy.util;
|
||||
|
||||
import eu.kennytv.maintenance.api.proxy.Server;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class ServerConnectResult {
|
||||
private final boolean cancel;
|
||||
private final Server target;
|
||||
|
||||
public ServerConnectResult(final boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
this.target = null;
|
||||
}
|
||||
|
||||
public ServerConnectResult(final Server target) {
|
||||
this.cancel = false;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Server getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ServerConnectResult{" +
|
||||
"cancel=" + cancel +
|
||||
", target=" + target +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>eu.kennytv.maintenance</groupId>
|
||||
<artifactId>maintenance-parent</artifactId>
|
||||
<version>3.0.6</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maintenance-core</artifactId>
|
||||
<name>MaintenanceCore</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>eu.kennytv.maintenance</groupId>
|
||||
<artifactId>maintenance-api</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.23</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.minecrell</groupId>
|
||||
<artifactId>ServerListPlus</artifactId>
|
||||
<version>3.4.9-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>29.0-jre</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package eu.kennytv.maintenance.core.util;
|
||||
|
||||
public final class MaintenanceVersion {
|
||||
|
||||
public static final String VERSION = "${project.version}";
|
||||
}
|
||||
@@ -0,0 +1,432 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import eu.kennytv.maintenance.api.IMaintenance;
|
||||
import eu.kennytv.maintenance.api.event.MaintenanceChangedEvent;
|
||||
import eu.kennytv.maintenance.api.event.manager.IEventManager;
|
||||
import eu.kennytv.maintenance.core.command.MaintenanceCommand;
|
||||
import eu.kennytv.maintenance.core.dump.MaintenanceDump;
|
||||
import eu.kennytv.maintenance.core.dump.PluginDump;
|
||||
import eu.kennytv.maintenance.core.event.EventManager;
|
||||
import eu.kennytv.maintenance.core.hook.ServerListPlusHook;
|
||||
import eu.kennytv.maintenance.core.runnable.MaintenanceRunnable;
|
||||
import eu.kennytv.maintenance.core.runnable.MaintenanceScheduleRunnable;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
import eu.kennytv.maintenance.core.util.ServerType;
|
||||
import eu.kennytv.maintenance.core.util.Task;
|
||||
import eu.kennytv.maintenance.core.util.Version;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class MaintenancePlugin implements IMaintenance {
|
||||
protected final EventManager eventManager;
|
||||
protected final Version version;
|
||||
protected Settings settings;
|
||||
protected ServerListPlusHook serverListPlusHook;
|
||||
protected MaintenanceRunnable runnable;
|
||||
protected MaintenanceCommand commandManager;
|
||||
private final String prefix;
|
||||
private final ServerType serverType;
|
||||
private Version newestVersion;
|
||||
private boolean debug;
|
||||
|
||||
protected MaintenancePlugin(final String version, final ServerType serverType) {
|
||||
this.version = new Version(version);
|
||||
this.serverType = serverType;
|
||||
this.prefix = "§8[§eMaintenance" + serverType + "§8] ";
|
||||
this.eventManager = new EventManager();
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaintenance(final boolean maintenance) {
|
||||
settings.setMaintenance(maintenance);
|
||||
settings.getConfig().set("maintenance-enabled", maintenance);
|
||||
settings.saveConfig();
|
||||
serverActions(maintenance);
|
||||
}
|
||||
|
||||
public void serverActions(final boolean maintenance) {
|
||||
if (isTaskRunning()) {
|
||||
cancelTask();
|
||||
}
|
||||
if (serverListPlusHook != null) {
|
||||
serverListPlusHook.setEnabled(!maintenance);
|
||||
}
|
||||
|
||||
if (maintenance) {
|
||||
broadcast(settings.getMessage("maintenanceActivated"));
|
||||
if (settings.isKickOnlinePlayers()) {
|
||||
kickPlayers();
|
||||
}
|
||||
} else {
|
||||
broadcast(settings.getMessage("maintenanceDeactivated"));
|
||||
}
|
||||
|
||||
eventManager.callEvent(new MaintenanceChangedEvent(maintenance));
|
||||
}
|
||||
|
||||
public String replacePingVariables(String s) {
|
||||
if (s.contains("%TIMER%")) {
|
||||
s = s.replace("%TIMER%", getTimerMessage());
|
||||
}
|
||||
if (s.contains("%ONLINE%")) {
|
||||
s = s.replace("%ONLINE%", Integer.toString(getOnlinePlayers()));
|
||||
}
|
||||
if (s.contains("%MAX%")) {
|
||||
s = s.replace("%MAX%", Integer.toString(getMaxPlayers()));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public String getTimerMessage() {
|
||||
if (!isTaskRunning()) return settings.getMessage("motdTimerNotRunning", "-");
|
||||
final int preHours = runnable.getSecondsLeft() / 60;
|
||||
final int minutes = preHours % 60;
|
||||
final int seconds = runnable.getSecondsLeft() % 60;
|
||||
return settings.getMessage("motdTimer", "%HOURS%:%MINUTES%:%SECONDS%")
|
||||
.replace("%HOURS%", String.format("%02d", preHours / 60))
|
||||
.replace("%MINUTES%", String.format("%02d", minutes))
|
||||
.replace("%SECONDS%", String.format("%02d", seconds));
|
||||
}
|
||||
|
||||
public void startMaintenanceRunnable(final long duration, final TimeUnit unit, final boolean enable) {
|
||||
runnable = new MaintenanceRunnable(this, settings, (int) unit.toSeconds(duration), enable);
|
||||
// Save the endtimer to be able to continue it after a server stop
|
||||
if (settings.isSaveEndtimerOnStop() && !runnable.shouldEnable()) {
|
||||
settings.setSavedEndtimer(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(runnable.getSecondsLeft()));
|
||||
}
|
||||
}
|
||||
|
||||
public void scheduleMaintenanceRunnable(final long duration, final int maintenanceDuration, final TimeUnit unit) {
|
||||
runnable = new MaintenanceScheduleRunnable(this, settings, (int) unit.toSeconds(duration), (int) unit.toSeconds(maintenanceDuration));
|
||||
}
|
||||
|
||||
public boolean updateAvailable() {
|
||||
try {
|
||||
checkNewestVersion();
|
||||
return version.compareTo(newestVersion) == -1;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void continueLastEndtimer() {
|
||||
if (!settings.isSaveEndtimerOnStop()) return;
|
||||
if (settings.getSavedEndtimer() == 0) return;
|
||||
|
||||
final long current = System.currentTimeMillis();
|
||||
getLogger().info("Found interrupted endtimer from last uptime...");
|
||||
if (!isMaintenance()) {
|
||||
getLogger().info("Maintenance has already been disabled, thus the timer has been cancelled.");
|
||||
settings.setSavedEndtimer(0);
|
||||
} else if (settings.getSavedEndtimer() < current) {
|
||||
getLogger().info("The endtimer has already expired, maintenance has been disabled.");
|
||||
setMaintenance(false);
|
||||
settings.setSavedEndtimer(0);
|
||||
} else {
|
||||
startMaintenanceRunnable(settings.getSavedEndtimer() - current, TimeUnit.MILLISECONDS, false);
|
||||
getLogger().info("The timer has been continued - maintenance will be disabled in: " + getTimerMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected void sendEnableMessage() {
|
||||
if (!settings.hasUpdateChecks()) return;
|
||||
async(() -> {
|
||||
try {
|
||||
checkNewestVersion();
|
||||
} catch (final Exception e) {
|
||||
getLogger().warning("An error occured during update checking!");
|
||||
return;
|
||||
}
|
||||
|
||||
final int compare = version.compareTo(newestVersion);
|
||||
if (compare == -1) {
|
||||
getLogger().info("§cNewest version available: §aVersion " + newestVersion + "§c, you're on §a" + version);
|
||||
} else if (compare == 1) {
|
||||
if (version.getTag().equalsIgnoreCase("snapshot")) {
|
||||
getLogger().info("§cYou're running a development version, please report bugs on the Discord server (https://discord.gg/vGCUzHq) or the GitHub issue tracker (https://github.com/KennyTV/Maintenance/issues)");
|
||||
} else {
|
||||
getLogger().info("§cYou're running a version, that doesn't exist! §cN§ai§dc§ee§5!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean installUpdate() {
|
||||
// Ore sad :(
|
||||
Preconditions.checkArgument(serverType != ServerType.SPONGE);
|
||||
try {
|
||||
final String fileSuffix = serverType == ServerType.VELOCITY ? "Velocity" : "";
|
||||
final URLConnection conn = new URL("https://github.com/KennyTV/Maintenance/releases/download/" + newestVersion + "/Maintenance" + fileSuffix + ".jar").openConnection();
|
||||
writeFile(new BufferedInputStream(conn.getInputStream()), new BufferedOutputStream(new FileOutputStream(getPluginFolder() + "Maintenance.tmp")));
|
||||
final File file = new File(getPluginFolder() + "Maintenance.tmp");
|
||||
final long newlength = file.length();
|
||||
if (newlength < 10000) {
|
||||
file.delete();
|
||||
return false;
|
||||
}
|
||||
|
||||
writeFile(new FileInputStream(file), new BufferedOutputStream(new FileOutputStream(getPluginFile())));
|
||||
file.delete();
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void writeFile(final InputStream is, final OutputStream os) throws IOException {
|
||||
final byte[] chunk = new byte[1024];
|
||||
int chunkSize;
|
||||
while ((chunkSize = is.read(chunk)) != -1) {
|
||||
os.write(chunk, 0, chunkSize);
|
||||
}
|
||||
is.close();
|
||||
os.close();
|
||||
}
|
||||
|
||||
private void checkNewestVersion() throws Exception {
|
||||
final HttpURLConnection c = (HttpURLConnection) new URL("https://api.spigotmc.org/legacy/update.php?resource=40699").openConnection();
|
||||
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(c.getInputStream()))) {
|
||||
final String newVersionString = reader.readLine();
|
||||
final Version newVersion = new Version(newVersionString);
|
||||
if (!newVersion.equals(version)) {
|
||||
newestVersion = newVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String pasteDump() {
|
||||
final MaintenanceDump dump = new MaintenanceDump(this, settings);
|
||||
try {
|
||||
final HttpURLConnection connection = (HttpURLConnection) new URL("https://hastebin.com/documents").openConnection();
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("User-Agent", "Maintenance/" + getVersion());
|
||||
connection.setRequestProperty("Content-Type", "text/plain");
|
||||
|
||||
final GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
final OutputStream out = connection.getOutputStream();
|
||||
out.write(gsonBuilder.disableHtmlEscaping().setPrettyPrinting().create().toJson(dump).getBytes(StandardCharsets.UTF_8));
|
||||
out.close();
|
||||
|
||||
if (connection.getResponseCode() == 503) {
|
||||
getLogger().warning("Could not paste dump, hastebin.com down?");
|
||||
return null;
|
||||
}
|
||||
|
||||
final InputStream in = connection.getInputStream();
|
||||
final String output = CharStreams.toString(new InputStreamReader(in));
|
||||
in.close();
|
||||
|
||||
final JsonObject jsonOutput = gsonBuilder.create().fromJson(output, JsonObject.class);
|
||||
if (!jsonOutput.has("key")) {
|
||||
getLogger().log(Level.WARNING, "Could not paste dump, there was no key returned :(");
|
||||
return null;
|
||||
}
|
||||
|
||||
return jsonOutput.get("key").getAsString();
|
||||
} catch (final IOException e) {
|
||||
getLogger().log(Level.WARNING, "Could not paste dump :(");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void loadMaintenanceIcon() {
|
||||
final File file = new File(getDataFolder(), "maintenance-icon.png");
|
||||
if (!file.exists()) {
|
||||
getLogger().warning("Could not find a 'maintenance-icon.png' file - did you create one in the plugin's folder?");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
loadIcon(file);
|
||||
} catch (final Exception e) {
|
||||
getLogger().log(Level.WARNING, "Could not load the 'maintenance-icon.png' file!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void cancelTask() {
|
||||
if (settings.isSaveEndtimerOnStop() && !runnable.shouldEnable()) {
|
||||
settings.setSavedEndtimer(0);
|
||||
}
|
||||
|
||||
runnable.getTask().cancel();
|
||||
runnable = null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public UUID checkUUID(final SenderInfo sender, final String s) {
|
||||
final UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(s);
|
||||
} catch (final Exception e) {
|
||||
sender.sendMessage(settings.getMessage("invalidUuid"));
|
||||
return null;
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String[] removeArrayIndex(final String[] args, final int index) {
|
||||
final List<String> argsList = Lists.newArrayList(args);
|
||||
argsList.remove(index);
|
||||
return argsList.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public boolean isNumeric(final String string) {
|
||||
return string.matches("[0-9]+");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMaintenance() {
|
||||
return settings.isMaintenance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTaskRunning() {
|
||||
return runnable != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventManager getEventManager() {
|
||||
return eventManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return version.toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<String> getMaintenanceServersDump() {
|
||||
return isMaintenance() ? Arrays.asList("global") : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDebug(final boolean debug) {
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
public int getSaltLevel() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
public Version getNewestVersion() {
|
||||
return newestVersion;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #isTaskRunning()
|
||||
*/
|
||||
@Nullable
|
||||
public MaintenanceRunnable getRunnable() {
|
||||
return runnable;
|
||||
}
|
||||
|
||||
public MaintenanceCommand getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public ServerType getServerType() {
|
||||
return serverType;
|
||||
}
|
||||
|
||||
protected String getPluginFolder() {
|
||||
return "plugins/";
|
||||
}
|
||||
|
||||
public abstract void async(Runnable runnable);
|
||||
|
||||
public abstract void broadcast(String message);
|
||||
|
||||
public abstract void sendUpdateNotification(SenderInfo sender);
|
||||
|
||||
public abstract Task startMaintenanceRunnable(Runnable runnable);
|
||||
|
||||
@Nullable
|
||||
public abstract SenderInfo getOfflinePlayer(String name);
|
||||
|
||||
@Nullable
|
||||
public abstract SenderInfo getOfflinePlayer(UUID uuid);
|
||||
|
||||
public abstract File getDataFolder();
|
||||
|
||||
public abstract InputStream getResource(String name);
|
||||
|
||||
public abstract Logger getLogger();
|
||||
|
||||
public abstract String getServerVersion();
|
||||
|
||||
public abstract List<PluginDump> getPlugins();
|
||||
|
||||
protected abstract void loadIcon(File file) throws Exception;
|
||||
|
||||
protected abstract void kickPlayers();
|
||||
|
||||
protected abstract File getPluginFile();
|
||||
|
||||
protected abstract int getOnlinePlayers();
|
||||
|
||||
protected abstract int getMaxPlayers();
|
||||
}
|
||||
@@ -0,0 +1,497 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core;
|
||||
|
||||
import eu.kennytv.maintenance.api.ISettings;
|
||||
import eu.kennytv.maintenance.api.event.MaintenanceReloadedEvent;
|
||||
import eu.kennytv.maintenance.core.config.Config;
|
||||
import eu.kennytv.maintenance.core.config.ConfigSection;
|
||||
import eu.kennytv.maintenance.core.util.ServerType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Settings implements ISettings {
|
||||
private static final int CURRENT_CONFIG_VERSION = 4;
|
||||
private static final Random RANDOM = new Random();
|
||||
protected final MaintenancePlugin plugin;
|
||||
private final Map<UUID, String> whitelistedPlayers = new HashMap<>();
|
||||
private final String[] unsupportedFields;
|
||||
protected boolean maintenance;
|
||||
private Set<Integer> broadcastIntervals;
|
||||
private List<String> pingMessages;
|
||||
private List<String> timerSpecificPingMessages;
|
||||
private String playerCountMessage;
|
||||
private String playerCountHoverMessage;
|
||||
private String languageName;
|
||||
private boolean customPlayerCountMessage;
|
||||
private boolean customMaintenanceIcon;
|
||||
private boolean joinNotifications;
|
||||
private boolean updateChecks;
|
||||
private boolean saveEndtimerOnStop;
|
||||
private boolean kickOnlinePlayers;
|
||||
private boolean debug;
|
||||
private long savedEndtimer;
|
||||
|
||||
protected Config config;
|
||||
protected Config language;
|
||||
protected Config whitelist;
|
||||
|
||||
public Settings(final MaintenancePlugin plugin, final String... unsupportedFields) {
|
||||
this.plugin = plugin;
|
||||
this.unsupportedFields = unsupportedFields;
|
||||
if (!plugin.getDataFolder().exists()) {
|
||||
updatePluginDirectory();
|
||||
plugin.getDataFolder().mkdirs();
|
||||
}
|
||||
|
||||
createFile("config.yml");
|
||||
createFile("WhitelistedPlayers.yml");
|
||||
|
||||
reloadConfigs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfigs() {
|
||||
try {
|
||||
config = new Config(new File(plugin.getDataFolder(), "config.yml"), unsupportedFields);
|
||||
config.load();
|
||||
config.resetAwesomeHeader();
|
||||
whitelist = new Config(new File(plugin.getDataFolder(), "WhitelistedPlayers.yml"));
|
||||
whitelist.load();
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("Unable to load Maintenance files!", e);
|
||||
}
|
||||
|
||||
loadSettings();
|
||||
createLanguageFile();
|
||||
|
||||
try {
|
||||
language = new Config(new File(plugin.getDataFolder(), "language-" + languageName + ".yml"));
|
||||
language.load();
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("Unable to load Maintenance language file!", e);
|
||||
}
|
||||
|
||||
updateLanguageFile();
|
||||
|
||||
// Directly cache colored messages - this should not be saved!
|
||||
transformColoredMessages(language.getValues());
|
||||
|
||||
plugin.getEventManager().callEvent(new MaintenanceReloadedEvent());
|
||||
}
|
||||
|
||||
private void transformColoredMessages(final Map<String, Object> map) {
|
||||
for (final Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
if (entry.getValue() instanceof Map) {
|
||||
transformColoredMessages((Map<String, Object>) entry.getValue());
|
||||
} else if (entry.getValue() instanceof String) {
|
||||
entry.setValue(getColoredString(replaceNewlineVar((String) entry.getValue())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
try {
|
||||
config.save();
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Public, as it is used in the MaintenanceAddon
|
||||
public void createFile(final String name) {
|
||||
createFile(name, name);
|
||||
}
|
||||
|
||||
private void createFile(final String name, final String from) {
|
||||
final File file = new File(plugin.getDataFolder(), name);
|
||||
if (!file.exists()) {
|
||||
try (final InputStream in = plugin.getResource(from)) {
|
||||
Files.copy(in, file.toPath());
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("Unable to create " + name + " file for Maintenance!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void saveWhitelistedPlayers() {
|
||||
try {
|
||||
whitelist.save();
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void createLanguageFile() {
|
||||
final String fileName = "language-" + languageName + ".yml";
|
||||
final File file = new File(plugin.getDataFolder(), fileName);
|
||||
if (file.exists()) return;
|
||||
|
||||
try (final InputStream in = plugin.getResource(fileName)) {
|
||||
Files.copy(in, file.toPath());
|
||||
} catch (final IOException e) {
|
||||
plugin.getLogger().warning("Unable to provide language " + languageName);
|
||||
// Fall back to English language (if not already selected)
|
||||
if (!languageName.equals("en")) {
|
||||
plugin.getLogger().warning("Falling back to default language: en");
|
||||
languageName = "en";
|
||||
createLanguageFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadSettings() {
|
||||
updateConfig();
|
||||
|
||||
pingMessages = config.getStringList("pingmessages");
|
||||
if (config.getBoolean("enable-timerspecific-messages")) {
|
||||
timerSpecificPingMessages = config.getStringList("timerspecific-pingmessages");
|
||||
}
|
||||
maintenance = config.getBoolean("maintenance-enabled");
|
||||
customPlayerCountMessage = config.getBoolean("enable-playercountmessage");
|
||||
customMaintenanceIcon = config.getBoolean("custom-maintenance-icon");
|
||||
joinNotifications = config.getBoolean("send-join-notification");
|
||||
broadcastIntervals = new HashSet<>(config.getIntList("timer-broadcast-for-seconds"));
|
||||
if (plugin.getServerType() != ServerType.SPONGE) {
|
||||
playerCountMessage = getColoredString(getConfigString("playercountmessage"));
|
||||
}
|
||||
playerCountHoverMessage = replaceNewlineVar(getColoredString(getConfigString("playercounthovermessage")));
|
||||
languageName = getConfigString("language").toLowerCase();
|
||||
kickOnlinePlayers = config.getBoolean("kick-online-players", true);
|
||||
updateChecks = config.getBoolean("update-checks", true);
|
||||
debug = config.getBoolean("debug");
|
||||
|
||||
final ConfigSection section = config.getSection("continue-endtimer-after-restart");
|
||||
saveEndtimerOnStop = section.getBoolean("enabled");
|
||||
savedEndtimer = section.getLong("end");
|
||||
|
||||
if (customMaintenanceIcon) {
|
||||
plugin.loadMaintenanceIcon();
|
||||
}
|
||||
|
||||
whitelistedPlayers.clear();
|
||||
for (final Map.Entry<String, Object> entry : whitelist.getValues().entrySet()) {
|
||||
try {
|
||||
whitelistedPlayers.put(UUID.fromString(entry.getKey()), (String) entry.getValue());
|
||||
} catch (final Exception e) {
|
||||
plugin.getLogger().warning("invalid WhitelistedPlayers entry: " + entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
loadExtraSettings();
|
||||
}
|
||||
|
||||
private void updatePluginDirectory() {
|
||||
// All plugin identifiers were changed to 'Maintenance' ('maintenance' for Sponge and Velocity) in 3.0.5
|
||||
// Don't worry, this is only checked if no plugin folder is found
|
||||
String oldDirName = "Maintenance" + plugin.getServerType();
|
||||
if (plugin.getServerType() == ServerType.SPONGE || plugin.getServerType() == ServerType.VELOCITY) {
|
||||
oldDirName = oldDirName.toLowerCase();
|
||||
}
|
||||
|
||||
final File oldDir = new File(plugin.getDataFolder().getParentFile(), oldDirName);
|
||||
if (!oldDir.exists()) return;
|
||||
|
||||
try {
|
||||
Files.move(oldDir.toPath(), plugin.getDataFolder().toPath());
|
||||
plugin.getLogger().info("Moved old " + oldDirName + " to new " + plugin.getDataFolder().getName() + " directory!");
|
||||
} catch (final IOException e) {
|
||||
plugin.getLogger().severe("Error while copying " + oldDirName + " to new " + plugin.getDataFolder().getName() + " directory!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConfig() {
|
||||
boolean changed = false;
|
||||
|
||||
// Update config to latest version (config version included since 3.0.1)
|
||||
if (config.getInt("config-version") != CURRENT_CONFIG_VERSION) {
|
||||
plugin.getLogger().info("Updating config to latest version...");
|
||||
createFile("config-new.yml", "config.yml");
|
||||
final File file = new File(plugin.getDataFolder(), "config-new.yml");
|
||||
final Config tempConfig = new Config(file, unsupportedFields);
|
||||
try {
|
||||
tempConfig.load();
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
config.addMissingFields(tempConfig.getValues(), tempConfig.getComments());
|
||||
config.set("config-version", CURRENT_CONFIG_VERSION);
|
||||
|
||||
file.delete();
|
||||
tempConfig.clear();
|
||||
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
saveConfig();
|
||||
plugin.getLogger().info("Done! Updated config!");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLanguageFile() {
|
||||
final String filePrefix = "language-" + languageName;
|
||||
try {
|
||||
createFile(filePrefix + "-new.yml", filePrefix + ".yml");
|
||||
} catch (final NullPointerException e) {
|
||||
plugin.getLogger().info("Not checking for updated language strings, since there is no " + filePrefix + ".yml in the resource files (if your file is self translated and up to date, you can ignore this).");
|
||||
return;
|
||||
} catch (final Exception e) {
|
||||
plugin.getLogger().warning("Couldn't update language file, as the " + filePrefix + ".yml could not be loaded from the resource files!");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
final File file = new File(plugin.getDataFolder(), filePrefix + "-new.yml");
|
||||
final Config tempConfig = new Config(file);
|
||||
try {
|
||||
tempConfig.load();
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean updated = language.addMissingFields(tempConfig.getValues(), tempConfig.getComments());
|
||||
tempConfig.clear();
|
||||
file.delete();
|
||||
if (updated) {
|
||||
try {
|
||||
language.save();
|
||||
plugin.getLogger().info("Updated language file!");
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final String ALL_CODES = "0123456789AaBbCcDdEeFfKkLlMmNnOoRr";
|
||||
|
||||
public String getColoredString(final String s) {
|
||||
// Method taken from Bungee
|
||||
final char[] b = s.toCharArray();
|
||||
for (int i = 0; i < b.length - 1; i++) {
|
||||
if (b[i] == '&' && ALL_CODES.indexOf(b[i + 1]) > -1) {
|
||||
b[i] = '§';
|
||||
b[i + 1] = Character.toLowerCase(b[i + 1]);
|
||||
}
|
||||
}
|
||||
return new String(b);
|
||||
}
|
||||
|
||||
public String getConfigString(final String path) {
|
||||
final String s = config.getString(path);
|
||||
if (s == null) {
|
||||
plugin.getLogger().warning("The config is missing the following string: " + path);
|
||||
return "null";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public String getMessage(final String path) {
|
||||
return getMessage(path, "null");
|
||||
}
|
||||
|
||||
public String getMessage(final String path, final String def) {
|
||||
final String s = language.getString(path);
|
||||
if (s == null) {
|
||||
plugin.getLogger().warning("The language file is missing the following string: " + path);
|
||||
return def;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public String getRandomPingMessage() {
|
||||
if (plugin.isTaskRunning() && !plugin.getRunnable().shouldEnable()
|
||||
&& hasTimerSpecificPingMessages() && !timerSpecificPingMessages.isEmpty()) {
|
||||
return getPingMessage(timerSpecificPingMessages);
|
||||
}
|
||||
return pingMessages.isEmpty() ? "" : getPingMessage(pingMessages);
|
||||
}
|
||||
|
||||
private String getPingMessage(final List<String> list) {
|
||||
final String s = list.size() == 1 ? list.get(0) : list.get(RANDOM.nextInt(list.size()));
|
||||
return getColoredString(replaceNewlineVar(plugin.replacePingVariables(s)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeWhitelistedPlayer(final UUID uuid) {
|
||||
if (!whitelistedPlayers.containsKey(uuid)) return false;
|
||||
whitelistedPlayers.remove(uuid);
|
||||
whitelist.remove(uuid.toString());
|
||||
saveWhitelistedPlayers();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean removeWhitelistedPlayer(final String name) {
|
||||
UUID uuid = null;
|
||||
for (final Map.Entry<UUID, String> e : whitelistedPlayers.entrySet()) {
|
||||
if (e.getValue().equalsIgnoreCase(name)) {
|
||||
uuid = e.getKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (uuid == null) return false;
|
||||
|
||||
whitelistedPlayers.remove(uuid);
|
||||
whitelist.remove(uuid.toString());
|
||||
saveWhitelistedPlayers();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addWhitelistedPlayer(final UUID uuid, final String name) {
|
||||
final boolean contains = !whitelistedPlayers.containsKey(uuid);
|
||||
whitelistedPlayers.put(uuid, name);
|
||||
whitelist.set(uuid.toString(), name);
|
||||
saveWhitelistedPlayers();
|
||||
return contains;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID, String> getWhitelistedPlayers() {
|
||||
return whitelistedPlayers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWhitelisted(final UUID uuid) {
|
||||
return whitelistedPlayers.containsKey(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMaintenance() {
|
||||
return maintenance;
|
||||
}
|
||||
|
||||
public void setMaintenance(final boolean maintenance) {
|
||||
this.maintenance = maintenance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJoinNotifications() {
|
||||
return joinNotifications;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomIcon() {
|
||||
return customMaintenanceIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean debugEnabled() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public boolean hasUpdateChecks() {
|
||||
return updateChecks;
|
||||
}
|
||||
|
||||
public boolean isSaveEndtimerOnStop() {
|
||||
return saveEndtimerOnStop;
|
||||
}
|
||||
|
||||
public boolean hasTimerSpecificPingMessages() {
|
||||
return timerSpecificPingMessages != null;
|
||||
}
|
||||
|
||||
public boolean isKickOnlinePlayers() {
|
||||
return kickOnlinePlayers;
|
||||
}
|
||||
|
||||
public long getSavedEndtimer() {
|
||||
return savedEndtimer;
|
||||
}
|
||||
|
||||
public void setSavedEndtimer(final long millis) {
|
||||
if (savedEndtimer == millis) return;
|
||||
this.savedEndtimer = millis;
|
||||
config.getSection("continue-endtimer-after-restart").set("end", millis);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
// The ping messages still contain the %NEWLINE% (if they have 2 lines)
|
||||
public List<String> getPingMessages() {
|
||||
return pingMessages;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<String> getTimerSpecificPingMessages() {
|
||||
return timerSpecificPingMessages;
|
||||
}
|
||||
|
||||
public Set<Integer> getBroadcastIntervals() {
|
||||
return broadcastIntervals;
|
||||
}
|
||||
|
||||
public String getPlayerCountMessage() {
|
||||
return plugin.replacePingVariables(playerCountMessage);
|
||||
}
|
||||
|
||||
public String getPlayerCountHoverMessage() {
|
||||
return plugin.replacePingVariables(playerCountHoverMessage);
|
||||
}
|
||||
|
||||
public String getKickMessage() {
|
||||
return plugin.replacePingVariables(getMessage("kickmessage"));
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return languageName;
|
||||
}
|
||||
|
||||
public boolean hasCustomPlayerCountMessage() {
|
||||
return customPlayerCountMessage;
|
||||
}
|
||||
|
||||
/*
|
||||
* Note on why this even exists: Yaml will force save all strings containing line breaks '\n' in this rather chunky format:
|
||||
* key: |-
|
||||
* First line text
|
||||
* Second line text.
|
||||
* ...
|
||||
*
|
||||
* This also happens to string lists, making those practically unreadable (in partciular the motd list), as well as confusing for most users in general.
|
||||
* Because of this, I replace %NEWLINE% manually, to spare users from these ugly breaks.
|
||||
*/
|
||||
protected String replaceNewlineVar(final String s) {
|
||||
return s.replace("%NEWLINE%", "\n");
|
||||
}
|
||||
|
||||
protected void loadExtraSettings() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.command;
|
||||
|
||||
import eu.kennytv.maintenance.core.MaintenancePlugin;
|
||||
import eu.kennytv.maintenance.core.Settings;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CommandInfo {
|
||||
protected final MaintenancePlugin plugin;
|
||||
private final String helpMessageKey;
|
||||
private final String permission;
|
||||
|
||||
protected CommandInfo(final MaintenancePlugin plugin, @Nullable final String permission) {
|
||||
this.plugin = plugin;
|
||||
this.permission = permission;
|
||||
// Just take the class name as the language key
|
||||
this.helpMessageKey = "help" + getClass().getSimpleName().replace("Command", "");
|
||||
}
|
||||
|
||||
public boolean hasPermission(final SenderInfo sender) {
|
||||
return sender.hasMaintenancePermission(permission);
|
||||
}
|
||||
|
||||
public String getHelpMessage() {
|
||||
return getMessage(helpMessageKey);
|
||||
}
|
||||
|
||||
public List<String> getTabCompletion(final SenderInfo sender, final String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public abstract void execute(SenderInfo sender, String[] args);
|
||||
|
||||
protected boolean checkPermission(final SenderInfo sender, final String permission) {
|
||||
if (!sender.hasMaintenancePermission(permission)) {
|
||||
sender.sendMessage(getMessage("noPermission"));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean checkArgs(final SenderInfo sender, final String[] args, final int length) {
|
||||
if (args.length != length) {
|
||||
sender.sendMessage(getHelpMessage());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected String getMessage(final String s) {
|
||||
return plugin.getSettings().getMessage(s);
|
||||
}
|
||||
|
||||
protected Settings getSettings() {
|
||||
return plugin.getSettings();
|
||||
}
|
||||
}
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.command;
|
||||
|
||||
import eu.kennytv.maintenance.core.MaintenancePlugin;
|
||||
import eu.kennytv.maintenance.core.Settings;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.AbortTimerCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.DebugCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.DumpCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.EndtimerCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.HelpCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.MotdCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.ReloadCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.RemoveMotdCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.ScheduleTimerCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.SetMotdCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.StarttimerCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.ToggleCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.UpdateCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.WhitelistAddCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.WhitelistCommand;
|
||||
import eu.kennytv.maintenance.core.command.subcommand.WhitelistRemoveCommand;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
import eu.kennytv.maintenance.core.util.ServerType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class MaintenanceCommand {
|
||||
protected final MaintenancePlugin plugin;
|
||||
protected final Settings settings;
|
||||
private final Map<String, CommandInfo> commandExecutors = new LinkedHashMap<>();
|
||||
private final List<CommandInfo> commands = new ArrayList<>();
|
||||
private final HelpCommand help;
|
||||
|
||||
protected MaintenanceCommand(final MaintenancePlugin plugin, final Settings settings) {
|
||||
this.plugin = plugin;
|
||||
this.settings = settings;
|
||||
help = new HelpCommand(plugin);
|
||||
}
|
||||
|
||||
protected void registerCommands() {
|
||||
add(help, "help");
|
||||
add(new ReloadCommand(plugin), "reload");
|
||||
|
||||
addToggleAndTimerCommands();
|
||||
|
||||
add(new WhitelistCommand(plugin), "whitelist");
|
||||
add(new WhitelistAddCommand(plugin), "add");
|
||||
add(new WhitelistRemoveCommand(plugin), "remove");
|
||||
|
||||
add(new SetMotdCommand(plugin), "setmotd");
|
||||
add(new RemoveMotdCommand(plugin), "removemotd");
|
||||
add(new MotdCommand(plugin), "motd");
|
||||
|
||||
add(new UpdateCommand(plugin), "update", "forceupdate");
|
||||
add(new DumpCommand(plugin), "dump");
|
||||
add(new DebugCommand(plugin), "debug");
|
||||
}
|
||||
|
||||
protected void add(final CommandInfo command, final String... aliases) {
|
||||
commands.add(command);
|
||||
for (final String alias : aliases) {
|
||||
commandExecutors.put(alias, command);
|
||||
}
|
||||
}
|
||||
|
||||
public void execute(final SenderInfo sender, final String[] args) {
|
||||
if (!sender.hasMaintenancePermission("command")) {
|
||||
sender.sendMessage(settings.getMessage("noPermission"));
|
||||
return;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
help.sendUsage(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
final CommandInfo command = commandExecutors.get(args[0].toLowerCase());
|
||||
if (command == null) {
|
||||
help.sendUsage(sender);
|
||||
return;
|
||||
}
|
||||
if (!command.hasPermission(sender)) {
|
||||
sender.sendMessage(settings.getMessage("noPermission"));
|
||||
return;
|
||||
}
|
||||
|
||||
command.execute(sender, args);
|
||||
}
|
||||
|
||||
public List<String> getSuggestions(final SenderInfo sender, final String[] args) {
|
||||
if (!sender.hasMaintenancePermission("command") || args.length == 0) return Collections.emptyList();
|
||||
final String s = args[0].toLowerCase();
|
||||
if (args.length == 1) {
|
||||
final List<String> list = new ArrayList<>();
|
||||
for (final Map.Entry<String, CommandInfo> entry : commandExecutors.entrySet()) {
|
||||
final String command = entry.getKey();
|
||||
if (command.startsWith(s) && entry.getValue().hasPermission(sender)) {
|
||||
list.add(command);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
final CommandInfo info = commandExecutors.get(args[0]);
|
||||
return info != null && info.hasPermission(sender) ? info.getTabCompletion(sender, args) : Collections.emptyList();
|
||||
}
|
||||
|
||||
public boolean checkTimerArgs(final SenderInfo sender, final String time, final boolean taskCheck) {
|
||||
if (!plugin.isNumeric(time)) return true;
|
||||
if (taskCheck) {
|
||||
if (plugin.isTaskRunning()) {
|
||||
sender.sendMessage(settings.getMessage("timerAlreadyRunning"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
final int minutes = Integer.parseInt(time);
|
||||
if (minutes > 40320) {
|
||||
sender.sendMessage(settings.getMessage("timerTooLong"));
|
||||
return true;
|
||||
}
|
||||
if (minutes < 1) {
|
||||
sender.sendMessage("§8§o[KennyTV whispers to you] §7§oThink about running a timer for a negative amount of minutes. Doesn't work §lthat §7§owell.");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean checkTimerArgs(final SenderInfo sender, final String time) {
|
||||
return checkTimerArgs(sender, time, true);
|
||||
}
|
||||
|
||||
protected void addToggleAndTimerCommands() {
|
||||
add(new ToggleCommand(plugin), "on", "off");
|
||||
|
||||
add(new StarttimerCommand(plugin), "starttimer", "start");
|
||||
add(new EndtimerCommand(plugin), "endtimer", "end");
|
||||
add(new ScheduleTimerCommand(plugin), "scheduletimer", "schedule");
|
||||
add(new AbortTimerCommand(plugin), "aborttimer", "abort");
|
||||
}
|
||||
|
||||
public void checkForUpdate(final SenderInfo sender) {
|
||||
if (plugin.updateAvailable()) {
|
||||
sender.sendMessage(plugin.getPrefix() + "§cNewest version available: §aVersion " + plugin.getNewestVersion() + "§c, you're on §a" + plugin.getVersion());
|
||||
// Ore sad :(
|
||||
if (plugin.getServerType() != ServerType.SPONGE) {
|
||||
sender.sendMessage(plugin.getPrefix() + "§c§lWARNING: §cYou will have to restart the server to prevent further issues and to complete the update! If you can't do that, don't update!");
|
||||
sendUpdateMessage(sender);
|
||||
} else {
|
||||
sender.sendMessage(plugin.getPrefix() + "§aDownload the latest version on the Ore plugin page: §bhttps://ore.spongepowered.org/KennyTV/Maintenance");
|
||||
}
|
||||
} else
|
||||
sender.sendMessage(plugin.getPrefix() + "§aYou already have the latest version of the plugin!");
|
||||
}
|
||||
|
||||
protected void sendUpdateMessage(final SenderInfo sender) {
|
||||
sender.sendMessage(plugin.getPrefix() + "§eUse §c§l/maintenance forceupdate §eto update!");
|
||||
}
|
||||
|
||||
public List<String> getServersCompletion(final String s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> getMaintenanceServersCompletion(final String s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> getPlayersCompletion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract void sendDumpMessage(final SenderInfo sender, final String url);
|
||||
|
||||
public List<CommandInfo> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.command.subcommand;
|
||||
|
||||
import eu.kennytv.maintenance.core.MaintenancePlugin;
|
||||
import eu.kennytv.maintenance.core.command.CommandInfo;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
|
||||
public final class AbortTimerCommand extends CommandInfo {
|
||||
|
||||
public AbortTimerCommand(final MaintenancePlugin plugin) {
|
||||
super(plugin, "timer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final SenderInfo sender, final String[] args) {
|
||||
if (args.length != 1) {
|
||||
sender.sendMessage(getHelpMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.isTaskRunning()) {
|
||||
sender.sendMessage(getMessage("timerNotRunning"));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.cancelTask();
|
||||
sender.sendMessage(getMessage("timerCancelled"));
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Maintenance - https://git.io/maintenancemode
|
||||
* Copyright (C) 2018-2021 KennyTV (https://github.com/KennyTV)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package eu.kennytv.maintenance.core.command.subcommand;
|
||||
|
||||
import eu.kennytv.maintenance.core.MaintenancePlugin;
|
||||
import eu.kennytv.maintenance.core.command.CommandInfo;
|
||||
import eu.kennytv.maintenance.core.util.SenderInfo;
|
||||
|
||||
public final class DebugCommand extends CommandInfo {
|
||||
|
||||
public DebugCommand(final MaintenancePlugin plugin) {
|
||||
super(plugin, "debug");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final SenderInfo sender, final String[] args) {
|
||||
if (checkArgs(sender, args, 1)) return;
|
||||
|
||||
//TODO put this and the help message into language files
|
||||
plugin.setDebug(!plugin.isDebug());
|
||||
sender.sendMessage("Debug mode is now " + (plugin.isDebug() ? "enabled" : "disabled"));
|
||||
}
|
||||
}
|
||||
Loaded 100 of 176 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user