Update build configurations and add villager messaging functionality
This commit updates the version of the shadow plugin and the Java language version in the build configuration. Modifications have been made in the shadowJar configuration. The main feature in this commit is the introduction of a messaging system for villagers. This includes the necessary methods and fields in the existing villager classes and the addition of a new VillagerMessagesConfig class. Messages can now be added via config and each villager type can potentially return a random message when interacted with. A sound effect has also been added to correlate with the villager type. The WorthConfig class has been additionally refined to handle invalid material cases.
This commit is contained in:
parent
cbae508f04
commit
9f18b41925
|
|
@ -2,7 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocatio
|
|||
|
||||
plugins {
|
||||
id("java")
|
||||
id("com.github.johnrengelman.shadow") version "7.1.0"
|
||||
id("com.github.johnrengelman.shadow") version "7.1.1"
|
||||
id("maven-publish")
|
||||
}
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ apply<JavaLibraryPlugin>()
|
|||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
languageVersion.set(JavaLanguageVersion.of(21))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -44,24 +44,22 @@ tasks {
|
|||
}
|
||||
|
||||
shadowJar {
|
||||
dependsOn(getByName("relocateJars") as ConfigureShadowRelocation)
|
||||
archiveFileName.set("${project.name}-${project.version}.jar")
|
||||
minimize()
|
||||
configurations = listOf(project.configurations.shadow.get())
|
||||
archiveFileName.set("${rootProject.name}.jar")
|
||||
manifest {
|
||||
attributes("Main-Class" to "VillagerUI")
|
||||
}
|
||||
}
|
||||
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
|
||||
create<ConfigureShadowRelocation>("relocateJars") {
|
||||
target = shadowJar.get()
|
||||
prefix = "${project.name}.lib"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.alttd:Galaxy-API:1.19-R0.1-SNAPSHOT")
|
||||
compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT") {
|
||||
isChanging = true
|
||||
}
|
||||
compileOnly("com.github.milkbowl:VaultAPI:1.7") {
|
||||
exclude("org.bukkit","bukkit")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,6 +203,7 @@ public final class Config extends AbstractConfig {
|
|||
);
|
||||
}
|
||||
});
|
||||
VillagerMessagesConfig.reload();
|
||||
}
|
||||
|
||||
private static TreeSet<ItemStack> loadProducts(ConfigurationSection productsSection) {
|
||||
|
|
|
|||
52
src/main/java/com/alttd/config/VillagerMessagesConfig.java
Normal file
52
src/main/java/com/alttd/config/VillagerMessagesConfig.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package com.alttd.config;
|
||||
|
||||
import com.alttd.objects.VillagerType;
|
||||
import com.alttd.objects.VillagerTypeManager;
|
||||
import com.alttd.util.Logger;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class VillagerMessagesConfig extends AbstractConfig {
|
||||
static VillagerMessagesConfig config;
|
||||
static int version;
|
||||
|
||||
protected VillagerMessagesConfig() {
|
||||
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "VillagerShopUI"), "villager-messages.yml");
|
||||
}
|
||||
|
||||
protected static void reload() {
|
||||
config = new VillagerMessagesConfig();
|
||||
|
||||
version = config.getInt("config-version", 1);
|
||||
config.set("config-version", 1);
|
||||
|
||||
config.readConfig(VillagerMessagesConfig.class, null);
|
||||
}
|
||||
|
||||
private static void loadVillagerMessages() {
|
||||
Logger.info("Reloading VillagerMessages config...");
|
||||
ConfigurationSection configurationSection = config.getConfigurationSection("messages");
|
||||
if (configurationSection == null) {
|
||||
Logger.warning("No villager messages found in config.");
|
||||
config.getStringList("messages.example-tag", List.of("This is an example"));
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> keys = configurationSection.getKeys(false);
|
||||
if (keys.isEmpty()) {
|
||||
Logger.warning("No villager types found in config.");
|
||||
}
|
||||
|
||||
keys.forEach(key -> {
|
||||
VillagerType villagerType = VillagerTypeManager.getVillagerType(key);
|
||||
if (villagerType == null) {
|
||||
Logger.info("Unknown villager type: " + key);
|
||||
return;
|
||||
}
|
||||
villagerType.setMessages(configurationSection.getStringList(key));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -87,6 +87,10 @@ public class WorthConfig extends AbstractConfig {
|
|||
Logger.warning("Invalid material % in trade worth", key);
|
||||
continue;
|
||||
}
|
||||
if (material == null) {
|
||||
Logger.warning("Invalid material % in trade worth", key);
|
||||
continue;
|
||||
}
|
||||
map.put(material, new Price(Utilities.round(worth.getDouble(key), 2), material));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +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.objects.*;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
|
|
@ -65,6 +67,27 @@ public class VillagerEvents implements Listener {
|
|||
}.runTaskAsynchronously(VillagerUI.getInstance());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractOnEntity(PlayerInteractOnEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!(event.getEntity() instanceof Villager villager)) {
|
||||
return;
|
||||
}
|
||||
|
||||
VillagerType loadedVillager = LoadedVillagers.getLoadedVillager(villager.getUniqueId());
|
||||
if (loadedVillager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
loadedVillager.getRandomMessage().ifPresent(player::sendMessage);
|
||||
if (loadedVillager instanceof BlackMarketVillagerType) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_HURT, 1.0F, 1.0F);
|
||||
} else if (loadedVillager instanceof ShopVillagerType) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_YES, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVillagerDeath(EntityDeathEvent event) {
|
||||
if (!event.getEntityType().equals(EntityType.VILLAGER))
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.alttd.objects;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
|
@ -15,6 +17,9 @@ public class BlackMarketVillagerType implements VillagerType {
|
|||
private final int maxTradesPerReboot;
|
||||
private final HashMap<UUID, Set<ItemStack>> playerTrades = new HashMap<>();
|
||||
private final HashMap<UUID, Integer> playerTradeCount = new HashMap<>();
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
public BlackMarketVillagerType(String name, String displayName, String profession, int maxAvailableItems, int maxTradesPerReboot, Set<ItemStack> trading) {
|
||||
this.name = name;
|
||||
|
|
@ -85,4 +90,25 @@ public class BlackMarketVillagerType implements VillagerType {
|
|||
public String getPermission() {
|
||||
return "villagerui.villager." + getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Component> getRandomMessage() {
|
||||
if (messages.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
int index = random.nextInt(messages.size());
|
||||
String message = messages.get(index);
|
||||
return Optional.of(MiniMessage.miniMessage().deserialize(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMessage(String message) {
|
||||
messages.add(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMessages(List<String> messages) {
|
||||
this.messages.clear();
|
||||
this.messages.addAll(messages);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
package com.alttd.objects;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
|
||||
public class ShopVillagerType implements VillagerType{
|
||||
private final String name;
|
||||
|
|
@ -12,6 +13,9 @@ public class ShopVillagerType implements VillagerType{
|
|||
private final Set<ItemStack> buying;
|
||||
private final Set<ItemStack> selling;
|
||||
private final Villager.Profession profession;
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
public ShopVillagerType(String name, String displayName, TreeSet<ItemStack> buying, TreeSet<ItemStack> selling, String profession) {
|
||||
this.name = name;
|
||||
|
|
@ -44,4 +48,22 @@ public class ShopVillagerType implements VillagerType{
|
|||
public String getPermission() {
|
||||
return "villagerui.villager." + getName();
|
||||
}
|
||||
|
||||
public Optional<Component> getRandomMessage() {
|
||||
if (messages.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
int index = random.nextInt(messages.size());
|
||||
String message = messages.get(index);
|
||||
return Optional.of(MiniMessage.miniMessage().deserialize(message));
|
||||
}
|
||||
|
||||
public void addMessage(String message) {
|
||||
messages.add(message);
|
||||
}
|
||||
|
||||
public void setMessages(List<String> messages) {
|
||||
this.messages.clear();
|
||||
this.messages.addAll(messages);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
package com.alttd.objects;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public interface VillagerType {
|
||||
|
|
@ -18,4 +21,10 @@ public interface VillagerType {
|
|||
Villager.Profession getProfession();
|
||||
|
||||
String getPermission();
|
||||
|
||||
Optional<Component> getRandomMessage();
|
||||
|
||||
void addMessage(String message);
|
||||
|
||||
void setMessages(List<String> messages);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user