diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..27fa0f7 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,27 @@ +name: Java CI + +on: + push: + pull_request: + +jobs: + build: + name: Build + + runs-on: ubuntu-latest + + strategy: + matrix: + java-version: [1.8, 11] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup JDK ${{ matrix.java-version }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java-version }} + + - name: Build + run: mvn -B package diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e965709..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -sudo: false - -language: java -jdk: - - openjdk8 - - openjdk11 - -cache: - directories: - - $HOME/.m2 - -script: - - mvn clean install -B -V diff --git a/README.md b/README.md index 024cd54..0f8efc1 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,13 @@ -# ViaChatFixer -[![Build Status](https://travis-ci.org/MrMicky-FR/ViaChatFixer.svg?branch=master)](https://travis-ci.org/MrMicky-FR/ViaChatFixer) +# ViaChatFixer -ViaChatFixer is a Spigot plugin that allow 1.11+ players to have longer chat messages on 1.8-1.10 servers with ViaVersion +[![Java CI](https://github.com/MrMicky-FR/ViaChatFixer/actions/workflows/build.yml/badge.svg)](https://github.com/MrMicky-FR/ViaChatFixer/actions/workflows/build.yml) -In Minecraft 1.11, the maximum messages length has gone from 100 characters to 256 characters. -So if your server is under 1.11, 1.11 and higher players will have their chat messages cut at 100 characters. +ViaChatFixer is a Spigot plugin that allow 1.11+ players to have longer chat messages on 1.8-1.10 servers with ViaVersion -This plugin fix this problem, so 1.11 and higher players will able to send longer chat messages up to 256 characters :) +In Minecraft 1.11, the maximum messages length has gone from 100 characters to 256 characters. So if your server is under 1.11, 1.11 and higher +players will have their chat messages cut at 100 characters. -**The plugin is currently in beta, so if you find bugs please open an issue** +This plugin fix this problem, so 1.11 and higher players will be able to send longer chat messages up to 256 characters. ## Downloads @@ -17,12 +16,13 @@ You can download releases and find more information on [SpigotMC](https://www.sp ## Installation Just put the ViaChatFixer jar in your plugins folder. -Currently this plugin only works on Spigot, but Sponge support should be added soon. -This plugin can work with BungeeCord as long as ViaVersion and this plugin are on the Spigot servers. -**All players online during a reload will not be able to have longer chat messages until they reconnect** +ViaChatFixer currently supports ViaVersion v3.0 or higher. + +All players online during a reload will not be able to have longer chat messages until they reconnect. + +## Supported Platforms -## Planned features +ViaChatFixer can be installed on Bukkit/Spigot/Paper servers or on Sponge servers. -* Sponge support -* BungeeCord support _(not sure)_ +If you are using a proxy, ViaVersion and ViaChatFixer must be installed on the backend servers. diff --git a/bukkit/pom.xml b/bukkit/pom.xml index dbacd01..99fdbf2 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -7,7 +7,7 @@ fr.mrmicky viachatfixer - 0.3.0 + 1.0.0 viachatfixer-bukkit @@ -22,16 +22,16 @@ - - org.spigotmc - spigot-api - 1.8.8-R0.1-SNAPSHOT - provided - fr.mrmicky viachatfixer-common ${project.version} + compile + + + org.spigotmc + spigot-api + 1.10.2-R0.1-SNAPSHOT provided diff --git a/bukkit/src/main/java/fr/mrmicky/viachatfixer/bukkit/ViaChatFixerBukkit.java b/bukkit/src/main/java/fr/mrmicky/viachatfixer/bukkit/ViaChatFixerBukkit.java index 1c92792..0b4127a 100644 --- a/bukkit/src/main/java/fr/mrmicky/viachatfixer/bukkit/ViaChatFixerBukkit.java +++ b/bukkit/src/main/java/fr/mrmicky/viachatfixer/bukkit/ViaChatFixerBukkit.java @@ -1,8 +1,9 @@ package fr.mrmicky.viachatfixer.bukkit; -import fr.mrmicky.viachatfixer.ViaChatFixerPlatform; -import fr.mrmicky.viachatfixer.handlers.ChatHandler; -import fr.mrmicky.viachatfixer.handlers.via.ViaChatHandler; +import fr.mrmicky.viachatfixer.common.ChatHandler; +import fr.mrmicky.viachatfixer.common.ViaChatFixerPlatform; +import fr.mrmicky.viachatfixer.common.logger.JavaLoggerAdapter; +import fr.mrmicky.viachatfixer.common.logger.LoggerAdapter; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -10,39 +11,46 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.plugin.java.JavaPlugin; -import java.util.logging.Level; +public final class ViaChatFixerBukkit extends JavaPlugin implements Listener, ViaChatFixerPlatform { -public final class ViaChatFixerBukkit extends JavaPlugin implements ViaChatFixerPlatform, Listener { + private final ChatHandler chatHandler = new ChatHandler(this); - private ChatHandler chatHandler; + private LoggerAdapter logger; + + @Override + public void onLoad() { + this.logger = new JavaLoggerAdapter(getLogger()); + } @Override public void onEnable() { if (getServer().getPluginManager().getPlugin("ViaVersion") == null) { - getLogger().severe("ViaVersion is not installed"); + this.logger.error("You need to install ViaVersion to use ViaChatFixer"); getServer().getPluginManager().disablePlugin(this); return; } - chatHandler = new ViaChatHandler(this); - // Only load when ViaVersion is loaded getServer().getScheduler().runTask(this, () -> { try { - chatHandler.init(); + this.chatHandler.init(); + + getServer().getPluginManager().registerEvents(this, this); } catch (Exception e) { - getLogger().log(Level.SEVERE, "An error occurred while enabling", e); + this.logger.error("An error occurred during initialization", e); getServer().getPluginManager().disablePlugin(this); - return; } - - getServer().getPluginManager().registerEvents(this, this); }); } + @Override + public LoggerAdapter getLoggerAdapter() { + return this.logger; + } + @EventHandler(priority = EventPriority.LOWEST) public void onAsyncPlayerChat(AsyncPlayerChatEvent e) { - String message = chatHandler.handle(e.getPlayer().getUniqueId()); + String message = this.chatHandler.handle(e.getPlayer().getUniqueId()); if (message != null) { e.setMessage(message); @@ -51,7 +59,7 @@ public void onAsyncPlayerChat(AsyncPlayerChatEvent e) { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerCommand(PlayerCommandPreprocessEvent e) { - String message = chatHandler.handle(e.getPlayer().getUniqueId()); + String message = this.chatHandler.handle(e.getPlayer().getUniqueId()); if (message != null) { e.setMessage(message); diff --git a/common/pom.xml b/common/pom.xml index 7ec7888..9e7a947 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -7,11 +7,27 @@ fr.mrmicky viachatfixer - 0.3.0 + 1.0.0 viachatfixer-common ViaChatFixerCommon + + + viaversion-repo + https://repo.viaversion.com/ + + + + + + us.myles + viaversion + 3.0.0 + provided + + + diff --git a/common/src/main/java/fr/mrmicky/viachatfixer/ViaChatFixerPlatform.java b/common/src/main/java/fr/mrmicky/viachatfixer/ViaChatFixerPlatform.java deleted file mode 100644 index 5cc2d2f..0000000 --- a/common/src/main/java/fr/mrmicky/viachatfixer/ViaChatFixerPlatform.java +++ /dev/null @@ -1,8 +0,0 @@ -package fr.mrmicky.viachatfixer; - -import java.util.logging.Logger; - -public interface ViaChatFixerPlatform { - - Logger getLogger(); -} diff --git a/common/src/main/java/fr/mrmicky/viachatfixer/handlers/via/ViaChatHandler.java b/common/src/main/java/fr/mrmicky/viachatfixer/common/ChatHandler.java similarity index 78% rename from common/src/main/java/fr/mrmicky/viachatfixer/handlers/via/ViaChatHandler.java rename to common/src/main/java/fr/mrmicky/viachatfixer/common/ChatHandler.java index 5ed7e67..db4b1e4 100644 --- a/common/src/main/java/fr/mrmicky/viachatfixer/handlers/via/ViaChatHandler.java +++ b/common/src/main/java/fr/mrmicky/viachatfixer/common/ChatHandler.java @@ -1,7 +1,5 @@ -package fr.mrmicky.viachatfixer.handlers.via; +package fr.mrmicky.viachatfixer.common; -import fr.mrmicky.viachatfixer.ViaChatFixerPlatform; -import fr.mrmicky.viachatfixer.handlers.ChatHandler; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.protocol.Protocol; @@ -17,20 +15,21 @@ import java.util.Set; import java.util.UUID; -public class ViaChatHandler implements ChatHandler { +public class ChatHandler { private final Set unknownPlayers = new HashSet<>(); private final ViaChatFixerPlatform platform; - public ViaChatHandler(ViaChatFixerPlatform platform) { + private boolean enabled = false; + + public ChatHandler(ViaChatFixerPlatform platform) { this.platform = platform; } - @Override public void init() { if (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.v1_11.getId()) { - platform.getLogger().warning("This plugin is not required on 1.11+ servers, you can just remove it :)"); + this.platform.getLoggerAdapter().warn("This plugin is not required on 1.11+ servers, you can just remove it."); return; } @@ -72,34 +71,46 @@ public void registerMap() { }); } }, true); + + this.enabled = true; } - @Override public String handle(UUID uuid) { + if (!this.enabled) { + return null; + } + + ChatTracker chatTracker = getChatTracker(uuid); + + if (chatTracker == null) { + return null; + } + + String message = chatTracker.getLastMessage(); + + chatTracker.reset(); + + return message; + } + + private ChatTracker getChatTracker(UUID uuid) { UserConnection connection = Via.getManager().getConnection(uuid); if (connection == null) { - if (unknownPlayers.add(uuid)) { - platform.getLogger().warning("Unknown connection for player with UUID " + uuid); + if (this.unknownPlayers.add(uuid)) { + this.platform.getLoggerAdapter().warn("Unknown connection for player with UUID " + uuid); } + return null; } ChatTracker chatTracker = connection.get(ChatTracker.class); - if (chatTracker == null || chatTracker.getLastMessage() == null) { - return null; - } - - if (!chatTracker.isValid(100)) { + if (chatTracker != null && !chatTracker.isValid(100)) { chatTracker.reset(); return null; } - String message = chatTracker.getLastMessage(); - - chatTracker.reset(); - - return message; + return chatTracker; } } diff --git a/common/src/main/java/fr/mrmicky/viachatfixer/handlers/via/ChatTracker.java b/common/src/main/java/fr/mrmicky/viachatfixer/common/ChatTracker.java similarity index 55% rename from common/src/main/java/fr/mrmicky/viachatfixer/handlers/via/ChatTracker.java rename to common/src/main/java/fr/mrmicky/viachatfixer/common/ChatTracker.java index 67bfefd..cd01b2a 100644 --- a/common/src/main/java/fr/mrmicky/viachatfixer/handlers/via/ChatTracker.java +++ b/common/src/main/java/fr/mrmicky/viachatfixer/common/ChatTracker.java @@ -1,4 +1,4 @@ -package fr.mrmicky.viachatfixer.handlers.via; +package fr.mrmicky.viachatfixer.common; import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.UserConnection; @@ -13,20 +13,24 @@ public ChatTracker(UserConnection user) { } public String getLastMessage() { - return lastMessage; + return this.lastMessage; } public boolean isValid(int time) { - return (System.currentTimeMillis() - lastMessageTime) < time; + if (this.lastMessage == null) { + return false; + } + + return (System.currentTimeMillis() - this.lastMessageTime) < time; } public void updateLastMessage(String message) { - lastMessage = message; - lastMessageTime = System.currentTimeMillis(); + this.lastMessage = message; + this.lastMessageTime = System.currentTimeMillis(); } public void reset() { - lastMessage = null; - lastMessageTime = 0; + this.lastMessage = null; + this.lastMessageTime = 0; } } diff --git a/common/src/main/java/fr/mrmicky/viachatfixer/common/ViaChatFixerPlatform.java b/common/src/main/java/fr/mrmicky/viachatfixer/common/ViaChatFixerPlatform.java new file mode 100644 index 0000000..9ab610d --- /dev/null +++ b/common/src/main/java/fr/mrmicky/viachatfixer/common/ViaChatFixerPlatform.java @@ -0,0 +1,9 @@ +package fr.mrmicky.viachatfixer.common; + +import fr.mrmicky.viachatfixer.common.logger.LoggerAdapter; + +public interface ViaChatFixerPlatform { + + LoggerAdapter getLoggerAdapter(); + +} diff --git a/common/src/main/java/fr/mrmicky/viachatfixer/common/logger/JavaLoggerAdapter.java b/common/src/main/java/fr/mrmicky/viachatfixer/common/logger/JavaLoggerAdapter.java new file mode 100644 index 0000000..763b8fb --- /dev/null +++ b/common/src/main/java/fr/mrmicky/viachatfixer/common/logger/JavaLoggerAdapter.java @@ -0,0 +1,38 @@ +package fr.mrmicky.viachatfixer.common.logger; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class JavaLoggerAdapter implements LoggerAdapter { + + private final Logger logger; + + public JavaLoggerAdapter(Logger logger) { + this.logger = logger; + } + + @Override + public void info(String message) { + this.logger.info(message); + } + + @Override + public void warn(String message) { + this.logger.warning(message); + } + + @Override + public void warn(String message, Throwable throwable) { + this.logger.log(Level.WARNING, message, throwable); + } + + @Override + public void error(String message) { + this.logger.severe(message); + } + + @Override + public void error(String message, Throwable throwable) { + this.logger.log(Level.SEVERE, message, throwable); + } +} diff --git a/common/src/main/java/fr/mrmicky/viachatfixer/common/logger/LoggerAdapter.java b/common/src/main/java/fr/mrmicky/viachatfixer/common/logger/LoggerAdapter.java new file mode 100644 index 0000000..020d94c --- /dev/null +++ b/common/src/main/java/fr/mrmicky/viachatfixer/common/logger/LoggerAdapter.java @@ -0,0 +1,14 @@ +package fr.mrmicky.viachatfixer.common.logger; + +public interface LoggerAdapter { + + void info(String message); + + void warn(String message); + + void warn(String message, Throwable throwable); + + void error(String message); + + void error(String message, Throwable throwable); +} diff --git a/common/src/main/java/fr/mrmicky/viachatfixer/handlers/ChatHandler.java b/common/src/main/java/fr/mrmicky/viachatfixer/handlers/ChatHandler.java deleted file mode 100644 index a4fd6c0..0000000 --- a/common/src/main/java/fr/mrmicky/viachatfixer/handlers/ChatHandler.java +++ /dev/null @@ -1,10 +0,0 @@ -package fr.mrmicky.viachatfixer.handlers; - -import java.util.UUID; - -public interface ChatHandler { - - void init() throws Exception; - - String handle(UUID uuid); -} diff --git a/pom.xml b/pom.xml index 444a907..4a04e74 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ fr.mrmicky viachatfixer - 0.3.0 + 1.0.0 pom ViaChatFixer @@ -14,8 +14,7 @@ common bukkit - + sponge universal @@ -35,22 +34,12 @@ + + + src/main/resources + true + + - - - viaversion-repo - https://repo.viaversion.com/ - - - - - - us.myles - viaversion - 3.0.0 - provided - - - diff --git a/sponge/pom.xml b/sponge/pom.xml new file mode 100644 index 0000000..0550ce6 --- /dev/null +++ b/sponge/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + + + fr.mrmicky + viachatfixer + 1.0.0 + + + viachatfixer-sponge + + ViaChatFixerSponge + + + + + org.codehaus.mojo + templating-maven-plugin + 1.0.0 + + + filter-src + + filter-sources + + + + + + + + + + sponge-repo + https://repo.spongepowered.org/maven/ + + + + + + fr.mrmicky + viachatfixer-common + ${project.version} + compile + + + org.spongepowered + spongeapi + 5.1.0 + provided + + + + diff --git a/sponge/src/main/java-templates/fr/mrmicky/viachatfixer/sponge/ViaChatFixerVersion.java b/sponge/src/main/java-templates/fr/mrmicky/viachatfixer/sponge/ViaChatFixerVersion.java new file mode 100644 index 0000000..1ad32f1 --- /dev/null +++ b/sponge/src/main/java-templates/fr/mrmicky/viachatfixer/sponge/ViaChatFixerVersion.java @@ -0,0 +1,7 @@ +package fr.mrmicky.viachatfixer.sponge; + +public final class ViaChatFixerVersion { + + public static final String VERSION = "${project.version}"; + +} diff --git a/sponge/src/main/java/fr/mrmicky/viachatfixer/sponge/SpongeLogger.java b/sponge/src/main/java/fr/mrmicky/viachatfixer/sponge/SpongeLogger.java new file mode 100644 index 0000000..f622793 --- /dev/null +++ b/sponge/src/main/java/fr/mrmicky/viachatfixer/sponge/SpongeLogger.java @@ -0,0 +1,40 @@ +package fr.mrmicky.viachatfixer.sponge; + +import com.google.inject.Inject; +import fr.mrmicky.viachatfixer.common.logger.LoggerAdapter; +import org.slf4j.Logger; + +public class SpongeLogger implements LoggerAdapter { + + private final Logger logger; + + @Inject + public SpongeLogger(Logger logger) { + this.logger = logger; + } + + @Override + public void info(String message) { + this.logger.info(message); + } + + @Override + public void warn(String message) { + this.logger.warn(message); + } + + @Override + public void warn(String message, Throwable throwable) { + this.logger.warn(message, throwable); + } + + @Override + public void error(String message) { + this.logger.error(message); + } + + @Override + public void error(String message, Throwable throwable) { + this.logger.error(message, throwable); + } +} diff --git a/sponge/src/main/java/fr/mrmicky/viachatfixer/sponge/ViaChatFixerSponge.java b/sponge/src/main/java/fr/mrmicky/viachatfixer/sponge/ViaChatFixerSponge.java new file mode 100644 index 0000000..f5ab81a --- /dev/null +++ b/sponge/src/main/java/fr/mrmicky/viachatfixer/sponge/ViaChatFixerSponge.java @@ -0,0 +1,110 @@ +package fr.mrmicky.viachatfixer.sponge; + +import com.google.inject.Inject; +import fr.mrmicky.viachatfixer.common.ChatHandler; +import fr.mrmicky.viachatfixer.common.ViaChatFixerPlatform; +import org.spongepowered.api.entity.living.player.Player; +import org.spongepowered.api.event.Listener; +import org.spongepowered.api.event.Order; +import org.spongepowered.api.event.command.SendCommandEvent; +import org.spongepowered.api.event.filter.cause.Root; +import org.spongepowered.api.event.game.state.GameStartedServerEvent; +import org.spongepowered.api.event.message.MessageChannelEvent; +import org.spongepowered.api.plugin.Dependency; +import org.spongepowered.api.plugin.Plugin; +import org.spongepowered.api.text.Text; + +import java.lang.reflect.Field; + +@Plugin( + id = "viachatfixer", + name = "ViaChatFixer", + version = ViaChatFixerVersion.VERSION, + dependencies = @Dependency(id = "viaversion"), + description = "Allow 1.11+ players to have longer chat messages on 1.8-1.10 servers with ViaVersion", + authors = "MrMicky" +) +public final class ViaChatFixerSponge implements ViaChatFixerPlatform { + + private final ChatHandler chatHandler = new ChatHandler(this); + + private final SpongeLogger logger; + + private Field chatRawMessageField; + private boolean chatRawMessageFieldInitialized; + + @Inject + public ViaChatFixerSponge(SpongeLogger logger) { + this.logger = logger; + } + + @Listener + public void onServerStart(GameStartedServerEvent event) { + try { + this.chatHandler.init(); + } catch (Exception e) { + this.logger.error("An error occurred during initialization", e); + } + } + + @Listener(order = Order.FIRST, beforeModifications = true) + public void onChat(MessageChannelEvent.Chat event, @Root Player player) { + String message = this.chatHandler.handle(player.getUniqueId()); + + if (message == null) { + return; + } + + Text text = Text.of(message); + + event.getFormatter().setBody(text); + + setChatEventRawMessage(event, text); + } + + @Listener(order = Order.FIRST, beforeModifications = true) + public void onCommand(SendCommandEvent event, @Root Player player) { + String command = this.chatHandler.handle(player.getUniqueId()); + + if (command == null) { + return; + } + + command = command.trim(); + + if (command.startsWith("/")) { + command = command.substring(1); + } + + String[] args = command.split(" ", 2); + + event.setCommand(args[0]); + event.setArguments(args.length > 1 ? args[1] : ""); + } + + @Override + public SpongeLogger getLoggerAdapter() { + return this.logger; + } + + private void setChatEventRawMessage(MessageChannelEvent.Chat event, Text rawMessage) { + try { + if (!this.chatRawMessageFieldInitialized) { + this.chatRawMessageFieldInitialized = true; + + Field field = event.getClass().getDeclaredField("rawMessage"); + field.setAccessible(true); + + this.chatRawMessageField = field; + } + + if (this.chatRawMessageField != null) { + this.chatRawMessageField.set(event, rawMessage); + } + } catch (ReflectiveOperationException e) { + this.logger.warn("Unable to find rawMessage field in " + event.getClass().getName(), e); + + this.chatRawMessageField = null; + } + } +} diff --git a/universal/pom.xml b/universal/pom.xml index fdfe087..f118ffa 100644 --- a/universal/pom.xml +++ b/universal/pom.xml @@ -7,7 +7,7 @@ fr.mrmicky viachatfixer - 0.3.0 + 1.0.0 viachatfixer-universal @@ -47,18 +47,12 @@ ${project.version} compile - +