Skip to content

Commit

Permalink
Add nexo furniture support (#806)
Browse files Browse the repository at this point in the history
* Add a crate interact event

This is to have proper support for other plugins like Nexo, or ItemsAdder

* Add nexo interact listener

* add editor.yml

* fix isCrateLocation method

* add replacement command/feature for /crazycrates set

* remove unneeded code

* update invalid docs url

* change crate to nullable

* add {reason} placeholder to force exit

* Switch to fully location based for nexo

* check if hand is off_hand

* spawn display entity above location

* update default messages.yml

* Add ability to remove crates when using /crazycrates editor

* deprecate old way of removing crates

* No longer need to sneak, or be in creative mode to remove crates.

* always register our editor for normal blocks

* Register more of our listeners

* return if block is air

* fix the last little odd bug

* add trim example back to default files

* reduce duplicate methods

* return if the block clicked is furniture

* update key checks

* cancel key interactions

* simplify interact handling with nexo/vanilla

* update editor message

* prevent re-adding to the crate editor

* add/clean checks to prevent editor messes

* remove from editor crate if they don't have the permission

* remove dead imports

* use Block.isEmpty()

* prevent key check if itemstack is empty

* add more if hand checks

* add config option to pick custom items plugin

* chore: remove import

* add items adder support for furniture

* add "none" option to the config.yml

* add isFurniture method

* use proper plugin check

---------

Signed-off-by: Ryder Belserion <[email protected]>
  • Loading branch information
ryderbelserion authored Dec 16, 2024
1 parent cc4e46c commit 8bb0e1c
Show file tree
Hide file tree
Showing 27 changed files with 1,223 additions and 375 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ch.jalu.configme.SettingsManager;
import ch.jalu.configme.SettingsManagerBuilder;
import ch.jalu.configme.resource.YamlFileResourceOptions;
import com.badbones69.crazycrates.common.config.impl.EditorKeys;
import com.badbones69.crazycrates.common.config.migrate.ConfigMigration;
import com.badbones69.crazycrates.common.config.migrate.LocaleMigration;
import com.badbones69.crazycrates.common.config.impl.ConfigKeys;
Expand All @@ -17,6 +18,8 @@ public class ConfigManager {

private static SettingsManager config;

private static SettingsManager editor;

private static SettingsManager messages;

/**
Expand All @@ -31,6 +34,12 @@ public static void load(final File dataFolder) {
.configurationData(ConfigKeys.class)
.create();

editor = SettingsManagerBuilder
.withYamlFile(new File(dataFolder, "editor.yml"), builder)
.migrationService(new ConfigMigration())
.configurationData(EditorKeys.class)
.create();

messages = SettingsManagerBuilder
.withYamlFile(new File(dataFolder, "messages.yml"), builder)
.migrationService(new LocaleMigration())
Expand All @@ -43,6 +52,7 @@ public static void load(final File dataFolder) {
*/
public static void refresh() {
config.reload();
editor.reload();
messages.reload();
}

Expand All @@ -53,6 +63,13 @@ public static SettingsManager getConfig() {
return config;
}

/**
* @return gets editor.yml
*/
public static SettingsManager getEditor() {
return editor;
}

/**
* @return gets messages.yml
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,27 @@ public void registerComments(CommentsConfiguration conf) {
})
public static final Property<State> message_state = newBeanProperty(State.class, "root.message-state", State.send_message);

@Comment({
"A list of available custom item plugins:",
" -> ItemsAdder",
" -> Oraxen",
" -> Nexo",
" -> None",
"",
"If the option is set to blank, it'll pick whatever plugin it feels like picking.",
"Set the value to None if you do not want any."
})
public static final Property<String> custom_items_plugin = newProperty("root.custom-items-plugin", "");

@Comment({
"A list of available hologram plugins:",
" -> DecentHolograms",
" -> FancyHolograms",
" -> CMI",
" -> None",
"",
"If the option is set to blank, it'll pick whatever plugin it feels like picking."
"If the option is set to blank, it'll pick whatever plugin it feels like picking.",
"Set the value to None if you do not want any."
})
public static final Property<String> hologram_plugin = newProperty("root.hologram-plugin", "");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.badbones69.crazycrates.common.config.impl;

import ch.jalu.configme.Comment;
import ch.jalu.configme.SettingsHolder;
import ch.jalu.configme.configurationdata.CommentsConfiguration;
import ch.jalu.configme.properties.Property;
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;

public class EditorKeys implements SettingsHolder {

protected EditorKeys() {}

@Override
public void registerComments(CommentsConfiguration conf) {
String[] header = {
"Support: https://discord.gg/badbones-s-live-chat-182615261403283459",
"Github: https://github.com/Crazy-Crew",
"",
"Issues: https://github.com/Crazy-Crew/CrazyCrates/issues",
"Features: https://github.com/Crazy-Crew/CrazyCrates/issues",
"",
"List of all sounds: https://minecraft.wiki/w/Sounds.json#Java_Edition_values",
};

String[] deprecation = {
"",
"Warning: This section is subject to change so it is considered deprecated.",
"This is your warning before the change happens. Please read the latest changelogs",
""
};

conf.setComment("editor", header);
}

@Comment("If this is set to true, when you are in /crazycrates editor... any existing crate locations will be overridden on right click.")
public static final Property<Boolean> overwrite_old_crate_locations = newProperty("editor.overwrite-old-crate-locations", false);

}
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public void registerComments(CommentsConfiguration conf) {
"<gold>/crates mass-open <crate_name> <physical/virtual> [amount] <gray>- <yellow>Mass opens a set amount of crates.",
"<gold>/crates tp <location> <gray>- <yellow>Teleport to a Crate.",
"<gold>/crates give <physical/virtual> <crate_name> [amount] [player] <gray>- <yellow>Allows you to take keys from a player.",
"<gold>/crates set <crate_name> <gray>- <yellow>Set the block you are looking at as a crate.",
"<gold>/crates set Menu <gray>- <yellow>Set the block you are looking at to open the /crates menu.",
"<gold>/crates editor -c/--crate <crate_name> or -e/--exit <gray>- <yellow>Allows you to enter/exit editor mode.",
"<gold>/crates migrate -mt/--migration_type <migration_type> --crate/-crate <crate> --data/-d <gray>- <yellow>A command to migrate from other plugins or for internal changes.",
"<gold>/crates reload <gray>- <yellow>Reloads the config/data files.",
"<gold>/crates set1/set2 <gray>- <yellow>Sets position <red>#1 <yellow>or <red>#2 <yellow>for when making a new schematic for QuadCrates.",
"<gold>/crates save <file name> <gray>- <yellow>Create a new nbt file in the schematics folder.",
Expand All @@ -161,6 +161,6 @@ public void registerComments(CommentsConfiguration conf) {
"<gold>/keys <gray>- <yellow>Shows how many keys you have.",
"<gold>/crates <gray>- <yellow>Opens the menu.",
"",
"<gray>You can find a list of permissions @ <yellow>https://docs.crazycrew.us/crazycrates/info/commands/permissions"
"<gray>You can find a list of permissions @ <yellow>https://docs.crazycrew.us/docs/plugins/crazycrates/commands/permissions"
));
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,25 @@ public void registerComments(CommentsConfiguration conf) {
@Comment("A list of available placeholders: {world}")
public static final Property<String> world_disabled = newProperty("crates.world-disabled", "{prefix}<red>I am sorry but Crates are disabled in {world}.");

@Comment("A list of available placeholders: {crate}")
public static final Property<String> editor_enter = newProperty("crates.editor.enter", "{prefix}<red>You are now in editor mode.");

public static final Property<String> editor_exit = newProperty("crates.editor.exit", "{prefix}<red>You are no longer in editor mode.");

public static final Property<String> editor_already_in = newProperty("crates.editor.already-in", "{prefix}<red>You are already in the editor mode.");

@Comment("A list of available placeholders: {reason}")
public static final Property<String> force_editor_exit = newProperty("crates.editor.force-exit", "{prefix}<red>You have been forced out of the editor mode for {reason}.");

@Comment("A list of available placeholders: {crate}")
public static final Property<List<String>> created_physical_crate = newListProperty("crates.physical-crate.created", List.of(
"{prefix}<gray>You have set that block to {crate}.",
"<gray>To remove the crate shift break in creative to remove."
));

@Comment("A list of available placeholders: {id}, {new_crate}")
public static final Property<String> physical_crate_overridden = newProperty("crates.physical-crate.override", "{prefix}<gray>You have overridden the crate's location with id <gold>{id} with {new_crate}.");

@Comment("A list of available placeholders: {crate}")
public static final Property<String> physical_crate_already_exists = newProperty("crates.physical-crate.exists", "{prefix}<gray>This location already has a crate named <gold>{crate} <gray>with id: <gold>{id}.");

Expand Down
11 changes: 11 additions & 0 deletions common/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,23 @@ root:
# send_actionbar -> sends messages in actionbar.
#
message-state: "send_message"
# A list of available custom item plugins:
# -> ItemsAdder
# -> Oraxen
# -> Nexo
# -> None
#
# If the option is set to blank, it'll pick whatever plugin it feels like picking.
# Set the value to None if you do not want any.
custom-items-plugin: ""
# A list of available hologram plugins:
# -> DecentHolograms
# -> FancyHolograms
# -> CMI
# -> None
#
# If the option is set to blank, it'll pick whatever plugin it feels like picking.
# Set the value to None if you do not want any.
hologram-plugin: ""
# This will wipe the example folder on /crazycrates reload or plugin startup. so you always have fresh examples to look at.
update-examples-folder: true
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/resources/crates/CrateExample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Crate:
Weight: 15.0
# The list of items to win.
Items:
- "Item:diamond_helmet, Name:<red>Diamond Helmet, protection:5, unbreaking:3"
- "Item:diamond_helmet, Name:<red>Diamond Helmet, protection:5, unbreaking:3, Trim-Material:quartz, Trim-Pattern:sentry"
"4":
# The enchants to be stored on the book.
DisplayEnchantments:
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/resources/editor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Support: https://discord.gg/badbones-s-live-chat-182615261403283459
# Github: https://github.com/Crazy-Crew
#
# Issues: https://github.com/Crazy-Crew/CrazyCrates/issues
# Features: https://github.com/Crazy-Crew/CrazyCrates/issues
#
# List of all sounds: https://minecraft.wiki/w/Sounds.json#Java_Edition_values
editor:
# If this is set to true, when you are in /crazycrates editor... any existing crate locations will be overridden on right click.
overwrite-old-crate-locations: false
15 changes: 10 additions & 5 deletions common/src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ crates:
need-more-room: "{prefix}<red>There is not enough space to open that here"
# A list of available placeholders: {world}
world-disabled: "{prefix}<red>I am sorry but Crates are disabled in {world}."
editor:
# A list of available placeholders: {crate}
enter: "{prefix}<red>You are now in editor mode."
# A list of available placeholders: {crate}
exit: "{prefix}<red>You are no longer in editor mode."
# A list of available placeholders: {reason}
force-exit: "{prefix}<red>You have been forced out of the editor mode for {reason}."
physical-crate:
# A list of available placeholders: {crate}
created:
Expand Down Expand Up @@ -267,10 +274,8 @@ command:
- "<gold>/crates tp <location> <gray>- <yellow>Teleport to a Crate."
- "<gold>/crates give <physical/virtual> <crate_name> [amount] [player] <gray>- <yellow>Allows
you to take keys from a player."
- "<gold>/crates set <crate_name> <gray>- <yellow>Set the block you are looking at
as a crate."
- "<gold>/crates set Menu <gray>- <yellow>Set the block you are looking at to open
the /crates menu."
- "<gold>/crates editor -c/--crate <crate_name> or -e/--exit <gray>- <yellow>Allows you to enter/exit editor mode."
- "<gold>/crates migrate -mt/--migration_type <migration_type> --crate/-crate <crate> --data/-d <gray>- <yellow>A command to migrate from other plugins or for internal changes."
- "<gold>/crates reload <gray>- <yellow>Reloads the config/data files."
- "<gold>/crates set1/set2 <gray>- <yellow>Sets position <red>#1 <yellow>or <red>#2
<yellow>for when making a new schematic for QuadCrates."
Expand All @@ -281,4 +286,4 @@ command:
- "<gold>/keys <gray>- <yellow>Shows how many keys you have."
- "<gold>/crates <gray>- <yellow>Opens the menu."
- ""
- "<gray>You can find a list of permissions @ <yellow>https://docs.crazycrew.us/crazycrates/info/commands/permissions"
- "<gray>You can find a list of permissions @ <yellow>https://docs.crazycrew.us/docs/plugins/crazycrates/commands/permissions"
12 changes: 8 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ decentholograms = "2.8.8"
headdatabaseapi = "1.3.1"
placeholderapi = "2.11.6"
fancyholograms = "2.4.1"
nexo = "0.5.0-dev.14"
itemsadder = "3.6.1"
cmi-api = "9.7.4.1"
cmi-lib = "1.5.1.4"
oraxen = "1.171.0"
nexo = "0.1.0-dev.0"

# Vital API
vital = "0.1.2"
Expand Down Expand Up @@ -52,11 +55,12 @@ kyori-api = { module = "net.kyori:adventure-api", version.ref = "adventure" }
# Bukkit Plugins API
decent-holograms = { module = "com.github.decentsoftware-eu:decentholograms", version.ref = "decentholograms" }
headdatabaseapi = { module = "com.arcaniax:HeadDatabase-API", version.ref = "headdatabaseapi" }
itemsadder = { module = "com.github.LoneDev6:api-itemsadder", version.ref = "itemsadder" }
fancy-holograms = { module = "de.oliver:FancyHolograms", version.ref = "fancyholograms" }
placeholderapi = { module = "me.clip:placeholderapi", version.ref = "placeholderapi" }
oraxen = { module = "io.th0rgal:oraxen", version.ref = "oraxen" }
cmi-api = { module = "CMI-API:CMI-API", version = "9.7.4.1" }
cmi-lib = { module = "CMILib:CMILib", version = "1.5.1.4" }
cmi-api = { module = "CMI-API:CMI-API", version.ref = "cmi-api" }
cmi-lib = { module = "CMILib:CMILib", version.ref = "cmi-lib" }
nexo = { module = "com.nexomc:nexo", version.ref = "nexo" }

# Crate Plugins API
Expand All @@ -77,7 +81,7 @@ jalu = { module = "ch.jalu:configme", version.ref = "jalu" }
dependencies = ["decent-holograms", "fancy-holograms", "cmi-lib", "cmi-api"]

# Shared with the git submodules
shared = ["headdatabaseapi", "placeholderapi", "oraxen", "nexo"]
shared = ["headdatabaseapi", "placeholderapi", "itemsadder", "oraxen", "nexo"]

# Only used for migrations from other crate plugins
crates = ["excellentcrates", "nightcore"]
Expand Down
19 changes: 15 additions & 4 deletions paper/src/main/java/com/badbones69/crazycrates/CrazyCrates.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.badbones69.crazycrates.common.Server;
import com.badbones69.crazycrates.common.config.ConfigManager;
import com.badbones69.crazycrates.common.config.impl.ConfigKeys;
import com.badbones69.crazycrates.listeners.crates.CrateInteractListener;
import com.badbones69.crazycrates.listeners.items.PaperInteractListener;
import com.badbones69.crazycrates.support.MetricsWrapper;
import com.badbones69.crazycrates.utils.MiscUtils;
import com.badbones69.crazycrates.commands.CommandManager;
Expand All @@ -25,6 +27,7 @@
import com.ryderbelserion.vital.paper.api.enums.Support;
import com.ryderbelserion.vital.utils.Methods;
import me.arcaniax.hdb.api.HeadDatabaseAPI;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -106,18 +109,26 @@ public void onEnable() {
// Load commands.
CommandManager.load();

final PluginManager manager = getServer().getPluginManager();

List.of(
// Other listeners.
new BrokeLocationsListener(),
new CrateControlListener(),
new EntityDamageListener(),
new MobileCrateListener(),
new CosmicCrateListener(),
new QuadCrateListener(),
new CrateOpenListener(),
new WarCrateListener(),
new MiscListener()
).forEach(listener -> getServer().getPluginManager().registerEvents(listener, this));
new MiscListener(),

new CrateInteractListener(),
new CrateControlListener(),
new CrateOpenListener(),

new PaperInteractListener()
).forEach(listener -> manager.registerEvents(listener, this));

this.crateManager.loadCustomItems();

if (Support.placeholder_api.isEnabled()) {
if (MiscUtils.isLogging()) getComponentLogger().info("PlaceholderAPI support is enabled!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ public enum Messages {
not_a_number(CrateKeys.not_a_number),
preview_disabled(CrateKeys.preview_disabled),
not_enough_keys(CrateKeys.not_enough_keys),
editor_enter(CrateKeys.editor_enter),
editor_already_in(CrateKeys.editor_already_in),
editor_exit(CrateKeys.editor_exit),
force_editor_exit(CrateKeys.force_editor_exit),
created_physical_crate(CrateKeys.created_physical_crate, true),
physical_crate_already_exists(CrateKeys.physical_crate_already_exists),
physical_crate_overridden(CrateKeys.physical_crate_overridden),
removed_physical_crate(CrateKeys.removed_physical_crate),
crate_locations(CrateKeys.crate_locations, true),
crate_locations_format(CrateKeys.crate_location_format),
Expand Down
Loading

0 comments on commit 8bb0e1c

Please sign in to comment.