Add Commands !players !exp name !death name

This commit is contained in:
nzBryce101
2024-04-02 10:48:30 +13:00
parent 58b085d832
commit 3a0ba8f81c
2 changed files with 40 additions and 2 deletions

View File

@@ -6,5 +6,12 @@ author: Bryce
api-version: 1.20.4
commands:
players:
description: Command description here
description: displays the list of players logged on to the server
usage: /players
exp:
description: update & show the exp counter (OBS)
usage: /exp <player>
death:
description: update Death counter and post in chat [player has died [x] times]
usage: /death <player>

View File

@@ -6,6 +6,9 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.Statistic;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class MCbot extends JavaPlugin {
@@ -79,7 +82,35 @@ public class MCbot extends JavaPlugin {
.collect(Collectors.toList()));
return "Players online: " + playerList;
}
if (command.startsWith("!exp ")) {
// Extract player name from command
String playerName = command.substring(5); // Assuming "!exp " is 5 characters long
// Get player object by name
Player player = Bukkit.getPlayer(playerName);
if (player != null) {
// Get player's experience level
int expLevel = player.getLevel();
return playerName + "'s experience level: " + expLevel;
} else {
return "Player not found: " + playerName;
}
}
if (command.startsWith("!deaths ")) {
//Extract player name from command
String playerName = command.substring(8); // Assuming "!deaths " is at least 8 chars long
// Get Player object by name
Player player = Bukkit.getPlayer(playerName);
if(player != null) {
// Get Player's Death Count
int deaths = player.getStatistic(Statistic.DEATHS);
return playerName + "has died" + deaths + "times";
}else {
return "Player not found: " + playerName;
}
}
// Add more command processing logic as needed
return "Unknown command: " + command;
}