Skip to content

Commit

Permalink
3.0.2 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv authored May 17, 2019
2 parents 7e249fa + 915b43d commit 77e1444
Show file tree
Hide file tree
Showing 27 changed files with 185 additions and 72 deletions.
8 changes: 8 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# 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))
Expand Down
2 changes: 1 addition & 1 deletion maintenance-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>

<artifactId>maintenance-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion maintenance-build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>

<artifactId>maintenance-build</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions maintenance-bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>

<artifactId>maintenance-bungee</artifactId>
Expand All @@ -29,7 +29,7 @@
<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>
Expand Down
2 changes: 1 addition & 1 deletion maintenance-core-proxy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>

<artifactId>maintenance-core-proxy</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion maintenance-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>eu.kennytv.maintenance</groupId>
<artifactId>maintenance-parent</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>

<artifactId>maintenance-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -165,7 +166,8 @@ 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();
Expand Down Expand Up @@ -216,11 +218,8 @@ public String pasteDump() {
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) {
Expand Down Expand Up @@ -279,6 +278,12 @@ public UUID checkUUID(final SenderInfo sender, final String s) {
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]+");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
import java.util.logging.Level;

public class Settings implements ISettings {
private static final int CURRENT_CONFIG_VERSION = 1;
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<>();
private final String[] unsupportedFields;
protected boolean maintenance;
private Set<Integer> broadcastIntervals;
private List<String> pingMessages;
private List<String> timerSpecificPingMessages;
private String playerCountMessage;
private String playerCountHoverMessage;
private String languageName;
Expand Down Expand Up @@ -147,6 +148,8 @@ private void loadSettings() {
updateConfig();

pingMessages = config.getStringList("pingmessages");
if (config.getBoolean("enable-timerspecific-messages"))
timerSpecificPingMessages = config.getStringList("timerspecific-pingmessages");
maintenance = config.getBoolean("maintenance-enabled");
customPlayerCountMessage = config.getBoolean("enable-playercountmessage");
customMaintenanceIcon = config.getBoolean("custom-maintenance-icon");
Expand Down Expand Up @@ -323,8 +326,15 @@ public String getMessage(final String path, final String def) {
}

public String getRandomPingMessage() {
if (pingMessages.isEmpty()) return "";
final String s = pingMessages.size() == 1 ? pingMessages.get(0) : pingMessages.get(RANDOM.nextInt(pingMessages.size()));
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"));
}

Expand Down Expand Up @@ -396,6 +406,10 @@ public boolean isSaveEndtimerOnStop() {
return saveEndtimerOnStop;
}

public boolean hasTimerSpecificPingMessages() {
return timerSpecificPingMessages != null;
}

public long getSavedEndtimer() {
return savedEndtimer;
}
Expand All @@ -415,6 +429,13 @@ public List<String> getPingMessages() {
return pingMessages;
}

/**
* May be null
*/
public List<String> getTimerSpecificPingMessages() {
return timerSpecificPingMessages;
}

public Set<Integer> getBroadcastIntervals() {
return broadcastIntervals;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,49 @@
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,57 @@
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);
return;
}

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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,33 @@
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;
}

Expand All @@ -61,31 +73,37 @@ public void execute(final SenderInfo sender, final String[] args) {
}

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;
Expand Down
Loading

0 comments on commit 77e1444

Please sign in to comment.