diff --git a/api/src/main/java/us/crazycrew/crazycrates/platform/IServer.java b/api/src/main/java/us/crazycrew/crazycrates/platform/IServer.java index 287252ae4..36b7f3997 100644 --- a/api/src/main/java/us/crazycrew/crazycrates/platform/IServer.java +++ b/api/src/main/java/us/crazycrew/crazycrates/platform/IServer.java @@ -68,11 +68,11 @@ default File getDataFolder() { /** * Gets a list of crate files with the option to keep or remove the extension. * - * @param keepExtension true or false + * @param removeExtension true means remove it, false means keep it * @return {@link List} * @since 0.9.0 */ - List getCrateFiles(final boolean keepExtension); + List getCrateFiles(final boolean removeExtension); /** * Gets a list of crate files without the extension. diff --git a/changelog.md b/changelog.md index e128ddaac..d4353b8bf 100644 --- a/changelog.md +++ b/changelog.md @@ -1,98 +1,15 @@ -## Changes 🔨 -### New API -CrazyCrates API has been bumped to 0.9.0 - -#### A new class has been added. -Key Manager class, which allows you to check Items that players are holding. - -You can fetch this by doing CratesProvider#get()#getKeyManager() - -```java -/** - * A class for the KeyManager, It handles checking physical keys, and anything else we might need soon. - * - * @author Ryder Belserion - * @version 0.9.0 - * @since 0.9.0 - */ -public abstract class KeyManager { - - /** - * The default constructor for {@link KeyManager}. - * - * @author Ryder Belserion - * @since 0.9.0 - */ - public KeyManager() {} - - /** - * Checks if the item is a valid key. - * - * @param item the ItemStack - * @return true or false - * @since 0.9.0 - */ - public abstract boolean isKey(@NotNull final I item); - - /** - * Checks if an item matches another item. - * - * @param item the initial ItemStack - * @param comparing the ItemStack to compare - * @return true or false - * @since 0.9.0 - */ - public abstract boolean isMatchingKey(@NotNull final I item, @NotNull final I comparing); - - /** - * Gets the name of the crate the key belongs to. - * - * @param item the ItemStack - * @return the name of the crate - * @since 0.9.0 - */ - public abstract String getKey(@NotNull final I item); - -} -``` - -### Configuration changes -- `ChestLines` has been renamed to `Rows` in the crate config files, [5eec53b](https://github.com/Crazy-Crew/CrazyCrates/commit/5eec53b) - - All existing configurations should continue to work, You can run `/crazyrates migrate -mt CratesDeprecated` to change this, or simply use Find and Replace. - -### Other Changes -- Added the ability to customize the row/column of the back/next and menu button. -- Added the ability to customize the CSGO animation to either have the top/bottom be static or dynamic. [95de51e](https://github.com/Crazy-Crew/CrazyCrates/commit/95de41e) - - If you run /crazycrates migrate -mt CratesDeprecated, The existing options you need will generate. - - Please refer to the `examples/crates/CrateExample.yml` folder for a full example of how to do it. - - It supports the same structure as the new way to do items in the `Items` section which can be found on the documentation. -- Run the command on click in the Crate Menu, instead of on open. - - [6c580b1](https://github.com/Crazy-Crew/CrazyCrates/commit/6c580b1) -- Added %chance% / %weight% to the prize/default message. -- Added command syntax suggestions to all existing commands. -- Return "N/A" if the file is empty, because files#getFirst() throws an error because no element found. -- Utilize built in methods from CMI/DecentHolograms to handle coloring the messages for better compatibility with their plugins. - - This will maybe also allow other plugin specific features like CMI's countless other features for holograms. -- Remove the brackets from custom name for the item displayed above QuickCrate. -- Fill the bottom border with air to prevent item overfill with the buttons. -- Added toggle to disable opening tracking crate. - - [76625ba](https://github.com/Crazy-Crew/CrazyCrates/commit/76625ba961367be51a75fc907faa75ad87676b79) - -## Bugs Fixed 🐛 -- Fixed an error with WonderCrate.yml on first install, because a prize was lacking an `Items` section. -- Fixed a potential memory leak caused by using double brace initializers. -- Fixed multiple bugs with PlaceholderAPI support. -- Fixed a typo in CosmicCrateManager. [#873](https://github.com/Crazy-Crew/CrazyCrates/commit/876f3a7) -- Fixed a typo with %crate_opened_raw%. - - [1ef6553](https://github.com/Crazy-Crew/CrazyCrates/commit/1ef6553) -- Fixed an issue with items dropping on Folia. [#856](https://github.com/Crazy-Crew/CrazyCrates/pull/856) -- Fixed an issue by using #runNow instead of #run which calls the internal void method. -- Fixed multiple issues with migration types. -- Fixed multiple issues on Folia due to not using schedulers when needed. - - [0e139f6](https://github.com/Crazy-Crew/CrazyCrates/commit/0e139f6) -- Fixed an issue with potion color not applying with the new items section. -- Fixed an issue with the shield banners using the new item format. -- Fixed an issue with the tier chance per prize not properly showing. -- Fixed crates debug command. - -As always, Report 🐛 to https://github.com/Crazy-Crew/CrazyCrates/issues +## Changes +- Updated the remaining default internal placeholders to be wrapped in {} instead of %%, The previous placeholders using %% will still work. +- Removed all `HideItemFlag` options as we provide the ability to set Item Models which achieve the same result! +- Updated, and improved the migration types. +- Removed all old usage of the Legacy ItemBuilder. +- Removed the ability to create a Spawner with an entity type, It no longer worked. and Mojang provides a perfectly good command to create spawners. +- Removed unnecessary code that picked a prize 2,000+ times after it was already picked. + +## Bug Fixed +- Fixed a bug where enchant levels were not being migrated properly. + +## Configuration Changes +- Updated configuration for item displayed in /crates. You must run /crazycrates migrate -mt CratesDeprecated. +- `use-different-items-layout` if on a fresh install, is now true out of the box. + - The old `Items` section is now considered stale, receives no new updates, and will likely be removed. diff --git a/gradlew.bat b/gradlew.bat old mode 100755 new mode 100644 index e509b2dd8..c4bdd3ab8 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,93 +1,93 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem -@rem SPDX-License-Identifier: Apache-2.0 -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:execute -@rem Setup the command line - - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/paper/src/main/java/com/badbones69/crazycrates/core/Server.java b/paper/src/main/java/com/badbones69/crazycrates/core/Server.java index 8358c0b54..7ec04d238 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/core/Server.java +++ b/paper/src/main/java/com/badbones69/crazycrates/core/Server.java @@ -1,7 +1,9 @@ package com.badbones69.crazycrates.core; import com.badbones69.crazycrates.core.impl.Settings; -import com.ryderbelserion.fusion.core.api.utils.FileUtils; +import com.ryderbelserion.fusion.core.FusionProvider; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.files.PaperFileManager; import org.jetbrains.annotations.NotNull; import us.crazycrew.crazycrates.CratesProvider; import us.crazycrew.crazycrates.api.KeyManager; @@ -14,6 +16,10 @@ public class Server implements IServer { + private final FusionPaper fusion = (FusionPaper) FusionProvider.getInstance(); + + private final PaperFileManager fileManager = this.fusion.getFileManager(); + private final Path path; private final Path crates; @@ -66,8 +72,8 @@ public void reload() { } @Override - public @NotNull final List getCrateFiles(boolean keepExtension) { - return keepExtension ? FileUtils.getNamesByExtension("crates", this.path, ".yml") : FileUtils.getNamesWithoutExtension("crates", this.path, ".yml"); + public @NotNull final List getCrateFiles(final boolean removeExtension) { + return this.fileManager.getFileNames("crates", this.path, ".yml", removeExtension); } @Override diff --git a/paper/src/main/java/com/badbones69/crazycrates/core/config/impl/ConfigKeys.java b/paper/src/main/java/com/badbones69/crazycrates/core/config/impl/ConfigKeys.java index 230e789a5..eaa83bd65 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/core/config/impl/ConfigKeys.java +++ b/paper/src/main/java/com/badbones69/crazycrates/core/config/impl/ConfigKeys.java @@ -74,7 +74,7 @@ public void registerComments(CommentsConfiguration conf) { "", "Take a backup before you run the migration as there may be bugs." }) - public static final Property use_different_items_layout = newProperty("root.use-different-items-layout", false); + public static final Property use_different_items_layout = newProperty("root.use-different-items-layout", true); @Comment("Sends anonymous statistics to https://bstats.org/plugin/bukkit/CrazyCrates/4514") public static final Property toggle_metrics = newProperty("root.toggle-metrics", true); diff --git a/paper/src/main/java/com/badbones69/crazycrates/core/constants/PluginSupport.java b/paper/src/main/java/com/badbones69/crazycrates/core/constants/PluginSupport.java new file mode 100644 index 000000000..beb03b1f9 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazycrates/core/constants/PluginSupport.java @@ -0,0 +1,19 @@ +package com.badbones69.crazycrates.core.constants; + +import com.ryderbelserion.fusion.core.FusionKey; +import java.util.List; + +public class PluginSupport { + + public static final FusionKey decent_holograms = FusionKey.key("crazycrates", "DecentHolograms"); + + public static final FusionKey fancy_holograms = FusionKey.key("crazycrates", "FancyHolograms"); + + public static final FusionKey cmi = FusionKey.key("crazycrates", "CMI"); + + public static final List dependencies = List.of( + decent_holograms, + fancy_holograms, + cmi + ); +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/core/enums/Comments.java b/paper/src/main/java/com/badbones69/crazycrates/core/enums/Comments.java index 1ad523f6b..fe8e2b2c1 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/core/enums/Comments.java +++ b/paper/src/main/java/com/badbones69/crazycrates/core/enums/Comments.java @@ -20,7 +20,8 @@ public enum Comments { "The damage to apply to the item." )), glowing(List.of( - "Should the item glow?" + "Available Types: add_glow, remove_glow, or none.", + "None, or blank value means no state will be applied." )), amount(List.of( "The amount of the item to give." @@ -67,7 +68,7 @@ public enum Comments { )), enchantments(List.of( "The configuration section for enchantments, minecraft: is not needed in front of the enchantment.", - "A list of enchantments https://jd.papermc.io/paper/1.21.4/io/papermc/paper/registry/keys/EnchantmentKeys.html", + "A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html", "enchantment: amount" )), potions(List.of( diff --git a/paper/src/main/java/com/badbones69/crazycrates/core/enums/Property.java b/paper/src/main/java/com/badbones69/crazycrates/core/enums/Property.java index 8e8ef8d48..f60042eaf 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/core/enums/Property.java +++ b/paper/src/main/java/com/badbones69/crazycrates/core/enums/Property.java @@ -8,8 +8,12 @@ import com.badbones69.crazycrates.core.config.impl.messages.ErrorKeys; import com.badbones69.crazycrates.core.config.impl.messages.MiscKeys; import com.badbones69.crazycrates.core.config.impl.messages.PlayerKeys; +import com.badbones69.crazycrates.paper.CrazyCrates; +import com.ryderbelserion.fusion.paper.FusionPaper; + import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import static ch.jalu.configme.properties.PropertyInitializer.newListProperty; import static ch.jalu.configme.properties.PropertyInitializer.newProperty; @@ -123,6 +127,10 @@ public enum Property { help(CommandKeys.help, newListProperty("Messages.Help", CommandKeys.help.getDefaultValue()), Collections.emptyList()), admin_help(CommandKeys.admin_help, newListProperty("Messages.Admin-Help", CommandKeys.admin_help.getDefaultValue()), Collections.emptyList()); + private final CrazyCrates plugin = CrazyCrates.getPlugin(); + + private final FusionPaper fusion = this.plugin.getFusion(); + private ch.jalu.configme.properties.Property newString; private ch.jalu.configme.properties.Property oldString; @@ -260,14 +268,18 @@ public boolean moveList(PropertyReader reader, ConfigurationData configuration) List list = new ArrayList<>(); if (this.oldList.getPath().equalsIgnoreCase("Settings.GUI-Customizer")) { - this.oldList.determineValue(reader).getValue().forEach(line -> list.add(line.replaceAll("Item:", "item:") - .replaceAll("Slot:", "slot:") - .replaceAll("Name:", "name:") - .replaceAll("Lore:", "lore:") - .replaceAll("Glowing:", "glowing:") - .replaceAll("Player:", "player:") - .replaceAll("Unbreakable-Item", "unbreakable_item:") - .replaceAll("Hide-Item-Flags", "hide_item_flags:"))); + this.oldList.determineValue(reader).getValue().forEach(line -> { + list.add(this.fusion.replacePlaceholder(line, new HashMap<>() {{ + put("Item:", "item:"); + put("Slot:", "slot:"); + put("Name:", "name:"); + put("Lore:", "lore:"); + put("Glowing:", "glowing:"); + put("Player:", "player:"); + put("Unbreakable-Item:", "unbreakable_item:"); + put("Hide-Item-Flags:", "hide_item_flags:"); + }})); + }); } else { this.oldList.determineValue(reader).getValue().forEach(line -> list.add(replace(line))); } @@ -284,21 +296,23 @@ public boolean moveList(PropertyReader reader, ConfigurationData configuration) * @return the finalized message to set */ private String replace(String message) { - return message.replaceAll("%page%", "{page}") - .replaceAll("%prefix%", "{prefix}") - .replaceAll("%world%", "{world}") - .replaceAll("%crate%", "{crate}") - .replaceAll("%key%", "{key}") - .replaceAll("%keys%", "{keys}") - .replaceAll("%cratetype%", "{cratetype}") - .replaceAll("%player%", "{player}") - .replaceAll("%prize%", "{prize}") - .replaceAll("%number%", "{number}") - .replaceAll("%keytype%", "{keytype}") - .replaceAll("%usage%", "{usage}") - .replaceAll("%key-amount%", "{key_amount}") - .replaceAll("%amount%", "{amount}") - .replaceAll("%id%", "{id}") - .replaceAll("%crates_opened%", "{crates_opened}"); + return this.fusion.replacePlaceholder(message, new HashMap<>() {{ + put("%page%", "{page}"); + put("%prefix%", "{prefix}"); + put("%world%", "{world}"); + put("%crate%", "{crate}"); + put("%key%", "{key}"); + put("%keys%", "{keys}"); + put("%cratetype%", "{cratetype}"); + put("%player%", "{player}"); + put("%prize%", "{prize}"); + put("%number%", "{number}"); + put("%keytype%", "{keytype}"); + put("%usage%", "{usage}"); + put("%key-amount%", "{key_amount}"); + put("%amount%", "{amount}"); + put("%id%", "{id}"); + put("%crates_opened%", "{crates_opened}"); + }}); } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/CrazyCrates.java b/paper/src/main/java/com/badbones69/crazycrates/paper/CrazyCrates.java index cbe2cf113..5383c3960 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/CrazyCrates.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/CrazyCrates.java @@ -1,9 +1,9 @@ package com.badbones69.crazycrates.paper; -import com.badbones69.crazycrates.paper.api.enums.other.Plugins; import com.badbones69.crazycrates.core.Server; import com.badbones69.crazycrates.core.config.ConfigManager; import com.badbones69.crazycrates.core.config.impl.ConfigKeys; +import com.badbones69.crazycrates.core.constants.PluginSupport; import com.badbones69.crazycrates.paper.listeners.crates.CrateInteractListener; import com.badbones69.crazycrates.paper.listeners.items.PaperInteractListener; import com.badbones69.crazycrates.paper.managers.BukkitKeyManager; @@ -24,16 +24,15 @@ import com.badbones69.crazycrates.paper.managers.BukkitUserManager; import com.badbones69.crazycrates.paper.managers.InventoryManager; import com.badbones69.crazycrates.paper.tasks.crates.CrateManager; -import com.ryderbelserion.fusion.core.api.enums.FileAction; -import com.ryderbelserion.fusion.core.api.enums.FileType; -import com.ryderbelserion.fusion.core.api.utils.AdvUtils; +import com.ryderbelserion.fusion.files.enums.FileType; +import com.ryderbelserion.fusion.kyori.mods.ModManager; +import com.ryderbelserion.fusion.kyori.mods.ModSupport; +import com.ryderbelserion.fusion.kyori.mods.objects.Mod; import com.ryderbelserion.fusion.paper.FusionPaper; -import com.ryderbelserion.fusion.paper.files.FileManager; -import net.kyori.adventure.text.logger.slf4j.ComponentLogger; +import com.ryderbelserion.fusion.paper.files.PaperFileManager; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import java.nio.file.Path; -import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Timer; @@ -65,12 +64,16 @@ public CrazyCrates() { private MetricsWrapper metrics; - private FileManager fileManager; + private PaperFileManager fileManager; @Override public void onEnable() { - this.fusion = new FusionPaper(getComponentLogger(), getDataPath()); - this.fusion.enable(this); + this.fusion = new FusionPaper(this); + this.fusion.init(); + + final ModManager modManager = this.fusion.getModManager(); + + PluginSupport.dependencies.forEach(dependency -> modManager.addMod(dependency, new Mod(this.fusion))); this.fileManager = this.fusion.getFileManager(); @@ -79,25 +82,14 @@ public void onEnable() { this.instance = new Server(path); this.instance.apply(); - this.fileManager.refresh(false).addFile(path.resolve("locations.yml"), FileType.PAPER, List.of( - FileAction.STATIC_FILE - ), null) - .addFile(path.resolve("data.yml"), FileType.PAPER, List.of( - FileAction.STATIC_FILE - ), null) - .addFile(path.resolve("guis").resolve("respin-gui.yml"), FileType.PAPER, List.of( - FileAction.STATIC_FILE - ), null) - .addFolder(path.resolve("logs"), FileType.LOG, List.of( - FileAction.EXTRACT_FOLDER, - FileAction.STATIC_FILE - ), null) - .addFolder(path.resolve("crates"), FileType.PAPER, List.of( - FileAction.EXTRACT_FOLDER - ), null) - .addFolder(path.resolve("schematics"), FileType.NBT, List.of( - FileAction.EXTRACT_FOLDER - ), null); + this.fileManager.extractFolder("guis", path); + + this.fileManager.addPaperFile(path.resolve("locations.yml")) + .addPaperFile(path.resolve("data.yml")) + .addPaperFile(path.resolve("guis").resolve("respin-gui.yml")) + .addPaperFolder(path.resolve("crates")) + .addFolder(path.resolve("schematics"), FileType.NBT) + .addFolder(path.resolve("logs"), FileType.LOG); MiscUtils.janitor(); MiscUtils.save(); @@ -124,7 +116,7 @@ public void onEnable() { this.crateManager.loadCrates(); if (ConfigManager.getConfig().getProperty(ConfigKeys.toggle_metrics)) { - this.metrics = new MetricsWrapper(4514); + this.metrics = new MetricsWrapper(this, 4514); this.metrics.start(); } @@ -152,26 +144,13 @@ public void onEnable() { this.crateManager.loadCustomItems(); - if (Plugins.placeholder_api.isEnabled()) { - if (MiscUtils.isLogging()) getComponentLogger().info("PlaceholderAPI support is enabled!"); + if (this.fusion.isModReady(ModSupport.placeholder_api)) { + this.fusion.log("warn", "PlaceholderAPI support is enabled!"); new PlaceholderAPISupport().register(); } - if (MiscUtils.isLogging()) { - final ComponentLogger logger = getComponentLogger(); - - // Print dependency garbage - for (final Plugins value : Plugins.values()) { - if (value.isEnabled()) { - logger.info(AdvUtils.parse("" + value.getName() + " FOUND")); - } else { - logger.info(AdvUtils.parse("" + value.getName() + " NOT FOUND")); - } - } - - logger.info("Done ({})!", String.format(Locale.ROOT, "%.3fs", (double) (System.nanoTime() - this.startTime) / 1.0E9D)); - } + this.fusion.log("info", "Done ({})", String.format(Locale.ROOT, "%.3fs", (double) (System.nanoTime() - this.startTime) / 1.0E9D)); } @Override @@ -223,7 +202,7 @@ public final CrateManager getCrateManager() { return this.crateManager; } - public final FileManager getFileManager() { + public final PaperFileManager getFileManager() { return this.fileManager; } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/ChestManager.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/ChestManager.java index 90e837e6d..c8a48d71a 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/ChestManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/ChestManager.java @@ -1,11 +1,7 @@ package com.badbones69.crazycrates.paper.api; import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.block.Chest; -import org.bukkit.block.EnderChest; +import org.bukkit.block.*; import org.bukkit.block.data.Directional; import org.jetbrains.annotations.NotNull; @@ -18,19 +14,19 @@ public static void openChest(@NotNull final Block block, final boolean forceUpda switch (block.getType()) { case ENDER_CHEST -> { - final EnderChest enderChest = (EnderChest) blockState; + if (blockState instanceof EnderChest enderChest) { + if (!enderChest.isOpen()) enderChest.open(); - if (!enderChest.isOpen()) enderChest.open(); - - blockState.update(forceUpdate); + blockState.update(forceUpdate); + } } case CHEST, TRAPPED_CHEST -> { - final Chest chest = (Chest) blockState; - - if (!chest.isOpen()) chest.open(); + if (blockState instanceof Chest chest) { + if (!chest.isOpen()) chest.open(); - blockState.update(forceUpdate); + blockState.update(forceUpdate); + } } } } @@ -42,22 +38,22 @@ public static void closeChest(@NotNull final Block block, final boolean forceUpd switch (block.getType()) { case ENDER_CHEST -> { - final EnderChest enderChest = (EnderChest) blockState; - - if (enderChest.isOpen()) { - enderChest.close(); + if (blockState instanceof EnderChest enderChest) { + if (enderChest.isOpen()) { + enderChest.close(); - blockState.update(forceUpdate); + blockState.update(forceUpdate); + } } } case CHEST, TRAPPED_CHEST -> { - final Chest chest = (Chest) blockState; - - if (chest.isOpen()) { - chest.close(); + if (blockState instanceof Chest chest) { + if (chest.isOpen()) { + chest.close(); - blockState.update(forceUpdate); + blockState.update(forceUpdate); + } } } } @@ -94,15 +90,15 @@ public static boolean isChestOpen(@NotNull final Block block) { switch (block.getType()) { case ENDER_CHEST -> { - final EnderChest enderChest = (EnderChest) blockState; - - isOpen = enderChest.isOpen(); + if (blockState instanceof EnderChest enderChest) { + isOpen = enderChest.isOpen(); + } } case CHEST, TRAPPED_CHEST -> { - final Chest chest = (Chest) blockState; - - isOpen = chest.isOpen(); + if (blockState instanceof Chest chest) { + isOpen = chest.isOpen(); + } } } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/PlayerBuilder.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/PlayerBuilder.java deleted file mode 100644 index 9718c22a4..000000000 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/PlayerBuilder.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.badbones69.crazycrates.paper.api; - -import com.badbones69.crazycrates.paper.CrazyCrates; -import org.bukkit.OfflinePlayer; -import org.bukkit.Server; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.Nullable; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; - -public record PlayerBuilder(String name) { - - private static final CrazyCrates plugin = CrazyCrates.getPlugin(); - private static final Server server = plugin.getServer(); - - /** - * Gets the {@link OfflinePlayer}. - * - * @return {@link OfflinePlayer} - * @since 0.0.1 - */ - public @Nullable OfflinePlayer getOfflinePlayer() { - if (this.name.isEmpty()) return null; - - CompletableFuture future = CompletableFuture.supplyAsync(() -> server.getOfflinePlayer(this.name)).thenApply(OfflinePlayer::getUniqueId); - - return server.getOfflinePlayer(future.join()); - } - - /** - * Gets the {@link Player}. - * - * @return {@link Player} - * @since 0.0.1 - */ - public @Nullable Player getPlayer() { - if (this.name.isEmpty()) return null; - - return server.getPlayerExact(this.name); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/PrizeManager.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/PrizeManager.java index 2bb022342..e173d739a 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/PrizeManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/PrizeManager.java @@ -1,10 +1,6 @@ package com.badbones69.crazycrates.paper.api; -import ch.jalu.configme.SettingsManager; -import com.badbones69.crazycrates.core.config.ConfigManager; -import com.badbones69.crazycrates.core.config.impl.ConfigKeys; import com.badbones69.crazycrates.paper.api.enums.Messages; -import com.badbones69.crazycrates.paper.api.enums.other.Plugins; import com.badbones69.crazycrates.paper.api.enums.other.keys.FileKeys; import com.badbones69.crazycrates.paper.api.objects.Tier; import com.badbones69.crazycrates.paper.CrazyCrates; @@ -12,9 +8,9 @@ import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.api.objects.Prize; import com.badbones69.crazycrates.paper.managers.BukkitUserManager; -import com.ryderbelserion.fusion.core.api.utils.StringUtils; -import me.clip.placeholderapi.PlaceholderAPI; -import net.kyori.adventure.text.logger.slf4j.ComponentLogger; +import com.badbones69.crazycrates.paper.utils.CommandUtils; +import com.ryderbelserion.fusion.core.utils.StringUtils; +import com.ryderbelserion.fusion.paper.FusionPaper; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.configuration.ConfigurationSection; @@ -29,20 +25,18 @@ import com.badbones69.crazycrates.paper.utils.MsgUtils; import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.HashMap; import java.util.Map; import java.util.Random; -import static java.util.regex.Matcher.quoteReplacement; public class PrizeManager { private static final CrazyCrates plugin = CrazyCrates.getPlugin(); + private static final FusionPaper fusion = plugin.getFusion(); private static final Server server = plugin.getServer(); private static final PluginManager pluginManager = server.getPluginManager(); - private static final ComponentLogger logger = plugin.getComponentLogger(); private static final BukkitUserManager userManager = plugin.getUserManager(); - private static final SettingsManager config = ConfigManager.getConfig(); - public static int getCap(@NotNull final Crate crate, @NotNull final Player player) { final String format = "crazycrates.respin." + crate.getFileName() + "."; final String lowerCase = format.toLowerCase(); @@ -133,7 +127,7 @@ public static void givePrize(@NotNull final Player player, @NotNull final Crate */ public static void givePrize(@NotNull final Player player, @NotNull final Location location, @NotNull final Crate crate, @Nullable Prize prize) { if (prize == null) { - if (MiscUtils.isLogging()) logger.warn("No prize was found when giving {} a prize.", player.getName()); + fusion.log("warn", "No prize was found when giving {} a prize.", player.getName()); return; } @@ -161,11 +155,7 @@ public static void givePrize(@NotNull final Player player, @NotNull final Locati MiscUtils.dropItems(prize.getEditorItems(), player); // drops any leftover editor items. - if (config.getProperty(ConfigKeys.use_different_items_layout)) { - MiscUtils.dropBuilders(prize.getItems(), player); - } else { - MiscUtils.dropLegacyBuilders(prize.getItemBuilders(), player); - } + MiscUtils.dropBuilders(prize.getItems(), player); for (final String command : crate.getPrizeCommands()) { runCommands(player, prize, crate, command); @@ -193,52 +183,47 @@ public static void givePrize(@NotNull final Player player, @NotNull final Locati } } - private static void runCommands(@NotNull final Player player, @NotNull final Prize prize, @NotNull final Crate crate, @NotNull String command) { - String cmd = command; + private static void runCommands(@NotNull final Player player, @NotNull final Prize prize, @NotNull final Crate crate, @NotNull final String command) { + final String value = MsgUtils.getRandomNumber(command); - if (cmd.contains("%random%:")) { - final StringBuilder commandBuilder = new StringBuilder(); + final String maxPulls = String.valueOf(prize.getMaxPulls()); + final String pulls = String.valueOf(getCurrentPulls(prize, crate)); + final String playerName = player.getName(); + final String fancyName = crate.getCrateName(); + final String crateName = crate.getFileName(); - for (String word : cmd.split(" ")) { - if (word.startsWith("%random%:")) {// /give %player% iron %random%:1-64 - word = word.replace("%random%:", ""); + final String chance = StringUtils.format(crate.getChance(prize.getWeight())); + final String weight = String.valueOf(prize.getWeight()); - try { - long min = Long.parseLong(word.split("-")[0]); - long max = Long.parseLong(word.split("-")[1]); + final Map placeholders = new HashMap<>(); - commandBuilder.append(MiscUtils.pickNumber(min, max)).append(" "); - } catch (final Exception exception) { - commandBuilder.append("1 "); + placeholders.put("%player%", playerName); + placeholders.put("%crate_fancy%", fancyName); + placeholders.put("%crate%", crateName); + placeholders.put("%maxpulls%", maxPulls); + placeholders.put("%pulls%", pulls); + placeholders.put("%chance%", chance); + placeholders.put("%weight%", weight); - if (MiscUtils.isLogging()) { - logger.warn("The prize {} in the {} crate has caused an error when trying to run a command.", prize.getPrizeName(), prize.getCrateName()); - logger.warn("Command: {}", cmd); - } - } - } else { - commandBuilder.append(word).append(" "); - } - } + placeholders.put("{player}", playerName); + placeholders.put("{crate_fancy}", fancyName); + placeholders.put("{crate}", crateName); + placeholders.put("{maxpulls}", maxPulls); + placeholders.put("{pulls}", pulls); + placeholders.put("{chance}", chance); + placeholders.put("{weight}", weight); - cmd = commandBuilder.toString(); - cmd = cmd.substring(0, cmd.length() - 1); - } + final String prizeName = fusion.replacePlaceholder(prize.getPrizeName(), placeholders); - if (Plugins.placeholder_api.isEnabled() ) cmd = PlaceholderAPI.setPlaceholders(player, cmd); + final String strippedName = prize.getStrippedName(); - final String maxPulls = String.valueOf(prize.getMaxPulls()); - final String pulls = String.valueOf(getCurrentPulls(prize, crate)); - final String prizeName = prize.getPrizeName().replaceAll("%maxpulls%", maxPulls).replaceAll("%pulls%", pulls); - - MiscUtils.sendCommand(cmd - .replaceAll("%player%", quoteReplacement(player.getName())) - .replaceAll("%reward%", quoteReplacement(prizeName)) - .replaceAll("%reward_stripped%", quoteReplacement(prize.getStrippedName())) - .replaceAll("%crate_fancy%", quoteReplacement(crate.getCrateName())) - .replaceAll("%crate%", quoteReplacement(crate.getFileName())) - .replaceAll("%maxpulls%", maxPulls) - .replaceAll("%pulls%", pulls)); + placeholders.put("%reward_stripped%", strippedName); + placeholders.put("%reward%", prizeName); + + placeholders.put("{reward_stripped}", strippedName); + placeholders.put("{reward}", prizeName); + + CommandUtils.executeCommand(player, value, placeholders); } private static void sendMessage(@NotNull final Player player, @NotNull final Prize prize, @NotNull final Crate crate, @NotNull final String message) { @@ -246,19 +231,42 @@ private static void sendMessage(@NotNull final Player player, @NotNull final Pri final String maxPulls = String.valueOf(prize.getMaxPulls()); final String pulls = String.valueOf(getCurrentPulls(prize, crate)); - final String prizeName = prize.getPrizeName().replaceAll("%maxpulls%", maxPulls).replaceAll("%pulls%", pulls); - - final String defaultMessage = message - .replaceAll("%player%", quoteReplacement(player.getName())) - .replaceAll("%reward%", quoteReplacement(prizeName)) - .replaceAll("%reward_stripped%", quoteReplacement(prize.getStrippedName())) - .replaceAll("%crate%", quoteReplacement(crate.getCrateName())) - .replaceAll("%maxpulls%", maxPulls) - .replaceAll("%pulls%", pulls) - .replaceAll("%chance%", StringUtils.format(crate.getChance(prize.getWeight()))) - .replaceAll("%weight%", String.valueOf(prize.getWeight())); - - MsgUtils.sendMessage(player, Plugins.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(player, defaultMessage) : defaultMessage, false); + final String playerName = player.getName(); + final String fancyName = crate.getCrateName(); + final String crateName = crate.getFileName(); + + final String chance = StringUtils.format(crate.getChance(prize.getWeight())); + final String weight = String.valueOf(prize.getWeight()); + + final Map placeholders = new HashMap<>(); + + placeholders.put("%player%", playerName); + placeholders.put("%crate_fancy%", fancyName); + placeholders.put("%crate%", crateName); + placeholders.put("%maxpulls%", maxPulls); + placeholders.put("%pulls%", pulls); + placeholders.put("%chance%", chance); + placeholders.put("%weight%", weight); + + placeholders.put("{player}", playerName); + placeholders.put("{crate_fancy}", fancyName); + placeholders.put("{crate}", crateName); + placeholders.put("{maxpulls}", maxPulls); + placeholders.put("{pulls}", pulls); + placeholders.put("{chance}", chance); + placeholders.put("{weight}", weight); + + final String prizeName = fusion.replacePlaceholder(prize.getPrizeName(), placeholders); + + final String strippedName = prize.getStrippedName(); + + placeholders.put("%reward_stripped%", strippedName); + placeholders.put("%reward%", prizeName); + + placeholders.put("{reward_stripped}", strippedName); + placeholders.put("{reward}", prizeName); + + player.sendMessage(fusion.parse(player, message, placeholders)); } public static int getCurrentPulls(final Prize prize, final Crate crate) { diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/CrateBuilder.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/CrateBuilder.java index 15cdd5fdd..462ff81a1 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/CrateBuilder.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/CrateBuilder.java @@ -17,8 +17,9 @@ import com.badbones69.crazycrates.paper.tasks.crates.other.CosmicCrateManager; import com.badbones69.crazycrates.paper.tasks.crates.effects.SoundEffect; import com.google.common.base.Preconditions; -import com.ryderbelserion.fusion.core.api.utils.AdvUtils; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import io.papermc.paper.threadedregions.scheduler.ScheduledTask; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; @@ -44,6 +45,8 @@ public abstract class CrateBuilder extends FoliaScheduler { protected final CrazyCrates plugin = CrazyCrates.getPlugin(); + protected final FusionPaper fusion = this.plugin.getFusion(); + protected final ComponentLogger logger = this.plugin.getComponentLogger(); protected final CrateManager crateManager = this.plugin.getCrateManager(); @@ -203,7 +206,7 @@ public void run() { } reward.setVelocity(new Vector(0, 0.2, 0)); - reward.customName(AdvUtils.parse(prize.getPrizeName())); + reward.customName(fusion.parse(player, prize.getPrizeName())); reward.setCustomNameVisible(true); reward.setCanMobPickup(false); reward.setCanPlayerPickup(false); @@ -343,7 +346,7 @@ public void setItem(final int slot, @NotNull final ItemStack item) { * @param lore lore of item */ public void setItem(final int slot, @NotNull final ItemType itemType, @NotNull final String name, @NotNull final List lore) { - this.inventory.setItem(slot, new LegacyItemBuilder(this.plugin, itemType).setPlayer(this.player).setDisplayName(name).setDisplayLore(lore).asItemStack()); + this.inventory.setItem(slot, ItemBuilder.from(itemType, 1).withDisplayName(name).withDisplayLore(lore).asItemStack(this.player)); } /** @@ -354,7 +357,7 @@ public void setItem(final int slot, @NotNull final ItemType itemType, @NotNull f * @param name name of item */ public void setItem(final int slot, @NotNull final ItemType itemType, @NotNull final String name) { - this.inventory.setItem(slot, new LegacyItemBuilder(this.plugin, itemType).setPlayer(this.player).setDisplayName(name).asItemStack()); + this.inventory.setItem(slot, ItemBuilder.from(itemType, 1).withDisplayName(name).asItemStack(this.player)); } /** @@ -370,7 +373,7 @@ public void setCustomGlassPane(final int slot) { * @return the itemstack */ public @NotNull final ItemStack getRandomGlassPane() { - return MiscUtils.getRandomPaneColor().setDisplayName(" ").asItemStack(); + return MiscUtils.getRandomPaneColor().withDisplayName(" ").asItemStack(); } protected final SettingsManager config = ConfigManager.getConfig(); @@ -459,19 +462,17 @@ public void playSound(@NotNull final String type, @NotNull final Sound.Source so public final void populateTiers() { final CosmicCrateManager manager = (CosmicCrateManager) this.crate.getManager(); - final LegacyItemBuilder itemBuilder = manager.getMysteryCrate().setPlayer(this.player); + final ItemBuilder itemBuilder = manager.getMysteryCrate(); for (int slot = 0; slot <= this.size; slot++) { - itemBuilder.addNamePlaceholder("%Slot%", String.valueOf(slot)).addLorePlaceholder("%Slot%", String.valueOf(slot)); - - itemBuilder.setAmount(slot); + itemBuilder.addPlaceholder("%Slot%", String.valueOf(slot)).setAmount(slot); final Tier tier = PrizeManager.getTier(this.crate); if (tier != null) { this.crateManager.addTier(this.player, slot, tier); - getInventory().setItem(getInventory().firstEmpty(), itemBuilder.asItemStack()); + getInventory().setItem(getInventory().firstEmpty(), itemBuilder.asItemStack(this.player)); } } } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/InventoryBuilder.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/InventoryBuilder.java index bafd678fc..54f8b6c75 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/InventoryBuilder.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/InventoryBuilder.java @@ -1,20 +1,18 @@ package com.badbones69.crazycrates.paper.api.builders; import com.badbones69.crazycrates.paper.CrazyCrates; -import com.badbones69.crazycrates.paper.api.enums.other.Plugins; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.api.objects.Tier; import com.badbones69.crazycrates.paper.managers.BukkitUserManager; import com.badbones69.crazycrates.paper.managers.InventoryManager; import com.badbones69.crazycrates.paper.tasks.crates.CrateManager; -import com.ryderbelserion.fusion.core.api.utils.AdvUtils; +import com.ryderbelserion.fusion.paper.FusionPaper; import com.ryderbelserion.fusion.paper.utils.ColorUtils; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import org.bukkit.Server; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; -import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; @@ -25,7 +23,9 @@ public abstract class InventoryBuilder implements InventoryHolder, Listener { protected final CrazyCrates plugin = CrazyCrates.getPlugin(); - + + protected final FusionPaper fusion = this.plugin.getFusion(); + protected final BukkitUserManager userManager = this.plugin.getUserManager(); protected final InventoryManager inventoryManager = this.plugin.getInventoryManager(); @@ -49,9 +49,7 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl this.title = title; this.size = size; - final String inventoryTitle = Plugins.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title; - - this.inventory = this.server.createInventory(this, this.size, AdvUtils.parse(inventoryTitle)); + this.inventory = this.server.createInventory(this, this.size, this.fusion.parse(this.player, this.title)); } public InventoryBuilder(@NotNull final Player player, @NotNull final String title, final int size, @NotNull final Crate crate) { @@ -61,9 +59,7 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl this.crate = crate; - final String inventoryTitle = Plugins.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title; - - this.inventory = this.server.createInventory(this, this.size, AdvUtils.parse(inventoryTitle)); + this.inventory = this.server.createInventory(this, this.size, this.fusion.parse(this.player, this.title)); } public InventoryBuilder(@NotNull final Player player, @NotNull final String title, final int size, final int page, @NotNull final Crate crate) { @@ -74,9 +70,7 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl this.crate = crate; - final String inventoryTitle = Plugins.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title; - - this.inventory = this.server.createInventory(this, this.size, AdvUtils.parse(inventoryTitle)); + this.inventory = this.server.createInventory(this, this.size, this.fusion.parse(this.player, this.title)); } public InventoryBuilder(@NotNull final Player player, @NotNull final String title, final int size, @NotNull final Crate crate, @NotNull final List tiers) { @@ -87,9 +81,7 @@ public InventoryBuilder(@NotNull final Player player, @NotNull final String titl this.crate = crate; this.tiers = tiers; - final String inventoryTitle = Plugins.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(getPlayer(), this.title) : this.title; - - this.inventory = this.server.createInventory(this, this.size, AdvUtils.parse(inventoryTitle)); + this.inventory = this.server.createInventory(this, this.size, this.fusion.parse(this.player, this.title)); } public InventoryBuilder() {} diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/LegacyItemBuilder.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/LegacyItemBuilder.java deleted file mode 100644 index 74225a8f4..000000000 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/LegacyItemBuilder.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.badbones69.crazycrates.paper.api.builders; - -import com.badbones69.crazycrates.paper.CrazyCrates; -import com.ryderbelserion.fusion.paper.api.builders.items.legacy.ItemBuilder; -import com.ryderbelserion.fusion.paper.utils.ItemUtils; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.ItemType; -import org.jetbrains.annotations.NotNull; - -public class LegacyItemBuilder extends ItemBuilder { - - private final CrazyCrates plugin = CrazyCrates.getPlugin(); - - public LegacyItemBuilder(final CrazyCrates plugin, final LegacyItemBuilder itemBuilder, final boolean createNewStack) { - super(plugin, itemBuilder, createNewStack); - } - - public LegacyItemBuilder(final CrazyCrates plugin, final ItemType itemType, final int amount) { - super(plugin, itemType, amount); - } - - public LegacyItemBuilder(final CrazyCrates plugin, final LegacyItemBuilder itemBuilder) { - super(plugin, itemBuilder); - } - - public LegacyItemBuilder(final CrazyCrates plugin, final ItemType itemType) { - super(plugin, itemType, 1); - } - - public LegacyItemBuilder(final CrazyCrates plugin, final ItemStack itemStack) { - super(plugin, itemStack, false); - } - - public LegacyItemBuilder(final CrazyCrates plugin) { - super(plugin); - } - - @Override - public @NotNull LegacyItemBuilder fromBase64(@NotNull final String base64) { - if (base64.isEmpty()) return this; - - return new LegacyItemBuilder(this.plugin, ItemUtils.fromBase64(base64)); - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/gui/DynamicInventoryBuilder.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/gui/DynamicInventoryBuilder.java index 426a00de3..0477f9980 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/gui/DynamicInventoryBuilder.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/gui/DynamicInventoryBuilder.java @@ -3,9 +3,9 @@ import com.badbones69.crazycrates.core.config.beans.inventories.ItemPlacement; import com.badbones69.crazycrates.core.config.impl.ConfigKeys; import com.badbones69.crazycrates.paper.api.objects.Crate; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.Gui; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiItem; -import com.ryderbelserion.fusion.paper.api.builders.gui.types.PaginatedGui; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.Gui; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiItem; +import com.ryderbelserion.fusion.paper.builders.gui.types.PaginatedGui; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemType; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/gui/InventoryBuilder.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/gui/InventoryBuilder.java index 1af9be573..7ec50f4ed 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/gui/InventoryBuilder.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/gui/InventoryBuilder.java @@ -3,7 +3,6 @@ import ch.jalu.configme.SettingsManager; import com.badbones69.crazycrates.core.config.beans.inventories.ItemPlacement; import com.badbones69.crazycrates.paper.CrazyCrates; -import com.badbones69.crazycrates.paper.api.enums.other.Plugins; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.managers.BukkitUserManager; import com.badbones69.crazycrates.paper.managers.InventoryManager; @@ -11,29 +10,35 @@ import com.badbones69.crazycrates.core.config.impl.ConfigKeys; import com.badbones69.crazycrates.paper.tasks.crates.CrateManager; import com.badbones69.crazycrates.paper.tasks.menus.CrateMainMenu; -import com.badbones69.crazycrates.paper.utils.MiscUtils; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiItem; -import com.ryderbelserion.fusion.paper.api.builders.gui.types.BaseGui; -import me.clip.placeholderapi.PlaceholderAPI; +import com.badbones69.crazycrates.paper.utils.CommandUtils; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiItem; +import com.ryderbelserion.fusion.paper.builders.gui.types.BaseGui; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import java.text.NumberFormat; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; -import static java.util.regex.Matcher.quoteReplacement; -public abstract class InventoryBuilder { +public abstract class InventoryBuilder extends FoliaScheduler { protected final Player player; public InventoryBuilder(@NotNull final Player player) { + super(CrazyCrates.getPlugin(), null, player); + this.player = player; } protected final CrazyCrates plugin = CrazyCrates.getPlugin(); + protected final FusionPaper fusion = this.plugin.getFusion(); + protected final ComponentLogger logger = this.plugin.getComponentLogger(); protected final CrateManager crateManager = this.plugin.getCrateManager(); @@ -60,17 +65,21 @@ public void addMenuButton(@NotNull final Player player, @NotNull final Crate cra if (this.config.getProperty(ConfigKeys.menu_button_override)) { final List commands = this.config.getProperty(ConfigKeys.menu_button_command_list); - if (!commands.isEmpty()) { - commands.forEach(value -> { - final String command = value.replaceAll("%player%", quoteReplacement(player.getName())).replaceAll("%crate%", quoteReplacement(crate.getFileName())); + final Map placeholders = new HashMap<>() {{ + put("%player%", player.getName()); + put("%crate%", crate.getFileName()); + + put("{player}", player.getName()); + put("{crate}", crate.getFileName()); + }}; - MiscUtils.sendCommand(command); - }); + if (!commands.isEmpty()) { + commands.forEach(value -> CommandUtils.executeCommand(player, value, placeholders)); return; } - if (MiscUtils.isLogging()) this.logger.warn("The property {} is empty, so no commands were run.", ConfigKeys.menu_button_command_list.getPath()); + this.fusion.log("warn", "The property {} is empty, so no commands were run.", ConfigKeys.menu_button_command_list.getPath()); return; } @@ -81,40 +90,48 @@ public void addMenuButton(@NotNull final Player player, @NotNull final Crate cra })); } - public final String parse(@NotNull final Player player, @NotNull final String title) { - return Plugins.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(player, title) : title; - } - - public final String getCrates(@NotNull final String option) { - if (option.isEmpty()) return ""; - + public final Map getPlaceholders() { final UUID uuid = this.player.getUniqueId(); final NumberFormat instance = NumberFormat.getInstance(); - String clone = option; + final Map placeholders = new HashMap<>(); - for (Crate crate : this.crateManager.getUsableCrates()) { + for (final Crate crate : this.crateManager.getUsableCrates()) { final String fileName = crate.getFileName(); final String lowerCase = fileName.toLowerCase(); final int virtual = this.userManager.getVirtualKeys(uuid, fileName); final int physical = this.userManager.getPhysicalKeys(uuid, fileName); - + final int opened = this.userManager.getCrateOpened(uuid, fileName); final int total = virtual + physical; - final int opened = this.userManager.getCrateOpened(uuid, fileName); + placeholders.put("{%s}".formatted(lowerCase), instance.format(virtual)); + placeholders.put("{%s_raw_physical}".formatted(lowerCase), String.valueOf(physical)); + placeholders.put("{%s_physical}".formatted(lowerCase), instance.format(physical)); + + placeholders.put("{%s_raw_opened}".formatted(lowerCase), String.valueOf(opened)); + placeholders.put("{%s_raw_total}".formatted(lowerCase), String.valueOf(total)); + placeholders.put("{%s_raw}".formatted(lowerCase), String.valueOf(virtual)); - clone = clone.replaceAll("%" + lowerCase + "%", instance.format(virtual)) - .replaceAll("%" + lowerCase + "_physical%", instance.format(physical)) - .replaceAll("%" + lowerCase + "_total%", instance.format(total)) - .replaceAll("%" + lowerCase + "_opened%", instance.format(opened)) - .replaceAll("%" + lowerCase + "_raw%", String.valueOf(virtual)) - .replaceAll("%" + lowerCase + "_raw_physical%", String.valueOf(physical)) - .replaceAll("%" + lowerCase + "_raw_total%", String.valueOf(total)) - .replaceAll("%" + lowerCase + "_raw_opened%", String.valueOf(opened)); + placeholders.put("{%s_opened}".formatted(lowerCase), instance.format(opened)); + placeholders.put("{%s_total}".formatted(lowerCase), instance.format(total)); + + placeholders.put("%{}%".replace("{}", lowerCase), instance.format(virtual)); + placeholders.put("%{}_raw_physical%".replace("{}", lowerCase), String.valueOf(physical)); + placeholders.put("%{}_physical%".replace("{}", lowerCase), instance.format(physical)); + + placeholders.put("%{}_raw_opened%".replace("{}", lowerCase), String.valueOf(opened)); + placeholders.put("%{}_raw_total%".replace("{}", lowerCase), String.valueOf(total)); + placeholders.put("%{}_raw%".replace("{}", lowerCase), String.valueOf(virtual)); + + placeholders.put("%{}_opened%".replace("{}", lowerCase), instance.format(opened)); + placeholders.put("%{}_total%".replace("{}", lowerCase), instance.format(total)); } - return clone; + placeholders.put("{player}", player.getName()); + placeholders.put("%player%", player.getName()); + + return placeholders; } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/gui/StaticInventoryBuilder.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/gui/StaticInventoryBuilder.java index ef740a3b8..16d5659a6 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/gui/StaticInventoryBuilder.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/gui/StaticInventoryBuilder.java @@ -1,18 +1,41 @@ package com.badbones69.crazycrates.paper.api.builders.gui; import com.badbones69.crazycrates.paper.api.objects.Crate; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.Gui; +import com.badbones69.crazycrates.paper.api.objects.Tier; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.Gui; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.List; + public abstract class StaticInventoryBuilder extends InventoryBuilder { + private final List tiers; private final Player player; private final Crate crate; - private final Gui gui; + /** + * Builds an inventory with a set title/rows + * + * @param player {@link Player} + * @param title {@link String} + * @param rows {@link Integer} + */ + public StaticInventoryBuilder(@NotNull final Player player, @NotNull final Crate crate, @NotNull final List tiers, @NotNull final String title, final int rows) { + super(player); + + this.gui = Gui.gui(this.plugin).setTitle(this.fusion.papi(player, title)).setRows(rows).disableInteractions().create(); + + this.player = player; + this.crate = crate; + this.tiers = tiers; + } + /** * Builds an inventory with a set title/rows * @@ -23,10 +46,11 @@ public abstract class StaticInventoryBuilder extends InventoryBuilder { public StaticInventoryBuilder(@NotNull final Player player, @NotNull final Crate crate, @NotNull final String title, final int rows) { super(player); - this.gui = Gui.gui(this.plugin).setTitle(parse(player, title)).setRows(rows).disableInteractions().create(); + this.gui = Gui.gui(this.plugin).setTitle(this.fusion.papi(player, title)).setRows(rows).disableInteractions().create(); this.player = player; this.crate = crate; + this.tiers = new ArrayList<>(); } /** @@ -39,10 +63,11 @@ public StaticInventoryBuilder(@NotNull final Player player, @NotNull final Crate public StaticInventoryBuilder(@NotNull final Player player, @NotNull final String title, final int rows) { super(player); - this.gui = Gui.gui(this.plugin).setTitle(parse(player, title)).setRows(rows).disableInteractions().create(); + this.gui = Gui.gui(this.plugin).setTitle(this.fusion.papi(player, title)).setRows(rows).disableInteractions().create(); this.player = player; this.crate = null; + this.tiers = new ArrayList<>(); } /** @@ -54,10 +79,11 @@ public StaticInventoryBuilder(@NotNull final Player player, @NotNull final Strin public StaticInventoryBuilder(@NotNull final Player player, @NotNull final Crate crate) { super(player); - this.gui = Gui.gui(this.plugin).setTitle(parse(player, crate.getPreviewName())).setRows(crate.getPreviewTierCrateRows()).disableInteractions().create(); + this.gui = Gui.gui(this.plugin).setTitle(this.fusion.papi(player, crate.getPreviewName())).setRows(crate.getPreviewTierCrateRows()).disableInteractions().create(); this.player = player; this.crate = crate; + this.tiers = new ArrayList<>(); } public abstract void open(); @@ -85,7 +111,7 @@ public StaticInventoryBuilder(@NotNull final Player player, @NotNull final Crate * * @return the title of the gui */ - public @NotNull final String getTitle() { + public @NotNull String getTitle() { return this.gui.getTitle(); } @@ -99,6 +125,43 @@ public final boolean contains(@NotNull final String message) { return getTitle().contains(message); } + /** + * Updates the gui title. + * + * @param message the new title + */ + public void updateTitle(@NotNull final String message) { + this.gui.setTitle(message); + this.gui.updateTitle(this.player); + } + + /** + * Get a list of tiers. + * + * @return list of tiers + */ + public @NotNull final List getTiers() { + return this.tiers; + } + + /** + * Fetches the inventory view. + * + * @return the inventory view + */ + public @NotNull final InventoryView getView() { + return getPlayer().getOpenInventory(); + } + + /** + * Fetches the gui inventory. + * + * @return the inventory + */ + public @NotNull final Inventory getInventory() { + return getGui().getInventory(); + } + /** * Gets the {@link Gui}. * diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/types/features/CrateSpinMenu.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/types/features/CrateSpinMenu.java index d8f1ddd4f..d9812235c 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/types/features/CrateSpinMenu.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/builders/types/features/CrateSpinMenu.java @@ -4,11 +4,11 @@ import com.badbones69.crazycrates.paper.api.enums.Messages; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.api.objects.gui.GuiSettings; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.Gui; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiFiller; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiItem; -import com.ryderbelserion.fusion.paper.api.enums.Scheduler; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.Gui; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiFiller; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiItem; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.scheduler.Scheduler; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import java.util.List; diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/enums/Messages.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/enums/Messages.java index 290cc11b5..ca8782844 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/enums/Messages.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/enums/Messages.java @@ -3,17 +3,17 @@ import ch.jalu.configme.SettingsManager; import ch.jalu.configme.properties.Property; import com.badbones69.crazycrates.core.enums.State; -import com.badbones69.crazycrates.paper.utils.MiscUtils; -import com.ryderbelserion.fusion.core.api.utils.AdvUtils; -import com.ryderbelserion.fusion.core.api.utils.StringUtils; -import org.bukkit.command.CommandSender; +import com.ryderbelserion.fusion.core.FusionProvider; +import com.ryderbelserion.fusion.core.utils.StringUtils; +import com.ryderbelserion.fusion.kyori.FusionKyori; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; import com.badbones69.crazycrates.core.config.ConfigManager; import com.badbones69.crazycrates.core.config.impl.messages.CommandKeys; import com.badbones69.crazycrates.core.config.impl.messages.CrateKeys; import com.badbones69.crazycrates.core.config.impl.messages.ErrorKeys; import com.badbones69.crazycrates.core.config.impl.messages.MiscKeys; import com.badbones69.crazycrates.core.config.impl.messages.PlayerKeys; -import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import com.badbones69.crazycrates.core.config.impl.ConfigKeys; import java.util.HashMap; @@ -130,14 +130,12 @@ public enum Messages { this.isList = isList; } + private final FusionKyori fusion = (FusionKyori) FusionProvider.getInstance(); + private final SettingsManager config = ConfigManager.getConfig(); private final SettingsManager messages = ConfigManager.getMessages(); - private boolean isList() { - return this.isList; - } - public String getString() { return this.messages.getProperty(this.property); } @@ -146,11 +144,11 @@ public List getList() { return this.messages.getProperty(this.properties); } - public String getMessage(@NotNull final CommandSender sender) { + public Component getMessage(@NotNull final Audience sender) { return getMessage(sender, new HashMap<>()); } - public String getMessage(@NotNull final CommandSender sender, @NotNull final String placeholder, @NotNull final String replacement) { + public Component getMessage(@NotNull final Audience sender, @NotNull final String placeholder, @NotNull final String replacement) { final Map placeholders = new HashMap<>(); placeholders.put(placeholder, replacement); @@ -158,15 +156,35 @@ public String getMessage(@NotNull final CommandSender sender, @NotNull final Str return getMessage(sender, placeholders); } - public String getMessage(@NotNull final CommandSender sender, @NotNull final Map placeholders) { + public String getString(@NotNull final Audience sender, @NotNull final String placeholder, @NotNull final String replacement) { + final Map placeholders = new HashMap<>(); + + placeholders.put(placeholder, replacement); + + return getString(sender, placeholders); + } + + public String getString(@NotNull final Audience sender, @NotNull final Map placeholders) { + final Map map = new HashMap<>(placeholders); + + map.putIfAbsent("{prefix}", this.config.getProperty(ConfigKeys.command_prefix)); + + return asString(sender, map); + } + + public String getString(@NotNull final Audience sender) { + return getString(sender, new HashMap<>()); + } + + public Component getMessage(@NotNull final Audience sender, @NotNull final Map placeholders) { final Map map = new HashMap<>(placeholders); map.putIfAbsent("{prefix}", this.config.getProperty(ConfigKeys.command_prefix)); - return parse(sender, map); + return asComponent(sender, map); } - public void sendMessage(@NotNull final CommandSender sender, @NotNull final String placeholder, @NotNull final String replacement) { + public void sendMessage(@NotNull final Audience sender, @NotNull final String placeholder, @NotNull final String replacement) { final State state = this.config.getProperty(ConfigKeys.message_state); switch (state) { @@ -175,7 +193,7 @@ public void sendMessage(@NotNull final CommandSender sender, @NotNull final Stri } } - public void sendMessage(@NotNull final CommandSender sender, @NotNull final Map placeholders) { + public void sendMessage(@NotNull final Audience sender, @NotNull final Map placeholders) { final State state = this.config.getProperty(ConfigKeys.message_state); switch (state) { @@ -184,7 +202,7 @@ public void sendMessage(@NotNull final CommandSender sender, @NotNull final Map< } } - public void sendMessage(@NotNull final CommandSender sender) { + public void sendMessage(@NotNull final Audience sender) { final State state = this.config.getProperty(ConfigKeys.message_state); switch (state) { @@ -193,79 +211,89 @@ public void sendMessage(@NotNull final CommandSender sender) { } } - public void sendActionBar(@NotNull final CommandSender sender, @NotNull final String placeholder, @NotNull final String replacement) { - final String msg = getMessage(sender, placeholder, replacement); + public void sendActionBar(@NotNull final Audience sender, @NotNull final String placeholder, @NotNull final String replacement) { + final Component component = getMessage(sender, placeholder, replacement); - if (msg.isBlank()) return; + if (component.equals(Component.empty())) return; - if (sender instanceof Player player) { - player.sendActionBar(AdvUtils.parse(msg)); - } + sender.sendActionBar(component); } - public void sendActionBar(@NotNull final CommandSender sender, @NotNull final Map placeholders) { - final String msg = getMessage(sender, placeholders); + public void sendActionBar(@NotNull final Audience sender, @NotNull final Map placeholders) { + final Component component = asComponent(sender, placeholders); - if (msg.isBlank()) return; + if (component.equals(Component.empty())) return; - if (sender instanceof Player player) { - player.sendActionBar(AdvUtils.parse(msg)); - } + sender.sendActionBar(component); } - public void sendActionBar(@NotNull final CommandSender sender) { - final String msg = getMessage(sender); + public void sendActionBar(@NotNull final Audience sender) { + final Component component = getMessage(sender); - if (msg.isBlank()) return; + if (component.equals(Component.empty())) return; - if (sender instanceof Player player) { - player.sendActionBar(AdvUtils.parse(msg)); - } + sender.sendActionBar(component); } - public void sendRichMessage(@NotNull final CommandSender sender, @NotNull final String placeholder, @NotNull final String replacement) { - final String msg = getMessage(sender, placeholder, replacement); + public void sendRichMessage(@NotNull final Audience sender, @NotNull final String placeholder, @NotNull final String replacement) { + final Component component = getMessage(sender, placeholder, replacement); - if (msg.isBlank()) return; + if (component.equals(Component.empty())) return; - sender.sendRichMessage(msg); + sender.sendMessage(component); } - public void sendRichMessage(@NotNull final CommandSender sender, @NotNull final Map placeholders) { - final String msg = getMessage(sender, placeholders); + public void sendRichMessage(@NotNull final Audience sender, @NotNull final Map placeholders) { + final Component component = asComponent(sender, placeholders); - if (msg.isBlank()) return; + if (component.equals(Component.empty())) return; - sender.sendRichMessage(msg); + sender.sendMessage(component); } - public void sendRichMessage(@NotNull final CommandSender sender) { - final String msg = getMessage(sender); + public void sendRichMessage(@NotNull final Audience sender) { + final Component component = getMessage(sender); - if (msg.isBlank()) return; + if (component.equals(Component.empty())) return; - sender.sendRichMessage(msg); + sender.sendMessage(component); + } + + public final boolean isList() { + return this.isList; } public void migrate() { if (this.isList) { - this.messages.setProperty(this.properties, AdvUtils.convert(this.messages.getProperty(this.properties), true)); + this.messages.setProperty(this.properties, StringUtils.convertLegacy(this.messages.getProperty(this.properties), true)); return; } - this.messages.setProperty(this.property, AdvUtils.convert(this.messages.getProperty(this.property), true)); + this.messages.setProperty(this.property, StringUtils.convertLegacy(this.messages.getProperty(this.property), true)); } - private @NotNull String parse(@NotNull final CommandSender sender, @NotNull final Map placeholders) { + private @NotNull Component asComponent(@NotNull final Audience audience, @NotNull final Map placeholders) { String message; - if (isList()) { + if (this.isList) { + message = StringUtils.toString(getList()); + } else { + message = getString(); + } + + return this.fusion.parse(audience, message, placeholders); + } + + private @NotNull String asString(@NotNull final Audience audience, @NotNull final Map placeholders) { + String message; + + if (this.isList) { message = StringUtils.toString(getList()); } else { message = getString(); } - return MiscUtils.populatePlaceholders(sender, message, placeholders); + return this.fusion.papi(audience, this.fusion.replacePlaceholder(message, placeholders)); } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/enums/other/Plugins.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/enums/other/Plugins.java deleted file mode 100644 index 7a5b3bccd..000000000 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/enums/other/Plugins.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.badbones69.crazycrates.paper.api.enums.other; - -import com.badbones69.crazycrates.paper.CrazyCrates; -import org.bukkit.Server; -import org.bukkit.plugin.PluginManager; -import org.jetbrains.annotations.NotNull; - -public enum Plugins { - - oraxen("Oraxen"), - - nexo("Nexo"), - - items_adder("ItemsAdder"), - - head_database("HeadDatabase"), - - cmi("CMI"), - - fancy_holograms("FancyHolograms"), - - decent_holograms("DecentHolograms"), - - factions_uuid("FactionsUUID"), - - vault("Vault"), - - yard_watch("YardWatch"), - - world_guard("WorldGuard"), - - mcmmo("McMMO"), - - placeholder_api("PlaceholderAPI"), - - luckperms("LuckPerms"); - - private final CrazyCrates plugin = CrazyCrates.getPlugin(); - - private final Server server = this.plugin.getServer(); - - private final PluginManager pluginManager = this.server.getPluginManager(); - - private final String name; - - Plugins(@NotNull final String name) { - this.name = name; - } - - public final boolean isEnabled() { - return this.pluginManager.isPluginEnabled(this.name); - } - - public @NotNull final String getName() { - return this.name; - } -} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/enums/other/keys/FileKeys.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/enums/other/keys/FileKeys.java index 88de916fc..82183165f 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/enums/other/keys/FileKeys.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/enums/other/keys/FileKeys.java @@ -1,30 +1,28 @@ package com.badbones69.crazycrates.paper.api.enums.other.keys; import com.badbones69.crazycrates.paper.CrazyCrates; -import com.ryderbelserion.fusion.core.api.enums.FileAction; -import com.ryderbelserion.fusion.core.api.exceptions.FusionException; -import com.ryderbelserion.fusion.core.api.enums.FileType; -import com.ryderbelserion.fusion.core.files.types.LogCustomFile; -import com.ryderbelserion.fusion.paper.files.FileManager; +import com.ryderbelserion.fusion.core.exceptions.FusionException; +import com.ryderbelserion.fusion.files.enums.FileType; +import com.ryderbelserion.fusion.files.types.LogCustomFile; +import com.ryderbelserion.fusion.paper.files.PaperFileManager; import com.ryderbelserion.fusion.paper.files.types.PaperCustomFile; import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.nio.file.Path; -import java.util.ArrayList; +import java.util.Optional; public enum FileKeys { - respin_gui(FileType.PAPER, "respin-gui.yml", "guis"), + respin_gui(FileType.PAPER_YAML, "respin-gui.yml", "guis"), crate_log(FileType.LOG, "crates.log", "logs"), key_log(FileType.LOG, "keys.log", "logs"), - locations(FileType.PAPER, "locations.yml"), - data(FileType.PAPER, "data.yml"); + locations(FileType.PAPER_YAML, "locations.yml"), + data(FileType.PAPER_YAML, "data.yml"); private final CrazyCrates plugin = CrazyCrates.getPlugin(); - private final FileManager fileManager = this.plugin.getFileManager(); + private final PaperFileManager fileManager = this.plugin.getFileManager(); private final Path path = this.plugin.getDataPath(); private final FileType fileType; @@ -48,23 +46,23 @@ public enum FileKeys { } public @NotNull final PaperCustomFile getPaperCustomFile() { - @Nullable final PaperCustomFile customFile = this.fileManager.getPaperCustomFile(this.location); + @NotNull final Optional customFile = this.fileManager.getPaperFile(this.location); - if (customFile == null) { + if (customFile.isEmpty()) { throw new FusionException("Could not find custom file for " + this.location); } - return customFile; + return customFile.get(); } public @NotNull final LogCustomFile getLogCustomFile() { - @Nullable final LogCustomFile customFile = (LogCustomFile) this.fileManager.getCustomFile(this.location); + @NotNull final Optional customFile = this.fileManager.getLogFile(this.location); - if (customFile == null) { + if (customFile.isEmpty()) { throw new FusionException("Could not find custom file for " + this.location); } - return customFile; + return customFile.get(); } public @NotNull final FileType getFileType() { @@ -75,10 +73,6 @@ public enum FileKeys { return this.location; } - public void save(@NotNull final String content, @NotNull final ArrayList actions) { - this.fileManager.saveFile(this.location, actions, content); - } - public void save() { this.fileManager.saveFile(this.location); } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/events/CrateInteractEvent.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/events/CrateInteractEvent.java index 08ec0cc1f..cd3cdbd50 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/events/CrateInteractEvent.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/events/CrateInteractEvent.java @@ -1,12 +1,13 @@ package com.badbones69.crazycrates.paper.api.events; import com.badbones69.crazycrates.paper.CrazyCrates; -import com.badbones69.crazycrates.paper.api.enums.other.Plugins; import com.badbones69.crazycrates.paper.api.objects.crates.CrateLocation; import com.badbones69.crazycrates.paper.tasks.crates.CrateManager; import com.nexomc.nexo.api.NexoFurniture; import com.nexomc.nexo.api.events.furniture.NexoFurnitureBreakEvent; import com.nexomc.nexo.api.events.furniture.NexoFurnitureInteractEvent; +import com.ryderbelserion.fusion.kyori.mods.ModSupport; +import com.ryderbelserion.fusion.paper.FusionPaper; import io.th0rgal.oraxen.api.OraxenFurniture; import io.th0rgal.oraxen.api.events.furniture.OraxenFurnitureBreakEvent; import io.th0rgal.oraxen.api.events.furniture.OraxenFurnitureInteractEvent; @@ -24,6 +25,8 @@ public class CrateInteractEvent extends Event implements Cancellable { private final CrazyCrates plugin = CrazyCrates.getPlugin(); + private final FusionPaper fusion = this.plugin.getFusion(); + private final CrateManager crateManager = this.plugin.getCrateManager(); private NexoFurnitureInteractEvent nexoInteractEvent; @@ -124,19 +127,19 @@ public CrateInteractEvent(@NotNull final PlayerInteractEvent paperEvent, @NotNul * @return true or false */ public boolean isFurniture(@NotNull final Location location) { - final String pluginName = this.plugin.getFusion().getItemsPlugin().toLowerCase(); + final String pluginName = this.fusion.getItemsPlugin().toLowerCase(); boolean isFurniture = false; switch (pluginName) { - case "nexo" -> isFurniture = Plugins.nexo.isEnabled() && NexoFurniture.isFurniture(location); + case "nexo" -> isFurniture = this.fusion.isModReady(ModSupport.nexo) && NexoFurniture.isFurniture(location); - case "oraxen" -> isFurniture = Plugins.oraxen.isEnabled() && OraxenFurniture.isFurniture(location.getBlock()); + case "oraxen" -> isFurniture = this.fusion.isModReady(ModSupport.oraxen) && OraxenFurniture.isFurniture(location.getBlock()); default -> { - if (Plugins.nexo.isEnabled() && NexoFurniture.isFurniture(location)) { + if (this.fusion.isModReady(ModSupport.nexo) && NexoFurniture.isFurniture(location)) { isFurniture = true; - } else if (Plugins.oraxen.isEnabled() && OraxenFurniture.isFurniture(location.getBlock())) { + } else if (this.fusion.isModReady(ModSupport.oraxen) && OraxenFurniture.isFurniture(location.getBlock())) { isFurniture = true; } } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/Crate.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/Crate.java index 928ef98bd..e1f89e1c0 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/Crate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/Crate.java @@ -10,11 +10,11 @@ import com.badbones69.crazycrates.paper.managers.BukkitUserManager; import com.badbones69.crazycrates.paper.tasks.crates.CrateManager; import com.badbones69.crazycrates.paper.tasks.crates.effects.SoundEffect; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; -import com.ryderbelserion.fusion.core.api.utils.AdvUtils; -import com.ryderbelserion.fusion.paper.api.builders.items.ItemBuilder; -import com.ryderbelserion.fusion.paper.files.FileManager; -import com.ryderbelserion.fusion.paper.files.types.PaperCustomFile; +import com.ryderbelserion.fusion.core.utils.StringUtils; +import com.ryderbelserion.fusion.files.interfaces.ICustomFile; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.builders.types.custom.CustomBuilder; +import com.ryderbelserion.fusion.paper.files.PaperFileManager; import com.ryderbelserion.fusion.paper.utils.ColorUtils; import com.ryderbelserion.fusion.paper.utils.ItemUtils; import io.papermc.paper.datacomponent.DataComponentTypes; @@ -38,15 +38,17 @@ import org.bukkit.inventory.ItemStack; import com.badbones69.crazycrates.paper.utils.MiscUtils; import java.nio.file.Path; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.UUID; public class Crate { - private LegacyItemBuilder previewTierBorderItem; - private LegacyItemBuilder borderItem; - private LegacyItemBuilder keyBuilder; + private ItemBuilder previewTierBorderItem; + private ItemBuilder borderItem; + private ItemBuilder keyBuilder; private AbstractCrateManager manager; private final String fileName; @@ -120,7 +122,7 @@ public class Crate { public Crate(@NotNull final String name, @NotNull final String previewName, @NotNull final CrateType crateType, - @NotNull final LegacyItemBuilder key, + @NotNull final ItemBuilder key, @NotNull final String keyName, @NotNull final ArrayList prizes, @NotNull final YamlConfiguration file, @@ -132,7 +134,7 @@ public Crate(@NotNull final String name, @NotNull final List prizeCommands, @NotNull final CrateHologram hologram) { this.name = name.replaceAll(".yml", ""); - this.keyBuilder = key.setDisplayName(keyName).setPersistentString(ItemKeys.crate_key.getNamespacedKey(), this.name); + this.keyBuilder = key.withDisplayName(keyName).setPersistentString(ItemKeys.crate_key.getNamespacedKey(), this.name); this.keyName = keyName; this.file = file; @@ -143,6 +145,8 @@ public Crate(@NotNull final String name, this.prizeMessage = prizeMessage; this.prizeCommands = prizeCommands; + this.crateName = file.getString("Crate.Preview.Display.Name", " "); + this.glassBorderToggle = this.file.contains("Crate.Settings.Border.Glass-Border.Toggle") ? this.file.getBoolean("Crate.Settings.Border.Glass-Border.Toggle", this.glassBorderToggle) : this.file.getBoolean("Crate.Animation.Glass-Frame.Toggle", this.glassBorderToggle); @@ -222,27 +226,33 @@ public Crate(@NotNull final String name, this.maxSlots = this.rows * 9; - this.crateName = file.getString("Crate.Name", " "); - this.animationName = file.getString("Crate.Animation.Name", this.crateName); @NotNull final String borderName = file.getString("Crate.Preview.Glass.Name", " "); - this.borderItem = new LegacyItemBuilder(this.plugin) - .withType(file.getString("Crate.Preview.Glass.Item", "gray_stained_glass_pane").toLowerCase()) - .setCustomModelData(file.getString("Crate.Preview.Glass.Custom-Model-Data", "")) - .setItemModel(file.getString("Crate.Preview.Glass.Model.Namespace", ""), file.getString("Crate.Preview.Glass.Model.Id", "")) - .setHidingItemFlags(file.getBoolean("Crate.Preview.Glass.HideItemFlags", false)) - .setDisplayName(borderName); + this.borderItem = ItemBuilder.from(file.getString("Crate.Preview.Glass.Item", "gray_stained_glass_pane").toLowerCase()) + .withDisplayName(borderName).withConsumer(consumer -> { + final CustomBuilder customBuilder = consumer.asCustomBuilder(); + + customBuilder.setCustomModelData(file.getString("Crate.Preview.Glass.Custom-Model-Data", "")); + + customBuilder.setItemModel(file.getString("Crate.Preview.Glass.Model.Namespace", ""), file.getString("Crate.Preview.Glass.Model.Id", "")); + + customBuilder.build(); + }); @NotNull final String previewTierBorderName = file.getString("Crate.tier-preview.glass.name", " "); - this.previewTierBorderItem = new LegacyItemBuilder(this.plugin) - .withType(file.getString("Crate.tier-preview.glass.item", "gray_stained_glass_pane").toLowerCase()) - .setCustomModelData(file.getString("Crate.tier-preview.glass.custom-model-data", "")) - .setItemModel(file.getString("Crate.tier-preview.glass.model.namespace", ""), file.getString("Crate.tier-preview.glass.model.id", "")) - .setHidingItemFlags(file.getBoolean("Crate.tier-preview.glass.hideitemflags", false)) - .setDisplayName(previewTierBorderName); + this.previewTierBorderItem = ItemBuilder.from(file.getString("Crate.tier-preview.glass.item", "gray_stained_glass_pane").toLowerCase()) + .withDisplayName(previewTierBorderName).withConsumer(consumer -> { + final CustomBuilder customBuilder = consumer.asCustomBuilder(); + + customBuilder.setCustomModelData(file.getString("Crate.tier-preview.glass.custom-model-data", "")); + + customBuilder.setItemModel(file.getString("Crate.tier-preview.glass.model.namespace", ""), file.getString("Crate.tier-preview.glass.model.id", "")); + + customBuilder.build(); + }); setTierPreviewRows(file.getInt("Crate.tier-preview.rows", 5)); @@ -307,7 +317,7 @@ public final boolean isPreviewTierToggle() { /** * @return item for the preview border. */ - public @NotNull final LegacyItemBuilder getPreviewTierBorderItem() { + public @NotNull final ItemBuilder getPreviewTierBorderItem() { return this.previewTierBorderItem; } @@ -565,7 +575,7 @@ public final boolean isBorderToggle() { * * @return the ItemBuilder for the border item. */ - public @NotNull final LegacyItemBuilder getBorderItem() { + public @NotNull final ItemBuilder getBorderItem() { return this.borderItem; } @@ -624,7 +634,33 @@ public final CrateTierMenu getTierPreview(@NotNull final Player player) { * @return the key as an item stack. */ public @NotNull final ItemStack getKey(@NotNull final Player player) { - return this.userManager.addPlaceholders(this.keyBuilder.setPlayer(player), this).asItemStack(); + final UUID uuid = player.getUniqueId(); + + final int virtualKeys = this.userManager.getVirtualKeys(uuid, fileName); + final int physicalKeys = this.userManager.getPhysicalKeys(uuid, fileName); + + final int totalKeys = virtualKeys + physicalKeys; + + final int openedCrates = this.userManager.getCrateOpened(uuid, fileName); + + final NumberFormat instance = NumberFormat.getNumberInstance(); + + return this.keyBuilder.addPlaceholder("{keys_physical_raw}", String.valueOf(physicalKeys)) + .addPlaceholder("{keys_physical}", instance.format(physicalKeys)) + .addPlaceholder("{keys_total_raw}", String.valueOf(totalKeys)) + .addPlaceholder("{keys_total}", instance.format(totalKeys)) + .addPlaceholder("{keys}", instance.format(virtualKeys)) + .addPlaceholder("{crate_opened_raw}", String.valueOf(openedCrates)) + .addPlaceholder("{crate_opened}", instance.format(openedCrates)) + + .addPlaceholder("%keys_physical_raw%", String.valueOf(physicalKeys)) + .addPlaceholder("%keys_physical%", instance.format(physicalKeys)) + .addPlaceholder("%keys_total_raw%", String.valueOf(totalKeys)) + .addPlaceholder("%keys_total%", instance.format(totalKeys)) + .addPlaceholder("%keys%", instance.format(virtualKeys)) + .addPlaceholder("%crate_opened_raw%", String.valueOf(openedCrates)) + .addPlaceholder("%crate_opened%", instance.format(openedCrates)) + .asItemStack(player); } /** @@ -641,7 +677,33 @@ public final CrateTierMenu getTierPreview(@NotNull final Player player) { * @return the key as an item stack. */ public @NotNull final ItemStack getKey(final int amount, @NotNull final Player player) { - return this.userManager.addPlaceholders(this.keyBuilder.setPlayer(player), this).setAmount(amount).asItemStack(); + final UUID uuid = player.getUniqueId(); + + final int virtualKeys = this.userManager.getVirtualKeys(uuid, fileName); + final int physicalKeys = this.userManager.getPhysicalKeys(uuid, fileName); + + final int totalKeys = virtualKeys + physicalKeys; + + final int openedCrates = this.userManager.getCrateOpened(uuid, fileName); + + final NumberFormat instance = NumberFormat.getNumberInstance(); + + return this.keyBuilder.setAmount(amount).addPlaceholder("{keys_physical_raw}", String.valueOf(physicalKeys)) + .addPlaceholder("{keys_physical}", instance.format(physicalKeys)) + .addPlaceholder("{keys_total_raw}", String.valueOf(totalKeys)) + .addPlaceholder("{keys_total}", instance.format(totalKeys)) + .addPlaceholder("{keys}", instance.format(virtualKeys)) + .addPlaceholder("{crate_opened_raw}", String.valueOf(openedCrates)) + .addPlaceholder("{crate_opened}", instance.format(openedCrates)) + + .addPlaceholder("%keys_physical_raw%", String.valueOf(physicalKeys)) + .addPlaceholder("%keys_physical%", instance.format(physicalKeys)) + .addPlaceholder("%keys_total_raw%", String.valueOf(totalKeys)) + .addPlaceholder("%keys_total%", instance.format(totalKeys)) + .addPlaceholder("%keys%", instance.format(virtualKeys)) + .addPlaceholder("%crate_opened_raw%", String.valueOf(openedCrates)) + .addPlaceholder("%crate_opened%", instance.format(openedCrates)) + .asItemStack(player); } /** @@ -858,7 +920,7 @@ private void setItem(@Nullable final ItemStack itemStack, @NotNull final String return section + "." + path; } - private final FileManager fileManager = this.plugin.getFileManager(); + private final PaperFileManager fileManager = this.plugin.getFileManager(); private final Path dataPath = this.plugin.getDataPath(); @@ -868,11 +930,7 @@ private void setItem(@Nullable final ItemStack itemStack, @NotNull final String private void saveFile() { if (this.fileName.isEmpty()) return; - final PaperCustomFile customFile = this.fileManager.getPaperCustomFile(this.dataPath.resolve("crates").resolve(this.fileName)); - - if (customFile != null) { - customFile.save(); // save to file - } + this.fileManager.getPaperFile(this.dataPath.resolve("crates").resolve(this.fileName)).ifPresent(ICustomFile::save); this.crateManager.reloadCrate(this.crateManager.getCrateFromName(this.name)); } @@ -932,16 +990,14 @@ public final int getRequiredKeys() { * @return list of prizes */ public @NotNull final List getPreviewItems(@Nullable final Player player, @Nullable final Tier tier) { - List prizes = new ArrayList<>(); + final List prizes = new ArrayList<>(); for (final Prize prize : getPrizes()) { - // if (prize.getWeight() == -1) continue; - if (tier == null) { - prizes.add(player == null ? prize.getDisplayItem(this) : prize.getDisplayItem(player, this)); + prizes.add(prize.getDisplayItem(player, this)); } else { if (prize.getTiers().contains(tier)) { - prizes.add(player == null ? prize.getDisplayItem(this) : prize.getDisplayItem(player, this)); + prizes.add(prize.getDisplayItem(player, this)); } } } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/Prize.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/Prize.java index 51bada276..051a76ad5 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/Prize.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/Prize.java @@ -4,25 +4,21 @@ import com.badbones69.crazycrates.core.config.impl.ConfigKeys; import com.badbones69.crazycrates.paper.CrazyCrates; import com.badbones69.crazycrates.paper.api.PrizeManager; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; import com.badbones69.crazycrates.paper.api.enums.Messages; -import com.badbones69.crazycrates.paper.api.enums.other.Plugins; import com.badbones69.crazycrates.paper.api.enums.other.keys.ItemKeys; import com.badbones69.crazycrates.paper.utils.ItemUtils; import com.badbones69.crazycrates.paper.utils.MiscUtils; import com.badbones69.crazycrates.core.config.ConfigManager; import com.badbones69.crazycrates.core.config.impl.messages.CrateKeys; -import com.ryderbelserion.fusion.core.api.utils.AdvUtils; -import com.ryderbelserion.fusion.core.api.utils.StringUtils; -import com.ryderbelserion.fusion.paper.api.builders.items.ItemBuilder; -import com.ryderbelserion.fusion.paper.utils.ColorUtils; -import me.clip.placeholderapi.PlaceholderAPI; -import net.kyori.adventure.text.Component; +import com.ryderbelserion.fusion.core.utils.StringUtils; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.builders.types.PatternBuilder; +import com.ryderbelserion.fusion.paper.builders.types.PotionBuilder; +import com.ryderbelserion.fusion.paper.builders.types.custom.CustomBuilder; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; -import org.bukkit.Color; import org.bukkit.Server; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemType; @@ -42,8 +38,9 @@ public class Prize { private final SettingsManager config = ConfigManager.getConfig(); + private final FusionPaper fusion = this.plugin.getFusion(); + private final ConfigurationSection section; - private final List builders; private final List items; private final List commands; private final List messages; @@ -51,7 +48,7 @@ public class Prize { private final String prizeName; private List permissions = new ArrayList<>(); - private LegacyItemBuilder displayItem = new LegacyItemBuilder(this.plugin); + private ItemBuilder displayItem = ItemBuilder.from(ItemType.STONE, 1); private boolean firework = false; private String crateName = ""; private double weight = -1; @@ -76,10 +73,8 @@ public Prize(@NotNull final ConfigurationSection section, @NotNull final List(); } else { - this.builders = ItemUtils.convertStringList(this.section.getStringList("Items"), this.sectionName); - this.items = new ArrayList<>(); + this.items = ItemUtils.convertStringList(this.section.getStringList("Items"), this.sectionName); } this.maxPulls = section.getInt("Settings.Max-Pulls", -1); @@ -111,7 +106,7 @@ public Prize(@NotNull final ConfigurationSection section, @NotNull final List(); } else { - this.builders = ItemUtils.convertStringList(this.section.getStringList("Items"), this.sectionName); - this.items = new ArrayList<>(); + this.items = ItemUtils.convertStringList(this.section.getStringList("Items"), this.sectionName); } } @@ -145,11 +138,11 @@ public Prize(@NotNull final String prizeName, @NotNull final String sectionName, * @return the name of the prize. */ public @NotNull final String getPrizeName() { - return this.prizeName.isEmpty() ? "" : this.prizeName; + return this.prizeName.isEmpty() ? "" : this.prizeName; } public @NotNull final String getStrippedName() { - return PlainTextComponentSerializer.plainText().serialize(AdvUtils.parse(getPrizeName())); + return PlainTextComponentSerializer.plainText().serialize(this.fusion.parse(getPrizeName())); } /** @@ -174,16 +167,10 @@ public Prize(@NotNull final String prizeName, @NotNull final String sectionName, final int maxPulls = getMaxPulls(); final String amount = String.valueOf(pulls); - List lore = new ArrayList<>(); - - final boolean isPapiEnabled = Plugins.placeholder_api.isEnabled(); - - final String displayName = this.displayItem.getDisplayName(); - - this.displayItem.setDisplayName(player != null && isPapiEnabled ? PlaceholderAPI.setPlaceholders(player, displayName) : displayName); + final List lore = new ArrayList<>(); if (this.section.contains("DisplayLore") && !this.section.contains("Lore")) { - this.section.getStringList("DisplayLore").forEach(line -> lore.add(player != null && isPapiEnabled ? PlaceholderAPI.setPlaceholders(player, line) : line)); + lore.addAll(this.section.getStringList("DisplayLore")); } if (this.section.contains("Lore")) { @@ -195,39 +182,29 @@ public Prize(@NotNull final String prizeName, @NotNull final String sectionName, ).forEach(this.logger::warn); } - this.section.getStringList("Lore").forEach(line -> lore.add(player != null && isPapiEnabled ? PlaceholderAPI.setPlaceholders(player, line) : line)); + lore.addAll(this.section.getStringList("Lore")); } if (maxPulls != 0 && pulls != 0 && pulls >= maxPulls) { - if (player != null) { - final String line = Messages.crate_prize_max_pulls.getMessage(player); - - if (!line.isEmpty()) { - final String variable = line.replaceAll("\\{maxpulls}", String.valueOf(maxPulls)).replaceAll("\\{pulls}", amount); + final String line = player != null ? Messages.crate_prize_max_pulls.getString(player) : ConfigManager.getMessages().getProperty(CrateKeys.crate_prize_max_pulls); - lore.add(isPapiEnabled ? PlaceholderAPI.setPlaceholders(player, variable) : variable); - } - } else { - final String line = ConfigManager.getMessages().getProperty(CrateKeys.crate_prize_max_pulls); - - if (!line.isEmpty()) { - lore.add(line.replaceAll("\\{maxpulls}", String.valueOf(maxPulls)).replaceAll("\\{pulls}", amount)); - } + if (!line.isEmpty()) { + lore.add(line); } } - this.displayItem.setDisplayLore(lore); - - if (player != null) { - this.displayItem.setPlayer(player); - } + this.displayItem.withDisplayLore(lore); - final String weight = tiers.isEmpty() ? StringUtils.format(crate.getChance(getWeight())) : StringUtils.format(crate.getTierChance(getWeight())); + final String weight = StringUtils.format(crate.getChance(getWeight())); - this.displayItem.addLorePlaceholder("%chance%", weight).addLorePlaceholder("%maxpulls%", String.valueOf(maxPulls)).addLorePlaceholder("%pulls%", amount); - this.displayItem.addNamePlaceholder("%chance%", weight).addNamePlaceholder("%maxpulls%", String.valueOf(maxPulls)).addNamePlaceholder("%pulls%", amount); + this.displayItem.addPlaceholder("{chance}", weight) + .addPlaceholder("{maxpulls}", String.valueOf(maxPulls)) + .addPlaceholder("{pulls}", amount) + .addPlaceholder("%chance%", weight) + .addPlaceholder("%maxpulls%", String.valueOf(maxPulls)) + .addPlaceholder("%pulls%", amount); - return this.displayItem.setPersistentString(ItemKeys.crate_prize.getNamespacedKey(), this.sectionName).asItemStack(); + return this.displayItem.setPersistentString(ItemKeys.crate_prize.getNamespacedKey(), this.sectionName).asItemStack(player); } /** @@ -250,13 +227,6 @@ public Prize(@NotNull final String prizeName, @NotNull final String sectionName, public @NotNull final List getCommands() { return this.commands; } - - /** - * @return the ItemBuilders for all the custom items made from the Items: option. - */ - public @NotNull final List getItemBuilders() { - return this.builders; - } /** * @return the ItemBuilders for all custom items made by the Items configuration section. @@ -271,7 +241,7 @@ public Prize(@NotNull final String prizeName, @NotNull final String sectionName, * @return true or false */ public final boolean isItemsEmpty() { - return this.config.getProperty(ConfigKeys.use_different_items_layout) && getItems().isEmpty() || getItemBuilders().isEmpty(); + return getItems().isEmpty(); } /** @@ -287,8 +257,8 @@ public final boolean isItemsEmpty() { * @return the weight */ public final double getWeight() { - if (this.weight == -1 && MiscUtils.isLogging()) { - this.logger.warn("Cannot fetch the weight as the option is not present for this prize: {} in the crate: {}", this.prizeName, this.crateName); + if (this.weight == -1) { + this.fusion.log("warn", "Cannot fetch the weight as the option is not present for this prize: {} in the crate: {}", this.prizeName, this.crateName); } return this.weight; @@ -347,48 +317,62 @@ private void send(@NotNull final Player target, @NotNull final Crate crate) { final String message = StringUtils.toString(messages); - final Map placeholders = Map.of( - "%player%", target.getName(), - "%crate%", crate.getCrateName(), - "%reward%", getPrizeName().replaceAll("%maxpulls%", max_pulls).replaceAll("%pulls%", current_pulls), - "%maxpulls%", max_pulls, - "%pulls%", current_pulls, - "%reward_stripped%", getStrippedName() + final String name = target.getName(); + final String crateName = crate.getCrateName(); + final String strippedName = getStrippedName(); + final String prizeName = this.fusion.replacePlaceholder(getPrizeName(), Map.of( + "%maxpulls%", max_pulls, + "%pulls%", current_pulls, + + "{maxpulls}", max_pulls, + "{pulls}", current_pulls + )); + + final Map placeholders = Map.ofEntries( + Map.entry("%player%", name), + Map.entry("%crate%", crateName), + Map.entry("%reward%", prizeName), + Map.entry("%maxpulls%", max_pulls), + Map.entry("%pulls%", current_pulls), + Map.entry("%reward_stripped%", strippedName), + + Map.entry("{player}", name), + Map.entry("{crate}", crateName), + Map.entry("{reward}", prizeName), + Map.entry("{maxpulls}", max_pulls), + Map.entry("{pulls}", current_pulls), + Map.entry("{reward_stripped}", strippedName) ); - final Component component = AdvUtils.parse(MiscUtils.populatePlaceholders(target, message, placeholders)); - if (permission.isEmpty()) { - server.broadcast(component); + server.broadcast(this.fusion.parse(target, message, placeholders)); return; } - server.broadcast(component, permission); + server.broadcast(this.fusion.parse(target, message, placeholders), permission); } - private @NotNull LegacyItemBuilder display() { - LegacyItemBuilder builder = new LegacyItemBuilder(this.plugin); - + private void display() { try { if (this.section.contains("DisplayData")) { - builder = builder.fromBase64(this.section.getString("DisplayData", "")); + this.displayItem.withBase64(this.section.getString("DisplayData", "")); } if (this.section.contains("DisplayName")) { - builder.setDisplayName(this.prizeName); + this.displayItem.withDisplayName(this.prizeName); } if (this.section.contains("DisplayItem")) { - builder.withType(this.section.getString("DisplayItem", "red_terracotta").toLowerCase()); + this.displayItem.withCustomItem(this.section.getString("DisplayItem", "red_terracotta").toLowerCase()); } if (this.section.contains("DisplayAmount")) { - builder.setAmount(this.section.getInt("DisplayAmount", 1)); + this.displayItem.setAmount(this.section.getInt("DisplayAmount", 1)); } if (this.section.contains("DisplayLore") && !this.section.contains("Lore")) { - builder.setDisplayLore(this.section.getStringList("DisplayLore")); + this.displayItem.withDisplayLore(this.section.getStringList("DisplayLore")); } if (this.section.contains("Lore")) { @@ -400,16 +384,12 @@ private void send(@NotNull final Player target, @NotNull final Crate crate) { ).forEach(this.logger::warn); } - builder.setDisplayLore(this.section.getStringList("Lore")); + this.displayItem.withDisplayLore(this.section.getStringList("Lore")); } - //builder.addLorePlaceholder("%chance%", this.getTotalChance()); - - if (this.section.contains("Glowing")) { - builder.setGlowing(this.section.getBoolean("Glowing", false)); - } + ItemUtils.updateEnchantGlintState(this.displayItem, this.section.getString("Glowing", "add_glow")); - builder.setDamage(this.section.getInt("DisplayDamage", 0)); + this.displayItem.setItemDamage(this.section.getInt("DisplayDamage", 0)); if (this.section.contains("Patterns")) { if (MiscUtils.isLogging()) { @@ -420,64 +400,64 @@ private void send(@NotNull final Player target, @NotNull final Crate crate) { ).forEach(this.logger::warn); } + final PatternBuilder patternBuilder = this.displayItem.asPatternBuilder(); + for (final String pattern : this.section.getStringList("Patterns")) { - builder.addPattern(pattern.toLowerCase()); + final String[] split = pattern.split(":"); + final String type = split[0]; + final String color = split[1]; + + patternBuilder.addPattern(type, color); } + + patternBuilder.build(); } if (this.section.contains("DisplayPatterns")) { + final PatternBuilder patternBuilder = this.displayItem.asPatternBuilder(); + for (final String pattern : this.section.getStringList("DisplayPatterns")) { - builder.addPattern(pattern.toLowerCase()); + final String[] split = pattern.split(":"); + final String type = split[0]; + final String color = split[1]; + + patternBuilder.addPattern(type, color); } - } - builder.setHidingItemFlags(this.section.getBoolean("HideItemFlags", false) || !this.section.getStringList("Flags").isEmpty()); + patternBuilder.build(); + } - builder.setUnbreakable(this.section.getBoolean("Unbreakable", false)); + this.displayItem.setUnbreakable(this.section.getBoolean("Unbreakable", false)); - builder.setCustomModelData(this.section.getString("Settings.Custom-Model-Data", "")); + final CustomBuilder customBuilder = this.displayItem.asCustomBuilder(); - builder.setItemModel(this.section.getString("Settings.Model.Namespace", ""), this.section.getString("Settings.Model.Id", "")); + customBuilder.setCustomModelData(this.section.getString("Settings.Custom-Model-Data", "")); - if (this.section.contains("Settings.Mob-Type")) { - final EntityType type = com.ryderbelserion.fusion.paper.utils.ItemUtils.getEntity(this.section.getString("Settings.Mob-Type", "cow")); + customBuilder.setItemModel(this.section.getString("Settings.Model.Namespace", ""), this.section.getString("Settings.Model.Id", "")); - if (type != null) { - builder.setEntityType(type); - } - } + customBuilder.build(); if (this.section.contains("Settings.RGB")) { - @Nullable final Color color = ColorUtils.getRGB(this.section.getString("Settings.RGB", "")); - - if (color != null) { - builder.setColor(color); - } + this.displayItem.setColor(this.section.getString("Settings.RGB", "")); } else if (this.section.contains("Settings.Color")) { - builder.setColor(ColorUtils.getColor(this.section.getString("Settings.Color", "RED"))); + this.displayItem.setColor(this.section.getString("Settings.Color", "RED")); } if (this.section.contains("Skull")) { - builder.setSkull(section.getString("Skull", "")); + this.displayItem.withSkull(section.getString("Skull", "")); } if (this.section.contains("Player")) { - builder.setPlayer(this.section.getString("Player", "")); - } - - if (this.section.contains("DisplayTrim.Pattern") && builder.isArmor()) { - builder.applyTrimPattern(this.section.getString("DisplayTrim.Pattern", "sentry")); + this.displayItem.asSkullBuilder().withName(this.section.getString("Player", "")).build(); } - if (this.section.contains("DisplayTrim.Material") && builder.isArmor()) { - builder.applyTrimMaterial(this.section.getString("DisplayTrim.Material", "quartz")); - } + this.displayItem.setTrim(this.section.getString("DisplayTrim.Pattern", ""), this.section.getString("DisplayTrim.Material", "")); if (this.section.contains("DisplayEnchantments")) { for (final String ench : this.section.getStringList("DisplayEnchantments")) { String[] value = ench.split(":"); - builder.addEnchantment(value[0], Integer.parseInt(value[1]), true); + this.displayItem.addEnchantment(value[0], Integer.parseInt(value[1])); } } @@ -485,6 +465,8 @@ private void send(@NotNull final Player target, @NotNull final Crate crate) { final ConfigurationSection potions = this.section.getConfigurationSection("DisplayPotions"); if (potions != null) { + final PotionBuilder potionBuilder = this.displayItem.asPotionBuilder(); + for (final String potion : potions.getKeys(false)) { final PotionEffectType type = com.ryderbelserion.fusion.paper.utils.ItemUtils.getPotionEffect(potion); @@ -495,16 +477,16 @@ private void send(@NotNull final Player target, @NotNull final Crate crate) { final int duration = data.getInt("duration", 10) * 20; final int level = data.getInt("level", 1); - builder.addPotionEffect(type, duration, level); + potionBuilder.withPotionEffect(type, duration, level); } } } + + potionBuilder.build(); } } - - return builder; } catch (final Exception exception) { - return new LegacyItemBuilder(this.plugin, ItemType.RED_TERRACOTTA).setDisplayName("ERROR").setDisplayLore(List.of( + this.displayItem = ItemBuilder.from(ItemType.RED_TERRACOTTA).withDisplayName("ERROR").withDisplayLore(List.of( "There was an error with one of your prizes!", "The reward in question is labeled: " + section.getName() + " in crate: " + crateName, "Name of the reward is " + section.getString("DisplayName"), diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/Tier.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/Tier.java index c7375c587..385fd1d3a 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/Tier.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/Tier.java @@ -2,10 +2,10 @@ import com.badbones69.crazycrates.paper.CrazyCrates; import com.badbones69.crazycrates.paper.api.enums.other.keys.ItemKeys; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; -import com.badbones69.crazycrates.paper.utils.MiscUtils; -import com.ryderbelserion.fusion.core.api.utils.StringUtils; -import net.kyori.adventure.text.logger.slf4j.ComponentLogger; +import com.ryderbelserion.fusion.core.utils.StringUtils; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.builders.types.custom.CustomBuilder; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -17,9 +17,9 @@ public class Tier { private final CrazyCrates plugin = CrazyCrates.getPlugin(); - private final ComponentLogger logger = this.plugin.getComponentLogger(); + private final FusionPaper fusion = this.plugin.getFusion(); - private final LegacyItemBuilder item; + private final ItemBuilder item; private final String name; private final List lore; private final String coloredName; @@ -33,9 +33,16 @@ public Tier(@NotNull final String tier, @NotNull final ConfigurationSection sect this.lore = section.getStringList("Lore"); // this returns an empty list if not found anyway. - this.item = new LegacyItemBuilder(this.plugin).withType(section.getString("Item", "chest").toLowerCase()).setHidingItemFlags(section.getBoolean("HideItemFlags", false)) - .setCustomModelData(section.getString("Custom-Model-Data", "")) - .setItemModel(section.getString("Model.Namespace", ""), section.getString("Model.Id", "")); + this.item = ItemBuilder.from(section.getString("Item", "chest").toLowerCase()) + .withConsumer(consumer -> { + final CustomBuilder customBuilder = consumer.asCustomBuilder(); + + customBuilder.setCustomModelData(section.getString("Custom-Model-Data", "")); + + customBuilder.setItemModel(section.getString("Model.Namespace", ""), section.getString("Model.Id", "")); + + customBuilder.build(); + }); this.weight = section.getDouble("Weight", -1); @@ -59,7 +66,7 @@ public Tier(@NotNull final String tier, @NotNull final ConfigurationSection sect /** * @return the colored glass pane. */ - public @NotNull final LegacyItemBuilder getItem() { + public @NotNull final ItemBuilder getItem() { return this.item; } @@ -69,8 +76,8 @@ public Tier(@NotNull final String tier, @NotNull final ConfigurationSection sect * @return the total chance divided */ public final double getWeight() { - if (this.weight == -1 && MiscUtils.isLogging()) { - this.logger.warn("Cannot fetch the weight as the option is not present for this tier: {}", this.name); + if (this.weight == -1) { + this.fusion.log("warn", "Cannot fetch the weight as the option is not present for this tier: {}", this.name); } return this.weight; @@ -87,9 +94,9 @@ public final int getSlot() { * @return the tier item shown in the preview. */ public @NotNull final ItemStack getTierItem(@Nullable final Player target, @NotNull final Crate crate) { - if (target != null) this.item.setPlayer(target); + final String weight = StringUtils.format(crate.getTierChance(getWeight())); - return this.item.setDisplayName(this.coloredName).setDisplayLore(this.lore).addLorePlaceholder("%chance%", StringUtils.format(crate.getTierChance(getWeight()))) - .setPersistentString(ItemKeys.crate_tier.getNamespacedKey(), this.name).asItemStack(); + return this.item.withDisplayName(this.coloredName).withDisplayLore(this.lore).addPlaceholder("{chance}", weight).addPlaceholder("%chance%", weight) + .setPersistentString(ItemKeys.crate_tier.getNamespacedKey(), this.name).asItemStack(target); } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/gui/GuiSettings.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/gui/GuiSettings.java index bb49dc3fa..c23deea89 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/gui/GuiSettings.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/gui/GuiSettings.java @@ -1,15 +1,14 @@ package com.badbones69.crazycrates.paper.api.objects.gui; import com.badbones69.crazycrates.paper.CrazyCrates; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; import com.badbones69.crazycrates.paper.api.enums.FillerType; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.api.objects.Prize; import com.badbones69.crazycrates.paper.api.objects.gui.buttons.CrateButton; import com.badbones69.crazycrates.paper.api.objects.gui.buttons.GuiButton; -import com.badbones69.crazycrates.paper.utils.MiscUtils; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiItem; -import net.kyori.adventure.text.logger.slf4j.ComponentLogger; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiItem; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.NotNull; @@ -21,7 +20,7 @@ public class GuiSettings { private final CrazyCrates plugin = CrazyCrates.getPlugin(); - private final ComponentLogger logger = this.plugin.getComponentLogger(); + private final FusionPaper fusion = this.plugin.getFusion(); private final String title; private final int rows; @@ -44,9 +43,8 @@ public GuiSettings(@NotNull final Crate crate, @Nullable final Prize prize, @Not this.isFillerToggled = configuration.getBoolean("filler.toggle", false); this.fillerType = FillerType.getFromName(configuration.getString("filler.fill-type", "border")); - this.fillerStack = new LegacyItemBuilder(this.plugin) - .withType(configuration.getString("filler.toggle.material", "red_stained_glass_pane")) - .setDisplayName(configuration.getString("filler.toggle.name", " ")).asGuiItem(); + this.fillerStack = ItemBuilder.from(configuration.getString("filler.toggle.material", "red_stained_glass_pane")) + .withDisplayName(configuration.getString("filler.toggle.name", " ")).asGuiItem(); final ConfigurationSection staticButtons = configuration.getConfigurationSection("buttons.static"); @@ -59,9 +57,7 @@ public GuiSettings(@NotNull final Crate crate, @Nullable final Prize prize, @Not final int slot = button.getInt("slot"); if (this.buttons.containsKey(slot)) { - if (MiscUtils.isLogging()) { - this.logger.warn("Slot {} is taken, Try using another slot as we do not allow duplicates", slot); - } + this.fusion.log("warn", "Slot {} is taken, Try using another slot as we do not allow duplicates", slot); return; } @@ -81,9 +77,7 @@ public GuiSettings(@NotNull final Crate crate, @Nullable final Prize prize, @Not final int slot = button.getInt("slot"); if (this.buttons.containsKey(slot)) { - if (MiscUtils.isLogging()) { - this.logger.warn("Slot {} is taken, Try using another slot as we do not allow duplicates", slot); - } + this.fusion.log("warn", "Slot {} is taken, Try using another slot as we do not allow duplicates", slot); return; } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/gui/buttons/CrateButton.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/gui/buttons/CrateButton.java index 26f2cc0c1..a5027cd90 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/gui/buttons/CrateButton.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/gui/buttons/CrateButton.java @@ -7,8 +7,8 @@ import com.badbones69.crazycrates.paper.managers.BukkitUserManager; import com.badbones69.crazycrates.paper.managers.events.enums.EventType; import com.badbones69.crazycrates.paper.tasks.crates.CrateManager; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiAction; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiItem; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiAction; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiItem; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -30,7 +30,12 @@ public CrateButton(@NotNull final Crate crate, @Nullable final Prize prize, @Not super(section, Map.of( "%crate_pretty%", crate.getCrateName(), "%crate_raw%", crate.getFileName(), - "%prize%", prize != null ? prize.getSectionName() : "N/A" + "%prize%", prize != null ? prize.getSectionName() : "N/A", + + "{crate_pretty}", crate.getCrateName(), + "{crate_raw}", crate.getFileName(), + + "{prize}", prize != null ? prize.getSectionName() : "N/A" )); this.crate = crate; @@ -86,8 +91,8 @@ public CrateButton(@NotNull final Crate crate, @Nullable final Prize prize, @Not final int cap = PrizeManager.getCap(crate, player); Messages.crate_prize_max_respins.sendMessage(player, Map.of("{status}", cap >= 1 ? - Messages.crate_prize_max_respins_left.getMessage(player, Map.of("{respins_total}", String.valueOf(cap), "{respins_left}", "0")) : - Messages.crate_prize_max_respins_none.getMessage(player))); + Messages.crate_prize_max_respins_left.getString(player, Map.of("{respins_total}", String.valueOf(cap), "{respins_left}", "0")) : + Messages.crate_prize_max_respins_none.getString(player))); return; } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/gui/buttons/GuiButton.java b/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/gui/buttons/GuiButton.java index c0c39e496..5a6d33081 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/gui/buttons/GuiButton.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/api/objects/gui/buttons/GuiButton.java @@ -1,11 +1,12 @@ package com.badbones69.crazycrates.paper.api.objects.gui.buttons; import com.badbones69.crazycrates.paper.CrazyCrates; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; import com.badbones69.crazycrates.paper.tasks.crates.effects.SoundEffect; -import com.badbones69.crazycrates.paper.utils.MiscUtils; +import com.badbones69.crazycrates.paper.utils.CommandUtils; import com.badbones69.crazycrates.paper.utils.MsgUtils; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiItem; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiItem; import net.kyori.adventure.sound.Sound; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; @@ -18,18 +19,19 @@ public class GuiButton { protected final CrazyCrates plugin = CrazyCrates.getPlugin(); + protected final FusionPaper fusion = this.plugin.getFusion(); + private final Map placeholders; private final ConfigurationSection section; - private final LegacyItemBuilder guiItem; + private final ItemBuilder guiItem; private final List commands; private final List messages; public GuiButton(@NotNull final ConfigurationSection section, @NotNull final Map placeholders) { - this.guiItem = new LegacyItemBuilder(this.plugin) - .withType(section.getString("material", "emerald_block")) - .setDisplayName(section.getString("name", "No display name found.")) - .setDisplayLore(section.getStringList("lore")); + this.guiItem = ItemBuilder.from(section.getString("material", "emerald_block")) + .withDisplayName(section.getString("name", "No display name found.")) + .withDisplayLore(section.getStringList("lore")); this.commands = section.getStringList("commands"); this.messages = section.getStringList("messages"); @@ -43,8 +45,8 @@ public GuiButton(@NotNull final ConfigurationSection section, @NotNull final Map player.closeInventory(InventoryCloseEvent.Reason.OPEN_NEW); - this.commands.forEach(command -> MiscUtils.sendCommand(command, this.placeholders)); - this.messages.forEach(message -> MsgUtils.sendMessage(player, MiscUtils.populatePlaceholders(player, message, this.placeholders), false)); + this.commands.forEach(command -> CommandUtils.executeCommand(player, command, this.placeholders)); + this.messages.forEach(message -> MsgUtils.message(player, message, this.placeholders, false)); final ConfigurationSection sound = this.section.getConfigurationSection("sound"); diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/CommandManager.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/CommandManager.java index aff550236..93b7a8dab 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/CommandManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/CommandManager.java @@ -22,7 +22,7 @@ import com.badbones69.crazycrates.paper.commands.crates.types.player.CommandKey; import com.badbones69.crazycrates.paper.commands.crates.types.player.CommandTransfer; import com.badbones69.crazycrates.paper.tasks.crates.CrateManager; -import com.badbones69.crazycrates.paper.api.PlayerBuilder; +import com.ryderbelserion.fusion.paper.builders.PlayerBuilder; import dev.triumphteam.cmd.bukkit.BukkitCommandManager; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.bukkit.Server; @@ -124,7 +124,7 @@ public static void load() { return migrators; }); - commandManager.registerArgument(PlayerBuilder.class, (sender, context) -> new PlayerBuilder(context)); + commandManager.registerArgument(PlayerBuilder.class, (sender, context) -> new PlayerBuilder(plugin, context)); List.of( new CommandTeleport(), diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/BaseCommand.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/BaseCommand.java index e1df529bb..c883292e7 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/BaseCommand.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/BaseCommand.java @@ -11,7 +11,8 @@ import com.badbones69.crazycrates.paper.managers.BukkitUserManager; import com.badbones69.crazycrates.paper.managers.InventoryManager; import com.badbones69.crazycrates.paper.tasks.crates.CrateManager; -import com.ryderbelserion.fusion.paper.files.FileManager; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.files.PaperFileManager; import dev.triumphteam.cmd.core.annotations.Command; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import org.bukkit.OfflinePlayer; @@ -35,6 +36,8 @@ public abstract class BaseCommand { protected final CrazyCrates plugin = CrazyCrates.getPlugin(); + protected final FusionPaper fusion = this.plugin.getFusion(); + protected final Path path = this.plugin.getDataPath(); protected final Server server = this.plugin.getServer(); @@ -49,7 +52,7 @@ public abstract class BaseCommand { protected final CrateManager crateManager = this.plugin.getCrateManager(); - protected final FileManager fileManager = this.plugin.getFileManager(); + protected final PaperFileManager fileManager = this.plugin.getFileManager(); protected final SettingsManager config = ConfigManager.getConfig(); @@ -161,7 +164,7 @@ private void takeKey(@NotNull final CommandSender sender, @Nullable final Player final int totalKeys = this.userManager.getTotalKeys(uuid, fileName); if (totalKeys < 1) { - if (MiscUtils.isLogging()) this.logger.warn("The player {} does not have enough keys to take.", name); + this.fusion.log("warn", "The player {} does not have enough keys to take.", name); Messages.cannot_take_keys.sendMessage(sender, "{player}", name); diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/CommandReload.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/CommandReload.java index c5486a37e..6d0e1a950 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/CommandReload.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/CommandReload.java @@ -5,8 +5,8 @@ import com.badbones69.crazycrates.paper.utils.MiscUtils; import com.badbones69.crazycrates.paper.commands.crates.types.BaseCommand; import com.badbones69.crazycrates.core.config.impl.ConfigKeys; -import com.ryderbelserion.fusion.core.api.enums.FileAction; -import com.ryderbelserion.fusion.core.api.enums.FileType; +import com.ryderbelserion.fusion.files.enums.FileAction; +import com.ryderbelserion.fusion.files.enums.FileType; import dev.triumphteam.cmd.bukkit.annotation.Permission; import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.core.annotations.Syntax; @@ -14,7 +14,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.permissions.PermissionDefault; import org.jetbrains.annotations.Nullable; -import java.util.List; public class CommandReload extends BaseCommand { @@ -28,29 +27,14 @@ public void reload(CommandSender sender) { this.plugin.getInstance().reload(); - this.fileManager.refresh(false).addFile(this.path.resolve("locations.yml"), FileType.PAPER, List.of( - FileAction.STATIC_FILE, - FileAction.RELOAD_FILE - ), null) - .addFile(this.path.resolve("data.yml"), FileType.PAPER, List.of( - FileAction.STATIC_FILE, - FileAction.RELOAD_FILE - ), null) - .addFile(this.path.resolve("guis").resolve("respin-gui.yml"), FileType.PAPER, List.of( - FileAction.STATIC_FILE, - FileAction.RELOAD_FILE - ), null) - .addFolder(this.path.resolve("logs"), FileType.LOG, List.of( - FileAction.EXTRACT_FOLDER, - FileAction.STATIC_FILE, - FileAction.RELOAD_FILE - ), null) - .addFolder(this.path.resolve("crates"), FileType.PAPER, List.of( - FileAction.EXTRACT_FOLDER - ), null) - .addFolder(this.path.resolve("schematics"), FileType.NBT, List.of( - FileAction.EXTRACT_FOLDER - ), null); + this.fileManager.extractFolder("guis", this.path); + + this.fileManager.addPaperFile(this.path.resolve("locations.yml"), consumer -> consumer.addAction(FileAction.RELOAD_FILE)) + .addPaperFile(this.path.resolve("data.yml"), consumer -> consumer.addAction(FileAction.RELOAD_FILE)) + .addPaperFile(this.path.resolve("guis").resolve("respin-gui.yml"), consumer -> consumer.addAction(FileAction.RELOAD_FILE)) + .addPaperFolder(this.path.resolve("crates"), consumer -> consumer.addAction(FileAction.RELOAD_FILE)) + .addFolder(this.path.resolve("schematics"), FileType.NBT, consumer -> consumer.addAction(FileAction.RELOAD_FILE)) + .addFolder(this.path.resolve("logs"), FileType.LOG, consumer -> consumer.addAction(FileAction.RELOAD_FILE)); MiscUtils.save(); diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/CommandList.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/CommandList.java index 2786829bb..351ccea2b 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/CommandList.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/CommandList.java @@ -4,7 +4,7 @@ import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.api.objects.crates.CrateLocation; import com.badbones69.crazycrates.paper.commands.crates.types.BaseCommand; -import com.ryderbelserion.fusion.core.api.utils.StringUtils; +import com.ryderbelserion.fusion.core.utils.StringUtils; import dev.triumphteam.cmd.bukkit.annotation.Permission; import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.core.annotations.Syntax; @@ -27,7 +27,7 @@ public void list(CommandSender sender) { final Location location = crateLocation.getLocation(); final Crate crate = crateLocation.getCrate(); - crates.add(Messages.crate_locations_format.getMessage(sender, Map.of( + crates.add(Messages.crate_locations_format.getString(sender, Map.of( "{crate_name}", crate.getCrateName(), "{id}", crateLocation.getID(), "{x}", String.valueOf(location.getBlockX()), diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/CommandMigrate.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/CommandMigrate.java index 87353be70..077c3fc0f 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/CommandMigrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/CommandMigrate.java @@ -81,7 +81,7 @@ public void migrate(final CommandSender sender, Flags flags) { case CRATES_DEPRECATED_ALL -> new DeprecatedCrateMigrator(sender).run(); - case SPECIALIZED_CRATES -> sender.sendRichMessage(Messages.migration_not_available.getMessage(sender)); + case SPECIALIZED_CRATES -> Messages.migration_not_available.sendMessage(sender); case EXCELLENT_CRATES -> { if (!MiscUtils.isExcellentCratesEnabled()) { diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/CommandTeleport.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/CommandTeleport.java index 791c843cc..0327e15e5 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/CommandTeleport.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/CommandTeleport.java @@ -11,7 +11,6 @@ import org.bukkit.permissions.PermissionDefault; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; -import java.util.Objects; public class CommandTeleport extends BaseCommand { @@ -37,24 +36,46 @@ public void teleport(Player player, @ArgName("crate_id") @Optional @Suggestion(" return; } + String value = ""; + for (final String name : section.getKeys(false)) { if (name.equalsIgnoreCase(id)) { - final World world = this.server.getWorld(Objects.requireNonNull(this.locations.getString("Locations." + name + ".World"))); + value = name; + + break; + } + } + + Location validLocation = null; - final int x = this.locations.getInt("Locations." + name + ".X"); - final int y = this.locations.getInt("Locations." + name + ".Y"); - final int z = this.locations.getInt("Locations." + name + ".Z"); + if (!value.isBlank()) { + final ConfigurationSection location = this.locations.getConfigurationSection("Locations." + value); - final Location loc = new Location(world, x, y, z); + if (location != null) { + final String worldName = location.getString("World", ""); - player.teleport(loc.add(.5, 0, .5)); + if (!worldName.isBlank()) { + final World world = this.server.getWorld(worldName); - Messages.crate_teleported.sendMessage(player, "{name}", name); + if (world != null) { + final int x = location.getInt("X"); + final int y = location.getInt("Y"); + final int z = location.getInt("Z"); - return; + validLocation = new Location(world, x, y, z); + } + } } } - Messages.crate_cannot_teleport.sendMessage(player, "{id}", id); + if (validLocation == null) { + Messages.crate_cannot_teleport.sendMessage(player, "{id}", id); + + return; + } + + player.teleport(validLocation.add(0.5, 0, 0.5)); + + Messages.crate_teleported.sendMessage(player, "{name}", value); } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/ICrateMigrator.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/ICrateMigrator.java index 5b10e343a..4a8e2592e 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/ICrateMigrator.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/ICrateMigrator.java @@ -7,8 +7,9 @@ import com.badbones69.crazycrates.paper.commands.crates.types.admin.crates.migrator.enums.MigrationType; import com.badbones69.crazycrates.core.config.ConfigManager; import com.badbones69.crazycrates.paper.tasks.crates.CrateManager; -import com.ryderbelserion.fusion.core.api.utils.StringUtils; -import com.ryderbelserion.fusion.paper.files.FileManager; +import com.ryderbelserion.fusion.core.utils.StringUtils; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.files.PaperFileManager; import com.ryderbelserion.fusion.paper.files.types.PaperCustomFile; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import org.bukkit.command.CommandSender; @@ -22,6 +23,8 @@ public abstract class ICrateMigrator { protected final CrazyCrates plugin = CrazyCrates.getPlugin(); + protected final FusionPaper fusion = this.plugin.getFusion(); + protected final ComponentLogger logger = this.plugin.getComponentLogger(); protected final Path dataPath = this.plugin.getDataPath(); @@ -32,7 +35,7 @@ public abstract class ICrateMigrator { protected final SettingsManager messages = ConfigManager.getMessages(); - protected final FileManager fileManager = this.plugin.getFileManager(); + protected final PaperFileManager fileManager = this.plugin.getFileManager(); protected final CommandSender sender; @@ -59,8 +62,8 @@ public ICrateMigrator(final CommandSender sender, final MigrationType type, fina public abstract void set(ConfigurationSection section, String path, T value); - public File getCratesDirectory() { - return null; + public Path getCratesDirectory() { + return this.dataPath.resolve("crates"); } public void sendMessage(List files, final int success, final int failed) { diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorMultiple.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorMultiple.java index c7badc752..20856eece 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorMultiple.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorMultiple.java @@ -2,15 +2,13 @@ import com.badbones69.crazycrates.paper.commands.crates.types.admin.crates.migrator.ICrateMigrator; import com.badbones69.crazycrates.paper.commands.crates.types.admin.crates.migrator.enums.MigrationType; -import com.ryderbelserion.fusion.core.api.enums.FileType; -import com.ryderbelserion.fusion.core.api.interfaces.files.ICustomFile; import com.ryderbelserion.fusion.paper.files.types.PaperCustomFile; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; -import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.Optional; public class MojangMappedMigratorMultiple extends ICrateMigrator { @@ -20,24 +18,28 @@ public MojangMappedMigratorMultiple(final CommandSender sender) { @Override public void run() { - final Collection>> customFiles = this.fileManager.getCustomFiles().values(); - final List failed = new ArrayList<>(); final List success = new ArrayList<>(); - customFiles.forEach(key -> { - try { - if (key.isStatic() || !key.isLoaded() || key.getFileType() != FileType.PAPER) return; + final List paths = this.fusion.getFiles(getCratesDirectory(), ".yml"); + + for (final Path path : paths) { + final Optional optional = this.fileManager.getPaperFile(path); + + if (optional.isEmpty()) continue; + + final PaperCustomFile customFile = optional.get(); - final PaperCustomFile customFile = (PaperCustomFile) key; + if (!customFile.isLoaded()) continue; + try { migrate(customFile, ""); success.add("⤷ " + customFile.getFileName()); } catch (final Exception exception) { - failed.add("⤷ " + key.getFileName()); + failed.add("⤷ " + customFile.getFileName()); } - }); + } // reload crates this.crateManager.loadHolograms(); @@ -58,9 +60,4 @@ public void run() { public void set(final ConfigurationSection section, final String path, T value) { section.set(path, value); } - - @Override - public final File getCratesDirectory() { - return new File(this.plugin.getDataFolder(), "crates"); - } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorSingle.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorSingle.java index 83e41415e..7d1715e65 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorSingle.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorSingle.java @@ -7,10 +7,11 @@ import com.ryderbelserion.fusion.paper.files.types.PaperCustomFile; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; -import java.io.File; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; public class MojangMappedMigratorSingle extends ICrateMigrator { @@ -26,9 +27,9 @@ public void run() { return; } - final PaperCustomFile customFile = this.fileManager.getPaperCustomFile(this.dataPath.resolve("crates").resolve(this.crateName)); + @NotNull final Optional optional = this.fileManager.getPaperFile(this.dataPath.resolve("crates").resolve(this.crateName)); - if (customFile == null) { + if (optional.isEmpty()) { Messages.error_migrating.sendMessage(this.sender, Map.of( "{file}", crateName, "{type}", type.getName(), @@ -38,7 +39,9 @@ public void run() { return; } - if (customFile.isStatic()) { + final PaperCustomFile customFile = optional.get(); + + if (!customFile.isLoaded()) { Messages.error_migrating.sendMessage(this.sender, Map.of( "{file}", crateName, "{type}", type.getName(), @@ -78,9 +81,4 @@ public void run() { public void set(final ConfigurationSection section, final String path, T value) { section.set(path, value); } - - @Override - public final File getCratesDirectory() { - return new File(this.plugin.getDataFolder(), "crates"); - } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/DeprecatedCrateMigrator.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/DeprecatedCrateMigrator.java index 0691b9562..fb82b64ad 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/DeprecatedCrateMigrator.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/DeprecatedCrateMigrator.java @@ -2,16 +2,14 @@ import com.badbones69.crazycrates.paper.commands.crates.types.admin.crates.migrator.ICrateMigrator; import com.badbones69.crazycrates.paper.commands.crates.types.admin.crates.migrator.enums.MigrationType; -import com.ryderbelserion.fusion.core.api.enums.FileType; -import com.ryderbelserion.fusion.core.api.interfaces.files.ICustomFile; import com.ryderbelserion.fusion.paper.files.types.PaperCustomFile; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; -import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.Optional; public class DeprecatedCrateMigrator extends ICrateMigrator { @@ -21,23 +19,27 @@ public DeprecatedCrateMigrator(final CommandSender sender) { @Override public void run() { - final Collection>> customFiles = this.fileManager.getCustomFiles().values(); - final List failed = new ArrayList<>(); final List success = new ArrayList<>(); - customFiles.forEach(key -> { - try { - if (key.isStatic() || !key.isLoaded() || key.getFileType() != FileType.PAPER) return; + final List paths = this.fusion.getFiles(getCratesDirectory(), ".yml"); + + for (final Path path : paths) { + final Optional optional = this.fileManager.getPaperFile(path); + + if (optional.isEmpty()) continue; - final PaperCustomFile customFile = (PaperCustomFile) key; + final PaperCustomFile customFile = optional.get(); - final YamlConfiguration configuration = customFile.getConfiguration(); + if (!customFile.isLoaded()) continue; - final ConfigurationSection section = configuration.getConfigurationSection("Crate"); + final YamlConfiguration configuration = customFile.getConfiguration(); - if (section == null) return; + final ConfigurationSection section = configuration.getConfigurationSection("Crate"); + if (section == null) continue; + + try { boolean isSave = false; if (section.contains("CrateName")) { @@ -47,6 +49,87 @@ public void run() { isSave = true; } + final ConfigurationSection displaySection = section.contains("Preview.Display") ? section.getConfigurationSection("Preview.Display") : section.createSection("Preview.Display"); + + if (displaySection != null) { + if (section.contains("Glowing") && section.isBoolean("Glowing")) { + final boolean isGlowing = section.getBoolean("Glowing", false); + + if (isGlowing) { + set(displaySection, "Glowing", "add_glow"); + } else { + set(displaySection, "Glowing", "remove_glow"); + } + + set(section, "Glowing", null); + + isSave = true; + } + + if (section.contains("Item")) { + set(displaySection, "Item", section.getString("Item", "chest")); + set(section, "Item", null); + + isSave = true; + } + + if (section.contains("Custom-Model-Data")) { + set(displaySection, "Custom-Model-Data", section.getInt("Custom-Model-Data", -1)); + set(section, "Custom-Model-Data", null); + + isSave = true; + } + + if (section.contains("Model.Namespace") && section.contains("Model.Id")) { + set(displaySection, "Model.Namespace", section.getString("Model.Namespace", "")); + set(displaySection, "Model.Id", section.getString("Model.Id", "")); + + set(section, "Model", null); + + isSave = true; + } + + if (section.contains("Slot")) { + set(displaySection, "Slot", section.getInt("Slot", -1)); + set(section, "Slot", null); + + isSave = true; + } + + if (section.contains("Name")) { + set(displaySection, "Name", section.getString("Name", " ")); + set(section, "Name", null); + + isSave = true; + } + + if (section.contains("Lore")) { + set(displaySection, "Lore", section.getStringList("Lore")); + set(section, "Lore", null); + + isSave = true; + } + + if (section.contains("InGUI")) { + set(displaySection, "Toggle", section.getBoolean("InGUI", false)); + set(section, "InGUI", null); + + isSave = true; + } + } + + if (section.contains("PhysicalKey.Glowing") && section.isBoolean("PhysicalKey.Glowing")) { + final boolean isGlowing = section.getBoolean("PhysicalKey.Glowing", false); + + if (isGlowing) { + set(section, "PhysicalKey.Glowing", "add_glow"); + } else { + set(section, "PhysicalKey.Glowing", "remove_glow"); + } + + isSave = true; + } + if (section.contains("Preview-Name")) { set(section, "Preview.Name", section.getString("Preview-Name", " ")); set(section, "Preview-Name", null); @@ -93,18 +176,31 @@ public void run() { isSave = true; } + + if (prizeSection.contains("Glowing") && prizeSection.isBoolean("Glowing")) { + final boolean isGlowing = section.getBoolean("Glowing", false); + + if (isGlowing) { + set(section, "Glowing", "add_glow"); + } else { + set(section, "Glowing", "remove_glow"); + } + + isSave = true; + } } } if (isSave) { customFile.save(); + customFile.load(); } success.add("⤷ " + customFile.getFileName()); - } catch (Exception exception) { - failed.add("⤷ " + key.getFileName()); + } catch (final Exception exception) { + failed.add("⤷ " + customFile.getFileName()); } - }); + } final int convertedCrates = success.size(); final int failedCrates = failed.size(); @@ -116,8 +212,6 @@ public void run() { sendMessage(files, convertedCrates, failedCrates); - this.fileManager.init(new ArrayList<>()); - // reload crates this.crateManager.loadHolograms(); this.crateManager.loadCrates(); @@ -127,9 +221,4 @@ public void run() { public void set(final ConfigurationSection section, final String path, T value) { section.set(path, value); } - - @Override - public final File getCratesDirectory() { - return new File(this.plugin.getDataFolder(), "crates"); - } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/LegacyColorMigrator.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/LegacyColorMigrator.java index 1452bc68f..0a9138db3 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/LegacyColorMigrator.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/LegacyColorMigrator.java @@ -4,16 +4,15 @@ import com.badbones69.crazycrates.paper.commands.crates.types.admin.crates.migrator.ICrateMigrator; import com.badbones69.crazycrates.paper.commands.crates.types.admin.crates.migrator.enums.MigrationType; import com.badbones69.crazycrates.core.config.impl.ConfigKeys; -import com.ryderbelserion.fusion.core.api.enums.FileType; -import com.ryderbelserion.fusion.core.api.interfaces.files.ICustomFile; -import com.ryderbelserion.fusion.core.api.utils.AdvUtils; +import com.ryderbelserion.fusion.core.utils.StringUtils; import com.ryderbelserion.fusion.paper.files.types.PaperCustomFile; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; +import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.Optional; public class LegacyColorMigrator extends ICrateMigrator { @@ -27,20 +26,20 @@ public void run() { final List success = new ArrayList<>(); try { - this.config.setProperty(ConfigKeys.command_prefix, AdvUtils.convert(this.config.getProperty(ConfigKeys.command_prefix), true)); - this.config.setProperty(ConfigKeys.inventory_name, AdvUtils.convert(this.config.getProperty(ConfigKeys.inventory_name), true)); + this.config.setProperty(ConfigKeys.command_prefix, StringUtils.convertLegacy(this.config.getProperty(ConfigKeys.command_prefix), true)); + this.config.setProperty(ConfigKeys.inventory_name, StringUtils.convertLegacy(this.config.getProperty(ConfigKeys.inventory_name), true)); - this.config.setProperty(ConfigKeys.menu_button_name, AdvUtils.convert(this.config.getProperty(ConfigKeys.menu_button_name), true)); - this.config.setProperty(ConfigKeys.menu_button_lore, AdvUtils.convert(this.config.getProperty(ConfigKeys.menu_button_lore), true)); + this.config.setProperty(ConfigKeys.menu_button_name, StringUtils.convertLegacy(this.config.getProperty(ConfigKeys.menu_button_name), true)); + this.config.setProperty(ConfigKeys.menu_button_lore, StringUtils.convertLegacy(this.config.getProperty(ConfigKeys.menu_button_lore), true)); - this.config.setProperty(ConfigKeys.next_button_name, AdvUtils.convert(this.config.getProperty(ConfigKeys.next_button_name), true)); - this.config.setProperty(ConfigKeys.next_button_lore, AdvUtils.convert(this.config.getProperty(ConfigKeys.next_button_lore), true)); + this.config.setProperty(ConfigKeys.next_button_name, StringUtils.convertLegacy(this.config.getProperty(ConfigKeys.next_button_name), true)); + this.config.setProperty(ConfigKeys.next_button_lore, StringUtils.convertLegacy(this.config.getProperty(ConfigKeys.next_button_lore), true)); - this.config.setProperty(ConfigKeys.back_button_name, AdvUtils.convert(this.config.getProperty(ConfigKeys.back_button_name), true)); - this.config.setProperty(ConfigKeys.back_button_lore, AdvUtils.convert(this.config.getProperty(ConfigKeys.back_button_lore), true)); + this.config.setProperty(ConfigKeys.back_button_name, StringUtils.convertLegacy(this.config.getProperty(ConfigKeys.back_button_name), true)); + this.config.setProperty(ConfigKeys.back_button_lore, StringUtils.convertLegacy(this.config.getProperty(ConfigKeys.back_button_lore), true)); - this.config.setProperty(ConfigKeys.filler_name, AdvUtils.convert(this.config.getProperty(ConfigKeys.filler_name), true)); - this.config.setProperty(ConfigKeys.filler_lore, AdvUtils.convert(this.config.getProperty(ConfigKeys.filler_lore), true)); + this.config.setProperty(ConfigKeys.filler_name, StringUtils.convertLegacy(this.config.getProperty(ConfigKeys.filler_name), true)); + this.config.setProperty(ConfigKeys.filler_lore, StringUtils.convertLegacy(this.config.getProperty(ConfigKeys.filler_lore), true)); success.add("⤷ config.yml"); @@ -63,72 +62,76 @@ public void run() { failed.add("⤷ messages.yml"); } - final Collection>> customFiles = this.fileManager.getCustomFiles().values(); + final List paths = this.fusion.getFiles(getCratesDirectory(), ".yml"); - customFiles.forEach(key -> { - try { - if (key.isStatic() || !key.isLoaded() || key.getFileType() != FileType.PAPER) return; + for (final Path path : paths) { + final Optional optional = this.fileManager.getPaperFile(path); + + if (optional.isEmpty()) continue; + + final PaperCustomFile customFile = optional.get(); - final PaperCustomFile customFile = (PaperCustomFile) key; + if (!customFile.isLoaded()) continue; - final YamlConfiguration configuration = customFile.getConfiguration(); + final YamlConfiguration configuration = customFile.getConfiguration(); - final ConfigurationSection section = configuration.getConfigurationSection("Crate"); + final ConfigurationSection section = configuration.getConfigurationSection("Crate"); - if (section == null) return; + if (section == null) continue; + try { boolean isSave = false; if (section.contains("CrateName")) { - set(section, "Name", AdvUtils.convert(section.getString("CrateName", " "), true)); + set(section, "Name", StringUtils.convertLegacy(section.getString("CrateName", " "), true)); set(section, "CrateName", null); isSave = true; } else if (section.contains("Name")) { - set(section, "Name", AdvUtils.convert(section.getString("Name", " "), true)); + set(section, "Name", StringUtils.convertLegacy(section.getString("Name", " "), true)); isSave = true; } if (section.contains("Preview-Name")) { - set(section, "Preview.Name", AdvUtils.convert(section.getString("Preview.Name", " "), true)); + set(section, "Preview.Name", StringUtils.convertLegacy(section.getString("Preview.Name", " "), true)); set(section, "Preview-Name", null); isSave = true; } else if (section.contains("Preview.Name")) { - set(section, "Preview.Name", AdvUtils.convert(section.getString("Preview.Name", " "), true)); + set(section, "Preview.Name", StringUtils.convertLegacy(section.getString("Preview.Name", " "), true)); isSave = true; } if (section.contains("Preview.Glass.Name")) { - set(section, "Preview.Glass.Name", AdvUtils.convert(section.getString("Preview.Glass.Name", " "), true)); + set(section, "Preview.Glass.Name", StringUtils.convertLegacy(section.getString("Preview.Glass.Name", " "), true)); isSave = true; } if (section.contains("tier-preview.glass.name")) { - set(section, "tier-preview.glass.name", AdvUtils.convert(section.getString("tier-preview.glass.name", " "), true)); + set(section, "tier-preview.glass.name", StringUtils.convertLegacy(section.getString("tier-preview.glass.name", " "), true)); isSave = true; } if (section.contains("BroadCast")) { - set(section, "BroadCast", AdvUtils.convert(section.getString("BroadCast", " "), true)); + set(section, "BroadCast", StringUtils.convertLegacy(section.getString("BroadCast", " "), true)); isSave = true; } if (section.contains("Lore")) { - set(section, "Lore", AdvUtils.convert(section.getStringList("Lore"), true)); + set(section, "Lore", StringUtils.convertLegacy(section.getStringList("Lore"), true)); isSave = true; } if (section.contains("PhysicalKey")) { - set(section, "PhysicalKey.Name", AdvUtils.convert(section.getString("PhysicalKey.Name", " "), true)); + set(section, "PhysicalKey.Name", StringUtils.convertLegacy(section.getString("PhysicalKey.Name", " "), true)); - set(section, "PhysicalKey.Lore", AdvUtils.convert(section.getStringList("PhysicalKey.Lore"), true)); + set(section, "PhysicalKey.Lore", StringUtils.convertLegacy(section.getStringList("PhysicalKey.Lore"), true)); isSave = true; } @@ -142,13 +145,13 @@ public void run() { if (tierSection == null) continue; if (tierSection.contains("Name")) { - set(tierSection, "Name", AdvUtils.convert(tierSection.getString("Name", " "), true)); + set(tierSection, "Name", StringUtils.convertLegacy(tierSection.getString("Name", " "), true)); isSave = true; } if (tierSection.contains("Lore")) { - set(tierSection, "Lore", AdvUtils.convert(tierSection.getStringList("Name"), true)); + set(tierSection, "Lore", StringUtils.convertLegacy(tierSection.getStringList("Name"), true)); isSave = true; } @@ -164,42 +167,42 @@ public void run() { if (prizeSection == null) continue; if (prizeSection.contains("Lore")) { - set(prizeSection, "DisplayLore", AdvUtils.convert(prizeSection.getStringList("Lore"), true)); + set(prizeSection, "DisplayLore", StringUtils.convertLegacy(prizeSection.getStringList("Lore"), true)); set(prizeSection, "Lore", null); isSave = true; } else if (prizeSection.contains("DisplayLore")) { - set(prizeSection, "DisplayLore", AdvUtils.convert(prizeSection.getStringList("DisplayLore"), true)); + set(prizeSection, "DisplayLore", StringUtils.convertLegacy(prizeSection.getStringList("DisplayLore"), true)); isSave = true; } if (prizeSection.contains("DisplayName")) { - set(prizeSection, "DisplayName", AdvUtils.convert(prizeSection.getString("DisplayName", " "), true)); + set(prizeSection, "DisplayName", StringUtils.convertLegacy(prizeSection.getString("DisplayName", " "), true)); isSave = true; } if (prizeSection.contains("Messages")) { - set(prizeSection, "Messages", AdvUtils.convert(prizeSection.getStringList("Messages"), true)); + set(prizeSection, "Messages", StringUtils.convertLegacy(prizeSection.getStringList("Messages"), true)); isSave = true; } if (prizeSection.contains("Items")) { - set(prizeSection, "Items", AdvUtils.convert(prizeSection.getStringList("Items"), true)); + set(prizeSection, "Items", StringUtils.convertLegacy(prizeSection.getStringList("Items"), true)); isSave = true; } if (prizeSection.contains("Alternative-Prize.Messages")) { - set(prizeSection, "Alternative-Prize.Messages", AdvUtils.convert(prizeSection.getStringList("Alternative-Prize.Messages"), true)); + set(prizeSection, "Alternative-Prize.Messages", StringUtils.convertLegacy(prizeSection.getStringList("Alternative-Prize.Messages"), true)); isSave = true; } if (prizeSection.contains("Alternative-Prize.Items")) { - set(prizeSection, "Alternative-Prize.Items", AdvUtils.convert(prizeSection.getStringList("Alternative-Prize.Items"), true)); + set(prizeSection, "Alternative-Prize.Items", StringUtils.convertLegacy(prizeSection.getStringList("Alternative-Prize.Items"), true)); isSave = true; } @@ -208,13 +211,14 @@ public void run() { if (isSave) { customFile.save(); + customFile.load(); } success.add("⤷ " + customFile.getFileName()); } catch (final Exception exception) { - failed.add("⤷ " + key.getFileName()); + failed.add("⤷ " + customFile.getFileName()); } - }); + } final int convertedCrates = success.size(); final int failedCrates = failed.size(); @@ -226,8 +230,6 @@ public void run() { sendMessage(files, convertedCrates, failedCrates); - this.fileManager.init(new ArrayList<>()); - // reload crates this.crateManager.loadHolograms(); this.crateManager.loadCrates(); diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/NewItemMigrator.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/NewItemMigrator.java index 2e668b4b6..c359246aa 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/NewItemMigrator.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/NewItemMigrator.java @@ -4,18 +4,15 @@ import com.badbones69.crazycrates.paper.commands.crates.types.admin.crates.migrator.ICrateMigrator; import com.badbones69.crazycrates.paper.commands.crates.types.admin.crates.migrator.enums.MigrationType; import com.badbones69.crazycrates.paper.utils.MiscUtils; -import com.ryderbelserion.fusion.core.api.enums.FileType; -import com.ryderbelserion.fusion.core.api.interfaces.files.ICustomFile; -import com.ryderbelserion.fusion.core.api.utils.StringUtils; +import com.ryderbelserion.fusion.core.utils.StringUtils; import com.ryderbelserion.fusion.paper.files.types.PaperCustomFile; import com.ryderbelserion.fusion.paper.utils.ItemUtils; import org.bukkit.block.banner.PatternType; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.inventory.ItemFlag; import org.bukkit.potion.PotionEffectType; -import java.io.File; +import java.nio.file.Path; import java.util.*; public class NewItemMigrator extends ICrateMigrator { @@ -26,22 +23,26 @@ public NewItemMigrator(final CommandSender sender) { @Override public void run() { - final Collection>> customFiles = this.fileManager.getCustomFiles().values(); - final List failed = new ArrayList<>(); final List success = new ArrayList<>(); - customFiles.forEach(key -> { - try { - if (key.isStatic() || !key.isLoaded() || key.getFileType() != FileType.PAPER) return; + final List paths = this.fusion.getFiles(getCratesDirectory(), ".yml"); + + for (final Path path : paths) { + final Optional optional = this.fileManager.getPaperFile(path); + + if (optional.isEmpty()) continue; - final PaperCustomFile customFile = (PaperCustomFile) key; + final PaperCustomFile customFile = optional.get(); + if (!customFile.isLoaded()) continue; + + try { final YamlConfiguration configuration = customFile.getConfiguration(); final ConfigurationSection section = configuration.getConfigurationSection("Crate"); - if (section == null) return; + if (section == null) continue; boolean isSave = false; @@ -158,8 +159,11 @@ public void run() { } } catch (final Exception ignored) {} - if (ItemUtils.getEnchantment(placeholder) != null) { - enchantments.put(option.toLowerCase(), StringUtils.tryParseInt(value).map(Number::intValue).orElse(1)); + final String[] splitter = split.split(":"); + final String enchantment = splitter[0]; + + if (ItemUtils.getEnchantment(enchantment) != null) { + enchantments.put(enchantment.toLowerCase(), StringUtils.tryParseInt(splitter[1]).map(Number::intValue).orElse(1)); final ConfigurationSection enchantmentSection = prizeSection.createSection("Items." + uuid + ".enchantments"); @@ -170,17 +174,6 @@ public void run() { break; } - if (!prizeSection.contains("Items." + uuid + ".hide-tool-tip")) { - for (ItemFlag itemFlag : ItemFlag.values()) { - if (itemFlag.name().equalsIgnoreCase(option)) { - prizeSection.set("Items." + uuid + ".hide-tool-tip", true); - prizeSection.setComments("Items." + uuid + ".hide-tool-tip", Comments.hide_tool_tip.getComments()); - - break; - } - } - } - try { final PatternType patternType = ItemUtils.getPatternType(placeholder); @@ -206,13 +199,14 @@ public void run() { if (isSave) { customFile.save(); + customFile.load(); } success.add("⤷ " + customFile.getFileName()); } catch (final Exception exception) { - failed.add("⤷ " + key.getFileName()); + failed.add("⤷ " + customFile.getFileName()); } - }); + } final int convertedCrates = success.size(); final int failedCrates = failed.size(); @@ -224,8 +218,6 @@ public void run() { sendMessage(files, convertedCrates, failedCrates); - this.fileManager.init(new ArrayList<>()); - // reload crates this.crateManager.loadHolograms(); this.crateManager.loadCrates(); @@ -235,9 +227,4 @@ public void run() { public void set(final ConfigurationSection section, final String path, T value) { section.set(path, value); } - - @Override - public final File getCratesDirectory() { - return new File(this.plugin.getDataFolder(), "crates"); - } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/WeightMigrator.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/WeightMigrator.java index 75647c9cb..07f8854bc 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/WeightMigrator.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/deprecation/WeightMigrator.java @@ -3,16 +3,14 @@ import com.badbones69.crazycrates.paper.utils.MiscUtils; import com.badbones69.crazycrates.paper.commands.crates.types.admin.crates.migrator.ICrateMigrator; import com.badbones69.crazycrates.paper.commands.crates.types.admin.crates.migrator.enums.MigrationType; -import com.ryderbelserion.fusion.core.api.enums.FileType; -import com.ryderbelserion.fusion.core.api.interfaces.files.ICustomFile; import com.ryderbelserion.fusion.paper.files.types.PaperCustomFile; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; -import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import java.util.Optional; public class WeightMigrator extends ICrateMigrator { @@ -22,22 +20,26 @@ public WeightMigrator(final CommandSender sender) { @Override public void run() { - final Collection>> customFiles = this.fileManager.getCustomFiles().values(); - final List failed = new ArrayList<>(); final List success = new ArrayList<>(); - customFiles.forEach(key -> { - try { - if (key.isStatic() || !key.isLoaded() || key.getFileType() != FileType.PAPER) return; + final List paths = this.fusion.getFiles(getCratesDirectory(), ".yml"); + + for (final Path path : paths) { + final Optional optional = this.fileManager.getPaperFile(path); - final PaperCustomFile customFile = (PaperCustomFile) key; + if (optional.isEmpty()) continue; + final PaperCustomFile customFile = optional.get(); + + if (!customFile.isLoaded()) continue; + + try { final YamlConfiguration configuration = customFile.getConfiguration(); final ConfigurationSection section = configuration.getConfigurationSection("Crate"); - if (section == null) return; + if (section == null) continue; boolean isSave = false; @@ -94,16 +96,16 @@ public void run() { prizeSection.set("Weight", MiscUtils.calculateWeight(chance, maxRange)); } } - if (isSave) { customFile.save(); + customFile.load(); } success.add("⤷ " + customFile.getFileName()); } catch (final Exception exception) { - failed.add("⤷ " + key.getFileName()); + failed.add("⤷ " + customFile.getFileName()); } - }); + } final int convertedCrates = success.size(); final int failedCrates = failed.size(); @@ -115,8 +117,6 @@ public void run() { sendMessage(files, convertedCrates, failedCrates); - this.fileManager.init(new ArrayList<>()); - // reload crates this.crateManager.loadHolograms(); this.crateManager.loadCrates(); @@ -126,9 +126,4 @@ public void run() { public void set(final ConfigurationSection section, final String path, T value) { section.set(path, value); } - - @Override - public final File getCratesDirectory() { - return new File(this.plugin.getDataFolder(), "crates"); - } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/plugins/ExcellentCratesMigrator.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/plugins/ExcellentCratesMigrator.java index 272bac8ed..b02e290bc 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/plugins/ExcellentCratesMigrator.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/crates/migrator/types/plugins/ExcellentCratesMigrator.java @@ -4,8 +4,8 @@ import com.badbones69.crazycrates.paper.api.enums.other.keys.FileKeys; import com.badbones69.crazycrates.paper.commands.crates.types.admin.crates.migrator.ICrateMigrator; import com.badbones69.crazycrates.paper.commands.crates.types.admin.crates.migrator.enums.MigrationType; -import com.badbones69.crazycrates.paper.utils.MiscUtils; -import com.ryderbelserion.fusion.core.api.utils.AdvUtils; +import com.ryderbelserion.fusion.core.utils.StringUtils; +import com.ryderbelserion.fusion.files.enums.FileAction; import com.ryderbelserion.fusion.paper.files.types.PaperCustomFile; import com.ryderbelserion.fusion.paper.utils.ItemUtils; import io.papermc.paper.datacomponent.DataComponentTypes; @@ -28,6 +28,8 @@ import us.crazycrew.crazycrates.api.users.UserManager; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -89,15 +91,19 @@ public void run() { return; } - final File directory = getCratesDirectory(); + final Path directory = getCratesDirectory(); - if (!directory.exists()) { - directory.mkdirs(); + if (!Files.exists(directory)) { + try { + Files.createDirectory(directory); + } catch (final IOException exception) { + this.fusion.log("warn", "Could not create directory {}, {}", directory, exception); + } } final File crateDirectory = CratesAPI.PLUGIN.getDataFolder(); - YamlConfiguration locationData = FileKeys.locations.getConfiguration(); + final YamlConfiguration locationData = FileKeys.locations.getConfiguration(); final @NotNull Collection crates = CratesAPI.getCrateManager().getCrates(); @@ -111,10 +117,10 @@ public void run() { final String crateName = crate.getFile().getName(); final String strippedName = crateName.replace(".yml", ""); - final File crateFile = new File(directory, crateName); + final Path path = directory.resolve(crateName); - if (crateFile.exists()) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} already exists in {}.", crateName, directory.getName()); + if (Files.exists(path)) { + this.fusion.log("warn", "Crate {} already exists in {}.", crateName, directory.getFileName()); failed.add("⤷ " + crateName); @@ -122,14 +128,14 @@ public void run() { } try { - crateFile.createNewFile(); + Files.createFile(path); } catch (final IOException exception) { - if (MiscUtils.isLogging()) this.logger.warn("Failed to create crate file {} in {}.", crateName, directory.getName(), exception); + this.fusion.log("warn", "Failed to create crate file {} in {}.", crateName, directory.getFileName(), exception); failed.add("⤷ " + crateName); } - final PaperCustomFile customFile = new PaperCustomFile(crateFile.toPath(), new ArrayList<>()).load(); + final PaperCustomFile customFile = new PaperCustomFile(this.fileManager, path, consumer -> consumer.addAction(FileAction.ALREADY_EXTRACTED)).load(); final YamlConfiguration configuration = customFile.getConfiguration(); @@ -183,8 +189,8 @@ public void run() { menuFile.getStringList("Crate.Lore").forEach(line -> previewLore.add(line.replaceAll("%player% is opening a %crate%.".replace("%crate%", AdvUtils.convert(crate.getName()))); + set(root, "BroadCast", "%prefix%%player% is opening a %crate%.".replace("%crate%", StringUtils.convertLegacy(crate.getName()))); set(root, "opening-command.toggle", false); set(root, "opening-command.commands", List.of("put your command here.")); @@ -246,7 +252,7 @@ public void run() { final String itemName = crateConfig.getString("Item.Name", ""); - set(root, "Preview-Name", AdvUtils.convert(itemName.isEmpty() ? crateConfig.getString("Name", "%crate%").replace("%crate%", strippedName) : itemName + " Preview")); + set(root, "Preview-Name", StringUtils.convertLegacy(itemName.isEmpty() ? crateConfig.getString("Name", "%crate%").replace("%crate%", strippedName) : itemName + " Preview")); if (crateItem.hasData(DataComponentTypes.CUSTOM_MODEL_DATA)) { @Nullable final CustomModelData builder = crateItem.getData(DataComponentTypes.CUSTOM_MODEL_DATA); @@ -277,7 +283,7 @@ public void run() { crate.getName() ); - hologramText.add(AdvUtils.convert(filtered)); + hologramText.add(StringUtils.convertLegacy(filtered)); }); set(root, "Hologram.Message", hologramText); @@ -293,10 +299,10 @@ public void run() { set(root, "PhysicalKey.Data", ItemUtils.toBase64(itemStack)); - set(root, "PhysicalKey.Name", AdvUtils.convert(key.getName().replace("#", "#&"))); + set(root, "PhysicalKey.Name", StringUtils.convertLegacy(key.getName().replace("#", "#&"))); set(root, "PhysicalKey.Item", itemStack.getType().getKey().getKey()); - set(root, "PhysicalKey.Lore", AdvUtils.convert(key.getConfig().getStringList("Lore"))); + set(root, "PhysicalKey.Lore", StringUtils.convertLegacy(key.getConfig().getStringList("Lore"))); set(root, "PhysicalKey.Glowing", config.contains("Item.Enchants")); } @@ -314,12 +320,12 @@ public void run() { final List lore = itemLore.lines(); if (!lore.isEmpty()) { - set(root, "Prizes." + id + ".DisplayLore", AdvUtils.fromComponent(lore)); + set(root, "Prizes." + id + ".DisplayLore", StringUtils.fromComponent(lore)); } } } - set(root, "Prizes." + id + ".DisplayName", AdvUtils.convert(reward.getName().replace("#", "#&"))); + set(root, "Prizes." + id + ".DisplayName", StringUtils.convertLegacy(reward.getName().replace("#", "#&"))); set(root, "Prizes." + id + ".Commands", reward.getCommands()); @@ -366,7 +372,7 @@ public void run() { }); }); - this.fileManager.addFile(customFile.save()); + this.fileManager.addFile(customFile.getPath(), customFile.save()); success.add("⤷ " + crateName); } @@ -390,9 +396,4 @@ public void run() { public void set(final ConfigurationSection section, final String path, T value) { section.set(path, value); } - - @Override - public final File getCratesDirectory() { - return new File(this.plugin.getDataFolder(), "crates"); - } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/keys/CommandGive.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/keys/CommandGive.java index f03c67369..913f4e940 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/keys/CommandGive.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/keys/CommandGive.java @@ -6,7 +6,7 @@ import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.utils.MiscUtils; import com.badbones69.crazycrates.paper.commands.crates.types.BaseCommand; -import com.badbones69.crazycrates.paper.api.PlayerBuilder; +import com.ryderbelserion.fusion.paper.builders.PlayerBuilder; import dev.triumphteam.cmd.bukkit.annotation.Permission; import dev.triumphteam.cmd.core.annotations.*; import dev.triumphteam.cmd.core.argument.keyed.Flags; diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/keys/CommandOpen.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/keys/CommandOpen.java index e0f04845e..a2cbc63f6 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/keys/CommandOpen.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/keys/CommandOpen.java @@ -76,7 +76,7 @@ public void open(Player player, @ArgName("crate") @Suggestion("crates") String c if (crateType == CrateType.menu) { Messages.internal_error.sendMessage(player); - if (MiscUtils.isLogging()) this.logger.error("An error has occurred: The crate type is Menu for the crate named {}", crateName); + this.fusion.log("error", "An error has occurred: The crate type is Menu for the crate named {}", crateName); return; } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/keys/CommandTake.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/keys/CommandTake.java index d815ee19a..c89060c6b 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/keys/CommandTake.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/admin/keys/CommandTake.java @@ -3,7 +3,7 @@ import com.badbones69.crazycrates.paper.api.enums.Messages; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.commands.crates.types.BaseCommand; -import com.badbones69.crazycrates.paper.api.PlayerBuilder; +import com.ryderbelserion.fusion.paper.builders.PlayerBuilder; import dev.triumphteam.cmd.bukkit.annotation.Permission; import dev.triumphteam.cmd.core.annotations.ArgName; import dev.triumphteam.cmd.core.annotations.Command; diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/player/CommandKey.java b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/player/CommandKey.java index 10da4e4e2..d5f42d905 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/player/CommandKey.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/commands/crates/types/player/CommandKey.java @@ -2,13 +2,11 @@ import com.badbones69.crazycrates.paper.CrazyCrates; import com.badbones69.crazycrates.paper.api.enums.Messages; -import com.badbones69.crazycrates.paper.api.enums.other.Plugins; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.managers.BukkitUserManager; import com.badbones69.crazycrates.paper.tasks.crates.CrateManager; import dev.triumphteam.cmd.bukkit.annotation.Permission; import dev.triumphteam.cmd.core.annotations.*; -import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.permissions.PermissionDefault; @@ -32,11 +30,11 @@ public class CommandKey { @Permission(value = "crazycrates.keys", def = PermissionDefault.TRUE) @Syntax("/keys") public void personal(Player player) { - getKeys(player, player, Messages.virtual_keys_header.getMessage( + getKeys(player, player, Messages.virtual_keys_header.getString( player, "{crates_opened}", String.valueOf(userManager.getTotalCratesOpened(player.getUniqueId())) - ), Messages.no_virtual_key.getMessage(player)); + ), Messages.no_virtual_key.getString(player)); } @Command("view") @@ -61,10 +59,10 @@ public void view(CommandSender sender, @ArgName("player") @Optional @Suggestion( return; } - getKeys(target, sender, Messages.other_player_no_keys_header.getMessage(target, Map.of( + getKeys(target, sender, Messages.other_player_no_keys_header.getString(target, Map.of( "{crates_opened}", String.valueOf(userManager.getTotalCratesOpened(target.getUniqueId())), "{player}", targetName - )), Messages.other_player_no_keys.getMessage(target, "{player}", targetName)); + )), Messages.other_player_no_keys.getString(target, "{player}", targetName)); } /** @@ -96,7 +94,7 @@ private void getKeys(@NotNull final Player player, @NotNull final CommandSender if (amount > 0) { hasKeys = true; - message.add(Messages.per_crate.getMessage(player, Map.of( + message.add(Messages.per_crate.getString(player, Map.of( "{crate_opened}", String.valueOf(userManager.getCrateOpened(uuid, crate.getFileName())), "{keys}", String.valueOf(amount), "{crate}", crate.getCrateName() @@ -104,22 +102,6 @@ private void getKeys(@NotNull final Player player, @NotNull final CommandSender } } - if (Plugins.placeholder_api.isEnabled() ) { - if (sender instanceof Player person) { - if (hasKeys) { - message.forEach(line -> person.sendRichMessage(PlaceholderAPI.setPlaceholders(person, line))); - - return; - } - - sender.sendRichMessage(PlaceholderAPI.setPlaceholders(person, content)); - - return; - } - - return; - } - if (hasKeys) { message.forEach(sender::sendRichMessage); diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/MiscListener.java b/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/MiscListener.java index a09ffe22f..e07ff6d7e 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/MiscListener.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/MiscListener.java @@ -7,7 +7,6 @@ import com.badbones69.crazycrates.paper.api.objects.gui.GuiSettings; import com.badbones69.crazycrates.paper.tasks.menus.CratePrizeMenu; import com.badbones69.crazycrates.paper.api.objects.Crate; -import com.badbones69.crazycrates.paper.api.objects.Prize; import com.badbones69.crazycrates.paper.api.objects.Tier; import com.badbones69.crazycrates.paper.managers.BukkitUserManager; import com.badbones69.crazycrates.paper.managers.InventoryManager; @@ -166,13 +165,7 @@ public void onInventoryCloseEvent(InventoryCloseEvent event) { final Tier tier = this.crateManager.getTier(crate, item); if (tier != null) { - Prize prize = crate.pickPrize(player, tier); - - for (int stop = 0; prize == null && stop <= 2000; stop++) { //todo() wtf? - prize = crate.pickPrize(player, tier); - } - - PrizeManager.givePrize(player, crate, prize); + PrizeManager.givePrize(player, crate, crate.pickPrize(player, tier)); playSound = true; } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/CrateOpenListener.java b/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/CrateOpenListener.java index 503503cb3..28bf7c886 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/CrateOpenListener.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/CrateOpenListener.java @@ -2,7 +2,6 @@ import ch.jalu.configme.SettingsManager; import com.badbones69.crazycrates.paper.CrazyCrates; -import com.badbones69.crazycrates.paper.api.enums.other.Plugins; import com.badbones69.crazycrates.core.config.ConfigManager; import com.badbones69.crazycrates.core.config.impl.ConfigKeys; import com.badbones69.crazycrates.paper.managers.BukkitUserManager; @@ -11,21 +10,24 @@ import com.badbones69.crazycrates.paper.api.enums.Messages; import com.badbones69.crazycrates.paper.api.events.CrateOpenEvent; import com.badbones69.crazycrates.paper.api.objects.Crate; -import com.badbones69.crazycrates.paper.utils.MiscUtils; -import com.ryderbelserion.fusion.core.api.utils.AdvUtils; -import me.clip.placeholderapi.PlaceholderAPI; +import com.badbones69.crazycrates.paper.utils.CommandUtils; +import com.ryderbelserion.fusion.paper.FusionPaper; import org.bukkit.Server; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.configuration.file.YamlConfiguration; import us.crazycrew.crazycrates.api.enums.types.CrateType; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class CrateOpenListener implements Listener { private final CrazyCrates plugin = CrazyCrates.getPlugin(); + private final FusionPaper fusion = this.plugin.getFusion(); + private final Server server = this.plugin.getServer(); private final CrateManager crateManager = this.plugin.getCrateManager(); @@ -90,35 +92,39 @@ public void onCrateOpen(CrateOpenEvent event) { final String broadcastMessage = configuration.getString("Crate.BroadCast", ""); final boolean broadcastToggle = configuration.getBoolean("Crate.OpeningBroadCast", false); - if (broadcastToggle && crateType != CrateType.cosmic && !event.isSilent()) { //todo() add a permission? - if (!broadcastMessage.isBlank()) { - final String builder = Plugins.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(player, broadcastMessage) : broadcastMessage; + if (broadcastToggle && crateType != CrateType.cosmic && !event.isSilent() && !broadcastMessage.isBlank()) { + this.server.broadcast(this.fusion.parse(player, broadcastMessage, new HashMap<>() {{ + put("{prefix}", config.getProperty(ConfigKeys.command_prefix)); + put("{player}", player.getName()); + put("{crate}", fancyName); - this.server.broadcast(AdvUtils.parse(builder.replaceAll("%crate%", fancyName) - .replaceAll("%prefix%", this.config.getProperty(ConfigKeys.command_prefix)) - .replaceAll("%player%", playerName))); - } + put("%prefix%", config.getProperty(ConfigKeys.command_prefix)); + put("%player%", player.getName()); + put("%crate%", fancyName); + }})); } - final boolean commandToggle = configuration.contains("Crate.opening-command") && configuration.getBoolean("Crate.opening-command.toggle"); + final boolean commandToggle = configuration.getBoolean("Crate.opening-command.toggle", false); if (commandToggle) { final List commands = configuration.getStringList("Crate.opening-command.commands"); if (!commands.isEmpty()) { - commands.forEach(line -> { - String builder; - - if (Plugins.placeholder_api.isEnabled() ) { - builder = PlaceholderAPI.setPlaceholders(player, line.replaceAll("%crate%", fileName) - .replaceAll("%prefix%", this.config.getProperty(ConfigKeys.command_prefix)) - .replaceAll("%player%", playerName)); - } else { - builder = line.replaceAll("%crate%", fileName).replaceAll("%prefix%", this.config.getProperty(ConfigKeys.command_prefix)).replaceAll("%player%", playerName); - } - - MiscUtils.sendCommand(builder); - }); + final Map placeholders = new HashMap<>() {{ + put("%crate%", fileName); + put("%prefix%", config.getProperty(ConfigKeys.command_prefix)); + put("%player%", playerName); + + put("{crate}", fileName); + put("{prefix}", config.getProperty(ConfigKeys.command_prefix)); + put("{player}", playerName); + }}; + + for (final String command : commands) { + if (command.isEmpty()) continue; + + CommandUtils.executeCommand(player, command, placeholders); + } } } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/types/CosmicCrateListener.java b/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/types/CosmicCrateListener.java index b5372f1af..f0e087cbf 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/types/CosmicCrateListener.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/types/CosmicCrateListener.java @@ -1,15 +1,13 @@ package com.badbones69.crazycrates.paper.listeners.crates.types; import ch.jalu.configme.SettingsManager; -import com.badbones69.crazycrates.paper.api.enums.other.Plugins; import com.badbones69.crazycrates.paper.api.events.PlayerReceiveKeyEvent; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; import com.badbones69.crazycrates.paper.managers.events.EventManager; import com.badbones69.crazycrates.paper.managers.events.enums.EventType; -import com.ryderbelserion.fusion.core.api.utils.AdvUtils; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import io.papermc.paper.persistence.PersistentDataContainerView; -import me.clip.placeholderapi.PlaceholderAPI; import net.kyori.adventure.sound.Sound; import com.badbones69.crazycrates.core.config.ConfigManager; import com.badbones69.crazycrates.core.config.impl.ConfigKeys; @@ -42,7 +40,6 @@ import com.badbones69.crazycrates.paper.tasks.crates.CrateManager; import com.badbones69.crazycrates.paper.utils.MiscUtils; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.TimerTask; import java.util.UUID; @@ -51,7 +48,7 @@ public class CosmicCrateListener implements Listener { private final CrazyCrates plugin = CrazyCrates.getPlugin(); - private final ComponentLogger logger = this.plugin.getComponentLogger(); + private final FusionPaper fusion = this.plugin.getFusion(); private final Server server = this.plugin.getServer(); @@ -114,11 +111,7 @@ public void onPrizeReceive(InventoryClickEvent event) { // If tier is null, return if (tier == null) return; - Prize prize = crate.pickPrize(player, tier); - - for (int stop = 0; prize == null && stop <= 2000; stop++) { //todo() wtf? - prize = crate.pickPrize(player, tier); - } + final Prize prize = crate.pickPrize(player, tier); if (prize == null) return; @@ -199,10 +192,13 @@ public void onMysteryBoxClick(InventoryClickEvent event) { // Gets the tier name. final String tierName = tier.getName(); + final String number = String.valueOf(pickedSlot); + // Get item builder. - LegacyItemBuilder builder = cosmicCrateManager.getPickedCrate().setPlayer(player) - .addNamePlaceholder("%Slot%", String.valueOf(pickedSlot)) - .addLorePlaceholder("%Slot%", String.valueOf(pickedSlot)); + final ItemBuilder builder = cosmicCrateManager.getPickedCrate() + .addPlaceholder("{slot}", number) + .addPlaceholder("%slot%", number) + .addPlaceholder("%Slot%", number); // Set the amount. builder.setAmount(pickedSlot); @@ -211,7 +207,7 @@ public void onMysteryBoxClick(InventoryClickEvent event) { cosmicCrateManager.setTier(builder, tierName); // Overwrite the current item. - event.setCurrentItem(builder.asItemStack()); + event.setCurrentItem(builder.asItemStack(player)); // Add the picked prize. cosmicCrateManager.addPickedPrize(player, slot, tier); @@ -222,10 +218,13 @@ public void onMysteryBoxClick(InventoryClickEvent event) { } else if (container.has(ItemKeys.cosmic_picked_crate.getNamespacedKey())) { final Tier tier = this.crateManager.getTier(player, slot); + final String number = String.valueOf(pickedSlot); + // Get item builder. - LegacyItemBuilder builder = cosmicCrateManager.getMysteryCrate().setPlayer(player) - .addNamePlaceholder("%Slot%", String.valueOf(pickedSlot)) - .addLorePlaceholder("%Slot%", String.valueOf(pickedSlot)); + final ItemBuilder builder = cosmicCrateManager.getMysteryCrate() + .addPlaceholder("{slot}", number) + .addPlaceholder("%slot%", number) + .addPlaceholder("%Slot%", number); // Set the amount. builder.setAmount(pickedSlot); @@ -262,7 +261,8 @@ public void onMysteryBoxClick(InventoryClickEvent event) { // If they don't have enough keys. if (value) { - Map placeholders = new HashMap<>(); + final Map placeholders = new HashMap<>(); + placeholders.put("{crate}", fancyName); placeholders.put("{key}", crate.getKeyName()); @@ -327,14 +327,16 @@ public void onMysteryBoxClick(InventoryClickEvent event) { final String broadcastMessage = configuration.getString("Crate.BroadCast", ""); final boolean broadcastToggle = configuration.getBoolean("Crate.OpeningBroadCast", false); - if (broadcastToggle) { //todo() add a permission? - if (!broadcastMessage.isBlank()) { - String builder = Plugins.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(player, broadcastMessage) : broadcastMessage; + if (broadcastToggle && !broadcastMessage.isBlank()) { + this.server.broadcast(this.fusion.parse(player, broadcastMessage, new HashMap<>() {{ + put("{prefix}", config.getProperty(ConfigKeys.command_prefix)); + put("{player}", player.getName()); + put("{crate}", fancyName); - this.server.broadcast(AdvUtils.parse(builder.replaceAll("%crate%", fancyName) - .replaceAll("%prefix%", this.config.getProperty(ConfigKeys.command_prefix)) - .replaceAll("%player%", player.getName()))); - } + put("%prefix%", config.getProperty(ConfigKeys.command_prefix)); + put("%player%", player.getName()); + put("%crate%", fancyName); + }})); } EventManager.logEvent(EventType.event_crate_opened, player.getName(), player, crate, type, 1); @@ -376,7 +378,7 @@ public void run() { Messages.key_refund.sendMessage(player, "{crate}", fancyName); - if (MiscUtils.isLogging()) logger.error("An issue occurred when the user {} was using the {} crate and so they were issued a key refund.", player.getName(), fileName, exception); + fusion.log("error", "An issue occurred when the user {} was using the {} crate and so they were issued a key refund.", player.getName(), fileName, exception); // Play a sound crate.playSound(player, player.getLocation(), "stop-sound", "block.anvil.place", Sound.Source.MASTER); @@ -440,7 +442,7 @@ private void showRewards(@NotNull final Player player, @NotNull final InventoryV player.updateInventory(); - if (ConfigManager.getConfig().getProperty(ConfigKeys.cosmic_crate_timeout)) { + if (config.getProperty(ConfigKeys.cosmic_crate_timeout)) { this.crateManager.addCrateTask(player, new TimerTask() { @Override public void run() { @@ -457,6 +459,14 @@ public void run() { "The task has been cancelled, They have been given their prizes and the gui is closed." ).forEach(logger::info); } + new FoliaScheduler(plugin, null, player) { + @Override + public void run() { + player.closeInventory(InventoryCloseEvent.Reason.UNLOADED); + } + }.runNow(); + + fusion.log("warn", "{} spent too long looking at the gui, instead of collecting their prizes. The task is cancelled, andd they now have their prizes."); } }, 10000L); } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/types/QuadCrateListener.java b/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/types/QuadCrateListener.java index 5a605a8ca..dd22e5b18 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/types/QuadCrateListener.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/types/QuadCrateListener.java @@ -1,8 +1,8 @@ package com.badbones69.crazycrates.paper.listeners.crates.types; import com.badbones69.crazycrates.paper.api.PrizeManager; -import com.badbones69.crazycrates.paper.utils.ItemUtils; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import org.bukkit.Location; @@ -39,7 +39,7 @@ public class QuadCrateListener implements Listener { private final CrazyCrates plugin = CrazyCrates.getPlugin(); - private final ComponentLogger logger = this.plugin.getComponentLogger(); + private final FusionPaper fusion = this.plugin.getFusion(); private final SessionManager sessionManager = new SessionManager(); @@ -85,7 +85,7 @@ public void onChestClick(PlayerInteractEvent event) { display.editPersistentDataContainer(container -> container.set(ItemKeys.crate_prize.getNamespacedKey(), PersistentDataType.STRING, "1")); // Convert the item stack to item builder. - final ItemStack itemStack = ItemUtils.convertItemStack(display).asItemStack(); + final ItemStack itemStack = display.clone(); final Location location = block.getLocation(); @@ -100,10 +100,7 @@ public void run() { final String crateName = prize.getCrateName(); final String prizeName = prize.getPrizeName(); - List.of( - "A prize could not be given due to an invalid display item for this prize.", - "Crate: %s Prize: %s" - ).forEach(line -> logger.warn(String.format(line, crateName, prizeName), exception)); + fusion.log("warn", "A prize could not be given, due to an invalid display item for the prize, Crate: {}, Prize: {}, Exception: {}", crateName, prizeName, exception); cancel(); diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/types/WarCrateListener.java b/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/types/WarCrateListener.java index d7d3e6acd..d29d2dca5 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/types/WarCrateListener.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/listeners/crates/types/WarCrateListener.java @@ -4,7 +4,7 @@ import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.api.objects.Prize; import com.badbones69.crazycrates.paper.api.PrizeManager; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import net.kyori.adventure.sound.Sound; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/managers/BukkitUserManager.java b/paper/src/main/java/com/badbones69/crazycrates/paper/managers/BukkitUserManager.java index a8f5d6795..9b2c10492 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/managers/BukkitUserManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/managers/BukkitUserManager.java @@ -7,9 +7,8 @@ import com.badbones69.crazycrates.core.config.ConfigManager; import com.badbones69.crazycrates.core.config.impl.ConfigKeys; import com.badbones69.crazycrates.paper.tasks.crates.CrateManager; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; -import net.kyori.adventure.text.logger.slf4j.ComponentLogger; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.inventory.EntityEquipment; @@ -36,12 +35,12 @@ public class BukkitUserManager extends UserManager { private final CrazyCrates plugin = CrazyCrates.getPlugin(); + private final FusionPaper fusion = this.plugin.getFusion(); + private final Server server = this.plugin.getServer(); private final PluginManager pluginManager = this.server.getPluginManager(); - private final ComponentLogger logger = this.plugin.getComponentLogger(); - private final CrateManager crateManager = this.plugin.getCrateManager(); private final FileKeys data = FileKeys.data; @@ -59,7 +58,7 @@ public int getVirtualKeys(@NotNull final UUID uuid, @NotNull final String crateN @Override public void addVirtualKeys(@NotNull final UUID uuid, @NotNull final String crateName, final int amount) { if (isPlayerNull(uuid)) { - if (MiscUtils.isLogging()) this.logger.warn("Player with the uuid: {} is null.", uuid); + this.fusion.log("warn", "Player with the uuid: {} is null.", uuid); return; } @@ -67,7 +66,7 @@ public void addVirtualKeys(@NotNull final UUID uuid, @NotNull final String crate final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return; } @@ -90,7 +89,7 @@ public void addVirtualKeys(@NotNull final UUID uuid, @NotNull final String crate @Override public void setKeys(@NotNull final UUID uuid, @NotNull final String crateName, final int amount) { if (isPlayerNull(uuid)) { - if (MiscUtils.isLogging()) this.logger.warn("Player with the uuid: {} is null.", uuid); + this.fusion.log("warn", "Player with the uuid: {} is null.", uuid); return; } @@ -98,7 +97,7 @@ public void setKeys(@NotNull final UUID uuid, @NotNull final String crateName, f final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return; } @@ -122,7 +121,7 @@ private boolean isPlayerNull(@NotNull final UUID uuid) { @Override public void addKeys(@NotNull final UUID uuid, @NotNull final String crateName, @NotNull final KeyType keyType, final int amount) { if (isPlayerNull(uuid)) { - if (MiscUtils.isLogging()) this.logger.warn("Player with the uuid {} is null.", uuid); + this.fusion.log("warn", "Player with the uuid {} is null.", uuid); return; } @@ -130,7 +129,7 @@ public void addKeys(@NotNull final UUID uuid, @NotNull final String crateName, @ final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return; } @@ -173,7 +172,7 @@ public int getTotalKeys(@NotNull final UUID uuid, @NotNull final String crateNam @Override public int getPhysicalKeys(@NotNull final UUID uuid, @NotNull final String crateName) { if (isPlayerNull(uuid)) { - if (MiscUtils.isLogging()) this.logger.warn("Player with the uuid {} is null.", uuid); + this.fusion.log("warn", "Player with the uuid {} is null.", uuid); return 0; } @@ -181,7 +180,7 @@ public int getPhysicalKeys(@NotNull final UUID uuid, @NotNull final String crate final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return 0; } @@ -202,7 +201,7 @@ public int getPhysicalKeys(@NotNull final UUID uuid, @NotNull final String crate @Override public boolean takeKeys(@NotNull final UUID uuid, @NotNull final String crateName, @NotNull final KeyType keyType, final int amount, final boolean checkHand) { if (isPlayerNull(uuid)) { - if (MiscUtils.isLogging()) this.logger.warn("Player with the uuid {} is null.", uuid); + this.fusion.log("warn", "Player with the uuid {} is null.", uuid); return false; } @@ -210,7 +209,7 @@ public boolean takeKeys(@NotNull final UUID uuid, @NotNull final String crateNam final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return false; } @@ -319,7 +318,7 @@ public boolean hasPhysicalKey(@NotNull final UUID uuid, @NotNull final String cr final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return false; } @@ -357,7 +356,7 @@ public boolean addOfflineKeys(@NotNull final UUID uuid, @NotNull final String cr final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return false; } @@ -385,7 +384,7 @@ public boolean addOfflineKeys(@NotNull final UUID uuid, @NotNull final String cr return true; } catch (final Exception exception) { - if (MiscUtils.isLogging()) this.logger.error("Could not add keys to offline player with uuid: {}", uuid, exception); + this.fusion.log("error", "Could not add keys to offline player with uuid: {}", uuid, exception); return false; } @@ -396,7 +395,7 @@ public boolean takeOfflineKeys(@NotNull final UUID uuid, @NotNull final String c final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return false; } @@ -430,7 +429,7 @@ public boolean takeOfflineKeys(@NotNull final UUID uuid, @NotNull final String c return true; } catch (final Exception exception) { - if (MiscUtils.isLogging()) this.logger.error("Could not take keys from offline player with uuid: {}", uuid, exception); + this.fusion.log("error", "Could not take keys from offline player with uuid: {}", uuid, exception); return false; } @@ -587,7 +586,7 @@ public int getCrateOpened(@NotNull final UUID uuid, @NotNull final String crateN final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return 0; } @@ -600,7 +599,7 @@ public void addOpenedCrate(@NotNull final UUID uuid, @NotNull final String crate final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return; } @@ -637,7 +636,7 @@ public void addOpenedCrate(@NotNull final UUID uuid, @NotNull final String crate final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return; } @@ -675,7 +674,7 @@ public int getCrateRespin(@NotNull final UUID uuid, @NotNull final String crateN final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return 0; } @@ -687,7 +686,7 @@ public void addRespinPrize(@NotNull final UUID uuid, @NotNull final String crate final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return; } @@ -705,7 +704,7 @@ public final boolean hasRespinPrize(@NotNull final UUID uuid, @NotNull final Str final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return false; } @@ -721,7 +720,7 @@ public void removeRespinPrize(@NotNull final UUID uuid, @NotNull final String cr final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return; } @@ -745,7 +744,7 @@ public void removeRespinPrize(@NotNull final UUID uuid, @NotNull final String cr final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return ""; } @@ -761,7 +760,7 @@ public void removeRespinCrate(@NotNull final UUID uuid, @NotNull final String cr final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return; } @@ -787,7 +786,7 @@ public void addRespinCrate(@NotNull final UUID uuid, @NotNull final String crate final Crate crate = isCrateInvalid(crateName); if (crate == null) { - if (MiscUtils.isLogging()) this.logger.warn("Crate {} doesn't exist.", crateName); + this.fusion.log("warn", "Crate {} doesn't exist.", crateName); return; } @@ -820,39 +819,4 @@ public void addRespinCrate(@NotNull final UUID uuid, @NotNull final String crate return this.crateManager.getCrateFromName(crateName); } - - /** - * Adds internal placeholders to the itembuilder. - * - * @param itemBuilder the itembuilder - * @param crate the crate - * @return the itembuilder - */ - public LegacyItemBuilder addPlaceholders(@NotNull final LegacyItemBuilder itemBuilder, @NotNull final Crate crate) { - final String fileName = crate.getFileName(); - - if (fileName.isEmpty()) return itemBuilder; - - final UUID uuid = itemBuilder.getPlayer(); - - if (uuid == null) return itemBuilder; - - final int virtualKeys = getVirtualKeys(uuid, fileName); - final int physicalKeys = getPhysicalKeys(uuid, fileName); - - final int totalKeys = virtualKeys + physicalKeys; - - final int openedCrates = getCrateOpened(uuid, fileName); - - final NumberFormat instance = NumberFormat.getNumberInstance(); - - return itemBuilder.addNamePlaceholder("%keys%", instance.format(virtualKeys)) - .addNamePlaceholder("%keys_physical%", instance.format(physicalKeys)) - .addNamePlaceholder("%keys_total%", instance.format(totalKeys)) - .addNamePlaceholder("%crate_opened%", instance.format(openedCrates)) - .addNamePlaceholder("%keys_raw%", String.valueOf(virtualKeys)) - .addNamePlaceholder("%keys_physical_raw%", String.valueOf(physicalKeys)) - .addNamePlaceholder("%keys_total_raw%", String.valueOf(totalKeys)) - .addNamePlaceholder("%crate_opened_raw", String.valueOf(openedCrates)); - } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/managers/InventoryManager.java b/paper/src/main/java/com/badbones69/crazycrates/paper/managers/InventoryManager.java index 7dc098ceb..20b6cc509 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/managers/InventoryManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/managers/InventoryManager.java @@ -7,8 +7,9 @@ import com.badbones69.crazycrates.paper.api.enums.other.keys.ItemKeys; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.api.objects.Tier; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; -import com.ryderbelserion.fusion.paper.api.builders.gui.types.PaginatedGui; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.builders.gui.types.PaginatedGui; +import net.kyori.adventure.audience.Audience; import org.bukkit.Server; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryCloseEvent; @@ -31,52 +32,53 @@ public class InventoryManager { private final CrazyCrates plugin = CrazyCrates.getPlugin(); private final Server server = this.plugin.getServer(); - private LegacyItemBuilder menuButton; - private LegacyItemBuilder nextButton; - private LegacyItemBuilder backButton; + private ItemBuilder menuButton; + private ItemBuilder nextButton; + private ItemBuilder backButton; public void loadButtons() { final ModelData menuModelData = this.config.getProperty(ConfigKeys.menu_button_item_model); - this.menuButton = new LegacyItemBuilder(this.plugin).withType(this.config.getProperty(ConfigKeys.menu_button_item).toLowerCase()) - .setDisplayName(this.config.getProperty(ConfigKeys.menu_button_name)) - .setDisplayLore(this.config.getProperty(ConfigKeys.menu_button_lore)) - .setCustomModelData(this.config.getProperty(ConfigKeys.menu_button_model_data)) - .setItemModel(menuModelData.getNamespace(), menuModelData.getId()); + this.menuButton = ItemBuilder.from(this.config.getProperty(ConfigKeys.menu_button_item).toLowerCase()) + .withDisplayName(this.config.getProperty(ConfigKeys.menu_button_name)) + .withDisplayLore(this.config.getProperty(ConfigKeys.menu_button_lore)); + + this.menuButton.asCustomBuilder().setCustomModelData(this.config.getProperty(ConfigKeys.menu_button_model_data)) + .setItemModel(menuModelData.getNamespace(), menuModelData.getId()).build(); final ModelData nextModelData = this.config.getProperty(ConfigKeys.next_button_item_model); - this.nextButton = new LegacyItemBuilder(this.plugin).withType(this.config.getProperty(ConfigKeys.next_button_item).toLowerCase()) - .setDisplayName(this.config.getProperty(ConfigKeys.next_button_name)) - .setDisplayLore(this.config.getProperty(ConfigKeys.next_button_lore)) - .setCustomModelData(this.config.getProperty(ConfigKeys.next_button_model_data)) - .setItemModel(nextModelData.getNamespace(), nextModelData.getId()); + this.nextButton = ItemBuilder.from(this.config.getProperty(ConfigKeys.next_button_item).toLowerCase()) + .withDisplayName(this.config.getProperty(ConfigKeys.next_button_name)) + .withDisplayLore(this.config.getProperty(ConfigKeys.next_button_lore)); + + this.nextButton.asCustomBuilder().setCustomModelData(this.config.getProperty(ConfigKeys.next_button_model_data)) + .setItemModel(nextModelData.getNamespace(), nextModelData.getId()).build(); final ModelData backModelData = this.config.getProperty(ConfigKeys.back_button_item_model); - this.backButton = new LegacyItemBuilder(this.plugin).withType(this.config.getProperty(ConfigKeys.back_button_item).toLowerCase()) - .setDisplayName(this.config.getProperty(ConfigKeys.back_button_name)) - .setDisplayLore(this.config.getProperty(ConfigKeys.back_button_lore)) - .setCustomModelData(this.config.getProperty(ConfigKeys.back_button_model_data)) - .setItemModel(backModelData.getNamespace(), backModelData.getId()); + this.backButton = ItemBuilder.from(this.config.getProperty(ConfigKeys.back_button_item).toLowerCase()) + .withDisplayName(this.config.getProperty(ConfigKeys.back_button_name)) + .withDisplayLore(this.config.getProperty(ConfigKeys.back_button_lore)); + + this.backButton.asCustomBuilder().setCustomModelData(this.config.getProperty(ConfigKeys.back_button_model_data)) + .setItemModel(backModelData.getNamespace(), backModelData.getId()).build(); } public final ItemStack getMenuButton(@NotNull final Player player) { - return this.menuButton.setPlayer(player).asItemStack(); + return this.menuButton.asItemStack(player); } public final ItemStack getNextButton(@Nullable final Player player, @Nullable final Tier tier, @NotNull final PaginatedGui gui) { - final LegacyItemBuilder button = new LegacyItemBuilder(this.plugin, this.nextButton); + final ItemBuilder button = ItemBuilder.from(this.nextButton.asItemStack()); - if (player != null) { - button.setPlayer(player).addLorePlaceholder("{page}", String.valueOf(gui.getNextPageNumber())); - } + button.addPlaceholder("{page}", String.valueOf(gui.getNextPageNumber())); if (tier != null) { button.setPersistentString(ItemKeys.crate_tier.getNamespacedKey(), tier.getName()); } - return button.asItemStack(); + return button.asItemStack(player); } public final ItemStack getNextButton(@Nullable final Player player, @NotNull final PaginatedGui gui) { @@ -84,17 +86,15 @@ public final ItemStack getNextButton(@Nullable final Player player, @NotNull fin } public final ItemStack getBackButton(@Nullable final Player player, @Nullable final Tier tier, @NotNull final PaginatedGui gui) { - final LegacyItemBuilder button = new LegacyItemBuilder(this.plugin, this.backButton); + final ItemBuilder button = ItemBuilder.from(this.backButton.asItemStack()); - if (player != null) { - button.setPlayer(player).addLorePlaceholder("{page}", String.valueOf(gui.getPreviousPageNumber())); - } + button.addPlaceholder("{page}", String.valueOf(gui.getNextPageNumber())); if (tier != null) { button.setPersistentString(ItemKeys.crate_tier.getNamespacedKey(), tier.getName()); } - return button.asItemStack(); + return button.asItemStack(player); } public final ItemStack getBackButton(@Nullable final Player player, @NotNull final PaginatedGui gui) { diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/managers/events/EventManager.java b/paper/src/main/java/com/badbones69/crazycrates/paper/managers/events/EventManager.java index 19402b752..9b88adfa5 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/managers/events/EventManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/managers/events/EventManager.java @@ -7,9 +7,8 @@ import com.badbones69.crazycrates.core.config.ConfigManager; import com.badbones69.crazycrates.core.config.impl.ConfigKeys; import com.badbones69.crazycrates.paper.managers.events.enums.EventType; -import com.ryderbelserion.fusion.core.api.utils.AdvUtils; -import com.ryderbelserion.fusion.core.files.types.LogCustomFile; -import com.ryderbelserion.fusion.paper.files.FileManager; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.files.PaperFileManager; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.bukkit.command.CommandSender; @@ -18,13 +17,14 @@ import us.crazycrew.crazycrates.api.enums.types.KeyType; import java.nio.file.Path; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Date; public class EventManager { private final static CrazyCrates plugin = CrazyCrates.getPlugin(); + private final static FusionPaper fusion = plugin.getFusion(); + private final static ComponentLogger logger = plugin.getComponentLogger(); private final static SettingsManager config = ConfigManager.getConfig(); @@ -98,23 +98,19 @@ private static void handle(@NotNull final EventType type, @NotNull final String log(message, path, type); } - private static final FileManager fileManager = plugin.getFileManager(); + private static final PaperFileManager fileManager = plugin.getFileManager(); private static void log(@NotNull final String message, @Nullable final Path path, @NotNull final EventType type) { final String time = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date(System.currentTimeMillis())); if (path != null && config.getProperty(ConfigKeys.log_to_file)) { - final LogCustomFile customFile = (LogCustomFile) fileManager.getCustomFile(path); - - if (customFile != null) { - customFile.save("[" + time + " " + type.getEvent() + "]: " + PlainTextComponentSerializer.plainText().serialize(AdvUtils.parse(message)), new ArrayList<>()); - } + fileManager.getLogFile(path).ifPresent(file -> file.save("[" + time + " " + type.getEvent() + "]: " + PlainTextComponentSerializer.plainText().serialize(fusion.parse(message)))); } final boolean log_to_console = config.getProperty(ConfigKeys.log_to_console); if (log_to_console) { - logger.info("[{} {}]: {}", time, type.getEvent(), AdvUtils.parse(message)); + logger.info("[{} {}]: {}", time, type.getEvent(), PlainTextComponentSerializer.plainText().serialize(fusion.parse(message))); } } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/support/MetricsWrapper.java b/paper/src/main/java/com/badbones69/crazycrates/paper/support/MetricsWrapper.java index 8cbe3a1e1..6bfe5c2c1 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/support/MetricsWrapper.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/support/MetricsWrapper.java @@ -1,5 +1,6 @@ package com.badbones69.crazycrates.paper.support; +import ch.jalu.configme.SettingsManager; import com.badbones69.crazycrates.paper.CrazyCrates; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.core.config.ConfigManager; @@ -14,20 +15,20 @@ public class MetricsWrapper{ - private final CrazyCrates plugin = CrazyCrates.getPlugin(); + private final SettingsManager config = ConfigManager.getConfig(); private final CrateManager crateManager; private final Metrics metrics; - public MetricsWrapper(final int serviceId) { - this.metrics = new Metrics(this.plugin, serviceId); + public MetricsWrapper(@NotNull final CrazyCrates plugin, final int serviceId) { + this.metrics = new Metrics(plugin, serviceId); - this.crateManager = this.plugin.getCrateManager(); + this.crateManager = plugin.getCrateManager(); } public void start() { - if (this.metrics == null || !ConfigManager.getConfig().getProperty(ConfigKeys.toggle_metrics)) return; + if (this.metrics == null || !this.config.getProperty(ConfigKeys.toggle_metrics)) return; final List crates = new ArrayList<>(this.crateManager.getCrates()); diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/support/holograms/types/CMIHologramsSupport.java b/paper/src/main/java/com/badbones69/crazycrates/paper/support/holograms/types/CMIHologramsSupport.java index 50a95b9a1..280de63f4 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/support/holograms/types/CMIHologramsSupport.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/support/holograms/types/CMIHologramsSupport.java @@ -4,7 +4,7 @@ import com.Zrips.CMI.Modules.Display.CMIBillboard; import com.Zrips.CMI.Modules.Holograms.CMIHologram; import com.badbones69.crazycrates.paper.api.objects.crates.CrateHologram; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import net.Zrips.CMILib.Colors.CMIChatColor; import net.Zrips.CMILib.Container.CMILocation; import org.bukkit.Location; diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/support/holograms/types/FancyHologramsSupport.java b/paper/src/main/java/com/badbones69/crazycrates/paper/support/holograms/types/FancyHologramsSupport.java index bbbc31a57..5baa0b78f 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/support/holograms/types/FancyHologramsSupport.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/support/holograms/types/FancyHologramsSupport.java @@ -3,8 +3,8 @@ import com.badbones69.crazycrates.paper.api.objects.crates.CrateHologram; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.support.holograms.HologramManager; -import com.ryderbelserion.fusion.paper.api.enums.Scheduler; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.scheduler.Scheduler; import de.oliver.fancyholograms.api.FancyHologramsPlugin; import de.oliver.fancyholograms.api.data.TextHologramData; import de.oliver.fancyholograms.api.hologram.Hologram; diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/CrateManager.java b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/CrateManager.java index 0cd9429bc..901e5430c 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/CrateManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/CrateManager.java @@ -2,8 +2,8 @@ import ch.jalu.configme.SettingsManager; import com.Zrips.CMI.Modules.ModuleHandling.CMIModule; +import com.badbones69.crazycrates.core.constants.PluginSupport; import com.badbones69.crazycrates.paper.api.builders.CrateBuilder; -import com.badbones69.crazycrates.paper.api.enums.other.Plugins; import com.badbones69.crazycrates.core.config.impl.EditorKeys; import com.badbones69.crazycrates.paper.listeners.items.NexoInteractListener; import com.badbones69.crazycrates.paper.listeners.items.OraxenInteractListener; @@ -32,12 +32,12 @@ import com.badbones69.crazycrates.paper.tasks.crates.types.WarCrate; import com.badbones69.crazycrates.paper.tasks.crates.types.WheelCrate; import com.badbones69.crazycrates.paper.tasks.crates.types.WonderCrate; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; -import com.ryderbelserion.fusion.core.api.enums.FileAction; -import com.ryderbelserion.fusion.core.api.utils.FileUtils; +import com.ryderbelserion.fusion.kyori.mods.ModSupport; import com.ryderbelserion.fusion.paper.FusionPaper; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; -import com.ryderbelserion.fusion.paper.files.FileManager; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.builders.types.custom.CustomBuilder; +import com.ryderbelserion.fusion.paper.files.PaperFileManager; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import com.ryderbelserion.fusion.paper.files.types.PaperCustomFile; import io.papermc.paper.persistence.PersistentDataContainerView; import io.papermc.paper.threadedregions.scheduler.ScheduledTask; @@ -79,6 +79,8 @@ import com.badbones69.crazycrates.paper.CrazyCrates; import com.badbones69.crazycrates.paper.utils.ItemUtils; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -88,7 +90,7 @@ public class CrateManager { private final BukkitKeyManager keyManager = this.plugin.getKeyManager(); private final Path dataPath = this.plugin.getDataPath(); private final InventoryManager inventoryManager = this.plugin.getInventoryManager(); - private final FileManager fileManager = this.plugin.getFileManager(); + private final PaperFileManager fileManager = this.plugin.getFileManager(); private final com.badbones69.crazycrates.core.Server instance = this.plugin.getInstance(); private final FusionPaper fusion = this.plugin.getFusion(); @@ -253,7 +255,7 @@ public void reloadCrate(@Nullable final Crate crate) { this.brokeCrates.add(fileName); - if (MiscUtils.isLogging()) this.logger.warn("There was an error while loading the {} file.", fileName, exception); + this.fusion.log("warn", "There was an error while loading the {} file.", fileName, exception); } } @@ -263,16 +265,24 @@ public void loadCustomItems() { final String pluginName = this.fusion.getItemsPlugin().toLowerCase(); switch (pluginName) { - case "nexo" -> manager.registerEvents(new NexoInteractListener(), this.plugin); + case "nexo" -> { + if (this.fusion.isModReady(ModSupport.nexo)) { + manager.registerEvents(new NexoInteractListener(), this.plugin); + } + } - case "oraxen" -> manager.registerEvents(new OraxenInteractListener(), this.plugin); + case "oraxen" -> { + if (this.fusion.isModReady(ModSupport.oraxen)) { + manager.registerEvents(new OraxenInteractListener(), this.plugin); + } + } default -> { - if (Plugins.nexo.isEnabled()) { + if (this.fusion.isModReady(ModSupport.nexo)) { manager.registerEvents(new NexoInteractListener(), this.plugin); } - if (Plugins.oraxen.isEnabled()) { + if (this.fusion.isModReady(ModSupport.oraxen)) { manager.registerEvents(new OraxenInteractListener(), this.plugin); } } @@ -287,7 +297,7 @@ public void loadHolograms() { switch (pluginName) { case "decentholograms" -> { - if (!Plugins.decent_holograms.isEnabled()) return; + if (!this.fusion.isModReady(PluginSupport.decent_holograms)) return; if (this.holograms != null && this.holograms.getName().equalsIgnoreCase("DecentHolograms")) { // we don't need to do anything. return; @@ -297,13 +307,13 @@ public void loadHolograms() { } case "fancyholograms" -> { - if (!Plugins.fancy_holograms.isEnabled()) return; + if (!this.fusion.isModReady(PluginSupport.fancy_holograms)) return; this.holograms = new FancyHologramsSupport(); } case "cmi" -> { - if (!Plugins.cmi.isEnabled() && !CMIModule.holograms.isEnabled()) return; + if (!this.fusion.isModReady(PluginSupport.cmi) && !CMIModule.holograms.isEnabled()) return; this.holograms = new CMIHologramsSupport(); } @@ -311,7 +321,7 @@ public void loadHolograms() { case "none" -> {} default -> { - if (Plugins.decent_holograms.isEnabled()) { + if (this.fusion.isModReady(PluginSupport.fancy_holograms)) { if (this.holograms == null) { this.holograms = new DecentHologramsSupport(); } @@ -319,13 +329,13 @@ public void loadHolograms() { break; } - if (Plugins.fancy_holograms.isEnabled()) { + if (this.fusion.isModReady(PluginSupport.decent_holograms)) { this.holograms = new FancyHologramsSupport(); break; } - if (this.holograms == null && Plugins.cmi.isEnabled() && CMIModule.holograms.isEnabled()) { + if (this.holograms == null && this.fusion.isModReady(PluginSupport.cmi) && CMIModule.holograms.isEnabled()) { this.fusion.log("warn", "CMI Support is currently not automatically available."); this.fusion.log("warn", "Try manually setting hologram-plugin to CMI after downgrading to 9.8.2.0"); this.fusion.log("warn", "https://github.com/Zrips/CMI/issues/9919"); @@ -348,12 +358,12 @@ public void loadHolograms() { } } - public List getCrateNames(final boolean keepExtension) { - return this.instance.getCrateFiles(keepExtension); + public List getCrateNames(final boolean removeExtension) { + return this.instance.getCrateFiles(removeExtension); } public List getCrateNames() { - return this.instance.getCrateFiles(false); + return this.instance.getCrateFiles(true); } private final SettingsManager config = ConfigManager.getConfig(); @@ -363,17 +373,22 @@ public List getCrateNames() { */ public void loadCrates() { if (this.config.getProperty(ConfigKeys.update_examples_folder)) { - final List actions = new ArrayList<>(); + final Path examples = this.dataPath.resolve("examples"); - actions.add(FileAction.DELETE_FILE); - actions.add(FileAction.EXTRACT_FOLDER); + if (Files.exists(examples)) { + try { + this.fusion.deleteDirectory(examples); - FileUtils.extract("guis", this.dataPath.resolve("examples"), actions); - FileUtils.extract("logs", this.dataPath.resolve("examples"), actions); - FileUtils.extract("crates", this.dataPath.resolve("examples"), actions); - FileUtils.extract("schematics", this.dataPath.resolve("examples"), actions); + Files.createDirectory(examples); + } catch (final IOException exception) { + this.fusion.log("warn", "Failed to delete and then create the examples directory!", exception); + } + } - actions.remove(FileAction.EXTRACT_FOLDER); + this.fileManager.extractFolder("guis", examples); + this.fileManager.extractFolder("logs", examples); + this.fileManager.extractFolder("crates", examples); + this.fileManager.extractFolder("schematics", examples); List.of( "config.yml", @@ -381,7 +396,7 @@ public void loadCrates() { "locations.yml", "messages.yml", "editor.yml" - ).forEach(file -> FileUtils.extract(file, this.dataPath.resolve("examples"), actions)); + ).forEach(file -> this.fileManager.extractFile(file, examples.resolve(file))); } this.giveNewPlayersKeys = false; @@ -393,15 +408,19 @@ public void loadCrates() { this.holograms.purge(false); } - if (MiscUtils.isLogging()) this.logger.info("Loading all crate information..."); + this.fusion.log("warn", "Loading all crate information..."); final Path crates = this.dataPath.resolve("crates"); - for (final String crateName : getCrateNames(true)) { + for (final String crateName : getCrateNames(false)) { try { - final PaperCustomFile customFile = this.fileManager.getPaperCustomFile(crates.resolve(crateName)); + final @NotNull Optional optional = this.fileManager.getPaperFile(crates.resolve(crateName)); + + if (optional.isEmpty()) continue; - if (customFile == null || !customFile.isLoaded()) continue; + final PaperCustomFile customFile = optional.get(); + + if (!customFile.isLoaded()) continue; final YamlConfiguration file = customFile.getConfiguration(); @@ -434,7 +453,7 @@ public void loadCrates() { if (isTiersEmpty && tiers.isEmpty()) { this.brokeCrates.add(crateName); - if (MiscUtils.isLogging()) this.logger.warn("No tiers were found for {}.yml file.", crateName); + this.fusion.log("warn", "No tiers were found for {}.yml file.", crateName); continue; } @@ -521,13 +540,13 @@ public void loadCrates() { } catch (final Exception exception) { this.brokeCrates.add(crateName); - if (MiscUtils.isLogging()) this.logger.warn("There was an error while loading the {} file.", crateName, exception); + this.fusion.log("warn", "There was an error while loading the {} file.", crateName, exception); } } addCrate(new Crate("Menu")); - if (MiscUtils.isLogging()) this.logger.warn("All crate information has been loaded, Loading physical crate locations!"); + this.fusion.log("warn", "All crate information has been loaded, Loading physical crate locations!"); final YamlConfiguration locations = FileKeys.locations.getConfiguration(); @@ -599,12 +618,12 @@ public void loadCrates() { if (schematicName.endsWith(".nbt")) { this.crateSchematics.add(new CrateSchematic(schematicName, new File(this.plugin.getDataFolder() + "/schematics/" + schematicName))); - if (isLogging) this.logger.info("{} was successfully found and loaded.", schematicName); + this.fusion.log("warn", "{} was successfully found and loaded.", schematicName); } } } - if (MiscUtils.isLogging()) this.logger.info("All schematics were found and loaded."); + this.fusion.log("warn", "All schematics were found and loaded."); cleanDataFile(); @@ -1488,19 +1507,26 @@ public void removeBrokeLocation(@NotNull final List crateLocation } // Internal methods. - private LegacyItemBuilder getKey(@NotNull final FileConfiguration file) { + private ItemBuilder getKey(@NotNull final FileConfiguration file) { final String name = file.getString("Crate.PhysicalKey.Name", ""); final String customModelData = file.getString("Crate.PhysicalKey.Custom-Model-Data", ""); final String namespace = file.getString("Crate.PhysicalKey.Model.Namespace", ""); final String id = file.getString("Crate.PhysicalKey.Model.Id", ""); final List lore = file.getStringList("Crate.PhysicalKey.Lore"); - final boolean glowing = file.getBoolean("Crate.PhysicalKey.Glowing", true); - final boolean hideFlags = file.getBoolean("Crate.PhysicalKey.HideItemFlags", false); - final LegacyItemBuilder itemBuilder = file.contains("Crate.PhysicalKey.Data") ? new LegacyItemBuilder(this.plugin) - .fromBase64(file.getString("Crate.PhysicalKey.Data", "")) : new LegacyItemBuilder(this.plugin).withType(file.getString("Crate.PhysicalKey.Item", "tripwire_hook").toLowerCase()); + final ItemBuilder itemBuilder = ItemBuilder.from(file.getString("Crate.PhysicalKey.Data", file.getString("Crate.PhysicalKey.Item", "tripwire_hook").toLowerCase())); + + ItemUtils.updateEnchantGlintState(itemBuilder, file.getString("Crate.PhysicalKey.Glowing", "add_glow")); + + final CustomBuilder customBuilder = itemBuilder.asCustomBuilder(); + + customBuilder.setCustomModelData(customModelData); + + customBuilder.setItemModel(namespace, id); + + customBuilder.build(); - return itemBuilder.setDisplayName(name).setDisplayLore(lore).setGlowing(glowing).setItemModel(namespace, id).setHidingItemFlags(hideFlags).setCustomModelData(customModelData); + return itemBuilder.withDisplayName(name).withDisplayLore(lore)/*.setHidingItemFlags(hideFlags)*/; } // Cleans the data file. @@ -1549,14 +1575,14 @@ private void cleanDataFile() { } if (!removePlayers.isEmpty()) { - if (isLogging) this.logger.info("{} player's data has been marked to be removed.", removePlayers.size()); + this.fusion.log("warn", "{} player's data has been marked to be removed.", removePlayers.size()); removePlayers.forEach(uuid -> data.set("Players." + uuid, null)); - if (isLogging) this.logger.info("All empty player data has been removed."); + this.fusion.log("warn", "All empty player data has been removed."); } - if (isLogging) this.logger.info("The data.yml file has been cleaned."); + this.fusion.log("warn", "The data.yml file has been cleaned."); FileKeys.data.save(); } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/other/CosmicCrateManager.java b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/other/CosmicCrateManager.java index a57c902af..e6e26134e 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/other/CosmicCrateManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/other/CosmicCrateManager.java @@ -3,7 +3,8 @@ import com.badbones69.crazycrates.paper.api.PrizeManager; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.api.objects.Tier; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.builders.types.custom.CustomBuilder; import io.papermc.paper.persistence.PersistentDataContainerView; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -19,8 +20,8 @@ public class CosmicCrateManager extends AbstractCrateManager { - private final LegacyItemBuilder mysteryCrate; - private final LegacyItemBuilder pickedCrate; + private final ItemBuilder mysteryCrate; + private final ItemBuilder pickedCrate; private final YamlConfiguration file; private final int totalPrizes; @@ -38,22 +39,31 @@ public CosmicCrateManager(@NotNull final YamlConfiguration file) { this.totalPrizes = file.getInt(path + "Total-Prize-Amount", 4); - this.mysteryCrate = new LegacyItemBuilder(this.plugin) - .withType(file.getString(path + "Mystery-Crate.Item", "chest").toLowerCase()) - .setDisplayName(file.getString(path + "Mystery-Crate.Name", "???")) - .setHidingItemFlags(file.getBoolean(path + "Mystery-Crate.HideItemFlags", false)) - .setDisplayLore(file.contains(path + "Mystery-Crate.Lore") ? file.getStringList(path + "Mystery-Crate.Lore") : Collections.singletonList("You may choose 4 crates.")) + this.mysteryCrate = ItemBuilder.from(file.getString(path + "Mystery-Crate.Item", "chest").toLowerCase()) + .withDisplayName(file.getString(path + "Mystery-Crate.Name", "???")) + .withDisplayLore(file.contains(path + "Mystery-Crate.Lore") ? file.getStringList(path + "Mystery-Crate.Lore") : Collections.singletonList("You may choose 4 crates.")) .setPersistentInteger(ItemKeys.cosmic_mystery_crate.getNamespacedKey(), 1) - .setCustomModelData(file.getString(path + "Mystery-Crate.Custom-Model-Data", "")) - .setItemModel(file.getString(path + "Mystery-Crate.Model.Namespace", ""), file.getString(path + "Mystery-Crate.Model.Id", "")); + .withConsumer(consumer -> { + final CustomBuilder customBuilder = consumer.asCustomBuilder(); - this.pickedCrate = new LegacyItemBuilder(this.plugin).withType(file.getString(path + "Picked-Crate.Item", "gray_stained_glass_pane").toLowerCase()) - .setDisplayName(file.getString(path + "Picked-Crate.Name", "???")) - .setHidingItemFlags(file.getBoolean(path + "Picked-Crate.HideItemFlags", false)) - .setDisplayLore(file.contains(path + "Picked-Crate.Lore") ? file.getStringList(path + "Picked-Crate.Lore") : Collections.singletonList("You have chosen #%slot%.")) + customBuilder.setCustomModelData(file.getString(path + "Mystery-Crate.Custom-Model-Data", "")); + customBuilder.setItemModel(file.getString(path + "Mystery-Crate.Model.Namespace", ""), file.getString(path + "Mystery-Crate.Model.Id", "")); + + customBuilder.build(); + }); + + this.pickedCrate = ItemBuilder.from(file.getString(path + "Picked-Crate.Item", "gray_stained_glass_pane").toLowerCase()) + .withDisplayName(file.getString(path + "Picked-Crate.Name", "???")) + .withDisplayLore(file.contains(path + "Picked-Crate.Lore") ? file.getStringList(path + "Picked-Crate.Lore") : Collections.singletonList("You have chosen #{slot}.")) .setPersistentInteger(ItemKeys.cosmic_picked_crate.getNamespacedKey(), 1) - .setCustomModelData(file.getString(path + "Picked-Crate.Custom-Model-Data", "")) - .setItemModel(file.getString(path + "Picked-Crate.Model.Namespace", ""), file.getString(path + "Picked-Crate.Model.Id", "")); + .withConsumer(consumer -> { + final CustomBuilder customBuilder = consumer.asCustomBuilder(); + + customBuilder.setCustomModelData(file.getString(path + "Picked-Crate.Custom-Model-Data", "")); + customBuilder.setItemModel(file.getString(path + "Picked-Crate.Model.Namespace", ""), file.getString(path + "Picked-Crate.Model.Id", "")); + + customBuilder.build(); + }); } /** @@ -73,14 +83,14 @@ public final int getTotalPrizes() { /** * @return mystery crate builder. */ - public @NotNull final LegacyItemBuilder getMysteryCrate() { + public @NotNull final ItemBuilder getMysteryCrate() { return this.mysteryCrate; } /** * @return picked crate builder. */ - public @NotNull final LegacyItemBuilder getPickedCrate() { + public @NotNull final ItemBuilder getPickedCrate() { return this.pickedCrate; } @@ -108,7 +118,7 @@ public final Tier getTier(@NotNull final ItemStack itemStack, @NotNull final Cra * @param itemBuilder the itembuilder * @param name the name of the tier */ - public void setTier(@NotNull final LegacyItemBuilder itemBuilder, @Nullable final String name) { + public void setTier(@NotNull final ItemBuilder itemBuilder, @Nullable final String name) { if (name == null || name.isEmpty()) return; itemBuilder.setPersistentString(ItemKeys.crate_tier.getNamespacedKey(), name); @@ -170,4 +180,4 @@ public void removePickedPlayer(@NotNull final Player player) { public final Map getPrizes(@NotNull final Player player) { return Collections.unmodifiableMap(this.prizes.getOrDefault(player.getUniqueId(), new HashMap<>())); } -} +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/other/quadcrates/QuadCrateManager.java b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/other/quadcrates/QuadCrateManager.java index 46c6c0764..79228f8b5 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/other/quadcrates/QuadCrateManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/other/quadcrates/QuadCrateManager.java @@ -1,11 +1,12 @@ package com.badbones69.crazycrates.paper.tasks.crates.other.quadcrates; +import ch.jalu.configme.SettingsManager; import com.badbones69.crazycrates.paper.api.objects.crates.CrateLocation; import com.badbones69.crazycrates.paper.support.holograms.HologramManager; import com.badbones69.crazycrates.paper.managers.BukkitUserManager; import com.badbones69.crazycrates.paper.tasks.crates.other.quadcrates.structures.StructureManager; -import com.ryderbelserion.fusion.paper.api.enums.Scheduler; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.scheduler.Scheduler; import net.kyori.adventure.sound.Sound; import org.bukkit.*; import com.badbones69.crazycrates.core.config.ConfigManager; @@ -32,6 +33,8 @@ public class QuadCrateManager { private final CrazyCrates plugin = CrazyCrates.getPlugin(); + private final SettingsManager config = ConfigManager.getConfig(); + private final CrateManager crateManager = this.plugin.getCrateManager(); private final BukkitUserManager userManager = this.plugin.getUserManager(); @@ -266,7 +269,7 @@ public void run() { crate.playSound(player, player.getLocation(), "stop-sound", "entity.player.levelup", Sound.Source.MASTER); } - }.runDelayed(ConfigManager.getConfig().getProperty(ConfigKeys.quad_crate_timer) * 20)); + }.runDelayed(this.config.getProperty(ConfigKeys.quad_crate_timer) * 20)); } /** diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/other/quadcrates/structures/StructureManager.java b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/other/quadcrates/structures/StructureManager.java index 6aa67eab1..33b76ac33 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/other/quadcrates/structures/StructureManager.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/other/quadcrates/structures/StructureManager.java @@ -1,9 +1,8 @@ package com.badbones69.crazycrates.paper.tasks.crates.other.quadcrates.structures; import com.badbones69.crazycrates.paper.CrazyCrates; -import com.badbones69.crazycrates.paper.utils.MiscUtils; import com.google.common.collect.Lists; -import net.kyori.adventure.text.logger.slf4j.ComponentLogger; +import com.ryderbelserion.fusion.paper.FusionPaper; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Server; @@ -28,9 +27,8 @@ public class StructureManager implements IStructureManager { private final Set preStructurePasteBlocks = new HashSet<>(); private final CrazyCrates plugin = CrazyCrates.getPlugin(); + private final FusionPaper fusion = this.plugin.getFusion(); private final Server server = this.plugin.getServer(); - private final ComponentLogger logger = this.plugin.getComponentLogger(); - private final boolean isVerbose = MiscUtils.isLogging(); private File file = null; @@ -52,7 +50,7 @@ public void applyStructure(@Nullable final File file) { try { return getStructureManager().loadStructure(this.file); } catch (final IOException exception) { - if (this.isVerbose) this.logger.error("Failed to load structure: {}!", this.file.getName(), exception); + this.fusion.log("error", "Failed to load structure: {}!", this.file.getName(), exception); return null; } @@ -77,7 +75,7 @@ public void saveStructure(@Nullable final File file, @Nullable final Location on try { getStructureManager().saveStructure(file, this.structure); } catch (final IOException exception) { - if (this.isVerbose) this.logger.error("Failed to save structure to: {}!", file.getName(), exception); + this.fusion.log("error", "Failed to save structure to: {}!", file.getName(), exception); } } @@ -99,7 +97,7 @@ public void pasteStructure(@Nullable final Location location, final boolean stor // Get the structure blocks. if (storeBlocks) getStructureBlocks(clonedLocation); } catch (final Exception exception) { - if (this.isVerbose) this.logger.error("Could not paste structure", exception); + this.fusion.log("error", "Could not paste structure", exception); } } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/CasinoCrate.java b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/CasinoCrate.java index 641624493..decf73445 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/CasinoCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/CasinoCrate.java @@ -7,7 +7,7 @@ import com.badbones69.crazycrates.paper.managers.events.enums.EventType; import com.badbones69.crazycrates.paper.utils.MiscUtils; import com.badbones69.crazycrates.paper.api.PrizeManager; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import io.papermc.paper.persistence.PersistentDataContainerView; import net.kyori.adventure.sound.Sound; import org.bukkit.entity.Player; @@ -115,7 +115,7 @@ public void open(@NotNull final KeyType type, final boolean checkHand, final boo @Nullable final Tier tier_tres = this.crate.getTier(section.getString("types.row-1", "")); if (tier_uno == null || tier_dos == null || tier_tres == null) { - if (MiscUtils.isLogging()) this.logger.warn("One of your tiers in {} could not be found, or is empty. Search for row-1, row-2 or row-3", fileName); + this.fusion.log("warn", "One of your tiers in {} could not be found, or is empty. Search for row-1, row-2 or row-3", fileName); this.crateManager.endCrate(this.player); diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/FireCrackerCrate.java b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/FireCrackerCrate.java index 6df71fe0e..0fd4ea14d 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/FireCrackerCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/FireCrackerCrate.java @@ -9,7 +9,7 @@ import com.badbones69.crazycrates.paper.api.objects.gui.GuiSettings; import com.badbones69.crazycrates.paper.managers.events.enums.EventType; import com.badbones69.crazycrates.paper.support.holograms.HologramManager; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/RouletteCrate.java b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/RouletteCrate.java index 1c4237650..50f33aa30 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/RouletteCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/RouletteCrate.java @@ -7,7 +7,7 @@ import com.badbones69.crazycrates.paper.api.PrizeManager; import com.badbones69.crazycrates.paper.api.objects.gui.GuiSettings; import com.badbones69.crazycrates.paper.managers.events.enums.EventType; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import net.kyori.adventure.sound.Sound; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryCloseEvent; diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/WarCrate.java b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/WarCrate.java index a7495c83d..ab97a38e3 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/WarCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/WarCrate.java @@ -1,14 +1,15 @@ package com.badbones69.crazycrates.paper.tasks.crates.types; import com.badbones69.crazycrates.paper.api.objects.Crate; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; import com.badbones69.crazycrates.paper.managers.events.enums.EventType; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; +import net.kyori.adventure.key.Key; import net.kyori.adventure.sound.Sound; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ItemType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import us.crazycrew.crazycrates.api.enums.types.KeyType; @@ -21,7 +22,7 @@ public class WarCrate extends CrateBuilder { - private final Map colorCodes = new HashMap<>(); + private final Map<@NotNull Key, String> colorCodes = new HashMap(); public WarCrate(@NotNull final Crate crate, @NotNull final Player player, final int size) { super(crate, player, size); @@ -109,8 +110,10 @@ private void setRandomGlass() { if (this.colorCodes.isEmpty()) getColorCode(); - final LegacyItemBuilder builder = MiscUtils.getRandomPaneColor(); - builder.setDisplayName("<" + this.colorCodes.get(builder.getType()) + ">???"); + final ItemBuilder builder = MiscUtils.getRandomPaneColor(); + + builder.withDisplayName("<" + this.colorCodes.get(builder.getKey()) + ">???"); + final ItemStack item = builder.asItemStack(); for (int index = 0; index < 9; index++) { @@ -119,21 +122,21 @@ private void setRandomGlass() { } private void getColorCode() { - this.colorCodes.put(Material.WHITE_STAINED_GLASS_PANE, "white"); - this.colorCodes.put(Material.ORANGE_STAINED_GLASS_PANE, "gold"); - this.colorCodes.put(Material.MAGENTA_STAINED_GLASS_PANE, "light_purple"); - this.colorCodes.put(Material.LIGHT_BLUE_STAINED_GLASS_PANE, "dark_aqua"); - this.colorCodes.put(Material.YELLOW_STAINED_GLASS_PANE, "yellow"); - this.colorCodes.put(Material.LIME_STAINED_GLASS_PANE, "green"); - this.colorCodes.put(Material.PINK_STAINED_GLASS_PANE, "red"); - this.colorCodes.put(Material.GRAY_STAINED_GLASS_PANE, "dark_gray"); - this.colorCodes.put(Material.LIGHT_GRAY_STAINED_GLASS_PANE, "gray"); - this.colorCodes.put(Material.CYAN_STAINED_GLASS_PANE, "aqua"); - this.colorCodes.put(Material.PURPLE_STAINED_GLASS_PANE, "dark_purple"); - this.colorCodes.put(Material.BLUE_STAINED_GLASS_PANE, "dark_blue"); - this.colorCodes.put(Material.BROWN_STAINED_GLASS_PANE, "gold"); - this.colorCodes.put(Material.GREEN_STAINED_GLASS_PANE, "green"); - this.colorCodes.put(Material.RED_STAINED_GLASS_PANE, "dark_red"); - this.colorCodes.put(Material.BLACK_STAINED_GLASS_PANE, "black"); + this.colorCodes.put(ItemType.WHITE_STAINED_GLASS_PANE.key(), "white"); + this.colorCodes.put(ItemType.ORANGE_STAINED_GLASS_PANE.key(), "gold"); + this.colorCodes.put(ItemType.MAGENTA_STAINED_GLASS_PANE.key(), "light_purple"); + this.colorCodes.put(ItemType.LIGHT_BLUE_STAINED_GLASS_PANE.key(), "dark_aqua"); + this.colorCodes.put(ItemType.YELLOW_STAINED_GLASS_PANE.key(), "yellow"); + this.colorCodes.put(ItemType.LIME_STAINED_GLASS_PANE.key(), "green"); + this.colorCodes.put(ItemType.PINK_STAINED_GLASS_PANE.key(), "red"); + this.colorCodes.put(ItemType.GRAY_STAINED_GLASS_PANE.key(), "dark_gray"); + this.colorCodes.put(ItemType.LIGHT_GRAY_STAINED_GLASS_PANE.key(), "gray"); + this.colorCodes.put(ItemType.CYAN_STAINED_GLASS_PANE.key(), "aqua"); + this.colorCodes.put(ItemType.PURPLE_STAINED_GLASS_PANE.key(), "dark_purple"); + this.colorCodes.put(ItemType.BLUE_STAINED_GLASS_PANE.key(), "dark_blue"); + this.colorCodes.put(ItemType.BROWN_STAINED_GLASS_PANE.key(), "gold"); + this.colorCodes.put(ItemType.GREEN_STAINED_GLASS_PANE.key(), "green"); + this.colorCodes.put(ItemType.RED_STAINED_GLASS_PANE.key(), "dark_red"); + this.colorCodes.put(ItemType.BLACK_STAINED_GLASS_PANE.key(), "black"); } } \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/WheelCrate.java b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/WheelCrate.java index 44f7939ea..3add5fcfe 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/WheelCrate.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/crates/types/WheelCrate.java @@ -7,7 +7,7 @@ import com.badbones69.crazycrates.paper.api.PrizeManager; import com.badbones69.crazycrates.paper.api.objects.gui.GuiSettings; import com.badbones69.crazycrates.paper.managers.events.enums.EventType; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import net.kyori.adventure.sound.Sound; import org.bukkit.Material; import org.bukkit.entity.Player; diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CrateAdminMenu.java b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CrateAdminMenu.java index 1e79cbe1b..fdfde5add 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CrateAdminMenu.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CrateAdminMenu.java @@ -1,15 +1,15 @@ package com.badbones69.crazycrates.paper.tasks.menus; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; import com.badbones69.crazycrates.paper.api.builders.gui.DynamicInventoryBuilder; import com.badbones69.crazycrates.paper.api.enums.Messages; import com.badbones69.crazycrates.paper.api.enums.Permissions; import com.badbones69.crazycrates.paper.utils.MiscUtils; import com.badbones69.crazycrates.core.config.impl.ConfigKeys; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiFiller; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiItem; -import com.ryderbelserion.fusion.paper.api.builders.gui.types.PaginatedGui; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiFiller; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiItem; +import com.ryderbelserion.fusion.paper.builders.gui.types.PaginatedGui; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -131,8 +131,8 @@ public void run() { this.gui.open(this.player, gui -> { final int rows = gui.getRows(); - gui.setItem(rows, 5, new LegacyItemBuilder(this.plugin, ItemType.CHEST) - .setDisplayName("What is this menu?") + gui.setItem(rows, 5, ItemBuilder.from(ItemType.CHEST, 1) + .withDisplayName("What is this menu?") .addDisplayLore(" ⤷ Right click to go back to the main menu!") .addDisplayLore("") .addDisplayLore("A cheat cheat menu of all your available keys.") diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CrateMainMenu.java b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CrateMainMenu.java index 4b29c3752..a5a3adde6 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CrateMainMenu.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CrateMainMenu.java @@ -1,18 +1,20 @@ package com.badbones69.crazycrates.paper.tasks.menus; import com.badbones69.crazycrates.core.config.beans.ModelData; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; import com.badbones69.crazycrates.paper.api.builders.gui.StaticInventoryBuilder; import com.badbones69.crazycrates.paper.api.enums.Messages; import com.badbones69.crazycrates.paper.api.enums.other.keys.ItemKeys; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.managers.events.enums.EventType; +import com.badbones69.crazycrates.paper.utils.CommandUtils; import com.badbones69.crazycrates.paper.utils.ItemUtils; import com.badbones69.crazycrates.paper.utils.MiscUtils; import com.badbones69.crazycrates.core.config.impl.ConfigKeys; -import com.ryderbelserion.fusion.core.api.utils.StringUtils; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.Gui; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiFiller; +import com.ryderbelserion.fusion.core.utils.StringUtils; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.Gui; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiFiller; +import com.ryderbelserion.fusion.paper.builders.types.custom.CustomBuilder; import io.papermc.paper.persistence.PersistentDataContainerView; import net.kyori.adventure.key.Key; import net.kyori.adventure.sound.Sound; @@ -22,6 +24,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ItemType; import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.NotNull; import us.crazycrew.crazycrates.api.enums.types.KeyType; @@ -47,18 +50,28 @@ public void open() { final ModelData fillerModel = this.config.getProperty(ConfigKeys.filler_item_model); - guiFiller.fill(new LegacyItemBuilder(this.plugin) - .withType(this.config.getProperty(ConfigKeys.filler_item)) - .setDisplayName(this.config.getProperty(ConfigKeys.filler_name)) - .setDisplayLore(this.config.getProperty(ConfigKeys.filler_lore)) - .setCustomModelData(this.config.getProperty(ConfigKeys.filler_model_data)) - .setItemModel(fillerModel.getNamespace(), fillerModel.getId()) - .asGuiItem()); + final ItemBuilder itemBuilder = ItemBuilder.from(this.config.getProperty(ConfigKeys.filler_item)).withDisplayName(this.config.getProperty(ConfigKeys.filler_name)) + .withDisplayLore(this.config.getProperty(ConfigKeys.filler_lore)) + .withConsumer(consumer -> { + final CustomBuilder customBuilder = consumer.asCustomBuilder(); + + customBuilder.setCustomModelData(this.config.getProperty(ConfigKeys.filler_model_data)); + + customBuilder.setItemModel(fillerModel.getNamespace(), fillerModel.getId()); + + customBuilder.build(); + }); + + guiFiller.fill(itemBuilder.asGuiItem(this.player)); } + final Map placeholders = getPlaceholders(); + if (this.config.getProperty(ConfigKeys.gui_customizer_toggle)) { for (String custom : this.config.getProperty(ConfigKeys.gui_customizer)) { - final LegacyItemBuilder item = new LegacyItemBuilder(this.plugin); + final ItemBuilder itemBuilder = ItemBuilder.from(ItemType.STONE, 1); + + itemBuilder.setPlaceholders(placeholders); int slot = 0; @@ -67,32 +80,38 @@ public void open() { String value = key.replace(option + ":", "").replace(option, ""); switch (option.toLowerCase()) { - case "item" -> item.withType(value.toLowerCase()); - case "name" -> item.setDisplayName(getCrates(value).replace("{player}", player.getName())); + case "item" -> { + itemBuilder.withCustomItem(value.toLowerCase()); + } + case "name" -> itemBuilder.withDisplayName(value); case "lore" -> { String[] lore = value.split(","); - for (String line : lore) { - item.addDisplayLore(getCrates(line).replace("{player}", player.getName())); + for (final String line : lore) { + itemBuilder.addDisplayLore(line); } } - case "custom-model-data" -> item.setCustomModelData(value); + case "custom-model-data" -> itemBuilder.asCustomBuilder().setCustomModelData(value).build(); - case "glowing" -> item.setGlowing(StringUtils.tryParseBoolean(value).orElse(false)); + case "glowing" -> ItemUtils.updateEnchantGlintState(itemBuilder, value); case "slot" -> slot = StringUtils.tryParseInt(value).orElse(-1).intValue(); - case "unbreakable-item" -> item.setUnbreakable(StringUtils.tryParseBoolean(value).orElse(false)); + case "unbreakable-item" -> itemBuilder.setUnbreakable(StringUtils.tryParseBoolean(value).orElse(false)); - case "hide-item-flags" -> item.setHidingItemFlags(StringUtils.tryParseBoolean(value).orElse(false)); + case "hide-item-flags" -> { + if (StringUtils.tryParseBoolean(value).orElse(false)) { + itemBuilder.hideToolTip(); + } + } - case "command" -> item.setPersistentString(ItemKeys.crate_command.getNamespacedKey(), value); + case "command" -> itemBuilder.setPersistentString(ItemKeys.crate_command.getNamespacedKey(), value); } } - this.gui.setItem(slot, item.setPlayer(this.player).asGuiItem(action -> { + this.gui.setItem(slot, itemBuilder.asGuiItem(this.player, action -> { final ItemStack itemStack = action.getCurrentItem(); if (itemStack == null || itemStack.isEmpty()) return; @@ -105,74 +124,93 @@ public void open() { if (command == null) return; - MiscUtils.sendCommand(player, command, Map.of("{player}", player.getName())); + CommandUtils.executeCommand(this.player, command, Map.of("{player}", this.player.getName())); })); } } - for (Crate crate : this.crateManager.getUsableCrates()) { + for (final Crate crate : this.crateManager.getUsableCrates()) { final YamlConfiguration file = crate.getFile(); final ConfigurationSection section = file.getConfigurationSection("Crate"); - if (section != null) { - if (section.getBoolean("InGUI", false)) { - final String fileName = crate.getFileName(); - - int slot = section.getInt("Slot"); - - final int virtualKeys = this.userManager.getVirtualKeys(uuid, fileName); - final int physicalKeys = this.userManager.getPhysicalKeys(uuid, fileName); - - final int totalKeys = virtualKeys + physicalKeys; - - final int openedCrates = this.userManager.getCrateOpened(uuid, fileName); - - final NumberFormat instance = NumberFormat.getNumberInstance(); - - final LegacyItemBuilder builder = new LegacyItemBuilder(this.plugin) - .withType(section.getString("Item", "chest").toLowerCase()) - .setDisplayName(crate.getCrateName()) - .setCustomModelData(section.getString("Custom-Model-Data", "")) - .setItemModel(section.getString("Model.Namespace", ""), section.getString("Model.Id", "")) - .addLorePlaceholder("%keys%", instance.format(virtualKeys)) - .addLorePlaceholder("%keys_physical%", instance.format(physicalKeys)) - .addLorePlaceholder("%keys_total%", instance.format(totalKeys)) - .addLorePlaceholder("%crate_opened%", instance.format(openedCrates)) - .addLorePlaceholder("%keys_raw%", String.valueOf(virtualKeys)) - .addLorePlaceholder("%keys_physical_raw%", String.valueOf(physicalKeys)) - .addLorePlaceholder("%keys_total_raw%", String.valueOf(totalKeys)) - .addLorePlaceholder("%crate_opened_raw%", String.valueOf(openedCrates)) - .addLorePlaceholder("%player%", this.player.getName()) - .setPersistentString(ItemKeys.crate_key.getNamespacedKey(), fileName); - - this.gui.setItem(slot, ItemUtils.getItem(section, builder, this.player).asGuiItem(event -> { - final String fancyName = crate.getCrateName(); - - switch (event.getClick()) { - case ClickType.LEFT -> { - final boolean isLeftClickToPreview = this.config.getProperty(ConfigKeys.crate_virtual_interaction); - - if (isLeftClickToPreview) { - openPreview(crate, fancyName); - } else { - openCrate(uuid, crate, fileName, fancyName); - } - } + if (section == null) continue; - case ClickType.RIGHT -> { - final boolean isRightClickToOpen = this.config.getProperty(ConfigKeys.crate_virtual_interaction); + final ConfigurationSection display = section.getConfigurationSection("Preview.Display"); - if (isRightClickToOpen) { - openCrate(uuid, crate, fileName, fancyName); - } else { - openPreview(crate, fancyName); - } - } + if (display == null) continue; + + if (!display.getBoolean("Toggle", false)) continue; + + final String fileName = crate.getFileName(); + final int slot = display.getInt("Slot"); + + final int virtualKeys = this.userManager.getVirtualKeys(uuid, fileName); + final int physicalKeys = this.userManager.getPhysicalKeys(uuid, fileName); + + final int totalKeys = virtualKeys + physicalKeys; + + final int openedCrates = this.userManager.getCrateOpened(uuid, fileName); + + final NumberFormat instance = NumberFormat.getNumberInstance(); + + final ItemBuilder itemBuilder = ItemBuilder.from(display.getString("Item", "chest").toLowerCase()) + .withDisplayName(crate.getCrateName()) + .setPersistentString(ItemKeys.crate_key.getNamespacedKey(), fileName) + .addPlaceholder("%keys%", instance.format(virtualKeys)) + .addPlaceholder("%keys_physical%", instance.format(physicalKeys)) + .addPlaceholder("%keys_total%", instance.format(totalKeys)) + .addPlaceholder("%crate_opened%", instance.format(openedCrates)) + .addPlaceholder("%keys_raw%", String.valueOf(virtualKeys)) + .addPlaceholder("%keys_physical_raw%", String.valueOf(physicalKeys)) + .addPlaceholder("%keys_total_raw%", String.valueOf(totalKeys)) + .addPlaceholder("%crate_opened_raw%", String.valueOf(openedCrates)) + .addPlaceholder("%player%", this.player.getName()) + + .addPlaceholder("{keys}", instance.format(virtualKeys)) + .addPlaceholder("{keys_physical}", instance.format(physicalKeys)) + .addPlaceholder("{keys_total}", instance.format(totalKeys)) + .addPlaceholder("{crate_opened}", instance.format(openedCrates)) + .addPlaceholder("{keys_raw}", String.valueOf(virtualKeys)) + .addPlaceholder("{keys_physical_raw}", String.valueOf(physicalKeys)) + .addPlaceholder("{keys_total_raw}", String.valueOf(totalKeys)) + .addPlaceholder("{crate_opened_raw}", String.valueOf(openedCrates)) + .addPlaceholder("{player}", this.player.getName()) + .withConsumer(consumer -> { + final CustomBuilder customBuilder = consumer.asCustomBuilder(); + + customBuilder.setCustomModelData(display.getString("Custom-Model-Data", "")); + + customBuilder.setItemModel(display.getString("Model.Namespace", ""), display.getString("Model.Id", "")); + + customBuilder.build(); + }); + + this.gui.setItem(slot, ItemUtils.getItem(display, itemBuilder).asGuiItem(this.player, event -> { + final String fancyName = crate.getCrateName(); + + switch (event.getClick()) { + case ClickType.LEFT -> { + final boolean isLeftClickToPreview = this.config.getProperty(ConfigKeys.crate_virtual_interaction); + + if (isLeftClickToPreview) { + openPreview(crate, fancyName); + } else { + openCrate(uuid, crate, fileName, fancyName); } - })); + } + + case ClickType.RIGHT -> { + final boolean isRightClickToOpen = this.config.getProperty(ConfigKeys.crate_virtual_interaction); + + if (isRightClickToOpen) { + openCrate(uuid, crate, fileName, fancyName); + } else { + openPreview(crate, fancyName); + } + } } - } + })); } this.gui.open(this.player); @@ -238,4 +276,4 @@ private void openPreview(@NotNull final Crate crate, @NotNull final String fancy Messages.preview_disabled.sendMessage(this.player, "{crate}", fancyName); } } -} +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CratePreviewMenu.java b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CratePreviewMenu.java index 544545ad2..8da9e20a4 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CratePreviewMenu.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CratePreviewMenu.java @@ -3,19 +3,21 @@ import com.badbones69.crazycrates.paper.api.builders.gui.DynamicInventoryBuilder; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.api.objects.Tier; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiFiller; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiItem; -import com.ryderbelserion.fusion.paper.api.builders.gui.types.PaginatedGui; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiFiller; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiItem; +import com.ryderbelserion.fusion.paper.builders.gui.types.PaginatedGui; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemType; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + import java.util.UUID; public class CratePreviewMenu extends DynamicInventoryBuilder { - private final Tier tier; + private @Nullable final Tier tier; - public CratePreviewMenu(@NotNull final Player player, @NotNull final Crate crate, @NotNull final Tier tier) { + public CratePreviewMenu(@NotNull final Player player, @NotNull final Crate crate, @Nullable final Tier tier) { super(player, crate, crate.getPreviewName(), crate.getPreviewRows()); this.tier = tier; @@ -33,7 +35,7 @@ public void open() { final GuiFiller guiFiller = this.gui.getFiller(); if (crate.isBorderToggle()) { - final GuiItem guiItem = new GuiItem(crate.getBorderItem().asItemStack()); + final GuiItem guiItem = crate.getBorderItem().asGuiItem(); guiFiller.fillTop(guiItem); guiFiller.fillBottom(guiItem); diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CrateTierMenu.java b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CrateTierMenu.java index d8752d85d..39cf83c02 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CrateTierMenu.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/tasks/menus/CrateTierMenu.java @@ -4,9 +4,9 @@ import com.badbones69.crazycrates.paper.api.enums.other.keys.ItemKeys; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.api.objects.Tier; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.Gui; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiFiller; -import com.ryderbelserion.fusion.paper.api.builders.gui.interfaces.GuiItem; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.Gui; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiFiller; +import com.ryderbelserion.fusion.paper.builders.gui.interfaces.GuiItem; import io.papermc.paper.persistence.PersistentDataContainerView; import net.kyori.adventure.sound.Sound; import org.bukkit.entity.Player; @@ -37,7 +37,7 @@ public void open() { final boolean isPreviewBorderEnabled = this.crate.isPreviewTierBorderToggle(); if (isPreviewBorderEnabled) { - final GuiItem guiItem = this.crate.getPreviewTierBorderItem().setPlayer(this.player).asGuiItem(); + final GuiItem guiItem = this.crate.getPreviewTierBorderItem().asGuiItem(this.player); final GuiFiller guiFiller = this.gui.getFiller(); diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/utils/CommandUtils.java b/paper/src/main/java/com/badbones69/crazycrates/paper/utils/CommandUtils.java new file mode 100644 index 000000000..06c2e398a --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/utils/CommandUtils.java @@ -0,0 +1,33 @@ +package com.badbones69.crazycrates.paper.utils; + +import com.badbones69.crazycrates.paper.CrazyCrates; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; +import com.ryderbelserion.fusion.paper.scheduler.Scheduler; +import net.kyori.adventure.audience.Audience; +import org.bukkit.Server; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.Map; + +public class CommandUtils { + + private static final CrazyCrates plugin = CrazyCrates.getPlugin(); + + private static final FusionPaper fusion = plugin.getFusion(); + + private static final Server server = plugin.getServer(); + + public static void executeCommand(@Nullable final Audience audience, @NotNull final String command, @NotNull final Map placeholders) { + if (command.isEmpty()) return; + + final String result = fusion.papi(audience, fusion.replacePlaceholder(command, placeholders)); + + new FoliaScheduler(plugin, Scheduler.global_scheduler) { + @Override + public void run() { + server.dispatchCommand(server.getConsoleSender(), result); + } + }.runNow(); + } +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/utils/ItemUtils.java b/paper/src/main/java/com/badbones69/crazycrates/paper/utils/ItemUtils.java index 9b3272bca..86bf3741a 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/utils/ItemUtils.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/utils/ItemUtils.java @@ -4,22 +4,16 @@ import com.badbones69.crazycrates.paper.api.enums.other.keys.ItemKeys; import com.badbones69.crazycrates.paper.api.objects.Crate; import com.badbones69.crazycrates.paper.tasks.crates.CrateManager; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; -import com.ryderbelserion.fusion.core.api.utils.StringUtils; +import com.ryderbelserion.fusion.core.utils.StringUtils; import com.ryderbelserion.fusion.paper.FusionPaper; -import com.ryderbelserion.fusion.paper.api.builders.items.ItemBuilder; -import com.ryderbelserion.fusion.paper.api.builders.items.types.PatternBuilder; -import com.ryderbelserion.fusion.paper.api.builders.items.types.PotionBuilder; -import com.ryderbelserion.fusion.paper.api.builders.items.types.SkullBuilder; -import com.ryderbelserion.fusion.paper.api.builders.items.types.SpawnerBuilder; -import com.ryderbelserion.fusion.paper.utils.ColorUtils; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.builders.types.PatternBuilder; +import com.ryderbelserion.fusion.paper.builders.types.PotionBuilder; +import com.ryderbelserion.fusion.paper.builders.types.SkullBuilder; +import com.ryderbelserion.fusion.paper.builders.types.custom.CustomBuilder; import io.papermc.paper.persistence.PersistentDataContainerView; -import org.bukkit.Color; -import org.bukkit.DyeColor; -import org.bukkit.block.banner.PatternType; -import org.bukkit.entity.EntityType; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemType; import org.bukkit.inventory.PlayerInventory; @@ -55,6 +49,28 @@ public static void removeItem(@NotNull final ItemStack item, @NotNull final Play item.setAmount(amount - 1); } + public static void updateEnchantGlintState(@NotNull final ItemBuilder itemBuilder, @NotNull final String state) { + final Optional legacy = StringUtils.tryParseBoolean(state); + + if (legacy.isPresent()) { + final boolean isGlowing = legacy.get(); + + if (isGlowing) { + itemBuilder.addEnchantGlint(); + } else { + itemBuilder.removeEnchantGlint(); + } + + return; + } + + switch (state) { + case "add_glow" -> itemBuilder.addEnchantGlint(); + case "remove_glow" -> itemBuilder.removeEnchantGlint(); + case "none", "" -> {} + } + } + public static String getEnchant(@NotNull final String enchant) { if (enchant.isEmpty()) return ""; @@ -158,68 +174,60 @@ public static String getKey(@NotNull final PersistentDataContainerView container return container.get(ItemKeys.crate_key.getNamespacedKey(), PersistentDataType.STRING); } - public static @NotNull LegacyItemBuilder getItem(@NotNull final ConfigurationSection section, @NotNull final LegacyItemBuilder builder, @NotNull final Player player) { - return getItem(section, builder.setPlayer(player)); - } + public static @NotNull ItemBuilder getItem(@NotNull final ConfigurationSection section, @NotNull final ItemBuilder builder) { + ItemUtils.updateEnchantGlintState(builder, section.getString("Glowing", "add_glow")); - public static @NotNull LegacyItemBuilder getItem(@NotNull final ConfigurationSection section, @NotNull final LegacyItemBuilder builder) { - if (section.contains("Glowing")) { - builder.setGlowing(section.getBoolean("Glowing", false)); - } - - builder.setDamage(section.getInt("DisplayDamage", 0)); + builder.setItemDamage(section.getInt("DisplayDamage", 0)); - builder.setDisplayLore(section.getStringList("Lore")); + builder.withDisplayLore(section.getStringList("Lore")); + + if (section.contains("Patterns")) { + final PatternBuilder patternBuilder = builder.asPatternBuilder(); - builder.addPatterns(section.getStringList("Patterns")); + for (final String key : section.getStringList("Patterns")) { + final String[] split = key.split(":"); + final String type = split[0]; + final String color = split[1]; - builder.setHidingItemFlags(section.getBoolean("HideItemFlags", false) || !section.getStringList("Flags").isEmpty()); + patternBuilder.addPattern(type, color); + } + + patternBuilder.build(); + } builder.setUnbreakable(section.getBoolean("Unbreakable", false)); if (section.contains("Skull")) { - builder.setSkull(section.getString("Skull", "")); + builder.withSkull(section.getString("Skull", "")); } - if (section.contains("Player") && builder.isPlayerHead()) { - builder.setPlayer(section.getString("Player", "")); + if (section.contains("Player")) { + builder.asSkullBuilder().withName(section.getString("Player", "")).build(); } - builder.setCustomModelData(section.getString("Custom-Model-Data", "")); + final CustomBuilder customBuilder = builder.asCustomBuilder(); - builder.setItemModel(section.getString("Model.Namespace", ""), section.getString("Model.Id", "")); - - if (section.contains("DisplayTrim.Pattern") && builder.isArmor()) { - builder.applyTrimPattern(section.getString("DisplayTrim.Pattern", "sentry")); - } - - if (section.contains("DisplayTrim.Material") && builder.isArmor()) { - builder.applyTrimMaterial(section.getString("DisplayTrim.Material", "quartz")); - } + customBuilder.setCustomModelData(section.getString("Custom-Model-Data", "")); + + customBuilder.setItemModel(section.getString("Model.Namespace", ""), section.getString("Model.Id", "")); + + customBuilder.build(); + + builder.setTrim(section.getString("DisplayTrim.Pattern", ""), section.getString("DisplayTrim.Material", "")); if (section.contains("DisplayEnchantments")) { for (final String ench : section.getStringList("DisplayEnchantments")) { String[] value = ench.split(":"); - builder.addEnchantment(value[0], Integer.parseInt(value[1]), true); + builder.addEnchantment(value[0], Integer.parseInt(value[1])); } } return builder; } - public static LegacyItemBuilder convertItemStack(@Nullable final Player player, @NotNull final ItemStack itemStack) { - LegacyItemBuilder itemBuilder = new LegacyItemBuilder(plugin, itemStack); - - if (player != null) { - itemBuilder.setPlayer(player); - } - - return itemBuilder; - } - - public static LegacyItemBuilder convertItemStack(@NotNull final ItemStack itemStack) { - return convertItemStack(null, itemStack); + public static ItemBuilder convertItemStack(@Nullable final Player player, @NotNull final ItemStack itemStack) { + return ItemBuilder.from(itemStack); } public static List convertConfigurationSection(final ConfigurationSection section) { @@ -237,13 +245,13 @@ public static List convertConfigurationSection(final ConfigurationS if (item.contains("data")) { final String base64 = item.getString("data", null); - if (base64 != null && !base64.isEmpty()) { //todo() move this if check to fusion's itembuilder as we should not set a name if it's empty to ensure Minecraft can do it's thing. + if (base64 != null && !base64.isEmpty()) { itemBuilder.withBase64(base64); } } - if (item.contains("name")) { //todo() move this if check to fusion's itembuilder as we should not set a name if it's empty to ensure Minecraft can do it's thing. - itemBuilder.setDisplayName(item.getString("name", "")); + if (item.contains("name")) { + itemBuilder.withDisplayName(item.getString("name", "")); } if (item.contains("lore")) { @@ -268,7 +276,7 @@ public static List convertConfigurationSection(final ConfigurationS } } - itemBuilder.setCustomModelData(item.getString("custom-model-data", "")); + itemBuilder.asCustomBuilder().setCustomModelData(item.getString("custom-model-data", "")).build(); if (item.getBoolean("hide-tool-tip", false)) { itemBuilder.hideToolTip(); @@ -278,8 +286,7 @@ public static List convertConfigurationSection(final ConfigurationS itemBuilder.setUnbreakable(item.getBoolean("unbreakable-item", false)); - // settings - itemBuilder.setEnchantGlint(item.getBoolean("settings.glowing", false)); + ItemUtils.updateEnchantGlintState(itemBuilder, item.getString("settings.glowing", "none")); final String player = item.getString("settings.player", null); @@ -301,14 +308,6 @@ public static List convertConfigurationSection(final ConfigurationS itemBuilder.setColor(value); - final String mobType = item.getString("settings.mob.type", null); - - if (mobType != null && !mobType.isEmpty()) { - final SpawnerBuilder spawnerBuilder = itemBuilder.asSpawnerBuilder(); - - spawnerBuilder.withEntityType(com.ryderbelserion.fusion.paper.utils.ItemUtils.getEntity(mobType)).build(); - } - itemBuilder.setTrim(item.getString("settings.trim.pattern", ""), item.getString("settings.trim.material", "")); if (itemBuilder.isPotion()) { @@ -360,12 +359,12 @@ public static List convertConfigurationSection(final ConfigurationS return cache; } - public static List convertStringList(@NotNull final List itemStrings, @NotNull final String section) { + public static List convertStringList(@NotNull final List itemStrings, @NotNull final String section) { return itemStrings.stream().map(itemString -> convertString(itemString, section)).collect(Collectors.toList()); } - public static LegacyItemBuilder convertString(@NotNull final String itemString, @NotNull final String section) { - LegacyItemBuilder itemBuilder = new LegacyItemBuilder(plugin); + public static ItemBuilder convertString(@NotNull final String itemString, @NotNull final String section) { + ItemBuilder itemBuilder = ItemBuilder.from(ItemType.STONE, 1); try { for (String optionString : itemString.split(", ")) { @@ -373,76 +372,59 @@ public static LegacyItemBuilder convertString(@NotNull final String itemString, String value = optionString.replace(option + ":", "").replace(option, ""); switch (option.toLowerCase()) { - case "item" -> itemBuilder.withType(value.toLowerCase()); - case "data" -> itemBuilder = itemBuilder.fromBase64(value); - case "name" -> itemBuilder.setDisplayName(value); - case "mob" -> { - final EntityType type = com.ryderbelserion.fusion.paper.utils.ItemUtils.getEntity(value); - - if (type != null) { - itemBuilder.setEntityType(type); - } - } - case "glowing" -> itemBuilder.setGlowing(StringUtils.tryParseBoolean(value).orElse(false)); + case "item" -> itemBuilder.withCustomItem(value.toLowerCase()); + case "data" -> itemBuilder.withBase64(value); + case "name" -> itemBuilder.withDisplayName(value); + case "glowing" -> ItemUtils.updateEnchantGlintState(itemBuilder, value); case "amount" -> { final Optional amount = StringUtils.tryParseInt(value); itemBuilder.setAmount(amount.map(Number::intValue).orElse(1)); } case "damage" -> { final Optional amount = StringUtils.tryParseInt(value); - itemBuilder.setDamage(amount.map(Number::intValue).orElse(0)); + itemBuilder.setItemDamage(amount.map(Number::intValue).orElse(0)); } - case "lore" -> itemBuilder.setDisplayLore(List.of(value.split(","))); - case "player" -> itemBuilder.setPlayer(value); - case "skull" -> itemBuilder.setSkull(value); - case "custom-model-data" -> itemBuilder.setCustomModelData(value); + case "lore" -> itemBuilder.withDisplayLore(List.of(value.split(","))); + case "player" -> itemBuilder.asSkullBuilder().withName(value).build(); + case "skull" -> itemBuilder.withSkull(value); + case "custom-model-data" -> itemBuilder.asCustomBuilder().setCustomModelData(value).build(); case "unbreakable-item" -> itemBuilder.setUnbreakable(value.isEmpty() || value.equalsIgnoreCase("true")); - case "hide-tool-tip" -> itemBuilder.setHidingItemFlags(value.equalsIgnoreCase("true")); - case "trim-pattern" -> itemBuilder.applyTrimPattern(value); - case "trim-material" -> itemBuilder.applyTrimMaterial(value); - case "rgb" -> { - @Nullable final Color color = ColorUtils.getRGB(value); - - if (color != null) { - itemBuilder.setColor(color); + case "hide-tool-tip" -> { + if (value.equalsIgnoreCase("true")) { + itemBuilder.hideToolTip(); } } - case "color" -> { - @Nullable final Color color = ColorUtils.getColor(value); + case "trim" -> { + String[] split = value.split("!"); // trim:trim_pattern!trim_material - itemBuilder.setColor(color); + String trim = split[0]; + String material = split[1]; + + itemBuilder.setTrim(trim.toLowerCase(), material.toLowerCase()); } + + case "rgb", "color" -> itemBuilder.setColor(value); + default -> { if (com.ryderbelserion.fusion.paper.utils.ItemUtils.getEnchantment(option.toLowerCase()) != null) { - final Optional amount = StringUtils.tryParseInt(value); + final Optional amount = NumberUtils.tryParseInt(value); - itemBuilder.addEnchantment(option.toLowerCase(), amount.map(Number::intValue).orElse(1), true); + if (enchantment != null) { + final Optional level = StringUtils.tryParseInt(value); - break; + itemBuilder.addEnchantment(getEnchant(option), level.map(Number::intValue).orElse(1)); } - for (ItemFlag itemFlag : ItemFlag.values()) { - if (itemFlag.name().equalsIgnoreCase(option)) { - itemBuilder.setHidingItemFlags(true); + if (itemBuilder.isBanner() || itemBuilder.isShield()) { + final PatternBuilder builder = itemBuilder.asPatternBuilder(); - break; - } + builder.addPattern(option, value).build(); } - - try { - DyeColor color = ColorUtils.getDyeColor(value); - - PatternType patternType = com.ryderbelserion.fusion.paper.utils.ItemUtils.getPatternType(option.toLowerCase()); - - if (patternType != null) { - itemBuilder.addPattern(patternType, color); - } - } catch (final Exception ignored) {} } } } } catch (final Exception exception) { - itemBuilder.withType(ItemType.RED_TERRACOTTA).setDisplayName("Error found!, Prize Name: " + section); + itemBuilder.withType(ItemType.RED_TERRACOTTA).withDisplayName("Error found!, Prize Name: " + section); fusion.log("error", "An error has occurred with the prize {}, {}", section, exception.getMessage()); } diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/utils/MiscUtils.java b/paper/src/main/java/com/badbones69/crazycrates/paper/utils/MiscUtils.java index 48665b323..2f0a06297 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/utils/MiscUtils.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/utils/MiscUtils.java @@ -1,13 +1,10 @@ package com.badbones69.crazycrates.paper.utils; import com.badbones69.crazycrates.paper.api.enums.Permissions; -import com.badbones69.crazycrates.paper.api.builders.LegacyItemBuilder; -import com.badbones69.crazycrates.paper.api.enums.other.Plugins; import com.badbones69.crazycrates.paper.api.enums.other.keys.FileKeys; -import com.ryderbelserion.fusion.paper.api.builders.items.ItemBuilder; -import com.ryderbelserion.fusion.paper.api.enums.Scheduler; -import com.ryderbelserion.fusion.paper.api.scheduler.FoliaScheduler; -import me.clip.placeholderapi.PlaceholderAPI; +import com.ryderbelserion.fusion.paper.FusionPaper; +import com.ryderbelserion.fusion.paper.builders.ItemBuilder; +import com.ryderbelserion.fusion.paper.scheduler.FoliaScheduler; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import org.bukkit.*; import org.bukkit.configuration.file.YamlConfiguration; @@ -47,29 +44,12 @@ public class MiscUtils { private static final CrazyCrates plugin = CrazyCrates.getPlugin(); + private static final FusionPaper fusion = plugin.getFusion(); + private static final Path dataPath = plugin.getDataPath(); private static final ComponentLogger logger = plugin.getComponentLogger(); - public static void sendCommand(@Nullable final CommandSender sender, @NotNull final String command, @NotNull final Map placeholders) { - if (command.isEmpty()) return; - - final Server server = plugin.getServer(); - - final String result = populatePlaceholders(sender, command, placeholders); - - new FoliaScheduler(plugin, Scheduler.global_scheduler) { - @Override - public void run() { - server.dispatchCommand(server.getConsoleSender(), result); - } - }.runNow(); - } - - public static void sendCommand(@NotNull final String command, @NotNull final Map placeholders) { - sendCommand(null, command, placeholders); - } - public static void dropBuilders(@NotNull final List builders, @NotNull final Player player) { if (builders.isEmpty()) return; @@ -82,38 +62,6 @@ public static void dropBuilders(@NotNull final List builders, @NotN dropItems(items, player); } - public static void dropLegacyBuilders(@NotNull final List builders, @NotNull final Player player) { - if (builders.isEmpty()) return; - - final boolean isPlaceholderAPIEnabled = Plugins.placeholder_api.isEnabled(); - - final List items = new ArrayList<>(); - - for (final LegacyItemBuilder builder : builders) { - if (isPlaceholderAPIEnabled) { - final String displayName = builder.getDisplayName(); - - if (!displayName.isEmpty()) { - builder.setDisplayName(PlaceholderAPI.setPlaceholders(player, displayName)); - } - - final List displayLore = builder.getDisplayLore(); - - if (!displayLore.isEmpty()) { - List lore = new ArrayList<>(); - - displayLore.forEach(line -> lore.add(PlaceholderAPI.setPlaceholders(player, line))); - - builder.setDisplayLore(lore); - } - } - - items.add(builder.asItemStack()); - } - - dropItems(items, player); - } - public static void dropItems(@NotNull final List items, @NotNull final Player player) { final Location location = player.getLocation(); @@ -154,34 +102,6 @@ public void run() { } } - public static void sendCommand(@NotNull final String command) { - sendCommand(command, new HashMap<>()); - } - - public static String populatePlaceholders(@Nullable final CommandSender sender, @NotNull String line, @NotNull final Map placeholders) { - if (sender != null && Plugins.placeholder_api.isEnabled()) { - if (sender instanceof Player player) { - line = PlaceholderAPI.setPlaceholders(player, line); - } - } - - if (!placeholders.isEmpty()) { - for (final Map.Entry placeholder : placeholders.entrySet()) { - - if (placeholder != null) { - final String key = placeholder.getKey(); - final String value = placeholder.getValue(); - - if (key != null && value != null) { - line = line.replace(key, value).replace(key.toLowerCase(), value); - } - } - } - } - - return line; - } - public static void janitor() { if (!Files.exists(dataPath.resolve("logs")) || !ConfigManager.getConfig().getProperty(ConfigKeys.log_to_file)) { return; @@ -334,7 +254,7 @@ public static void save() { return leftover; } else { - if (MiscUtils.isLogging()) logger.warn("Items cannot be null."); + fusion.log("warn", "Items cannot be null."); } return null; @@ -401,7 +321,7 @@ public static Random getRandom() { return useDifferentRandom() ? ThreadLocalRandom.current() : new Random(); } - public static LegacyItemBuilder getRandomPaneColor() { + public static ItemBuilder getRandomPaneColor() { List panes = Arrays.asList( ItemType.LIGHT_BLUE_STAINED_GLASS_PANE, ItemType.MAGENTA_STAINED_GLASS_PANE, @@ -419,7 +339,7 @@ public static LegacyItemBuilder getRandomPaneColor() { ItemType.RED_STAINED_GLASS_PANE ); - return new LegacyItemBuilder(plugin, panes.get(ThreadLocalRandom.current().nextInt(panes.size()))); + return ItemBuilder.from(panes.get(ThreadLocalRandom.current().nextInt(panes.size())), 1); } public static void addItem(@NotNull final Player player, @NotNull final ItemStack... items) { diff --git a/paper/src/main/java/com/badbones69/crazycrates/paper/utils/MsgUtils.java b/paper/src/main/java/com/badbones69/crazycrates/paper/utils/MsgUtils.java index dddecc48c..0f2226cc6 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/paper/utils/MsgUtils.java +++ b/paper/src/main/java/com/badbones69/crazycrates/paper/utils/MsgUtils.java @@ -2,21 +2,71 @@ import com.badbones69.crazycrates.core.config.ConfigManager; import com.badbones69.crazycrates.core.config.impl.ConfigKeys; +import com.badbones69.crazycrates.paper.CrazyCrates; +import com.ryderbelserion.fusion.core.utils.StringUtils; +import com.ryderbelserion.fusion.paper.FusionPaper; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; -import static java.util.regex.Matcher.quoteReplacement; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; public class MsgUtils { - public static void sendMessage(@NotNull final CommandSender sender, @NotNull final String message, final boolean prefixToggle) { + private static @NotNull final CrazyCrates plugin = CrazyCrates.getPlugin(); + + private static @NotNull final FusionPaper fusion = plugin.getFusion(); + + public static void message(@NotNull final CommandSender sender, @NotNull final String message, @NotNull final Map placeholders, final boolean includePrefix) { if (message.isEmpty()) return; final String prefix = ConfigManager.getConfig().getProperty(ConfigKeys.command_prefix); - final boolean sendPrefix = !prefix.isEmpty() && prefixToggle; + final boolean hasPrefix = !prefix.isEmpty() && includePrefix; + + final Map safePlaceholders = new HashMap<>(placeholders); + + if (hasPrefix) { + safePlaceholders.put("%prefix%", prefix); + safePlaceholders.put("%Prefix%", prefix); + + safePlaceholders.put("{prefix}", prefix); + } + + sender.sendMessage(fusion.parse(sender, message, safePlaceholders)); + } + + public static String getRandomNumber(@NotNull final String value) { + String safeLine = value; + + if (safeLine.contains("%random%")) { + safeLine = fusion.replacePlaceholder(safeLine, new HashMap<>() {{ + put("%random%", "{random}"); + }}); + } + + if (safeLine.contains("{random}")) { + final String number = safeLine.split(":")[1]; + + if (number.contains("-")) { + final String[] splitter = number.split("-"); + + final Optional minRange = StringUtils.tryParseInt(splitter[0]); + final Optional maxRange = StringUtils.tryParseInt(splitter[1]); + + if (minRange.isPresent() && maxRange.isPresent()) { + final int minimum = minRange.get().intValue(); + final int maximum = maxRange.get().intValue(); + + final int amount = MiscUtils.getRandom().nextInt(minimum, maximum); - final String msg = sendPrefix ? message.replaceAll("%prefix%", quoteReplacement(prefix)).replaceAll("%Prefix%", quoteReplacement(prefix)) : message; + safeLine = safeLine.replace("%s:%s-%s".formatted("{random}", minimum, maximum), String.valueOf(amount)); + } else { + fusion.log("warn", "The values supplied with {} seem to not be integers. {}", "{random}", value); + } + } + } - sender.sendRichMessage(msg); + return safeLine; } } \ No newline at end of file diff --git a/paper/src/main/resources/config.yml b/paper/src/main/resources/config.yml index 5d2c4601a..3a0fce8c6 100644 --- a/paper/src/main/resources/config.yml +++ b/paper/src/main/resources/config.yml @@ -14,7 +14,7 @@ root: # You can run /crazycrates migrate -mt NewItemFormat which should migrate all existing prizes after you set this to true # # Take a backup before you run the migration as there may be bugs. - use-different-items-layout: false + use-different-items-layout: true # This option defines what in-game editor format is used in CrazyCrates. # # true -> uses the new editor diff --git a/paper/src/main/resources/crates/AdvancedExample.yml b/paper/src/main/resources/crates/AdvancedExample.yml index 79b6d0b8b..96bf3de87 100644 --- a/paper/src/main/resources/crates/AdvancedExample.yml +++ b/paper/src/main/resources/crates/AdvancedExample.yml @@ -12,22 +12,17 @@ Crate: RequiredKeys: 10 # Max amount of crates that can be opened at once using /crates mass-open Max-Mass-Open: 10 - # If the crate shows in /crates. - # If the type is QuickCrate/CrateOnTheGo/FireCracker, They will not work as they require a Physical Crate. - InGUI: true - # Slot the item is in the GUI. - Slot: 13 # Enables/Disables the Broadcasts message when they open a crate. OpeningBroadCast: true # Message that is broadcast when opening the crate. - BroadCast: "%prefix%%player% is opening a Advanced Crate." + BroadCast: "{prefix}{player} is opening a Advanced Crate." # This section is related to commands opening when a crate is opened. opening-command: # If the commands should be sent or not. toggle: false # The commands to run when the crate opens. # Supports all placeholderapi placeholders - # Supports %prefix which returns our prefix, %player% which uses the player name + # Supports {prefix} which returns our prefix, {player} which uses the player name commands: - "put your command here." sound: @@ -67,7 +62,7 @@ Crate: # A default message if the prize doesn't have any Messages # i.e. Messages: [] or the value isn't there. Prize-Message: - - "You have won %reward% from %crate%." + - "You have won {reward} from {crate}." # A list of commands to run by default on every prize. # If you do not want these commands to run, set this to [] Prize-Commands: [] @@ -79,7 +74,7 @@ Crate: Toggle: false # The messages to broadcast. Messages: - - "%player% won the prize %reward%." + - "{player} won the prize {reward}." # If the player has this permission, they don't get the broadcast. Permission: "" # Settings related to rewards. @@ -93,27 +88,6 @@ Crate: # i.e. crazycrates.respin.crate_name.1-20 # It will simply register multiple permissions, so it shows up in things like LuckPerms. Max-Cap: 20 - # Item the crate is in the GUI - Item: "chest" - # The custom model data of the item, -1 is disabled. - Custom-Model-Data: -1 - # The item model, Mojang introduced this in 1.21.4... this replaces custom model data! - # Set this to blank for it to do nothing. - Model: - # The namespace i.e. nexo - Namespace: "" - # The id i.e. emerald_helmet - Id: "" - # If the crate in the main /cc GUI is glowing or not. - Glowing: false - # Name of the item in the GUI. - Name: "Advanced Crate" - # The lore of the item in the GUI. - Lore: - - "This crate contains strange objects." - - "You have %keys% keys to open this crate with." - - "You have opened this crate: %crate_opened% times" - - "(!) Right click to view rewards." Preview: # The name of the inventory for the preview menu. Name: "Advanced Crate Preview" @@ -138,6 +112,33 @@ Crate: Namespace: "" # The id i.e. emerald_helmet Id: "" + # Settings related to the item in /crates + Display: + # If the crate shows in the /crates. + # If the type is QuickCrate/CrateOnTheGo/FireCracker, They will not work as they require a Physical Crate. + Toggle: true + # Item the crate is in the GUI + Item: "chest" + # Name of the item in the GUI. + Name: "Advanced Crate" + # The lore of the item in the GUI. + Lore: + - "This crate contains strange objects." + - "You have {keys} keys to open this crate with." + - "You have opened this crate: {crate_opened} times" + - "(!) Right click to view rewards." + # The item model, Mojang introduced this in 1.21.4... this replaces custom model data! + # Set this to blank for it to do nothing. + Model: + # The namespace i.e. nexo + Namespace: "" + # The id i.e. emerald_helmet + Id: "" + # Available Types: add_glow, remove_glow, or none. + # None, or blank value means no state will be applied. + Glowing: "add_glow" + # Slot the item is in the GUI. + Slot: 13 PhysicalKey: # Name of the Key. Name: "Advanced Crate Key" @@ -156,8 +157,9 @@ Crate: Namespace: "" # The id i.e. emerald_helmet Id: "" - # Makes the key look enchanted. - Glowing: true + # Available Types: add_glow, remove_glow, or none. + # None, or blank value means no state will be applied. + Glowing: "add_glow" # Settings for the holograms. Hologram: # Toggle on and off the holograms for the crates. @@ -217,13 +219,100 @@ Crate: Commands: # This adds the blacklist permission to the player when they win the prize, # After this, they will no longer be able to use this prize. - - "lp user %player% permission set crazycrates.blacklist.warlord" + - "lp user {player} permission set crazycrates.blacklist.warlord" # The list of items to give. Items: - - "Item:netherite_helmet, Amount:1, Damage:25, Trim-Pattern:sentry, Trim-Material:redstone, Name:Warlord's Helmet, protection:5, unbreaking:3" - - "Item:netherite_chestplate, Amount:1, Damage:25, Trim-Pattern:sentry, Trim-Material:redstone, Name:Warlord's Chestplate, protection:5, unbreaking:3" - - "Item:netherite_leggings, Amount:1, Damage:25, Trim-Pattern:sentry, Trim-Material:redstone, Name:Warlord's Leggings, protection:5, unbreaking:3" - - "Item:netherite_boots, Amount:1, Damage:25, Trim-Pattern:sentry, Trim-Material:redstone, Name:Warlord's Boots, protection:5, unbreaking:3" + 1: + # The material of the item. + material: "netherite_helmet" + # The amount of the item to give. + amount: 1 + # Generic settings. + settings: + # The damage to apply to the item. + damage: 25 + # The trim settings + trim: + # The trim pattern of the armor. + pattern: "sentry" + # The trim material of the armor. + material: "redstone" + # The name of the item. + name: "Warlord's Helmet" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 3 + protection: 5 + 2: + # The material of the item. + material: "netherite_chestplate" + # The amount of the item to give. + amount: 1 + # Generic settings. + settings: + # The damage to apply to the item. + damage: 25 + # The trim settings + trim: + # The trim pattern of the armor. + pattern: "sentry" + # The trim material of the armor. + material: "redstone" + # The name of the item. + name: "Warlord's Chestplate" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 3 + protection: 5 + 3: + # The material of the item. + material: "netherite_boots" + # The amount of the item to give. + amount: 1 + settings: + # The damage to apply to the item. + damage: 25 + # The trim settings + trim: + # The trim pattern of the armor. + pattern: "sentry" + # The trim material of the armor. + material: "redstone" + # The name of the item. + name: "Warlord's Leggings" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 3 + protection: 5 + 4: + # The material of the item. + material: "netherite_boots" + # The name of the item. + name: "Warlord's Boots" + # The amount of the item to give. + amount: 1 + # Generic settings. + settings: + # The damage to apply to the item. + damage: 25 + # The trim settings + trim: + # The trim pattern of the armor. + pattern: "sentry" + # The trim material of the armor. + material: "redstone" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 3 + protection: 5 # A list of permissions, If a player has any of these permissions. they cannot win this prize again! BlackListed-Permissions: - "crazycrates.blacklist.warlord" @@ -236,10 +325,15 @@ Crate: - " [CrazyCrates]: You have already won that prize, so enjoy some gold nuggets." # A list of commands to run. Commands: - - "give %player% gold_nugget 16" + - "give {player} gold_nugget 16" # Alternatively, instead of commands. You can have an Items section which functions the same as the Items section above. + # The list of items to win. Items: - - "Item:gold_nugget, Amount:16" + 1: + # The material of the item. + material: "gold_nugget" + # The amount of the item to give. + amount: 16 "2": # The enchants to be stored on the book. DisplayEnchantments: @@ -268,4 +362,12 @@ Crate: Weight: 25.0 # The list of items to win. Items: - - "Item:enchanted_book, protection:5, unbreaking:3" \ No newline at end of file + 1: + # The material of the item. + material: "enchanted_book" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 3 + protection: 5 \ No newline at end of file diff --git a/paper/src/main/resources/crates/CasinoCrate.yml b/paper/src/main/resources/crates/CasinoCrate.yml index 60a45eecd..c569cded4 100644 --- a/paper/src/main/resources/crates/CasinoCrate.yml +++ b/paper/src/main/resources/crates/CasinoCrate.yml @@ -12,22 +12,17 @@ Crate: RequiredKeys: 20 # Max amount of crates that can be opened at once using /crates mass-open Max-Mass-Open: 10 - # If the crate shows in /crates. - # If the type is QuickCrate/CrateOnTheGo/FireCracker, They will not work as they require a Physical Crate. - InGUI: true - # Slot the item is in the GUI. - Slot: 15 # Enables/Disables the Broadcasts message when they open a crate. OpeningBroadCast: true # Message that is broadcast when opening the crate. - BroadCast: "%prefix%%player% is opening a Casino Crate." + BroadCast: "{prefix}{player} is opening a Casino Crate." # This section is related to commands opening when a crate is opened. opening-command: # If the commands should be sent or not. toggle: false # The commands to run when the crate opens. # Supports all placeholderapi placeholders - # Supports %prefix which returns our prefix, %player% which uses the player name + # Supports {prefix} which returns our prefix, {player} which uses the player name commands: - "put your command here." sound: @@ -67,7 +62,7 @@ Crate: # A default message if the prize doesn't have any Messages # i.e. Messages: [] or the value isn't there. Prize-Message: - - "You have won %reward% from %crate%." + - "You have won {reward} from {crate}." # A list of commands to run by default on every prize. # If you do not want these commands to run, set this to [] Prize-Commands: [] @@ -84,30 +79,9 @@ Crate: Toggle: false # The messages to broadcast. Messages: - - "%player% won the prize %reward%." + - "{player} won the prize {reward}." # If the player has this permission, they don't get the broadcast. Permission: "" - # Item the crate is in the GUI - Item: "gold_ingot" - # The custom model data of the item, -1 is disabled. - Custom-Model-Data: -1 - # The item model, Mojang introduced this in 1.21.4... this replaces custom model data! - # Set this to blank for it to do nothing. - Model: - # The namespace i.e. nexo - Namespace: "" - # The id i.e. emerald_helmet - Id: "" - # If the crate in the main /crates is glowing or not. - Glowing: false - # Name of the item in the GUI. - Name: "Casino Crate" - # The lore of the item in the GUI. - Lore: - - "This crate contains strange objects." - - "You have %keys% keys to open this crate with." - - "You have opened this crate: %crate_opened% times" - - "(!) Right click to view rewards." Preview: # The name of the inventory for the preview menu. Name: "Casino Crate Preview" @@ -132,6 +106,33 @@ Crate: Id: "" # The item that shows in the border. Can be glass or any other item. Item: "gray_stained_glass_pane" + # Settings related to the item in /crates + Display: + # If the crate shows in the /crates. + # If the type is QuickCrate/CrateOnTheGo/FireCracker, They will not work as they require a Physical Crate. + Toggle: true + # Item the crate is in the GUI + Item: "gold_ingot" + # Name of the item in the GUI. + Name: "Casino Crate" + # The lore of the item in the GUI. + Lore: + - "This crate contains strange objects." + - "You have {keys} keys to open this crate with." + - "You have opened this crate: {crate_opened} times" + - "(!) Right click to view rewards." + # The item model, Mojang introduced this in 1.21.4... this replaces custom model data! + # Set this to blank for it to do nothing. + Model: + # The namespace i.e. nexo + Namespace: "" + # The id i.e. emerald_helmet + Id: "" + # Available Types: add_glow, remove_glow, or none. + # None, or blank value means no state will be applied. + Glowing: "add_glow" + # Slot the item is in the GUI. + Slot: 15 tier-preview: # Turn on and off the preview for this crate. toggle: true @@ -176,7 +177,7 @@ Crate: # The in-game lore of the tier. Lore: - "A basic tier." - - "%chance%%" + - "{chance}%" # The item used for the secondary gui when you right-click for the preview. Item: "chest" # The custom model data of the item, -1 is disabled. @@ -198,7 +199,7 @@ Crate: # The in-game lore of the tier. Lore: - "An uncommon tier." - - "%chance%%" + - "{chance}%" # The item used for the secondary gui when you right-click for the preview. Item: "chest" # The custom model data of the item, -1 is disabled. @@ -220,7 +221,7 @@ Crate: # The in-game lore of the tier. Lore: - "A rare tier." - - "%chance%%" + - "{chance}%" # The item used for the secondary gui when you right-click for the preview. Item: "ender_chest" # The custom model data of the item, -1 is disabled. @@ -254,8 +255,9 @@ Crate: - "For a special Crate." # The item the key is. Item: "cyan_dye" - # Makes the key look enchanted. - Glowing: true + # Available Types: add_glow, remove_glow, or none. + # None, or blank value means no state will be applied. + Glowing: "add_glow" # Settings for the holograms. Hologram: # Toggle on and off the holograms for the crates. @@ -305,8 +307,17 @@ Crate: Player: "1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e" # Only uncomment this if using HeadDatabase by Arcaniax # Skull: "7129" + # The list of items to give. Items: - - "Item:player_head, Player:1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e, Name:BadBones69" + 1: + material: "player_head" + # The name of the item. + name: "BadBones69" + # Generic settings. + settings: + # The player name/texture to display. + # https://minecraft-heads.com/ + player: "1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e" "2": # The name of the item to display in the gui. DisplayName: "Warlord's Set" @@ -349,13 +360,100 @@ Crate: Commands: # This adds the blacklist permission to the player when they win the prize, # After this, they will no longer be able to use this prize. - - "lp user %player% permission set crazycrates.blacklist.warlord" + - "lp user {player} permission set crazycrates.blacklist.warlord" # The list of items to give. Items: - - "Item:netherite_helmet, Amount:1, Damage:25, Trim-Pattern:sentry, Trim-Material:redstone, Name:Warlord's Helmet, protection:5, unbreaking:3" - - "Item:netherite_chestplate, Amount:1, Damage:25, Trim-Pattern:sentry, Trim-Material:redstone, Name:Warlord's Chestplate, protection:5, unbreaking:3" - - "Item:netherite_leggings, Amount:1, Damage:25, Trim-Pattern:sentry, Trim-Material:redstone, Name:Warlord's Leggings, protection:5, unbreaking:3" - - "Item:netherite_boots, Amount:1, Damage:25, Trim-Pattern:sentry, Trim-Material:redstone, Name:Warlord's Boots, protection:5, unbreaking:3" + 1: + # The material of the item. + material: "netherite_helmet" + # The amount of the item to give. + amount: 1 + # Generic settings. + settings: + # The damage to apply to the item. + damage: 25 + # The trim settings + trim: + # The trim pattern of the armor. + pattern: "sentry" + # The trim material of the armor. + material: "redstone" + # The name of the item. + name: "Warlord's Helmet" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 3 + protection: 5 + 2: + # The material of the item. + material: "netherite_chestplate" + # The amount of the item to give. + amount: 1 + # Generic settings. + settings: + # The damage to apply to the item. + damage: 25 + # The trim settings + trim: + # The trim pattern of the armor. + pattern: "sentry" + # The trim material of the armor. + material: "redstone" + # The name of the item. + name: "Warlord's Chestplate" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 3 + protection: 5 + 3: + # The material of the item. + material: "netherite_boots" + # The amount of the item to give. + amount: 1 + settings: + # The damage to apply to the item. + damage: 25 + # The trim settings + trim: + # The trim pattern of the armor. + pattern: "sentry" + # The trim material of the armor. + material: "redstone" + # The name of the item. + name: "Warlord's Leggings" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 3 + protection: 5 + 4: + # The material of the item. + material: "netherite_boots" + # The amount of the item to give. + amount: 1 + # Generic settings. + settings: + # The damage to apply to the item. + damage: 25 + # The trim settings + trim: + # The trim pattern of the armor. + pattern: "sentry" + # The trim material of the armor. + material: "redstone" + # The name of the item. + name: "Warlord's Boots" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 3 + protection: 5 # A list of permissions, If a player has any of these permissions. they cannot win this prize again! BlackListed-Permissions: - "crazycrates.blacklist.warlord" @@ -368,10 +466,15 @@ Crate: - " [CrazyCrates]: You have already won that prize, so enjoy some gold nuggets." # A list of commands to run. Commands: - - "give %player% gold_nugget 16" + - "give {player} gold_nugget 16" # Alternatively, instead of commands. You can have an Items section which functions the same as the Items section above. + # The list of items to win. Items: - - "Item:gold_nugget, Amount:16" + 1: + # The material of the item. + material: "gold_nugget" + # The amount of the item to give. + amount: 16 "3": # The enchants to be stored on the book. DisplayEnchantments: @@ -404,7 +507,15 @@ Crate: - "Rare" # The list of items to win. Items: - - "Item:enchanted_book, protection:5, unbreaking:3" + 1: + # The material of the item. + material: "enchanted_book" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 3 + protection: 5 "4": # The name of the item to display in the gui. DisplayName: "Fancy Pants" @@ -446,13 +557,34 @@ Crate: # The lore of the item. DisplayLore: - "Win a fancy pair of pants." - - "Chance: %chance%" - # The items to win. + - "Chance: {chance}" + # The list of items to win. Items: - - "Item:chainmail_leggings, Amount:1, Damage:75, Trim-Pattern:sentry, Trim-Material:lapis, Name:Fancy Pants, protection:2" + 1: + # The material of the item. + material: "chainmail_leggings" + # The name of the item. + name: "Fancy Pants" + # The amount of the item to give. + amount: 1 + # Generic settings. + settings: + # The damage to apply to the item. + damage: 75 + # The trim settings + trim: + # The trim pattern of the armor. + pattern: "sentry" + # The trim material of the armor. + material: "lapis" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + protection: 2 # The messages to send. Messages: - - "You just won a %reward%." + - "You just won a {reward}." "5": # The name of the item to display in the gui. DisplayName: "Classic Sword" @@ -491,9 +623,25 @@ Crate: - "Basic" - "UnCommon" - "Rare" - # The items to win. + # The list of items to win. Items: - - "Item:diamond_sword, Amount:1, Damage:7, Name:Classic Sword, sharpness:2, fire_aspect:1" + 1: + # The material of the item. + material: "diamond_sword" + # The name of the item. + name: "Classic Sword" + # The amount of the item to give. + amount: 1 + # Generic settings. + settings: + # The damage to apply to the item. + damage: 7 + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + sharpness: 2 + fire_aspect: 1 # The messages to send. Messages: - - "You just won %reward%." \ No newline at end of file + - "You just won {reward}." \ No newline at end of file diff --git a/paper/src/main/resources/crates/CosmicCrate.yml b/paper/src/main/resources/crates/CosmicCrate.yml index d21d7c28a..88da27794 100644 --- a/paper/src/main/resources/crates/CosmicCrate.yml +++ b/paper/src/main/resources/crates/CosmicCrate.yml @@ -12,22 +12,17 @@ Crate: RequiredKeys: 4 # Max amount of crates that can be opened at once using /crates mass-open Max-Mass-Open: 10 - # If the crate shows in the /crates. - # If the type is QuickCrate/CrateOnTheGo/FireCracker, They will not work as they require a Physical Crate. - InGUI: true - # Slot the item is in the GUI. - Slot: 29 # Enables/Disables the Broadcasts message when they open a crate. OpeningBroadCast: true # Message that is broadcast when opening the crate. - BroadCast: "%prefix%%player% is opening a Cosmic Crate." + BroadCast: "{prefix}{player} is opening a Cosmic Crate." # This section is related to commands opening when a crate is opened. opening-command: # If the commands should be sent or not. toggle: false # The commands to run when the crate opens. # Supports all placeholderapi placeholders - # Supports %prefix which returns our prefix, %player% which uses the player name + # Supports {prefix} which returns our prefix, {player} which uses the player name commands: - "put your command here." sound: @@ -67,7 +62,7 @@ Crate: # A default message if the prize doesn't have any Messages # i.e. Messages: [] or the value isn't there. Prize-Message: - - "You have won %reward% from %crate%." + - "You have won {reward} from {crate}." # A list of commands to run by default on every prize. # If you do not want these commands to run, set this to [] Prize-Commands: [] @@ -79,30 +74,9 @@ Crate: Toggle: false # The messages to broadcast. Messages: - - "%player% won the prize %reward%." + - "{player} won the prize {reward}." # If the player has this permission, they don't get the broadcast. Permission: "" - # Item the crate is in the GUI - Item: "ender_chest" - # The custom model data of the item, -1 is disabled. - Custom-Model-Data: -1 - # The item model, Mojang introduced this in 1.21.4... this replaces custom model data! - # Set this to blank for it to do nothing. - Model: - # The namespace i.e. nexo - Namespace: "" - # The id i.e. emerald_helmet - Id: "" - # If the crate in the main /crates is glowing or not. - Glowing: false - # Name of the item in the GUI. - Name: "Cosmic Crate" - # The lore of the item in the GUI. - Lore: - - "This crate contains strange objects." - - "You have %keys% keys to open this crate with." - - "You have opened this crate: %crate_opened% times" - - "(!) Right click to view rewards." Preview: # The name of the inventory for the preview menu. Name: "Cosmic Crate Preview" @@ -127,6 +101,33 @@ Crate: Id: "" # The item that shows in the border. Can be glass or any other item. Item: "gray_stained_glass_pane" + # Settings related to the item in /crates + Display: + # If the crate shows in the /crates. + # If the type is QuickCrate/CrateOnTheGo/FireCracker, They will not work as they require a Physical Crate. + Toggle: true + # Item the crate is in the GUI + Item: "ender_chest" + # Name of the item in the GUI. + Name: "Cosmic Crate" + # The lore of the item in the GUI. + Lore: + - "This crate contains strange objects." + - "You have {keys} keys to open this crate with." + - "You have opened this crate: {crate_opened} times" + - "(!) Right click to view rewards." + # The item model, Mojang introduced this in 1.21.4... this replaces custom model data! + # Set this to blank for it to do nothing. + Model: + # The namespace i.e. nexo + Namespace: "" + # The id i.e. emerald_helmet + Id: "" + # Available Types: add_glow, remove_glow, or none. + # None, or blank value means no state will be applied. + Glowing: "add_glow" + # Slot the item is in the GUI. + Slot: 29 tier-preview: # Turn on and off the preview for this crate. toggle: true @@ -163,7 +164,7 @@ Crate: # The in-game lore of the tier. Lore: - "A basic tier." - - "%chance%%" + - "{chance}%" # The item used for the secondary gui when you right-click for the preview. Item: "chest" # The custom model data of the item, -1 is disabled. @@ -185,7 +186,7 @@ Crate: # The in-game lore of the tier. Lore: - "An uncommon tier." - - "%chance%%" + - "{chance}%" # The item used for the secondary gui when you right-click for the preview. Item: "chest" # The custom model data of the item, -1 is disabled. @@ -207,7 +208,7 @@ Crate: # The in-game lore of the tier. Lore: - "A rare tier." - - "%chance%%" + - "{chance}%" # The item used for the secondary gui when you right-click for the preview. Item: "ender_chest" # The custom model data of the item, -1 is disabled. @@ -240,8 +241,9 @@ Crate: - "A fancy key to open a cosmical crate!" # The item the key is. Item: "purple_dye" - # Makes the key look enchanted. - Glowing: true + # Available Types: add_glow, remove_glow, or none. + # None, or blank value means no state will be applied. + Glowing: "add_glow" # Settings for the holograms. Hologram: # Toggle on and off the holograms for the crates. @@ -298,7 +300,7 @@ Crate: Name: "???" # The lore of the picked crate. Lore: - - "You have chosen #%slot%." + - "You have chosen #{slot}." # All the prizes that can be obtained in the Crate. Prizes: "1": @@ -331,8 +333,18 @@ Crate: Player: "1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e" # Only uncomment this if using HeadDatabase by Arcaniax # Skull: "7129" + # The list of items to win. Items: - - "Item:player_head, Player:1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e, Name:BadBones69" + 1: + # The material of the item. + material: "player_head" + # The name of the item. + name: "BadBones69" + # Generic settings. + settings: + # The player name/texture to display. + # https://minecraft-heads.com/ + player: "1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e" "2": DisplayName: "Cheap Helmet" DisplayItem: "golden_helmet" @@ -367,15 +379,36 @@ Crate: # The lore of the item. DisplayLore: - "Win a cheap helmet." - - "Chance: %chance%" + - "Chance: {chance}" # The tiers the prize can be won from. Tiers: - "Basic" - "UnCommon" - "Rare" - # The items to win. + # The list of items to win. Items: - - "Item:golden_helmet, Amount:1, Damage:5, Trim-Pattern:sentry, Trim-Material:diamond, Name:Cheap Helmet, protection:1, aqua_affinity:1" + 1: + material: "golden_helmet" + # The name of the item. + name: "Cheap Helmet" + # The amount of the item to give. + amount: 1 + # Generic settings. + settings: + # The damage to apply to the item. + damage: 5 + # The trim settings + trim: + # The trim pattern of the armor. + pattern: "sentry" + # The trim material of the armor. + material: "diamond" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + protection: 1 + aqua_affinity: 1 "3": # The name of the item to display in the gui. DisplayName: "$1,000" @@ -399,7 +432,7 @@ Crate: # The lore of the item. DisplayLore: - "Make it rain Money." - - "Chance: %chance%" + - "Chance: {chance}" # If the prize should spawn fireworks. Firework: true # The tiers the prize can be won from. @@ -409,7 +442,7 @@ Crate: - "Rare" # The commands to run. Commands: - - "eco give %player% 1000" + - "eco give {player} 1000" "4": # The name of the item to display in the gui. DisplayName: "Crazy Sword" @@ -440,13 +473,29 @@ Crate: # The lore of the item. DisplayLore: - "Win a crazy cool sword." - - "Chance: %chance%" + - "Chance: {chance}" # The tiers the prize can be won from. Tiers: - "Rare" - # The items to win. + # The list of items to win. Items: - - "Item:golden_sword, Amount:1, Damage:12, Name:Crazy Sword, sharpness:5, fire_aspect:1" + 1: + # The material of the item. + material: "golden_sword" + # The name of the item. + name: "Crazy Sword" + # The amount of the item to give. + amount: 1 + # Generic settings. + settings: + # The damage to apply to the item. + damage: 12 + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + sharpness: 5 + fire_aspect: 1 "5": # The name of the item to display in the gui. DisplayName: "$1,000,000" @@ -470,7 +519,7 @@ Crate: # The lore of the item. DisplayLore: - "Make it rain a butt load of Money." - - "Chance: %chance%" + - "Chance: {chance}" # If the prize should spawn fireworks. Firework: true # The tiers the prize can be won from. @@ -478,7 +527,7 @@ Crate: - "Rare" # The commands to run. Commands: - - "eco give %player% 1000000" + - "eco give {player} 1000000" "6": # The name of the item to display in the gui. DisplayName: "Crazy Crate Key (x2)" @@ -503,15 +552,16 @@ Crate: DisplayLore: - "A special Key" - "For a special Crate." - - "Chance: %chance%" + - "Chance: {chance}" # If the prize should spawn fireworks. Firework: true - # If the display item should glow. - Glowing: true + # Available Types: add_glow, remove_glow, or none. + # None, or blank value means no state will be applied. + Glowing: "add_glow" # The tiers the prize can be won from. Tiers: - "UnCommon" - "Rare" # The commands to run. Commands: - - "crates give physical CrateExample 2 %player%" \ No newline at end of file + - "crates give physical CrateExample 2 {player}" \ No newline at end of file diff --git a/paper/src/main/resources/crates/CrateExample.yml b/paper/src/main/resources/crates/CrateExample.yml index ef4b4a50f..241ae7396 100644 --- a/paper/src/main/resources/crates/CrateExample.yml +++ b/paper/src/main/resources/crates/CrateExample.yml @@ -12,22 +12,17 @@ Crate: RequiredKeys: 0 # Max amount of crates that can be opened at once using /crates mass-open Max-Mass-Open: 10 - # If the crate shows in the /crates. - # If the type is QuickCrate/CrateOnTheGo/FireCracker, They will not work as they require a Physical Crate. - InGUI: true - # Slot the item is in the GUI. - Slot: 11 # Enables/Disables the Broadcasts message when they open a crate. OpeningBroadCast: true # Message that is broadcast when opening the crate. - BroadCast: "%prefix%%player% is opening a Basic Crate." + BroadCast: "{prefix}{player} is opening a Basic Crate." # This section is related to commands opening when a crate is opened. opening-command: # If the commands should be sent or not. toggle: false # The commands to run when the crate opens. # Supports all placeholderapi placeholders - # Supports %prefix which returns our prefix, %player% which uses the player name + # Supports {prefix} which returns our prefix, {player} which uses the player name commands: - "put your command here." sound: @@ -67,7 +62,7 @@ Crate: # A default message if the prize doesn't have any Messages # i.e. Messages: [] or the value isn't there. Prize-Message: - - "You have won %reward% from %crate%." + - "You have won {reward} from {crate}." # A list of commands to run by default on every prize. # If you do not want these commands to run, set this to [] Prize-Commands: [] @@ -87,7 +82,7 @@ Crate: Toggle: false # The messages to broadcast. Messages: - - "%player% won the prize %reward%." + - "{player} won the prize {reward}." # If the player has this permission, they don't get the broadcast. Permission: "" # Settings related to rewards. @@ -104,27 +99,7 @@ Crate: # i.e. crazycrates.respin..1-20 # It will simply register multiple permissions, so it shows up in things like LuckPerms. Max-Cap: 20 - # Item the crate is in the GUI - Item: "diamond" - # The custom model data of the item, -1 is disabled. - Custom-Model-Data: -1 - # The item model, Mojang introduced this in 1.21.4... this replaces custom model data! - # Set this to blank for it to do nothing. - Model: - # The namespace i.e. nexo - Namespace: "" - # The id i.e. emerald_helmet - Id: "" - # If the crate in the main /crates is glowing or not. - Glowing: false - # Name of the item in the GUI. - Name: "Basic Crate" - # The lore of the item in the GUI. - Lore: - - "This crate contains strange objects." - - "You have %keys% keys to open this crate with." - - "You have opened this crate: %crate_opened% times" - - "(!) Right click to view rewards." + # Preview related settings Preview: # The name of the inventory for the preview menu. Name: "Basic Crate Preview" @@ -149,6 +124,33 @@ Crate: Namespace: "" # The id i.e. emerald_helmet Id: "" + # Settings related to the item in /crates + Display: + # If the crate shows in the /crates. + # If the type is QuickCrate/CrateOnTheGo/FireCracker, They will not work as they require a Physical Crate. + Toggle: true + # Item the crate is in the GUI + Item: "diamond" + # Name of the item in the GUI. + Name: "Basic Crate" + # The lore of the item in the GUI. + Lore: + - "This crate contains strange objects." + - "You have {keys} keys to open this crate with." + - "You have opened this crate: {crate_opened} times" + - "(!) Right click to view rewards." + # The item model, Mojang introduced this in 1.21.4... this replaces custom model data! + # Set this to blank for it to do nothing. + Model: + # The namespace i.e. nexo + Namespace: "" + # The id i.e. emerald_helmet + Id: "" + # Available Types: add_glow, remove_glow, or none. + # None, or blank value means no state will be applied. + Glowing: "add_glow" + # Slot the item is in the GUI. + Slot: 11 # Settings related to animations... Animation: # This is only when an animation starts. @@ -213,8 +215,9 @@ Crate: Namespace: "" # The id i.e. emerald_helmet Id: "" - # Makes the key look enchanted. - Glowing: true + # Available Types: add_glow, remove_glow, or none. + # None, or blank value means no state will be applied. + Glowing: "add_glow" # Settings for the holograms. Hologram: # Toggle on and off the holograms for the crates. @@ -263,8 +266,18 @@ Crate: Player: "1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e" # Only uncomment this if using HeadDatabase by Arcaniax # Skull: "7129" + # The list of items to win. Items: - - "Item:player_head, Player:1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e, Name:BadBones69" + 1: + # The material of the item. + material: "player_head" + # The name of the item. + name: "BadBones69" + # Generic settings. + settings: + # The player name/texture to display. + # https://minecraft-heads.com/ + player: "1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e" "2": # The name of the item to display in the gui. DisplayName: "Diamond Sword" @@ -291,7 +304,17 @@ Crate: Weight: 15.0 # The list of items to win. Items: - - "Item:diamond_sword, Name:Diamond Sword, sharpness:5, looting:3" + 1: + # The material of the item. + material: "diamond_sword" + # The name of the item. + name: "Diamond Sword" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + looting: 3 + sharpness: 5 "3": # The name of the item to display in the gui. DisplayName: "Diamond Helmet" @@ -326,7 +349,25 @@ Crate: Weight: 15.0 # The list of items to win. Items: - - "Item:diamond_helmet, Name:Diamond Helmet, protection:5, unbreaking:3, Trim-Material:quartz, Trim-Pattern:sentry" + 1: + # The material of the item. + material: "diamond_helmet" + # The name of the item. + name: "Diamond Helmet" + # Generic settings. + settings: + # The trim settings + trim: + # The trim pattern of the armor. + pattern: "sentry" + # The trim material of the armor. + material: "quartz" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 3 + protection: 5 "4": # The enchants to be stored on the book. DisplayEnchantments: @@ -355,7 +396,15 @@ Crate: Weight: 25.0 # The list of items to win. Items: - - "Item:enchanted_book, protection:5, unbreaking:3" + 1: + # The material of the item. + material: "enchanted_book" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 3 + protection: 5 "5": # The display name of the item. DisplayName: "$1,000" @@ -379,7 +428,7 @@ Crate: Toggle: false # The messages to broadcast. Messages: - - "%player% won the prize %reward%." + - "{player} won the prize {reward}." # If the player has this permission, they don't get the broadcast. Permission: "" # The amount to display in the gui. @@ -394,13 +443,13 @@ Crate: Firework: true # Run commands when a prize is won. Commands: - - "eco give %player% 1000" + - "eco give {player} 1000" # Override the global message. Messages: - - "You won %reward%." + - "You won {reward}." "6": # The name of the item to display in the gui. - DisplayName: "Fancy Shield | %pulls%/%maxpulls%" + DisplayName: "Fancy Shield | {pulls}/{maxpulls}" # The item to display in the gui. DisplayItem: "shield" # A list of patterns: https://jd.papermc.io/paper/1.21/org/bukkit/block/banner/PatternType.html @@ -431,33 +480,20 @@ Crate: Weight: 15.0 # The list of items to win. Items: - - "Item:shield, base:white, gradient_up:light_gray, straight_cross:light_blue, flower:light_blue" + 1: + # The material of the item. + material: "shield" + # Generic settings. + settings: + # The configuration section for patterns, minecraft: is not needed in front of the pattern. + # A list of enchantments https://jd.papermc.io/paper/1.21.4/io/papermc/paper/registry/keys/BannerPatternKeys.html + # pattern: color + patterns: + straight_cross: light_blue + gradient_up: light_gray + base: white + flower: light_blue "7": - # The name of the item to display in the gui. - DisplayName: "Creeper Spawner" - # The spawner to display in the gui. - DisplayItem: "spawner" - # Prize display preview settings - Settings: - # The custom model data of the item, -1 is disabled. - Custom-Model-Data: -1 - # The item model, Mojang introduced this in 1.21.4... this replaces custom model data! - # Set this to blank for it to do nothing. - Model: - # The namespace i.e. nexo - Namespace: "" - # The id i.e. emerald_helmet - Id: "" - # The type of mob for the spawner. - Mob-Type: creeper - # The amount to display in the gui. - DisplayAmount: 1 - # The lower the number, the less likely to win it. - Weight: 23.5 - # The list of items to win. - Items: - - "Item:spawner, Mob:creeper" - "8": # The name of the item to display in the gui. DisplayName: "Red Potion" # The item to display in the gui. @@ -474,6 +510,7 @@ Crate: # The id i.e. emerald_helmet Id: "" # The rgb used for the potion. + # RGB = performance RGB: '229,164,229' # Color: RED # The amount to display in the gui. @@ -482,4 +519,27 @@ Crate: Weight: 15.0 # The list of items to win. Items: - - "Item:potion, RGB:229,164,229" # Color:RED \ No newline at end of file + 1: + # The material of the item. + material: potion + # Generic settings. + settings: + # The rgb of the item. + # RGB = performance + rgb: 229,164,229 + # The potion settings. + potions: + # The name of the potion. + strength: + # The length of the potion. + duration: 60 + # The level of the potion. + level: 3 + # The style settings of the potion. + style: + # Should the icon show? + icon: false + # Should there be ambient effects? + ambient: false + # Should particles be shown? + particles: true \ No newline at end of file diff --git a/paper/src/main/resources/crates/QuadCrate.yml b/paper/src/main/resources/crates/QuadCrate.yml index 162f81870..d5d34cc7d 100644 --- a/paper/src/main/resources/crates/QuadCrate.yml +++ b/paper/src/main/resources/crates/QuadCrate.yml @@ -12,22 +12,17 @@ Crate: RequiredKeys: 4 # Max amount of crates that can be opened at once using /crates mass-open Max-Mass-Open: 10 - # If the crate shows in the /crates. - # If the type is QuickCrate/CrateOnTheGo/FireCracker, They will not work as they require a Physical Crate. - InGUI: true - # Slot the item is in the GUI. - Slot: 31 # Enables/Disables the Broadcasts message when they open a crate. OpeningBroadCast: true # Message that is broadcast when opening the crate. - BroadCast: "%prefix%%player% is opening a Quad Crate." + BroadCast: "{prefix}{player} is opening a Quad Crate." # This section is related to commands opening when a crate is opened. opening-command: # If the commands should be sent or not. toggle: false # The commands to run when the crate opens. # Supports all placeholderapi placeholders - # Supports %prefix which returns our prefix, %player% which uses the player name + # Supports {prefix} which returns our prefix, {player} which uses the player name commands: - "put your command here." sound: @@ -73,7 +68,7 @@ Crate: # A default message if the prize doesn't have any Messages # i.e. Messages: [] or the value isn't there. Prize-Message: - - "You have won %reward% from %crate%." + - "You have won {reward} from {crate}." # A list of commands to run by default on every prize. # If you do not want these commands to run, set this to [] Prize-Commands: [] @@ -85,30 +80,9 @@ Crate: Toggle: false # The messages to broadcast. Messages: - - "%player% won the prize %reward%." + - "{player} won the prize {reward}." # If the player has this permission, they don't get the broadcast. Permission: "" - # Item the crate is in the GUI - Item: "brewing_stand" - # The custom model data of the item, -1 is disabled. - Custom-Model-Data: -1 - # The item model, Mojang introduced this in 1.21.4... this replaces custom model data! - # Set this to blank for it to do nothing. - Model: - # The namespace i.e. nexo - Namespace: "" - # The id i.e. emerald_helmet - Id: "" - # If the crate in the main /crates is glowing or not. - Glowing: false - # Name of the item in the GUI. - Name: "Quad Crate" - # The lore of the item in the GUI. - Lore: - - "This crate contains strange objects." - - "You have %keys% keys to open this crate with." - - "You have opened this crate: %crate_opened% times" - - "(!) Right click to view rewards." Preview: # The name of the inventory for the preview menu. Name: "Quad Crate Preview" @@ -133,6 +107,33 @@ Crate: Namespace: "" # The id i.e. emerald_helmet Id: "" + # Settings related to the item in /crates + Display: + # If the crate shows in the /crates. + # If the type is QuickCrate/CrateOnTheGo/FireCracker, They will not work as they require a Physical Crate. + Toggle: true + # Item the crate is in the GUI + Item: "brewing_stand" + # Name of the item in the GUI. + Name: "Quad Crate" + # The lore of the item in the GUI. + Lore: + - "This crate contains strange objects." + - "You have {keys} keys to open this crate with." + - "You have opened this crate: {crate_opened} times" + - "(!) Right click to view rewards." + # The item model, Mojang introduced this in 1.21.4... this replaces custom model data! + # Set this to blank for it to do nothing. + Model: + # The namespace i.e. nexo + Namespace: "" + # The id i.e. emerald_helmet + Id: "" + # Available Types: add_glow, remove_glow, or none. + # None, or blank value means no state will be applied. + Glowing: "add_glow" + # Slot the item is in the GUI. + Slot: 31 # This section is related to .nbt files. structure: # If it should randomly use an .nbt file. @@ -157,8 +158,9 @@ Crate: Namespace: "" # The id i.e. emerald_helmet Id: "" - # Makes the key look enchanted. - Glowing: true + # Available Types: add_glow, remove_glow, or none. + # None, or blank value means no state will be applied. + Glowing: "add_glow" # Settings for the holograms. Hologram: # Toggle on and off the holograms for the crates. @@ -207,8 +209,18 @@ Crate: Player: "1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e" # Only uncomment this if using HeadDatabase by Arcaniax # Skull: "7129" + # The list of items to win. Items: - - "Item:player_head, Player:1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e, Name:BadBones69" + 1: + # The material of the item. + material: "player_head" + # The name of the item. + name: "BadBones69" + # Generic settings. + settings: + # The player name/texture to display. + # https://minecraft-heads.com/ + player: "1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e" "2": # The name of the item to display in the gui. DisplayName: "Fancy Pants" @@ -246,12 +258,33 @@ Crate: - "Chance: 4%" # The lower the number, the less likely to win it. Weight: 40.0 - # The items to win. + # The list of items to win. Items: - - "Item:chainmail_leggings, Amount:1, Damage:75, Trim-Pattern:sentry, Trim-Material:lapis, Name:Fancy Pants, protection:2" + 1: + # The material of the item. + material: "chainmail_leggings" + # The name of the item. + name: "Fancy Pants" + # The amount of the item to give. + amount: 1 + # Generic settings. + settings: + # The damage to apply to the item. + damage: 75 + # The trim settings + trim: + # The trim pattern of the armor. + pattern: "sentry" + # The trim material of the armor. + material: "lapis" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + protection: 2 # The messages to send. Messages: - - "You just won a %reward%." + - "You just won a {reward}." "3": # The name of the item to display in the gui. DisplayName: "Classic Sword" @@ -284,9 +317,25 @@ Crate: - "Chance: 3.5%" # The lower the number, the less likely to win it. Weight: 35.0 - # The items to win. + # The list of items to win. Items: - - "Item:diamond_sword, Amount:1, Damage:7, Name:Classic Sword, sharpness:2, fire_aspect:1" + 1: + # The material of the item. + material: "diamond_sword" + # The name of the item. + name: "Classic Sword" + # The amount of the item to give. + amount: 1 + # Generic settings. + settings: + # The damage to apply to the item. + damage: 7 + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + sharpness: 2 + fire_aspect: 1 # The messages to send. Messages: - - "You just won %reward%." \ No newline at end of file + - "You just won {reward}." \ No newline at end of file diff --git a/paper/src/main/resources/crates/WonderCrate.yml b/paper/src/main/resources/crates/WonderCrate.yml index 480a9c9ad..ad4120755 100644 --- a/paper/src/main/resources/crates/WonderCrate.yml +++ b/paper/src/main/resources/crates/WonderCrate.yml @@ -12,22 +12,17 @@ Crate: RequiredKeys: 5 # Max amount of crates that can be opened at once using /crates mass-open Max-Mass-Open: 10 - # If the crate shows in the /crates. - # If the type is QuickCrate/CrateOnTheGo/FireCracker, They will not work as they require a Physical Crate. - InGUI: true - # Slot the item is in the GUI. - Slot: 33 # Enables/Disables the Broadcasts message when they open a crate. OpeningBroadCast: true # Message that is broadcast when opening the crate. - BroadCast: "%prefix%%player% is opening a Wonder Crate." + BroadCast: "{prefix}{player} is opening a Wonder Crate." # This section is related to commands opening when a crate is opened. opening-command: # If the commands should be sent or not. toggle: false # The commands to run when the crate opens. # Supports all placeholderapi placeholders - # Supports %prefix which returns our prefix, %player% which uses the player name + # Supports {prefix} which returns our prefix, {player} which uses the player name commands: - "put your command here." sound: @@ -67,7 +62,7 @@ Crate: # A default message if the prize doesn't have any Messages # i.e. Messages: [] or the value isn't there. Prize-Message: - - "You have won %reward% from %crate%." + - "You have won {reward} from {crate}." # A list of commands to run by default on every prize. # If you do not want these commands to run, set this to [] Prize-Commands: [] @@ -79,7 +74,7 @@ Crate: Toggle: false # The messages to broadcast. Messages: - - "%player% won the prize %reward%." + - "{player} won the prize {reward}." # If the player has this permission, they don't get the broadcast. Permission: "" # Settings related to rewards. @@ -93,27 +88,6 @@ Crate: # i.e. crazycrates.respin.crate_name.1-20 # It will simply register multiple permissions, so it shows up in things like LuckPerms. Max-Cap: 20 - # Item the crate is in the GUI - Item: "shulker_box" - # The custom model data of the item, -1 is disabled. - Custom-Model-Data: -1 - # The item model, Mojang introduced this in 1.21.4... this replaces custom model data! - # Set this to blank for it to do nothing. - Model: - # The namespace i.e. nexo - Namespace: "" - # The id i.e. emerald_helmet - Id: "" - # If the crate in the main /crates is glowing or not. - Glowing: false - # Name of the item in the GUI. - Name: "Wonder Crate" - # The lore of the item in the GUI. - Lore: - - "This crate contains strange objects." - - "You have %keys% keys to open this crate with." - - "You have opened this crate: %crate_opened% times" - - "(!) Right click to view rewards." Preview: # The name of the inventory for the preview menu. Name: "Wonder Crate Preview" @@ -138,6 +112,33 @@ Crate: Namespace: "" # The id i.e. emerald_helmet Id: "" + # Settings related to the item in /crates + Display: + # If the crate shows in the /crates. + # If the type is QuickCrate/CrateOnTheGo/FireCracker, They will not work as they require a Physical Crate. + Toggle: true + # Item the crate is in the GUI + Item: "shulker_box" + # Name of the item in the GUI. + Name: "Wonder Crate" + # The lore of the item in the GUI. + Lore: + - "This crate contains strange objects." + - "You have {keys} keys to open this crate with." + - "You have opened this crate: {crate_opened} times" + - "(!) Right click to view rewards." + # The item model, Mojang introduced this in 1.21.4... this replaces custom model data! + # Set this to blank for it to do nothing. + Model: + # The namespace i.e. nexo + Namespace: "" + # The id i.e. emerald_helmet + Id: "" + # Available Types: add_glow, remove_glow, or none. + # None, or blank value means no state will be applied. + Glowing: "add_glow" + # Slot the item is in the GUI. + Slot: 33 PhysicalKey: # Name of the Key. Name: "Wonder Crate Key" @@ -155,8 +156,9 @@ Crate: Namespace: "" # The id i.e. emerald_helmet Id: "" - # Makes the key look enchanted. - Glowing: true + # Available Types: add_glow, remove_glow, or none. + # None, or blank value means no state will be applied. + Glowing: "add_glow" # Settings for the holograms. Hologram: # Toggle on and off the holograms for the crates. @@ -205,8 +207,18 @@ Crate: Player: "1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e" # Only uncomment this if using HeadDatabase by Arcaniax # Skull: "7129" + # The list of items to win. Items: - - "Item:player_head, Player:1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e, Name:BadBones69" + 1: + # The material of the item. + material: "player_head" + # The name of the item. + name: "BadBones69" + # Generic settings. + settings: + # The player name/texture to display. + # https://minecraft-heads.com/ + player: "1ee3126ff2c343da525eef2b93272b9fed36273d0ea08c2616b80009948ad57e" "2": # The name of the item to display in the gui. DisplayName: "Diamond Sword" @@ -233,7 +245,17 @@ Crate: Weight: 15.0 # The list of items to win. Items: - - "Item:diamond_sword, Name:Diamond Sword, sharpness:5, looting:3" + 1: + # The material of the item. + material: "diamond_sword" + # The name of the item. + name: "Diamond Sword" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + sharpness: 5 + looting: 3 "3": # The name of the item to display in the gui. DisplayName: "Diamond Helmet" @@ -268,7 +290,17 @@ Crate: Weight: 15.0 # The list of items to win. Items: - - "Item:diamond_helmet, Name:Diamond Helmet, protection:5, unbreaking:3" + 1: + # The material of the item. + material: "diamond_helmet" + # The name of the item. + name: "Diamond Helmet" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 3 + protection: 5 "4": # The enchants to be stored on the book. DisplayEnchantments: @@ -297,7 +329,15 @@ Crate: Weight: 25.0 # The list of items to win. Items: - - "Item:enchanted_book, protection:5, unbreaking:3" + 1: + # The material of the item. + material: "enchanted_book" + # The configuration section for enchantments, minecraft: is not needed in front of the enchantment. + # A list of enchantments https://jd.papermc.io/paper/1.21.10/io/papermc/paper/registry/keys/EnchantmentKeys.html + # enchantment: amount + enchantments: + unbreaking: 5 + protection: 3 "5": # The display name of the item. DisplayName: "$1,000" @@ -320,14 +360,14 @@ Crate: # The lore of the item. DisplayLore: - "Make it rain Money." - - "Chance: %chance%" + - "Chance: {chance}" # The chance to win i.e. 20% Weight: 20.0 # Spawn fireworks. Firework: true # Run commands when a prize is won. Commands: - - "eco give %player% 1000" + - "eco give {player} 1000" # Override the global message. Messages: - - "You won %reward%." \ No newline at end of file + - "You won {reward}." \ No newline at end of file