Skip to content

Commit

Permalink
Flatten modules structure
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMicky-FR committed Jun 19, 2024
1 parent 99f5b98 commit acaa50d
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 228 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You can download releases and find more information on [SpigotMC](https://www.sp

## Installation

Just put the ViaChatFixer jar in your plugins folder.
Just put the ViaChatFixer jar in your `plugins` folder.

ViaChatFixer currently supports ViaVersion v5.0 or higher, and requires Java 17.

Expand Down
39 changes: 0 additions & 39 deletions bukkit/pom.xml

This file was deleted.

33 changes: 0 additions & 33 deletions common/pom.xml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

37 changes: 28 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,48 @@
<groupId>fr.mrmicky</groupId>
<artifactId>viachatfixer</artifactId>
<version>1.2.0</version>
<packaging>pom</packaging>

<name>ViaChatFixer</name>

<modules>
<module>common</module>
<module>bukkit</module>
<module>universal</module>
</modules>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.10.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.viaversion</groupId>
<artifactId>viaversion-common</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>viaversion-repo</id>
<url>https://repo.viaversion.com/</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>17</source>
<target>17</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.mrmicky.viachatfixer.common;
package fr.mrmicky.viachatfixer;

import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
Expand All @@ -17,18 +17,20 @@ public class ChatHandler {

private final Set<UUID> unknownPlayers = new HashSet<>();

private final ViaChatFixerPlatform platform;
private final ViaChatFixer plugin;

private boolean enabled = false;

public ChatHandler(ViaChatFixerPlatform platform) {
this.platform = platform;
public ChatHandler(ViaChatFixer plugin) {
this.plugin = plugin;
}

public void init() {
if (Via.getAPI().getServerVersion().lowestSupportedProtocolVersion().getVersion() >= ProtocolVersion.v1_11.getVersion()) {
this.platform.getLoggerAdapter().warn("This plugin is not required on 1.11+ servers, you can just remove it.");
return;
public boolean init() {
ProtocolVersion lowestVersion = Via.getAPI().getServerVersion().lowestSupportedProtocolVersion();

if (lowestVersion.getVersion() >= ProtocolVersion.v1_11.getVersion()) {
this.plugin.getLogger().warning("This plugin is not required on 1.11+ servers, you can just remove it.");
return false;
}

Protocol<?, ?, ?, ?> protocol = Via.getManager().getProtocolManager().getProtocol(Protocol1_10To1_11.class);
Expand All @@ -42,7 +44,7 @@ public void init() {
public void register() {
map(Types.STRING); // 0 - Message
handler(wrapper -> {
// 100 character limit on older servers
// 100 characters limit on older servers
String message = wrapper.get(Types.STRING, 0);

if (message.length() <= 100) {
Expand Down Expand Up @@ -70,6 +72,8 @@ public void register() {
}, true);

this.enabled = true;

return true;
}

public String handle(UUID uuid) {
Expand All @@ -95,7 +99,7 @@ private ChatTracker getChatTracker(UUID uuid) {

if (connection == null) {
if (this.unknownPlayers.add(uuid)) {
this.platform.getLoggerAdapter().warn("Unknown connection for player with UUID " + uuid);
this.plugin.getLogger().warning("Unknown connection for player with UUID " + uuid);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.mrmicky.viachatfixer.common;
package fr.mrmicky.viachatfixer;

import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
package fr.mrmicky.viachatfixer;

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;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;

public final class BukkitPlugin extends JavaPlugin implements Listener, ViaChatFixerPlatform {
import java.util.logging.Level;

private LoggerAdapter logger;
private ChatHandler chatHandler;
public final class ViaChatFixer extends JavaPlugin implements Listener {

@Override
public void onLoad() {
this.logger = new JavaLoggerAdapter(getLogger());
}
private ChatHandler chatHandler;

@Override
public void onEnable() {
try {
Class.forName("com.viaversion.viaversion.api.ViaManager");
Class.forName("com.viaversion.viaversion.api.type.Types");
} catch (ClassNotFoundException e) {
this.logger.error("You need to install ViaVersion v5.0.0 or higher to use this version of ViaChatFixer.");
this.logger.error("If you can't update ViaVersion, you can use an older ViaChatFixer versions.");
getLogger().severe("You need to install ViaVersion v5.0.0 or higher to use this version of ViaChatFixer.");
getLogger().severe("If you can't update ViaVersion, you can use an older ViaChatFixer versions.");
getServer().getPluginManager().disablePlugin(this);
return;
}
Expand All @@ -37,21 +29,19 @@ public void onEnable() {
// Only load when ViaVersion is loaded
getServer().getScheduler().runTask(this, () -> {
try {
this.chatHandler.init();
if (!this.chatHandler.init()) {
getServer().getPluginManager().disablePlugin(this);
return;
}

getServer().getPluginManager().registerEvents(this, this);
} catch (Exception e) {
this.logger.error("An error occurred during initialization", e);
getLogger().log(Level.SEVERE, "An error occurred during initialization", e);
getServer().getPluginManager().disablePlugin(this);
}
});
}

@Override
public LoggerAdapter getLoggerAdapter() {
return this.logger;
}

@EventHandler(priority = EventPriority.LOWEST)
public void onAsyncPlayerChat(AsyncPlayerChatEvent e) {
String message = this.chatHandler.handle(e.getPlayer().getUniqueId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ author: MrMicky
description: Allow 1.11+ players to have longer chat messages on 1.8-1.10 servers with ViaVersion
website: https://www.spigotmc.org/resources/viachatfixer.61955/
softdepend: [ViaVersion]
main: fr.mrmicky.viachatfixer.BukkitPlugin
main: fr.mrmicky.viachatfixer.ViaChatFixer
52 changes: 0 additions & 52 deletions universal/pom.xml

This file was deleted.

0 comments on commit acaa50d

Please sign in to comment.