Add basic groups
# Conflicts: # src/main/java/gent/zeus/mc13dtl/MC13DTL.java
This commit is contained in:
parent
09b15cd16e
commit
9dc7eff01e
3 changed files with 74 additions and 13 deletions
|
@ -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,20 +12,29 @@ 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 MC13DTL instance;
|
||||
public static ScoreboardManager sm;
|
||||
public static Scoreboard scoreboard;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
getServer().getPluginManager().registerEvents(new GameStateHandler(), this);
|
||||
LifecycleEventManager<Plugin> manager = this.getLifecycleManager();
|
||||
manager.registerEventHandler(LifecycleEvents.COMMANDS, event -> {
|
||||
Commands commands = event.registrar();
|
||||
commands.register("start-game", "Start a game of 13 days to live", new GameStateCommand());
|
||||
});
|
||||
BukkitScheduler scheduler = this.getServer().getScheduler();
|
||||
scheduler.runTaskTimer(this, new RandomEventRunner(), 0, 100);
|
||||
}
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
getServer().getPluginManager().registerEvents(new GameStateHandler(), this);
|
||||
LifecycleEventManager<Plugin> manager = this.getLifecycleManager();
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
46
src/main/java/gent/zeus/mc13dtl/group/GroupAddCommand.java
Normal file
46
src/main/java/gent/zeus/mc13dtl/group/GroupAddCommand.java
Normal 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>");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package gent.zeus.mc13dtl.group;
|
||||
|
||||
public class GroupRemoveCommand {
|
||||
}
|
Loading…
Reference in a new issue