Compare commits

..

No commits in common. "3fc8561265e6442b2db9f360fe607824cd8402b1" and "5d2dfd9e19f1fa9909a0eb08144faf72eef4f911" have entirely different histories.

14 changed files with 132 additions and 382 deletions

26
Jenkinsfile vendored
View File

@ -1,26 +0,0 @@
pipeline {
agent any
stages {
stage('Gradle') {
steps {
sh 'bash gradlew build'
}
}
stage('Archive') {
steps {
archiveArtifacts artifacts: 'build/libs/', followSymlinks: false
}
}
stage('discord') {
when {
anyOf {
branch 'main'
branch 'master'
}
}
steps {
discordSend description: "Build: ${BUILD_NUMBER}", showChangeset: true, result: currentBuild.currentResult, title: currentBuild.fullProjectName, webhookURL: env.discordwebhook
}
}
}
}

View File

@ -2,7 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocatio
plugins {
id("java")
id("com.github.johnrengelman.shadow") version "7.1.1"
id("com.github.johnrengelman.shadow") version "7.1.0"
id("maven-publish")
}
@ -14,7 +14,7 @@ apply<JavaLibraryPlugin>()
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
languageVersion.set(JavaLanguageVersion.of(17))
}
}
@ -44,22 +44,24 @@ tasks {
}
shadowJar {
archiveFileName.set("${rootProject.name}.jar")
manifest {
attributes("Main-Class" to "VillagerUI")
}
dependsOn(getByName("relocateJars") as ConfigureShadowRelocation)
archiveFileName.set("${project.name}-${project.version}.jar")
minimize()
configurations = listOf(project.configurations.shadow.get())
}
build {
dependsOn(shadowJar)
}
create<ConfigureShadowRelocation>("relocateJars") {
target = shadowJar.get()
prefix = "${project.name}.lib"
}
}
dependencies {
compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT") {
isChanging = true
}
compileOnly("com.alttd:Galaxy-API:1.19-R0.1-SNAPSHOT")
compileOnly("com.github.milkbowl:VaultAPI:1.7") {
exclude("org.bukkit","bukkit")
}

Binary file not shown.

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

257
gradlew vendored
View File

@ -1,7 +1,7 @@
#!/bin/sh
#!/usr/bin/env sh
#
# Copyright © 2015-2021 the original authors.
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -17,101 +17,67 @@
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
MAX_FD="maximum"
warn () {
echo "$*"
} >&2
}
die () {
echo
echo "$*"
echo
exit 1
} >&2
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
@ -121,9 +87,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD=$JAVA_HOME/bin/java
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@ -132,7 +98,7 @@ Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
@ -140,95 +106,80 @@ location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=$( cygpath --unix "$JAVACMD" )
JAVACMD=`cygpath --unix "$JAVACMD"`
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

View File

@ -15,15 +15,10 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Axolotl;
import org.bukkit.entity.Player;
import org.bukkit.entity.TropicalFish;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.AxolotlBucketMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.TropicalFishBucketMeta;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
@ -83,7 +78,7 @@ public class TradeGUI extends GUIMerchant {
Placeholder.unparsed("item_name", material.name())
)));
List<Component> lore = new ArrayList<>();
for (String entry : Config.TRANSACTION_ITEM_DESCRIPTION_NO_POINTS) {
for (String entry : Config.TRANSACTION_ITEM_DESCRIPTION) {
lore.add(miniMessage.deserialize(entry, TagResolver.resolver(
Placeholder.unparsed("amount", String.valueOf(amount)),
Placeholder.unparsed("price", String.format("%,.2f", price))
@ -138,9 +133,7 @@ public class TradeGUI extends GUIMerchant {
}
econ.withdrawPlayer(player, price);
villagerType.makeTrade(uuid);
ItemStack itemStack = new ItemStack(material, amount);
randomizeMetaIfNeeded(material, itemStack);
player.getInventory().addItem(itemStack);
player.getInventory().addItem(new ItemStack(material, amount));
player.sendMiniMessage(Config.TRADED_ITEM, TagResolver.resolver(
Placeholder.parsed("amount", String.valueOf(amount)),
@ -156,25 +149,6 @@ public class TradeGUI extends GUIMerchant {
trade(villagerType, player, material, amount, price);
}
private void randomizeMetaIfNeeded(Material material, ItemStack itemStack) {
if (material.equals(Material.AXOLOTL_BUCKET)) {
AxolotlBucketMeta axolotlBucketMeta = (AxolotlBucketMeta) itemStack.getItemMeta();
int value = new Random().nextInt(0, Axolotl.Variant.values().length - 1);
axolotlBucketMeta.setVariant(Axolotl.Variant.values()[value]);
itemStack.setItemMeta(axolotlBucketMeta);
} else if (material.equals(Material.TROPICAL_FISH_BUCKET)) {
TropicalFishBucketMeta tropicalFishBucketMeta = (TropicalFishBucketMeta) itemStack.getItemMeta();
Random random = new Random();
int bodyColor = random.nextInt(0, DyeColor.values().length - 1);
int pattern = random.nextInt(0, TropicalFish.Pattern.values().length - 1);
int patternColor = random.nextInt(0, DyeColor.values().length - 1);
tropicalFishBucketMeta.setBodyColor(DyeColor.values()[bodyColor]);
tropicalFishBucketMeta.setPattern(TropicalFish.Pattern.values()[pattern]);
tropicalFishBucketMeta.setPatternColor(DyeColor.values()[patternColor]);
itemStack.setItemMeta(tropicalFishBucketMeta);
}
}
private ItemStack getPriceItem(double price) {
if (price < 0) return nameItem(new ItemStack(Material.BARRIER), -1);
else if (price <= 10) return nameItem(new ItemStack(Material.IRON_INGOT), price);

View File

@ -48,7 +48,7 @@ public class CommandCreateVillager extends SubCommand {
commandSender.sendMiniMessage(getHelpMessage(), null);
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]));
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);
@ -81,9 +81,7 @@ public class CommandCreateVillager extends SubCommand {
case 2 -> res.addAll(VillagerTypeManager.getVillagerTypes().stream()
.map(VillagerType::getName)
.collect(Collectors.toList()));
case 3 -> res.addAll(Arrays.stream(Villager.Type.values())
.map(something -> something.name())
.collect(Collectors.toList()));
case 3 -> res.addAll(Arrays.stream(Villager.Type.values()).map(Enum::name).collect(Collectors.toList()));
case 4 -> {
if (commandSender instanceof Player player) {
res.add(String.valueOf(Utilities.round(player.getLocation().getX(), 2)));

View File

@ -18,7 +18,7 @@ public final class Config extends AbstractConfig {
static Config config;
static int version;
public Config() {
super(new File(File.separator + "mnt" + File.separator + "configs" + File.separator + "VillagerShopUI"), "config.yml");
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "VillagerShopUI"), "config.yml");
}
public static void reload() {
@ -105,15 +105,11 @@ public final class Config extends AbstractConfig {
"<gold>Price: <dark_aqua><price></dark_aqua></gold>",
"<gold>Points: <dark_aqua><points></dark_aqua></gold>");
public static List<String> TRANSACTION_ITEM_DESCRIPTION_NO_POINTS = List.of(
"<gold>Amount: <dark_aqua><amount></dark_aqua></gold>",
"<gold>Price: <dark_aqua><price></dark_aqua></gold>");
private static void guiText() {
VILLAGER_NAME = config.getString("gui-text.villager-name", VILLAGER_NAME);
CONFIRM_BUTTON = config.getString("gui-text.confirm-button", CONFIRM_BUTTON);
TRANSACTION_ITEM_NAME = config.getString("gui-text.transaction-item-name", TRANSACTION_ITEM_NAME);
TRANSACTION_ITEM_DESCRIPTION = config.getStringList("gui-text.transaction-item-description", TRANSACTION_ITEM_DESCRIPTION);
TRANSACTION_ITEM_DESCRIPTION_NO_POINTS = config.getStringList("gui-text.transaction-item-description-no-points", TRANSACTION_ITEM_DESCRIPTION_NO_POINTS);
}
public static String NOT_ENOUGH_MONEY = "<red>You only have $<money>, you need at least $<price> for this purchase.</red>";
@ -203,7 +199,6 @@ public final class Config extends AbstractConfig {
);
}
});
VillagerMessagesConfig.reload();
}
private static TreeSet<ItemStack> loadProducts(ConfigurationSection productsSection) {

View File

@ -1,52 +0,0 @@
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(File.separator + "mnt" + 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));
});
}
}

