Updated VillagerShopUI to 1.21.6 (using Cosmos)

This commit is contained in:
akastijn 2025-06-27 20:39:21 +02:00
parent 3fc8561265
commit 97c711ea29
19 changed files with 140 additions and 98 deletions

View File

@ -1,5 +1,3 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
plugins {
id("java")
id("com.github.johnrengelman.shadow") version "7.1.1"
@ -27,9 +25,12 @@ publishing {
repositories{
maven {
name = "alttd"
url = uri("https://repo.destro.xyz/snapshots")
credentials(PasswordCredentials::class)
name = "nexus"
url = uri("https://repo.alttd.com/repository/alttd-snapshot/")
credentials {
username = project.property("alttdSnapshotUsername") as String
password = project.property("alttdSnapshotPassword") as String
}
}
}
}
@ -57,11 +58,11 @@ tasks {
}
dependencies {
compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT") {
compileOnly("com.alttd.cosmos:cosmos-api:1.21.6-R0.1-SNAPSHOT") {
isChanging = true
}
compileOnly("com.github.milkbowl:VaultAPI:1.7") {
exclude("org.bukkit","bukkit")
}
compileOnly("com.alttd.datalock:api:1.1.0-SNAPSHOT")
}
}

View File

@ -1,10 +1,21 @@
rootProject.name = "VillagerShopUI"
val nexusUser = providers.gradleProperty("alttdSnapshotUsername").get()
val nexusPass = providers.gradleProperty("alttdSnapshotPassword").get()
dependencyResolutionManagement {
repositories {
mavenLocal()
mavenCentral()
maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
maven {
name = "nexus"
url = uri("https://repo.alttd.com/repository/alttd-snapshot/")
credentials {
username = nexusUser
password = nexusPass
}
}
maven("https://repo.destro.xyz/snapshots") // Cosmos
maven("https://jitpack.io") { // Vault
content { includeGroup("com.github.milkbowl") }
}

View File

@ -64,7 +64,7 @@ public class BuyGUI extends GUIMerchant {
int transPts = itemPts * amount;
EconUser econUser = EconUser.getUser(player.getUniqueId());
if (econUser == null) {
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
player.sendRichMessage(Config.LOADING_ECON_DATA);
return;
}
int oldPoints = econUser.getPointsMap().getOrDefault(villagerType.getName(), 0);
@ -87,14 +87,14 @@ public class BuyGUI extends GUIMerchant {
if ((newTime - 120) > lastClicked)
lastClicked = newTime;
else {
player.sendMiniMessage(Config.CLICKING_TOO_FAST, null);
player.sendRichMessage(Config.CLICKING_TOO_FAST);
return;
}
Economy econ = VillagerUI.getInstance().getEconomy();
double balance = econ.getBalance(player);
if (balance < purchase.price()) {
player.sendMiniMessage(Config.NOT_ENOUGH_MONEY, TagResolver.resolver(
player.sendRichMessage(Config.NOT_ENOUGH_MONEY, TagResolver.resolver(
Placeholder.unparsed("money", String.valueOf(Utilities.round(balance, 2))),
Placeholder.unparsed("price", String.format("%,.2f", purchase.price()))
));
@ -113,7 +113,7 @@ public class BuyGUI extends GUIMerchant {
ref.space += itemStack.getMaxStackSize() - itemStack.getAmount();
});
if (ref.space < purchase.amount()) {
player.sendMiniMessage(Config.NOT_ENOUGH_SPACE, TagResolver.resolver(
player.sendRichMessage(Config.NOT_ENOUGH_SPACE, TagResolver.resolver(
Placeholder.unparsed("space", String.valueOf(ref.space)),
Placeholder.unparsed("amount", String.valueOf(purchase.amount()))
));
@ -125,7 +125,7 @@ public class BuyGUI extends GUIMerchant {
player.getInventory().addItem(new ItemStack(purchase.material(), purchase.amount()));
int newPoints = econUser.getPointsMap().get(villagerType.getName());
player.sendMiniMessage(Config.PURCHASED_ITEM, TagResolver.resolver(
player.sendRichMessage(Config.PURCHASED_ITEM, TagResolver.resolver(
Placeholder.unparsed("amount", String.valueOf(purchase.amount())),
Placeholder.unparsed("item", Utilities.capitalize(purchase.material().name()
.toLowerCase().replaceAll("_", " "))),

View File

@ -94,7 +94,7 @@ public class SellGUI extends GUIMerchant {
private void sell(VillagerType villagerType, Player player, Material material, int amount, Price price, boolean bulk) {
EconUser econUser = EconUser.getUser(player.getUniqueId());
if (econUser == null) {
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
player.sendRichMessage(Config.LOADING_ECON_DATA);
return;
}
@ -120,12 +120,12 @@ public class SellGUI extends GUIMerchant {
if ((newTime - 120) > lastClicked)
lastClicked = newTime;
else {
player.sendMiniMessage(Config.CLICKING_TOO_FAST, null);
player.sendRichMessage(Config.CLICKING_TOO_FAST);
return;
}
PlayerInventory inventory = player.getInventory();
if (countTotalBlocksInInventory(inventory, purchase.material()) < purchase.amount()) {
player.sendMiniMessage(Config.NOT_ENOUGH_ITEMS, TagResolver.resolver(
player.sendRichMessage(Config.NOT_ENOUGH_ITEMS, TagResolver.resolver(
Placeholder.unparsed("type", purchase.material().name()),
Placeholder.unparsed("amount", String.valueOf(purchase.amount()))));
return;
@ -153,7 +153,7 @@ public class SellGUI extends GUIMerchant {
int newPoints = econUser.getPointsMap().get(villagerType.getName());
player.sendMiniMessage(Config.SOLD_ITEM, TagResolver.resolver(
player.sendRichMessage(Config.SOLD_ITEM, TagResolver.resolver(
Placeholder.unparsed("amount", String.valueOf(purchase.amount())),
Placeholder.unparsed("item", Utilities.capitalize(purchase.material().name()
.toLowerCase().replaceAll("_", " "))),

View File

@ -66,7 +66,7 @@ public class TradeGUI extends GUIMerchant {
private void trade(BlackMarketVillagerType villagerType, Player player, Material material, int amount, Double price) {
EconUser econUser = EconUser.getUser(player.getUniqueId());
if (econUser == null) {
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
player.sendRichMessage(Config.LOADING_ECON_DATA);
return;
}
@ -99,13 +99,13 @@ public class TradeGUI extends GUIMerchant {
if ((newTime - 120) > lastClicked)
lastClicked = newTime;
else {
player.sendMiniMessage(Config.CLICKING_TOO_FAST, null);
player.sendRichMessage(Config.CLICKING_TOO_FAST);
return;
}
UUID uuid = player.getUniqueId();
if (villagerType.getRemainingTrades(uuid) <= 0) {
player.sendMiniMessage(Config.NO_TRADES_REMAINING, null);
player.sendRichMessage(Config.NO_TRADES_REMAINING);
return;
}
@ -113,7 +113,7 @@ public class TradeGUI extends GUIMerchant {
double balance = econ.getBalance(player);
if (balance < price) {
player.sendMiniMessage(Config.NOT_ENOUGH_MONEY, TagResolver.resolver(
player.sendRichMessage(Config.NOT_ENOUGH_MONEY, TagResolver.resolver(
Placeholder.unparsed("money", String.valueOf(Utilities.round(balance, 2))),
Placeholder.unparsed("price", String.format("%,.2f", price))
));
@ -130,7 +130,7 @@ public class TradeGUI extends GUIMerchant {
atomicInteger.addAndGet(itemStack.getMaxStackSize() - itemStack.getAmount());
});
if (atomicInteger.get() < amount) {
player.sendMiniMessage(Config.NOT_ENOUGH_SPACE, TagResolver.resolver(
player.sendRichMessage(Config.NOT_ENOUGH_SPACE, TagResolver.resolver(
Placeholder.unparsed("space", String.valueOf(atomicInteger.get())),
Placeholder.unparsed("amount", String.valueOf(amount))
));
@ -142,7 +142,7 @@ public class TradeGUI extends GUIMerchant {
randomizeMetaIfNeeded(material, itemStack);
player.getInventory().addItem(itemStack);
player.sendMiniMessage(Config.TRADED_ITEM, TagResolver.resolver(
player.sendRichMessage(Config.TRADED_ITEM, TagResolver.resolver(
Placeholder.parsed("amount", String.valueOf(amount)),
Placeholder.parsed("item", Utilities.capitalize(material.name()
.toLowerCase().replaceAll("_", " "))),

View File

@ -45,17 +45,17 @@ public class CommandManager implements CommandExecutor, TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String cmd, @NotNull String[] args) {
if (args.length == 0) {
commandSender.sendMiniMessage(Config.HELP_MESSAGE_WRAPPER.replaceAll("<commands>", subCommands.stream()
commandSender.sendRichMessage(Config.HELP_MESSAGE_WRAPPER.replaceAll("<commands>", subCommands.stream()
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
.map(SubCommand::getHelpMessage)
.collect(Collectors.joining("\n"))), null);
.collect(Collectors.joining("\n"))));
return true;
}
SubCommand subCommand = getSubCommand(args[0]);
if (!commandSender.hasPermission(subCommand.getPermission())) {
commandSender.sendMiniMessage(Config.NO_PERMISSION, null);
commandSender.sendRichMessage(Config.NO_PERMISSION);
return true;
}
@ -93,4 +93,4 @@ public class CommandManager implements CommandExecutor, TabExecutor {
.findFirst()
.orElse(null);
}
}
}

View File

@ -26,21 +26,21 @@ public class CommandBuy extends SubCommand {
@Override
public boolean onCommand(CommandSender commandSender, String[] args) {
if (!(commandSender instanceof Player player)) {
commandSender.sendMiniMessage(Config.NO_CONSOLE, null);
commandSender.sendRichMessage(Config.NO_CONSOLE);
return true;
}
if (args.length == 1) {
//TODO open gui
player.sendMiniMessage(getHelpMessage(), null); //TODO remove later
player.sendRichMessage(getHelpMessage()); //TODO remove later
return true;
}
if (args.length != 2) {
player.sendMiniMessage(getHelpMessage(), null);
player.sendRichMessage(getHelpMessage());
return true;
}
EconUser user = EconUser.getUser(player.getUniqueId());
if (user == null) {
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
player.sendRichMessage(Config.LOADING_ECON_DATA);
return true;
}
Material item = Material.valueOf(args[1].toUpperCase());
@ -50,7 +50,7 @@ public class CommandBuy extends SubCommand {
.anyMatch(material -> material.equals(item)))
.findFirst();
if (optionalVillagerType.isEmpty()) {
player.sendMiniMessage(Config.NO_BUY_AT_SPAWN, TagResolver.resolver(Placeholder.unparsed("material", item.name())));
player.sendRichMessage(Config.NO_BUY_AT_SPAWN, TagResolver.resolver(Placeholder.unparsed("material", item.name())));
return true;
}
VillagerType villagerType = optionalVillagerType.get();
@ -61,7 +61,7 @@ public class CommandBuy extends SubCommand {
}
Integer curPoints = user.getPointsMap().getOrDefault(villagerType.getName(), 0);
double cost = price.calculatePriceThing(curPoints, price.getPoints(), true, price.getPoints());
player.sendMiniMessage(Config.BUY_ITEM_MESSAGE, TagResolver.resolver(
player.sendRichMessage(Config.BUY_ITEM_MESSAGE, TagResolver.resolver(
Placeholder.unparsed("material", item.name()),
Placeholder.unparsed("price", String.valueOf(cost)),
Placeholder.unparsed("points", String.valueOf(price.getPoints())),

View File

@ -3,6 +3,7 @@ package com.alttd.commands.subcommands;
import com.alttd.commands.SubCommand;
import com.alttd.config.Config;
import com.alttd.config.VillagerConfig;
import com.alttd.mappers.VillagerTypeMapper;
import com.alttd.objects.LoadedVillagers;
import com.alttd.objects.VillagerType;
import com.alttd.objects.VillagerTypeManager;
@ -19,40 +20,39 @@ import org.bukkit.entity.Villager;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.*;
import java.util.stream.Collectors;
public class CommandCreateVillager extends SubCommand {
@Override
public boolean onCommand(CommandSender commandSender, String[] args) {
if (args.length != 9) {
commandSender.sendMiniMessage(getHelpMessage(), null);
commandSender.sendRichMessage(getHelpMessage());
return true;
}
Optional<VillagerType> first = VillagerTypeManager.getVillagerTypes().stream().filter(villagerType -> villagerType.getName().equalsIgnoreCase(args[1])).findFirst();
Optional<VillagerType> first = VillagerTypeManager.getVillagerType(args[1]);
if (first.isEmpty()) {
commandSender.sendMiniMessage(getHelpMessage(), null);
commandSender.sendRichMessage(getHelpMessage());
return true;
}
VillagerType villagerType = first.get();
Villager.Type type = Villager.Type.valueOf(args[2].toUpperCase());
if (type == null) { //TODO test if this might need a try catch?
commandSender.sendMiniMessage(getHelpMessage(), null);
Optional<Villager.Type> optionalVillagerType = VillagerTypeMapper.map(args[2]);
if (optionalVillagerType.isEmpty()) {
commandSender.sendRichMessage(getHelpMessage());
return true;
}
World world = Bukkit.getServer().getWorld(args[8]);
if (world == null) {
commandSender.sendMiniMessage(getHelpMessage(), null);
commandSender.sendRichMessage(getHelpMessage());
return true;
}
Location location = new Location(world, Double.parseDouble(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Float.parseFloat(args[6]), Float.parseFloat(args[7]));
Villager villager = (Villager) world.spawnEntity(location, EntityType.VILLAGER, CreatureSpawnEvent.SpawnReason.CUSTOM);
villager.setPersistent(true);
villager.setInvulnerable(true);
villager.setVillagerType(type);
villager.setVillagerType(optionalVillagerType.get());
villager.setProfession(villagerType.getProfession());
villager.setRemoveWhenFarAway(false);
villager.setCollidable(false);
@ -80,10 +80,10 @@ public class CommandCreateVillager extends SubCommand {
switch (args.length) {
case 2 -> res.addAll(VillagerTypeManager.getVillagerTypes().stream()
.map(VillagerType::getName)
.collect(Collectors.toList()));
.toList());
case 3 -> res.addAll(Arrays.stream(Villager.Type.values())
.map(something -> something.name())
.collect(Collectors.toList()));
.toList());
case 4 -> {
if (commandSender instanceof Player player) {
res.add(String.valueOf(Utilities.round(player.getLocation().getX(), 2)));

View File

@ -20,11 +20,11 @@ public class CommandHelp extends SubCommand {
@Override
public boolean onCommand(CommandSender commandSender, String[] args) {
commandSender.sendMiniMessage(Config.HELP_MESSAGE_WRAPPER.replaceAll("<commands>", commandManager
commandSender.sendRichMessage(Config.HELP_MESSAGE_WRAPPER.replaceAll("<commands>", commandManager
.getSubCommands().stream()
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
.map(SubCommand::getHelpMessage)
.collect(Collectors.joining("\n"))), null);
.collect(Collectors.joining("\n"))));
return true;
}

View File

@ -9,6 +9,7 @@ import com.alttd.objects.VillagerTypeManager;
import com.alttd.util.Logger;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
@ -17,6 +18,7 @@ import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@ -27,12 +29,12 @@ public class CommandPoints extends SubCommand {
@Override
public boolean onCommand(CommandSender commandSender, String[] args) {
if (!(commandSender instanceof Player player)) {
commandSender.sendMiniMessage(Config.NO_CONSOLE, null);
commandSender.sendRichMessage(Config.NO_CONSOLE);
return true;
}
EconUser user = EconUser.getUser(player.getUniqueId());
if (user == null) {
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
player.sendRichMessage(Config.LOADING_ECON_DATA);
return true;
}
var ref = new Object() {
@ -45,20 +47,18 @@ public class CommandPoints extends SubCommand {
Object2ObjectOpenHashMap<String, Integer> pointsMap = user.getPointsMap();
pointsMap.keySet().forEach(key -> {
VillagerType villagerType = VillagerTypeManager.getVillagerType(key);
if (villagerType == null) {
Optional<VillagerType> optionalVillagerType = VillagerTypeManager.getVillagerType(key);
if (optionalVillagerType.isEmpty()) {
Logger.warning("Player % has unused villager type % in their point list.", player.getName(), key);
return;
}
VillagerType villagerType = optionalVillagerType.get();
int currentPoints = pointsMap.getOrDefault(key, 0);
if (currentPoints == 0) return;
if (currentPoints == 0) {
return;
}
allPointsAreZero.set(false);
ref.message = ref.message.append(miniMessage.deserialize("\n", TagResolver.resolver()));
ref.message = ref.message.append(miniMessage.deserialize(Config.POINTS_CONTENT, TagResolver.resolver(
Placeholder.unparsed("villager_type", VillagerTypeManager.getVillagerType(key).getDisplayName()),
Placeholder.unparsed("points", String.valueOf(currentPoints)),
Placeholder.unparsed("buy_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, true))),
Placeholder.unparsed("sell_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, false))))));
ref.message = ref.message.append(getPointContentComponent(villagerType, currentPoints));
});
if (allPointsAreZero.get()) {
ref.message = miniMessage.deserialize(Config.NO_VILLAGER_POINTS);
@ -70,36 +70,41 @@ public class CommandPoints extends SubCommand {
Object2ObjectOpenHashMap<String, Integer> pointsMap = user.getPointsMap();
int currentPoints = pointsMap.getOrDefault(villagerType.getName(), 0);
ref.message = ref.message.append(miniMessage.deserialize("\n", TagResolver.resolver()));
ref.message = ref.message.append(miniMessage.deserialize(Config.POINTS_CONTENT, TagResolver.resolver(
Placeholder.unparsed("villager_type", villagerType.getDisplayName()),
Placeholder.unparsed("points", String.valueOf(currentPoints)),
Placeholder.unparsed("buy_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, true))),
Placeholder.unparsed("sell_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, false)))
)));
ref.message = ref.message.append(getPointContentComponent(villagerType, currentPoints));
}
} else {
VillagerType villagerType = VillagerTypeManager.getVillagerType(args[1].toLowerCase());
Optional<VillagerType> optionalVillagerType = VillagerTypeManager.getVillagerType(args[1].toLowerCase());
Object2ObjectOpenHashMap<String, Integer> pointsMap = user.getPointsMap();
if (villagerType == null) {
player.sendMiniMessage(Config.NOT_A_VILLAGER, TagResolver.resolver(Placeholder.unparsed("villager_type", args[1])));
if (optionalVillagerType.isEmpty()) {
player.sendRichMessage(Config.NOT_A_VILLAGER, TagResolver.resolver(Placeholder.unparsed("villager_type", args[1])));
return true;
}
VillagerType villagerType = optionalVillagerType.get();
int currentPoints = pointsMap.getOrDefault(villagerType.getName(), 0);
ref.message = ref.message.append(miniMessage.deserialize(Config.POINTS_CONTENT, TagResolver.resolver(
Placeholder.unparsed("villager_type", villagerType.getDisplayName()),
Placeholder.unparsed("points", String.valueOf(currentPoints)),
Placeholder.unparsed("buy_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, true))),
Placeholder.unparsed("sell_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, false)))
)));
)));
}
} else
player.sendMiniMessage(getHelpMessage(), null);
} else {
player.sendRichMessage(getHelpMessage());
}
player.sendMessage(ref.message);
player.sendMessage((ComponentLike) ref.message);
return true;
}
private Component getPointContentComponent(VillagerType villagerType, int currentPoints) {
return miniMessage.deserialize("\n", TagResolver.resolver())
.append(miniMessage.deserialize(Config.POINTS_CONTENT, TagResolver.resolver(
Placeholder.unparsed("villager_type", villagerType.getDisplayName()),
Placeholder.unparsed("points", String.valueOf(currentPoints)),
Placeholder.unparsed("buy_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, true))),
Placeholder.unparsed("sell_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, false))))));
}
@Override
public String getName() {
return "points";
@ -108,10 +113,11 @@ public class CommandPoints extends SubCommand {
@Override
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
List<String> res = new ArrayList<>();
if (args.length == 2)
if (args.length == 2) {
res.addAll(VillagerTypeManager.getVillagerTypes().stream()
.map(VillagerType::getName)
.collect(Collectors.toList()));
.map(VillagerType::getName)
.collect(Collectors.toList()));
}
res.add("all");
return res;
}

View File

@ -16,7 +16,7 @@ public class CommandReload extends SubCommand {
Config.reload();
VillagerConfig.reload();
WorthConfig.reload();
commandSender.sendMiniMessage("<green>Reloaded VillagerShopUI config.</green>", null);
commandSender.sendRichMessage("<green>Reloaded VillagerShopUI config.</green>");
return true;
}

View File

@ -20,7 +20,7 @@ public class CommandRemoveVillager extends SubCommand {
@Override
public boolean onCommand(CommandSender commandSender, String[] args) {
if (!(commandSender instanceof Player player)) {
commandSender.sendMiniMessage(Config.NO_CONSOLE, null);
commandSender.sendRichMessage(Config.NO_CONSOLE);
return true;
}
@ -33,7 +33,7 @@ public class CommandRemoveVillager extends SubCommand {
LoadedVillagers.removeLoadedVillager(uuid);
VillagerConfig.removeVillager(uuid);
entity.remove();
player.sendMiniMessage(Config.REMOVED_VILLAGER, TagResolver.resolver(
player.sendRichMessage(Config.REMOVED_VILLAGER, TagResolver.resolver(
Placeholder.unparsed("uuid", uuid.toString())));
}
return true;

View File

@ -26,21 +26,21 @@ public class CommandSell extends SubCommand {
@Override
public boolean onCommand(CommandSender commandSender, String[] args) {
if (!(commandSender instanceof Player player)) {
commandSender.sendMiniMessage(Config.NO_CONSOLE, null);
commandSender.sendRichMessage(Config.NO_CONSOLE);
return true;
}
if (args.length == 1) {
//TODO open gui
player.sendMiniMessage(getHelpMessage(), null); //TODO remove later
player.sendRichMessage(getHelpMessage()); //TODO remove later
return true;
}
if (args.length != 2) {
player.sendMiniMessage(getHelpMessage(), null);
player.sendRichMessage(getHelpMessage());
return true;
}
EconUser user = EconUser.getUser(player.getUniqueId());
if (user == null) {
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
player.sendRichMessage(Config.LOADING_ECON_DATA);
return true;
}
Material item = Material.valueOf(args[1].toUpperCase());
@ -50,7 +50,7 @@ public class CommandSell extends SubCommand {
.anyMatch(material -> material.equals(item)))
.findFirst();
if (optionalVillagerType.isEmpty()) {
player.sendMiniMessage(Config.NO_SELL_AT_SPAWN, TagResolver.resolver(Placeholder.unparsed("material", item.name())));
player.sendRichMessage(Config.NO_SELL_AT_SPAWN, TagResolver.resolver(Placeholder.unparsed("material", item.name())));
return true;
}
VillagerType villagerType = optionalVillagerType.get();
@ -61,7 +61,7 @@ public class CommandSell extends SubCommand {
}
Integer curPoints = user.getPointsMap().getOrDefault(villagerType.getName(), 0);
double cost = price.calculatePriceThing(curPoints, price.getPoints(), false, price.getPoints());
player.sendMiniMessage(Config.SELL_ITEM_MESSAGE, TagResolver.resolver(
player.sendRichMessage(Config.SELL_ITEM_MESSAGE, TagResolver.resolver(
Placeholder.unparsed("material", item.name()),
Placeholder.unparsed("price", String.valueOf(cost)),
Placeholder.unparsed("points", String.valueOf(price.getPoints())),

View File

@ -4,6 +4,8 @@ import com.alttd.objects.LoadedVillagers;
import com.alttd.objects.VillagerType;
import com.alttd.objects.VillagerTypeManager;
import com.alttd.util.Logger;
import java.util.Optional;
import java.util.UUID;
public class VillagerConfig extends AbstractConfig {
@ -27,11 +29,10 @@ public class VillagerConfig extends AbstractConfig {
private static void loadVillagers() {
LoadedVillagers.clearLoadedVillagers();
config.getConfigurationSection("").getKeys(false).forEach(key -> {
VillagerType villagerType = VillagerTypeManager.getVillagerType(config.getString(key, ""));
if (villagerType != null)
LoadedVillagers.addLoadedVillager(UUID.fromString(key), villagerType);
else
Logger.warning("Invalid config entry %.", key);
Optional<VillagerType> optionalVillagerType = VillagerTypeManager.getVillagerType(config.getString(key, ""));
optionalVillagerType
.ifPresentOrElse(present -> LoadedVillagers.addLoadedVillager(UUID.fromString(key), present),
() -> Logger.warning("Invalid config entry %.", key));
});
}

View File

@ -7,6 +7,7 @@ import org.bukkit.configuration.ConfigurationSection;
import java.io.File;
import java.util.List;
import java.util.Optional;
import java.util.Set;
public class VillagerMessagesConfig extends AbstractConfig {
@ -41,12 +42,12 @@ public class VillagerMessagesConfig extends AbstractConfig {
}
keys.forEach(key -> {
VillagerType villagerType = VillagerTypeManager.getVillagerType(key);
if (villagerType == null) {
Optional<VillagerType> optionalVillagerType = VillagerTypeManager.getVillagerType(key);
if (optionalVillagerType.isEmpty()) {
Logger.info("Unknown villager type: " + key);
return;
}
villagerType.setMessages(configurationSection.getStringList(key));
optionalVillagerType.get().setMessages(configurationSection.getStringList(key));
});
}
}

View File

@ -5,8 +5,9 @@ import com.alttd.GUI.windows.TradeGUI;
import com.alttd.VillagerUI;
import com.alttd.config.Config;
import com.alttd.config.VillagerConfig;
import com.alttd.galaxy.event.player.PlayerInteractOnEntityEvent;
import com.alttd.cosmos.event.player.PlayerInteractOnEntityEvent;
import com.alttd.objects.*;
import net.kyori.adventure.text.ComponentLike;
import org.bukkit.Sound;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@ -35,12 +36,12 @@ public class VillagerEvents implements Listener {
Player player = event.getPlayer();
event.setCancelled(true);
if (!player.hasPermission(loadedVillager.getPermission())) {
player.sendMiniMessage(Config.NO_PERMISSION, null); //TODO more specific message?
player.sendRichMessage(Config.NO_PERMISSION); //TODO more specific message?
return;
}
EconUser user = EconUser.getUser(player.getUniqueId());
if (user == null) {
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
player.sendRichMessage(Config.LOADING_ECON_DATA);
return;
}
new BukkitRunnable() {
@ -80,7 +81,7 @@ public class VillagerEvents implements Listener {
return;
}
loadedVillager.getRandomMessage().ifPresent(player::sendMessage);
loadedVillager.getRandomMessage().ifPresent(component -> player.sendMessage((ComponentLike) component));
if (loadedVillager instanceof BlackMarketVillagerType) {
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_HURT, 1.0F, 1.0F);
} else if (loadedVillager instanceof ShopVillagerType) {

View File

@ -0,0 +1,20 @@
package com.alttd.mappers;
import org.bukkit.entity.Villager;
import java.util.Optional;
public class VillagerTypeMapper {
public static Optional<Villager.Type> map(String villagerType) {
return switch (villagerType.toUpperCase()) {
case "DESERT" -> Optional.of(Villager.Type.DESERT);
case "JUNGLE" -> Optional.of(Villager.Type.JUNGLE);
case "PLAINS" -> Optional.of(Villager.Type.PLAINS);
case "SAVANNA" -> Optional.of(Villager.Type.SAVANNA);
case "SNOW" -> Optional.of(Villager.Type.SNOW);
case "SWAMP" -> Optional.of(Villager.Type.SWAMP);
case "TAIGA" -> Optional.of(Villager.Type.TAIGA);
default -> Optional.empty();
};
}
}

View File

@ -132,7 +132,7 @@ public class EconUser {
public void notifyPlayer(UUID uuid, String villagerType) {
Player player = Bukkit.getPlayer(uuid);
if (player != null && player.isOnline())
player.sendMiniMessage(Config.NOTIFY_POINTS_RESET, Placeholder.unparsed("villager_type", villagerType));
player.sendRichMessage(Config.NOTIFY_POINTS_RESET, Placeholder.unparsed("villager_type", villagerType));
}
public static void tryLoadUser(UUID uuid) {

View File

@ -1,6 +1,7 @@
package com.alttd.objects;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
public class VillagerTypeManager {
@ -10,8 +11,8 @@ public class VillagerTypeManager {
return villagerTypes;
}
public static VillagerType getVillagerType(String name) {
return villagerTypes.stream().filter(villagerType -> villagerType.getName().equals(name)).findFirst().orElse(null);
public static Optional<VillagerType> getVillagerType(String name) {
return villagerTypes.stream().filter(villagerType -> villagerType.getName().equals(name)).findFirst();
}
public static void addVillagerType(VillagerType villagerType) {