Compare commits

..
17 Commits
14 changed files with 163 additions and 142 deletions
Vendored
+16 -10
View File
@@ -3,7 +3,13 @@ pipeline {
stages { stages {
stage('Gradle') { stage('Gradle') {
steps { steps {
sh './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('Archive') { stage('Archive') {
@@ -16,14 +22,14 @@ pipeline {
discordSend description: "Build: ${BUILD_NUMBER}", showChangeset: true, result: currentBuild.currentResult, title: currentBuild.fullProjectName, webhookURL: env.discordwebhook discordSend description: "Build: ${BUILD_NUMBER}", showChangeset: true, result: currentBuild.currentResult, title: currentBuild.fullProjectName, webhookURL: env.discordwebhook
} }
} }
stage('Copy to /mnt/updates/plugins') { // stage('Copy to /mnt/updates/plugins') {
when { // when {
branch 'main' // branch 'main'
branch 'master' // branch 'master'
} // }
steps { // steps {
sh 'cp build/libs/*.jar /mnt/updates/plugins/' // sh 'cp build/libs/*.jar /mnt/updates/plugins/'
} // }
} // }
} }
} }
+15 -29
View File
@@ -7,24 +7,18 @@ import net.minecrell.pluginyml.paper.PaperPluginDescription
plugins { plugins {
id("java") id("java")
id("java-library") id("java-library")
id("de.eldoria.plugin-yml.paper") version "0.8.0" id("de.eldoria.plugin-yml.paper") version "0.9.0"
id("xyz.jpenilla.run-paper") version "1.0.6" id("xyz.jpenilla.run-paper") version "1.0.6"
id("maven-publish") id("maven-publish")
} }
group = "com.alttd.playershops" group = "com.alttd.playershops"
version = System.getenv("BUILD_NUMBER") ?: "1.3-SNAPSHOT" version = System.getenv("BUILD_NUMBER") ?: "1.4-SNAPSHOT"
description = "Player Shop plugin for Altitude." description = "Player Shop plugin for Altitude."
apply<JavaLibraryPlugin>() apply<JavaLibraryPlugin>()
apply(plugin = "maven-publish") apply(plugin = "maven-publish")
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
tasks { tasks {
withType<JavaCompile> { withType<JavaCompile> {
options.encoding = Charsets.UTF_8.name() options.encoding = Charsets.UTF_8.name()
@@ -35,16 +29,17 @@ tasks {
} }
runServer { runServer {
val fileName = "./run/cosmos.jar" val dir = File(System.getProperty("user.home") + "/share/devserver/")
val file = File(fileName) if (!dir.parentFile.exists()) {
if (!file.parentFile.exists()) { dir.parentFile.mkdirs()
file.parentFile.mkdirs()
}
if (!file.exists()) {
download("https://jenkins.destro.xyz/job/Cosmos/lastSuccessfulBuild/artifact/cosmos-server/build/libs/cosmos-bundler-1.21.11-R0.1-SNAPSHOT-mojmap.jar", fileName)
} }
runDirectory.set(dir)
val fileName = "/cosmos.jar"
val file = File(dir.path + fileName)
serverJar(file) serverJar(file)
minecraftVersion("1.21") minecraftVersion("26.2")
} }
jar { jar {
@@ -73,23 +68,14 @@ publishing {
} }
dependencies { dependencies {
compileOnly("com.alttd.cosmos:cosmos-api:1.21.11-R0.1-SNAPSHOT") compileOnly("com.alttd.cosmos:cosmos-api:26.2.build.17-stable")
compileOnly("com.github.milkbowl:VaultAPI:1.7") { compileOnly("com.github.milkbowl:VaultAPI:1.7") {
exclude("org.bukkit","bukkit") exclude("org.bukkit","bukkit")
} }
compileOnly("com.github.TechFortress:GriefPrevention:16.17.1") compileOnly("com.github.TechFortress:GriefPrevention:16.17.1")
compileOnly("org.projectlombok:lombok:1.18.30") compileOnly("org.projectlombok:lombok:1.18.46")
annotationProcessor("org.projectlombok:lombok:1.18.30") annotationProcessor("org.projectlombok:lombok:1.18.46")
}
fun gitCommit(): String {
val os = ByteArrayOutputStream()
project.exec {
commandLine = "git rev-parse --short HEAD".split(" ")
standardOutput = os
}
return String(os.toByteArray()).trim()
} }
fun download(link: String, path: String) { fun download(link: String, path: String) {
@@ -104,7 +90,7 @@ paper {
name = rootProject.name name = rootProject.name
main = "$group.${rootProject.name}" main = "$group.${rootProject.name}"
bootstrapper = "$group.${rootProject.name}Bootstrap" bootstrapper = "$group.${rootProject.name}Bootstrap"
version = "${rootProject.version}-${gitCommit()}" version = "${rootProject.version}"
apiVersion = "1.21" apiVersion = "1.21"
authors = listOf("destro174") authors = listOf("destro174")
serverDependencies { serverDependencies {
Binary file not shown.
+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
networkTimeout=10000 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
Vendored
+7 -8
View File
@@ -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/HEAD/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/.
@@ -84,7 +86,7 @@ done
# shellcheck disable=SC2034 # shellcheck disable=SC2034
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# 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
@@ -112,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.
@@ -170,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" )
@@ -203,15 +203,14 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command: # Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped. # 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 # * 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. # 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. # Stop when "xargs" is not available.
Vendored
+13 -12
View File
@@ -13,6 +13,8 @@
@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 ##########################################################################
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 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
@@ -57,22 +59,21 @@ 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
+15 -5
View File
@@ -1,14 +1,24 @@
rootProject.name = "PlayerShops" rootProject.name = "PlayerShops"
val nexusUser = providers.gradleProperty("alttdSnapshotUsername").orNull ?: System.getenv("NEXUS_USERNAME")
val nexusPass = providers.gradleProperty("alttdSnapshotPassword").orNull ?: System.getenv("NEXUS_PASSWORD")
dependencyResolutionManagement { dependencyResolutionManagement {
repositories { repositories {
mavenCentral() mavenCentral()
maven { maven {
name = "AlttdNexus" url = uri("https://repo.alttd.com/repository/alttd-snapshot/")
url = uri( credentials {
"https://repo.alttd.com/repository/alttd-snapshot/" username = nexusUser
) password = nexusPass
credentials(PasswordCredentials::class) }
}
maven {
url = uri("https://repo.alttd.com/repository/alttd/")
credentials {
username = nexusUser
password = nexusPass
}
} }
maven("https://repo.destro.xyz/snapshots") maven("https://repo.destro.xyz/snapshots")
maven("https://jitpack.io") { // Vault maven("https://jitpack.io") { // Vault
@@ -174,12 +174,14 @@ public class MessageConfig {
public static String GUI_HOME_TITLE = "<green>PlayerShops"; public static String GUI_HOME_TITLE = "<green>PlayerShops";
public static String GUI_LIST_PLAYERS_TITLE = "<green>Player shops"; public static String GUI_LIST_PLAYERS_TITLE = "<green>Player shops";
public static String GUI_LIST_SHOPS_TITLE = "<green>Players shops by <playername>"; public static String GUI_LIST_SHOPS_TITLE = "<green>Players shops by <playername>";
public static String GUI_LIST_SHOPS_ITEM_TITLE = "<green>Players shops by item";
public static String GUI_LIST_TRANSACTIONS_TITLE = "<green>Shop Transactions"; public static String GUI_LIST_TRANSACTIONS_TITLE = "<green>Shop Transactions";
public static String GUI_MANAGE_TITLE = "<green>Shop Manager"; public static String GUI_MANAGE_TITLE = "<green>Shop Manager";
public static String GUI_PLAYER_SETTINGS_TITLE = "<green>Shop Settings Manager"; public static String GUI_PLAYER_SETTINGS_TITLE = "<green>Shop Settings Manager";
private static void guiTitles() { private static void guiTitles() {
GUI_HOME_TITLE = getString("gui.home-title", GUI_HOME_TITLE); GUI_HOME_TITLE = getString("gui.home-title", GUI_HOME_TITLE);
GUI_LIST_PLAYERS_TITLE = getString("gui.list-players-title", GUI_LIST_PLAYERS_TITLE); GUI_LIST_PLAYERS_TITLE = getString("gui.list-players-title", GUI_LIST_PLAYERS_TITLE);
GUI_LIST_SHOPS_ITEM_TITLE = getString("gui.list-items-title", GUI_LIST_SHOPS_ITEM_TITLE);
GUI_LIST_SHOPS_TITLE = getString("gui.list-shops-title", GUI_LIST_SHOPS_TITLE); GUI_LIST_SHOPS_TITLE = getString("gui.list-shops-title", GUI_LIST_SHOPS_TITLE);
GUI_LIST_TRANSACTIONS_TITLE = getString("gui.list-transactions-title", GUI_LIST_TRANSACTIONS_TITLE); GUI_LIST_TRANSACTIONS_TITLE = getString("gui.list-transactions-title", GUI_LIST_TRANSACTIONS_TITLE);
GUI_MANAGE_TITLE = getString("gui.manage-title", GUI_MANAGE_TITLE); GUI_MANAGE_TITLE = getString("gui.manage-title", GUI_MANAGE_TITLE);
@@ -4,29 +4,21 @@ import com.alttd.playershops.shop.PlayerShop;
import com.alttd.playershops.shop.ShopType; import com.alttd.playershops.shop.ShopType;
import com.alttd.playershops.utils.EconomyUtils; import com.alttd.playershops.utils.EconomyUtils;
import com.alttd.playershops.utils.ShopUtil; import com.alttd.playershops.utils.ShopUtil;
import com.alttd.playershops.utils.Util;
import io.papermc.paper.dialog.Dialog; import io.papermc.paper.dialog.Dialog;
import io.papermc.paper.registry.data.dialog.ActionButton; import io.papermc.paper.registry.data.dialog.ActionButton;
import io.papermc.paper.registry.data.dialog.DialogBase; import io.papermc.paper.registry.data.dialog.DialogBase;
import io.papermc.paper.registry.data.dialog.action.DialogAction; import io.papermc.paper.registry.data.dialog.action.DialogAction;
import io.papermc.paper.registry.data.dialog.body.DialogBody;
import io.papermc.paper.registry.data.dialog.input.DialogInput; import io.papermc.paper.registry.data.dialog.input.DialogInput;
import io.papermc.paper.registry.data.dialog.input.SingleOptionDialogInput; import io.papermc.paper.registry.data.dialog.input.SingleOptionDialogInput;
import io.papermc.paper.registry.data.dialog.type.DialogType; import io.papermc.paper.registry.data.dialog.type.DialogType;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickCallback; import net.kyori.adventure.text.event.ClickCallback;
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 org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.time.Duration; import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class ManageShopDialog extends AbstractDialog { public class ManageShopDialog extends AbstractDialog {
@@ -85,9 +77,6 @@ public class ManageShopDialog extends AbstractDialog {
.initial(false) .initial(false)
.build() .build()
); );
inputs.add(
DialogInput.singleOption("item", MiniMessage.miniMessage().deserialize("<gold>Item</gold>"), itemEntries()).build()
);
int maxQty = (shop.isInitialized() && shop.getItemStack() != null ? shop.getItemStack().getMaxStackSize() : 64); int maxQty = (shop.isInitialized() && shop.getItemStack() != null ? shop.getItemStack().getMaxStackSize() : 64);
int initialQty = (shop.isInitialized() ? Math.min(shop.getAmount(), maxQty) : 1); int initialQty = (shop.isInitialized() ? Math.min(shop.getAmount(), maxQty) : 1);
inputs.add( inputs.add(
@@ -148,19 +137,21 @@ public class ManageShopDialog extends AbstractDialog {
// Change Item // Change Item
if (Boolean.TRUE.equals(view.getBoolean("changeitem"))) { if (Boolean.TRUE.equals(view.getBoolean("changeitem"))) {
String selection = view.getText("item"); ItemStack itemStack = player.getInventory().getItemInMainHand().clone();
if (selection != null) { shop.setItemStack(itemStack);
if (selection.equalsIgnoreCase("reset")) { // String selection = view.getText("item");
shop.setItemStack(null); // if (selection != null) {
} else { // if (selection.equalsIgnoreCase("reset")) {
int slot; // shop.setItemStack(null);
try { // } else {
slot = Integer.parseInt(selection); // int slot;
shop.setItemStack(player.getInventory().getItem(slot)); // try {
} catch (NumberFormatException ignored) { // slot = Integer.parseInt(selection);
} // shop.setItemStack(player.getInventory().getItem(slot));
} // } catch (NumberFormatException ignored) {
} // }
// }
// }
} }
// Change Amount // Change Amount
@@ -188,27 +179,27 @@ public class ManageShopDialog extends AbstractDialog {
actions.add(saveButton); actions.add(saveButton);
} }
List<SingleOptionDialogInput.OptionEntry> itemEntries() { // List<SingleOptionDialogInput.OptionEntry> itemEntries() {
List<SingleOptionDialogInput.OptionEntry> optionEntries = new ArrayList<>(); // List<SingleOptionDialogInput.OptionEntry> optionEntries = new ArrayList<>();
//
if (getPlayer() == null) { // if (getPlayer() == null) {
return optionEntries; // return optionEntries;
} // }
//
optionEntries.add( // optionEntries.add(
SingleOptionDialogInput.OptionEntry.create("reset", MiniMessage.miniMessage().deserialize("<gold>Reset"), false) // SingleOptionDialogInput.OptionEntry.create("reset", MiniMessage.miniMessage().deserialize("<gold>Reset"), false)
); // );
//
for (int i = 0; i < getPlayer().getInventory().getSize() ; i++) { // for (int i = 0; i < getPlayer().getInventory().getSize() ; i++) {
ItemStack item = getPlayer().getInventory().getItem(i); // ItemStack item = getPlayer().getInventory().getItem(i);
if (item == null || item.getType() == Material.AIR) continue; // if (item == null || item.getType() == Material.AIR) continue;
ItemStack itemStack = item.clone(); // ItemStack itemStack = item.clone();
optionEntries.add( // optionEntries.add(
SingleOptionDialogInput.OptionEntry.create(String.valueOf(i), ShopUtil.spriteComponent(itemStack), shop.getItemStack() == itemStack) // SingleOptionDialogInput.OptionEntry.create(String.valueOf(i), ShopUtil.spriteComponent(itemStack), shop.getItemStack() == itemStack)
); // );
} // }
//
return optionEntries; // return optionEntries;
} // }
} }
@@ -44,7 +44,7 @@ public class SearchShopsDialog extends AbstractDialog {
closeButton, closeButton,
5) 5)
) )
.base(DialogBase.builder(MiniMessage.miniMessage().deserialize(MessageConfig.GUI_LIST_SHOPS_TITLE)) .base(DialogBase.builder(MiniMessage.miniMessage().deserialize(MessageConfig.GUI_LIST_SHOPS_ITEM_TITLE))
.body(texts) .body(texts)
.inputs(inputs) .inputs(inputs)
.afterAction(DialogBase.DialogAfterAction.CLOSE) .afterAction(DialogBase.DialogAfterAction.CLOSE)
@@ -59,6 +59,11 @@ public class SearchShopsDialog extends AbstractDialog {
for (Map.Entry<Material, List<PlayerShop>> entry : PlayerShops.getInstance().getShopHandler().shopByMaterial().entrySet()) { for (Map.Entry<Material, List<PlayerShop>> entry : PlayerShops.getInstance().getShopHandler().shopByMaterial().entrySet()) {
actions.add(ActionButton.builder(ShopUtil.spriteComponent(entry.getKey())) actions.add(ActionButton.builder(ShopUtil.spriteComponent(entry.getKey()))
.tooltip(
MiniMessage.miniMessage().deserialize(
entry.getValue().size() + "<green> Shops"
)
)
.action( .action(
DialogAction.customClick((view, audience) -> { DialogAction.customClick((view, audience) -> {
if (!(audience instanceof Player player)) { if (!(audience instanceof Player player)) {
@@ -210,7 +210,7 @@ public class ShopHandler {
* @return TreeMap containing a list of PlayerShops per material. * @return TreeMap containing a list of PlayerShops per material.
*/ */
public TreeMap<Material, List<PlayerShop>> shopByMaterial() { public TreeMap<Material, List<PlayerShop>> shopByMaterial() {
// TODO -- make this a cache. update cache on change, do not calc dynamicly // TODO -- make this a cache. update cache on change, do not calc dynamically
TreeMap<Material, List<PlayerShop>> shopByMaterialTreeSet = new TreeMap<>(); TreeMap<Material, List<PlayerShop>> shopByMaterialTreeSet = new TreeMap<>();
for (PlayerShop shop : getShops()) { for (PlayerShop shop : getShops()) {
@@ -218,7 +218,7 @@ public class ShopHandler {
continue; continue;
} }
Material material = shop.getItemStack().getType(); Material material = shop.getShopItemType();
List<PlayerShop> shopList = shopByMaterialTreeSet.computeIfAbsent(material, v -> new ArrayList<>()); List<PlayerShop> shopList = shopByMaterialTreeSet.computeIfAbsent(material, v -> new ArrayList<>());
shopList.add(shop); shopList.add(shop);
} }
@@ -148,9 +148,10 @@ public class PlayerShop {
} }
public Inventory getInventory() { public Inventory getInventory() {
// Could use a check if the block is still an InventoryHolder. if (shopLocation.getBlock().getState() instanceof InventoryHolder inventoryHolder) {
InventoryHolder container = (InventoryHolder) shopLocation.getBlock().getState(); return inventoryHolder.getInventory();
return container.getInventory(); }
return null;
} }
public boolean isInitialized() { public boolean isInitialized() {
@@ -432,12 +433,15 @@ public class PlayerShop {
} }
public ItemStack getItemStack() { public ItemStack getItemStack() {
if (!isInitialized()) if (!isInitialized()) {
return null; return null;
if (this.getType() != ShopType.RANDOM) }
if (this.getType() != ShopType.RANDOM) {
return itemStack; return itemStack;
if (this.getInventory().isEmpty()) }
if (this.getInventory() == null) {
return null; return null;
}
ArrayList<ItemStack> contents = new ArrayList<>(); ArrayList<ItemStack> contents = new ArrayList<>();
for (ItemStack it : this.getInventory().getContents()) { for (ItemStack it : this.getInventory().getContents()) {
if (it != null) { if (it != null) {
@@ -468,11 +472,13 @@ public class PlayerShop {
Component component = ShopUtil.itemNameComponent(getItemStack()) Component component = ShopUtil.itemNameComponent(getItemStack())
.append(Component.newline()) .append(Component.newline())
.append(Component.newline()) .append(Component.newline())
.append(Component.text("ShopOwner: " + getOwnerName()))
.append(Component.newline())
.append(Component.text("ShopType: " + type)) .append(Component.text("ShopType: " + type))
.append(Component.newline()) .append(Component.newline())
.append(Component.text("Price: " + price)) .append(Component.text("Price: " + price))
.append(Component.newline()) .append(Component.newline())
.append(Component.text("ShopType: " + amount)) .append(Component.text("Amount: " + amount))
.append(Component.newline()) .append(Component.newline())
.append(Component.text("World: " + shopLocation.getWorld().getName())) .append(Component.text("World: " + shopLocation.getWorld().getName()))
.append(Component.newline()) .append(Component.newline())
@@ -484,4 +490,11 @@ public class PlayerShop {
return component; return component;
} }
public Material getShopItemType() {
if (this.type == ShopType.RANDOM) {
return Material.STRUCTURE_VOID; // TODO -- Load from config
}
return itemStack.getType();
}
} }
@@ -109,17 +109,20 @@ public class InventoryUtils {
if (itemStack.getAmount() <= 0) if (itemStack.getAmount() <= 0)
return true; return true;
int overflow = addItem(inventory, itemStack); int remaining = itemStack.getAmount();
//revert back if inventory cannot hold all of the items for (ItemStack stack : inventory.getStorageContents()) {
if (overflow > 0) { if (stack == null || stack.getType().isAir()) {
ItemStack revert = itemStack.clone(); remaining -= itemStack.getMaxStackSize();
revert.setAmount(revert.getAmount() - overflow); } else if (stack.isSimilar(itemStack)) {
InventoryUtils.removeItem(inventory, revert); remaining -= stack.getMaxStackSize() - stack.getAmount();
return false; }
if (remaining <= 0)
return true;
} }
removeItem(inventory, itemStack);
return true; return false;
} }
} }
@@ -209,8 +209,7 @@ public class ItemMatcher {
if (mapView1 == null || mapView2 == null) if (mapView1 == null || mapView2 == null)
return false; return false;
if (mapView1.getId() == mapView2.getId()) return mapView1.getId() == mapView2.getId();
return true;
} }
return true; return true;
} }
@@ -228,13 +227,19 @@ public class ItemMatcher {
matcherList.add( matcherList.add(
(meta1, meta2) -> { (meta1, meta2) -> {
if (meta1 instanceof TropicalFishBucketMeta tropicalFishBucketMeta1 && meta2 instanceof TropicalFishBucketMeta tropicalFishBucketMeta2) { if (meta1 instanceof TropicalFishBucketMeta tropicalFishBucketMeta1 && meta2 instanceof TropicalFishBucketMeta tropicalFishBucketMeta2) {
if (tropicalFishBucketMeta1.hasVariant() != tropicalFishBucketMeta2.hasVariant()) { if (tropicalFishBucketMeta1.hasVariant() && tropicalFishBucketMeta2.hasVariant()) {
return false; if (tropicalFishBucketMeta1.getPattern() != tropicalFishBucketMeta2.getPattern()) {
return false;
}
if (tropicalFishBucketMeta1.getBodyColor() != tropicalFishBucketMeta2.getBodyColor()) {
return false;
}
return tropicalFishBucketMeta1.getPatternColor() == tropicalFishBucketMeta2.getPatternColor();
} }
return !tropicalFishBucketMeta1.hasVariant() // return !tropicalFishBucketMeta1.hasVariant()
|| (tropicalFishBucketMeta1.getPattern() == tropicalFishBucketMeta2.getPattern() // || (tropicalFishBucketMeta1.getPattern() == tropicalFishBucketMeta2.getPattern()
&& tropicalFishBucketMeta1.getBodyColor().equals(tropicalFishBucketMeta2.getBodyColor()) // && tropicalFishBucketMeta1.getBodyColor().equals(tropicalFishBucketMeta2.getBodyColor())
&& tropicalFishBucketMeta1.getPatternColor().equals(tropicalFishBucketMeta2.getPatternColor())); // && tropicalFishBucketMeta1.getPatternColor().equals(tropicalFishBucketMeta2.getPatternColor()));
} }
return true; return true;
} }
@@ -261,8 +266,8 @@ public class ItemMatcher {
return false; // not the same color return false; // not the same color
// Do we need all of the above checks inside the shulker? // Do we need all of the above checks inside the shulker?
if (Arrays.equals(shulkerBox1.getInventory().getContents(), shulkerBox2.getInventory().getContents())) // same content if true
return true; // same content return Arrays.equals(shulkerBox1.getInventory().getContents(), shulkerBox2.getInventory().getContents());
} }
} }
return true; return true;
@@ -290,7 +295,7 @@ public class ItemMatcher {
} }
if (item1 == null || item2 == null) { if (item1 == null || item2 == null) {
return true; return false;
} }
if (!item1.getType().equals(item2.getType())) { if (!item1.getType().equals(item2.getType())) {
@@ -305,7 +310,7 @@ public class ItemMatcher {
return metaMatches(item1, item2); return metaMatches(item1, item2);
} }
return !item1.hasItemMeta() && !item1.hasItemMeta(); return !item1.hasItemMeta() && !item2.hasItemMeta();
} }
protected static boolean metaMatches(ItemStack item1, ItemStack item2) { protected static boolean metaMatches(ItemStack item1, ItemStack item2) {