View File

@ -17,7 +17,7 @@ public class WorthConfig extends AbstractConfig {
static int version;
public WorthConfig() {
super(new File(File.separator + "mnt" + File.separator + "configs" + File.separator + "VillagerShopUI"), "worth.yml");
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "VillagerShopUI"), "worth.yml");
}
public static void reload() {
@ -54,8 +54,9 @@ public class WorthConfig extends AbstractConfig {
}
Material material;
material = Material.getMaterial(key);
if (material == null) {
try {
material = Material.getMaterial(key);
} catch (Exception e) {
Logger.warning("Invalid material % in trade worth", key);
continue;
}
@ -80,8 +81,9 @@ public class WorthConfig extends AbstractConfig {
}
Material material;
material = Material.getMaterial(key);
if (material == null) {
try {
material = Material.getMaterial(key);
} catch (Exception e) {
Logger.warning("Invalid material % in trade worth", key);
continue;
}

View File

@ -5,9 +5,7 @@ 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;
@ -67,27 +65,6 @@ 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))

View File

@ -1,9 +1,5 @@
package com.alttd.objects;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.entity.Villager;
import org.bukkit.inventory.ItemStack;
@ -19,22 +15,14 @@ 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;
this.displayName = displayName;
this.profession = Villager.Profession.valueOf(profession.toUpperCase());
this.maxAvailableItems = maxAvailableItems;
this.maxTradesPerReboot = maxTradesPerReboot;
this.trading = trading;
this.profession = getProfession(profession.toLowerCase());
}
Villager.Profession getProfession(String professionName) {
NamespacedKey namespacedKey = NamespacedKey.minecraft(professionName);
return Registry.VILLAGER_PROFESSION.get(namespacedKey);
}
private Set<ItemStack> getResizedCustomTradingSet() {
@ -97,25 +85,4 @@ 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);
}
}

View File

@ -1,13 +1,10 @@
package com.alttd.objects;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.entity.Villager;
import org.bukkit.inventory.ItemStack;
import java.util.*;
import java.util.Set;
import java.util.TreeSet;
public class ShopVillagerType implements VillagerType{
private final String name;
@ -15,21 +12,13 @@ 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;
this.displayName = displayName;
this.buying = buying;
this.selling = selling;
this.profession = getProfession(profession.toLowerCase());
}
Villager.Profession getProfession(String professionName) {
NamespacedKey namespacedKey = NamespacedKey.minecraft(professionName);
return Registry.VILLAGER_PROFESSION.get(namespacedKey);
this.profession = Villager.Profession.valueOf(profession.toUpperCase());
}
public String getName() {
@ -55,22 +44,4 @@ 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);
}
}

View File

@ -1,11 +1,8 @@
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 {
@ -21,10 +18,4 @@ public interface VillagerType {
Villager.Profession getProfession();
String getPermission();
Optional<Component> getRandomMessage();
void addMessage(String message);
void setMessages(List<String> messages);
}