Add basic groups

# Conflicts:
#	src/main/java/gent/zeus/mc13dtl/MC13DTL.java
This commit is contained in:
Xander 2024-09-14 21:52:32 +02:00
parent 09b15cd16e
commit 9dc7eff01e
No known key found for this signature in database
GPG key ID: 79979C7BA303E003
3 changed files with 74 additions and 13 deletions

View file

@ -1,5 +1,7 @@
package gent.zeus.mc13dtl;
import gent.zeus.mc13dtl.group.GroupAddCommand;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
@ -10,9 +12,13 @@ import gent.zeus.mc13dtl.gamestate.GameStateHandler;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
public class MC13DTL extends JavaPlugin {
public static MC13DTL instance;
public static ScoreboardManager sm;
public static Scoreboard scoreboard;
@Override
public void onEnable() {
@ -22,8 +28,13 @@ public class MC13DTL extends JavaPlugin {
manager.registerEventHandler(LifecycleEvents.COMMANDS, event -> {
Commands commands = event.registrar();
commands.register("start-game", "Start a game of 13 days to live", new GameStateCommand());
commands.register("groupadd", "Add player to group", new GroupAddCommand());
});
BukkitScheduler scheduler = this.getServer().getScheduler();
scheduler.runTaskTimer(this, new RandomEventRunner(), 0, 100);
scheduler.runTask(this, () -> {
sm = Bukkit.getScoreboardManager();
scoreboard = sm.getMainScoreboard();
});
}
}

View file

@ -0,0 +1,46 @@
package gent.zeus.mc13dtl.group;
import gent.zeus.mc13dtl.MC13DTL;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Team;
import org.jetbrains.annotations.NotNull;
import org.bukkit.ChatColor;
public class GroupAddCommand implements BasicCommand {
@Override
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
try {
if (args.length == 2) {
Player player = Bukkit.getPlayerExact(args[0]);
if (player != null) {
Integer index = Integer.parseInt(args[1]);
Team team = null;
try {
team = MC13DTL.scoreboard.registerNewTeam(index.toString());
team.setColor(ChatColor.values()[index % ChatColor.values().length]);
team.setPrefix("Team " + index.toString() + " ");
team.setAllowFriendlyFire(false);
} catch (IllegalArgumentException e) {
team = MC13DTL.scoreboard.getTeam(index.toString());
}
if (team != null) {
team.addPlayer(player);
player.sendRichMessage("<rainbow>You have been added to team " + index.toString());
}
} else {
commandSourceStack.getSender().sendMessage("Player " + args[0] + " does not exist.");
}
} else {
commandSourceStack.getSender().sendMessage("groupAdd usage: /groupAdd <player> <index>");
}
} catch (NumberFormatException ex) {
commandSourceStack.getSender().sendMessage("usage: /groupAdd <player> <NUMBER>");
}
}
}

View file

@ -0,0 +1,4 @@
package gent.zeus.mc13dtl.group;
public class GroupRemoveCommand {
}