...
 
Commits (8)
Changelog
=========
v2.1 (2019/07/15)
-----------------
v2.2.0 (2019/08/03)
-------------------
* Added automatic update checker
* Separated exceptions for greentext and orangetext
* Stopped greenifier from greenifying empty messages
v2.1.0 (2019/07/15)
-------------------
* Added persistent map of player status
* Added message if player is already enabled/disabled
* Added command aliases: `bgt`, `bukkitgreentext`
* Re-write command parser to be more efficient
* Re-wrote command parser to be more efficient
v2.0 (2019/07/05)
-----------------
v2.0.0 (2019/07/05)
-------------------
* Initial (re-)release
......@@ -67,7 +67,6 @@ when I debug my subpar code.
### Some to-do
* Separate exceptions for orangetext and greentext
* Toggle orangetext separately from greentext
* Support for reply reference (`>>31337`) and board reference (`>>>/out/`)
......
......@@ -6,7 +6,7 @@
<name>BukkitGreentext</name>
<description>Add 4chan-style quoting to Minecraft server chat</description>
<version>2.1</version>
<version>2.2.0</version>
<url>http://www.gitlab.com/ssterling/bukkitgreentext/</url>
<properties>
......@@ -21,6 +21,7 @@
<license>
<name>MIT</name>
<url>https://choosealicense.com/licenses/mit/</url>
<distribution>repo</distribution>
</license>
</licenses>
......@@ -58,7 +59,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.14.3-R0.1-SNAPSHOT</version>
<version>1.14.4-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
......
......@@ -26,7 +26,13 @@ package net.ssterling.BukkitGreentext;
import java.util.HashMap;
import java.util.UUID;
import java.util.List;
import java.io.File;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.PluginManager;
......@@ -41,7 +47,7 @@ import org.bstats.bukkit.Metrics;
/**
* @author Seth Price <ssterling AT firemail DOT cc>
* @version 2.0
* @version 2.2
* @since 1.0
*/
public class BukkitGreentext extends JavaPlugin
......@@ -68,6 +74,16 @@ public class BukkitGreentext extends JavaPlugin
*/
private static boolean is_debug;
/**
* Whether to check for updates on startup.
*/
private static boolean check_for_updates;
/**
* Spigot project ID (for update checker).
*/
private static final int PROJECT_ID = 55295;
/**
* The file pointer for the persistent hashmap.
*/
......@@ -123,6 +139,37 @@ public class BukkitGreentext extends JavaPlugin
}
}
/* Likewise, add `check-for-updates' if nonexistent (added in version 2.2) */
check_for_updates = config.getBoolean("check-for-updates");
if (!(config.isSet("check-for-updates"))) {
getLogger().config("Updating configuration file with new `check-for-updates' key...");
/* Like above, `check_for_updates' holds the default value */
config.set("check-for-updates", check_for_updates);
try {
this.saveConfig();
} catch (Throwable ex) {
getLogger().warning("Failed to update configuration file.");
ex.printStackTrace();
}
}
/* Finally, separate orangetext and greentext exceptions if not yet done */
if (config.isSet("exceptions") &&
!(config.isSet("greentext-exceptions") || config.isSet("orangetext-exceptions"))) {
getLogger().config("Updating configuration file to have separate `greentext-exception' and `orangetext-exception' lists (cloning contents of `exceptions)");
/* Clone the values of `exceptions' to the specific lists and remove `exceptions' */
List<String> exceptions_tmp = config.getStringList("exceptions");
config.set("greentext-exceptions", exceptions_tmp);
config.set("orangetext-exceptions", exceptions_tmp);
config.set("exceptions", null);
try {
this.saveConfig();
} catch (Throwable ex) {
getLogger().warning("Failed to update configuration file.");
ex.printStackTrace();
}
}
getLogger().finest("Initialising player hashmap...");
enabled_for_player = new HashMap<UUID, Boolean>();
......@@ -172,6 +219,29 @@ public class BukkitGreentext extends JavaPlugin
enabled_by_default = config.getBoolean("enabled-by-default");
getLogger().info("Successfully initialised " + pdf.getName() + " v" + pdf.getVersion());
/* Check for updates on the Spigot resource page
* (XXX this will work even if current version is newer, i.e. unreleased SNAPSHOT;
* this is to keep things simple as 99.8% of people won't be building something
* like this from the repo) */
if (check_for_updates) {
getLogger().fine("Checking for updates...");
String current_version = pdf.getVersion();
try {
URL update_url = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + PROJECT_ID);
URLConnection update_conn = update_url.openConnection();
String new_version = new BufferedReader(new InputStreamReader(update_conn.getInputStream())).readLine();
if (!(new_version.equals(current_version))) {
getLogger().info("New version " + new_version + " found (currently on " + current_version + "; download at: <https://www.spigotmc.org/resources/" + PROJECT_ID + "/>");
} else {
getLogger().info("No new version found");
}
} catch (Throwable ex) {
getLogger().warning("Failed to check for updates");
ex.printStackTrace();
}
}
}
@Override
......@@ -269,11 +339,17 @@ public class BukkitGreentext extends JavaPlugin
if (message.startsWith(">")) {
getLogger().fine("Message begins with `>'; checking whether it's greentext: `" + message + "'");
/* Make sure the message isn't just a `>' */
if (message.length() == 1) {
getLogger().fine("Aforementioned message contains only a `>'; ignoring");
return false;
}
/* Cycles through exceptions in `config.yml'.
* For example, if `:' is listed as an exception,
* any message starting with `>:' isn't greenified,
* such as in emoticons, e.g. `>:('. */
for (String exception : config.getStringList("exceptions")) {
for (String exception : config.getStringList("greentext-exceptions")) {
if (message.startsWith(">" + exception)) {
getLogger().fine("Aforementioned message begins with exception `>" + exception + "'; ignoring");
return false;
......@@ -298,9 +374,14 @@ public class BukkitGreentext extends JavaPlugin
getLogger().finest("Message passed to `isValidOrangetext()'; checking whether it ends with `<': `" + message + "'");
if (message.endsWith("<")) {
getLogger().fine("Message ends with `<'; checking whether it's orangetext: `" + message + "'");
/* Similarly, make sure the message isn't just a `<' */
if (message.length() == 1) {
getLogger().fine("Aforementioned message contains only a `<'; ignoring");
return false;
}
/* Same concept as in isValidGreentext() */
for (String exception : config.getStringList("exceptions")) {
for (String exception : config.getStringList("orangetext-exceptions")) {
if (message.endsWith(exception + "<")) {
getLogger().fine("Aforementioned message ends with exception `" + exception + "<'; ignoring");
return false;
......
check-for-permission: false
allow-orangetext: true
enabled-by-default: true
exceptions:
greentext-exceptions:
- ':'
- '_'
- '.'
orangetext-exceptions:
- ':'
- '_'
- '.'
debug: false
check-for-updates: true
name: BukkitGreentext
author: ssterling
version: 2.1
version: 2.2.0
description: Add 4chan-style quoting to Minecraft server chat
website: http://www.gitlab.com/ssterling/bukkitgreentext/
......