Compare commits
19
Commits
3fc8561265
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ea50a3d89 | ||
|
|
cee1709d00 | ||
|
|
6c5fb6862c | ||
|
|
10a534b81f | ||
|
|
1d7ea13ddb | ||
|
|
d24d157684 | ||
|
|
d484e4b7be | ||
|
|
e1ccfd05de | ||
|
|
1909c6d5bc | ||
|
|
36c92fcdb3 | ||
|
|
19374ad837 | ||
|
|
2d0b727789 | ||
|
|
1719130f69 | ||
|
|
b0e04548bd | ||
|
|
63bdbdaab1 | ||
|
|
4e1c813a42 | ||
|
|
61f9b09346 | ||
|
|
a7e5a99e01 | ||
|
|
97c711ea29 |
Vendored
+18
-2
@@ -3,7 +3,23 @@ pipeline {
|
|||||||
stages {
|
stages {
|
||||||
stage('Gradle') {
|
stage('Gradle') {
|
||||||
steps {
|
steps {
|
||||||
sh 'bash gradlew build'
|
withCredentials([usernamePassword(credentialsId: 'alttd-snapshot-user', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
|
||||||
|
sh '''
|
||||||
|
set +x
|
||||||
|
chmod +x gradlew
|
||||||
|
./gradlew build -PalttdSnapshotUsername=$USERNAME -PalttdSnapshotPassword=$PASSWORD
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Publish to Maven') {
|
||||||
|
steps {
|
||||||
|
withCredentials([usernamePassword(credentialsId: 'alttd-snapshot-user', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
|
||||||
|
sh '''
|
||||||
|
chmod +x gradlew
|
||||||
|
./gradlew publish -PalttdSnapshotUsername=$USERNAME -PalttdSnapshotPassword=$PASSWORD
|
||||||
|
'''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Archive') {
|
stage('Archive') {
|
||||||
@@ -23,4 +39,4 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-17
@@ -1,23 +1,15 @@
|
|||||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("com.github.johnrengelman.shadow") version "7.1.1"
|
id("com.gradleup.shadow") version "9.6.1"
|
||||||
id("maven-publish")
|
id("maven-publish")
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "com.alttd"
|
group = "com.alttd"
|
||||||
version = "1.0.0-SNAPSHOT"
|
version = System.getenv("BUILD_NUMBER") ?: "1.1-SNAPSHOT"
|
||||||
description = "Altitude Villager Shop plugin."
|
description = "Altitude Villager Shop plugin."
|
||||||
|
|
||||||
apply<JavaLibraryPlugin>()
|
apply<JavaLibraryPlugin>()
|
||||||
|
|
||||||
java {
|
|
||||||
toolchain {
|
|
||||||
languageVersion.set(JavaLanguageVersion.of(21))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
create<MavenPublication>("mavenJava") {
|
create<MavenPublication>("mavenJava") {
|
||||||
@@ -27,9 +19,12 @@ publishing {
|
|||||||
|
|
||||||
repositories{
|
repositories{
|
||||||
maven {
|
maven {
|
||||||
name = "alttd"
|
name = "nexus"
|
||||||
url = uri("https://repo.destro.xyz/snapshots")
|
url = uri("https://repo.alttd.com/repository/alttd/")
|
||||||
credentials(PasswordCredentials::class)
|
credentials {
|
||||||
|
username = project.property("alttdSnapshotUsername") as String
|
||||||
|
password = project.property("alttdSnapshotPassword") as String
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,11 +52,9 @@ tasks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT") {
|
compileOnly("com.alttd.cosmos:cosmos-api:26.2.build.17-stable")
|
||||||
isChanging = true
|
|
||||||
}
|
|
||||||
compileOnly("com.github.milkbowl:VaultAPI:1.7") {
|
compileOnly("com.github.milkbowl:VaultAPI:1.7") {
|
||||||
exclude("org.bukkit","bukkit")
|
exclude("org.bukkit","bukkit")
|
||||||
}
|
}
|
||||||
compileOnly("com.alttd.datalock:api:1.1.0-SNAPSHOT")
|
compileOnly("com.alttd.datalock:api:1.1.0-SNAPSHOT")
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
+3
-1
@@ -1,5 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright © 2015-2021 the original authors.
|
# Copyright © 2015 the original authors.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@@ -15,6 +15,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
@@ -55,7 +57,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (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
|
# https://github.com/gradle/gradle/blob/b631911858264c0b6e4d6603d677ff5218766cee/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
# within the Gradle project.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@@ -80,13 +82,11 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
APP_NAME="Gradle"
|
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@@ -114,7 +114,6 @@ case "$( uname )" in #(
|
|||||||
NONSTOP* ) nonstop=true ;;
|
NONSTOP* ) nonstop=true ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
@@ -133,22 +132,29 @@ location of your Java installation."
|
|||||||
fi
|
fi
|
||||||
else
|
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.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
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
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
@@ -165,7 +171,6 @@ fi
|
|||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
if "$cygwin" || "$msys" ; then
|
if "$cygwin" || "$msys" ; then
|
||||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
|
||||||
|
|
||||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
@@ -193,18 +198,27 @@ if "$cygwin" || "$msys" ; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
# double quotes to make sure that they get re-expanded; and
|
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
-classpath "$CLASSPATH" \
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
# Use "xargs" to parse quoted args.
|
# Use "xargs" to parse quoted args.
|
||||||
#
|
#
|
||||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
|||||||
Vendored
+22
-18
@@ -13,8 +13,10 @@
|
|||||||
@rem See the License for the specific language governing permissions and
|
@rem See the License for the specific language governing permissions and
|
||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%" == "" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@rem Gradle startup script for Windows
|
@rem Gradle startup script for Windows
|
||||||
@@ -25,7 +27,8 @@
|
|||||||
if "%OS%"=="Windows_NT" setlocal
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
@@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
|||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
@@ -56,32 +59,33 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
exit /b 1
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|||||||
+18
-1
@@ -1,10 +1,27 @@
|
|||||||
rootProject.name = "VillagerShopUI"
|
rootProject.name = "VillagerShopUI"
|
||||||
|
|
||||||
|
val nexusUser = providers.gradleProperty("alttdSnapshotUsername").orNull ?: System.getenv("NEXUS_USERNAME")
|
||||||
|
val nexusPass = providers.gradleProperty("alttdSnapshotPassword").orNull ?: System.getenv("NEXUS_PASSWORD")
|
||||||
|
|
||||||
dependencyResolutionManagement {
|
dependencyResolutionManagement {
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
|
maven {
|
||||||
|
url = uri("https://repo.alttd.com/repository/alttd-snapshot/")
|
||||||
|
credentials {
|
||||||
|
username = nexusUser
|
||||||
|
password = nexusPass
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
url = uri("https://repo.alttd.com/repository/alttd/")
|
||||||
|
credentials {
|
||||||
|
username = nexusUser
|
||||||
|
password = nexusPass
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maven("https://repo.destro.xyz/snapshots") // Cosmos
|
||||||
maven("https://jitpack.io") { // Vault
|
maven("https://jitpack.io") { // Vault
|
||||||
content { includeGroup("com.github.milkbowl") }
|
content { includeGroup("com.github.milkbowl") }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class BuyGUI extends GUIMerchant {
|
|||||||
int transPts = itemPts * amount;
|
int transPts = itemPts * amount;
|
||||||
EconUser econUser = EconUser.getUser(player.getUniqueId());
|
EconUser econUser = EconUser.getUser(player.getUniqueId());
|
||||||
if (econUser == null) {
|
if (econUser == null) {
|
||||||
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
|
player.sendRichMessage(Config.LOADING_ECON_DATA);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int oldPoints = econUser.getPointsMap().getOrDefault(villagerType.getName(), 0);
|
int oldPoints = econUser.getPointsMap().getOrDefault(villagerType.getName(), 0);
|
||||||
@@ -87,14 +87,14 @@ public class BuyGUI extends GUIMerchant {
|
|||||||
if ((newTime - 120) > lastClicked)
|
if ((newTime - 120) > lastClicked)
|
||||||
lastClicked = newTime;
|
lastClicked = newTime;
|
||||||
else {
|
else {
|
||||||
player.sendMiniMessage(Config.CLICKING_TOO_FAST, null);
|
player.sendRichMessage(Config.CLICKING_TOO_FAST);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Economy econ = VillagerUI.getInstance().getEconomy();
|
Economy econ = VillagerUI.getInstance().getEconomy();
|
||||||
double balance = econ.getBalance(player);
|
double balance = econ.getBalance(player);
|
||||||
|
|
||||||
if (balance < purchase.price()) {
|
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("money", String.valueOf(Utilities.round(balance, 2))),
|
||||||
Placeholder.unparsed("price", String.format("%,.2f", purchase.price()))
|
Placeholder.unparsed("price", String.format("%,.2f", purchase.price()))
|
||||||
));
|
));
|
||||||
@@ -113,7 +113,7 @@ public class BuyGUI extends GUIMerchant {
|
|||||||
ref.space += itemStack.getMaxStackSize() - itemStack.getAmount();
|
ref.space += itemStack.getMaxStackSize() - itemStack.getAmount();
|
||||||
});
|
});
|
||||||
if (ref.space < purchase.amount()) {
|
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("space", String.valueOf(ref.space)),
|
||||||
Placeholder.unparsed("amount", String.valueOf(purchase.amount()))
|
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()));
|
player.getInventory().addItem(new ItemStack(purchase.material(), purchase.amount()));
|
||||||
|
|
||||||
int newPoints = econUser.getPointsMap().get(villagerType.getName());
|
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("amount", String.valueOf(purchase.amount())),
|
||||||
Placeholder.unparsed("item", Utilities.capitalize(purchase.material().name()
|
Placeholder.unparsed("item", Utilities.capitalize(purchase.material().name()
|
||||||
.toLowerCase().replaceAll("_", " "))),
|
.toLowerCase().replaceAll("_", " "))),
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ public class SellGUI extends GUIMerchant {
|
|||||||
private void sell(VillagerType villagerType, Player player, Material material, int amount, Price price, boolean bulk) {
|
private void sell(VillagerType villagerType, Player player, Material material, int amount, Price price, boolean bulk) {
|
||||||
EconUser econUser = EconUser.getUser(player.getUniqueId());
|
EconUser econUser = EconUser.getUser(player.getUniqueId());
|
||||||
if (econUser == null) {
|
if (econUser == null) {
|
||||||
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
|
player.sendRichMessage(Config.LOADING_ECON_DATA);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,12 +120,12 @@ public class SellGUI extends GUIMerchant {
|
|||||||
if ((newTime - 120) > lastClicked)
|
if ((newTime - 120) > lastClicked)
|
||||||
lastClicked = newTime;
|
lastClicked = newTime;
|
||||||
else {
|
else {
|
||||||
player.sendMiniMessage(Config.CLICKING_TOO_FAST, null);
|
player.sendRichMessage(Config.CLICKING_TOO_FAST);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlayerInventory inventory = player.getInventory();
|
PlayerInventory inventory = player.getInventory();
|
||||||
if (countTotalBlocksInInventory(inventory, purchase.material()) < purchase.amount()) {
|
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("type", purchase.material().name()),
|
||||||
Placeholder.unparsed("amount", String.valueOf(purchase.amount()))));
|
Placeholder.unparsed("amount", String.valueOf(purchase.amount()))));
|
||||||
return;
|
return;
|
||||||
@@ -153,7 +153,7 @@ public class SellGUI extends GUIMerchant {
|
|||||||
|
|
||||||
|
|
||||||
int newPoints = econUser.getPointsMap().get(villagerType.getName());
|
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("amount", String.valueOf(purchase.amount())),
|
||||||
Placeholder.unparsed("item", Utilities.capitalize(purchase.material().name()
|
Placeholder.unparsed("item", Utilities.capitalize(purchase.material().name()
|
||||||
.toLowerCase().replaceAll("_", " "))),
|
.toLowerCase().replaceAll("_", " "))),
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class TradeGUI extends GUIMerchant {
|
|||||||
private void trade(BlackMarketVillagerType villagerType, Player player, Material material, int amount, Double price) {
|
private void trade(BlackMarketVillagerType villagerType, Player player, Material material, int amount, Double price) {
|
||||||
EconUser econUser = EconUser.getUser(player.getUniqueId());
|
EconUser econUser = EconUser.getUser(player.getUniqueId());
|
||||||
if (econUser == null) {
|
if (econUser == null) {
|
||||||
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
|
player.sendRichMessage(Config.LOADING_ECON_DATA);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,13 +99,13 @@ public class TradeGUI extends GUIMerchant {
|
|||||||
if ((newTime - 120) > lastClicked)
|
if ((newTime - 120) > lastClicked)
|
||||||
lastClicked = newTime;
|
lastClicked = newTime;
|
||||||
else {
|
else {
|
||||||
player.sendMiniMessage(Config.CLICKING_TOO_FAST, null);
|
player.sendRichMessage(Config.CLICKING_TOO_FAST);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
if (villagerType.getRemainingTrades(uuid) <= 0) {
|
if (villagerType.getRemainingTrades(uuid) <= 0) {
|
||||||
player.sendMiniMessage(Config.NO_TRADES_REMAINING, null);
|
player.sendRichMessage(Config.NO_TRADES_REMAINING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ public class TradeGUI extends GUIMerchant {
|
|||||||
double balance = econ.getBalance(player);
|
double balance = econ.getBalance(player);
|
||||||
|
|
||||||
if (balance < price) {
|
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("money", String.valueOf(Utilities.round(balance, 2))),
|
||||||
Placeholder.unparsed("price", String.format("%,.2f", price))
|
Placeholder.unparsed("price", String.format("%,.2f", price))
|
||||||
));
|
));
|
||||||
@@ -130,7 +130,7 @@ public class TradeGUI extends GUIMerchant {
|
|||||||
atomicInteger.addAndGet(itemStack.getMaxStackSize() - itemStack.getAmount());
|
atomicInteger.addAndGet(itemStack.getMaxStackSize() - itemStack.getAmount());
|
||||||
});
|
});
|
||||||
if (atomicInteger.get() < amount) {
|
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("space", String.valueOf(atomicInteger.get())),
|
||||||
Placeholder.unparsed("amount", String.valueOf(amount))
|
Placeholder.unparsed("amount", String.valueOf(amount))
|
||||||
));
|
));
|
||||||
@@ -142,7 +142,7 @@ public class TradeGUI extends GUIMerchant {
|
|||||||
randomizeMetaIfNeeded(material, itemStack);
|
randomizeMetaIfNeeded(material, itemStack);
|
||||||
player.getInventory().addItem(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("amount", String.valueOf(amount)),
|
||||||
Placeholder.parsed("item", Utilities.capitalize(material.name()
|
Placeholder.parsed("item", Utilities.capitalize(material.name()
|
||||||
.toLowerCase().replaceAll("_", " "))),
|
.toLowerCase().replaceAll("_", " "))),
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.alttd.datalock.DataLockAPI;
|
|||||||
import com.alttd.events.*;
|
import com.alttd.events.*;
|
||||||
import com.alttd.logging.LogInOut;
|
import com.alttd.logging.LogInOut;
|
||||||
import com.alttd.objects.EconUser;
|
import com.alttd.objects.EconUser;
|
||||||
|
import com.alttd.util.auto_sell.AutoSellTask;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
import com.alttd.util.SaveTask;
|
import com.alttd.util.SaveTask;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
@@ -36,15 +37,16 @@ public class VillagerUI extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
logInOut = new LogInOut();
|
logInOut = new LogInOut();
|
||||||
registerEvents();
|
AutoSellTask autoSellTask = new AutoSellTask();
|
||||||
new CommandManager();
|
registerEvents(autoSellTask);
|
||||||
|
new CommandManager(autoSellTask);
|
||||||
Config.reload();
|
Config.reload();
|
||||||
VillagerConfig.reload();
|
VillagerConfig.reload();
|
||||||
WorthConfig.reload();
|
WorthConfig.reload();
|
||||||
if (!setupEconomy())
|
if (!setupEconomy())
|
||||||
return;
|
return;
|
||||||
Database.getDatabase().init();
|
Database.getDatabase().init();
|
||||||
scheduleTasks();
|
scheduleTasks(autoSellTask);
|
||||||
DataLockAPI dataLockAPI = DataLockAPI.get();
|
DataLockAPI dataLockAPI = DataLockAPI.get();
|
||||||
if (dataLockAPI == null) {
|
if (dataLockAPI == null) {
|
||||||
Logger.severe("Unable to load datalockapi");
|
Logger.severe("Unable to load datalockapi");
|
||||||
@@ -68,7 +70,7 @@ public class VillagerUI extends JavaPlugin {
|
|||||||
logInOut.run();
|
logInOut.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scheduleTasks() {
|
private void scheduleTasks(AutoSellTask autoSellTask) {
|
||||||
new SaveTask().runTaskTimerAsynchronously(
|
new SaveTask().runTaskTimerAsynchronously(
|
||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
@@ -77,9 +79,14 @@ public class VillagerUI extends JavaPlugin {
|
|||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
20);
|
20);
|
||||||
|
autoSellTask.runTaskTimerAsynchronously(
|
||||||
|
this,
|
||||||
|
10 * 20,
|
||||||
|
10 * 20
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerEvents() {
|
private void registerEvents(AutoSellTask autoSellTask) {
|
||||||
getServer().getPluginManager().registerEvents(new GUIListener(), this);
|
getServer().getPluginManager().registerEvents(new GUIListener(), this);
|
||||||
getServer().getPluginManager().registerEvents(new VillagerEvents(), this);
|
getServer().getPluginManager().registerEvents(new VillagerEvents(), this);
|
||||||
getServer().getPluginManager().registerEvents(new LogoutEvent(), this);
|
getServer().getPluginManager().registerEvents(new LogoutEvent(), this);
|
||||||
@@ -87,6 +94,7 @@ public class VillagerUI extends JavaPlugin {
|
|||||||
getServer().getPluginManager().registerEvents(new VehicleEvent(), this);
|
getServer().getPluginManager().registerEvents(new VehicleEvent(), this);
|
||||||
getServer().getPluginManager().registerEvents(new SpawnShopListener(logInOut), this);
|
getServer().getPluginManager().registerEvents(new SpawnShopListener(logInOut), this);
|
||||||
getServer().getPluginManager().registerEvents(new DataLock(), this);
|
getServer().getPluginManager().registerEvents(new DataLock(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new ItemPickupEvent(autoSellTask), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Economy getEconomy() {
|
public Economy getEconomy() {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.alttd.commands;
|
|||||||
import com.alttd.VillagerUI;
|
import com.alttd.VillagerUI;
|
||||||
import com.alttd.commands.subcommands.*;
|
import com.alttd.commands.subcommands.*;
|
||||||
import com.alttd.config.Config;
|
import com.alttd.config.Config;
|
||||||
|
import com.alttd.util.auto_sell.AutoSellTask;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.command.*;
|
import org.bukkit.command.*;
|
||||||
@@ -18,7 +19,7 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
|||||||
private final List<SubCommand> subCommands;
|
private final List<SubCommand> subCommands;
|
||||||
private final MiniMessage miniMessage;
|
private final MiniMessage miniMessage;
|
||||||
|
|
||||||
public CommandManager() {
|
public CommandManager(AutoSellTask autoSellTask) {
|
||||||
VillagerUI villagerUI = VillagerUI.getInstance();
|
VillagerUI villagerUI = VillagerUI.getInstance();
|
||||||
|
|
||||||
PluginCommand command = villagerUI.getCommand("villagerui");
|
PluginCommand command = villagerUI.getCommand("villagerui");
|
||||||
@@ -36,8 +37,10 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
|||||||
new CommandPoints(),
|
new CommandPoints(),
|
||||||
new CommandBuy(),
|
new CommandBuy(),
|
||||||
new CommandSell(),
|
new CommandSell(),
|
||||||
|
new CommandAutoSell(autoSellTask),
|
||||||
new CommandCreateVillager(),
|
new CommandCreateVillager(),
|
||||||
new CommandReload(),
|
new CommandReload(),
|
||||||
|
new CommandReset(),
|
||||||
new CommandRemoveVillager());
|
new CommandRemoveVillager());
|
||||||
miniMessage = MiniMessage.miniMessage();
|
miniMessage = MiniMessage.miniMessage();
|
||||||
}
|
}
|
||||||
@@ -45,17 +48,17 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String cmd, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String cmd, @NotNull String[] args) {
|
||||||
if (args.length == 0) {
|
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()))
|
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||||
.map(SubCommand::getHelpMessage)
|
.map(SubCommand::getHelpMessage)
|
||||||
.collect(Collectors.joining("\n"))), null);
|
.collect(Collectors.joining("\n"))));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SubCommand subCommand = getSubCommand(args[0]);
|
SubCommand subCommand = getSubCommand(args[0]);
|
||||||
|
|
||||||
if (!commandSender.hasPermission(subCommand.getPermission())) {
|
if (!commandSender.hasPermission(subCommand.getPermission())) {
|
||||||
commandSender.sendMiniMessage(Config.NO_PERMISSION, null);
|
commandSender.sendRichMessage(Config.NO_PERMISSION);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,4 +96,4 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
|||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
package com.alttd.commands.subcommands;
|
||||||
|
|
||||||
|
import com.alttd.commands.SubCommand;
|
||||||
|
import com.alttd.config.Config;
|
||||||
|
import com.alttd.objects.VillagerTypeManager;
|
||||||
|
import com.alttd.util.auto_sell.AutoSellTask;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
|
import net.kyori.adventure.text.JoinConfiguration;
|
||||||
|
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;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class CommandAutoSell extends SubCommand {
|
||||||
|
|
||||||
|
private final AutoSellTask autoSellTask;
|
||||||
|
private final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
|
||||||
|
public CommandAutoSell(AutoSellTask autoSellTask) {
|
||||||
|
this.autoSellTask = autoSellTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
|
if (!(commandSender instanceof Player player)) {
|
||||||
|
commandSender.sendRichMessage(Config.NO_CONSOLE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args.length == 1) {
|
||||||
|
sendActiveList(player);
|
||||||
|
} else if (args.length == 2) {
|
||||||
|
if (args[1].equalsIgnoreCase("off")) {
|
||||||
|
turnOffAutoSell(player);
|
||||||
|
} else {
|
||||||
|
toggleMaterial(player, args[1]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.sendRichMessage(getHelpMessage());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendActiveList(Player player) {
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
if (!autoSellTask.hasAutoSellEntry(uuid)) {
|
||||||
|
player.sendRichMessage(Config.NO_AUTO_SELL_ITEMS);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Set<Material> materials = autoSellTask.getAutoSellList(uuid);
|
||||||
|
List<Component> materialComponents = materials.stream().map(Material::name)
|
||||||
|
.map(material -> miniMessage.deserialize(
|
||||||
|
Config.LIST_AUTO_SELL_COMPONENT,
|
||||||
|
Placeholder.parsed("material", material))).toList();
|
||||||
|
|
||||||
|
Component deserialize = miniMessage.deserialize(Config.LIST_AUTO_SELL_ITEMS);
|
||||||
|
Component joinedMaterialComponents = Component.join(JoinConfiguration.newlines(), materialComponents);
|
||||||
|
ComponentLike message = Component.join(JoinConfiguration.newlines(), deserialize, joinedMaterialComponents);
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void turnOffAutoSell(Player player) {
|
||||||
|
autoSellTask.clearAutoSell(player);
|
||||||
|
player.sendRichMessage(Config.DISABLED_AUTO_SELL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleMaterial(Player player, String stringMaterial) {
|
||||||
|
Material material = Material.getMaterial(stringMaterial.toUpperCase());
|
||||||
|
if (material == null) {
|
||||||
|
player.sendRichMessage(Config.INVALID_AUTO_SELL_ITEM, Placeholder.parsed("material", stringMaterial));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
|
boolean autoSellToggledOn = autoSellTask.toggleAutoSell(uuid, material);
|
||||||
|
|
||||||
|
TagResolver.Single materialPlaceholder = Placeholder.parsed("material", material.name());
|
||||||
|
|
||||||
|
if (autoSellToggledOn && autoSellTask.getEntries(uuid) > Config.MAX_AUTO_SELL) {
|
||||||
|
autoSellTask.removeAutoSell(uuid, material);
|
||||||
|
player.sendRichMessage(Config.MAX_AUTO_SELL_REACHED,
|
||||||
|
Placeholder.parsed("max_auto_sell", String.valueOf(Config.MAX_AUTO_SELL)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (autoSellToggledOn) {
|
||||||
|
player.sendRichMessage(Config.TURNED_ON_AUTO_SELL_FOR, materialPlaceholder);
|
||||||
|
} else {
|
||||||
|
player.sendRichMessage(Config.TURNED_OFF_AUTO_SELL_FOR, materialPlaceholder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "autosell";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||||
|
if (args.length != 2) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
ArrayList<String> tabComplete = new ArrayList<>();
|
||||||
|
tabComplete.add("off");
|
||||||
|
tabComplete.addAll(VillagerTypeManager
|
||||||
|
.getVillagerTypes()
|
||||||
|
.stream()
|
||||||
|
.flatMap(villagerType -> villagerType
|
||||||
|
.getSelling()
|
||||||
|
.stream()
|
||||||
|
.map(ItemStack::getType)
|
||||||
|
)
|
||||||
|
.map(material -> material.name().toLowerCase())
|
||||||
|
.toList());
|
||||||
|
tabComplete.removeIf(string -> !string.toLowerCase().startsWith(args[1].toLowerCase()));
|
||||||
|
return tabComplete;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpMessage() {
|
||||||
|
return Config.AUTO_SELL_MESSAGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,21 +26,21 @@ public class CommandBuy extends SubCommand {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
if (!(commandSender instanceof Player player)) {
|
if (!(commandSender instanceof Player player)) {
|
||||||
commandSender.sendMiniMessage(Config.NO_CONSOLE, null);
|
commandSender.sendRichMessage(Config.NO_CONSOLE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
//TODO open gui
|
//TODO open gui
|
||||||
player.sendMiniMessage(getHelpMessage(), null); //TODO remove later
|
player.sendRichMessage(getHelpMessage()); //TODO remove later
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
player.sendMiniMessage(getHelpMessage(), null);
|
player.sendRichMessage(getHelpMessage());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
EconUser user = EconUser.getUser(player.getUniqueId());
|
EconUser user = EconUser.getUser(player.getUniqueId());
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
|
player.sendRichMessage(Config.LOADING_ECON_DATA);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Material item = Material.valueOf(args[1].toUpperCase());
|
Material item = Material.valueOf(args[1].toUpperCase());
|
||||||
@@ -50,7 +50,7 @@ public class CommandBuy extends SubCommand {
|
|||||||
.anyMatch(material -> material.equals(item)))
|
.anyMatch(material -> material.equals(item)))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
if (optionalVillagerType.isEmpty()) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
VillagerType villagerType = optionalVillagerType.get();
|
VillagerType villagerType = optionalVillagerType.get();
|
||||||
@@ -61,7 +61,7 @@ public class CommandBuy extends SubCommand {
|
|||||||
}
|
}
|
||||||
Integer curPoints = user.getPointsMap().getOrDefault(villagerType.getName(), 0);
|
Integer curPoints = user.getPointsMap().getOrDefault(villagerType.getName(), 0);
|
||||||
double cost = price.calculatePriceThing(curPoints, price.getPoints(), true, price.getPoints());
|
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("material", item.name()),
|
||||||
Placeholder.unparsed("price", String.valueOf(cost)),
|
Placeholder.unparsed("price", String.valueOf(cost)),
|
||||||
Placeholder.unparsed("points", String.valueOf(price.getPoints())),
|
Placeholder.unparsed("points", String.valueOf(price.getPoints())),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.alttd.commands.subcommands;
|
|||||||
import com.alttd.commands.SubCommand;
|
import com.alttd.commands.SubCommand;
|
||||||
import com.alttd.config.Config;
|
import com.alttd.config.Config;
|
||||||
import com.alttd.config.VillagerConfig;
|
import com.alttd.config.VillagerConfig;
|
||||||
|
import com.alttd.mappers.VillagerTypeMapper;
|
||||||
import com.alttd.objects.LoadedVillagers;
|
import com.alttd.objects.LoadedVillagers;
|
||||||
import com.alttd.objects.VillagerType;
|
import com.alttd.objects.VillagerType;
|
||||||
import com.alttd.objects.VillagerTypeManager;
|
import com.alttd.objects.VillagerTypeManager;
|
||||||
@@ -19,40 +20,39 @@ import org.bukkit.entity.Villager;
|
|||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class CommandCreateVillager extends SubCommand {
|
public class CommandCreateVillager extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
if (args.length != 9) {
|
if (args.length != 9) {
|
||||||
commandSender.sendMiniMessage(getHelpMessage(), null);
|
commandSender.sendRichMessage(getHelpMessage());
|
||||||
return true;
|
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()) {
|
if (first.isEmpty()) {
|
||||||
commandSender.sendMiniMessage(getHelpMessage(), null);
|
commandSender.sendRichMessage(getHelpMessage());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
VillagerType villagerType = first.get();
|
VillagerType villagerType = first.get();
|
||||||
|
|
||||||
Villager.Type type = Villager.Type.valueOf(args[2].toUpperCase());
|
Optional<Villager.Type> optionalVillagerType = VillagerTypeMapper.map(args[2]);
|
||||||
if (type == null) { //TODO test if this might need a try catch?
|
if (optionalVillagerType.isEmpty()) {
|
||||||
commandSender.sendMiniMessage(getHelpMessage(), null);
|
commandSender.sendRichMessage(getHelpMessage());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
World world = Bukkit.getServer().getWorld(args[8]);
|
World world = Bukkit.getServer().getWorld(args[8]);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
commandSender.sendMiniMessage(getHelpMessage(), null);
|
commandSender.sendRichMessage(getHelpMessage());
|
||||||
return true;
|
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 villager = (Villager) world.spawnEntity(location, EntityType.VILLAGER, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||||
villager.setPersistent(true);
|
villager.setPersistent(true);
|
||||||
villager.setInvulnerable(true);
|
villager.setInvulnerable(true);
|
||||||
villager.setVillagerType(type);
|
villager.setVillagerType(optionalVillagerType.get());
|
||||||
villager.setProfession(villagerType.getProfession());
|
villager.setProfession(villagerType.getProfession());
|
||||||
villager.setRemoveWhenFarAway(false);
|
villager.setRemoveWhenFarAway(false);
|
||||||
villager.setCollidable(false);
|
villager.setCollidable(false);
|
||||||
@@ -80,10 +80,10 @@ public class CommandCreateVillager extends SubCommand {
|
|||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 2 -> res.addAll(VillagerTypeManager.getVillagerTypes().stream()
|
case 2 -> res.addAll(VillagerTypeManager.getVillagerTypes().stream()
|
||||||
.map(VillagerType::getName)
|
.map(VillagerType::getName)
|
||||||
.collect(Collectors.toList()));
|
.toList());
|
||||||
case 3 -> res.addAll(Arrays.stream(Villager.Type.values())
|
case 3 -> res.addAll(Arrays.stream(Villager.Type.values())
|
||||||
.map(something -> something.name())
|
.map(something -> something.name())
|
||||||
.collect(Collectors.toList()));
|
.toList());
|
||||||
case 4 -> {
|
case 4 -> {
|
||||||
if (commandSender instanceof Player player) {
|
if (commandSender instanceof Player player) {
|
||||||
res.add(String.valueOf(Utilities.round(player.getLocation().getX(), 2)));
|
res.add(String.valueOf(Utilities.round(player.getLocation().getX(), 2)));
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ public class CommandHelp extends SubCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
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()
|
.getSubCommands().stream()
|
||||||
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||||
.map(SubCommand::getHelpMessage)
|
.map(SubCommand::getHelpMessage)
|
||||||
.collect(Collectors.joining("\n"))), null);
|
.collect(Collectors.joining("\n"))));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.alttd.objects.VillagerTypeManager;
|
|||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
import net.kyori.adventure.text.Component;
|
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.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -27,12 +29,12 @@ public class CommandPoints extends SubCommand {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
if (!(commandSender instanceof Player player)) {
|
if (!(commandSender instanceof Player player)) {
|
||||||
commandSender.sendMiniMessage(Config.NO_CONSOLE, null);
|
commandSender.sendRichMessage(Config.NO_CONSOLE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
EconUser user = EconUser.getUser(player.getUniqueId());
|
EconUser user = EconUser.getUser(player.getUniqueId());
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
|
player.sendRichMessage(Config.LOADING_ECON_DATA);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
var ref = new Object() {
|
var ref = new Object() {
|
||||||
@@ -45,20 +47,18 @@ public class CommandPoints extends SubCommand {
|
|||||||
|
|
||||||
Object2ObjectOpenHashMap<String, Integer> pointsMap = user.getPointsMap();
|
Object2ObjectOpenHashMap<String, Integer> pointsMap = user.getPointsMap();
|
||||||
pointsMap.keySet().forEach(key -> {
|
pointsMap.keySet().forEach(key -> {
|
||||||
VillagerType villagerType = VillagerTypeManager.getVillagerType(key);
|
Optional<VillagerType> optionalVillagerType = VillagerTypeManager.getVillagerType(key);
|
||||||
if (villagerType == null) {
|
if (optionalVillagerType.isEmpty()) {
|
||||||
Logger.warning("Player % has unused villager type % in their point list.", player.getName(), key);
|
Logger.warning("Player % has unused villager type % in their point list.", player.getName(), key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
VillagerType villagerType = optionalVillagerType.get();
|
||||||
int currentPoints = pointsMap.getOrDefault(key, 0);
|
int currentPoints = pointsMap.getOrDefault(key, 0);
|
||||||
if (currentPoints == 0) return;
|
if (currentPoints == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
allPointsAreZero.set(false);
|
allPointsAreZero.set(false);
|
||||||
ref.message = ref.message.append(miniMessage.deserialize("\n", TagResolver.resolver()));
|
ref.message = ref.message.append(getPointContentComponent(villagerType, currentPoints));
|
||||||
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))))));
|
|
||||||
});
|
});
|
||||||
if (allPointsAreZero.get()) {
|
if (allPointsAreZero.get()) {
|
||||||
ref.message = miniMessage.deserialize(Config.NO_VILLAGER_POINTS);
|
ref.message = miniMessage.deserialize(Config.NO_VILLAGER_POINTS);
|
||||||
@@ -70,36 +70,41 @@ public class CommandPoints extends SubCommand {
|
|||||||
|
|
||||||
Object2ObjectOpenHashMap<String, Integer> pointsMap = user.getPointsMap();
|
Object2ObjectOpenHashMap<String, Integer> pointsMap = user.getPointsMap();
|
||||||
int currentPoints = pointsMap.getOrDefault(villagerType.getName(), 0);
|
int currentPoints = pointsMap.getOrDefault(villagerType.getName(), 0);
|
||||||
ref.message = ref.message.append(miniMessage.deserialize("\n", TagResolver.resolver()));
|
ref.message = ref.message.append(getPointContentComponent(villagerType, currentPoints));
|
||||||
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 {
|
} else {
|
||||||
VillagerType villagerType = VillagerTypeManager.getVillagerType(args[1].toLowerCase());
|
Optional<VillagerType> optionalVillagerType = VillagerTypeManager.getVillagerType(args[1].toLowerCase());
|
||||||
Object2ObjectOpenHashMap<String, Integer> pointsMap = user.getPointsMap();
|
Object2ObjectOpenHashMap<String, Integer> pointsMap = user.getPointsMap();
|
||||||
if (villagerType == null) {
|
if (optionalVillagerType.isEmpty()) {
|
||||||
player.sendMiniMessage(Config.NOT_A_VILLAGER, TagResolver.resolver(Placeholder.unparsed("villager_type", args[1])));
|
player.sendRichMessage(Config.NOT_A_VILLAGER, TagResolver.resolver(Placeholder.unparsed("villager_type", args[1])));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
VillagerType villagerType = optionalVillagerType.get();
|
||||||
int currentPoints = pointsMap.getOrDefault(villagerType.getName(), 0);
|
int currentPoints = pointsMap.getOrDefault(villagerType.getName(), 0);
|
||||||
ref.message = ref.message.append(miniMessage.deserialize(Config.POINTS_CONTENT, TagResolver.resolver(
|
ref.message = ref.message.append(miniMessage.deserialize(Config.POINTS_CONTENT, TagResolver.resolver(
|
||||||
Placeholder.unparsed("villager_type", villagerType.getDisplayName()),
|
Placeholder.unparsed("villager_type", villagerType.getDisplayName()),
|
||||||
Placeholder.unparsed("points", String.valueOf(currentPoints)),
|
Placeholder.unparsed("points", String.valueOf(currentPoints)),
|
||||||
Placeholder.unparsed("buy_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, true))),
|
Placeholder.unparsed("buy_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, true))),
|
||||||
Placeholder.unparsed("sell_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, false)))
|
Placeholder.unparsed("sell_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, false)))
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
player.sendMiniMessage(getHelpMessage(), null);
|
player.sendRichMessage(getHelpMessage());
|
||||||
|
}
|
||||||
|
|
||||||
player.sendMessage(ref.message);
|
player.sendMessage((ComponentLike) ref.message);
|
||||||
return true;
|
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
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "points";
|
return "points";
|
||||||
@@ -108,10 +113,11 @@ public class CommandPoints extends SubCommand {
|
|||||||
@Override
|
@Override
|
||||||
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||||
List<String> res = new ArrayList<>();
|
List<String> res = new ArrayList<>();
|
||||||
if (args.length == 2)
|
if (args.length == 2) {
|
||||||
res.addAll(VillagerTypeManager.getVillagerTypes().stream()
|
res.addAll(VillagerTypeManager.getVillagerTypes().stream()
|
||||||
.map(VillagerType::getName)
|
.map(VillagerType::getName)
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
res.add("all");
|
res.add("all");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class CommandReload extends SubCommand {
|
|||||||
Config.reload();
|
Config.reload();
|
||||||
VillagerConfig.reload();
|
VillagerConfig.reload();
|
||||||
WorthConfig.reload();
|
WorthConfig.reload();
|
||||||
commandSender.sendMiniMessage("<green>Reloaded VillagerShopUI config.</green>", null);
|
commandSender.sendRichMessage("<green>Reloaded VillagerShopUI config.</green>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class CommandRemoveVillager extends SubCommand {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
if (!(commandSender instanceof Player player)) {
|
if (!(commandSender instanceof Player player)) {
|
||||||
commandSender.sendMiniMessage(Config.NO_CONSOLE, null);
|
commandSender.sendRichMessage(Config.NO_CONSOLE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ public class CommandRemoveVillager extends SubCommand {
|
|||||||
LoadedVillagers.removeLoadedVillager(uuid);
|
LoadedVillagers.removeLoadedVillager(uuid);
|
||||||
VillagerConfig.removeVillager(uuid);
|
VillagerConfig.removeVillager(uuid);
|
||||||
entity.remove();
|
entity.remove();
|
||||||
player.sendMiniMessage(Config.REMOVED_VILLAGER, TagResolver.resolver(
|
player.sendRichMessage(Config.REMOVED_VILLAGER, TagResolver.resolver(
|
||||||
Placeholder.unparsed("uuid", uuid.toString())));
|
Placeholder.unparsed("uuid", uuid.toString())));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,21 +26,21 @@ public class CommandSell extends SubCommand {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||||
if (!(commandSender instanceof Player player)) {
|
if (!(commandSender instanceof Player player)) {
|
||||||
commandSender.sendMiniMessage(Config.NO_CONSOLE, null);
|
commandSender.sendRichMessage(Config.NO_CONSOLE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
//TODO open gui
|
//TODO open gui
|
||||||
player.sendMiniMessage(getHelpMessage(), null); //TODO remove later
|
player.sendRichMessage(getHelpMessage()); //TODO remove later
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
player.sendMiniMessage(getHelpMessage(), null);
|
player.sendRichMessage(getHelpMessage());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
EconUser user = EconUser.getUser(player.getUniqueId());
|
EconUser user = EconUser.getUser(player.getUniqueId());
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
|
player.sendRichMessage(Config.LOADING_ECON_DATA);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Material item = Material.valueOf(args[1].toUpperCase());
|
Material item = Material.valueOf(args[1].toUpperCase());
|
||||||
@@ -50,7 +50,7 @@ public class CommandSell extends SubCommand {
|
|||||||
.anyMatch(material -> material.equals(item)))
|
.anyMatch(material -> material.equals(item)))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
if (optionalVillagerType.isEmpty()) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
VillagerType villagerType = optionalVillagerType.get();
|
VillagerType villagerType = optionalVillagerType.get();
|
||||||
@@ -61,7 +61,7 @@ public class CommandSell extends SubCommand {
|
|||||||
}
|
}
|
||||||
Integer curPoints = user.getPointsMap().getOrDefault(villagerType.getName(), 0);
|
Integer curPoints = user.getPointsMap().getOrDefault(villagerType.getName(), 0);
|
||||||
double cost = price.calculatePriceThing(curPoints, price.getPoints(), false, price.getPoints());
|
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("material", item.name()),
|
||||||
Placeholder.unparsed("price", String.valueOf(cost)),
|
Placeholder.unparsed("price", String.valueOf(cost)),
|
||||||
Placeholder.unparsed("points", String.valueOf(price.getPoints())),
|
Placeholder.unparsed("points", String.valueOf(price.getPoints())),
|
||||||
|
|||||||
@@ -68,21 +68,25 @@ public final class Config extends AbstractConfig {
|
|||||||
public static String HELP_MESSAGE_WRAPPER = "<gold>VillagerShopUI help:\n<commands></gold>";
|
public static String HELP_MESSAGE_WRAPPER = "<gold>VillagerShopUI help:\n<commands></gold>";
|
||||||
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/villagerui help</gold></green>";
|
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/villagerui help</gold></green>";
|
||||||
public static String POINTS_MESSAGE = "<green>Show points: <gold>/villagerui points [villagerType]</green>";
|
public static String POINTS_MESSAGE = "<green>Show points: <gold>/villagerui points [villagerType]</green>";
|
||||||
|
public static String AUTO_SELL_MESSAGE = "<green>Toggle auto sell per item: <gold>/villagerui autosell <block></green>";
|
||||||
public static String BUY_MESSAGE = "<green>Check where/if you can buy an item: <gold>/villagerui buy <item_name></green>";
|
public static String BUY_MESSAGE = "<green>Check where/if you can buy an item: <gold>/villagerui buy <item_name></green>";
|
||||||
public static String SELL_MESSAGE = "<green>Check where/if you can sell an item: <gold>/villagerui sell <item_name></green>";
|
public static String SELL_MESSAGE = "<green>Check where/if you can sell an item: <gold>/villagerui sell <item_name></green>";
|
||||||
public static String RELOAD_MESSAGE = "<green>Reload configs: <gold>/villagerui reload</gold></green>";
|
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 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 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() {
|
private static void loadHelp() {
|
||||||
HELP_MESSAGE_WRAPPER = config.getString("help.help-wrapper", HELP_MESSAGE_WRAPPER);
|
HELP_MESSAGE_WRAPPER = config.getString("help.help-wrapper", HELP_MESSAGE_WRAPPER);
|
||||||
HELP_MESSAGE = config.getString("help.help", HELP_MESSAGE);
|
HELP_MESSAGE = config.getString("help.help", HELP_MESSAGE);
|
||||||
POINTS_MESSAGE = config.getString("help.points", POINTS_MESSAGE);
|
POINTS_MESSAGE = config.getString("help.points", POINTS_MESSAGE);
|
||||||
|
AUTO_SELL_MESSAGE = config.getString("help.auto-sell", AUTO_SELL_MESSAGE);
|
||||||
BUY_MESSAGE = config.getString("help.buy", BUY_MESSAGE);
|
BUY_MESSAGE = config.getString("help.buy", BUY_MESSAGE);
|
||||||
SELL_MESSAGE = config.getString("help.sell", SELL_MESSAGE);
|
SELL_MESSAGE = config.getString("help.sell", SELL_MESSAGE);
|
||||||
RELOAD_MESSAGE = config.getString("help.reload", RELOAD_MESSAGE);
|
RELOAD_MESSAGE = config.getString("help.reload", RELOAD_MESSAGE);
|
||||||
CREATE_VILLAGER_MESSAGE = config.getString("help.create-villager", CREATE_VILLAGER_MESSAGE);
|
CREATE_VILLAGER_MESSAGE = config.getString("help.create-villager", CREATE_VILLAGER_MESSAGE);
|
||||||
REMOVE_VILLAGER_MESSAGE = config.getString("help.remove-villager", REMOVE_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>";
|
public static String NO_PERMISSION = "<red>You do not have permission to do that.</red>";
|
||||||
@@ -140,6 +144,15 @@ public final class Config extends AbstractConfig {
|
|||||||
public static String LOADING_ECON_DATA = "<red>Loading your economy data, please wait...</red>";
|
public static String LOADING_ECON_DATA = "<red>Loading your economy data, please wait...</red>";
|
||||||
public static String NO_VILLAGER_POINTS = "<red>You don't have any villager points.</red>";
|
public static String NO_VILLAGER_POINTS = "<red>You don't have any villager points.</red>";
|
||||||
public static String NOTIFY_POINTS_RESET = "<green>Your points for <villager_type> reset to 0!</green>";
|
public static String NOTIFY_POINTS_RESET = "<green>Your points for <villager_type> reset to 0!</green>";
|
||||||
|
public static String NO_AUTO_SELL_ITEMS = "<green>You don't have any items set to auto sell!</green>";
|
||||||
|
public static String LIST_AUTO_SELL_ITEMS = "<green>You have the following items enabled to auto sell</green>";
|
||||||
|
public static String LIST_AUTO_SELL_COMPONENT = "<yellow><material></yellow>";
|
||||||
|
public static String INVALID_AUTO_SELL_ITEM = "<red><material> is not a valid auto sell item</red>";
|
||||||
|
public static String TURNED_ON_AUTO_SELL_FOR = "<yellow>Turned <green>on</green> auto sell for <material></yellow>";
|
||||||
|
public static String TURNED_OFF_AUTO_SELL_FOR = "<yellow>Turned <red>off</red> auto sell for <material></yellow>";
|
||||||
|
public static String AUTO_SOLD = "<green>You made <total_money_made> from auto selling</green>";
|
||||||
|
public static String MAX_AUTO_SELL_REACHED = "<red>You can only auto sell up to <max_auto_sell> items at a time</red>";
|
||||||
|
public static String DISABLED_AUTO_SELL = "<green>You have disabled auto sell</green>";
|
||||||
|
|
||||||
private static void loadMessages() {
|
private static void loadMessages() {
|
||||||
NOT_ENOUGH_MONEY = config.getString("messages.not-enough-money", NOT_ENOUGH_MONEY);
|
NOT_ENOUGH_MONEY = config.getString("messages.not-enough-money", NOT_ENOUGH_MONEY);
|
||||||
@@ -159,12 +172,23 @@ public final class Config extends AbstractConfig {
|
|||||||
LOADING_ECON_DATA = config.getString("messages.loading-econ-data", LOADING_ECON_DATA);
|
LOADING_ECON_DATA = config.getString("messages.loading-econ-data", LOADING_ECON_DATA);
|
||||||
NO_VILLAGER_POINTS = config.getString("messages.no-villager-points", NO_VILLAGER_POINTS);
|
NO_VILLAGER_POINTS = config.getString("messages.no-villager-points", NO_VILLAGER_POINTS);
|
||||||
NOTIFY_POINTS_RESET = config.getString("messages.notify-points-reset", NOTIFY_POINTS_RESET);
|
NOTIFY_POINTS_RESET = config.getString("messages.notify-points-reset", NOTIFY_POINTS_RESET);
|
||||||
|
NO_AUTO_SELL_ITEMS = config.getString("messages.no-auto-sell-items", NO_AUTO_SELL_ITEMS);
|
||||||
|
LIST_AUTO_SELL_ITEMS = config.getString("messages.list-auto-sell-items", LIST_AUTO_SELL_ITEMS);
|
||||||
|
LIST_AUTO_SELL_COMPONENT = config.getString("messages.list-auto-sell-component", LIST_AUTO_SELL_COMPONENT);
|
||||||
|
INVALID_AUTO_SELL_ITEM = config.getString("messages.invalid-auto-sell-item", INVALID_AUTO_SELL_ITEM);
|
||||||
|
TURNED_ON_AUTO_SELL_FOR = config.getString("messages.turned-on-auto-sell-for", TURNED_ON_AUTO_SELL_FOR);
|
||||||
|
TURNED_OFF_AUTO_SELL_FOR = config.getString("messages.turned-off-auto-sell-for", TURNED_OFF_AUTO_SELL_FOR);
|
||||||
|
AUTO_SOLD = config.getString("messages.auto-sold", AUTO_SOLD);
|
||||||
|
MAX_AUTO_SELL_REACHED = config.getString("messages.max-auto-sell-reached", MAX_AUTO_SELL_REACHED);
|
||||||
|
DISABLED_AUTO_SELL = config.getString("messages.disabled-auto-sell", DISABLED_AUTO_SELL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean DEBUG = false;
|
public static boolean DEBUG = false;
|
||||||
|
public static int MAX_AUTO_SELL = 5;
|
||||||
|
|
||||||
private static void loadSettings() {
|
private static void loadSettings() {
|
||||||
DEBUG = config.getBoolean("settings.debug", DEBUG);
|
DEBUG = config.getBoolean("settings.debug", DEBUG);
|
||||||
|
MAX_AUTO_SELL = config.getInt("settings.max-auto-sell", MAX_AUTO_SELL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadVillagerTypes() {
|
private static void loadVillagerTypes() {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.alttd.objects.LoadedVillagers;
|
|||||||
import com.alttd.objects.VillagerType;
|
import com.alttd.objects.VillagerType;
|
||||||
import com.alttd.objects.VillagerTypeManager;
|
import com.alttd.objects.VillagerTypeManager;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class VillagerConfig extends AbstractConfig {
|
public class VillagerConfig extends AbstractConfig {
|
||||||
@@ -27,11 +29,10 @@ public class VillagerConfig extends AbstractConfig {
|
|||||||
private static void loadVillagers() {
|
private static void loadVillagers() {
|
||||||
LoadedVillagers.clearLoadedVillagers();
|
LoadedVillagers.clearLoadedVillagers();
|
||||||
config.getConfigurationSection("").getKeys(false).forEach(key -> {
|
config.getConfigurationSection("").getKeys(false).forEach(key -> {
|
||||||
VillagerType villagerType = VillagerTypeManager.getVillagerType(config.getString(key, ""));
|
Optional<VillagerType> optionalVillagerType = VillagerTypeManager.getVillagerType(config.getString(key, ""));
|
||||||
if (villagerType != null)
|
optionalVillagerType
|
||||||
LoadedVillagers.addLoadedVillager(UUID.fromString(key), villagerType);
|
.ifPresentOrElse(present -> LoadedVillagers.addLoadedVillager(UUID.fromString(key), present),
|
||||||
else
|
() -> Logger.warning("Invalid config entry %.", key));
|
||||||
Logger.warning("Invalid config entry %.", key);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class VillagerMessagesConfig extends AbstractConfig {
|
public class VillagerMessagesConfig extends AbstractConfig {
|
||||||
@@ -41,12 +42,12 @@ public class VillagerMessagesConfig extends AbstractConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
keys.forEach(key -> {
|
keys.forEach(key -> {
|
||||||
VillagerType villagerType = VillagerTypeManager.getVillagerType(key);
|
Optional<VillagerType> optionalVillagerType = VillagerTypeManager.getVillagerType(key);
|
||||||
if (villagerType == null) {
|
if (optionalVillagerType.isEmpty()) {
|
||||||
Logger.info("Unknown villager type: " + key);
|
Logger.info("Unknown villager type: " + key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
villagerType.setMessages(configurationSection.getStringList(key));
|
optionalVillagerType.get().setMessages(configurationSection.getStringList(key));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.alttd.events;
|
||||||
|
|
||||||
|
import com.alttd.util.auto_sell.AutoSellTask;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ItemPickupEvent implements Listener {
|
||||||
|
|
||||||
|
private final AutoSellTask autoSellTask;
|
||||||
|
|
||||||
|
public ItemPickupEvent(AutoSellTask autoSellTask) {
|
||||||
|
this.autoSellTask = autoSellTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onItemPickupEvent(EntityPickupItemEvent event) {
|
||||||
|
if (!(event.getEntity() instanceof Player player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
if (!autoSellTask.autoSellEnabled(uuid, event.getItem().getItemStack().getType())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
autoSellTask.putAutoSellPlayer(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -31,6 +31,7 @@ public final class SpawnShopEvent extends Event {
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Trade
|
||||||
public SpawnShopEvent(Player player, Material material, int amount, double price, boolean buy) {
|
public SpawnShopEvent(Player player, Material material, int amount, double price, boolean buy) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
@@ -41,6 +42,17 @@ public final class SpawnShopEvent extends Event {
|
|||||||
this.buy = buy;
|
this.buy = buy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Auto sell
|
||||||
|
public SpawnShopEvent(Player player, Purchase purchase, int pointsBefore, int pointsAfter, double price) {
|
||||||
|
this.player = player;
|
||||||
|
this.amount = purchase.amount();
|
||||||
|
this.price = price;
|
||||||
|
this.item = purchase.material();
|
||||||
|
this.pointsBefore = pointsBefore;
|
||||||
|
this.pointsAfter = pointsAfter;
|
||||||
|
this.buy = false;
|
||||||
|
}
|
||||||
|
|
||||||
public int amount() {
|
public int amount() {
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
@@ -75,4 +87,3 @@ public final class SpawnShopEvent extends Event {
|
|||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import com.alttd.GUI.windows.TradeGUI;
|
|||||||
import com.alttd.VillagerUI;
|
import com.alttd.VillagerUI;
|
||||||
import com.alttd.config.Config;
|
import com.alttd.config.Config;
|
||||||
import com.alttd.config.VillagerConfig;
|
import com.alttd.config.VillagerConfig;
|
||||||
import com.alttd.galaxy.event.player.PlayerInteractOnEntityEvent;
|
import com.alttd.cosmos.event.player.PlayerInteractOnEntityEvent;
|
||||||
import com.alttd.objects.*;
|
import com.alttd.objects.*;
|
||||||
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -35,12 +36,12 @@ public class VillagerEvents implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
if (!player.hasPermission(loadedVillager.getPermission())) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
EconUser user = EconUser.getUser(player.getUniqueId());
|
EconUser user = EconUser.getUser(player.getUniqueId());
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
player.sendMiniMessage(Config.LOADING_ECON_DATA, null);
|
player.sendRichMessage(Config.LOADING_ECON_DATA);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@@ -80,7 +81,7 @@ public class VillagerEvents implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadedVillager.getRandomMessage().ifPresent(player::sendMessage);
|
loadedVillager.getRandomMessage().ifPresent(component -> player.sendMessage((ComponentLike) component));
|
||||||
if (loadedVillager instanceof BlackMarketVillagerType) {
|
if (loadedVillager instanceof BlackMarketVillagerType) {
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_HURT, 1.0F, 1.0F);
|
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_HURT, 1.0F, 1.0F);
|
||||||
} else if (loadedVillager instanceof ShopVillagerType) {
|
} else if (loadedVillager instanceof ShopVillagerType) {
|
||||||
|
|||||||
@@ -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();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -132,7 +132,7 @@ public class EconUser {
|
|||||||
public void notifyPlayer(UUID uuid, String villagerType) {
|
public void notifyPlayer(UUID uuid, String villagerType) {
|
||||||
Player player = Bukkit.getPlayer(uuid);
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
if (player != null && player.isOnline())
|
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) {
|
public static void tryLoadUser(UUID uuid) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.alttd.objects;
|
package com.alttd.objects;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class VillagerTypeManager {
|
public class VillagerTypeManager {
|
||||||
@@ -10,8 +11,8 @@ public class VillagerTypeManager {
|
|||||||
return villagerTypes;
|
return villagerTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VillagerType getVillagerType(String name) {
|
public static Optional<VillagerType> getVillagerType(String name) {
|
||||||
return villagerTypes.stream().filter(villagerType -> villagerType.getName().equals(name)).findFirst().orElse(null);
|
return villagerTypes.stream().filter(villagerType -> villagerType.getName().equals(name)).findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addVillagerType(VillagerType villagerType) {
|
public static void addVillagerType(VillagerType villagerType) {
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package com.alttd.util.auto_sell;
|
||||||
|
|
||||||
|
import com.alttd.VillagerUI;
|
||||||
|
import com.alttd.config.Config;
|
||||||
|
import com.alttd.config.WorthConfig;
|
||||||
|
import com.alttd.events.SpawnShopEvent;
|
||||||
|
import com.alttd.objects.*;
|
||||||
|
import com.alttd.util.Logger;
|
||||||
|
import com.alttd.util.Utilities;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class AutoSell {
|
||||||
|
|
||||||
|
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
|
||||||
|
public static void autoSell(Player player, Set<Material> materials) {
|
||||||
|
EconUser econUser = EconUser.getUser(player.getUniqueId());
|
||||||
|
if (econUser == null) {
|
||||||
|
player.sendRichMessage(Config.LOADING_ECON_DATA);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
double totalMoneyMade = VillagerTypeManager
|
||||||
|
.getVillagerTypes()
|
||||||
|
.stream()
|
||||||
|
.flatMap(villagerType -> villagerType
|
||||||
|
.getSelling()
|
||||||
|
.stream()
|
||||||
|
.map(ItemStack::getType)
|
||||||
|
.filter(materials::contains)
|
||||||
|
.map(material -> sell(player, econUser, villagerType, material)))
|
||||||
|
.mapToDouble(Double::doubleValue)
|
||||||
|
.sum();
|
||||||
|
player.sendActionBar(miniMessage.deserialize(Config.AUTO_SOLD,
|
||||||
|
Placeholder.parsed("total_money_made", String.valueOf(totalMoneyMade))));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double sell(Player player, EconUser econUser, VillagerType villagerType, Material material) {
|
||||||
|
int amount = countTotalBlocksInInventory(player.getInventory(), material);
|
||||||
|
if (amount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Price price = Utilities.getPrice(new ItemStack(material, amount), WorthConfig.sell);
|
||||||
|
if (price == null) {
|
||||||
|
Logger.warning("Unable to sell %s for % due to missing worth data.",
|
||||||
|
material.name(), villagerType.getName());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int oldPoints = econUser.getPointsMap().getOrDefault(villagerType.getName(), 0);
|
||||||
|
int itemPts = price.getPoints();
|
||||||
|
int transPts = (itemPts * amount) * -1;
|
||||||
|
double cost = price.calculatePriceThing(oldPoints, transPts, false, itemPts);
|
||||||
|
|
||||||
|
Purchase purchase = new Purchase(material, cost, itemPts, transPts, amount);
|
||||||
|
|
||||||
|
Economy econ = VillagerUI.getInstance().getEconomy();
|
||||||
|
double finalPrice = purchase.price();
|
||||||
|
if (!player.hasPermission("villagerui.autosell.full-price")) {
|
||||||
|
finalPrice /= 2;
|
||||||
|
}
|
||||||
|
econ.depositPlayer(player, finalPrice);
|
||||||
|
econUser.addPoints(villagerType.getName(), purchase.totalPointCost());
|
||||||
|
|
||||||
|
player.getInventory().remove(material);
|
||||||
|
player.updateInventory();
|
||||||
|
|
||||||
|
int newPoints = econUser.getPointsMap().get(villagerType.getName());
|
||||||
|
|
||||||
|
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
|
||||||
|
double effectivelyFinalPrice = finalPrice;
|
||||||
|
scheduler.callSyncMethod(VillagerUI.getInstance(), () -> {
|
||||||
|
Bukkit.getServer().getPluginManager()
|
||||||
|
.callEvent(new SpawnShopEvent(player, purchase, oldPoints, newPoints, effectivelyFinalPrice));
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
return finalPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int countTotalBlocksInInventory(Inventory inventory, Material material) {
|
||||||
|
return Arrays.stream(inventory.getContents())
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.filter(itemStack -> itemStack.getType().equals(material))
|
||||||
|
.mapToInt(ItemStack::getAmount)
|
||||||
|
.sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package com.alttd.util.auto_sell;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class AutoSellTask extends BukkitRunnable {
|
||||||
|
|
||||||
|
private final HashMap<UUID, Set<Material>> autoSellMap = new HashMap<>();
|
||||||
|
private final Set<UUID> autoSellPlayers = new HashSet<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
runAutoSell();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void putAutoSellPlayer(UUID uuid) {
|
||||||
|
autoSellPlayers.add(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void runAutoSell() {
|
||||||
|
Bukkit.getOnlinePlayers()
|
||||||
|
.stream()
|
||||||
|
.filter(player -> autoSellPlayers.contains(player.getUniqueId()))
|
||||||
|
.forEach(player -> {
|
||||||
|
Set<Material> materials = autoSellMap.get(player.getUniqueId());
|
||||||
|
if (materials != null && !materials.isEmpty()) {
|
||||||
|
AutoSell.autoSell(player, materials);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
autoSellPlayers.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAutoSellEntry(UUID uuid) {
|
||||||
|
if (!autoSellMap.containsKey(uuid)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !autoSellMap.get(uuid).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean toggleAutoSell(UUID uuid, Material material) {
|
||||||
|
Set<Material> materials = autoSellMap.computeIfAbsent(uuid, k -> new HashSet<>());
|
||||||
|
if (materials.contains(material)) {
|
||||||
|
materials.remove(material);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
materials.add(material);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Material> getAutoSellList(UUID uuid) {
|
||||||
|
return autoSellMap.getOrDefault(uuid, new HashSet<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean autoSellEnabled(UUID uuid, @NotNull Material type) {
|
||||||
|
if (!autoSellMap.containsKey(uuid)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Set<Material> materials = autoSellMap.getOrDefault(uuid, new HashSet<>());
|
||||||
|
if (materials.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return materials.contains(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEntries(UUID uuid) {
|
||||||
|
Set<Material> materials = autoSellMap.get(uuid);
|
||||||
|
if (materials == null || materials.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return materials.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAutoSell(UUID uuid, Material material) {
|
||||||
|
Set<Material> materials = autoSellMap.get(uuid);
|
||||||
|
if (materials == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
materials.remove(material);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void clearAutoSell(Player player) {
|
||||||
|
autoSellPlayers.remove(player.getUniqueId());
|
||||||
|
autoSellMap.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user