Add /delhome
Add clickevent to /homes
This commit is contained in:
parent
aebb408e6f
commit
d17466463b
3 changed files with 50 additions and 5 deletions
|
@ -20,5 +20,11 @@ public class CommandRegistry {
|
|||
.then(Commands.argument("name", StringArgumentType.string())
|
||||
.executes(ctx -> HomeCommand.execute(ctx, StringArgumentType.getString(ctx, "name"))))
|
||||
.build());
|
||||
cmds.register(Commands.literal("delhome")
|
||||
.requires(x -> x.getSender().hasPermission(DelHomeCommand.PERMISSION))
|
||||
.executes(ctx -> DelHomeCommand.execute(ctx, "Default"))
|
||||
.then(Commands.argument("name", StringArgumentType.string())
|
||||
.executes(ctx -> DelHomeCommand.execute(ctx, StringArgumentType.getString(ctx, "name"))))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
|
32
src/main/java/dev/zontreck/ase/commands/DelHomeCommand.java
Normal file
32
src/main/java/dev/zontreck/ase/commands/DelHomeCommand.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package dev.zontreck.ase.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
|
||||
import dev.zontreck.ase.AriasServerEssentials;
|
||||
import dev.zontreck.ase.SavedData;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
public class DelHomeCommand {
|
||||
public static final String PERMISSION = "ase.commands.delhome";
|
||||
|
||||
public static int execute(CommandContext<CommandSourceStack> ctx, String homeName) {
|
||||
Player player = (Player) ctx.getSource().getSender();
|
||||
SavedData data = AriasServerEssentials.getPlayerData(player.getUniqueId().toString());
|
||||
|
||||
if (data.homes.containsKey(homeName)) {
|
||||
player.sendMessage(Component.text("Home Deleted!", NamedTextColor.DARK_GREEN));
|
||||
|
||||
data.homes.remove(homeName);
|
||||
data.save(player.getUniqueId().toString());
|
||||
} else {
|
||||
player.sendMessage(Component.text("No such home exists", NamedTextColor.DARK_RED));
|
||||
}
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
package dev.zontreck.ase.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
|
@ -12,7 +9,13 @@ import dev.zontreck.ase.AriasServerEssentials;
|
|||
import dev.zontreck.ase.homes.Home;
|
||||
import dev.zontreck.ase.utils.PermissionUtils;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentBuilder;
|
||||
import net.kyori.adventure.text.event.ClickEvent.Action;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class HomesCommand {
|
||||
public static final String PERMISSION = "ase.commands.homes";
|
||||
|
@ -30,10 +33,14 @@ public class HomesCommand {
|
|||
player.sendMessage(ChatColor.DARK_GREEN + "You have [" + ChatColor.DARK_PURPLE
|
||||
+ AriasServerEssentials.getPlayerData(player.getUniqueId().toString()).homes.size()
|
||||
+ ChatColor.DARK_GREEN
|
||||
+ "/" + max + "] home(s)");
|
||||
+ "/" + ChatColor.DARK_RED + max + ChatColor.DARK_GREEN + "] home(s)");
|
||||
|
||||
for (Home home : AriasServerEssentials.getPlayerData(player.getUniqueId().toString()).homes.values()) {
|
||||
player.sendMessage(ChatColor.YELLOW + "Home: " + ChatColor.DARK_GREEN + home.getName());
|
||||
player.sendMessage(Component.text()
|
||||
.append(Component.text("Home: ", NamedTextColor.YELLOW))
|
||||
.append(Component.text(home.getName(), NamedTextColor.DARK_GREEN).clickEvent(
|
||||
net.kyori.adventure.text.event.ClickEvent.runCommand("/home " + home.getName())))
|
||||
.build());
|
||||
}
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue