Add villager points reset command and related configurations
This commit is contained in:
parent
e1ccfd05de
commit
d484e4b7be
|
|
@ -40,6 +40,7 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
|||
new CommandAutoSell(autoSellTask),
|
||||
new CommandCreateVillager(),
|
||||
new CommandReload(),
|
||||
new CommandReset(),
|
||||
new CommandRemoveVillager());
|
||||
miniMessage = MiniMessage.miniMessage();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,75 @@
|
|||
package com.alttd.commands.subcommands;
|
||||
|
||||
import com.alttd.commands.SubCommand;
|
||||
import com.alttd.config.Config;
|
||||
import com.alttd.objects.EconUser;
|
||||
import com.alttd.objects.VillagerType;
|
||||
import com.alttd.objects.VillagerTypeManager;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CommandReset extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
if (args.length != 2) {
|
||||
commandSender.sendRichMessage(getHelpMessage());
|
||||
return true;
|
||||
}
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendRichMessage(Config.NO_CONSOLE);
|
||||
return true;
|
||||
}
|
||||
EconUser user = EconUser.getUser(player.getUniqueId());
|
||||
if (user == null) {
|
||||
player.sendRichMessage(Config.LOADING_ECON_DATA);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equals("all")) {
|
||||
VillagerTypeManager.getVillagerTypes().forEach(villagerType -> resetPoints(user, villagerType));
|
||||
} else {
|
||||
Optional<VillagerType> optionalVillagerType = VillagerTypeManager.getVillagerType(args[1].toLowerCase());
|
||||
if (optionalVillagerType.isEmpty()) {
|
||||
player.sendRichMessage(Config.NOT_A_VILLAGER, TagResolver.resolver(Placeholder.unparsed("villager_type", args[1])));
|
||||
return true;
|
||||
}
|
||||
resetPoints(user, optionalVillagerType.get());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void resetPoints(EconUser user, VillagerType villagerType) {
|
||||
int pointsToRemove = user.getPointsMap().getOrDefault(villagerType.getName(), 0);
|
||||
user.addPoints(villagerType.getName(), pointsToRemove * -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "reset";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||
List<String> res = new ArrayList<>();
|
||||
if (args.length == 2) {
|
||||
res.addAll(VillagerTypeManager.getVillagerTypes().stream()
|
||||
.map(VillagerType::getName)
|
||||
.toList());
|
||||
}
|
||||
res.add("all");
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.RESET_POINTS_MESSAGE;
|
||||
}
|
||||
}
|
||||
|
|
@ -74,6 +74,7 @@ public final class Config extends AbstractConfig {
|
|||
public static String RELOAD_MESSAGE = "<green>Reload configs: <gold>/villagerui reload</gold></green>";
|
||||
public static String CREATE_VILLAGER_MESSAGE = "<green>Create a new trading villager: <gold>/villagerui createvillager <type> <biome> <x> <y> <z> <yaw> <pitch> <world></gold></green>";
|
||||
public static String REMOVE_VILLAGER_MESSAGE = "<green>Removes all existing trading villagers in a 2 block radius: <gold>/villagerui removevillager</gold></green>";
|
||||
public static String RESET_POINTS_MESSAGE = "<green>Reset all villager points: <gold>/villagerui resetpoints <villager_type></gold></green>";
|
||||
|
||||
private static void loadHelp() {
|
||||
HELP_MESSAGE_WRAPPER = config.getString("help.help-wrapper", HELP_MESSAGE_WRAPPER);
|
||||
|
|
@ -85,6 +86,7 @@ public final class Config extends AbstractConfig {
|
|||
RELOAD_MESSAGE = config.getString("help.reload", RELOAD_MESSAGE);
|
||||
CREATE_VILLAGER_MESSAGE = config.getString("help.create-villager", CREATE_VILLAGER_MESSAGE);
|
||||
REMOVE_VILLAGER_MESSAGE = config.getString("help.remove-villager", REMOVE_VILLAGER_MESSAGE);
|
||||
RESET_POINTS_MESSAGE = config.getString("help.reset-points-message", RESET_POINTS_MESSAGE);
|
||||
}
|
||||
|
||||
public static String NO_PERMISSION = "<red>You do not have permission to do that.</red>";
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user