Skip to content

Commit

Permalink
Fixes for Paper
Browse files Browse the repository at this point in the history
  • Loading branch information
teakivy committed Aug 8, 2022
1 parent a104ea8 commit b4e452e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/me/teakivy/nochatreports/NoChatReports.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import me.teakivy.nochatreports.util.ConfigUpdater;
import me.teakivy.nochatreports.util.Logger;
import me.teakivy.nochatreports.util.Metrics.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Locale;
import java.util.Objects;

public final class NoChatReports extends JavaPlugin {
Expand All @@ -30,6 +32,20 @@ public void onEnable() {
registerMetrics();

Logger.info(ChatColor.GREEN + "NoChatReports v" + getDescription().getVersion() + " loaded!");


if (Config.isPaperWorkaround()) return;

String[] paperServerTypes = {"Paper", "Purpur", "PaperSpigot", "Airplane"};

for (String serverType : paperServerTypes) {
if (Bukkit.getServer().getName().toLowerCase().contains(serverType.toLowerCase())) {
Logger.warning("This server is running on a known Paper forked server!");
Logger.warning("This plugin may not work properly.");
Logger.warning("Enable the 'paper-workaround' option in the config to fix this.");
break;
}
}
}

private void updateConfig() {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/me/teakivy/nochatreports/listeners/ChatListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package me.teakivy.nochatreports.listeners;

import me.teakivy.nochatreports.util.Config;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
Expand All @@ -8,6 +11,15 @@ public class ChatListener implements Listener {

@EventHandler
public void onChat(AsyncPlayerChatEvent e) {
if (Config.isPaperWorkaround()) {
e.setCancelled(true);

for (Player toPlayer : Bukkit.getOnlinePlayers()) {
toPlayer.sendMessage(String.format(e.getFormat(), e.getPlayer().getDisplayName(), e.getMessage()));
}

return;
}
e.setMessage(e.getMessage() + " ");
}
}

0 comments on commit b4e452e

Please sign in to comment.