Finished promote/demote command untested
This commit is contained in:
parent
abdd6fbfa4
commit
708c2ea185
|
|
@ -2,6 +2,7 @@ package com.alttd.boosterapi.config;
|
|||
|
||||
import com.alttd.boosterapi.util.ALogger;
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurationOptions;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
|
@ -181,4 +182,17 @@ public final class Config {
|
|||
private static void loadDonorStuff() {
|
||||
donorRanks = getList("donor.ranks", donorRanks);
|
||||
}
|
||||
|
||||
public static String INVALID_USER = "<red><player> does not exist.</red>";
|
||||
public static String INVALID_ACTION = "<red><action> is not a valid action user promote or demote.</red>";
|
||||
public static String INVALID_DONOR_RANK = "<red><rank> is not a valid donor rank.</red>";
|
||||
public static String DEMOTE_MESSAGE = "<red>Your <rank> rank was refunded and removed. Contact staff if you're unsure what caused this.</red>";
|
||||
public static String PROMOTE_MESSAGE = "<green>Thank you for your support! We applied the <rank> rank to your account.</green>";
|
||||
private static void loadMessages() {
|
||||
INVALID_USER = getString("messages.invalid-user", INVALID_USER);
|
||||
INVALID_ACTION = getString("messages.invalid-action", INVALID_ACTION);
|
||||
INVALID_DONOR_RANK = getString("messages.invalid-donor-rank", INVALID_DONOR_RANK);
|
||||
DEMOTE_MESSAGE = getString("messages.demote", DEMOTE_MESSAGE);
|
||||
PROMOTE_MESSAGE = getString("messages.promote", PROMOTE_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import net.kyori.adventure.text.minimessage.Template;
|
|||
import net.kyori.adventure.text.minimessage.template.TemplateResolver;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Utils {
|
||||
|
||||
|
|
@ -18,4 +19,10 @@ public class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
public static String capitalize(String string) {
|
||||
if (string.length() <= 1)
|
||||
return string.toUpperCase();
|
||||
string = string.toLowerCase();
|
||||
return string.substring(0, 1).toUpperCase() + string.toLowerCase().substring(1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ plugins {
|
|||
`java-library`
|
||||
`maven-publish`
|
||||
id("com.github.johnrengelman.shadow") version "7.1.0"
|
||||
id("net.minecrell.plugin-yml.bukkit") version "0.5.1"
|
||||
}
|
||||
|
||||
allprojects {
|
||||
|
|
@ -45,6 +44,7 @@ subprojects {
|
|||
url = uri("https://repo.destro.xyz/snapshots/")
|
||||
credentials(PasswordCredentials::class)
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
plugins {
|
||||
`maven-publish`
|
||||
id("com.github.johnrengelman.shadow")
|
||||
id("net.minecrell.plugin-yml.bukkit")
|
||||
id("net.minecrell.plugin-yml.bukkit") version "0.5.1"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ dependencies {
|
|||
exclude("net.kyori")
|
||||
exclude("net.kyori.examination")
|
||||
}
|
||||
//Luckperms
|
||||
compileOnly("net.luckperms:api:5.3")
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.alttd.boosterapi.util.ALogger;
|
|||
import com.alttd.proxydiscordlink.DiscordLink;
|
||||
import com.alttd.proxydiscordlink.bot.api.DiscordSendMessage;
|
||||
import com.alttd.vboosters.commands.BoosterCommand;
|
||||
import com.alttd.vboosters.commands.DonorRankCommand;
|
||||
import com.alttd.vboosters.listeners.PluginMessageListener;
|
||||
import com.alttd.vboosters.managers.BoosterManager;
|
||||
import com.google.inject.Inject;
|
||||
|
|
@ -79,6 +80,7 @@ public class VelocityBoosters {
|
|||
public void loadCommands() {
|
||||
// all (proxy)commands go here
|
||||
new BoosterCommand(server);
|
||||
new DonorRankCommand(server);
|
||||
}
|
||||
|
||||
public ChannelIdentifier getChannelIdentifier() {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package com.alttd.vboosters.commands;
|
|||
|
||||
import com.alttd.boosterapi.BoosterAPI;
|
||||
import com.alttd.boosterapi.config.Config;
|
||||
import com.alttd.boosterapi.util.Utils;
|
||||
import com.alttd.vboosters.VelocityBoosters;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
|
|
@ -11,52 +13,53 @@ import com.velocitypowered.api.command.CommandMeta;
|
|||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import net.luckperms.api.node.Node;
|
||||
import net.luckperms.api.node.NodeType;
|
||||
import net.luckperms.api.node.types.InheritanceNode;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class DonorRankCommand {
|
||||
|
||||
private final MiniMessage miniMessage;
|
||||
|
||||
public DonorRankCommand(ProxyServer proxyServer) {
|
||||
miniMessage = MiniMessage.get();
|
||||
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||
.<CommandSource>literal("donorrank")
|
||||
.requires(ctx -> ctx.hasPermission("command.proxy.donorrank"))
|
||||
.then(RequiredArgumentBuilder.argument("username", StringArgumentType.word()))
|
||||
.then(RequiredArgumentBuilder.argument("action", StringArgumentType.word()))
|
||||
.then(RequiredArgumentBuilder.argument("rank", StringArgumentType.word()))
|
||||
.then(RequiredArgumentBuilder.argument("transaction-id", StringArgumentType.word()))
|
||||
.executes(context -> {
|
||||
//EX: donorrank {username} promote archduke {transaction}
|
||||
//File: {transaction}, cbccaa76-906d-458e-a24e-4b74322f2bb7, none -> archduke
|
||||
//EX: donorrank {username} demote archduke {transaction}
|
||||
//TODO command format: /donorrank user promote rank donate_id
|
||||
//TODO store the command and before and after rank in a file
|
||||
//TODO remove old donor ranks and add the new one
|
||||
|
||||
if (!Config.donorRanks.contains(context.getInput())) //TODO validate group from command is donor
|
||||
return 0;
|
||||
String username = context.getArgument("username", String.class);
|
||||
String action = context.getArgument("context", String.class);
|
||||
String rank = context.getArgument("rank", String.class);
|
||||
|
||||
LuckPerms luckPerms = BoosterAPI.get().getLuckPerms();
|
||||
User user = luckPerms.getUserManager().getUser(UUID.fromString(context.getInput())); //TODO context.getInput needs to get uuid
|
||||
User user = luckPerms.getUserManager().getUser(username); //TODO test if this works with username
|
||||
|
||||
if (user == null) {
|
||||
context.getSource().sendMessage(MiniMessage.get().parse("string")); //TODO configurable message
|
||||
return 0;
|
||||
context.getSource().sendMessage(miniMessage.parse(
|
||||
Config.INVALID_USER,
|
||||
Template.of("player", username)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!Config.donorRanks.contains(context.getInput())) {
|
||||
context.getSource().sendMessage(miniMessage.parse(
|
||||
Config.INVALID_DONOR_RANK,
|
||||
Template.of("rank", rank)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case "promote" -> promote(user, rank);
|
||||
case "demote" -> demote(user, rank);
|
||||
default -> context.getSource().sendMessage(miniMessage.parse(Config.INVALID_ACTION));
|
||||
}
|
||||
user.getNodes(NodeType.INHERITANCE).stream()
|
||||
.filter(Node::getValue)
|
||||
.forEach(node -> {
|
||||
if (Config.donorRanks.contains(node.getKey()))
|
||||
user.data().remove(node);
|
||||
});
|
||||
user.data().add(InheritanceNode.builder(context.getInput()).build()); //TODO this needs to add the group from the command
|
||||
//TODO command format: /donorrank user promote rank donate_id
|
||||
//TODO get command and before and after rank from a file
|
||||
//TODO remove the command and before and after rank from a file
|
||||
//TODO remove current donor ranks and add the old one back (or remove them all if there was no old one)
|
||||
// VelocityBoosters.getPlugin().getLogger().info(stuff);
|
||||
return 1;
|
||||
})
|
||||
.build();
|
||||
|
|
@ -69,4 +72,37 @@ public class DonorRankCommand {
|
|||
|
||||
proxyServer.getCommandManager().register(meta, brigadierCommand);
|
||||
}
|
||||
|
||||
private void promote(User user, String rank) {
|
||||
user.getNodes(NodeType.INHERITANCE).stream()
|
||||
.filter(Node::getValue)
|
||||
.forEach(node -> {
|
||||
if (Config.donorRanks.contains(node.getKey()))
|
||||
user.data().remove(node);
|
||||
});
|
||||
user.data().add(InheritanceNode.builder(rank).build());
|
||||
VelocityBoosters.getPlugin().getProxy().getPlayer(user.getUniqueId()).ifPresent(player -> {
|
||||
if (player.isActive()) {
|
||||
player.sendMessage(miniMessage.parse(Config.PROMOTE_MESSAGE,
|
||||
Template.of("rank", Utils.capitalize(rank)),
|
||||
Template.of("player", player.getUsername())));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void demote(User user, String rank) {
|
||||
user.getNodes(NodeType.INHERITANCE).stream()
|
||||
.filter(Node::getValue)
|
||||
.forEach(node -> {
|
||||
if (Config.donorRanks.contains(node.getKey()))
|
||||
user.data().remove(node);
|
||||
});
|
||||
VelocityBoosters.getPlugin().getProxy().getPlayer(user.getUniqueId()).ifPresent(player -> {
|
||||
if (player.isActive()) {
|
||||
player.sendMessage(miniMessage.parse(Config.DEMOTE_MESSAGE,
|
||||
Template.of("rank", Utils.capitalize(rank)),
|
||||
Template.of("player", player.getUsername())));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user