Skip to content

Commit

Permalink
HP and Kill commands
Browse files Browse the repository at this point in the history
  • Loading branch information
InsertSoda committed Jun 22, 2024
1 parent d962d38 commit 2b93e7c
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
73 changes: 73 additions & 0 deletions src/main/java/com/insertsoda/craterchat/commands/HpCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.insertsoda.craterchat.commands;

import com.insertsoda.craterchat.CraterChat;
import com.insertsoda.craterchat.api.v1.Command;
import com.insertsoda.craterchat.api.v1.CommandManager;
import com.insertsoda.craterchat.api.v1.CommandSource;
import com.insertsoda.craterchat.api.v1.arguments.types.RelativeFloatType;
import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import finalforeach.cosmicreach.gamestates.InGame;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class HpCommand implements Command {
@Override
public void register(LiteralArgumentBuilder<CommandSource> literalArgumentBuilder) {
literalArgumentBuilder.then(
CommandManager.literal("add").then(
CommandManager.argument("amount", FloatArgumentType.floatArg()).executes(context -> {
float amount = FloatArgumentType.getFloat(context, "amount");
context.getSource().getPlayer().getEntity().hit(-amount);
CraterChat.Chat.sendMessage("Added " + amount + " hp");
return 1;
})
)
).then(
CommandManager.literal("remove").then(
CommandManager.argument("amount", FloatArgumentType.floatArg()).executes(context -> {
float amount = FloatArgumentType.getFloat(context, "amount");
context.getSource().getPlayer().getEntity().hit(amount);
CraterChat.Chat.sendMessage("Removed " + amount + " hp");
return 1;
})
)
).then(
CommandManager.literal("set").then(
CommandManager.argument("amount", FloatArgumentType.floatArg()).executes(context -> {
float amount = FloatArgumentType.getFloat(context, "amount");
context.getSource().getPlayer().getEntity().hitpoints = amount;
CraterChat.Chat.sendMessage("Set hp to " + amount);
return 1;
})
)
).then(
CommandManager.literal("get").executes((context) -> {
CraterChat.Chat.sendMessage("You currently have " + context.getSource().getPlayer().getEntity().hitpoints + " hp");
return 1;
})
);
}

@Override
public @NotNull String getName() {
return "hp";
}

@Override
public @Nullable String getDescription() {
return "Add, remove, set or get the player's hp";
}

@Override
public String getPossibleArguments() {
return "add|remove|set|get <amount>";
}

@Override
public List<String> getAliases() {
return List.of("health");
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/insertsoda/craterchat/commands/KillCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.insertsoda.craterchat.commands;

import com.insertsoda.craterchat.api.v1.Command;
import com.insertsoda.craterchat.api.v1.CommandSource;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class KillCommand implements Command {

@Override
public void register(LiteralArgumentBuilder<CommandSource> literalArgumentBuilder) {
literalArgumentBuilder.executes(context -> {
context.getSource().getPlayer().getEntity().hitpoints = 0;
return 1;
});
}

@Override
public @NotNull String getName() {
return "kill";
}

@Override
public @Nullable String getDescription() {
return "Kills the player";
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/insertsoda/craterchat/impl/PluginImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public List<Class<? extends Command>> register() {
TeleportCommand.class,
VersionCommand.class,
PluginsCommand.class,
SummonCommand.class
SummonCommand.class,
HpCommand.class,
KillCommand.class
);
}
}

0 comments on commit 2b93e7c

Please sign in to comment.