diff --git a/build.gradle.kts b/build.gradle.kts index ce8c23429..52f55789a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,11 +1,11 @@ plugins { `java-library` - id("io.papermc.paperweight.userdev") version "1.7.1" + id("io.papermc.paperweight.userdev") version "1.7.2" id("xyz.jpenilla.run-paper") version "2.3.0" // Adds runServer and runMojangMappedServer tasks for testing } dependencies { - paperDevBundle("1.20.6-R0.1-SNAPSHOT") + paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT") } java { @@ -55,7 +55,7 @@ configure(subprojects.filter { apply(plugin = "io.papermc.paperweight.userdev") dependencies { - paperDevBundle("1.20.6-R0.1-SNAPSHOT") + paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT") } } @@ -92,7 +92,7 @@ configure(subprojects.filter { } processResources { - filesMatching("**/plugin.yml") { + filesMatching("**/*plugin.yml") { expand(project.properties) } } @@ -136,7 +136,7 @@ configure(subprojects.filter { listOf("vane-bedtime", "vane-portals", "vane-regions").contains(it.name) }) { dependencies { - implementation(group = "us.dynmap", name = "dynmap-api", version = "3.2-SNAPSHOT") + implementation(group = "us.dynmap", name = "DynmapCoreAPI", version = "3.7-beta-6") implementation(group = "de.bluecolored.bluemap", name = "BlueMapAPI", version = "2.7.2") } } diff --git a/vane-admin/src/main/java/org/oddlama/vane/admin/AutostopGroup.java b/vane-admin/src/main/java/org/oddlama/vane/admin/AutostopGroup.java index b3200e8a8..139e3142b 100644 --- a/vane-admin/src/main/java/org/oddlama/vane/admin/AutostopGroup.java +++ b/vane-admin/src/main/java/org/oddlama/vane/admin/AutostopGroup.java @@ -34,16 +34,20 @@ public class AutostopGroup extends ModuleGroup { // Variables public BukkitTask task = null; public long start_time = -1; + public long stop_time = -1; public AutostopGroup(Context context) { super(context, "autostop", "Enable automatic server stop after certain time without online players."); } public long remaining() { + if (start_time == -1) { return -1; } - return start_time + (config_delay * 1000) - System.currentTimeMillis(); + + return stop_time - System.currentTimeMillis(); + } public void abort() { @@ -59,6 +63,7 @@ public void abort(CommandSender sender) { task.cancel(); task = null; start_time = -1; + stop_time = -1; lang_aborted.send_and_log(sender); } @@ -77,6 +82,7 @@ public void schedule(CommandSender sender, long delay) { } start_time = System.currentTimeMillis(); + stop_time = start_time + delay; task = schedule_task( () -> { diff --git a/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Autostop.java b/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Autostop.java index 59e732e0e..9046edd6b 100644 --- a/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Autostop.java +++ b/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Autostop.java @@ -1,12 +1,20 @@ package org.oddlama.vane.admin.commands; -import static org.oddlama.vane.util.TimeUtil.parse_time; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +import static io.papermc.paper.command.brigadier.Commands.argument; +import static io.papermc.paper.command.brigadier.Commands.literal; import org.bukkit.command.CommandSender; import org.oddlama.vane.admin.Admin; import org.oddlama.vane.admin.AutostopGroup; import org.oddlama.vane.annotation.command.Name; import org.oddlama.vane.core.command.Command; +import org.oddlama.vane.util.Conversions; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; @Name("autostop") public class Autostop extends Command { @@ -16,16 +24,20 @@ public class Autostop extends Command { public Autostop(AutostopGroup context) { super(context); this.autostop = context; + } - // Add help - params().fixed("help").ignore_case().exec(this::print_help); - // Command parameters - params().exec(this::status); - params().fixed("abort").ignore_case().exec(this::abort); - params().fixed("status").ignore_case().exec(this::status); - var schedule = params().fixed("schedule").ignore_case(); - schedule.exec(this::schedule); - schedule.any_string().exec(this::schedule_delay); + @Override + public LiteralArgumentBuilder get_command_base() { + return super.get_command_base() + .executes(ctx -> { status(ctx.getSource().getSender()); return SINGLE_SUCCESS; }) + .then(help()) + .then(literal("status").executes(ctx -> { status(ctx.getSource().getSender()); return SINGLE_SUCCESS; })) + .then(literal("abort").executes(ctx -> { abort(ctx.getSource().getSender()); return SINGLE_SUCCESS;})) + .then(literal("schedule") + .executes(ctx -> { schedule(ctx.getSource().getSender()); return SINGLE_SUCCESS; }) + .then(argument("time", ArgumentTypes.time()) + .executes(ctx -> { schedule_delay(ctx.getSource().getSender(), ctx.getArgument("time", Integer.class)); return SINGLE_SUCCESS;})) + ); } private void status(CommandSender sender) { @@ -40,11 +52,7 @@ private void schedule(CommandSender sender) { autostop.schedule(sender); } - private void schedule_delay(CommandSender sender, String delay) { - try { - autostop.schedule(sender, parse_time(delay)); - } catch (NumberFormatException e) { - get_module().core.lang_invalid_time_format.send(sender, e.getMessage()); - } + private void schedule_delay(CommandSender sender, int delay){ + autostop.schedule(sender, Conversions.ticks_to_ms(delay)); } } diff --git a/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Gamemode.java b/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Gamemode.java index a575af765..fa1924aaa 100644 --- a/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Gamemode.java +++ b/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Gamemode.java @@ -1,6 +1,9 @@ package org.oddlama.vane.admin.commands; -import net.kyori.adventure.text.format.NamedTextColor; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +import static io.papermc.paper.command.brigadier.Commands.argument; +import static io.papermc.paper.command.brigadier.Commands.literal; + import org.bukkit.GameMode; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -12,6 +15,16 @@ import org.oddlama.vane.core.lang.TranslatedMessage; import org.oddlama.vane.core.module.Context; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; +import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + @Name("gamemode") @Aliases({ "gm" }) public class Gamemode extends Command { @@ -21,14 +34,35 @@ public class Gamemode extends Command { public Gamemode(Context context) { super(context); - // Add help - params().fixed("help").ignore_case().exec(this::print_help); - // Command parameters - params().exec_player(this::toggle_gamemode_self); - params().choose_online_player().exec(this::toggle_gamemode_player); - var gamemode = params().choose_gamemode(); - gamemode.exec_player(this::set_gamemode_self); - gamemode.choose_online_player().exec(this::set_gamemode); + } + + @Override + public LiteralArgumentBuilder get_command_base() { + return super.get_command_base() + .then(help()) + + .executes(ctx -> {toggle_gamemode_self((Player) ctx.getSource().getSender()); return SINGLE_SUCCESS;}) + + .then(argument("game_mode", ArgumentTypes.gameMode()) + .executes(ctx -> { set_gamemode_self((Player) ctx.getSource().getSender(), ctx.getArgument("game_mode", GameMode.class)); return SINGLE_SUCCESS;}) + .then(argument("player", ArgumentTypes.player()) + .executes(ctx -> { + set_gamemode(ctx.getSource().getSender(), ctx.getArgument("game_mode", GameMode.class), player(ctx)); + return SINGLE_SUCCESS; + }) + ) + ) + .then(argument("player", ArgumentTypes.player()) + .executes(ctx -> { + toggle_gamemode_player(ctx.getSource().getSender(), player(ctx)); + + return SINGLE_SUCCESS; + }) + ); + } + + private Player player(CommandContext ctx) throws CommandSyntaxException{ + return ctx.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(ctx.getSource()).get(0); } private void toggle_gamemode_self(Player player) { @@ -45,6 +79,6 @@ private void set_gamemode_self(Player player, GameMode mode) { private void set_gamemode(CommandSender sender, GameMode mode, Player player) { player.setGameMode(mode); - lang_set.send(sender, player.displayName().color(NamedTextColor.AQUA), "§a" + mode.name()); + lang_set.send(sender, player.displayName().color(NamedTextColor.AQUA), Component.text(mode.name(), NamedTextColor.GREEN)); } } diff --git a/vane-admin/src/main/java/org/oddlama/vane/admin/commands/SlimeChunk.java b/vane-admin/src/main/java/org/oddlama/vane/admin/commands/SlimeChunk.java index 41b3ae9cc..aadcf7dac 100644 --- a/vane-admin/src/main/java/org/oddlama/vane/admin/commands/SlimeChunk.java +++ b/vane-admin/src/main/java/org/oddlama/vane/admin/commands/SlimeChunk.java @@ -1,5 +1,8 @@ package org.oddlama.vane.admin.commands; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +import static io.papermc.paper.command.brigadier.Commands.literal; + import org.bukkit.entity.Player; import org.oddlama.vane.admin.Admin; import org.oddlama.vane.annotation.command.Name; @@ -8,6 +11,10 @@ import org.oddlama.vane.core.lang.TranslatedMessage; import org.oddlama.vane.core.module.Context; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import io.papermc.paper.command.brigadier.CommandSourceStack; + @Name("slimechunk") public class SlimeChunk extends Command { @@ -19,10 +26,14 @@ public class SlimeChunk extends Command { public SlimeChunk(Context context) { super(context); - // Add help - params().fixed("help").ignore_case().exec(this::print_help); - // Command parameters - params().exec_player(this::is_slimechunk); + } + + @Override + public LiteralArgumentBuilder get_command_base() { + return super.get_command_base() + .requires(stack -> stack.getSender() instanceof Player) + .then(help()) + .executes(ctx -> {is_slimechunk((Player) ctx.getSource().getSender()); return SINGLE_SUCCESS;}); } private void is_slimechunk(final Player player) { diff --git a/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Time.java b/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Time.java index e4b85e0e5..d4cd7826d 100644 --- a/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Time.java +++ b/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Time.java @@ -1,54 +1,53 @@ package org.oddlama.vane.admin.commands; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +import static io.papermc.paper.command.brigadier.Commands.argument; import static org.oddlama.vane.util.WorldUtil.change_time_smoothly; -import java.util.List; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.oddlama.vane.admin.Admin; import org.oddlama.vane.annotation.command.Name; import org.oddlama.vane.core.command.Command; +import org.oddlama.vane.core.command.argumentType.TimeValueArgumentType; +import org.oddlama.vane.core.command.enums.TimeValue; import org.oddlama.vane.core.module.Context; -@Name("time") -public class Time extends Command { +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; - public enum TimeValue { - dawn(23000), - day(1000), - noon(6000), - afternoon(9000), - dusk(13000), - night(14000), - midnight(18000); +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; - private int ticks; +@Name("time") +public class Time extends Command { - private TimeValue(int ticks) { - this.ticks = ticks; - } + public Time(Context context) { + super(context); + } - public int ticks() { - return ticks; - } + @Override + public LiteralArgumentBuilder get_command_base() { + return super.get_command_base() + .then(help()) + .then(argument("time", TimeValueArgumentType.timeValue()) + .executes(ctx -> { set_time_current_world((Player) ctx.getSource().getSender(), time_value(ctx)); return SINGLE_SUCCESS;}) + .then(argument("world", ArgumentTypes.world()) + .executes(ctx -> { set_time(time_value(ctx), ctx.getArgument("world", World.class)); return SINGLE_SUCCESS;}) + ) + ) + ; } - public Time(Context context) { - super(context); - // Add help - params().fixed("help").ignore_case().exec(this::print_help); - // Command parameters - var time = params().choice("time", List.of(TimeValue.values()), t -> t.name()).ignore_case(); - time.exec_player(this::set_time_current_world); - time.choose_world().exec(this::set_time); + private TimeValue time_value(CommandContext ctx) { + return ctx.getArgument("time", TimeValue.class); } private void set_time_current_world(Player player, TimeValue t) { change_time_smoothly(player.getWorld(), get_module(), t.ticks(), 100); } - private void set_time(CommandSender sender, TimeValue t, World world) { + private void set_time(TimeValue t, World world) { change_time_smoothly(world, get_module(), t.ticks(), 100); } } diff --git a/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Weather.java b/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Weather.java index 1264429f5..b68aaecdb 100644 --- a/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Weather.java +++ b/vane-admin/src/main/java/org/oddlama/vane/admin/commands/Weather.java @@ -1,48 +1,45 @@ package org.oddlama.vane.admin.commands; -import java.util.List; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +import static io.papermc.paper.command.brigadier.Commands.argument; + import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.oddlama.vane.admin.Admin; import org.oddlama.vane.annotation.command.Name; import org.oddlama.vane.core.command.Command; +import org.oddlama.vane.core.command.argumentType.WeatherArgumentType; +import org.oddlama.vane.core.command.enums.WeatherValue; import org.oddlama.vane.core.module.Context; -@Name("weather") -public class Weather extends Command { - - public enum WeatherValue { - clear(false, false), - sun(false, false), - rain(true, false), - thunder(true, true); +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; - private boolean is_storm; - private boolean is_thunder; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; - private WeatherValue(boolean is_storm, boolean is_thunder) { - this.is_storm = is_storm; - this.is_thunder = is_thunder; - } +@Name("weather") +public class Weather extends Command { - public boolean storm() { - return is_storm; - } + public Weather(Context context) { + super(context); + } - public boolean thunder() { - return is_thunder; - } + @Override + public LiteralArgumentBuilder get_command_base() { + return super.get_command_base() + .then(help()) + .then(argument("weather", WeatherArgumentType.weather()) + .executes(ctx -> { set_weather_current_world((Player) ctx.getSource().getSender(), weather(ctx)); return SINGLE_SUCCESS;}) + .then(argument("world", ArgumentTypes.world()) + .executes(ctx -> { set_weather(ctx.getSource().getSender(), weather(ctx), ctx.getArgument("world", World.class)); return SINGLE_SUCCESS; }) + ) + ); } - public Weather(Context context) { - super(context); - // Add help - params().fixed("help").ignore_case().exec(this::print_help); - // Command parameters - var time = params().choice("weather", List.of(WeatherValue.values()), t -> t.name()).ignore_case(); - time.exec_player(this::set_weather_current_world); - time.choose_world().exec(this::set_weather); + private WeatherValue weather(CommandContext ctx){ + return ctx.getArgument("weather", WeatherValue.class); } private void set_weather_current_world(Player player, WeatherValue w) { diff --git a/vane-admin/src/main/resources/plugin.yml b/vane-admin/src/main/resources/paper-plugin.yml similarity index 57% rename from vane-admin/src/main/resources/plugin.yml rename to vane-admin/src/main/resources/paper-plugin.yml index 05fa2a93e..2a7145780 100644 --- a/vane-admin/src/main/resources/plugin.yml +++ b/vane-admin/src/main/resources/paper-plugin.yml @@ -2,13 +2,16 @@ name: ${name} version: ${version} description: Admin module for vane -authors: [oddlama] +authors: + - oddlama website: 'https://github.com/oddlama/vane' -depend: [vane-core] - main: org.oddlama.vane.admin.Admin -database: false -api-version: 1.19 +api-version: '1.21' load: STARTUP +dependencies: + server: + vane-core: + required: true + load: BEFORE \ No newline at end of file diff --git a/vane-bedtime/src/main/java/org/oddlama/vane/bedtime/BedtimeBlueMapLayerDelegate.java b/vane-bedtime/src/main/java/org/oddlama/vane/bedtime/BedtimeBlueMapLayerDelegate.java index 33ddb8b62..50f6b6f74 100644 --- a/vane-bedtime/src/main/java/org/oddlama/vane/bedtime/BedtimeBlueMapLayerDelegate.java +++ b/vane-bedtime/src/main/java/org/oddlama/vane/bedtime/BedtimeBlueMapLayerDelegate.java @@ -75,7 +75,7 @@ private void create_marker_set(final BlueMapAPI api, final World world) { public void update_marker(final OfflinePlayer player) { remove_marker(player.getUniqueId()); - final var loc = player.getBedSpawnLocation(); + final var loc = player.getRespawnLocation(); if (loc == null) { return; } diff --git a/vane-bedtime/src/main/java/org/oddlama/vane/bedtime/BedtimeDynmapLayerDelegate.java b/vane-bedtime/src/main/java/org/oddlama/vane/bedtime/BedtimeDynmapLayerDelegate.java index 0e29d8651..3c8a61902 100644 --- a/vane-bedtime/src/main/java/org/oddlama/vane/bedtime/BedtimeDynmapLayerDelegate.java +++ b/vane-bedtime/src/main/java/org/oddlama/vane/bedtime/BedtimeDynmapLayerDelegate.java @@ -5,7 +5,8 @@ import java.util.logging.Level; import org.bukkit.OfflinePlayer; import org.bukkit.plugin.Plugin; -import org.dynmap.DynmapAPI; +import org.dynmap.DynmapCommonAPI; +import org.dynmap.DynmapCommonAPIListener; import org.dynmap.markers.Marker; import org.dynmap.markers.MarkerAPI; import org.dynmap.markers.MarkerIcon; @@ -15,10 +16,9 @@ public class BedtimeDynmapLayerDelegate { private final BedtimeDynmapLayer parent; - private DynmapAPI dynmap_api = null; + private DynmapCommonAPI dynmap_api = null; private MarkerAPI marker_api = null; private boolean dynmap_enabled = false; - private MarkerSet marker_set = null; private MarkerIcon marker_icon = null; @@ -32,8 +32,16 @@ public Bedtime get_module() { public void on_enable(final Plugin plugin) { try { - dynmap_api = (DynmapAPI) plugin; - marker_api = dynmap_api.getMarkerAPI(); + DynmapCommonAPIListener.register(new DynmapCommonAPIListener() { + + @Override + public void apiEnabled(DynmapCommonAPI api) { + dynmap_api = api; + marker_api = dynmap_api.getMarkerAPI(); + } + + }); + } catch (Exception e) { get_module().log.log(Level.WARNING, "Error while enabling dynmap integration!", e); return; @@ -101,7 +109,7 @@ public boolean update_marker(final OfflinePlayer player) { return false; } - final var loc = player.getBedSpawnLocation(); + final var loc = player.getRespawnLocation(); if (loc == null) { return false; } diff --git a/vane-bedtime/src/main/resources/paper-plugin.yml b/vane-bedtime/src/main/resources/paper-plugin.yml new file mode 100644 index 000000000..7501dd2ef --- /dev/null +++ b/vane-bedtime/src/main/resources/paper-plugin.yml @@ -0,0 +1,23 @@ +name: ${name} +version: ${version} +description: Bedtime module for vane + +authors: + - oddlama +website: 'https://github.com/oddlama/vane' + +main: org.oddlama.vane.bedtime.Bedtime + +api-version: '1.21' +load: STARTUP +dependencies: + server: + vane-core: + required: true + load: BEFORE + dynmap: + required: false + load: AFTER + BlueMap: + required: false + load: AFTER \ No newline at end of file diff --git a/vane-bedtime/src/main/resources/plugin.yml b/vane-bedtime/src/main/resources/plugin.yml deleted file mode 100644 index 9ffac980a..000000000 --- a/vane-bedtime/src/main/resources/plugin.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: ${name} -version: ${version} -description: Bedtime module for vane - -authors: [oddlama] -website: 'https://github.com/oddlama/vane' - -depend: [vane-core] -softdepend: [dynmap, BlueMap] - -main: org.oddlama.vane.bedtime.Bedtime -database: false - -api-version: 1.19 -load: STARTUP diff --git a/vane-core/build.gradle.kts b/vane-core/build.gradle.kts index e30e9ab68..a64df737c 100644 --- a/vane-core/build.gradle.kts +++ b/vane-core/build.gradle.kts @@ -2,18 +2,23 @@ import java.security.MessageDigest plugins { id("io.github.goooler.shadow") version "8.1.7" - id("net.kyori.blossom") version "1.2.0" // Text replacement for version numbers + id("net.kyori.blossom") version "2.1.0" // Text replacement for version numbers } -blossom { - replaceToken("\$VERSION", project.version) +sourceSets { + main { + blossom { + javaSources { + property("\$VERSION", project.version.toString()) + } + } + } } - dependencies { implementation(group = "org.bstats", name = "bstats-base", version = "3.0.2") implementation(group = "org.bstats", name = "bstats-bukkit", version = "3.0.2") implementation(group = "org.reflections", name = "reflections", version = "0.10.2") - api(group = "org.json", name = "json", version = "20200518") + api(group = "org.json", name = "json", version = "20240303") implementation(project(":vane-annotations")) } diff --git a/vane-core/src/main/java/org/oddlama/vane/core/Core.java b/vane-core/src/main/java/org/oddlama/vane/core/Core.java index 17c84d36d..59d36d16c 100644 --- a/vane-core/src/main/java/org/oddlama/vane/core/Core.java +++ b/vane-core/src/main/java/org/oddlama/vane/core/Core.java @@ -22,7 +22,6 @@ import org.oddlama.vane.annotation.VaneModule; import org.oddlama.vane.annotation.config.ConfigBoolean; import org.oddlama.vane.annotation.lang.LangMessage; -import org.oddlama.vane.core.enchantments.CustomEnchantmentFixer; import org.oddlama.vane.core.enchantments.EnchantmentManager; import org.oddlama.vane.core.functional.Consumer1; import org.oddlama.vane.core.item.CustomItemRegistry; @@ -48,7 +47,6 @@ import net.minecraft.core.MappedRegistry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.item.enchantment.Enchantment; @VaneModule(name = "core", bstats = 8637, config_version = 6, lang_version = 4, storage_version = 1) public class Core extends Module { @@ -79,8 +77,6 @@ public static Core instance() { public final ResourcePackDistributor resource_pack_distributor; - public final CustomEnchantmentFixer custom_enchantment_fixer; - public void register_module(Module module) { vane_modules.add(module); } @@ -139,7 +135,6 @@ public Core() { new org.oddlama.vane.core.commands.Enchant(this); menu_manager = new MenuManager(this); resource_pack_distributor = new ResourcePackDistributor(this); - custom_enchantment_fixer = new CustomEnchantmentFixer(this); new CommandHider(this); model_data_registry = new CustomModelDataRegistry(); item_registry = new CustomItemRegistry(); @@ -168,10 +163,8 @@ public void unfreeze_registries() { // Unfreeze required registries frozen.set(BuiltInRegistries.ENTITY_TYPE, false); - frozen.set(BuiltInRegistries.ENCHANTMENT, false); intrusive_holder_cache.set(BuiltInRegistries.ENTITY_TYPE, new IdentityHashMap, Holder.Reference>>()); // Since 1.20.2 this is also needed for enchantments: - intrusive_holder_cache.set(BuiltInRegistries.ENCHANTMENT, new IdentityHashMap>()); } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } @@ -179,7 +172,6 @@ public void unfreeze_registries() { public void freeze_registries() { BuiltInRegistries.ENTITY_TYPE.freeze(); - BuiltInRegistries.ENCHANTMENT.freeze(); } @Override diff --git a/vane-core/src/main/java/org/oddlama/vane/core/command/Command.java b/vane-core/src/main/java/org/oddlama/vane/core/command/Command.java index 908f1f519..651447e94 100644 --- a/vane-core/src/main/java/org/oddlama/vane/core/command/Command.java +++ b/vane-core/src/main/java/org/oddlama/vane/core/command/Command.java @@ -1,5 +1,7 @@ package org.oddlama.vane.core.command; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +import static io.papermc.paper.command.brigadier.Commands.literal; import static org.oddlama.vane.util.ArrayUtil.prepend; import java.util.Collections; @@ -19,6 +21,13 @@ import org.oddlama.vane.core.module.Module; import org.oddlama.vane.core.module.ModuleComponent; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.tree.LiteralCommandNode; + +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.Commands; + @VaneCommand public abstract class Command> extends ModuleComponent { @@ -101,6 +110,9 @@ public List tabComplete(CommandSender sender, String alias, String[] arg // Root parameter private AnyParam root_param; + private LiteralArgumentBuilder brigadier_command; + private Aliases aliases; + public Command(Context context) { this(context, PermissionDefault.OP); } @@ -133,7 +145,9 @@ public Command(Context context, PermissionDefault permission_default) { bukkit_command.setLabel(name); bukkit_command.setName(name); - var aliases = getClass().getAnnotation(Aliases.class); + + aliases = getClass().getAnnotation(Aliases.class); + brigadier_command = Commands.literal(name).requires(stack -> stack.getSender().hasPermission(permission)); if (aliases != null) { bukkit_command.setAliases(List.of(aliases.value())); } @@ -159,6 +173,23 @@ public Param params() { return root_param; } + public LiteralArgumentBuilder get_command_base() { + return brigadier_command; + } + + public LiteralCommandNode get_command() { + return get_command_base().build(); + } + + public List get_aliases() { + if (aliases != null && aliases.value().length > 0) { + return List.of(aliases.value()); + } else { + return Collections.emptyList(); + } + + } + @Override protected void on_enable() { get_module().register_command(this); @@ -173,4 +204,15 @@ public void print_help(CommandSender sender) { lang_usage.send(sender, "§7/§3" + name); lang_help.send(sender); } + + public int print_help2(CommandContext ctx) { + lang_usage.send(ctx.getSource().getSender(), "§7/§3" + name); + lang_help.send(ctx.getSource().getSender()); + return com.mojang.brigadier.Command.SINGLE_SUCCESS; + } + + public LiteralArgumentBuilder help(){ + return literal("help").executes(ctx -> {print_help2(ctx); return SINGLE_SUCCESS;}); + } + } diff --git a/vane-core/src/main/java/org/oddlama/vane/core/command/Param.java b/vane-core/src/main/java/org/oddlama/vane/core/command/Param.java index 41435edb5..b340f8d0f 100644 --- a/vane-core/src/main/java/org/oddlama/vane/core/command/Param.java +++ b/vane-core/src/main/java/org/oddlama/vane/core/command/Param.java @@ -2,11 +2,11 @@ import static org.oddlama.vane.util.StorageUtil.namespaced_key; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; + import org.bukkit.GameMode; import org.bukkit.OfflinePlayer; import org.bukkit.World; @@ -37,6 +37,9 @@ import org.oddlama.vane.core.functional.Function6; import org.oddlama.vane.core.module.Module; +import io.papermc.paper.registry.RegistryAccess; +import io.papermc.paper.registry.RegistryKey; + @SuppressWarnings("overloads") public interface Param { public List get_params(); @@ -292,14 +295,14 @@ public default DynamicChoiceParam choose_enchantment( return choice( "enchantment", sender -> - org.bukkit.Registry.ENCHANTMENT.stream().filter(e -> filter.apply(sender, e)).collect(Collectors.toList()), + RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).stream().filter(e -> filter.apply(sender, e)).collect(Collectors.toList()), (sender, e) -> e.getKey().toString(), (sender, str) -> { var parts = str.split(":"); if (parts.length != 2) { return null; } - var e = org.bukkit.Registry.ENCHANTMENT.get(namespaced_key(parts[0], parts[1])); + var e = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).get(namespaced_key(parts[0], parts[1])); if (!filter.apply(sender, e)) { return null; } diff --git a/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/CustomItemArgumentType.java b/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/CustomItemArgumentType.java new file mode 100644 index 000000000..0c97ee2c7 --- /dev/null +++ b/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/CustomItemArgumentType.java @@ -0,0 +1,58 @@ +package org.oddlama.vane.core.command.argumentType; + +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.bukkit.NamespacedKey; +import org.jetbrains.annotations.NotNull; +import org.oddlama.vane.core.Core; +import org.oddlama.vane.core.item.api.CustomItem; + +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; + +import io.papermc.paper.command.brigadier.MessageComponentSerializer; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; +import io.papermc.paper.command.brigadier.argument.CustomArgumentType; + +public class CustomItemArgumentType implements CustomArgumentType.Converted { + + Core module; + + private CustomItemArgumentType(Core module) { + this.module = module; + } + + public static CustomItemArgumentType customItem(Core module) { + return new CustomItemArgumentType(module); + } + + @Override + public @NotNull ArgumentType getNativeType() { + return ArgumentTypes.namespacedKey(); + } + + @Override + public @NotNull CustomItem convert(@NotNull NamespacedKey nativeType) throws CommandSyntaxException { + return this.module.item_registry().all().stream().filter(item -> item.key().equals(nativeType)).findFirst() + .orElseThrow(); + } + + @Override + public @NotNull CompletableFuture listSuggestions(@NotNull CommandContext context, + @NotNull SuggestionsBuilder builder) { + Stream stream = this.module.item_registry().all().stream(); + if(!builder.getRemaining().isBlank()){ + stream = stream.filter(item -> item.key().toString().contains(builder.getRemainingLowerCase())); + } + stream.collect(Collectors.toMap(item -> item.key().toString(), CustomItem::displayName)) + .forEach((key, name) -> builder.suggest(key, MessageComponentSerializer.message().serialize(name))); + return builder.buildFuture(); + + } + +} diff --git a/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/EnchantmentFilterArgumentType.java b/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/EnchantmentFilterArgumentType.java new file mode 100644 index 000000000..989594f5d --- /dev/null +++ b/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/EnchantmentFilterArgumentType.java @@ -0,0 +1,64 @@ +package org.oddlama.vane.core.command.argumentType; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; + +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; + +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; +import io.papermc.paper.command.brigadier.argument.CustomArgumentType; +import io.papermc.paper.registry.RegistryAccess; +import io.papermc.paper.registry.RegistryKey; + +public class EnchantmentFilterArgumentType implements CustomArgumentType.Converted { + + ItemStack item; + + public static EnchantmentFilterArgumentType enchantmentFilter() { + return new EnchantmentFilterArgumentType(); + } + + @Override + public @NotNull ArgumentType getNativeType() { + return ArgumentTypes.resource(RegistryKey.ENCHANTMENT); + } + + @Override + public @NotNull Enchantment convert(@NotNull Enchantment nativeType) throws CommandSyntaxException { + return nativeType; + } + + @Override + public @NotNull CompletableFuture listSuggestions(@NotNull CommandContext context, + @NotNull SuggestionsBuilder builder) { + + CommandSourceStack stack = (CommandSourceStack) context.getSource(); + ItemStack item = ((Player) stack.getSender()).getInventory().getItemInMainHand(); + + Stream compatibleEnchantments = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).stream(); + if(item.getType() != Material.BOOK && item.getType() != Material.ENCHANTED_BOOK) { + compatibleEnchantments = compatibleEnchantments.filter(ench -> ench.canEnchantItem(item)); + } + + Stream stream = compatibleEnchantments.map(ench -> ench.getKey().asString()); + if(!builder.getRemaining().isBlank()) { + stream = stream.filter(ench -> ench.contains(builder.getRemainingLowerCase())); + } + + stream.forEach(builder::suggest); + return builder.buildFuture(); + } + +} diff --git a/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/ModuleArgumentType.java b/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/ModuleArgumentType.java new file mode 100644 index 000000000..eba21417a --- /dev/null +++ b/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/ModuleArgumentType.java @@ -0,0 +1,55 @@ +package org.oddlama.vane.core.command.argumentType; + +import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; + +import org.jetbrains.annotations.NotNull; +import org.oddlama.vane.core.Core; +import org.oddlama.vane.core.module.Module; + +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; + +import io.papermc.paper.command.brigadier.argument.CustomArgumentType; + + +public class ModuleArgumentType implements CustomArgumentType.Converted, String> { + + Core core; + + @Override + public @NotNull ArgumentType getNativeType() { + return StringArgumentType.word(); + } + + public static @NotNull ModuleArgumentType module(Core module) { + return new ModuleArgumentType().setCore(module); + } + + private ModuleArgumentType setCore(Core module) { + this.core = module.core; + return this; + } + + @Override + public @NotNull Module convert(@NotNull String nativeType) throws CommandSyntaxException { + return core.get_modules().stream().filter(module -> module.get_name().equalsIgnoreCase(nativeType)).findFirst().orElseThrow(); + + } + + @Override + public @NotNull CompletableFuture listSuggestions(@NotNull CommandContext context, + @NotNull SuggestionsBuilder builder) { + Stream stream = core.get_modules().stream().map(Module::get_name); + if(!builder.getRemaining().isBlank()) { + stream = stream.filter(module -> module.contains(builder.getRemainingLowerCase())); + } + + stream.forEach(module -> builder.suggest(module)); + return builder.buildFuture(); + } +} diff --git a/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/OfflinePlayerArgumentType.java b/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/OfflinePlayerArgumentType.java new file mode 100644 index 000000000..18fe691f0 --- /dev/null +++ b/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/OfflinePlayerArgumentType.java @@ -0,0 +1,47 @@ +package org.oddlama.vane.core.command.argumentType; + +import java.util.Arrays; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.jetbrains.annotations.NotNull; + +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; + +import io.papermc.paper.command.brigadier.argument.CustomArgumentType; + +public class OfflinePlayerArgumentType implements CustomArgumentType.Converted{ + + public static @NotNull OfflinePlayerArgumentType offlinePlayer() { + return new OfflinePlayerArgumentType(); + } + + @Override + public @NotNull ArgumentType getNativeType() { + return StringArgumentType.word(); + } + + @Override + public @NotNull OfflinePlayer convert(@NotNull String nativeType) throws CommandSyntaxException { + return Bukkit.getOfflinePlayer(nativeType); + } + + @Override + public @NotNull CompletableFuture listSuggestions(@NotNull CommandContext context, + @NotNull SuggestionsBuilder builder) { + OfflinePlayer[] players = Bukkit.getOfflinePlayers(); + Stream stream = Arrays.stream(players).map(p -> p.getName()).filter(p -> p != null); + if(!builder.getRemaining().isBlank()) { + stream = stream.filter(player -> player.contains(builder.getRemaining())); + } + stream.forEach(builder::suggest); + return builder.buildFuture(); + } +} diff --git a/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/TimeValueArgumentType.java b/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/TimeValueArgumentType.java new file mode 100644 index 000000000..7c005fef7 --- /dev/null +++ b/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/TimeValueArgumentType.java @@ -0,0 +1,45 @@ +package org.oddlama.vane.core.command.argumentType; + +import java.util.Arrays; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; + +import org.jetbrains.annotations.NotNull; +import org.oddlama.vane.core.command.enums.TimeValue; + +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; + +import io.papermc.paper.command.brigadier.argument.CustomArgumentType; + +public class TimeValueArgumentType implements CustomArgumentType.Converted { + + public static TimeValueArgumentType timeValue() { + return new TimeValueArgumentType(); + } + + @Override + public @NotNull ArgumentType getNativeType() { + return StringArgumentType.word(); + } + + @Override + public @NotNull TimeValue convert(@NotNull String nativeType) throws CommandSyntaxException { + return TimeValue.valueOf(nativeType); + } + + @Override + public @NotNull CompletableFuture listSuggestions(@NotNull CommandContext context, + @NotNull SuggestionsBuilder builder) { + Stream stream = Arrays.stream(TimeValue.values()).map(time -> time.name()); + if(!builder.getRemaining().isBlank()) { + stream = stream.filter(timeName -> timeName.contains(builder.getRemaining())); + } + stream.forEach(builder::suggest); + return builder.buildFuture(); + } +} diff --git a/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/WeatherArgumentType.java b/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/WeatherArgumentType.java new file mode 100644 index 000000000..bd0749716 --- /dev/null +++ b/vane-core/src/main/java/org/oddlama/vane/core/command/argumentType/WeatherArgumentType.java @@ -0,0 +1,47 @@ +package org.oddlama.vane.core.command.argumentType; + +import java.util.Arrays; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; + +import org.jetbrains.annotations.NotNull; +import org.oddlama.vane.core.command.enums.WeatherValue; + +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; + +import io.papermc.paper.command.brigadier.argument.CustomArgumentType; + +public class WeatherArgumentType implements CustomArgumentType.Converted{ + + public static WeatherArgumentType weather() { + return new WeatherArgumentType(); + } + + @Override + public @NotNull ArgumentType getNativeType() { + return StringArgumentType.word(); + } + + @Override + public @NotNull WeatherValue convert(@NotNull String nativeType) throws CommandSyntaxException { + return WeatherValue.valueOf(nativeType); + } + + @Override + public @NotNull CompletableFuture listSuggestions(@NotNull CommandContext context, + @NotNull SuggestionsBuilder builder) { + Stream stream = Arrays.stream(WeatherValue.values()).map(time -> time.name()); + if(!builder.getRemaining().isBlank()) { + stream = stream.filter(weatherName -> weatherName.contains(builder.getRemaining())); + } + stream.forEach(builder::suggest); + return builder.buildFuture(); + } + + +} diff --git a/vane-core/src/main/java/org/oddlama/vane/core/command/enums/TimeValue.java b/vane-core/src/main/java/org/oddlama/vane/core/command/enums/TimeValue.java new file mode 100644 index 000000000..64952b7d5 --- /dev/null +++ b/vane-core/src/main/java/org/oddlama/vane/core/command/enums/TimeValue.java @@ -0,0 +1,21 @@ +package org.oddlama.vane.core.command.enums; + +public enum TimeValue { + dawn(23000), + day(1000), + noon(6000), + afternoon(9000), + dusk(13000), + night(14000), + midnight(18000); + + private int ticks; + + private TimeValue(int ticks) { + this.ticks = ticks; + } + + public int ticks() { + return ticks; + } +} diff --git a/vane-core/src/main/java/org/oddlama/vane/core/command/enums/WeatherValue.java b/vane-core/src/main/java/org/oddlama/vane/core/command/enums/WeatherValue.java new file mode 100644 index 000000000..7b062bed2 --- /dev/null +++ b/vane-core/src/main/java/org/oddlama/vane/core/command/enums/WeatherValue.java @@ -0,0 +1,24 @@ +package org.oddlama.vane.core.command.enums; + +public enum WeatherValue { + clear(false, false), + sun(false, false), + rain(true, false), + thunder(true, true); + + private boolean is_storm; + private boolean is_thunder; + + private WeatherValue(boolean is_storm, boolean is_thunder) { + this.is_storm = is_storm; + this.is_thunder = is_thunder; + } + + public boolean storm() { + return is_storm; + } + + public boolean thunder() { + return is_thunder; + } +} \ No newline at end of file diff --git a/vane-core/src/main/java/org/oddlama/vane/core/commands/CustomItem.java b/vane-core/src/main/java/org/oddlama/vane/core/commands/CustomItem.java index 4765a1663..159e3053c 100644 --- a/vane-core/src/main/java/org/oddlama/vane/core/commands/CustomItem.java +++ b/vane-core/src/main/java/org/oddlama/vane/core/commands/CustomItem.java @@ -1,35 +1,46 @@ package org.oddlama.vane.core.commands; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +import static io.papermc.paper.command.brigadier.Commands.argument; +import static io.papermc.paper.command.brigadier.Commands.literal; + import org.bukkit.entity.Player; +import org.bukkit.permissions.PermissionDefault; import org.oddlama.vane.annotation.command.Name; import org.oddlama.vane.core.Core; import org.oddlama.vane.core.command.Command; +import org.oddlama.vane.core.command.argumentType.CustomItemArgumentType; import org.oddlama.vane.core.module.Context; import org.oddlama.vane.util.PlayerUtil; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import io.papermc.paper.command.brigadier.CommandSourceStack; + @Name("customitem") public class CustomItem extends Command { public CustomItem(Context context) { super(context); - // Add help - params().fixed("help").ignore_case().exec(this::print_help); + } + @Override + public LiteralArgumentBuilder get_command_base() { + // Help + return super.get_command_base().executes(stack -> { + print_help2(stack); + return SINGLE_SUCCESS; + }) + .then(help()) // Give custom item - params() - .fixed("give") - .choice( - "custom_item", - sender -> get_module().item_registry().all(), - (sender, e) -> e.key().toString(), - (sender, e) -> - get_module().item_registry().all() - .stream() - .filter(i -> i.key().toString().equalsIgnoreCase(e)) - .findFirst() - .orElse(null) - ) - .exec_player(this::give_custom_item); + .then(literal("give") + .requires(stack -> stack.getSender() instanceof Player) + .then(argument("custom_item", CustomItemArgumentType.customItem(get_module())) + .executes(ctx -> { + org.oddlama.vane.core.item.api.CustomItem item = ctx.getArgument("custom_item", org.oddlama.vane.core.item.api.CustomItem.class); + give_custom_item((Player) ctx.getSource().getSender(), item); + return SINGLE_SUCCESS; + }))); } private void give_custom_item(final Player player, final org.oddlama.vane.core.item.api.CustomItem custom_item) { diff --git a/vane-core/src/main/java/org/oddlama/vane/core/commands/Enchant.java b/vane-core/src/main/java/org/oddlama/vane/core/commands/Enchant.java index 4c01a7c10..e442b9dc0 100644 --- a/vane-core/src/main/java/org/oddlama/vane/core/commands/Enchant.java +++ b/vane-core/src/main/java/org/oddlama/vane/core/commands/Enchant.java @@ -1,5 +1,9 @@ package org.oddlama.vane.core.commands; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +import static io.papermc.paper.command.brigadier.Commands.argument; +import static io.papermc.paper.command.brigadier.Commands.literal; + import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.enchantments.Enchantment; @@ -9,9 +13,16 @@ import org.oddlama.vane.annotation.lang.LangMessage; import org.oddlama.vane.core.Core; import org.oddlama.vane.core.command.Command; +import org.oddlama.vane.core.command.argumentType.EnchantmentFilterArgumentType; import org.oddlama.vane.core.lang.TranslatedMessage; import org.oddlama.vane.core.module.Context; +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; + +import io.papermc.paper.command.brigadier.CommandSourceStack; + @Name("enchant") public class Enchant extends Command { @@ -26,23 +37,25 @@ public class Enchant extends Command { public Enchant(Context context) { super(context); - // Add help - params().fixed("help").ignore_case().exec(this::print_help); - // Command parameters - var enchantment = params().choose_enchantment(this::filter_by_held_item); - enchantment.exec_player(this::enchant_current_item_level_1); - enchantment - .any( - "level", - str -> { - try { - return Integer.parseUnsignedInt(str); - } catch (NumberFormatException e) { - return null; - } - } - ) - .exec_player(this::enchant_current_item); + } + + @Override + public LiteralArgumentBuilder get_command_base() { + + return super.get_command_base() + .requires(ctx -> ctx.getSender() instanceof Player) + .then(help()) + .then( + argument("enchantment", EnchantmentFilterArgumentType.enchantmentFilter()) + .executes(ctx -> {enchant_current_item_level_1((Player) ctx.getSource().getSender(), enchantment(ctx)); return SINGLE_SUCCESS;}) + .then(argument("level", IntegerArgumentType.integer(1)) + .executes(ctx -> {enchant_current_item((Player) ctx.getSource().getSender(), enchantment(ctx), ctx.getArgument("level", Integer.class)); return SINGLE_SUCCESS;}) + ) + ); + } + + private Enchantment enchantment(CommandContext ctx){ + return ctx.getArgument("enchantment", Enchantment.class); } private boolean filter_by_held_item(CommandSender sender, Enchantment e) { diff --git a/vane-core/src/main/java/org/oddlama/vane/core/commands/Vane.java b/vane-core/src/main/java/org/oddlama/vane/core/commands/Vane.java index 7af0ad202..ddb044383 100644 --- a/vane-core/src/main/java/org/oddlama/vane/core/commands/Vane.java +++ b/vane-core/src/main/java/org/oddlama/vane/core/commands/Vane.java @@ -1,5 +1,9 @@ package org.oddlama.vane.core.commands; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +import static io.papermc.paper.command.brigadier.Commands.argument; +import static io.papermc.paper.command.brigadier.Commands.literal; + import java.util.Random; import org.bukkit.command.CommandSender; @@ -10,10 +14,15 @@ import org.oddlama.vane.annotation.lang.LangMessage; import org.oddlama.vane.core.Core; import org.oddlama.vane.core.command.Command; +import org.oddlama.vane.core.command.argumentType.ModuleArgumentType; import org.oddlama.vane.core.lang.TranslatedMessage; import org.oddlama.vane.core.module.Context; import org.oddlama.vane.core.module.Module; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import io.papermc.paper.command.brigadier.CommandSourceStack; + @Name("vane") public class Vane extends Command { @@ -31,16 +40,20 @@ public class Vane extends Command { public Vane(Context context) { super(context); - // Add help - params().fixed("help").ignore_case().exec(this::print_help); - - // Command parameters - var reload = params().fixed("reload").ignore_case(); - reload.exec(this::reload_all); - reload.choose_module().exec(this::reload_module); + } - params().fixed("generate_resource_pack").ignore_case().exec(this::generate_resource_pack); - params().fixed("test_do_not_use_if_you_are_not_a_dev").ignore_case().exec(this::test); + @Override + public LiteralArgumentBuilder get_command_base() { + return super.get_command_base() + .then(help()) + + .then(literal("reload").executes(ctx -> { reload_all(ctx.getSource().getSender()); return SINGLE_SUCCESS;}) + .then(argument("module", ModuleArgumentType.module(get_module())) + .executes(ctx -> { reload_module(ctx.getSource().getSender(), ctx.getArgument("module", Module.class)); return SINGLE_SUCCESS;}) + ) + ) + .then(literal("generate_resource_pack").executes(ctx -> { generate_resource_pack(ctx.getSource().getSender()); return SINGLE_SUCCESS; })) + .then(literal("test_do_not_use_if_you_are_not_a_dev").executes(ctx -> { test(ctx.getSource().getSender()); return SINGLE_SUCCESS; })); } private void reload_module(CommandSender sender, Module module) { diff --git a/vane-core/src/main/java/org/oddlama/vane/core/enchantments/CustomEnchantment.java b/vane-core/src/main/java/org/oddlama/vane/core/enchantments/CustomEnchantment.java index a86301ac3..6cfb1455d 100644 --- a/vane-core/src/main/java/org/oddlama/vane/core/enchantments/CustomEnchantment.java +++ b/vane-core/src/main/java/org/oddlama/vane/core/enchantments/CustomEnchantment.java @@ -9,7 +9,6 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.inventory.ItemStack; -import org.bukkit.craftbukkit.enchantments.CraftEnchantment; import org.jetbrains.annotations.NotNull; import org.oddlama.vane.annotation.enchantment.Rarity; import org.oddlama.vane.annotation.enchantment.VaneEnchantment; @@ -22,9 +21,10 @@ import org.oddlama.vane.core.lang.TranslatedMessage; import org.oddlama.vane.core.module.Context; import org.oddlama.vane.core.module.Module; -import org.oddlama.vane.util.Nms; import org.oddlama.vane.util.StorageUtil; +import io.papermc.paper.registry.RegistryAccess; +import io.papermc.paper.registry.RegistryKey; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; @@ -36,13 +36,11 @@ public class CustomEnchantment> extends Listener { private VaneEnchantment annotation = getClass().getAnnotation(VaneEnchantment.class); private String name; private NamespacedKey key; - private NativeEnchantmentWrapper native_wrapper; - - private final Set supersedes = new HashSet<>(); public Recipes recipes; public LootTables loot_tables; + // Language @LangMessage public TranslatedMessage lang_name; @@ -67,11 +65,6 @@ public CustomEnchantment(Context context, boolean default_enabled) { } instances.put(getClass(), this); - // Register and create wrappers - get_module().core.unfreeze_registries(); - native_wrapper = new NativeEnchantmentWrapper(this); - Nms.register_enchantment(key(), native_wrapper); - // Automatic recipes and loot table config and registration recipes = new Recipes(get_context(), this.key, this::default_recipes); loot_tables = new LootTables(get_context(), this.key, this::default_loot_tables); @@ -81,30 +74,7 @@ public CustomEnchantment(Context context, boolean default_enabled) { * Returns the bukkit wrapper for this enchantment. */ public final Enchantment bukkit() { - return CraftEnchantment.minecraftToBukkit(native_wrapper); - } - - /** - * Returns all enchantments that are superseded by this enchantment. - */ - public final Set supersedes() { - return supersedes; - } - - /** - * Adds a superseded enchantment. Superseded enchantments will be removed - * from the item when this enchantment is added. - */ - public final void supersedes(NamespacedKey e) { - supersedes.add(e); - } - - /** - * Adds a superseded enchantment. Superseded enchantments will be removed - * from the item when this enchantment is added. - */ - public final void supersedes(Enchantment e) { - supersedes(e.getKey()); + return RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).get(key); } /** diff --git a/vane-core/src/main/java/org/oddlama/vane/core/enchantments/CustomEnchantmentFixer.java b/vane-core/src/main/java/org/oddlama/vane/core/enchantments/CustomEnchantmentFixer.java deleted file mode 100644 index 186a9026b..000000000 --- a/vane-core/src/main/java/org/oddlama/vane/core/enchantments/CustomEnchantmentFixer.java +++ /dev/null @@ -1,209 +0,0 @@ -package org.oddlama.vane.core.enchantments; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.inventory.InventoryCreativeEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.EnchantmentStorageMeta; -import org.oddlama.vane.core.Core; -import org.oddlama.vane.core.Listener; -import org.oddlama.vane.core.module.Context; -import org.oddlama.vane.util.Nms; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.ListenerPriority; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.wrappers.EnumWrappers; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket; -import net.minecraft.network.syncher.EntityDataSerializer; -import net.minecraft.network.syncher.SynchedEntityData.DataValue; -import net.minecraft.world.item.crafting.RecipeHolder; - -public class CustomEnchantmentFixer extends Listener { - - ArrayList containerAdapters = new ArrayList(); - - public CustomEnchantmentFixer(Context context) { - super(context); - - } - - @Override - protected void on_enable() { - super.on_enable(); - for (var type : new PacketType[] { - PacketType.Play.Server.WINDOW_ITEMS, - PacketType.Play.Server.ENTITY_METADATA, - PacketType.Play.Server.ENTITY_EQUIPMENT, - PacketType.Play.Server.SET_SLOT, - }) { - var a = new ContainerAdapter(type); - get_module().protocol_manager.addPacketListener(a); - containerAdapters.add(a); - } - - var recipeAdapter = new RecipeAdapter(); - get_module().protocol_manager.addPacketListener(recipeAdapter); - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onCreativeItemMove(InventoryCreativeEvent event) { - Optional vaneEnchantment = event.getCurrentItem().getEnchantments().keySet().stream() - .filter((enchantment) -> enchantment.getKey().getNamespace().startsWith("vane")) - .findFirst(); - if(vaneEnchantment.isPresent()) { - event.setCancelled(true); - event.getView().getPlayer().sendMessage(Component.text("Moving items with Vane enchantments in creative mode is temporarily inactive.", NamedTextColor.GOLD)); - } - } - - public static ItemStack removeVaneEnchants(ItemStack item) { - if (item == null || item.getType() == null || item.getType() == Material.AIR) - return item; - ItemStack itemCopy = item.clone(); - - itemCopy.getEnchantments().forEach((enchantment, level) -> { - if (enchantment.getKey().getNamespace().startsWith("vane")) { - itemCopy.removeEnchantment(enchantment); - } - }); - - // also remove stored enchantments for enchanted books - if (itemCopy.getItemMeta() instanceof EnchantmentStorageMeta) { - EnchantmentStorageMeta meta = (EnchantmentStorageMeta) itemCopy.getItemMeta(); - meta.getStoredEnchants().forEach((enchantment, level) -> { - if (enchantment.getKey().getNamespace().startsWith("vane")) { - meta.removeStoredEnchant(enchantment); - } - }); - itemCopy.setItemMeta(meta); - } - - return itemCopy; - } - - class ContainerAdapter extends PacketAdapter { - private PacketType type; - - public ContainerAdapter(PacketType type) { - super( - CustomEnchantmentFixer.this.get_module(), - ListenerPriority.HIGHEST, - type); - this.type = type; - } - - @Override - public void onPacketSending(PacketEvent event) { - if (event.getPacket().getHandle() instanceof ClientboundSetEntityDataPacket edp) { - var newlist = edp.packedItems().stream().map(x -> { - if (x.value() instanceof net.minecraft.world.item.ItemStack itemStack && !itemStack.isEmpty()) { - - var bukkititem = CustomEnchantmentFixer.removeVaneEnchants(itemStack.asBukkitCopy()); - var newitem = Nms.item_handle(bukkititem); - return new DataValue(x.id(), - (EntityDataSerializer) x.serializer(), newitem); - } - return x; - }).toList(); - var newPacket = new ClientboundSetEntityDataPacket(edp.id(), newlist); - event.setPacket(PacketContainer.fromPacket(newPacket)); - } - try { - var mods = event.getPacket().getItemListModifier(); - for (int i = 0; i < mods.size(); ++i) { - try { - var slots = mods.readSafely(i); - List newSlots = slots.stream() - .map((item) -> CustomEnchantmentFixer.removeVaneEnchants(item)).toList(); - mods.writeSafely(i, newSlots); - } catch (Exception e) { - } - } - } catch (Exception e) { - } - try { - var mods = event.getPacket().getItemArrayModifier(); - for (int i = 0; i < mods.size(); ++i) { - try { - var slots = mods.readSafely(i); - var newSlots = (ItemStack[]) Arrays.stream(slots) - .map((item) -> CustomEnchantmentFixer.removeVaneEnchants(item)).toArray(); - mods.writeSafely(i, newSlots); - } catch (Exception e) { - } - } - } catch (Exception e) { - } - try { - var mods = event.getPacket().getSlotStackPairLists(); - for (int i = 0; i < mods.size(); ++i) { - try { - var slots = mods.readSafely(i); - var newSlots = slots.stream() - .map((pair) -> new com.comphenix.protocol.wrappers.Pair( - pair.getFirst(), - CustomEnchantmentFixer.removeVaneEnchants(pair.getSecond()))) - .toList(); - mods.writeSafely(i, newSlots); - } catch (Exception e) { - } - } - } catch (Exception e) { - } - try { - var mods = event.getPacket().getItemModifier(); - for (int i = 0; i < mods.size(); ++i) { - try { - var item = mods.readSafely(i); - item = CustomEnchantmentFixer.removeVaneEnchants(item); - mods.writeSafely(i, item); - } catch (Exception e) { - } - } - } catch (Exception e) { - } - } - } - class RecipeAdapter extends PacketAdapter { - public RecipeAdapter() { - super(CustomEnchantmentFixer.this.get_module(), - ListenerPriority.HIGHEST, - PacketType.Play.Server.RECIPE_UPDATE); - } - - @Override - public void onPacketSending(PacketEvent event) { - if(event.getPacketType().getCurrentId() != 0x77) { - return; - } - var packet = (ClientboundUpdateRecipesPacket) event.getPacket().getHandle(); - - var newRecipes = new ArrayList>(); - for (RecipeHolder recipe : packet.getRecipes()) { - if(recipe.id().getNamespace().startsWith("vane_enchantment")) continue; - newRecipes.add(recipe); - } - - var newPacket = new PacketContainer(PacketType.Play.Server.RECIPE_UPDATE, new ClientboundUpdateRecipesPacket(newRecipes)); - - event.setPacket(newPacket); - } - } - -} diff --git a/vane-core/src/main/java/org/oddlama/vane/core/enchantments/EnchantmentManager.java b/vane-core/src/main/java/org/oddlama/vane/core/enchantments/EnchantmentManager.java index 5bb9a6d0b..7dc492c5c 100644 --- a/vane-core/src/main/java/org/oddlama/vane/core/enchantments/EnchantmentManager.java +++ b/vane-core/src/main/java/org/oddlama/vane/core/enchantments/EnchantmentManager.java @@ -74,18 +74,18 @@ public ItemStack update_enchanted_item( } private void remove_superseded(ItemStack item_stack, Map enchantments) { - if (enchantments.isEmpty()) { - return; - } + // if (enchantments.isEmpty()) { + // return; + // } // 1. Build a list of all enchantments that would be removed because // they are superseded by some enchantment. - final var to_remove_inclusive = enchantments.keySet().stream() - .map(x -> ((CraftEnchantment)x).getHandle()) - .filter(x -> x instanceof NativeEnchantmentWrapper) - .map(x -> ((NativeEnchantmentWrapper)x).custom().supersedes()) - .flatMap(Set::stream) - .collect(Collectors.toSet()); + // final var to_remove_inclusive = enchantments.keySet().stream() + // .map(x -> ((CraftEnchantment)x).getHandle()) + // .filter(x -> x instanceof NativeEnchantmentWrapper) + // .map(x -> ((NativeEnchantmentWrapper)x).custom().supersedes()) + // .flatMap(Set::stream) + // .collect(Collectors.toSet()); // 2. Before removing these enchantments, first re-build the list but // ignore any enchantments in the calculation that would themselves @@ -93,45 +93,45 @@ private void remove_superseded(ItemStack item_stack, Map e // enchantments to remove. Consider this: A supersedes B, and B supersedes C, but // A doesn't supersede C. Now an item with A B and C should get reduced to // A and C, not just to A. - var to_remove = enchantments.keySet().stream() - .map(x -> ((CraftEnchantment)x).getHandle()) - .filter(x -> x instanceof NativeEnchantmentWrapper) - .filter(x -> !to_remove_inclusive.contains(((NativeEnchantmentWrapper)x).custom().key())) // Ignore enchantments that are themselves removed. - .map(x -> ((NativeEnchantmentWrapper)x).custom().supersedes()) - .flatMap(Set::stream) - .map(x -> org.bukkit.Registry.ENCHANTMENT.get(x)) - .collect(Collectors.toSet()); - - for (var e : to_remove) { - item_stack.removeEnchantment(e); - enchantments.remove(e); - } + // var to_remove = enchantments.keySet().stream() + // .map(x -> ((CraftEnchantment)x).getHandle()) + // .filter(x -> x instanceof NativeEnchantmentWrapper) + // .filter(x -> !to_remove_inclusive.contains(((NativeEnchantmentWrapper)x).custom().key())) // Ignore enchantments that are themselves removed. + // .map(x -> ((NativeEnchantmentWrapper)x).custom().supersedes()) + // .flatMap(Set::stream) + // .map(x -> org.bukkit.Registry.ENCHANTMENT.get(x)) + // .collect(Collectors.toSet()); + + // for (var e : to_remove) { + // item_stack.removeEnchantment(e); + // enchantments.remove(e); + // } } private void update_lore(ItemStack item_stack, Map enchantments) { // Create lore by converting enchantment name and level to string // and prepend rarity color (can be overwritten in description) - final var vane_enchantments = enchantments - .entrySet() - .stream() - .filter(p -> ((CraftEnchantment)p.getKey()).getHandle() instanceof NativeEnchantmentWrapper) - .sorted(Map.Entry.comparingByKey(Comparator.comparing(x -> x.getKey().toString())) - .thenComparing(Map.Entry.comparingByValue()) - ) - .toList(); - - var lore = item_stack.lore(); - if (lore == null) { - lore = new ArrayList(); - } - - lore.removeIf(this::is_enchantment_lore); - lore.addAll(0, vane_enchantments.stream().map(ench -> - ItemUtil.add_sentinel(((NativeEnchantmentWrapper)((CraftEnchantment) ench.getKey()).getHandle()).custom().display_name(ench.getValue()), SENTINEL) - ).toList()); - - // Set lore - item_stack.lore(lore.isEmpty() ? null : lore); + // final var vane_enchantments = enchantments + // .entrySet() + // .stream() + // .filter(p -> ((CraftEnchantment)p.getKey()).getHandle() instanceof NativeEnchantmentWrapper) + // .sorted(Map.Entry.comparingByKey(Comparator.comparing(x -> x.getKey().toString())) + // .thenComparing(Map.Entry.comparingByValue()) + // ) + // .toList(); + + // var lore = item_stack.lore(); + // if (lore == null) { + // lore = new ArrayList(); + // } + + // lore.removeIf(this::is_enchantment_lore); + // lore.addAll(0, vane_enchantments.stream().map(ench -> + // ItemUtil.add_sentinel(((NativeEnchantmentWrapper)((CraftEnchantment) ench.getKey()).getHandle()).custom().display_name(ench.getValue()), SENTINEL) + // ).toList()); + + // // Set lore + // item_stack.lore(lore.isEmpty() ? null : lore); } private boolean is_enchantment_lore(final Component component) { @@ -143,29 +143,29 @@ private boolean is_enchantment_lore(final Component component) { return ItemUtil.has_sentinel(component, SENTINEL); } - // Triggers on Anvils, grindstones, and smithing tables. - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void on_prepare_enchanted_edit(final PrepareResultEvent event) { - if (event.getResult() == null) { - return; - } - - event.setResult(update_enchanted_item(event.getResult().clone())); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void on_enchant_item(final EnchantItemEvent event) { - final var map = new HashMap(event.getEnchantsToAdd()); - update_enchanted_item(event.getItem(), map); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void on_loot_generate(final LootGenerateEvent event) { - for (final var item : event.getLoot()) { - // Update all item lore in case they are enchanted - update_enchanted_item(item, true); - } - } + // // Triggers on Anvils, grindstones, and smithing tables. + // @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + // public void on_prepare_enchanted_edit(final PrepareResultEvent event) { + // if (event.getResult() == null) { + // return; + // } + + // event.setResult(update_enchanted_item(event.getResult().clone())); + // } + + // @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + // public void on_enchant_item(final EnchantItemEvent event) { + // final var map = new HashMap(event.getEnchantsToAdd()); + // update_enchanted_item(event.getItem(), map); + // } + + // @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + // public void on_loot_generate(final LootGenerateEvent event) { + // for (final var item : event.getLoot()) { + // // Update all item lore in case they are enchanted + // update_enchanted_item(item, true); + // } + // } private MerchantRecipe process_recipe(final MerchantRecipe recipe) { var result = recipe.getResult().clone(); @@ -183,27 +183,27 @@ private MerchantRecipe process_recipe(final MerchantRecipe recipe) { return new_recipe; } - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void on_acquire_trade(final VillagerAcquireTradeEvent event) { - event.setRecipe(process_recipe(event.getRecipe())); - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void on_right_click_villager(final PlayerInteractEntityEvent event) { - final var entity = event.getRightClicked(); - if (!(entity instanceof Merchant)) { - return; - } - - final var merchant = (Merchant) entity; - final var recipes = new ArrayList(); - - // Check all recipes - for (final var r : merchant.getRecipes()) { - recipes.add(process_recipe(r)); - } - - // Update recipes - merchant.setRecipes(recipes); - } + // @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + // public void on_acquire_trade(final VillagerAcquireTradeEvent event) { + // event.setRecipe(process_recipe(event.getRecipe())); + // } + + // @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + // public void on_right_click_villager(final PlayerInteractEntityEvent event) { + // final var entity = event.getRightClicked(); + // if (!(entity instanceof Merchant)) { + // return; + // } + + // final var merchant = (Merchant) entity; + // final var recipes = new ArrayList(); + + // // Check all recipes + // for (final var r : merchant.getRecipes()) { + // recipes.add(process_recipe(r)); + // } + + // // Update recipes + // merchant.setRecipes(recipes); + // } } diff --git a/vane-core/src/main/java/org/oddlama/vane/core/enchantments/NativeEnchantmentWrapper.java b/vane-core/src/main/java/org/oddlama/vane/core/enchantments/NativeEnchantmentWrapper.java deleted file mode 100644 index 2a1ae85ec..000000000 --- a/vane-core/src/main/java/org/oddlama/vane/core/enchantments/NativeEnchantmentWrapper.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.oddlama.vane.core.enchantments; - -import static org.oddlama.vane.util.Nms.bukkit_enchantment; -import static org.oddlama.vane.util.Nms.enchantment_slot_type; - -import java.util.Optional; - -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.flag.FeatureFlagSet; -import net.minecraft.world.flag.FeatureFlags; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.Enchantment; -import org.jetbrains.annotations.NotNull; -import org.oddlama.vane.util.Nms; - -/** - * Provides a native counterpart for CustomEnchantment. - * All logic will be forwarded to the CustomEnchantment instance. - */ -public class NativeEnchantmentWrapper extends Enchantment { - - private CustomEnchantment enchantment; - - public NativeEnchantmentWrapper(CustomEnchantment enchantment) { - // FIXME not sure of this constructor - super(new EnchantmentDefinition( - enchantment_slot_type(enchantment.target()), - Optional.empty(), - 0, - enchantment.max_level(), - new Enchantment.Cost(0, 0), - new Enchantment.Cost(0, 0), - 0, - FeatureFlags.VANILLA_SET, - new EquipmentSlot[] {} - )); - this.enchantment = enchantment; - } - - public CustomEnchantment custom() { - return this.enchantment; - } - - // FIXME these overriden methods are final - // @Override - // public int getMinLevel() { - // return enchantment.min_level(); - // } - - // @Override - // public int getMaxLevel() { - // return enchantment.max_level(); - // } - - // @Override - // public int getMinCost(int level) { - // return enchantment.min_cost(level); - // } - - // @Override - // public int getMaxCost(int level) { - // return enchantment.max_cost(level); - // } - - @Override - public boolean isTreasureOnly() { - return enchantment.is_treasure(); - } - - @Override - public boolean isDiscoverable() { - return enchantment.enabled() && enchantment.generate_in_treasure(); - } - - @Override - public boolean isTradeable() { - return enchantment.enabled() && enchantment.is_tradeable(); - } - - @Override - public boolean isCurse() { - return enchantment.is_curse(); - } - - @Override - public boolean checkCompatibility(@NotNull Enchantment other) { - return this != other && enchantment.is_compatible(bukkit_enchantment(other)); - } - - @Override - public boolean canEnchant(ItemStack itemstack) { - // Custom item pre-check - final var bukkit_item = Nms.bukkit_item_stack(itemstack); - if (!enchantment.allow_custom() && enchantment.get_module().core.item_registry().get(bukkit_item) != null) { - return false; - } - return enchantment.enabled() && enchantment.can_enchant(bukkit_item); - } -} diff --git a/vane-core/src/main/java/org/oddlama/vane/core/module/Module.java b/vane-core/src/main/java/org/oddlama/vane/core/module/Module.java index 6cddce622..166947014 100644 --- a/vane-core/src/main/java/org/oddlama/vane/core/module/Module.java +++ b/vane-core/src/main/java/org/oddlama/vane/core/module/Module.java @@ -2,8 +2,6 @@ import static org.oddlama.vane.util.ResourceList.get_resources; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.ProtocolManager; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; @@ -19,6 +17,7 @@ import java.util.logging.Logger; import java.util.regex.Pattern; import java.util.stream.Collectors; + import org.bstats.bukkit.Metrics; import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; @@ -32,6 +31,7 @@ import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionDefault; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.oddlama.vane.annotation.VaneModule; import org.oddlama.vane.annotation.config.ConfigBoolean; @@ -41,15 +41,19 @@ import org.oddlama.vane.annotation.persistent.Persistent; import org.oddlama.vane.core.Core; import org.oddlama.vane.core.LootTable; -import org.oddlama.vane.core.resourcepack.ResourcePackGenerator; - -import net.kyori.adventure.text.logger.slf4j.ComponentLogger; - import org.oddlama.vane.core.command.Command; import org.oddlama.vane.core.config.ConfigManager; import org.oddlama.vane.core.functional.Consumer1; import org.oddlama.vane.core.lang.LangManager; import org.oddlama.vane.core.persistent.PersistentStorageManager; +import org.oddlama.vane.core.resourcepack.ResourcePackGenerator; + +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.ProtocolManager; + +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager; +import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; +import net.kyori.adventure.text.logger.slf4j.ComponentLogger; public abstract class Module> extends JavaPlugin implements Context, org.bukkit.event.Listener { @@ -429,14 +433,10 @@ public String get_name() { } public void register_command(Command command) { - if ( - !getServer() - .getCommandMap() - .register(command.get_name(), command.get_prefix(), command.get_bukkit_command()) - ) { - log.warning("Command " + command.get_name() + " was registered using the fallback prefix!"); - log.warning("Another command with the same name already exists!"); - } + LifecycleEventManager manager = this.getLifecycleManager(); + manager.registerEventHandler(LifecycleEvents.COMMANDS, event -> { + event.registrar().register(command.get_command(), command.lang_description.str(), command.get_aliases()); + }); } public void unregister_command(Command command) { diff --git a/vane-core/src/main/java/org/oddlama/vane/util/ItemUtil.java b/vane-core/src/main/java/org/oddlama/vane/util/ItemUtil.java index 8cf39f3d3..9ae7e2cf8 100644 --- a/vane-core/src/main/java/org/oddlama/vane/util/ItemUtil.java +++ b/vane-core/src/main/java/org/oddlama/vane/util/ItemUtil.java @@ -33,6 +33,8 @@ import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.papermc.paper.registry.RegistryAccess; +import io.papermc.paper.registry.RegistryKey; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.HoverEvent; @@ -42,7 +44,6 @@ import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.item.ItemParser; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.RandomSource; import net.minecraft.world.item.Item; public class ItemUtil { @@ -67,9 +68,8 @@ public static void damage_item(final Player player, final ItemStack item_stack, if (handle == null) { return; } - RandomSource random = Nms.world_handle(player.getWorld()).getRandom(); - handle.hurtAndBreak(amount, random, player_handle(player), () -> { player.broadcastSlotBreak(EquipmentSlot.HAND); item_stack.subtract(); }); + handle.hurtAndBreak(amount, Nms.world_handle(player.getWorld()), player_handle(player), (item) -> { player.broadcastSlotBreak(EquipmentSlot.HAND); item_stack.subtract(); }); } public static String name_of(final ItemStack item) { @@ -325,7 +325,7 @@ private static ItemStack apply_enchants(final ItemStack item_stack, @Nullable St key = key.substring(0, level_delim); } - final var ench = org.bukkit.Registry.ENCHANTMENT.get(NamespacedKey.fromString(key)); + final var ench = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).get(NamespacedKey.fromString(key)); if (ench == null) { throw new IllegalArgumentException( "Cannot apply unknown enchantment '" + key + "' to item '" + item_stack + "'"); diff --git a/vane-core/src/main/java/org/oddlama/vane/util/Nms.java b/vane-core/src/main/java/org/oddlama/vane/util/Nms.java index 71fa140c6..61c167092 100644 --- a/vane-core/src/main/java/org/oddlama/vane/util/Nms.java +++ b/vane-core/src/main/java/org/oddlama/vane/util/Nms.java @@ -48,10 +48,6 @@ public static Entity entity_handle(final org.bukkit.entity.Entity entity) { return ((CraftEntity) entity).getHandle(); } - public static void register_enchantment(NamespacedKey key, Enchantment enchantment) { - Registry.register(BuiltInRegistries.ENCHANTMENT, new ResourceLocation(key.getNamespace(), key.getKey()), enchantment); - } - public static org.bukkit.enchantments.Enchantment bukkit_enchantment(Enchantment enchantment) { return CraftEnchantment.minecraftToBukkit(enchantment); } diff --git a/vane-core/src/main/resources/plugin.yml b/vane-core/src/main/resources/paper-plugin.yml similarity index 62% rename from vane-core/src/main/resources/plugin.yml rename to vane-core/src/main/resources/paper-plugin.yml index 16ecaa388..f83c5be86 100644 --- a/vane-core/src/main/resources/plugin.yml +++ b/vane-core/src/main/resources/paper-plugin.yml @@ -2,14 +2,17 @@ name: ${name} version: ${version} description: Immersive and lore friendly extensions for vanilla minecraft -authors: [oddlama] +authors: + - oddlama website: 'https://github.com/oddlama/vane' -depend: [ProtocolLib] -softdepend: [] - main: org.oddlama.vane.core.Core -database: false -api-version: 1.19 +api-version: '1.21' + load: STARTUP +dependencies: + server: + ProtocolLib: + load: BEFORE + required: true \ No newline at end of file diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/CustomEnchantmentRegistry.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/CustomEnchantmentRegistry.java new file mode 100644 index 000000000..b5981842c --- /dev/null +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/CustomEnchantmentRegistry.java @@ -0,0 +1,99 @@ +package org.oddlama.vane.enchantments; + +import java.util.List; + +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.EquipmentSlotGroup; +import org.bukkit.inventory.ItemType; + +import io.papermc.paper.registry.RegistryKey; +import io.papermc.paper.registry.TypedKey; +import io.papermc.paper.registry.data.EnchantmentRegistryEntry; +import io.papermc.paper.registry.event.RegistryFreezeEvent; +import io.papermc.paper.registry.set.RegistryKeySet; +import io.papermc.paper.registry.set.RegistrySet; +import io.papermc.paper.registry.tag.TagKey; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.text.Component; + +public abstract class CustomEnchantmentRegistry { + + final public static String NAMESPACE = "vane_enchantments"; + final private static String TRANSLATE_KEY = "vane_enchantments.enchantment_%s.name"; + Key key; + Component description; + int max_level; + + TagKey supported_item_tags; + List> supported_items = List.of(); + + TagKey exclusive_with_tags; + List> exclusive_with = List.of(); + + public CustomEnchantmentRegistry(String name, TagKey supported_item_tags, int max_level) { + this.key = Key.key(NAMESPACE, name); + this.description = Component.translatable(String.format(TRANSLATE_KEY, name)); + this.supported_item_tags = supported_item_tags; + this.max_level = max_level; + } + + public CustomEnchantmentRegistry(String name, List> supported_items, int max_level) { + this.key = Key.key(NAMESPACE, name); + this.description = Component.translatable(String.format(TRANSLATE_KEY, name)); + this.supported_items = supported_items; + this.max_level = max_level; + } + + /** + * Add exclusive enchantments to this enchantment: exclusive enchantments can't be on the + * same tool. + */ + public CustomEnchantmentRegistry exclusive_with(List> enchantments){ + this.exclusive_with = enchantments; + return this; + } + + /** + * Add exclusive enchantment tag to this enchantment: exclusive enchantments can't be on the + * same tool. + */ + public CustomEnchantmentRegistry exclusive_with(TagKey enchantment_tag){ + this.exclusive_with_tags = enchantment_tag; + return this; + } + + /** + * Get exclusive enchantments + */ + public RegistryKeySet exclusive_with(RegistryFreezeEvent freezeEvent) { + if(this.exclusive_with_tags != null) { + return freezeEvent.getOrCreateTag(exclusive_with_tags); + } else { + return RegistrySet.keySet(RegistryKey.ENCHANTMENT, this.exclusive_with); + } + } + + /** + * Register the enchantment in the registry + * + * @see https://docs.papermc.io/paper/dev/registries#create-new-entries + */ + public void register(RegistryFreezeEvent freezeEvent){ + freezeEvent.registry().register(TypedKey.create(RegistryKey.ENCHANTMENT, key), + e -> e.description(description) + .supportedItems(supported_items.size() > 0 ? RegistrySet.keySet(RegistryKey.ITEM, supported_items) : freezeEvent.getOrCreateTag(supported_item_tags)) + .anvilCost(1) + .maxLevel(max_level) + .weight(10) + .minimumCost(EnchantmentRegistryEntry.EnchantmentCost.of(1, 1)) + .maximumCost(EnchantmentRegistryEntry.EnchantmentCost.of(3, 1)) + .activeSlots(EquipmentSlotGroup.ANY) + .exclusiveWith(this.exclusive_with(freezeEvent)) + ); + } + + public TypedKey typedKey(String name) { + return TypedKey.create(RegistryKey.ENCHANTMENT, Key.key(NAMESPACE, name)); + } + +} diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/EnchantmentsBootstrapper.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/EnchantmentsBootstrapper.java new file mode 100644 index 000000000..9e6af1f3a --- /dev/null +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/EnchantmentsBootstrapper.java @@ -0,0 +1,39 @@ +package org.oddlama.vane.enchantments; + +import org.jetbrains.annotations.NotNull; +import org.oddlama.vane.enchantments.enchantments.registry.AngelRegistry; +import org.oddlama.vane.enchantments.enchantments.registry.GrapplingHookRegistry; +import org.oddlama.vane.enchantments.enchantments.registry.HellBentRegistry; +import org.oddlama.vane.enchantments.enchantments.registry.LeafchopperRegistry; +import org.oddlama.vane.enchantments.enchantments.registry.LightningRegistry; +import org.oddlama.vane.enchantments.enchantments.registry.RakeRegistry; +import org.oddlama.vane.enchantments.enchantments.registry.SeedingRegistry; +import org.oddlama.vane.enchantments.enchantments.registry.SouldboundRegistry; +import org.oddlama.vane.enchantments.enchantments.registry.TakeOffRegistry; +import org.oddlama.vane.enchantments.enchantments.registry.UnbreakableRegistry; +import org.oddlama.vane.enchantments.enchantments.registry.WingsRegistry; + +import io.papermc.paper.plugin.bootstrap.BootstrapContext; +import io.papermc.paper.plugin.bootstrap.PluginBootstrap; +import io.papermc.paper.registry.event.RegistryEvents; + +public class EnchantmentsBootstrapper implements PluginBootstrap { + + @Override + public void bootstrap(@NotNull BootstrapContext context) { + context.getLifecycleManager().registerEventHandler(RegistryEvents.ENCHANTMENT.freeze().newHandler(event -> { + new AngelRegistry(event); + new GrapplingHookRegistry(event); + new HellBentRegistry(event); + new LeafchopperRegistry(event); + new LightningRegistry(event); + new RakeRegistry(event); + new SeedingRegistry(event); + new WingsRegistry(event); + new SouldboundRegistry(event); + new TakeOffRegistry(event); + new UnbreakableRegistry(event); + })); + } + +} diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Angel.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Angel.java index 17c5e4470..84c516e9c 100644 --- a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Angel.java +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Angel.java @@ -7,9 +7,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.inventory.ItemStack; import org.bukkit.loot.LootTables; -import org.jetbrains.annotations.NotNull; import org.oddlama.vane.annotation.config.ConfigDouble; import org.oddlama.vane.annotation.config.ConfigDoubleList; import org.oddlama.vane.annotation.enchantment.Rarity; @@ -21,7 +19,6 @@ import org.oddlama.vane.core.module.Context; import org.oddlama.vane.core.enchantments.CustomEnchantment; import org.oddlama.vane.enchantments.Enchantments; -import org.oddlama.vane.util.StorageUtil; @VaneEnchantment(name = "angel", max_level = 5, rarity = Rarity.VERY_RARE, treasure = true, allow_custom = true) public class Angel extends CustomEnchantment { @@ -43,7 +40,6 @@ public class Angel extends CustomEnchantment { public Angel(Context context) { super(context); - supersedes(StorageUtil.namespaced_key("vane_enchantments", "wings")); } @Override @@ -70,11 +66,6 @@ public LootTableList default_loot_tables() { .add(1.0 / 250, 1, 1, on("vane_enchantments:enchanted_ancient_tome_of_the_gods"))); } - @Override - public boolean can_enchant(@NotNull ItemStack item_stack) { - return item_stack.getType() == Material.ELYTRA; - } - private double get_speed(int level) { if (level > 0 && level <= config_speed.size()) { return config_speed.get(level - 1); diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Leafchopper.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Leafchopper.java index f18d56b76..ade1f6b6b 100644 --- a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Leafchopper.java +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Leafchopper.java @@ -1,7 +1,5 @@ package org.oddlama.vane.enchantments.enchantments; -import com.destroystokyo.paper.MaterialTags; - import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.SoundCategory; @@ -12,14 +10,12 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; import org.oddlama.vane.annotation.enchantment.Rarity; import org.oddlama.vane.annotation.enchantment.VaneEnchantment; import org.oddlama.vane.core.config.recipes.RecipeList; import org.oddlama.vane.core.config.recipes.ShapedRecipeDefinition; -import org.oddlama.vane.core.module.Context; import org.oddlama.vane.core.enchantments.CustomEnchantment; +import org.oddlama.vane.core.module.Context; import org.oddlama.vane.enchantments.Enchantments; @VaneEnchantment(name = "leafchopper", rarity = Rarity.COMMON, treasure = true, target = EnchantmentTarget.TOOL) @@ -38,11 +34,6 @@ public RecipeList default_recipes() { .result(on("vane_enchantments:enchanted_ancient_tome_of_knowledge"))); } - @Override - public boolean can_enchant(@NotNull ItemStack item_stack) { - return MaterialTags.AXES.isTagged(item_stack); - } - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void on_player_left_click_leaves(PlayerInteractEvent event) { if ( diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Lightning.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Lightning.java index b48bffb4f..bf866451b 100644 --- a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Lightning.java +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Lightning.java @@ -1,27 +1,23 @@ package org.oddlama.vane.enchantments.enchantments; import org.bukkit.Material; +import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.enchantments.EnchantmentTarget; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; import org.oddlama.vane.annotation.config.ConfigBoolean; import org.oddlama.vane.annotation.config.ConfigInt; import org.oddlama.vane.annotation.enchantment.Rarity; import org.oddlama.vane.annotation.enchantment.VaneEnchantment; import org.oddlama.vane.core.config.recipes.RecipeList; import org.oddlama.vane.core.config.recipes.ShapedRecipeDefinition; -import org.oddlama.vane.core.module.Context; import org.oddlama.vane.core.enchantments.CustomEnchantment; +import org.oddlama.vane.core.module.Context; import org.oddlama.vane.enchantments.Enchantments; -import com.destroystokyo.paper.MaterialTags; - @VaneEnchantment( name = "lightning", max_level = 1, @@ -66,11 +62,6 @@ public RecipeList default_recipes() { .result(on("vane_enchantments:enchanted_ancient_tome_of_knowledge"))); } - @Override - public boolean can_enchant(@NotNull ItemStack item_stack) { - return MaterialTags.SWORDS.isTagged(item_stack); - } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void on_lightning_attack(final EntityDamageEvent event) { diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Rake.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Rake.java index ce5b13b86..89d48c583 100644 --- a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Rake.java +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Rake.java @@ -5,22 +5,18 @@ import static org.oddlama.vane.util.PlayerUtil.swing_arm; import static org.oddlama.vane.util.PlayerUtil.till_block; -import com.destroystokyo.paper.MaterialTags; - import org.bukkit.Material; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; import org.oddlama.vane.annotation.enchantment.Rarity; import org.oddlama.vane.annotation.enchantment.VaneEnchantment; import org.oddlama.vane.core.config.recipes.RecipeList; import org.oddlama.vane.core.config.recipes.ShapedRecipeDefinition; -import org.oddlama.vane.core.module.Context; import org.oddlama.vane.core.enchantments.CustomEnchantment; +import org.oddlama.vane.core.module.Context; import org.oddlama.vane.enchantments.Enchantments; @VaneEnchantment(name = "rake", max_level = 4, rarity = Rarity.COMMON, treasure = true, target = EnchantmentTarget.TOOL) @@ -39,11 +35,6 @@ public RecipeList default_recipes() { .result(on("vane_enchantments:enchanted_ancient_tome_of_knowledge"))); } - @Override - public boolean can_enchant(@NotNull ItemStack item_stack) { - return MaterialTags.HOES.isTagged(item_stack); - } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void on_player_till_farmland(final PlayerInteractEvent event) { if (!event.hasBlock() || event.getAction() != Action.RIGHT_CLICK_BLOCK) { diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Seeding.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Seeding.java index ba2bb706e..93f799f7c 100644 --- a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Seeding.java +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Seeding.java @@ -8,22 +8,18 @@ import static org.oddlama.vane.util.PlayerUtil.seed_block; import static org.oddlama.vane.util.PlayerUtil.swing_arm; -import com.destroystokyo.paper.MaterialTags; - import org.bukkit.Material; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; import org.oddlama.vane.annotation.enchantment.Rarity; import org.oddlama.vane.annotation.enchantment.VaneEnchantment; import org.oddlama.vane.core.config.recipes.RecipeList; import org.oddlama.vane.core.config.recipes.ShapedRecipeDefinition; -import org.oddlama.vane.core.module.Context; import org.oddlama.vane.core.enchantments.CustomEnchantment; +import org.oddlama.vane.core.module.Context; import org.oddlama.vane.enchantments.Enchantments; @VaneEnchantment( @@ -54,11 +50,6 @@ public RecipeList default_recipes() { .result(on("vane_enchantments:enchanted_ancient_tome_of_knowledge"))); } - @Override - public boolean can_enchant(@NotNull ItemStack item_stack) { - return MaterialTags.HOES.isTagged(item_stack); - } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void on_player_right_click_plant(final PlayerInteractEvent event) { if (!event.hasBlock() || event.getAction() != Action.RIGHT_CLICK_BLOCK) { diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Soulbound.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Soulbound.java index a1fb702b4..261b038f1 100644 --- a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Soulbound.java +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Soulbound.java @@ -24,7 +24,6 @@ import org.oddlama.vane.core.lang.TranslatedMessage; import org.oddlama.vane.core.module.Context; import org.oddlama.vane.core.enchantments.CustomEnchantment; -import org.oddlama.vane.core.enchantments.CustomEnchantmentFixer; import org.oddlama.vane.enchantments.Enchantments; import org.oddlama.vane.util.StorageUtil; @@ -141,7 +140,7 @@ public void on_player_drop_item(final PlayerDropItemEvent event) { var meta = dropped_item.getItemMeta(); drop_cooldown.clear(dropped_item.getItemMeta()); dropped_item.setItemMeta(meta); - lang_dropped_notification.send(event.getPlayer(), CustomEnchantmentFixer.removeVaneEnchants(dropped_item).displayName()); + lang_dropped_notification.send(event.getPlayer(), dropped_item.displayName()); return; } final var inventory = event.getPlayer().getInventory(); @@ -150,7 +149,7 @@ public void on_player_drop_item(final PlayerDropItemEvent event) { event.setCancelled(true); lang_drop_lock_warning.send_action_bar( event.getPlayer(), - CustomEnchantmentFixer.removeVaneEnchants(event.getItemDrop().getItemStack()).displayName() + event.getItemDrop().getItemStack().displayName() ); } else { // Inventory is full (e.g., when exiting crafting table with soulbound item in it) @@ -178,7 +177,7 @@ public void on_player_drop_item(final PlayerDropItemEvent event) { final var player = event.getPlayer(); inventory.setItem(non_soulbound_item_slot, dropped_item); player.getLocation().getWorld().dropItem(player.getLocation(), non_soulbound_item); - lang_drop_lock_warning.send_action_bar(player, CustomEnchantmentFixer.removeVaneEnchants(event.getItemDrop().getItemStack()).displayName()); + lang_drop_lock_warning.send_action_bar(player, event.getItemDrop().getItemStack().displayName()); event.setCancelled(true); } } diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/TakeOff.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/TakeOff.java index 0e7c57c4f..9550a6ee0 100644 --- a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/TakeOff.java +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/TakeOff.java @@ -12,10 +12,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityToggleGlideEvent; -import org.bukkit.inventory.ItemStack; import org.bukkit.loot.LootTables; import org.bukkit.util.Vector; -import org.jetbrains.annotations.NotNull; import org.oddlama.vane.annotation.config.ConfigDoubleList; import org.oddlama.vane.annotation.enchantment.Rarity; import org.oddlama.vane.annotation.enchantment.VaneEnchantment; @@ -23,8 +21,8 @@ import org.oddlama.vane.core.config.loot.LootTableList; import org.oddlama.vane.core.config.recipes.RecipeList; import org.oddlama.vane.core.config.recipes.ShapedRecipeDefinition; -import org.oddlama.vane.core.module.Context; import org.oddlama.vane.core.enchantments.CustomEnchantment; +import org.oddlama.vane.core.module.Context; import org.oddlama.vane.enchantments.Enchantments; @VaneEnchantment(name = "take_off", max_level = 3, rarity = Rarity.UNCOMMON, treasure = true, allow_custom = true) @@ -63,11 +61,6 @@ public LootTableList default_loot_tables() { .add(1.0 / 150, 1, 1, on("vane_enchantments:enchanted_ancient_tome_of_the_gods"))); } - @Override - public boolean can_enchant(@NotNull ItemStack item_stack) { - return item_stack.getType() == Material.ELYTRA; - } - private double get_boost_strength(int level) { if (level > 0 && level <= config_boost_strengths.size()) { return config_boost_strengths.get(level - 1); diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Unbreakable.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Unbreakable.java index df92b1c0c..7ff542440 100644 --- a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Unbreakable.java +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Unbreakable.java @@ -1,7 +1,6 @@ package org.oddlama.vane.enchantments.enchantments; import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerItemDamageEvent; @@ -13,8 +12,8 @@ import org.oddlama.vane.core.config.loot.LootTableList; import org.oddlama.vane.core.config.recipes.RecipeList; import org.oddlama.vane.core.config.recipes.ShapedRecipeDefinition; -import org.oddlama.vane.core.module.Context; import org.oddlama.vane.core.enchantments.CustomEnchantment; +import org.oddlama.vane.core.module.Context; import org.oddlama.vane.enchantments.Enchantments; @VaneEnchantment(name = "unbreakable", rarity = Rarity.RARE, treasure = true, allow_custom = true) @@ -22,8 +21,6 @@ public class Unbreakable extends CustomEnchantment { public Unbreakable(Context context) { super(context); - supersedes(Enchantment.UNBREAKING); - supersedes(Enchantment.MENDING); } @Override diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Wings.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Wings.java index 4ce930bf4..ff62d26fd 100644 --- a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Wings.java +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/Wings.java @@ -1,8 +1,8 @@ package org.oddlama.vane.enchantments.enchantments; +import static org.oddlama.vane.util.Conversions.ms_to_ticks; import static org.oddlama.vane.util.ItemUtil.damage_item; import static org.oddlama.vane.util.PlayerUtil.apply_elytra_boost; -import static org.oddlama.vane.util.Conversions.ms_to_ticks; import java.util.List; import java.util.concurrent.ThreadLocalRandom; @@ -12,10 +12,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerToggleSneakEvent; -import org.bukkit.inventory.ItemStack; import org.bukkit.loot.LootTables; import org.bukkit.util.Vector; -import org.jetbrains.annotations.NotNull; import org.oddlama.vane.annotation.config.ConfigDoubleList; import org.oddlama.vane.annotation.config.ConfigIntList; import org.oddlama.vane.annotation.enchantment.Rarity; @@ -24,8 +22,8 @@ import org.oddlama.vane.core.config.loot.LootTableList; import org.oddlama.vane.core.config.recipes.RecipeList; import org.oddlama.vane.core.config.recipes.ShapedRecipeDefinition; -import org.oddlama.vane.core.module.Context; import org.oddlama.vane.core.enchantments.CustomEnchantment; +import org.oddlama.vane.core.module.Context; import org.oddlama.vane.enchantments.Enchantments; @VaneEnchantment(name = "wings", max_level = 4, rarity = Rarity.RARE, treasure = true, allow_custom = true) @@ -76,11 +74,6 @@ public LootTableList default_loot_tables() { ); } - @Override - public boolean can_enchant(@NotNull ItemStack item_stack) { - return item_stack.getType() == Material.ELYTRA; - } - private int get_boost_cooldown(int level) { if (level > 0 && level <= config_boost_cooldowns.size()) { return config_boost_cooldowns.get(level - 1); diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/AngelRegistry.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/AngelRegistry.java new file mode 100644 index 000000000..788b14776 --- /dev/null +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/AngelRegistry.java @@ -0,0 +1,23 @@ +package org.oddlama.vane.enchantments.enchantments.registry; + +import java.util.List; + +import org.bukkit.enchantments.Enchantment; +import org.oddlama.vane.enchantments.CustomEnchantmentRegistry; + +import io.papermc.paper.registry.RegistryKey; +import io.papermc.paper.registry.TypedKey; +import io.papermc.paper.registry.data.EnchantmentRegistryEntry; +import io.papermc.paper.registry.event.RegistryFreezeEvent; +import io.papermc.paper.registry.keys.ItemTypeKeys; +import net.kyori.adventure.key.Key; + +public class AngelRegistry extends CustomEnchantmentRegistry { + + public AngelRegistry(RegistryFreezeEvent freezeEvent) { + super("angel", List.of(ItemTypeKeys.ELYTRA), 5); + this.exclusive_with(List.of(TypedKey.create(RegistryKey.ENCHANTMENT, Key.key(NAMESPACE, "wings")))) + .register(freezeEvent); + } + +} diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/GrapplingHookRegistry.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/GrapplingHookRegistry.java new file mode 100644 index 000000000..6bc773a52 --- /dev/null +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/GrapplingHookRegistry.java @@ -0,0 +1,17 @@ +package org.oddlama.vane.enchantments.enchantments.registry; + +import org.bukkit.enchantments.Enchantment; +import org.oddlama.vane.enchantments.CustomEnchantmentRegistry; + +import io.papermc.paper.registry.data.EnchantmentRegistryEntry; +import io.papermc.paper.registry.event.RegistryFreezeEvent; +import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys; + +public class GrapplingHookRegistry extends CustomEnchantmentRegistry { + + public GrapplingHookRegistry(RegistryFreezeEvent freezeEvent) { + super("grappling_hook", ItemTypeTagKeys.ENCHANTABLE_FISHING, 3); + this.register(freezeEvent); + } + +} diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/HellBentRegistry.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/HellBentRegistry.java new file mode 100644 index 000000000..4c7b64a1d --- /dev/null +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/HellBentRegistry.java @@ -0,0 +1,17 @@ +package org.oddlama.vane.enchantments.enchantments.registry; + +import org.bukkit.enchantments.Enchantment; +import org.oddlama.vane.enchantments.CustomEnchantmentRegistry; + +import io.papermc.paper.registry.data.EnchantmentRegistryEntry; +import io.papermc.paper.registry.event.RegistryFreezeEvent; +import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys; + +public class HellBentRegistry extends CustomEnchantmentRegistry{ + + public HellBentRegistry(RegistryFreezeEvent freezeEvent) { + super("hell_bent", ItemTypeTagKeys.ENCHANTABLE_HEAD_ARMOR, 1); + this.register(freezeEvent); + } + +} diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/LeafchopperRegistry.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/LeafchopperRegistry.java new file mode 100644 index 000000000..c8554c693 --- /dev/null +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/LeafchopperRegistry.java @@ -0,0 +1,15 @@ +package org.oddlama.vane.enchantments.enchantments.registry; + +import org.bukkit.enchantments.Enchantment; +import org.oddlama.vane.enchantments.CustomEnchantmentRegistry; + +import io.papermc.paper.registry.data.EnchantmentRegistryEntry; +import io.papermc.paper.registry.event.RegistryFreezeEvent; +import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys; + +public class LeafchopperRegistry extends CustomEnchantmentRegistry{ + public LeafchopperRegistry(RegistryFreezeEvent freezeEvent) { + super("leafchopper", ItemTypeTagKeys.AXES, 1); + this.register(freezeEvent); + } +} diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/LightningRegistry.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/LightningRegistry.java new file mode 100644 index 000000000..be35d6ad1 --- /dev/null +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/LightningRegistry.java @@ -0,0 +1,15 @@ +package org.oddlama.vane.enchantments.enchantments.registry; + +import org.bukkit.enchantments.Enchantment; +import org.oddlama.vane.enchantments.CustomEnchantmentRegistry; + +import io.papermc.paper.registry.data.EnchantmentRegistryEntry; +import io.papermc.paper.registry.event.RegistryFreezeEvent; +import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys; + +public class LightningRegistry extends CustomEnchantmentRegistry { + public LightningRegistry(RegistryFreezeEvent freezeEvent) { + super("lightning", ItemTypeTagKeys.ENCHANTABLE_SWORD, 1); + this.register(freezeEvent); + } +} diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/RakeRegistry.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/RakeRegistry.java new file mode 100644 index 000000000..ed213f717 --- /dev/null +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/RakeRegistry.java @@ -0,0 +1,19 @@ +package org.oddlama.vane.enchantments.enchantments.registry; + +import org.bukkit.enchantments.Enchantment; +import org.oddlama.vane.enchantments.CustomEnchantmentRegistry; + +import io.papermc.paper.registry.data.EnchantmentRegistryEntry; +import io.papermc.paper.registry.event.RegistryFreezeEvent; +import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys; + +public class RakeRegistry extends CustomEnchantmentRegistry { + + public RakeRegistry(RegistryFreezeEvent freezeEvent) { + super("rake", + ItemTypeTagKeys.HOES, + 4); + this.register(freezeEvent); + } + +} \ No newline at end of file diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/SeedingRegistry.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/SeedingRegistry.java new file mode 100644 index 000000000..43b5eaa6b --- /dev/null +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/SeedingRegistry.java @@ -0,0 +1,15 @@ +package org.oddlama.vane.enchantments.enchantments.registry; + +import org.bukkit.enchantments.Enchantment; +import org.oddlama.vane.enchantments.CustomEnchantmentRegistry; + +import io.papermc.paper.registry.data.EnchantmentRegistryEntry; +import io.papermc.paper.registry.event.RegistryFreezeEvent; +import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys; + +public class SeedingRegistry extends CustomEnchantmentRegistry { + public SeedingRegistry(RegistryFreezeEvent freezeEvent) { + super("seeding", ItemTypeTagKeys.HOES, 4); + this.register(freezeEvent); + } +} diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/SouldboundRegistry.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/SouldboundRegistry.java new file mode 100644 index 000000000..3305f8874 --- /dev/null +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/SouldboundRegistry.java @@ -0,0 +1,15 @@ +package org.oddlama.vane.enchantments.enchantments.registry; + +import org.bukkit.enchantments.Enchantment; +import org.oddlama.vane.enchantments.CustomEnchantmentRegistry; + +import io.papermc.paper.registry.data.EnchantmentRegistryEntry; +import io.papermc.paper.registry.event.RegistryFreezeEvent; +import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys; + +public class SouldboundRegistry extends CustomEnchantmentRegistry { + public SouldboundRegistry(RegistryFreezeEvent freezeEvent) { + super("soulbound", ItemTypeTagKeys.ENCHANTABLE_DURABILITY, 1); + this.register(freezeEvent); + } +} diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/TakeOffRegistry.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/TakeOffRegistry.java new file mode 100644 index 000000000..9699b730a --- /dev/null +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/TakeOffRegistry.java @@ -0,0 +1,17 @@ +package org.oddlama.vane.enchantments.enchantments.registry; + +import java.util.List; + +import org.bukkit.enchantments.Enchantment; +import org.oddlama.vane.enchantments.CustomEnchantmentRegistry; + +import io.papermc.paper.registry.data.EnchantmentRegistryEntry; +import io.papermc.paper.registry.event.RegistryFreezeEvent; +import io.papermc.paper.registry.keys.ItemTypeKeys; + +public class TakeOffRegistry extends CustomEnchantmentRegistry { + public TakeOffRegistry(RegistryFreezeEvent freezeEvent) { + super("take_off", List.of(ItemTypeKeys.ELYTRA), 3); + this.register(freezeEvent); + } +} diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/UnbreakableRegistry.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/UnbreakableRegistry.java new file mode 100644 index 000000000..dafadc4f3 --- /dev/null +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/UnbreakableRegistry.java @@ -0,0 +1,20 @@ +package org.oddlama.vane.enchantments.enchantments.registry; + +import java.util.List; + +import org.bukkit.enchantments.Enchantment; +import org.oddlama.vane.enchantments.CustomEnchantmentRegistry; + +import io.papermc.paper.registry.data.EnchantmentRegistryEntry; +import io.papermc.paper.registry.event.RegistryFreezeEvent; +import io.papermc.paper.registry.keys.EnchantmentKeys; +import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys; + +public class UnbreakableRegistry extends CustomEnchantmentRegistry { + + public UnbreakableRegistry(RegistryFreezeEvent freezeEvent) { + super("unbreakable", ItemTypeTagKeys.ENCHANTABLE_DURABILITY, 1); + this.exclusive_with(List.of(EnchantmentKeys.UNBREAKING, EnchantmentKeys.MENDING)); + this.register(freezeEvent); + } +} diff --git a/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/WingsRegistry.java b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/WingsRegistry.java new file mode 100644 index 000000000..984a37747 --- /dev/null +++ b/vane-enchantments/src/main/java/org/oddlama/vane/enchantments/enchantments/registry/WingsRegistry.java @@ -0,0 +1,20 @@ +package org.oddlama.vane.enchantments.enchantments.registry; + +import java.util.List; + +import org.bukkit.enchantments.Enchantment; +import org.oddlama.vane.enchantments.CustomEnchantmentRegistry; + +import io.papermc.paper.registry.data.EnchantmentRegistryEntry; +import io.papermc.paper.registry.event.RegistryFreezeEvent; +import io.papermc.paper.registry.keys.ItemTypeKeys; + +public class WingsRegistry extends CustomEnchantmentRegistry { + + public WingsRegistry(RegistryFreezeEvent freezeEvent) { + super("wings", List.of(ItemTypeKeys.ELYTRA), 4); + this.exclusive_with(List.of(typedKey("wings"))); + this.register(freezeEvent); + } + +} diff --git a/vane-enchantments/src/main/resources/paper-plugin.yml b/vane-enchantments/src/main/resources/paper-plugin.yml new file mode 100644 index 000000000..e02bfe68e --- /dev/null +++ b/vane-enchantments/src/main/resources/paper-plugin.yml @@ -0,0 +1,19 @@ +name: ${name} +version: ${version} +description: Enchantments module for vane + +authors: + - oddlama +website: 'https://github.com/oddlama/vane' + + +main: org.oddlama.vane.enchantments.Enchantments +bootstrapper: org.oddlama.vane.enchantments.EnchantmentsBootstrapper + +api-version: '1.21' +load: STARTUP +dependencies: + server: + vane-core: + required: true + load: BEFORE diff --git a/vane-enchantments/src/main/resources/plugin.yml b/vane-enchantments/src/main/resources/plugin.yml deleted file mode 100644 index 55c349c47..000000000 --- a/vane-enchantments/src/main/resources/plugin.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: ${name} -version: ${version} -description: Enchantments module for vane - -authors: [oddlama] -website: 'https://github.com/oddlama/vane' - -depend: [vane-core] - -main: org.oddlama.vane.enchantments.Enchantments -database: false - -api-version: 1.19 -load: STARTUP diff --git a/vane-permissions/src/main/java/org/oddlama/vane/permissions/argumentTypes/PermissionGroupArgumentType.java b/vane-permissions/src/main/java/org/oddlama/vane/permissions/argumentTypes/PermissionGroupArgumentType.java new file mode 100644 index 000000000..7c7261714 --- /dev/null +++ b/vane-permissions/src/main/java/org/oddlama/vane/permissions/argumentTypes/PermissionGroupArgumentType.java @@ -0,0 +1,53 @@ +package org.oddlama.vane.permissions.argumentTypes; + +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; + +import org.jetbrains.annotations.NotNull; + +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; + +import io.papermc.paper.command.brigadier.argument.CustomArgumentType; + +public class PermissionGroupArgumentType implements CustomArgumentType.Converted { + + Map> permission_groups; + + public static @NotNull PermissionGroupArgumentType permissionGroup(Map> permission_groups) { + return new PermissionGroupArgumentType(permission_groups); + } + + private PermissionGroupArgumentType(Map> permission_groups) { + this.permission_groups = permission_groups; + } + + @Override + public @NotNull String convert(@NotNull String nativeType) throws CommandSyntaxException { + return nativeType; + } + + @Override + public @NotNull ArgumentType getNativeType() { + return StringArgumentType.string(); + } + + @Override + public @NotNull CompletableFuture listSuggestions(@NotNull CommandContext context, + @NotNull SuggestionsBuilder builder) { + Stream stream = permission_groups.keySet().stream(); + if(!builder.getRemaining().isBlank()) { + stream = stream.filter(group -> group.contains(builder.getRemaining())); + } + stream.forEach(builder::suggest); + return builder.buildFuture(); + } + + +} diff --git a/vane-permissions/src/main/java/org/oddlama/vane/permissions/commands/Permission.java b/vane-permissions/src/main/java/org/oddlama/vane/permissions/commands/Permission.java index 800f38e7b..b0203a885 100644 --- a/vane-permissions/src/main/java/org/oddlama/vane/permissions/commands/Permission.java +++ b/vane-permissions/src/main/java/org/oddlama/vane/permissions/commands/Permission.java @@ -1,16 +1,28 @@ package org.oddlama.vane.permissions.commands; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +import static io.papermc.paper.command.brigadier.Commands.argument; +import static io.papermc.paper.command.brigadier.Commands.literal; + import java.util.Collections; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.permissions.PermissionDefault; import org.oddlama.vane.annotation.command.Aliases; import org.oddlama.vane.annotation.command.Name; import org.oddlama.vane.annotation.lang.LangMessage; import org.oddlama.vane.core.command.Command; +import org.oddlama.vane.core.command.argumentType.OfflinePlayerArgumentType; import org.oddlama.vane.core.lang.TranslatedMessage; import org.oddlama.vane.core.module.Context; import org.oddlama.vane.permissions.Permissions; +import org.oddlama.vane.permissions.argumentTypes.PermissionGroupArgumentType; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; + +import io.papermc.paper.command.brigadier.CommandSourceStack; @Name("permission") @Aliases({ "perm" }) @@ -57,55 +69,59 @@ public class Permission extends Command { public Permission(Context context) { super(context); - // Add help - params().fixed("help").ignore_case().exec(this::print_help); - - // Command parameters - var list = params().fixed("list").ignore_case(); - - // list groups - var groups = list.fixed("groups").ignore_case(); - groups.exec(this::list_groups); - groups.choose_any_player().exec(this::list_groups_for_player); - - // list permissions - var permissions = list.fixed("permissions").ignore_case(); - permissions.exec(this::list_permissions); - permissions.choose_any_player().exec(this::list_permissions_for_player); - permissions - .choice( - "permission_group", - sender -> get_module().permission_groups.keySet(), - (sender, g) -> g, - (sender, str) -> get_module().permission_groups.containsKey(str) ? str : null + } + + @Override + public LiteralArgumentBuilder get_command_base() { + return super.get_command_base() + .then(help()) + + .then(literal("list") + .then(literal("groups") + .executes(ctx -> {list_groups(ctx.getSource().getSender()); return SINGLE_SUCCESS;}) + .then(argument("offline_player", OfflinePlayerArgumentType.offlinePlayer()) + .executes(ctx -> {list_groups_for_player(sender(ctx), offline_player(ctx)); return SINGLE_SUCCESS;}) + ) + ) + .then(literal("permissions") + // FIXME weirdly autocompletion works in the console but not in game ?? + .then(argument("permission_group", PermissionGroupArgumentType.permissionGroup(get_module().permission_groups)) + .executes(ctx -> {list_permissions_for_group(ctx.getSource().getSender(), permission_group(ctx)); return SINGLE_SUCCESS;}) + ) + .then(argument("offline_player", OfflinePlayerArgumentType.offlinePlayer()) + .executes(ctx -> {list_permissions_for_player(ctx.getSource().getSender(), offline_player(ctx)); return SINGLE_SUCCESS;}) + ) + .executes(ctx -> {list_permissions(ctx.getSource().getSender()); return SINGLE_SUCCESS;}) + ) ) - .exec(this::list_permissions_for_group); - - // add a group to player - params() - .fixed("add") - .ignore_case() - .choose_any_player() - .choice( - "permission_group", - sender -> get_module().permission_groups.keySet(), - (sender, g) -> g, - (sender, str) -> get_module().permission_groups.containsKey(str) ? str : null + + .then(literal("add") + .then(argument("offline_player", OfflinePlayerArgumentType.offlinePlayer()) + .then(argument("permission_group", PermissionGroupArgumentType.permissionGroup(get_module().permission_groups)) + .executes(ctx -> {add_player_to_group(ctx.getSource().getSender(), offline_player(ctx), permission_group(ctx)); return SINGLE_SUCCESS;}) + ) + ) ) - .exec(this::add_player_to_group); - - // remove a group from player - params() - .fixed("remove") - .ignore_case() - .choose_any_player() - .choice( - "permission_group", - sender -> get_module().permission_groups.keySet(), - (sender, g) -> g, - (sender, str) -> get_module().permission_groups.containsKey(str) ? str : null + .then(literal("remove") + .then(argument("offline_player", OfflinePlayerArgumentType.offlinePlayer()) + .then(argument("permission_group", PermissionGroupArgumentType.permissionGroup(get_module().permission_groups)) + .executes(ctx -> {remove_player_from_group(ctx.getSource().getSender(), offline_player(ctx), permission_group(ctx)); return SINGLE_SUCCESS;}) + ) + ) ) - .exec(this::remove_player_from_group); + ; + } + + private String permission_group(CommandContext ctx){ + return ctx.getArgument("permission_group", String.class); + } + + private Player sender(CommandContext ctx){ + return (Player) ctx.getSource().getSender(); + } + + private OfflinePlayer offline_player(CommandContext ctx){ + return ctx.getArgument("offline_player", OfflinePlayer.class); } private String permission_default_value_color_code(PermissionDefault def) { diff --git a/vane-permissions/src/main/java/org/oddlama/vane/permissions/commands/Vouch.java b/vane-permissions/src/main/java/org/oddlama/vane/permissions/commands/Vouch.java index 87e6ebdca..8abf6e9b9 100644 --- a/vane-permissions/src/main/java/org/oddlama/vane/permissions/commands/Vouch.java +++ b/vane-permissions/src/main/java/org/oddlama/vane/permissions/commands/Vouch.java @@ -1,5 +1,8 @@ package org.oddlama.vane.permissions.commands; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +import static io.papermc.paper.command.brigadier.Commands.argument; + import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -12,10 +15,15 @@ import org.oddlama.vane.annotation.lang.LangMessage; import org.oddlama.vane.annotation.persistent.Persistent; import org.oddlama.vane.core.command.Command; +import org.oddlama.vane.core.command.argumentType.OfflinePlayerArgumentType; import org.oddlama.vane.core.lang.TranslatedMessage; import org.oddlama.vane.core.module.Context; import org.oddlama.vane.permissions.Permissions; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import io.papermc.paper.command.brigadier.CommandSourceStack; + @Name("vouch") public class Vouch extends Command { @@ -34,10 +42,15 @@ public class Vouch extends Command { public Vouch(Context context) { super(context); - // Add help - params().fixed("help").ignore_case().exec(this::print_help); - // Player vouch for player - params().choose_any_player().exec_player(this::vouch_for_player); + } + + @Override + public LiteralArgumentBuilder get_command_base() { + return super.get_command_base() + .then(help()) + .then(argument("offline_player", OfflinePlayerArgumentType.offlinePlayer()) + .executes(ctx -> {vouch_for_player((Player) ctx.getSource().getSender(), ctx.getArgument("offline_player", OfflinePlayer.class)); return SINGLE_SUCCESS;}) + ); } private void vouch_for_player(final Player sender, final OfflinePlayer vouched_player) { diff --git a/vane-permissions/src/main/resources/plugin.yml b/vane-permissions/src/main/resources/paper-plugin.yml similarity index 60% rename from vane-permissions/src/main/resources/plugin.yml rename to vane-permissions/src/main/resources/paper-plugin.yml index a8a04297f..3f9c03c00 100644 --- a/vane-permissions/src/main/resources/plugin.yml +++ b/vane-permissions/src/main/resources/paper-plugin.yml @@ -2,13 +2,16 @@ name: ${name} version: ${version} description: Permissions module for vane -authors: [oddlama] +authors: + - oddlama website: 'https://github.com/oddlama/vane' -depend: [vane-core] - main: org.oddlama.vane.permissions.Permissions -database: false -api-version: 1.19 +api-version: '1.21' load: STARTUP +dependencies: + server: + vane-core: + required: true + load: BEFORE \ No newline at end of file diff --git a/vane-portals/build.gradle.kts b/vane-portals/build.gradle.kts index a9e190a7e..9f2c929ff 100644 --- a/vane-portals/build.gradle.kts +++ b/vane-portals/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } dependencies { - compileOnly(group = "org.json", name = "json", version = "20200518") + compileOnly(group = "org.json", name = "json", version = "20240303") } tasks { diff --git a/vane-portals/src/main/java/org/oddlama/vane/portals/PortalConstructor.java b/vane-portals/src/main/java/org/oddlama/vane/portals/PortalConstructor.java index 9e0910bd0..cf7ad865a 100644 --- a/vane-portals/src/main/java/org/oddlama/vane/portals/PortalConstructor.java +++ b/vane-portals/src/main/java/org/oddlama/vane/portals/PortalConstructor.java @@ -384,7 +384,11 @@ private PortalBoundary check_construction_conditions( private PortalBlock create_portal_block(final Block block) { final PortalBlock.Type type; - final var mat = block.getType(); + var mat = block.getType(); + // treat cave air and void air as normal air + if(mat == Material.CAVE_AIR || mat == Material.VOID_AIR) { + mat = Material.AIR; + } if (mat == config_material_console) { type = PortalBlock.Type.CONSOLE; } else if (mat == config_material_boundary_1) { diff --git a/vane-portals/src/main/java/org/oddlama/vane/portals/PortalDynmapLayerDelegate.java b/vane-portals/src/main/java/org/oddlama/vane/portals/PortalDynmapLayerDelegate.java index e6f02ddb8..41385ceb3 100644 --- a/vane-portals/src/main/java/org/oddlama/vane/portals/PortalDynmapLayerDelegate.java +++ b/vane-portals/src/main/java/org/oddlama/vane/portals/PortalDynmapLayerDelegate.java @@ -3,8 +3,10 @@ import java.util.HashSet; import java.util.UUID; import java.util.logging.Level; + import org.bukkit.plugin.Plugin; -import org.dynmap.DynmapAPI; +import org.dynmap.DynmapCommonAPI; +import org.dynmap.DynmapCommonAPIListener; import org.dynmap.markers.Marker; import org.dynmap.markers.MarkerAPI; import org.dynmap.markers.MarkerIcon; @@ -15,7 +17,7 @@ public class PortalDynmapLayerDelegate { private final PortalDynmapLayer parent; - private DynmapAPI dynmap_api = null; + private DynmapCommonAPI dynmap_api = null; private MarkerAPI marker_api = null; private boolean dynmap_enabled = false; @@ -32,8 +34,17 @@ public Portals get_module() { public void on_enable(final Plugin plugin) { try { - dynmap_api = (DynmapAPI) plugin; - marker_api = dynmap_api.getMarkerAPI(); + DynmapCommonAPIListener.register(new DynmapCommonAPIListener() { + + @Override + public void apiEnabled(DynmapCommonAPI api) { + dynmap_api = api; + marker_api = dynmap_api.getMarkerAPI(); + + } + + }); + } catch (Exception e) { get_module().log.log(Level.WARNING, "Error while enabling dynmap integration!", e); return; diff --git a/vane-portals/src/main/resources/paper-plugin.yml b/vane-portals/src/main/resources/paper-plugin.yml new file mode 100644 index 000000000..a32f42f20 --- /dev/null +++ b/vane-portals/src/main/resources/paper-plugin.yml @@ -0,0 +1,22 @@ +name: ${name} +version: ${version} +description: Portals module for vane + +authors: [oddlama] +website: 'https://github.com/oddlama/vane' + +main: org.oddlama.vane.portals.Portals + +api-version: '1.21' +load: STARTUP +dependencies: + server: + vane-core: + required: true + load: BEFORE + dynmap: + required: false + load: AFTER + BlueMap: + required: false + load: AFTER \ No newline at end of file diff --git a/vane-portals/src/main/resources/plugin.yml b/vane-portals/src/main/resources/plugin.yml deleted file mode 100644 index f4713e38a..000000000 --- a/vane-portals/src/main/resources/plugin.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: ${name} -version: ${version} -description: Portals module for vane - -authors: [oddlama] -website: 'https://github.com/oddlama/vane' - -depend: [vane-core] -softdepend: [dynmap, BlueMap] - -main: org.oddlama.vane.portals.Portals -database: false - -api-version: 1.19 -load: STARTUP diff --git a/vane-proxy-core/build.gradle.kts b/vane-proxy-core/build.gradle.kts index 66c9e5d3e..f4dad10d7 100644 --- a/vane-proxy-core/build.gradle.kts +++ b/vane-proxy-core/build.gradle.kts @@ -8,8 +8,8 @@ blossom { } dependencies { - implementation(group = "com.electronwill.night-config", name = "toml", version = "3.6.4") - implementation(group = "org.slf4j", name = "slf4j-api", version = "1.7.30") + implementation(group = "com.electronwill.night-config", name = "toml", version = "3.8.0") + implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.13") implementation(rootProject.project(":vane-core")) compileOnly(group = "org.json", name = "json", version = "20200518") } diff --git a/vane-regions/build.gradle.kts b/vane-regions/build.gradle.kts index 398fc3af1..3e03e93e0 100644 --- a/vane-regions/build.gradle.kts +++ b/vane-regions/build.gradle.kts @@ -4,8 +4,8 @@ plugins { dependencies { implementation(project(":vane-portals")) - compileOnly(group = "com.github.MilkBowl", name = "VaultAPI", version = "1.7") - compileOnly(group = "org.json", name = "json", version = "20200518") + compileOnly(group = "com.github.MilkBowl", name = "VaultAPI", version = "1.7.1") + compileOnly(group = "org.json", name = "json", version = "20240303") } tasks { diff --git a/vane-regions/src/main/java/org/oddlama/vane/regions/RegionDynmapLayerDelegate.java b/vane-regions/src/main/java/org/oddlama/vane/regions/RegionDynmapLayerDelegate.java index 99be23d62..98e751ed6 100644 --- a/vane-regions/src/main/java/org/oddlama/vane/regions/RegionDynmapLayerDelegate.java +++ b/vane-regions/src/main/java/org/oddlama/vane/regions/RegionDynmapLayerDelegate.java @@ -3,8 +3,10 @@ import java.util.HashSet; import java.util.UUID; import java.util.logging.Level; + import org.bukkit.plugin.Plugin; -import org.dynmap.DynmapAPI; +import org.dynmap.DynmapCommonAPI; +import org.dynmap.DynmapCommonAPIListener; import org.dynmap.markers.Marker; import org.dynmap.markers.MarkerAPI; import org.dynmap.markers.MarkerSet; @@ -14,7 +16,7 @@ public class RegionDynmapLayerDelegate { private final RegionDynmapLayer parent; - private DynmapAPI dynmap_api = null; + private DynmapCommonAPI dynmap_api = null; private MarkerAPI marker_api = null; private boolean dynmap_enabled = false; @@ -30,8 +32,16 @@ public Regions get_module() { public void on_enable(final Plugin plugin) { try { - dynmap_api = (DynmapAPI) plugin; - marker_api = dynmap_api.getMarkerAPI(); + DynmapCommonAPIListener.register(new DynmapCommonAPIListener() { + + @Override + public void apiEnabled(DynmapCommonAPI api) { + dynmap_api = api; + marker_api = dynmap_api.getMarkerAPI(); + } + + }); + } catch (Exception e) { get_module().log.log(Level.WARNING, "Error while enabling dynmap integration!", e); return; diff --git a/vane-regions/src/main/java/org/oddlama/vane/regions/commands/Region.java b/vane-regions/src/main/java/org/oddlama/vane/regions/commands/Region.java index 301a86314..ab1018c77 100644 --- a/vane-regions/src/main/java/org/oddlama/vane/regions/commands/Region.java +++ b/vane-regions/src/main/java/org/oddlama/vane/regions/commands/Region.java @@ -1,5 +1,8 @@ package org.oddlama.vane.regions.commands; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +import static io.papermc.paper.command.brigadier.Commands.literal; + import org.bukkit.entity.Player; import org.oddlama.vane.annotation.command.Aliases; import org.oddlama.vane.annotation.command.Name; @@ -7,16 +10,24 @@ import org.oddlama.vane.core.module.Context; import org.oddlama.vane.regions.Regions; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import io.papermc.paper.command.brigadier.CommandSourceStack; + @Name("region") @Aliases({ "regions", "rg" }) public class Region extends Command { public Region(Context context) { super(context); - // Add help - params().fixed("help").ignore_case().exec(this::print_help); - // Command parameters - params().exec_player(this::open_menu); + } + + @Override + public LiteralArgumentBuilder get_command_base() { + return super.get_command_base() + .then(help()) + .requires(ctx -> ctx.getSender() instanceof Player) + .executes(ctx -> {open_menu((Player) ctx.getSource().getSender()); return SINGLE_SUCCESS;}); } private void open_menu(Player player) { diff --git a/vane-regions/src/main/resources/paper-plugin.yml b/vane-regions/src/main/resources/paper-plugin.yml new file mode 100644 index 000000000..c2defa5f1 --- /dev/null +++ b/vane-regions/src/main/resources/paper-plugin.yml @@ -0,0 +1,29 @@ +name: ${name} +version: ${version} +description: Regions module for vane + +authors: [oddlama] +website: 'https://github.com/oddlama/vane' + +main: org.oddlama.vane.regions.Regions + +api-version: '1.21' +load: STARTUP +dependencies: + server: + vane-core: + required: true + load: BEFORE + dynmap: + required: false + load: AFTER + BlueMap: + required: false + load: AFTER + vane-portals: + required: false + load: AFTER + Vault: + required: false + load: AFTER + \ No newline at end of file diff --git a/vane-regions/src/main/resources/plugin.yml b/vane-regions/src/main/resources/plugin.yml deleted file mode 100644 index d4d2e8627..000000000 --- a/vane-regions/src/main/resources/plugin.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: ${name} -version: ${version} -description: Regions module for vane - -authors: [oddlama] -website: 'https://github.com/oddlama/vane' - -depend: [vane-core] -softdepend: [dynmap, Vault, BlueMap, vane-portals] - -main: org.oddlama.vane.regions.Regions -database: false - -api-version: 1.19 -load: STARTUP diff --git a/vane-trifles/src/main/java/org/oddlama/vane/trifles/commands/Finditem.java b/vane-trifles/src/main/java/org/oddlama/vane/trifles/commands/Finditem.java index fa5073ce5..7d25f2bc7 100644 --- a/vane-trifles/src/main/java/org/oddlama/vane/trifles/commands/Finditem.java +++ b/vane-trifles/src/main/java/org/oddlama/vane/trifles/commands/Finditem.java @@ -1,24 +1,39 @@ package org.oddlama.vane.trifles.commands; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; +import static io.papermc.paper.command.brigadier.Commands.argument; + import java.util.List; import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemType; import org.bukkit.permissions.PermissionDefault; import org.oddlama.vane.annotation.command.Name; import org.oddlama.vane.core.command.Command; import org.oddlama.vane.core.module.Context; import org.oddlama.vane.trifles.Trifles; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; +import io.papermc.paper.registry.RegistryKey; + @Name("finditem") public class Finditem extends Command { public Finditem(Context context) { - // Anyone may use this by default. - super(context, PermissionDefault.TRUE); - // Add help - params().fixed("help").ignore_case().exec(this::print_help); - // Command parameters - params().choice("material", List.of(Material.values()), m -> m.getKey().toString()) - .ignore_case() - .exec_player(get_module().item_finder::find_item); + super(context, PermissionDefault.TRUE); + } + + @Override + public LiteralArgumentBuilder get_command_base() { + return super.get_command_base() + .then(help()) + .then(argument("material", ArgumentTypes.resource(RegistryKey.ITEM)) + .executes(ctx -> {get_module().item_finder.find_item((Player) ctx.getSource().getSender(), + ctx.getArgument("material", ItemType.class).asMaterial()); return SINGLE_SUCCESS;}) + ) + ; } } diff --git a/vane-trifles/src/main/java/org/oddlama/vane/trifles/commands/Heads.java b/vane-trifles/src/main/java/org/oddlama/vane/trifles/commands/Heads.java index 006852784..16417dea2 100644 --- a/vane-trifles/src/main/java/org/oddlama/vane/trifles/commands/Heads.java +++ b/vane-trifles/src/main/java/org/oddlama/vane/trifles/commands/Heads.java @@ -1,5 +1,6 @@ package org.oddlama.vane.trifles.commands; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; import static org.oddlama.vane.util.PlayerUtil.give_items; import static org.oddlama.vane.util.PlayerUtil.take_items; @@ -16,6 +17,10 @@ import org.oddlama.vane.core.module.Context; import org.oddlama.vane.trifles.Trifles; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import io.papermc.paper.command.brigadier.CommandSourceStack; + @Name("heads") public class Heads extends Command { @@ -28,10 +33,14 @@ public class Heads extends Command { public Heads(Context context) { // Anyone may use this by default. super(context, PermissionDefault.TRUE); - // Add help - params().fixed("help").ignore_case().exec(this::print_help); - // Command parameters - params().exec_player(this::open_head_library); + } + + @Override + public LiteralArgumentBuilder get_command_base() { + return super.get_command_base() + .requires(ctx -> ctx.getSender() instanceof Player) + .then(help()) + .executes(ctx -> {open_head_library((Player) ctx.getSource().getSender()); return SINGLE_SUCCESS;}); } private void open_head_library(final Player player) { diff --git a/vane-trifles/src/main/java/org/oddlama/vane/trifles/commands/Setspawn.java b/vane-trifles/src/main/java/org/oddlama/vane/trifles/commands/Setspawn.java index f0d5b46df..35e7b6de0 100644 --- a/vane-trifles/src/main/java/org/oddlama/vane/trifles/commands/Setspawn.java +++ b/vane-trifles/src/main/java/org/oddlama/vane/trifles/commands/Setspawn.java @@ -1,5 +1,8 @@ package org.oddlama.vane.trifles.commands; +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; + +import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.persistence.PersistentDataType; @@ -9,16 +12,25 @@ import org.oddlama.vane.core.module.Context; import org.oddlama.vane.util.StorageUtil; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import io.papermc.paper.command.brigadier.CommandSourceStack; + @Name("setspawn") public class Setspawn extends Command { public static final NamespacedKey IS_SPAWN_WORLD = StorageUtil.namespaced_key("vane", "is_spawn_world"); public Setspawn(Context context) { super(context); - // Add help - params().fixed("help").ignore_case().exec(this::print_help); - // Command parameters - params().exec_player(this::set_spawn); + } + + @Override + public LiteralArgumentBuilder get_command_base() { + return super.get_command_base() + .requires(ctx -> ctx.getSender() instanceof Player) + .then(help()) + .executes(ctx -> {set_spawn((Player) ctx.getSource().getSender()); return SINGLE_SUCCESS;}) + ; } private void set_spawn(Player player) { diff --git a/vane-trifles/src/main/java/org/oddlama/vane/trifles/items/DeathScroll.java b/vane-trifles/src/main/java/org/oddlama/vane/trifles/items/DeathScroll.java index 6761030cf..5ddb54758 100644 --- a/vane-trifles/src/main/java/org/oddlama/vane/trifles/items/DeathScroll.java +++ b/vane-trifles/src/main/java/org/oddlama/vane/trifles/items/DeathScroll.java @@ -81,5 +81,6 @@ public void on_player_death(final PlayerDeathEvent event) { final var pdc = event.getPlayer().getPersistentDataContainer(); StorageUtil.storage_set_location(pdc, RECENT_DEATH_LOCATION, event.getPlayer().getLocation()); pdc.set(RECENT_DEATH_TIME, PersistentDataType.LONG, System.currentTimeMillis()); + event.getPlayer().setCooldown(this.baseMaterial(), 0); } } diff --git a/vane-trifles/src/main/java/org/oddlama/vane/trifles/items/HomeScroll.java b/vane-trifles/src/main/java/org/oddlama/vane/trifles/items/HomeScroll.java index 5df07676c..e6434c78a 100644 --- a/vane-trifles/src/main/java/org/oddlama/vane/trifles/items/HomeScroll.java +++ b/vane-trifles/src/main/java/org/oddlama/vane/trifles/items/HomeScroll.java @@ -38,7 +38,7 @@ public RecipeList default_recipes() { @Override public Location teleport_location(final ItemStack scroll, Player player, boolean imminent_teleport) { - final var to_location = player.getBedSpawnLocation(); + final var to_location = player.getRespawnLocation(); if (imminent_teleport && to_location == null) { final var to_potential_location = player.getPotentialBedLocation(); if (to_potential_location != null) { diff --git a/vane-trifles/src/main/resources/plugin.yml b/vane-trifles/src/main/resources/paper-plugin.yml similarity index 58% rename from vane-trifles/src/main/resources/plugin.yml rename to vane-trifles/src/main/resources/paper-plugin.yml index f15d2248f..6b0a89a1f 100644 --- a/vane-trifles/src/main/resources/plugin.yml +++ b/vane-trifles/src/main/resources/paper-plugin.yml @@ -2,13 +2,16 @@ name: ${name} version: ${version} description: Trifles module for vane -authors: [oddlama] +authors: + - oddlama website: 'https://github.com/oddlama/vane' -depend: [vane-core] - main: org.oddlama.vane.trifles.Trifles -database: false -api-version: 1.19 +api-version: '1.21' load: STARTUP +dependencies: + server: + vane-core: + required: true + load: BEFORE \ No newline at end of file diff --git a/vane-velocity/build.gradle.kts b/vane-velocity/build.gradle.kts index e31e020df..f4932c716 100644 --- a/vane-velocity/build.gradle.kts +++ b/vane-velocity/build.gradle.kts @@ -4,11 +4,11 @@ plugins { dependencies { compileOnly(fileTree(mapOf("dir" to "external", "include" to listOf("*.jar")))) - implementation(group = "com.velocitypowered", name = "velocity-api", version = "3.1.1") - annotationProcessor(group = "com.velocitypowered", name = "velocity-api", version = "3.1.1") - implementation(group = "org.bstats", name = "bstats-velocity", version = "3.0.0") - implementation(group = "org.bstats", name = "bstats-base", version = "3.0.0") - implementation(group = "org.json", name = "json", version = "20200518") + implementation(group = "com.velocitypowered", name = "velocity-api", version = "3.3.0-SNAPSHOT") + annotationProcessor(group = "com.velocitypowered", name = "velocity-api", version = "3.3.0-SNAPSHOT") + implementation(group = "org.bstats", name = "bstats-velocity", version = "3.0.2") + implementation(group = "org.bstats", name = "bstats-base", version = "3.0.2") + implementation(group = "org.json", name = "json", version = "20240303") implementation(rootProject.project(":vane-core")) implementation(rootProject.project(":vane-proxy-core")) } diff --git a/vane-velocity/external/velocity-proxy-3.1.2-SNAPSHOT.jar b/vane-velocity/external/velocity-proxy-3.1.2-SNAPSHOT.jar deleted file mode 100644 index 6d07cbf8d..000000000 Binary files a/vane-velocity/external/velocity-proxy-3.1.2-SNAPSHOT.jar and /dev/null differ diff --git a/vane-velocity/external/velocity-proxy-3.3.0-SNAPSHOT.jar b/vane-velocity/external/velocity-proxy-3.3.0-SNAPSHOT.jar new file mode 100644 index 000000000..f20562e44 Binary files /dev/null and b/vane-velocity/external/velocity-proxy-3.3.0-SNAPSHOT.jar differ