Skip to content

Commit

Permalink
Fixed: Component to String conversion on non Adventure compatible pla…
Browse files Browse the repository at this point in the history
…tforms
  • Loading branch information
Bram1903 committed Jun 20, 2024
1 parent b53cc8f commit 9bebb38
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.deathmotion.playercrasher.data.CrashData;
import com.deathmotion.playercrasher.managers.CrashManager;
import com.deathmotion.playercrasher.util.ComponentCreator;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.event.PacketListenerAbstract;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import com.deathmotion.playercrasher.commands.BukkitCrashInfoCommand;
import com.deathmotion.playercrasher.interfaces.Scheduler;
import com.deathmotion.playercrasher.managers.LogManager;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import io.github.retrooper.packetevents.adventure.serializer.legacy.LegacyComponentSerializer;
import io.github.retrooper.packetevents.bstats.Metrics;
import lombok.Getter;
Expand All @@ -38,17 +36,35 @@
@Getter
public class BukkitPlayerCrasher extends PCPlatform<JavaPlugin> {

private final PCBukkit plugin;
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)&[0-9A-FK-ORX]|\\u25cf");

public final boolean useAdventure;
private final PCBukkit plugin;
private final boolean useAdventure;

public BukkitPlayerCrasher(PCBukkit plugin) {
this.plugin = plugin;

useAdventure = checkAdventureCompatibility();
}

private static boolean checkAdventureCompatibility() {
try {
Class.forName("io.papermc.paper.adventure.PaperAdventure");
return true;
} catch (ClassNotFoundException e) {
// ignored exception
}

try {
Class.forName("net.kyori.adventure.platform.bukkit.BukkitAudience ");
return true;
} catch (ClassNotFoundException e) {
// ignored exception
}

return false;
}

@Override
public JavaPlugin getPlatform() {
return this.plugin;
Expand Down Expand Up @@ -104,13 +120,4 @@ protected void registerCommands() {
new BukkitCrashCommand(this.plugin);
new BukkitCrashInfoCommand(this.plugin);
}

private static boolean checkAdventureCompatibility() {
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.deathmotion.playercrasher.schedulers.BukkitScheduler;
import com.deathmotion.playercrasher.schedulers.FoliaScheduler;
import com.deathmotion.playercrasher.util.BukkitLogManager;
import net.kyori.adventure.text.Component;
import org.bukkit.plugin.java.JavaPlugin;

public class PCBukkit extends JavaPlugin {
Expand All @@ -47,7 +46,6 @@ public void onEnable() {
pc.setScheduler(isFolia() ? new FoliaScheduler(this) : new BukkitScheduler(this));

pc.setLogManager(new BukkitLogManager(this));
pc.sendConsoleMessage(this.getPc().useAdventure ? Component.text("Using components") : Component.text("Using Legacy components"));

pc.commonOnEnable();
pc.registerCommands();
Expand Down

0 comments on commit 9bebb38

Please sign in to comment.