Skip to content

Commit

Permalink
Added: PlayerCrasher Base Command
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram1903 committed Jun 22, 2024
1 parent 02d1a8f commit 998ab1f
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

package com.deathmotion.playercrasher.util;


import com.deathmotion.playercrasher.data.Constants;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;

Expand Down Expand Up @@ -47,6 +51,25 @@ public class CommandUtil {
public static final Component noPersonalBrand = Component.text()
.append(Component.text("We haven't been able to retrieve your client brand.", NamedTextColor.RED))
.build();
private static final PCVersion version = PCVersion.createFromPackageVersion();

private static Component createColoredText(String text, NamedTextColor color, boolean bold) {
return Component.text(text, color).decoration(TextDecoration.BOLD, bold);
}

public static Component createPCCommandComponent() {
return Component.text()
.append(createColoredText("\u25cf", NamedTextColor.GREEN, true))
.append(createColoredText(" Running ", NamedTextColor.GRAY, false))
.append(createColoredText("AntiHealthIndicator", NamedTextColor.GREEN, true))
.append(createColoredText(" v" + version.toString(), NamedTextColor.GREEN, true))
.append(createColoredText(" by ", NamedTextColor.GRAY, false))
.append(createColoredText("Bram", NamedTextColor.GREEN, true))
.hoverEvent(HoverEvent.showText(createColoredText("Open Github Page!", NamedTextColor.GREEN, true)
.decorate(TextDecoration.UNDERLINED)))
.clickEvent(ClickEvent.openUrl(Constants.GITHUB_URL))
.build();
}

public static Component crashSent(String username) {
return Component.text()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public class PCVersion implements Comparable<PCVersion> {

public static final PCVersion UNKNOWN = new PCVersion(0, 0, 0);
private static final PCVersion UNKNOWN = new PCVersion(0, 0, 0);

private final int major;
private final int minor;
Expand Down Expand Up @@ -96,7 +96,7 @@ public static PCVersion createFromPackageVersion() {
Optional<PCVersion> version = Optional.ofNullable(PCPlatform.class.getPackage().getImplementationVersion()).map(PCVersion::fromString);
if (!version.isPresent()) {
Logger logger = Logger.getLogger(PCPlatform.class.getName());
logger.warning("[playercrasher-version] Failed to retrieve the PlayerCrasher version from the package implementation version. Are you using a using a custom build?");
logger.warning("[playercrasher-version] Failed to retrieve the PlayerCrasher version from the package implementation version.");
}

return version.orElse(UNKNOWN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.deathmotion.playercrasher.commands.BukkitCrashCommand;
import com.deathmotion.playercrasher.commands.BukkitCrashInfoCommand;
import com.deathmotion.playercrasher.commands.BukkitPCCommand;
import com.deathmotion.playercrasher.interfaces.Scheduler;
import com.deathmotion.playercrasher.managers.LogManager;
import com.deathmotion.playercrasher.util.MessageSender;
Expand Down Expand Up @@ -117,6 +118,7 @@ protected void enableBStats() {
}

protected void registerCommands() {
new BukkitPCCommand(this.plugin);
new BukkitCrashCommand(this.plugin);
new BukkitCrashInfoCommand(this.plugin);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.deathmotion.playercrasher.commands;

import com.deathmotion.playercrasher.PCBukkit;
import com.deathmotion.playercrasher.util.CommandUtil;
import com.deathmotion.playercrasher.util.MessageSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

public class BukkitPCCommand implements CommandExecutor {
private final MessageSender messageSender;

public BukkitPCCommand(PCBukkit plugin) {
this.messageSender = plugin.getPc().messageSender;

plugin.getCommand("PlayerCrasher").setExecutor(this);
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
messageSender.sendMessages(sender, CommandUtil.createPCCommandComponent());
return true;
}
}
2 changes: 0 additions & 2 deletions platforms/bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ depend:
commands:
PlayerCrasher:
description: Base command for PlayerCrasher.
permission: PlayerCrasher.Crash
permission-message: Unknown command. Type "/help" for help
aliases:
- pc
Crash:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.deathmotion.playercrasher.Util.MessageSender;
import com.deathmotion.playercrasher.commands.BungeeCrashCommand;
import com.deathmotion.playercrasher.commands.BungeeCrashInfoCommand;
import com.deathmotion.playercrasher.commands.BungeePCCommand;
import com.deathmotion.playercrasher.interfaces.Scheduler;
import io.github.retrooper.packetevents.adventure.serializer.legacy.LegacyComponentSerializer;
import io.github.retrooper.packetevents.bstats.Metrics;
Expand Down Expand Up @@ -68,8 +69,7 @@ public boolean hasPermission(UUID sender, String permission) {

@Override
public void sendConsoleMessage(Component message) {
String legacyMessage = STRIP_COLOR_PATTERN.matcher(LegacyComponentSerializer.legacyAmpersand().serialize(message)).replaceAll("").trim();
ProxyServer.getInstance().getConsole().sendMessage(legacyMessage);
ProxyServer.getInstance().getConsole().sendMessage(LegacyComponentSerializer.legacySection().serialize(message));
}

@Override
Expand All @@ -88,6 +88,7 @@ protected void enableBStats() {
}

protected void registerCommands() {
new BungeePCCommand(this.plugin);
new BungeeCrashCommand(this.plugin);
new BungeeCrashInfoCommand(this.plugin);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.deathmotion.playercrasher.commands;

import com.deathmotion.playercrasher.PCBungee;
import com.deathmotion.playercrasher.Util.MessageSender;
import com.deathmotion.playercrasher.util.CommandUtil;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;

public class BungeePCCommand extends Command {

private final MessageSender messageSender;

public BungeePCCommand(PCBungee plugin) {
super("PlayerCrasher", null, "pc");

this.messageSender = plugin.getPc().messageSender;
plugin.getProxy().getPluginManager().registerCommand(plugin, this);
}

@Override
public void execute(CommandSender sender, String[] args) {
messageSender.sendMessages(sender, CommandUtil.createPCCommandComponent());
}
}
2 changes: 0 additions & 2 deletions platforms/bungeecord/src/main/resources/bungee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ depend:
commands:
PlayerCrasher:
description: Base command for PlayerCrasher.
permission: PlayerCrasher.Crash
permission-message: Unknown command. Type "/help" for help
aliases:
- pc
Crash:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.deathmotion.playercrasher.commands.VelocityCrashCommand;
import com.deathmotion.playercrasher.commands.VelocityCrashInfoCommand;
import com.deathmotion.playercrasher.commands.VelocityPCCommand;
import com.deathmotion.playercrasher.schedulers.VelocityScheduler;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
Expand Down Expand Up @@ -78,6 +79,7 @@ private void enableBStats() {
}

private void registerCommands() {
new VelocityPCCommand(this);
new VelocityCrashCommand(this);
new VelocityCrashInfoCommand(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.deathmotion.playercrasher.commands;

import com.deathmotion.playercrasher.PCVelocity;
import com.deathmotion.playercrasher.util.CommandUtil;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.command.SimpleCommand;

public class VelocityPCCommand implements SimpleCommand {

public VelocityPCCommand(PCVelocity plugin) {
CommandMeta commandMeta = plugin.getPc().getPlatform().getCommandManager().metaBuilder("crashinfo")
.aliases("brand")
.build();
plugin.getPc().getPlatform().getCommandManager().register(commandMeta, this);
}

@Override
public void execute(Invocation invocation) {
invocation.source().sendMessage(CommandUtil.createPCCommandComponent());
}
}

0 comments on commit 998ab1f

Please sign in to comment.