Compare commits

...
52 Commits
Author SHA1 Message Date
KennyTV 77e1444dba 3.0.2 Release 2019-05-17 09:35:34 +02:00
KennyTV 915b43d897 👀 2019-05-17 09:35:14 +02:00
KennyTV adc06e3486 Update changelog 2019-05-17 09:31:17 +02:00
KennyTV cc7f5c2d11 Version increase to 3.0.2 2019-05-17 09:25:57 +02:00
KennyTV 0bb54ffc5d Finish timerspecific pingmessages 2019-05-17 09:21:35 +02:00
KennyTV 15ee2e6074 Update changelog, resort some config entries 2019-05-14 13:48:28 +02:00
KennyTV 89abab36f8 Timerspecific pingmessages 2019-05-14 09:07:23 +02:00
KennyTV e0bb1336b0 ‍Make setmotd command also set timerspecific messages 2019-05-13 22:53:04 +02:00
KennyTV 888ffd301a 🤦‍ 2019-05-13 15:30:40 +02:00
KennyTV 3a55dd3280 Make motd command display timerspecific ones 2019-05-13 15:30:00 +02:00
KennyTV 61c47ba2fa WIP: Timerspecific pingmessages 2019-05-13 11:02:13 +02:00
KennyTV b97e69a71f Make dumps prettier 2019-05-09 22:30:18 +02:00
KennyTV 75c940d089 Fix Sponge 8.0.0 compatibility 2019-05-09 21:53:30 +02:00
KennyTV 849fa2a720 Update to latest Velocity text api 2019-05-07 09:09:58 +02:00
KennyTV 7e249faa99 Update README.md 2019-04-27 15:34:07 +02:00
KennyTV c8272b39d5 Fix Velocity autoupdater 2019-04-17 15:38:51 +02:00
KennyTV b3c561ae26 Version increase to 3.0.2-SNAPSHOT 2019-04-17 15:38:33 +02:00
KennyTV af24c5a331 Update api, changelog and readme for latest release 2019-04-17 15:24:51 +02:00
KennyTV 4cc162f00d Merge pull request #29 from KennyTV/dev
3.0.1 Release
2019-04-17 14:38:55 +02:00
KennyTV 02610fd904 Version increase to 3.0.1 2019-04-17 14:36:56 +02:00
KennyTV bccd1bb936 Remove interface check 2019-04-17 14:36:47 +02:00
KennyTV c08dd5d430 Set group id to eu.kennytv.maintenance 2019-04-15 10:54:16 +02:00
KennyTV 1104a50882 Fix another potential error on startup 2019-04-14 13:07:01 +02:00
KennyTV 56898d7b40 Database sync fixes, adjustments to endtimer saving 2019-04-05 14:05:01 +02:00
KennyTV 4be31a6dd4 Update README 2019-04-05 14:04:45 +02:00
KennyTV 190a063d49 Add config updater + endtimer saving after restart 2019-04-03 14:22:06 +02:00
KennyTV 6e4591d45b Fix error printing in some cases, close hikari source on disable(/reload) 2019-04-03 11:15:30 +02:00
KennyTV 86c556e841 Hackily fix slf4j relocation and shorten jar sizes 2019-03-19 22:35:13 +01:00
KennyTV 404e14ee94 Revert "Only compile SnakeYaml in universal and Velocity file"
This reverts commit b8c0e3a7
2019-03-19 18:07:18 +01:00
KennyTV b8c0e3a799 Only compile SnakeYaml in universal and Velocity file 2019-03-19 18:04:05 +01:00
KennyTV 10d798acd4 Make ServerInfoPacketListener extend PacketAdapter instead of creating anonymous class 2019-03-19 17:04:08 +01:00
KennyTV be057f4b3b Don't register listener twice 2019-03-13 17:17:31 +01:00
KennyTV eea7a595c9 Add Ore url to plugin info 2019-03-13 10:21:29 +01:00
KennyTV bf4bf79b23 Readd update checking on Sponge, still disallow execution of update 2019-03-13 10:04:16 +01:00
KennyTV 686535228e Typo 👀 2019-03-11 13:24:33 +01:00
KennyTV 8b645b6f79 Fix Paper pinglistener and remove old code 2019-03-11 13:22:15 +01:00
KennyTV 4d97293a8c Rename dump variable 2019-03-11 13:00:43 +01:00
KennyTV c746a83f5f Use PaperServerListPingEvent if applicable 2019-03-11 12:48:10 +01:00
KennyTV eb7e6e3f0b Fix exception on ping that does not come from status packet 2019-03-10 19:08:08 +01:00
KennyTV f5ce41853f nooooo 2019-03-08 21:29:28 +01:00
KennyTV e67cde591c Try to please the beautiful people over at Ore (Sponge), attempt no 2 2019-03-08 21:28:35 +01:00
KennyTV 39682635c6 Try to please the beautiful people over at Ore (Sponge) 2019-03-08 21:18:21 +01:00
KennyTV efee532742 Make endtimer display format adjustable 2019-03-05 16:55:56 +01:00
KennyTV 0aee3a8fd6 Remove bStats from Sponge module
(Their beautiful repo is down and I don't really need it on Sponge anyways 🤔)
2019-02-21 17:22:29 +01:00
KennyTV f79b6caccb Minor maintenance event changes 2019-02-21 16:43:13 +01:00
KennyTV 73fd80b456 Some language changes 2019-02-21 15:35:52 +01:00
KennyTV ad1a7eb420 Make createFile method public 2019-02-19 17:30:58 +01:00
KennyTV bfa9b52497 Add api method to get a list of maintenance servers 2019-02-19 13:25:13 +01:00
KennyTV ff4b5b0d2e Custom maintenance events 2019-02-19 13:08:38 +01:00
KennyTV b8e73062fa Some language changes 2019-02-19 11:28:24 +01:00
KennyTV 863a9b3beb Version increase to 3.0.1-SNAPSHOT 2019-02-19 00:16:24 +01:00
KennyTV fe64936ddf Sneak Spanish language in 👀 2019-02-17 10:16:36 +01:00
61 changed files with 1179 additions and 265 deletions

No files matched your search

+24
View File
@@ -1,6 +1,30 @@
# 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.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!
Binary file not shown.
+6 -4
View File
@@ -1,7 +1,8 @@
# Maintenance
[![Version](https://img.shields.io/github/release/KennyTV/Maintenance.svg)](https://github.com/KennyTV/Maintenance/releases)
[![Build Status](https://travis-ci.org/KennyTV/Maintenance.svg?branch=master)](https://travis-ci.org/KennyTV/Maintenance)
[![Discord](https://img.shields.io/badge/discord-online-green.svg)](https://discord.gg/vGCUzHq)
[![Discord](https://img.shields.io/discord/489135856284729384.svg?label=Discord&logo=discord&logoColor=fff)](https://discord.gg/vGCUzHq)
[![Twitter](https://img.shields.io/twitter/follow/KennyTVN.svg?label=Twitter)](https://twitter.com/KennyTVN)
Maintenance is probably the most customizable free maintenance plugin for your Minecraft server you can find. It runs on Bukkit/Spigot, BungeeCord, Sponge as well as Velocity.
@@ -14,6 +15,7 @@ Its features include:
* 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)
A full list of commands, permissions and configuration options can be found in the wiki listed below.
* [Wiki](https://github.com/KennyTV/Maintenance/wiki)
@@ -23,13 +25,13 @@ A full list of commands, permissions and configuration options can be found in t
* [Issue tracker/bug reports](https://github.com/KennyTV/Maintenance/issues)
* [Discord](https://discord.gg/vGCUzHq)
Other forums
Other forum threads
* [Spigot forums](https://www.spigotmc.org/resources/maintenance.40699/)
* [Sponge forums](https://forums.spongepowered.org/t/maintenance/27421)
* [Ore/Sponge Forums](https://ore.spongepowered.org/KennyTV/Maintenance)
* [Velocity forums](https://forums.velocitypowered.com/t/maintenance/129)
## 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).
## Licence
You may only copy the code 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)).
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)).
+2 -2
View File
@@ -4,9 +4,9 @@
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</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0</version>
<version>3.0.2</version>
</parent>
<artifactId>maintenance-api</artifactId>
@@ -18,6 +18,8 @@
package eu.kennytv.maintenance.api;
import eu.kennytv.maintenance.api.event.manager.IEventManager;
/**
* @author KennyTV
* @since 2.1
@@ -57,4 +59,11 @@ public interface IMaintenance {
* @return {@link ISettings} instance
*/
ISettings getSettings();
/**
* Returns the {@link IEventManager} instance to register listeners to maintenance events.
*
* @return {@link IEventManager} instance
*/
IEventManager getEventManager();
}
@@ -0,0 +1,42 @@
/*
* Maintenance - https://git.io/maintenancemode
* Copyright (C) 2018 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;
}
}
@@ -0,0 +1,36 @@
/*
* Maintenance - https://git.io/maintenancemode
* Copyright (C) 2018 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);
}
@@ -0,0 +1,34 @@
/*
* Maintenance - https://git.io/maintenancemode
* Copyright (C) 2018 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);
}
@@ -0,0 +1,28 @@
/*
* Maintenance - https://git.io/maintenancemode
* Copyright (C) 2018 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 {
}
@@ -0,0 +1,52 @@
/*
* Maintenance - https://git.io/maintenancemode
* Copyright (C) 2018 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;
}
/**
* @return wrapped server object for the proxied server
*/
public Server getServer() {
return server;
}
/**
* @return true if maintenance has been enabled on the server, false otherwise
*/
public boolean isMaintenance() {
return maintenance;
}
}
@@ -20,6 +20,8 @@ package eu.kennytv.maintenance.api.proxy;
import eu.kennytv.maintenance.api.IMaintenance;
import java.util.Set;
/**
* @author KennyTV
* @since 3.0
@@ -59,4 +61,9 @@ public interface IMaintenanceProxy extends IMaintenance {
* @return wrapped server object if present, else null
*/
Server getServer(String server);
/**
* @return immutable set with names of all proxied server that are currently under maintenance
*/
Set<String> getMaintenanceServers();
}
+36 -16
View File
@@ -4,9 +4,9 @@
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</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0</version>
<version>3.0.2</version>
</parent>
<artifactId>maintenance-build</artifactId>
@@ -15,28 +15,48 @@
<dependencies>
<!-- Also includes maintenance-core and maintenance-core-proxy modules -->
<dependency>
<groupId>eu.kennytv</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-bungee</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>eu.kennytv</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-spigot</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>eu.kennytv</groupId>
<artifactId>maintenance-sponge</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>eu.kennytv</groupId>
<artifactId>maintenance-velocity</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.1</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>
+42 -4
View File
@@ -4,9 +4,9 @@
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</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0</version>
<version>3.0.2</version>
</parent>
<artifactId>maintenance-bungee</artifactId>
@@ -14,16 +14,54 @@
<dependencies>
<dependency>
<groupId>eu.kennytv</groupId>
<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.25</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.13-SNAPSHOT</version>
<version>1.14-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.1</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>
@@ -25,13 +25,18 @@ import net.md_5.bungee.api.plugin.Plugin;
import java.io.File;
public final class MaintenanceBungeeBase extends Plugin implements IMaintenanceBase {
private IMaintenance maintenance;
private MaintenanceBungeePlugin maintenance;
@Override
public void onEnable() {
maintenance = new MaintenanceBungeePlugin(this);
}
@Override
public void onDisable() {
maintenance.disable();
}
@Override
public IMaintenance getApi() {
return maintenance;
@@ -84,6 +84,7 @@ public final class MaintenanceBungeePlugin extends MaintenanceProxyPlugin {
commandManager = new MaintenanceBungeeCommand(this, settingsProxy);
pm.registerCommand(plugin, new MaintenanceBungeeCommandBase(commandManager));
continueLastEndtimer();
new MetricsLite(plugin);
// ServerListPlus integration
@@ -140,7 +141,7 @@ public final class MaintenanceBungeePlugin extends MaintenanceProxyPlugin {
}
@Override
protected Task startMaintenanceRunnable(final Runnable runnable) {
public Task startMaintenanceRunnable(final Runnable runnable) {
return new BungeeTask(getProxy().getScheduler().schedule(plugin, runnable, 0, 1, TimeUnit.SECONDS).getId());
}
+10 -3
View File
@@ -4,9 +4,9 @@
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</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0</version>
<version>3.0.2</version>
</parent>
<artifactId>maintenance-core-proxy</artifactId>
@@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>eu.kennytv</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-core</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
@@ -24,6 +24,13 @@
<artifactId>HikariCP</artifactId>
<version>3.2.0</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>
@@ -18,6 +18,7 @@
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;
@@ -29,10 +30,7 @@ import eu.kennytv.maintenance.core.util.SenderInfo;
import eu.kennytv.maintenance.core.util.ServerType;
import eu.kennytv.maintenance.core.util.Task;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* @author KennyTV
@@ -46,14 +44,18 @@ public abstract class MaintenanceProxyPlugin extends MaintenancePlugin implement
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);
settingsProxy.setMaintenance(maintenance);
settingsProxy.getConfig().set("maintenance-enabled", maintenance);
settingsProxy.saveConfig();
serverActions(maintenance);
super.setMaintenance(maintenance);
}
@Override
@@ -73,7 +75,7 @@ public abstract class MaintenanceProxyPlugin extends MaintenancePlugin implement
}
public void serverActions(final Server server, final boolean maintenance) {
if (server instanceof DummyServer) return;
if (server == null || server instanceof DummyServer) return;
if (maintenance) {
final Server fallback = getServer(settingsProxy.getFallbackServer());
if (fallback == null) {
@@ -85,6 +87,7 @@ public abstract class MaintenanceProxyPlugin extends MaintenancePlugin implement
} else
server.broadcast(settingsProxy.getMessage("singleMaintenanceDeactivated").replace("%SERVER%", server.getName()));
cancelSingleTask(server);
eventManager.callEvent(new ServerMaintenanceChangedEvent(server, maintenance));
}
@Override
@@ -92,6 +95,11 @@ public abstract class MaintenanceProxyPlugin extends MaintenancePlugin implement
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)
@@ -100,12 +108,12 @@ public abstract class MaintenanceProxyPlugin extends MaintenancePlugin implement
public MaintenanceRunnableBase startSingleMaintenanceRunnable(final Server server, final int minutes, final boolean enable) {
final MaintenanceRunnableBase runnable = new SingleMaintenanceRunnable(this, settingsProxy, minutes, enable, server);
serverTasks.put(server.getName(), startMaintenanceRunnable(runnable));
serverTasks.put(server.getName(), runnable.getTask());
return runnable;
}
@Override
public List<String> getMaintenanceServers() {
public List<String> getMaintenanceServersDump() {
final List<String> list = new ArrayList<>();
if (isMaintenance()) list.add("global");
list.addAll(settingsProxy.getMaintenanceServers());
@@ -28,10 +28,8 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
public final class SettingsProxy extends Settings {
private final MaintenanceProxyPlugin plugin;
private Set<String> maintenanceServers;
private String fallbackServer;
@@ -47,11 +45,10 @@ public final class SettingsProxy extends Settings {
public SettingsProxy(final MaintenanceProxyPlugin plugin) {
super(plugin);
this.plugin = plugin;
}
private void setupMySQL() throws Exception {
super.plugin.getLogger().info("Trying to open database connection...");
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");
@@ -71,7 +68,7 @@ public final class SettingsProxy extends Settings {
mySQL.executeUpdate("CREATE TABLE IF NOT EXISTS " + serverTable + " (server VARCHAR(64) PRIMARY KEY)");
maintenanceQuery = "SELECT * FROM " + mySQLTable + " WHERE setting = ?";
serverQuery = "SELECT * FROM " + serverTable;
super.plugin.getLogger().info("Done!");
plugin.getLogger().info("Done!");
}
@Override
@@ -82,7 +79,8 @@ public final class SettingsProxy extends Settings {
setupMySQL();
} catch (final Exception e) {
mySQL = null;
super.plugin.getLogger().log(Level.WARNING, "Error while trying do open database connection!", e);
plugin.getLogger().warning("Error while trying do open database connection!");
e.printStackTrace();
}
}
@@ -107,8 +105,8 @@ public final class SettingsProxy extends Settings {
if (hasMySQL() && System.currentTimeMillis() - lastMySQLCheck > millisecondsToCheck) {
final boolean databaseValue = loadMaintenance();
if (databaseValue != maintenance) {
plugin.serverActions(maintenance);
maintenance = databaseValue;
plugin.serverActions(maintenance);
}
lastMySQLCheck = System.currentTimeMillis();
}
@@ -118,8 +116,18 @@ public final class SettingsProxy extends Settings {
public boolean isMaintenance(final Server server) {
if (hasMySQL() && System.currentTimeMillis() - lastServerCheck > millisecondsToCheck) {
final Set<String> databaseValue = loadMaintenanceServersFromSQL();
if (!databaseValue.equals(maintenanceServers)) {
plugin.serverActions(server, maintenance);
if (!maintenanceServers.equals(databaseValue)) {
final MaintenanceProxyPlugin plugin = (MaintenanceProxyPlugin) super.plugin;
// Enable maintenance on yet unlisted servers
databaseValue.forEach(s -> {
if (!maintenanceServers.contains(s))
plugin.serverActions(plugin.getServer(s), true);
});
// Disable maintenance on now unlisted servers
maintenanceServers.forEach(s -> {
if (!databaseValue.contains(s))
plugin.serverActions(plugin.getServer(s), false);
});
maintenanceServers = databaseValue;
}
lastServerCheck = System.currentTimeMillis();
@@ -188,6 +196,7 @@ public final class SettingsProxy extends Settings {
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");
@@ -206,4 +215,8 @@ public final class SettingsProxy extends Settings {
public String getFallbackServer() {
return fallbackServer;
}
MySQL getMySQL() {
return mySQL;
}
}
@@ -50,7 +50,7 @@ public final class SingleEndtimerCommand extends ProxyCommandInfo {
sender.sendMessage(getMessage("alreadyDisabled"));
return;
}
plugin.startMaintenanceRunnable(Integer.parseInt(args[1]), false);
plugin.startMaintenanceRunnableForMinutes(Integer.parseInt(args[1]), false);
sender.sendMessage(getMessage("endtimerStarted").replace("%TIME%", plugin.getRunnable().getTime()));
} else if (args.length == 3) {
if (checkPermission(sender, "singleserver.timer")) return;
@@ -51,7 +51,7 @@ public final class SingleStarttimerCommand extends ProxyCommandInfo {
return;
}
plugin.startMaintenanceRunnable(Integer.parseInt(args[1]), true);
plugin.startMaintenanceRunnableForMinutes(Integer.parseInt(args[1]), true);
sender.sendMessage(getMessage("starttimerStarted").replace("%TIME%", plugin.getRunnable().getTime()));
} else if (args.length == 3) {
if (checkPermission(sender, "singleserver.timer")) return;
@@ -65,4 +65,8 @@ public final class MySQL {
executeUpdate(query, res -> {
}, objects);
}
public void close() {
hikariDataSource.close();
}
}
@@ -27,8 +27,8 @@ import eu.kennytv.maintenance.core.runnable.MaintenanceRunnableBase;
public final class SingleMaintenanceRunnable extends MaintenanceRunnableBase {
private final Server server;
public SingleMaintenanceRunnable(final MaintenancePlugin plugin, final Settings settings, final int minutes, final boolean enable, final Server server) {
super(plugin, settings, minutes, enable);
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;
}
+4 -4
View File
@@ -4,9 +4,9 @@
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</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0</version>
<version>3.0.2</version>
</parent>
<artifactId>maintenance-core</artifactId>
@@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>eu.kennytv</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-api</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
@@ -23,7 +23,7 @@
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.23</version>
<scope>compile</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.minecrell</groupId>
@@ -18,13 +18,18 @@
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.util.SenderInfo;
@@ -40,10 +45,12 @@ 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;
@@ -52,12 +59,15 @@ public abstract class MaintenancePlugin implements IMaintenance {
private final String prefix;
private final ServerType serverType;
private Version newestVersion;
private Task task;
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
@@ -79,19 +89,34 @@ public abstract class MaintenancePlugin implements IMaintenance {
broadcast(settings.getMessage("maintenanceActivated"));
} else
broadcast(settings.getMessage("maintenanceDeactivated"));
eventManager.callEvent(new MaintenanceChangedEvent(maintenance));
}
public String formatedTimer(final String s) {
return s.contains("%TIMER%") ? s.replace("%TIMER%", formatedTimer()) : s;
}
public String formatedTimer() {
if (!isTaskRunning()) return "-";
if (!isTaskRunning()) return settings.getMessage("motdTimerNotRunning", "-");
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);
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 int minutes, final boolean enable) {
runnable = new MaintenanceRunnable(this, settings, minutes, enable);
task = startMaintenanceRunnable(runnable);
public void startMaintenanceRunnableForMinutes(final int minutes, final boolean enable) {
startMaintenanceRunnableForSeconds(minutes * 60, enable);
}
public void startMaintenanceRunnableForSeconds(final int seconds, final boolean enable) {
runnable = new MaintenanceRunnable(this, settings, seconds, 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 boolean updateAvailable() {
@@ -99,6 +124,26 @@ public abstract class MaintenancePlugin implements IMaintenance {
return version.compareTo(newestVersion) == -1;
}
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 {
final int seconds = (int) TimeUnit.MILLISECONDS.toSeconds(settings.getSavedEndtimer() - current);
startMaintenanceRunnableForSeconds(seconds, false);
getLogger().info("The timer has been continued - maintenance will be disabled in: " + formatedTimer());
}
}
protected void sendEnableMessage() {
getLogger().info("Plugin by KennyTV");
if (!settings.hasUpdateChecks()) return;
@@ -118,8 +163,11 @@ public abstract class MaintenancePlugin implements IMaintenance {
}
public boolean installUpdate() {
// Ore sad :(
Preconditions.checkArgument(serverType != ServerType.SPONGE);
try {
final URLConnection conn = new URL("https://github.com/KennyTV/Maintenance/releases/download/" + newestVersion + "/Maintenance.jar").openConnection();
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();
@@ -170,11 +218,8 @@ public abstract class MaintenancePlugin implements IMaintenance {
connection.setRequestProperty("Content-Type", "text/plain");
final GsonBuilder gsonBuilder = new GsonBuilder();
final byte[] bytes = gsonBuilder.setPrettyPrinting().create().toJson(dump).getBytes(StandardCharsets.UTF_8);
connection.setRequestProperty("Content-Length", Integer.toString(bytes.length));
final OutputStream out = connection.getOutputStream();
out.write(bytes);
out.write(gsonBuilder.disableHtmlEscaping().setPrettyPrinting().create().toJson(dump).getBytes(StandardCharsets.UTF_8));
out.close();
if (connection.getResponseCode() == 503) {
@@ -194,7 +239,8 @@ public abstract class MaintenancePlugin implements IMaintenance {
return jsonOutput.get("key").getAsString();
} catch (final IOException e) {
getLogger().log(Level.WARNING, "Could not paste dump :(", e);
getLogger().log(Level.WARNING, "Could not paste dump :(");
e.printStackTrace();
return null;
}
}
@@ -209,15 +255,16 @@ public abstract class MaintenancePlugin implements IMaintenance {
try {
loadIcon(file);
} catch (final Exception e) {
getLogger().log(Level.WARNING, "Could not load the 'maintenance-icon.png' file!", e);
getLogger().log(Level.WARNING, "Could not load the 'maintenance-icon.png' file!");
e.printStackTrace();
}
}
public void cancelTask() {
task.cancel();
if (settings.isSaveEndtimerOnStop() && !runnable.shouldEnable())
settings.setSavedEndtimer(0);
runnable.getTask().cancel();
runnable = null;
task = null;
}
public UUID checkUUID(final SenderInfo sender, final String s) {
@@ -231,6 +278,12 @@ public abstract class MaintenancePlugin implements IMaintenance {
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]+");
}
@@ -242,7 +295,7 @@ public abstract class MaintenancePlugin implements IMaintenance {
@Override
public boolean isTaskRunning() {
return task != null && runnable != null;
return runnable != null;
}
@Override
@@ -250,15 +303,24 @@ public abstract class MaintenancePlugin implements IMaintenance {
return settings;
}
@Override
public IEventManager getEventManager() {
return eventManager;
}
@Override
public String getVersion() {
return version.toString();
}
public List<String> getMaintenanceServers() {
public List<String> getMaintenanceServersDump() {
return isMaintenance() ? Arrays.asList("global") : null;
}
public int getSaltLevel() {
return Integer.MAX_VALUE;
}
public Version getNewestVersion() {
return newestVersion;
}
@@ -289,6 +351,8 @@ public abstract class MaintenancePlugin implements IMaintenance {
public abstract void sendUpdateNotification(SenderInfo sender);
public abstract Task startMaintenanceRunnable(Runnable runnable);
public abstract SenderInfo getOfflinePlayer(String name);
public abstract SenderInfo getOfflinePlayer(UUID uuid);
@@ -307,7 +371,5 @@ public abstract class MaintenancePlugin implements IMaintenance {
protected abstract void kickPlayers();
protected abstract Task startMaintenanceRunnable(Runnable runnable);
protected abstract File getPluginFile();
}
@@ -20,6 +20,7 @@ package eu.kennytv.maintenance.core;
import eu.kennytv.maintenance.api.ISettings;
import eu.kennytv.maintenance.core.config.Config;
import eu.kennytv.maintenance.core.config.ConfigSection;
import eu.kennytv.maintenance.core.util.ServerType;
import java.io.File;
@@ -30,6 +31,7 @@ import java.util.*;
import java.util.logging.Level;
public class Settings implements ISettings {
private static final int CURRENT_CONFIG_VERSION = 2;
private static final Random RANDOM = new Random();
protected final MaintenancePlugin plugin;
private final Map<UUID, String> whitelistedPlayers = new HashMap<>();
@@ -37,6 +39,7 @@ public class Settings implements ISettings {
protected boolean maintenance;
private Set<Integer> broadcastIntervals;
private List<String> pingMessages;
private List<String> timerSpecificPingMessages;
private String playerCountMessage;
private String playerCountHoverMessage;
private String languageName;
@@ -44,7 +47,9 @@ public class Settings implements ISettings {
private boolean customMaintenanceIcon;
private boolean joinNotifications;
private boolean updateChecks;
private boolean saveEndtimerOnStop;
private boolean debug;
private long savedEndtimer;
protected Config config;
protected Config language;
@@ -99,10 +104,15 @@ public class Settings implements ISettings {
}
}
protected void createFile(final String name) {
// 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(name)) {
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);
@@ -138,6 +148,8 @@ public class Settings implements ISettings {
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");
@@ -149,6 +161,9 @@ public class Settings implements ISettings {
languageName = getConfigString("language").toLowerCase();
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();
}
@@ -194,9 +209,29 @@ public class Settings implements ISettings {
plugin.getLogger().warning("Could not move maintenance-icon from server directory to the plugin's directory! Please do so yourself!");
}
// 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 all configs to the new format!");
plugin.getLogger().info("Done! Updated config(s) to the latest version!");
}
}
@@ -208,7 +243,8 @@ public class Settings implements ISettings {
try {
oldConfig.load();
} catch (final IOException e) {
plugin.getLogger().log(Level.WARNING, "Error while trying to migrate old config file", e);
plugin.getLogger().log(Level.WARNING, "Error while trying to migrate old config file");
e.printStackTrace();
return false;
}
@@ -237,7 +273,8 @@ public class Settings implements ISettings {
try {
oldFile.load();
} catch (final IOException e) {
plugin.getLogger().log(Level.WARNING, "Error while trying to migrate old SpigotServers file", e);
plugin.getLogger().log(Level.WARNING, "Error while trying to migrate old SpigotServers file");
e.printStackTrace();
return false;
}
@@ -289,9 +326,16 @@ public class Settings implements ISettings {
}
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()));
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(plugin.formatedTimer(s).replace("%NEWLINE%", "\n"));
}
@Override
@@ -358,6 +402,25 @@ public class Settings implements ISettings {
return updateChecks;
}
public boolean isSaveEndtimerOnStop() {
return saveEndtimerOnStop;
}
public boolean hasTimerSpecificPingMessages() {
return timerSpecificPingMessages != null;
}
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;
}
@@ -366,21 +429,27 @@ public class Settings implements ISettings {
return pingMessages;
}
/**
* May be null
*/
public List<String> getTimerSpecificPingMessages() {
return timerSpecificPingMessages;
}
public Set<Integer> getBroadcastIntervals() {
return broadcastIntervals;
}
public String getPlayerCountMessage() {
return playerCountMessage.replace("%TIMER%", plugin.formatedTimer());
return plugin.formatedTimer(playerCountMessage);
}
public String getPlayerCountHoverMessage() {
return playerCountHoverMessage.replace("%TIMER%", plugin.formatedTimer());
return plugin.formatedTimer(playerCountHoverMessage);
}
public String getKickMessage() {
return getMessage("kickmessage", "§cThe server is currently under maintenance!%NEWLINE%§cTry again later!")
.replace("%NEWLINE%", "\n").replace("%TIMER%", plugin.formatedTimer());
return plugin.formatedTimer(getMessage("kickmessage", "§cThe server is currently under maintenance!%NEWLINE%§cTry again later!").replace("%NEWLINE%", "\n"));
}
public String getLanguage() {
@@ -22,6 +22,7 @@ import eu.kennytv.maintenance.core.MaintenancePlugin;
import eu.kennytv.maintenance.core.Settings;
import eu.kennytv.maintenance.core.command.subcommand.*;
import eu.kennytv.maintenance.core.util.SenderInfo;
import eu.kennytv.maintenance.core.util.ServerType;
import java.util.*;
import java.util.stream.Collectors;
@@ -132,8 +133,13 @@ public abstract class MaintenanceCommand {
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());
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);
// 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!");
}
@@ -40,7 +40,7 @@ public final class EndtimerCommand extends CommandInfo {
return;
}
plugin.startMaintenanceRunnable(Integer.parseInt(args[1]), false);
plugin.startMaintenanceRunnableForMinutes(Integer.parseInt(args[1]), false);
sender.sendMessage(getMessage("endtimerStarted").replace("%TIME%", plugin.getRunnable().getTime()));
}
}
@@ -22,22 +22,49 @@ import eu.kennytv.maintenance.core.MaintenancePlugin;
import eu.kennytv.maintenance.core.command.CommandInfo;
import eu.kennytv.maintenance.core.util.SenderInfo;
import java.util.Collections;
import java.util.List;
public final class MotdCommand extends CommandInfo {
public MotdCommand(final MaintenancePlugin plugin) {
super(plugin, "motd", "§6/maintenance motd §7(Lists the currently set maintenance motds)");
super(plugin, "motd", "§6/maintenance motd [timer] §7(Lists the currently set maintenance motds. If specifying 'timer', the timer motds are shown)");
}
@Override
public void execute(final SenderInfo sender, final String[] args) {
if (checkArgs(sender, args, 1)) return;
if (args.length == 1) {
sendList(sender, getSettings().getPingMessages());
} else if (args.length == 2 && args[1].equalsIgnoreCase("timer")) {
if (!getSettings().hasTimerSpecificPingMessages()) {
sender.sendMessage(getMessage("timerMotdDisabled"));
return;
}
sendList(sender, getSettings().getTimerSpecificPingMessages());
} else
sender.sendMessage(helpMessage);
}
private void sendList(final SenderInfo sender, final List<String> list) {
if (list == null || list.isEmpty()) {
sender.sendMessage(getMessage("motdListEmpty"));
return;
}
sender.sendMessage(getMessage("motdList"));
for (int i = 0; i < getSettings().getPingMessages().size(); i++) {
for (int i = 0; i < list.size(); i++) {
sender.sendMessage("§b" + (i + 1) + "§8§m---------");
for (final String motd : getSettings().getColoredString(getSettings().getPingMessages().get(i)).split("%NEWLINE%")) {
for (final String motd : getSettings().getColoredString(list.get(i)).split("%NEWLINE%")) {
sender.sendMessage(motd);
}
}
sender.sendMessage("§8§m----------");
}
@Override
public List<String> getTabCompletion(final SenderInfo sender, final String[] args) {
if (args.length != 2 || !getSettings().hasTimerSpecificPingMessages()) return Collections.emptyList();
return Collections.singletonList("timer");
}
}
@@ -30,11 +30,21 @@ import java.util.List;
public final class RemoveMotdCommand extends CommandInfo {
public RemoveMotdCommand(final MaintenancePlugin plugin) {
super(plugin, "setmotd", "§6/maintenance removemotd <index> §7(Removes a maintenance motd)");
super(plugin, "setmotd", "§6/maintenance removemotd [timer] <index> §7(Removes a maintenance motd. If using \"timer\" as an argument, a timerspecific pingmessage will be removed)");
}
@Override
public void execute(final SenderInfo sender, final String[] args) {
public void execute(final SenderInfo sender, String[] args) {
boolean timerPingMessages = false;
if (args.length == 3 && args[1].equalsIgnoreCase("timer")) {
if (!getSettings().hasTimerSpecificPingMessages()) {
sender.sendMessage(getMessage("timerMotdDisabled"));
return;
}
args = plugin.removeArrayIndex(args, 1);
timerPingMessages = true;
}
if (checkArgs(sender, args, 2)) return;
if (!plugin.isNumeric(args[1])) {
sender.sendMessage(helpMessage);
@@ -42,32 +52,35 @@ public final class RemoveMotdCommand extends CommandInfo {
}
final Settings settings = getSettings();
if (settings.getPingMessages().size() < 2) {
final List<String> pingMessages = timerPingMessages ? settings.getTimerSpecificPingMessages() : settings.getPingMessages();
if (pingMessages.size() < 2) {
sender.sendMessage(getMessage("removeMotdError"));
return;
}
final int index = Integer.parseInt(args[1]);
if (index == 0 || index > settings.getPingMessages().size()) {
sender.sendMessage(getMessage("setMotdIndexError").replace("%MOTDS%", Integer.toString(settings.getPingMessages().size()))
.replace("%NEWAMOUNT%", Integer.toString(settings.getPingMessages().size())));
if (index == 0 || index > pingMessages.size()) {
sender.sendMessage(getMessage("setMotdIndexError").replace("%MOTDS%", Integer.toString(pingMessages.size()))
.replace("%NEWAMOUNT%", Integer.toString(pingMessages.size())));
return;
}
settings.getPingMessages().remove(index - 1);
settings.getConfig().set("pingmessages", settings.getPingMessages());
pingMessages.remove(index - 1);
settings.getConfig().set(timerPingMessages ? "timerspecific-pingmessages" : "pingmessages", pingMessages);
settings.saveConfig();
sender.sendMessage(getMessage("removedMotd").replace("%INDEX%", args[1]));
}
@Override
public List<String> getTabCompletion(final SenderInfo sender, final String[] args) {
if (args.length != 2) return Collections.emptyList();
final int size = plugin.getSettings().getPingMessages().size();
final List<String> list = new ArrayList<>(size);
for (int i = 1; i <= size; i++) {
list.add(String.valueOf(i));
if (args.length == 2 || (args.length == 3 && args[1].equalsIgnoreCase("timer"))) {
final int size = (args.length == 3 ? plugin.getSettings().getTimerSpecificPingMessages() : plugin.getSettings().getPingMessages()).size();
final List<String> list = new ArrayList<>(size);
for (int i = 1; i <= size; i++) {
list.add(String.valueOf(i));
}
return list;
}
return list;
return Collections.emptyList();
}
}
@@ -31,21 +31,33 @@ import java.util.List;
public final class SetMotdCommand extends CommandInfo {
public SetMotdCommand(final MaintenancePlugin plugin) {
super(plugin, "setmotd", "§6/maintenance setmotd <index> <1/2> <message> §7(Sets a motd for maintenance mode)");
super(plugin, "setmotd", "§6/maintenance setmotd [timer] <index> <1/2> <message> §7(Sets a motd for maintenance mode. If using \"timer\" as an argument, a timerspecific pingmessage will be set)");
}
@Override
public void execute(final SenderInfo sender, final String[] args) {
public void execute(final SenderInfo sender, String[] args) {
boolean timerPingMessages = false;
if (args.length > 1 && args[1].equalsIgnoreCase("timer")) {
if (!getSettings().hasTimerSpecificPingMessages()) {
sender.sendMessage(getMessage("timerMotdDisabled"));
return;
}
// remove the "timer" off the args to keep the rest the code cleaner
args = plugin.removeArrayIndex(args, 1);
timerPingMessages = true;
}
if (args.length < 4 || !plugin.isNumeric(args[1])) {
sender.sendMessage(helpMessage);
return;
}
final Settings settings = getSettings();
final List<String> pingMessages = timerPingMessages ? settings.getTimerSpecificPingMessages() : settings.getPingMessages();
final int index = Integer.parseInt(args[1]);
if (index == 0 || index > settings.getPingMessages().size() + 1) {
sender.sendMessage(getMessage("setMotdIndexError").replace("%MOTDS%", Integer.toString(settings.getPingMessages().size()))
.replace("%NEWAMOUNT%", Integer.toString(settings.getPingMessages().size() + 1)));
if (index == 0 || index > pingMessages.size() + 1) {
sender.sendMessage(getMessage("setMotdIndexError").replace("%MOTDS%", Integer.toString(pingMessages.size()))
.replace("%NEWAMOUNT%", Integer.toString(pingMessages.size() + 1)));
return;
}
@@ -61,31 +73,37 @@ public final class SetMotdCommand extends CommandInfo {
}
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 oldMessage = index > pingMessages.size() ? "" : pingMessages.get(index - 1);
final String newMessage;
if (line == 1)
if (line == 1) {
newMessage = oldMessage.contains("%NEWLINE%") ?
message + "%NEWLINE%" + oldMessage.split("%NEWLINE%", 2)[1] : message;
else
} else {
newMessage = oldMessage.contains("%NEWLINE%") ?
oldMessage.split("%NEWLINE%", 2)[0] + "%NEWLINE%" + message : oldMessage + "%NEWLINE%" + message;
}
if (index > settings.getPingMessages().size())
settings.getPingMessages().add(newMessage);
if (index > pingMessages.size())
pingMessages.add(newMessage);
else
settings.getPingMessages().set(index - 1, newMessage);
settings.getConfig().set("pingmessages", settings.getPingMessages());
pingMessages.set(index - 1, newMessage);
settings.getConfig().set(timerPingMessages ? "timerspecific-pingmessages" : "pingmessages", pingMessages);
settings.saveConfig();
sender.sendMessage(settings.getMessage("setMotd").replace("%LINE%", args[2]).replace("%INDEX%", args[1])
.replace("%MOTD%", "§f" + settings.getColoredString(message)));
}
@Override
public List<String> getTabCompletion(final SenderInfo sender, final String[] args) {
public List<String> getTabCompletion(final SenderInfo sender, String[] args) {
boolean timer = false;
if (args.length > 1 && args[1].equalsIgnoreCase("timer")) {
args = plugin.removeArrayIndex(args, 1);
timer = true;
}
if (args.length == 3) return Arrays.asList("1", "2");
if (args.length == 2) {
final List<String> list = new ArrayList<>();
for (int i = 1; i <= getSettings().getPingMessages().size() + 1; i++) {
for (int i = 1; i <= (timer ? getSettings().getTimerSpecificPingMessages() : getSettings().getPingMessages()).size() + 1; i++) {
list.add(String.valueOf(i));
}
return list;
@@ -40,7 +40,7 @@ public final class StarttimerCommand extends CommandInfo {
return;
}
plugin.startMaintenanceRunnable(Integer.parseInt(args[1]), true);
plugin.startMaintenanceRunnableForMinutes(Integer.parseInt(args[1]), true);
sender.sendMessage(getMessage("starttimerStarted").replace("%TIME%", plugin.getRunnable().getTime()));
}
}
@@ -21,6 +21,7 @@ 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;
import eu.kennytv.maintenance.core.util.ServerType;
public final class UpdateCommand extends CommandInfo {
@@ -38,6 +39,11 @@ public final class UpdateCommand extends CommandInfo {
sender.sendMessage(plugin.getPrefix() + "§aYou already have the latest version of the plugin!");
return;
}
// Ore very sad :(
if (plugin.getServerType() == ServerType.SPONGE) {
sender.sendMessage(plugin.getPrefix() + "§cSorry, automated downloading of the plugin is not supported on Sponge! Please download the latest version manually! :(");
return;
}
sender.sendMessage(getMessage("updateDownloading"));
if (plugin.installUpdate())
@@ -18,6 +18,7 @@
package eu.kennytv.maintenance.core.config;
import com.google.common.collect.Sets;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
@@ -54,7 +55,7 @@ public final class Config extends ConfigSection {
public Config(final File file, final String... unsupportedFields) {
this.file = file;
this.unsupportedFields = new HashSet<>(Arrays.asList(unsupportedFields));
this.unsupportedFields = unsupportedFields.length == 0 ? Collections.emptySet() : Sets.newHashSet(unsupportedFields);
}
public void load() throws IOException {
@@ -95,6 +96,28 @@ public final class Config extends ConfigSection {
Files.write(this.file.toPath(), bytes);
}
public void addMissingFields(final Map<String, Object> fields, final Map<String, String[]> comments) {
// Note: Only scans for the first two levels
for (final Map.Entry<String, Object> entry : fields.entrySet()) {
final Object o = values.get(entry.getKey());
if (o != null) {
final Object o2 = entry.getValue();
if (!(o instanceof Map) || !(o2 instanceof Map)) continue;
final Map<String, Object> deepMap = (Map<String, Object>) o2;
for (final Map.Entry<String, Object> deepEntry : ((Map<String, Object>) o2).entrySet()) {
if (deepMap.containsKey(deepEntry.getKey())) continue;
deepMap.put(deepEntry.getKey(), deepEntry.getValue());
}
continue;
}
values.put(entry.getKey(), entry.getValue());
}
this.comments = new HashMap<>(comments);
}
@Override
public void set(final String key, final Object value, final String... comments) {
if (value == null) {
@@ -167,6 +190,4 @@ public final class Config extends ConfigSection {
public void resetAwesomeHeader() {
this.header = AWESOME_HEADER;
}
}
@@ -44,6 +44,10 @@ public class ConfigSection {
return (E) this.values.get(key);
}
public <E> E get(final String key, final E def) {
return values.containsKey(key) ? (E) this.values.get(key) : def;
}
public Object getObject(final String key) {
return this.values.get(key);
}
@@ -116,10 +120,19 @@ public class ConfigSection {
public double getDouble(final String key) {
final Object o = values.get(key);
return o instanceof Number ? ((Number) o).doubleValue() : 0;
return o instanceof Number ? ((Number) o).doubleValue() : 0D;
}
public double getDouble(final String key, final double def) {
public double getDouble(final String key, final long def) {
return values.containsKey(key) ? get(key) : def;
}
public long getLong(final String key) {
final Object o = values.get(key);
return o instanceof Number ? ((Number) o).longValue() : 0L;
}
public long getLong(final String key, final long def) {
return values.containsKey(key) ? get(key) : def;
}
@@ -33,7 +33,7 @@ public final class MaintenanceDump {
private final JsonObject plugins;
public MaintenanceDump(final MaintenancePlugin plugin, final Settings settings) {
general = new ServerDump(plugin.getVersion(), plugin.getServerType().toString(), plugin.getServerVersion(), plugin.getMaintenanceServers());
general = new ServerDump(plugin.getVersion(), plugin.getServerType().toString(), plugin.getServerVersion(), plugin.getMaintenanceServersDump());
configuration = new LinkedHashMap<>(settings.getConfig().getValues());
final Object o = configuration.get("mysql");
@@ -22,13 +22,13 @@ import java.util.List;
public final class ServerDump {
private final String pluginVersion;
private final String serverType;
private final String platform;
private final String serverVersion;
private final List<String> maintenance;
public ServerDump(final String pluginVersion, final String serverType, final String serverVersion, final List<String> maintenance) {
public ServerDump(final String pluginVersion, final String platform, final String serverVersion, final List<String> maintenance) {
this.pluginVersion = pluginVersion;
this.serverType = serverType;
this.platform = platform;
this.serverVersion = serverVersion;
this.maintenance = maintenance;
}
@@ -0,0 +1,43 @@
/*
* Maintenance - https://git.io/maintenancemode
* Copyright (C) 2018 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.event;
import eu.kennytv.maintenance.api.event.manager.EventListener;
import eu.kennytv.maintenance.api.event.manager.IEventManager;
import eu.kennytv.maintenance.api.event.manager.MaintenanceEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class EventManager implements IEventManager {
private final Map<String, List<EventListener>> listeners = new HashMap<>();
@Override
public void registerListener(final EventListener listener, final Class<? extends MaintenanceEvent> eventClass) {
listeners.computeIfAbsent(eventClass.getSimpleName(), s -> new ArrayList<>()).add(listener);
}
public void callEvent(final MaintenanceEvent event) {
final List<EventListener> list = listeners.get(event.getClass().getSimpleName());
if (list != null)
list.forEach(listener -> listener.onEvent(event));
}
}
@@ -44,12 +44,10 @@ public abstract class JoinListenerBase {
* @return true if the sender should be kicked
*/
protected boolean kickPlayer(final SenderInfo sender, final boolean updateCheck) {
if (settings.isMaintenance() && !sender.getUuid().equals(notifyUuid)) {
if (!sender.hasMaintenancePermission("bypass") && !settings.getWhitelistedPlayers().containsKey(sender.getUuid())) {
if (settings.isJoinNotifications())
broadcastJoinNotification(sender.getName());
return true;
}
if (settings.isMaintenance() && !sender.hasMaintenancePermission("bypass") && !settings.getWhitelistedPlayers().containsKey(sender.getUuid())) {
if (settings.isJoinNotifications())
broadcastJoinNotification(sender.getName());
return true;
}
if (updateCheck)
updateCheck(sender);
@@ -23,8 +23,8 @@ import eu.kennytv.maintenance.core.Settings;
public final class MaintenanceRunnable extends MaintenanceRunnableBase {
public MaintenanceRunnable(final MaintenancePlugin plugin, final Settings settings, final int minutes, final boolean enable) {
super(plugin, settings, minutes, enable);
public MaintenanceRunnable(final MaintenancePlugin plugin, final Settings settings, final int seconds, final boolean enable) {
super(plugin, settings, seconds, enable);
}
@Override
@@ -20,18 +20,21 @@ package eu.kennytv.maintenance.core.runnable;
import eu.kennytv.maintenance.core.MaintenancePlugin;
import eu.kennytv.maintenance.core.Settings;
import eu.kennytv.maintenance.core.util.Task;
public abstract class MaintenanceRunnableBase implements Runnable {
protected final MaintenancePlugin plugin;
protected final Settings settings;
protected final boolean enable;
private final Task task;
protected int seconds;
protected MaintenanceRunnableBase(final MaintenancePlugin plugin, final Settings settings, final int minutes, final boolean enable) {
protected MaintenanceRunnableBase(final MaintenancePlugin plugin, final Settings settings, final int seconds, final boolean enable) {
this.plugin = plugin;
this.settings = settings;
this.seconds = minutes * 60;
this.seconds = seconds;
this.enable = enable;
this.task = plugin.startMaintenanceRunnable(this);
}
@Override
@@ -67,10 +70,18 @@ public abstract class MaintenanceRunnableBase implements Runnable {
builder.append(time).append(" ").append(settings.getMessage(time == 1 ? timeUnit : timeUnit + "s"));
}
public boolean shouldEnable() {
return enable;
}
public int getSecondsLeft() {
return seconds;
}
public Task getTask() {
return task;
}
protected abstract void finish();
protected abstract String startMessageKey();
+22 -4
View File
@@ -14,8 +14,8 @@ maintenance-enabled: false
# Enables maintenance on certain servers managed by your Bungee instance(s).
proxied-maintenance-servers:
#- SpigotServer1
#- AnotherServer
- SpigotServer1
# - AnotherServer
# If maintenance is enabled on a proxied server with players on it,
# they will be sent to the fallback server instead of being kicked off the network.
@@ -29,6 +29,13 @@ pingmessages:
- "&cMaintenance mode!%NEWLINE%&6We will be back soon!"
# - "Other entry"
# If set to true and an endtimer is currently running, a pingmessage from this pool will be chosen
# instead of the ones above, so you can have different messages for when an endtimer is running/not running.
enable-timerspecific-messages: false
timerspecific-pingmessages:
- "&cMaintenance mode!%NEWLINE%&6We will be back in %TIMER%!"
# - "Other 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.
#
@@ -48,7 +55,7 @@ custom-maintenance-icon: false
send-join-notification: false
# Changes the language of command feedback/messages.
# Currently available are: en (English), de (German), fr (French), pt (Portuguese)
# Currently available are: en (English), de (German), fr (French), pt (Portuguese), es (Spanish)
language: en
# If you have 2 or more proxy instances, the database connection will make sure all proxies
@@ -67,10 +74,21 @@ mysql:
# (0 is not recommended if having more than a hundred concurrent players, then I'd recommend keeping it from 10-60).
update-interval: 15
# If enabled and the server is restarted while running an endtimer, the timer will be continued after the restart.
# If the timer ends while the server is offline, maintenance will be disabled as soon as the server starts again.
continue-endtimer-after-restart:
enabled: false
# This value is set everytime an endtimer is started, cancelled or ended.
# Do not manually change this value.
end: 0
# 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 disabled, you will no longer receive any messages if there is an update.
# Not recommended to disable, as new versions generally tend to run better and with less bugs.
# However, you can always check for updates manually using the '/maintenance update' command.
update-checks: true
update-checks: true
# Used for autoupdating the config, do not change this value.
config-version: 2
@@ -16,8 +16,12 @@ timerAlreadyRunning: "&8[&eMaintenance&8] &cMomentan läuft bereits ein Timer!"
timerNotRunning: "&8[&eMaintenance&8] &cMomentan läuft kein Timer."
timerCancelled: "&8[&eMaintenance&8] &cDer laufende Timer wurde beendet."
timerTooLong: "&8[&eMaintenance&8] &cDie angegebene Nummer muss kleiner als 40320 sein (= 28 Tage)!"
timerMotdDisabled: "&8[&eMaintenance&8] &cDu musst 'enable-timerspecific-messages' in der Config auf 'true' stellen, wenn du timerspezifische Motds benutzen/editieren möchtest."
motdTimer: "%HOURS%:%MINUTES%:%SECONDS%"
motdTimerNotRunning: "-"
joinNotification: "&8[&eMaintenance&8] &e%PLAYER% &chat versucht den Server beizutreten."
motdList: "&8[&eMaintenance&8] &7Liste der Maintenance MOTDs:"
motdListEmpty: "8[&eMaintenance&8] &cDu hast keine Maintenance MOTDs gesetzt!"
reload: "&8[&eMaintenance&8] &aConfig, WhitelistedPlayers, Language Datei und Maintenance Icon wurden neugeladen."
removedMotd: "&8[&eMaintenance&8] &aDie %INDEX%. Maintenance MOTD wurde entfernt."
removeMotdError: "&8[&eMaintenance&8] &cDu hast nur eine Maintenance MOTD, daher kannst du auch keine entfernen!"
@@ -16,8 +16,12 @@ timerAlreadyRunning: "&8[&eMaintenance&8] &cThere is already a timer scheduled!"
timerNotRunning: "&8[&eMaintenance&8] &cThere is currently no running timer."
timerCancelled: "&8[&eMaintenance&8] &cThe current timer has been disabled."
timerTooLong: "&8[&eMaintenance&8] &cThe number has to be less than 40320 (28 days)!"
timerMotdDisabled: "&8[&eMaintenance&8] &cYou have to set 'enable-timerspecific-messages' in the config to 'true', if you want to use/edit timerspecific motds."
motdTimer: "%HOURS%:%MINUTES%:%SECONDS%"
motdTimerNotRunning: "-"
joinNotification: "&8[&eMaintenance&8] &e%PLAYER% &ctried to join the server."
motdList: "&8[&eMaintenance&8] &7List of your maintenance motds:"
motdListEmpty: "8[&eMaintenance&8] &cYou don't have any maintenance motds set!"
reload: "&8[&eMaintenance&8] &aReloaded config, whitelistedplayers, language file and the maintenance icon."
removedMotd: "&8[&eMaintenance&8] &aRemoved motd number %INDEX%."
removeMotdError: "&8[&eMaintenance&8] &cYou only have one motd, so you cannot remove any!"
@@ -0,0 +1,67 @@
# Maintenance Plugin by KennyTV
# Don't remove words inbetween the '%' if you don't exactly know why you're doing it
noPermission: "&4No tienes Permiso para ejecutar este comando."
kickmessage: "&cEl servidor se encuentra en &6Mantenimiento!%NEWLINE%&cIntentalo de nuevo mas tarde!"
maintenanceActivated: "&8[&eMaintenance&8] &6Mantenimiento &7Activado"
maintenanceDeactivated: "&8[&eMaintenance&8] &7Modo &6Mantenimiento &7Desactivado"
alreadyEnabled: "&8[&eMaintenance&8] &7Modo &6Mantenimiento &7se encuentra Habilitado!"
alreadyDisabled: "&8[&eMaintenance&8] &7Modo &6Mantenimiento &7se encuentra Deshabilitado!"
helpPageNotFound: "&8[&eMaintenance&8] &7No hay pagina con ese número!"
endtimerBroadcast: "&8[&eMaintenance&8] &7El Modo &6Mantenimiento &7se desactivara en &6%TIME%&7."
endtimerStarted: "&8[&eMaintenance&8] &7Temporizador Iniciado: El Modo &6Mantenimiento &7se desactivará en &6%TIME%&7."
starttimerBroadcast: "&8[&eMaintenance&8] &7El Modo &6Mantenimiento &7se habilitara en &6%TIME%&7."
starttimerStarted: "&8[&eMaintenance&8] &7Temporizador Iniciado: El Modo &6Mantenimiento &7se activará en &6%TIME%&7."
timerAlreadyRunning: "&8[&eMaintenance&8] &7Ya hay un temporizador programado!"
timerNotRunning: "&8[&eMaintenance&8] &7Actualmente no hay temporizador."
timerCancelled: "&8[&eMaintenance&8] &cEl Temporizador actual ha sido deshabilitado."
timerTooLong: "&8[&eMaintenance&8] &7El numero debe ser menor a 40320 &6(28 dias)"
timerMotdDisabled: "&8[&eMaintenance&8] &cYou have to set 'enable-timerspecific-messages' in the config to 'true', if you want to use/edit timerspecific motds."
motdTimer: "%HOURS%:%MINUTES%:%SECONDS%"
motdTimerNotRunning: "-"
joinNotification: "&8[&eMaintenance&8] &c%PLAYER% &7Intenta unirse al servidor."
motdList: "&8[&eMaintenance&8] &7Lista de motds de &6Mantenimiento&7:"
motdListEmpty: "8[&eMaintenance&8] &cYou don't have any maintenance motds set!"
reload: "&8[&eMaintenance&8] &aConfiguracion Recargada"
removedMotd: "&8[&eMaintenance&8] &aNumero de Motd eliminado &6%INDEX%."
removeMotdError: "&8[&eMaintenance&8] &Solo tienes un Motd, por lo que no puedes eliminar ninguno!"
setMotd: "&8[&eMaintenance&8] &aEstablecer linea &6%LINE%&a del &6%INDEX%. &6Mantenimiento&a para %MOTD%"
setMotdIndexError: "&8[&eMaintenance&8] &aActualmente tiene &6%MOTDS%&a Motds, por lo que debe elegir un número entre 1 y %NEWAMOUNT%."
setMotdLineError: "&8[&eMaintenance&8] &7El segundo argumento tiene que ser el numero de línea.(1 ó 2)!"
updateDownloading: "&8[&eMaintenance&8] &aDescargando Actualizacion..."
updateFailed: "&8[&eMaintenance&8] &aActualizacion &cFallida!"
updateFinished: "&8[&eMaintenance&8] &aLa actualización fue exitosa!, Debes reiniciar el Servidor!"
whitelistedPlayers: "&8[&eMaintenance&8] &6Jugadores en lista blanca:"
whitelistedPlayersFormat: "&7- &a%NAME% &8(&7%UUID%&8)"
whitelistAdded: "&8[&eMaintenance&8] &a%PLAYER% &7Añadido a la lista de &6Mantenimiento!"
whitelistAlreadyAdded: "&8[&eMaintenance&8] &a%PLAYER% &7Se encuentra en la lista de &6Mantenimiento!"
whitelistRemoved: "&8[&eMaintenance&8] &c%PLAYER% &7Eliminado de la lista de &6Mantenimiento!"
whitelistNotFound: "&8[&eMaintenance&8] &7No se encuentra en la lista de &6Mantenimiento!"
whitelistEmpty: "&8[&eMaintenance&8] &7La lista de &6Mantenimiento está vacía! Usa '&6/Maintenance add <Player>' &7para agregar a alguien!"
playerNotFound: "&8[&eMaintenance&8] &7Ningun jugador con este nombre ha jugado en este servidor antes."
playerNotFoundUuid: "&8[&eMaintenance&8] &cNo se pudo encontrar el jugador con ese UUID."
playerNotOnline: "&8[&eMaintenance&8] &7No hay jugador en línea con ese nombre."
invalidUuid: "&8[&eMaintenance&8] &cFormato inválido!"
second: "Segundo"
seconds: "Segundos"
minute: "Minuto"
minutes: "Minutos"
hour: "Hora"
hours: "Horas"
# Some messages for the Bungee part, just ignore them if you use the plugin on Spigot
serverNotFound: "&8[&eMaintenance&8] &cNingún servidor con este nombre está registrado en el proxy!"
singleTimerAlreadyRunning: "&8[&eMaintenance&8] &cYa hay un temporizador programado!"
singleTimerNotRunning: "&8[&eMaintenance&8] &cActualmente no hay ningún temporizador en ejecución para ese servidor."
singleTimerCancelled: "&8[&eMaintenance&8] &cEl temporizador actual para el servidor &6%SERVER% &c ha sido desactivado."
singleEndtimerBroadcast: "&8[&eMaintenance&8] &7Modo &6Mantenimiento &7en el Servidor &6%SERVER% &cse desactivará en &6%TIME%"
singleStarttimerBroadcast: "&8[&eMaintenance&8] &7Modo &6Mantenimiento &7en el Servidor &6%SERVER%&7se activará en &6%TIME%"
singleMaintenanceKick: "&8[&eMaintenance&8] &7El servidor &6%SERVER% &7se encuentra en &6Mantenimiento&7! Intentalo mas tarde!"
singleMaintenanceKickComplete: "&7El Servidor &6%SERVER% &7esta en &6Mantenimiento&7!%NEWLINE%&cVuelve Mas Tarde!"
singleMaintenanceActivated: "&8[&eMaintenance&8] &7El Modo&6Mantenimiento &7Esta Activado en el Servidor &6%SERVER%&7."
singleMaintenanceDeactivated: "&8[&eMaintenance&8] &7El Modo &6Mantenimiento &7Ahora esta deshabilitado en &6%SERVER%&7."
singleServerAlreadyEnabled: "&8[&eMaintenance&8] &7El Modo &6Mantenimiento &7se encuentra Habilitado en &6%SERVER%&7!"
singleServerAlreadyDisabled: "&8[&eMaintenance&8] 7El Modo &6Mantenimiento &7se encuentra Deshabilitado en &6%SERVER%&7!"
singleServerMaintenanceList: "&8[&eMaintenance&8] &7Servidores Proxy, que tienen habilitado el &6Mantenimiento:"
singleServerMaintenanceListEmpty: "&8[&eMaintenance&8] &7No hay servidores Proxy que están en &6Mantenimiento&7."
@@ -16,8 +16,12 @@ timerAlreadyRunning: "&8[&eMaintenance&8] &cIl y a déjà un horaire prévu!"
timerNotRunning: "&8[&eMaintenance&8] &cIl n'y a actuellement aucune maintenance prévue."
timerCancelled: "&8[&eMaintenance&8] &cLa minuterie actuelle a été désactivée."
timerTooLong: "&8[&eMaintenance&8] &cLe nombre doit être inférieur à 40320 (28 jours)!"
timerMotdDisabled: "&8[&eMaintenance&8] &c'enable-timerspecific-messages' dans la config doit être 'true' si vous voulez des motd minuterie spéficique."
motdTimer: "%HOURS%:%MINUTES%:%SECONDS%"
motdTimerNotRunning: "-"
joinNotification: "&8[&eMaintenance&8] &e%PLAYER% &ca essayé de rejoindre le serveur."
motdList: "&8[&eMaintenance&8] &7Liste de vos motd pour la maintenance:"
motdListEmpty: "8[&eMaintenance&8] &cVous n'avez pas ajoutéz de motd pour la maintenance!"
reload: "&8[&eMaintenance&8] &afichier config, liste blanche (whitelist) joueurs, fichier de langue et l'icône de maintenance, recharger."
removedMotd: "&8[&eMaintenance&8] &aNuméro de motd supprimé %INDEX%."
removeMotdError: "&8[&eMaintenance&8] &cVous n’avez qu’un motd, vous ne pouvez donc en supprimer!"
@@ -2,7 +2,7 @@
# Nao removas o '%' se nao souberes exatamente o que estas a fazer
noPermission: "&cNao tens permissao para executar este comando."
kickmessage: "&cThe server is currently under maintenance!%NEWLINE%&cTry again later!"
kickmessage: "&cO servidor esta em manutencao!%NEWLINE%&cTente mais tarde!"
maintenanceActivated: "&8[&cManutencao&8] &6Manutencao esta agora ativada!"
maintenanceDeactivated: "&8[&cManutencao&8] &6Manutencao esta agora desativada!"
alreadyEnabled: "&8[&cManutencao&8] &cManutencao ja esta ativada!"
@@ -16,8 +16,12 @@ timerAlreadyRunning: "&8[&cManutencao&8] &cO Timer ja esta a decorrer!"
timerNotRunning: "&8[&cManutencao&8] &cO Timer nao esta a decorrer!"
timerCancelled: "&8[&cManutencao&8] &cO Timer foi cancelado!"
timerTooLong: "&8[&cManutencao&8] &cO numero tem de ser menor que 40320 (28 dias)!"
timerMotdDisabled: "&8[&eMaintenance&8] &cYou have to set 'enable-timerspecific-messages' in the config to 'true', if you want to use/edit timerspecific motds."
motdTimer: "%HOURS%:%MINUTES%:%SECONDS%"
motdTimerNotRunning: "-"
joinNotification: "&8[&cManutencao&8] &e%PLAYER% &ctentou entrar no servidor."
motdList: "&8[&cManutencao&8] &7Lista de motds de manutencao:"
motdListEmpty: "8[&eMaintenance&8] &cYou don't have any maintenance motds set!"
reload: "&8[&cManutencao&8] &aReloaded config, whitelistedplayers, linguagem e icon de manutencao."
removedMotd: "&8[&cManutencao&8] &aRemovida motd numero %INDEX%."
removeMotdError: "&8[&cManutencao&8] &cSo tens uma motd, entao nao podes remover esta!"
@@ -35,9 +39,9 @@ whitelistRemoved: "&8[&cManutencao&8] &b%PLAYER% &aremovido da whitelist!"
whitelistNotFound: "&8[&cManutencao&8] &cEste jogador nao esta na whitelist!"
whitelistEmpty: "&8[&cManutencao&8] &cA whitelist esta vazia! Usa &e/maintenance add <player/uuid> &cpara adicionar alguem!"
playerNotFound: "&8[&cManutencao&8] &cNinguem com esse nome se registou no servidor."
playerNotFoundUuid: "&8[&cManutencao&8] &cNinguem com esse uuid se registou no servidor."
playerNotFoundUuid: "&8[&cManutencao&8] &cNenhum player com esse uuid foi encontrado."
playerNotOnline: "&8[&cManutencao&8] &cNao esta ninguem online com esse nome"
invalidUuid: "&8[&eMaintenance&8] &cUuid inválido!"
invalidUuid: "&8[&eMaintenance&8] &cFormato de uuid invalido!"
second: "segundo"
seconds: "segundos"
+12 -5
View File
@@ -4,9 +4,9 @@
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</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0</version>
<version>3.0.2</version>
</parent>
<artifactId>maintenance-spigot</artifactId>
@@ -14,17 +14,24 @@
<dependencies>
<dependency>
<groupId>eu.kennytv</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-core</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- Needed for backwards compatibility with Paper -->
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>1.5.25</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib-API</artifactId>
@@ -20,18 +20,24 @@ package eu.kennytv.maintenance.spigot;
import eu.kennytv.maintenance.api.IMaintenance;
import eu.kennytv.maintenance.api.IMaintenanceBase;
import eu.kennytv.maintenance.core.MaintenancePlugin;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
public final class MaintenanceSpigotBase extends JavaPlugin implements IMaintenanceBase {
private IMaintenance maintenance;
private MaintenancePlugin maintenance;
@Override
public void onEnable() {
maintenance = new MaintenanceSpigotPlugin(this);
}
@Override
public void onDisable() {
maintenance.disable();
}
@Override
public IMaintenance getApi() {
return maintenance;
@@ -28,6 +28,7 @@ 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.spigot.command.MaintenanceSpigotCommand;
import eu.kennytv.maintenance.spigot.listener.PaperServerListPingListener;
import eu.kennytv.maintenance.spigot.listener.PlayerLoginListener;
import eu.kennytv.maintenance.spigot.listener.ServerInfoPacketListener;
import eu.kennytv.maintenance.spigot.listener.ServerListPingListener;
@@ -77,13 +78,19 @@ public final class MaintenanceSpigotPlugin extends MaintenancePlugin {
final PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new PlayerLoginListener(this, settings), plugin);
if (pm.isPluginEnabled("ProtocolLib")) {
pm.registerEvents(new ServerInfoPacketListener(this, plugin, settings), plugin);
if (isAcceptablePaper()) {
pm.registerEvents(new PaperServerListPingListener(this, settings), plugin);
} else {
pm.registerEvents(new ServerListPingListener(this, settings), plugin);
getLogger().info("To use this plugin on Spigot to its full extend, you need the plugin ProtocolLib!");
if (pm.isPluginEnabled("ProtocolLib")) {
pm.registerEvents(new ServerInfoPacketListener(this, plugin, settings), plugin);
} else {
pm.registerEvents(new ServerListPingListener(this, settings), plugin);
getLogger().warning("To use this plugin on Spigot to its full extend, you need the plugin ProtocolLib!");
}
}
continueLastEndtimer();
new MetricsLite(plugin);
// ServerListPlus integration
@@ -95,6 +102,15 @@ public final class MaintenanceSpigotPlugin extends MaintenancePlugin {
}
}
private boolean isAcceptablePaper() {
try {
Class.forName("com.destroystokyo.paper.event.server.PaperServerListPingEvent");
return true;
} catch (final ClassNotFoundException e) {
return false;
}
}
@Deprecated
public static IMaintenance getAPI() {
return MaintenanceSpigotAPI.getAPI();
@@ -0,0 +1,144 @@
/*
* Maintenance - https://git.io/maintenancemode
* Copyright (C) 2018 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.spigot.listener;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
import com.destroystokyo.paper.profile.PlayerProfile;
import com.destroystokyo.paper.profile.ProfileProperty;
import com.mojang.authlib.GameProfile;
import eu.kennytv.maintenance.core.Settings;
import eu.kennytv.maintenance.spigot.MaintenanceSpigotPlugin;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
public final class PaperServerListPingListener implements Listener {
private final MaintenanceSpigotPlugin plugin;
private final Settings settings;
public PaperServerListPingListener(final MaintenanceSpigotPlugin plugin, final Settings settings) {
this.plugin = plugin;
this.settings = settings;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void serverListPing(final PaperServerListPingEvent event) {
if (!settings.isMaintenance()) return;
event.setMotd(settings.getRandomPingMessage());
if (settings.hasCustomPlayerCountMessage()) {
event.setProtocolVersion(0);
event.setVersion(settings.getPlayerCountMessage()
.replace("%ONLINE%", Integer.toString(plugin.getServer().getOnlinePlayers().size()))
.replace("%MAX%", Integer.toString(plugin.getServer().getMaxPlayers())));
}
final List<PlayerProfile> sample = event.getPlayerSample();
sample.clear();
for (final String string : settings.getPlayerCountHoverMessage().split("%NEWLINE%"))
sample.add(new DummyProfile(string));
if (settings.hasCustomIcon() && plugin.getFavicon() != null)
event.setServerIcon(plugin.getFavicon());
}
// Less unnecessary object creation :>
private static final class DummyProfile implements PlayerProfile {
private final String name;
private DummyProfile(final String name) {
this.name = name;
}
@Nullable
@Override
public String getName() {
return name;
}
@Override
public String setName(@Nullable final String name) {
return this.name;
}
@Nullable
@Override
public UUID getId() {
return null;
}
@Override
public UUID setId(@Nullable final UUID uuid) {
return null;
}
@Nonnull
@Override
public Set<ProfileProperty> getProperties() {
return Collections.emptySet();
}
@Override
public boolean hasProperty(final String property) {
return false;
}
@Override
public void setProperty(final ProfileProperty property) {
}
@Override
public void setProperties(final Collection<ProfileProperty> properties) {
}
@Override
public boolean removeProperty(final String property) {
return false;
}
@Override
public void clearProperties() {
}
@Override
public boolean isComplete() {
return false;
}
@Override
public boolean completeFromCache() {
return false;
}
@Override
public boolean complete(final boolean textures) {
return false;
}
// Keep this here for backwards compatibility
public GameProfile getGameProfile() {
return null;
}
}
}
@@ -37,55 +37,47 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public final class ServerInfoPacketListener implements Listener {
public final class ServerInfoPacketListener extends PacketAdapter implements Listener {
private final UUID uuid = new UUID(0, 0);
private final MaintenanceSpigotPlugin plugin;
private final Settings settings;
//private WrappedServerPing.CompressedImage image;
public ServerInfoPacketListener(final MaintenanceSpigotPlugin plugin, final MaintenanceSpigotBase base, final Settings settings) {
super(base, ListenerPriority.HIGHEST, PacketType.Status.Server.SERVER_INFO);
this.plugin = plugin;
this.settings = settings;
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(base, ListenerPriority.HIGHEST, PacketType.Status.Server.SERVER_INFO) {
@Override
public void onPacketSending(final PacketEvent event) {
if (!settings.isMaintenance()) return;
ProtocolLibrary.getProtocolManager().addPacketListener(this);
}
final WrappedServerPing ping = event.getPacket().getServerPings().read(0);
ping.setMotD(settings.getRandomPingMessage());
@Override
public void onPacketSending(final PacketEvent event) {
if (!settings.isMaintenance()) return;
if (settings.hasCustomPlayerCountMessage()) {
ping.setVersionProtocol(0);
ping.setVersionName(settings.getPlayerCountMessage()
.replace("%ONLINE%", Integer.toString(base.getServer().getOnlinePlayers().size()))
.replace("%MAX%", Integer.toString(base.getServer().getMaxPlayers())));
}
final WrappedServerPing ping = event.getPacket().getServerPings().read(0);
ping.setMotD(settings.getRandomPingMessage());
final List<WrappedGameProfile> players = new ArrayList<>();
for (final String string : settings.getPlayerCountHoverMessage().split("%NEWLINE%"))
players.add(new WrappedGameProfile(uuid, string));
ping.setPlayers(players);
//if (settings.hasCustomIcon() && image != null) ping.setFavicon(image);
}
});
if (settings.hasCustomPlayerCountMessage()) {
ping.setVersionProtocol(1);
ping.setVersionName(settings.getPlayerCountMessage()
.replace("%ONLINE%", Integer.toString(plugin.getServer().getOnlinePlayers().size()))
.replace("%MAX%", Integer.toString(plugin.getServer().getMaxPlayers())));
}
final List<WrappedGameProfile> players = new ArrayList<>();
for (final String string : settings.getPlayerCountHoverMessage().split("%NEWLINE%"))
players.add(new WrappedGameProfile(uuid, string));
ping.setPlayers(players);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void serverListPing(final ServerListPingEvent event) {
if (settings.isMaintenance() && settings.hasCustomIcon() && plugin.getFavicon() != null)
event.setServerIcon(plugin.getFavicon());
}
/*@Override
public boolean loadIcon() {
try {
image = WrappedServerPing.CompressedImage.fromPng(ImageIO.read(new File("maintenance-icon.png")));
} catch (final Exception e) {
pl.getLogger().warning("Could not load 'maintenance-icon.png' - did you create one in your Spigot folder (not the plugins folder)?");
if (pl.getApi().getSettings().debugEnabled())
e.printStackTrace();
return false;
// Set the icon here, not in the packet listener, as it's broken for 1.13+ clients on older server versions
if (settings.isMaintenance() && settings.hasCustomIcon() && plugin.getFavicon() != null) {
try {
event.setServerIcon(plugin.getFavicon());
} catch (final UnsupportedOperationException ignored) {
// Thrown in a ping that has not been requested through a status packet, we can just ignore that case
}
}
return true;
}*/
}
}
@@ -41,7 +41,12 @@ public final class ServerListPingListener implements Listener {
event.setMaxPlayers(0);
event.setMotd(settings.getRandomPingMessage());
if (settings.hasCustomIcon() && plugin.getFavicon() != null)
event.setServerIcon(plugin.getFavicon());
if (settings.hasCustomIcon() && plugin.getFavicon() != null) {
try {
event.setServerIcon(plugin.getFavicon());
} catch (final UnsupportedOperationException ignored) {
// Thrown in a ping that has not been requested through a status packet, we can just ignore that case
}
}
}
}
+3 -9
View File
@@ -4,9 +4,9 @@
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</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0</version>
<version>3.0.2</version>
</parent>
<artifactId>maintenance-sponge</artifactId>
@@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>eu.kennytv</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-core</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
@@ -25,11 +25,5 @@
<version>7.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-sponge</artifactId>
<version>1.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
@@ -36,8 +36,8 @@ import eu.kennytv.maintenance.sponge.util.LoggerWrapper;
import eu.kennytv.maintenance.sponge.util.SpongeOfflinePlayerInfo;
import eu.kennytv.maintenance.sponge.util.SpongeSenderInfo;
import eu.kennytv.maintenance.sponge.util.SpongeTask;
import org.bstats.sponge.Metrics2;
import org.spongepowered.api.Game;
import org.spongepowered.api.Platform;
import org.spongepowered.api.Server;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.config.ConfigDir;
@@ -45,6 +45,7 @@ import org.spongepowered.api.event.EventManager;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.GameReloadEvent;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GameStoppingEvent;
import org.spongepowered.api.network.status.Favicon;
import org.spongepowered.api.plugin.Dependency;
import org.spongepowered.api.plugin.Plugin;
@@ -73,19 +74,14 @@ import java.util.stream.Collectors;
* @since 3.0
*/
@Plugin(id = "maintenancesponge", name = "MaintenanceSponge", version = MaintenanceVersion.VERSION, authors = "KennyTV",
description = "Enable maintenance mode with a custom maintenance motd and icon.", url = "https://www.spigotmc.org/resources/maintenance.40699/",
description = "Enable maintenance mode with a custom maintenance motd and icon.", url = "https://ore.spongepowered.org/KennyTV/Maintenance",
dependencies = @Dependency(id = "serverlistplus", optional = true))
public final class MaintenanceSpongePlugin extends MaintenancePlugin {
private Logger logger;
private Favicon favicon;
@Inject
private Game game;
@Inject
private PluginContainer container;
@Inject
private Metrics2 metrics;
@Inject
@ConfigDir(sharedRoot = false)
@Inject private Game game;
@Inject private PluginContainer container;
@Inject @ConfigDir(sharedRoot = false)
private File dataFolder;
@Inject
@@ -97,7 +93,8 @@ public final class MaintenanceSpongePlugin extends MaintenancePlugin {
public void onEnable(final GameInitializationEvent event) {
logger = new LoggerWrapper(container.getLogger());
settings = new Settings(this, "mysql", "proxied-maintenance-servers", "fallback", "playercountmessage", "enable-playercountmessage");
settings = new Settings(this, "mysql", "proxied-maintenance-servers", "fallback",
"playercountmessage", "enable-playercountmessage");
sendEnableMessage();
@@ -107,7 +104,8 @@ public final class MaintenanceSpongePlugin extends MaintenancePlugin {
final EventManager em = game.getEventManager();
em.registerListeners(this, new ClientPingServerListener(this, settings));
em.registerListeners(this, new ClientConnectionListener(this, settings));
em.registerListeners(this, new ClientPingServerListener(this, settings));
continueLastEndtimer();
// ServerListPlus integration
game.getPluginManager().getPlugin("serverlistplus").ifPresent(slpContainer -> slpContainer.getInstance().ifPresent(serverListPlus -> {
@@ -117,6 +115,11 @@ public final class MaintenanceSpongePlugin extends MaintenancePlugin {
}));
}
@Listener
public void onDisable(final GameStoppingEvent event) {
disable();
}
@Listener
public void reload(final GameReloadEvent event) {
settings.reloadConfigs();
@@ -206,7 +209,7 @@ public final class MaintenanceSpongePlugin extends MaintenancePlugin {
@Override
public String getServerVersion() {
return game.getPlatform().getImplementation().getName();
return game.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getVersion().orElse("woop wooop");
}
@Override
+42 -4
View File
@@ -4,9 +4,9 @@
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</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0</version>
<version>3.0.2</version>
</parent>
<artifactId>maintenance-velocity</artifactId>
@@ -14,16 +14,54 @@
<dependencies>
<dependency>
<groupId>eu.kennytv</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-core-proxy</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<!-- Velocity does not shade snakeyaml -->
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.23</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<!-- Needed to relocate stuff in Velocity module, but not in the core one -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.zaxxer.hikari</pattern>
<shadedPattern>eu.kennytv.lib.hikari</shadedPattern>
</relocation>
<relocation>
<pattern>org.yaml.snakeyaml</pattern>
<shadedPattern>eu.kennytv.lib.snakeyaml</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -27,6 +27,7 @@ import com.velocitypowered.api.event.player.ServerPreConnectEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
import com.velocitypowered.api.event.proxy.ProxyReloadEvent;
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
@@ -54,7 +55,7 @@ import eu.kennytv.maintenance.velocity.util.VelocityTask;
import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.kyori.text.serializer.ComponentSerializers;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import javax.imageio.ImageIO;
import java.io.File;
@@ -104,6 +105,8 @@ public final class MaintenanceVelocityPlugin extends MaintenanceProxyPlugin {
em.register(this, ServerPreConnectEvent.class, PostOrder.LAST, new ServerConnectListener(this, settingsProxy));
em.register(this, new LoginListener(this, settingsProxy));
continueLastEndtimer();
// ServerListPlus integration
server.getPluginManager().getPlugin("serverlistplus").ifPresent(slpContainer -> slpContainer.getInstance().ifPresent(serverListPlus -> {
serverListPlusHook = new ServerListPlusHook(serverListPlus);
@@ -118,13 +121,18 @@ public final class MaintenanceVelocityPlugin extends MaintenanceProxyPlugin {
logger.info("Reloaded config files!");
}
@Subscribe
public void onDisable(final ProxyShutdownEvent event) {
disable();
}
@Override
public void sendUpdateNotification(final SenderInfo sender) {
final TextComponent tc1 = translate(getPrefix());
final TextComponent tc2 = translate("§cDownload it at: §6https://www.spigotmc.org/resources/maintenance.40699/");
final TextComponent click = translate(" §7§l§o(CLICK ME)");
click.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.spigotmc.org/resources/maintenance.40699/"));
click.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("§aDownload the latest version")));
click.clickEvent(ClickEvent.openUrl("https://www.spigotmc.org/resources/maintenance.40699/"));
click.hoverEvent(HoverEvent.showText(TextComponent.of("§aDownload the latest version")));
tc1.append(tc2);
tc1.append(click);
((VelocitySenderInfo) sender).sendMessage(tc1);
@@ -187,7 +195,8 @@ public final class MaintenanceVelocityPlugin extends MaintenanceProxyPlugin {
@Override
public String getServer(final SenderInfo sender) {
final Optional<Player> player = server.getPlayer(sender.getUuid());
return player.map(p -> p.getCurrentServer().get().getServerInfo().getName()).orElse("");
if (!player.isPresent() || player.get().getCurrentServer().isPresent()) return "";
return player.get().getCurrentServer().get().getServerInfo().getName();
}
@Override
@@ -253,6 +262,6 @@ public final class MaintenanceVelocityPlugin extends MaintenanceProxyPlugin {
}
public TextComponent translate(final String s) {
return ComponentSerializers.LEGACY.deserialize(s);
return LegacyComponentSerializer.INSTANCE.deserialize(s);
}
}
@@ -61,8 +61,8 @@ public final class MaintenanceVelocityCommand extends MaintenanceProxyCommand im
@Override
protected void sendUpdateMessage(final SenderInfo sender) {
final TextComponent tc = TextComponent.builder("").append(plugin.translate("§6× §8[§aUpdate§8]"))
.clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/maintenance forceupdate"))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, plugin.translate("§aClick here to update the plugin")))
.clickEvent(ClickEvent.runCommand("/maintenance forceupdate"))
.hoverEvent(HoverEvent.showText(plugin.translate("§aClick here to update the plugin")))
.append(plugin.translate(" §8(§7Or use the command §c/maintenance forceupdate§8)")).build();
((VelocitySenderInfo) sender).sendMessage(tc);
}
@@ -70,8 +70,8 @@ public final class MaintenanceVelocityCommand extends MaintenanceProxyCommand im
@Override
public void sendDumpMessage(final SenderInfo sender, final String url) {
final TextComponent clickText = TextComponent.builder("").append(plugin.translate(plugin.getPrefix() + "§7Click here to copy the link."))
.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, url))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, plugin.translate("§aClick here to copy the link"))).build();
.clickEvent(ClickEvent.suggestCommand(url))
.hoverEvent(HoverEvent.showText(plugin.translate("§aClick here to copy the link"))).build();
((VelocitySenderInfo) sender).sendMessage(clickText);
}
@@ -43,6 +43,8 @@ public final class ServerConnectListener implements EventHandler<ServerPreConnec
if (!event.getResult().isAllowed()) return;
final Player player = event.getPlayer();
if (!event.getResult().getServer().isPresent()) return;
final RegisteredServer target = event.getResult().getServer().get();
if (!plugin.isMaintenance(target)) return;
if (plugin.hasPermission(player, "bypass") || settings.getWhitelistedPlayers().containsKey(player.getUniqueId())) return;
@@ -22,7 +22,7 @@ import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
import eu.kennytv.maintenance.core.util.SenderInfo;
import net.kyori.text.TextComponent;
import net.kyori.text.serializer.ComponentSerializers;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import java.util.UUID;
@@ -50,7 +50,7 @@ public final class VelocitySenderInfo implements SenderInfo {
@Override
public void sendMessage(final String message) {
sender.sendMessage(ComponentSerializers.LEGACY.deserialize(message));
sender.sendMessage(LegacyComponentSerializer.INSTANCE.deserialize(message));
}
@Override
@@ -21,7 +21,7 @@ package eu.kennytv.maintenance.velocity.util;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import eu.kennytv.maintenance.api.proxy.Server;
import net.kyori.text.TextComponent;
import net.kyori.text.serializer.ComponentSerializers;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
public final class VelocityServer implements Server {
private final RegisteredServer server;
@@ -42,7 +42,7 @@ public final class VelocityServer implements Server {
@Override
public void broadcast(final String message) {
final TextComponent s = ComponentSerializers.LEGACY.deserialize(message);
final TextComponent s = LegacyComponentSerializer.INSTANCE.deserialize(message);
server.getPlayersConnected().forEach(p -> p.sendMessage(s));
}
+6 -26
View File
@@ -4,9 +4,9 @@
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>
<groupId>eu.kennytv</groupId>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0</version>
<version>3.0.2</version>
<packaging>pom</packaging>
<name>Maintenance</name>
@@ -43,6 +43,10 @@
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
@@ -59,10 +63,6 @@
<id>dmulloy2-repo</id>
<url>http://repo.dmulloy2.net/nexus/repository/public/</url>
</repository>
<repository>
<id>bstats-repo</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
<repository>
<id>minecrell</id>
<url>https://repo.minecrell.net/snapshots</url>
@@ -82,26 +82,6 @@
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.zaxxer.hikari</pattern>
<shadedPattern>eu.kennytv.lib.hikari</shadedPattern>
</relocation>
<relocation>
<pattern>org.yaml.snakeyaml</pattern>
<shadedPattern>eu.kennytv.lib.snakeyaml</shadedPattern>
</relocation>
<!-- Relocate slf4j to prevent issues on Bungee (except Logger class to prevent false relocation of injected Sponge/Velocity logger) -->
<relocation>
<pattern>org.slf4j</pattern>
<shadedPattern>org.slf4j.other</shadedPattern>
<excludes>
<exclude>org.slf4j.Logger</exclude>
</excludes>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>