Skip to content

Commit

Permalink
Added: CrashInfoCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram1903 committed May 17, 2024
1 parent fa5e401 commit 77800ac
Show file tree
Hide file tree
Showing 21 changed files with 444 additions and 9 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ Technically, it should also work on any Spigot or Paper fork, but I can't guaran
- `Particle`
- `Position`


## Commands
- `/pc` - Displays the plugin's version and author.
- `/crash (player) [Method]` - Crashes the specified player's game.
- `/crashinfo [player]` - Displays the client brand and version of the specified player.

## Permission Nodes

Players that are OP (Operators) have these permissions by default.

- `PlayerCrasher.Crash` Allows the player to use the /crash command.
- `PlayerCrasher.Bypass` Exempts the player from being crashed when the /crash command is used on them.
- `PlayerCrasher.Alerts` Makes the player receive alerts when a player is being crashed by another player.
- `PlayerCrasher.CrashInfo` - Allows the player to use the /crashinfo command.
- `PlayerCrasher.UpdateNotify` Makes the player receive an update notification when a new version is available.

## Installation Guide
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ tasks {
// 1.17 = Java 16
// 1.18 - 1.20.4 = Java 17
// 1-20.5+ = Java 21
val version = "1.20.6"
val javaVersion = 21
val version = "1.8.8"
val javaVersion = 8

val requiredPlugins = runPaper.downloadPluginsSpec {
url("https://ci.codemc.io/job/retrooper/job/packetevents/lastSuccessfulBuild/artifact/spigot/build/libs/packetevents-spigot-2.3.1-SNAPSHOT.jar")
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/deathmotion/playercrasher/PlayerCrasher.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* This file is part of PlayerCrasher - https://github.com/Bram1903/MinecraftPlayerCrasher
* Copyright (C) 2024 Bram and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.deathmotion.playercrasher;

import com.deathmotion.playercrasher.listeners.BrandHandler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* This file is part of PlayerCrasher - https://github.com/Bram1903/MinecraftPlayerCrasher
* Copyright (C) 2024 Bram and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.deathmotion.playercrasher.commands;

import com.deathmotion.playercrasher.PlayerCrasher;
Expand Down Expand Up @@ -66,8 +84,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (user.getClientVersion().isOlderThan(ClientVersion.V_1_12)) {
method = CrashMethod.POSITION;
}
}
else {
} else {
try {
method = CrashMethod.valueOf(args[1].toUpperCase());
} catch (IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* This file is part of PlayerCrasher - https://github.com/Bram1903/MinecraftPlayerCrasher
* Copyright (C) 2024 Bram and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.deathmotion.playercrasher.commands;

import com.deathmotion.playercrasher.PlayerCrasher;
import com.deathmotion.playercrasher.managers.CrashManager;
import com.deathmotion.playercrasher.util.AdventureCompatUtil;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.protocol.player.User;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class CrashInfoCommand implements CommandExecutor {
private final CrashManager crashManager;
private final AdventureCompatUtil adventure;

public CrashInfoCommand(PlayerCrasher plugin) {
this.crashManager = plugin.getCrashManager();
this.adventure = plugin.getAdventureCompatUtil();
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!sender.hasPermission("PlayerCrasher.CrashInfo")) {
sender.sendMessage("Unknown command. Type \"/help\" for help.");
return false;
}

if (args.length == 0) {
if (!(sender instanceof Player)) {
sender.sendMessage("You must specify a player when running this command from the console.");
return false;
} else {
User user = PacketEvents.getAPI().getPlayerManager().getUser(sender);
String clientBrand = crashManager.getClientBrand(user.getUUID()).orElse(null);

if (clientBrand == null) {
user.sendMessage(Component.text("We haven't been able to retrieve your client brand.", NamedTextColor.RED));
return false;
}

Component crashInfoComponent = Component.text()
.append(Component.text("You are running ", NamedTextColor.GRAY))
.append(Component.text(clientBrand, NamedTextColor.GOLD)
.decorate(TextDecoration.BOLD))
.append(Component.text(" on Minecraft version ", NamedTextColor.GRAY))
.append(Component.text(user.getClientVersion().getReleaseName(), NamedTextColor.GOLD)
.decorate(TextDecoration.BOLD))
.append(Component.text(".", NamedTextColor.GRAY))
.build();

user.sendMessage(crashInfoComponent);
return true;
}
}

Player playerToCheck = Bukkit.getPlayer(args[0]);

if (playerToCheck == null) {
adventure.sendComponent(sender, Component.text("Player not found.", NamedTextColor.RED));
return false;
}

User userToCheck = PacketEvents.getAPI().getPlayerManager().getUser(playerToCheck);
String clientBrand = crashManager.getClientBrand(userToCheck.getUUID()).orElse(null);

if (clientBrand == null) {
adventure.sendComponent(sender, Component.text("We haven't been able to retrieve the client brand of " + playerToCheck.getName() + ".", NamedTextColor.RED));
return false;
}

Component crashInfoComponent = Component.text()
.append(Component.text(playerToCheck.getName(), NamedTextColor.GOLD)
.decorate(TextDecoration.BOLD))
.append(Component.text(" is running ", NamedTextColor.GRAY))
.append(Component.text(clientBrand, NamedTextColor.GOLD)
.decorate(TextDecoration.BOLD))
.append(Component.text(" on Minecraft version ", NamedTextColor.GRAY))
.append(Component.text(userToCheck.getClientVersion().getReleaseName(), NamedTextColor.GOLD)
.decorate(TextDecoration.BOLD))
.append(Component.text(".", NamedTextColor.GRAY))
.build();

adventure.sendComponent(sender, crashInfoComponent);
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* This file is part of PlayerCrasher - https://github.com/Bram1903/MinecraftPlayerCrasher
* Copyright (C) 2024 Bram and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.deathmotion.playercrasher.commands;

import com.deathmotion.playercrasher.PlayerCrasher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* This file is part of PlayerCrasher - https://github.com/Bram1903/MinecraftPlayerCrasher
* Copyright (C) 2024 Bram and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.deathmotion.playercrasher.enums;

import lombok.Getter;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/deathmotion/playercrasher/enums/CrashMethod.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* This file is part of PlayerCrasher - https://github.com/Bram1903/MinecraftPlayerCrasher
* Copyright (C) 2024 Bram and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.deathmotion.playercrasher.enums;

import lombok.Getter;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/deathmotion/playercrasher/events/PlayerQuit.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* This file is part of PlayerCrasher - https://github.com/Bram1903/MinecraftPlayerCrasher
* Copyright (C) 2024 Bram and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.deathmotion.playercrasher.events;

import com.deathmotion.playercrasher.PlayerCrasher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* This file is part of PlayerCrasher - https://github.com/Bram1903/MinecraftPlayerCrasher
* Copyright (C) 2024 Bram and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.deathmotion.playercrasher.events;

import com.deathmotion.playercrasher.PlayerCrasher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* This file is part of PlayerCrasher - https://github.com/Bram1903/MinecraftPlayerCrasher
* Copyright (C) 2024 Bram and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.deathmotion.playercrasher.listeners;

import com.deathmotion.playercrasher.PlayerCrasher;
Expand All @@ -18,17 +36,19 @@ public BrandHandler(PlayerCrasher plugin) {
@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (event.getPacketType() != PacketType.Configuration.Client.PLUGIN_MESSAGE) return;
WrapperPlayClientPluginMessage wrapper = new WrapperPlayClientPluginMessage(event);

String channelName = wrapper.getChannelName();
byte[] data = wrapper.getData();
WrapperPlayClientPluginMessage packet = new WrapperPlayClientPluginMessage(event);

String channelName = packet.getChannelName();
if (!channelName.equalsIgnoreCase("minecraft:brand") && !channelName.equals("MC|Brand")) return;

byte[] data = packet.getData();

// Thanks for GrimAC for this fix - Prevents the server from being crashed by a client with a brand name that is too long
if (data.length > 64 || data.length == 0) return;

byte[] minusLength = new byte[data.length - 1];
System.arraycopy(data, 1, minusLength, 0, minusLength.length);
String brand = new String(minusLength).replace(" (Velocity)", ""); // removes velocity's brand suffix
String brand = new String(minusLength).replace(" (Velocity)", "");

crashManager.addClientBrand(event.getUser().getUUID(), prettyBrandName(brand));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* This file is part of PlayerCrasher - https://github.com/Bram1903/MinecraftPlayerCrasher
* Copyright (C) 2024 Bram and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.deathmotion.playercrasher.listeners;

import com.deathmotion.playercrasher.PlayerCrasher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* This file is part of PlayerCrasher - https://github.com/Bram1903/MinecraftPlayerCrasher
* Copyright (C) 2024 Bram and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.deathmotion.playercrasher.managers;

import com.deathmotion.playercrasher.PlayerCrasher;
Expand Down
Loading

0 comments on commit 77800ac

Please sign in to comment.