diff --git a/common/build.gradle.kts b/common/build.gradle.kts index c22d38c0..a3abf45e 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -38,7 +38,7 @@ dependencies { compileOnly("com.github.LoneDev6:API-ItemsAdder:2.5.4") compileOnly("net.citizensnpcs:citizens-main:2.0.29-SNAPSHOT") compileOnly("com.ticxo.modelengine:api:R2.4.1:") - implementation("net.kyori:adventure-api:4.9.3") + implementation("net.kyori:adventure-api:4.10.0") implementation ("net.kyori:adventure-text-minimessage:4.10.0-SNAPSHOT") implementation("net.kyori:adventure-platform-bukkit:4.0.1") implementation("dev.triumphteam:triumph-gui:3.1.2") @@ -73,6 +73,8 @@ tasks { dependencies { exclude(dependency("org.yaml:snakeyaml")) } + + destinationDirectory.set(file("D:\\paper-1.18.1\\plugins")) } javadoc { diff --git a/common/build/generated/plugin-yml/Bukkit/plugin.yml b/common/build/generated/plugin-yml/Bukkit/plugin.yml index 7397355e..a6404f8c 100644 --- a/common/build/generated/plugin-yml/Bukkit/plugin.yml +++ b/common/build/generated/plugin-yml/Bukkit/plugin.yml @@ -1,5 +1,5 @@ name: HMCCosmetics -version: 1.9.4 +version: 1.10.0-BETA main: io.github.fisher2911.hmccosmetics.HMCCosmetics description: | Intuitive, easy-to-use cosmetics plugin, designed for servers using resource packs. diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/HMCCosmetics.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/HMCCosmetics.java index f268cc34..43a08f56 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/HMCCosmetics.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/HMCCosmetics.java @@ -131,13 +131,29 @@ public class HMCCosmetics extends JavaPlugin { private void registerCommands() { this.commandManager = new CommandManager(this, true); final HookManager hookManager = HookManager.getInstance(); - this.commandManager.getMessageHandler().register( - "cmd.no.console", player -> + final me.mattstudios.mf.base.MessageHandler messageHandler = this.commandManager.getMessageHandler(); + messageHandler.register("cmd.no.console", player -> this.messageHandler.sendMessage( player, Messages.MUST_BE_PLAYER ) ); + messageHandler.register("cmd.no.permission", player -> + this.messageHandler.sendMessage( + player, + Messages.NO_PERMISSION + ) + ); + messageHandler.register("cmd.no.exists", player -> + this.messageHandler.sendMessage( + player, + Messages.HELP_COMMAND + )); + messageHandler.register("cmd.wrong.usage", player -> + this.messageHandler.sendMessage( + player, + Messages.HELP_COMMAND + )); final CompletionHandler completionHandler = this.commandManager.getCompletionHandler(); completionHandler.register("#types", resolver -> diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java index d92c8311..2a3268a2 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java @@ -23,7 +23,6 @@ import me.mattstudios.mf.annotations.Permission; import me.mattstudios.mf.annotations.SubCommand; import me.mattstudios.mf.base.CommandBase; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -112,9 +111,7 @@ public class CosmeticsCommand extends CommandBase { final ArmorItem armorItem = user.getPlayerArmor().getItem(type); - if (dyeColor != null) { - this.setDyeColor(dyeColor, armorItem, player); - } + this.setDyeColor(dyeColor, armorItem, player); this.userManager.setItem(user, armorItem); @@ -315,7 +312,7 @@ public class CosmeticsCommand extends CommandBase { if (npcId == null) { this.messageHandler.sendMessage( sender, - new Message("illegal-npc-id", ChatColor.RED + "Invalid NPC id specified: " + npcId) + new Message("illegal-npc-id", "" + "Invalid NPC id specified: " + npcId) ); return; } diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java index 8b8d6ebf..82dd98e8 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java @@ -9,10 +9,12 @@ import io.github.fisher2911.hmccosmetics.gui.ColorItem; import io.github.fisher2911.hmccosmetics.gui.DyeSelectorGui; import io.github.fisher2911.hmccosmetics.gui.WrappedGuiItem; import io.github.fisher2911.hmccosmetics.message.Adventure; + import java.lang.reflect.Type; import java.util.Arrays; import java.util.HashMap; import java.util.Map; + import org.bukkit.Color; import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.configurate.ConfigurationNode; @@ -118,8 +120,7 @@ public class DyeGuiSerializer implements TypeSerializer { return new DyeSelectorGui( plugin, - Adventure.SERIALIZER.serialize( - Adventure.MINI_MESSAGE.deserialize(title)), + title, rowsNode.getInt(), guiItemMap, cosmeticSlots, diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/GuiSerializer.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/GuiSerializer.java index a7d79529..a99efec2 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/GuiSerializer.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/GuiSerializer.java @@ -68,8 +68,7 @@ public class GuiSerializer implements TypeSerializer { } return new CosmeticGui(plugin, - Adventure.SERIALIZER.serialize( - Adventure.MINI_MESSAGE.deserialize(title)), + title, rowsNode.getInt(), guiItemMap); } diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.java index 2522afec..492835bb 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.java @@ -31,7 +31,6 @@ public class WardrobeSettings { private static final String YAW_PATH = "yaw"; private static final String PITCH_PATH = "pitch"; - private final HMCCosmetics plugin; private boolean disableOnDamage; diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticGui.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticGui.java index c75c6b85..39690a0d 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticGui.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/CosmeticGui.java @@ -1,6 +1,5 @@ package io.github.fisher2911.hmccosmetics.gui; -import dev.triumphteam.gui.components.GuiAction; import dev.triumphteam.gui.guis.Gui; import dev.triumphteam.gui.guis.GuiItem; import io.github.fisher2911.hmccosmetics.HMCCosmetics; @@ -12,19 +11,19 @@ import io.github.fisher2911.hmccosmetics.message.Messages; import io.github.fisher2911.hmccosmetics.message.Placeholder; import io.github.fisher2911.hmccosmetics.user.User; import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder; - -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Optional; - +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Nullable; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + public class CosmeticGui { private static final float COOL_DOWN = 0.5f; @@ -131,9 +130,9 @@ public class CosmeticGui { } public void open(final User user, final Player player) { + final Component component = Adventure.MINI_MESSAGE.deserialize(this.title); this.gui = Gui.gui(). - title(Adventure.MINI_MESSAGE.deserialize( - Placeholder.applyPapiPlaceholders(player, this.title))). + title(component). rows(this.rows). create(); diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/hook/ModelEngineHook.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/hook/ModelEngineHook.java index 894d7ec2..25533b81 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/hook/ModelEngineHook.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/hook/ModelEngineHook.java @@ -23,7 +23,6 @@ public class ModelEngineHook implements Hook { public void addPlayerToModel(final Player player, final String id, final BaseEntity entity) { final ModeledEntity model = ModelEngineAPI.getModeledEntity(entity.getUniqueId()); - if (model == null) { this.spawnModel(id, entity); return; diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/hook/entity/BalloonEntity.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/hook/entity/BalloonEntity.java index 660da36f..18dbc56c 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/hook/entity/BalloonEntity.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/hook/entity/BalloonEntity.java @@ -121,7 +121,7 @@ public class BalloonEntity implements BaseEntity { @Override public EntityType getType() { - return EntityType.PIG; + return EntityType.PUFFERFISH; } @Override diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Adventure.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Adventure.java index c783f691..681e1cee 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Adventure.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Adventure.java @@ -13,5 +13,6 @@ public class Adventure { public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().tags( StandardTags.defaults() - ).build(); + ). + build(); } diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/message/MessageHandler.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/message/MessageHandler.java index ff3af602..a990ceb2 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/message/MessageHandler.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/message/MessageHandler.java @@ -5,6 +5,7 @@ import io.github.fisher2911.hmccosmetics.util.Utils; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; +import net.kyori.adventure.title.Title; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; @@ -12,6 +13,8 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import java.io.File; +import java.time.Duration; +import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -129,22 +132,22 @@ public class MessageHandler { ); final TitleMessage titleMessage = (TitleMessage) key; Component component = Adventure.MINI_MESSAGE.deserialize(message); - player.sendTitle( - Adventure.SERIALIZER.serialize(component), - "", - titleMessage.getFadeIn() * 20, - titleMessage.getDuration() * 20, - titleMessage.getFadeOut() * 20 - ); -// this.adventure.player(player).showTitle( -// Title.title( -// component, -// Component.empty(), -// Title.Times.times( -// Duration.of(titleMessage.getFadeIn(), ChronoUnit.SECONDS), -// Duration.of(titleMessage.getDuration(), ChronoUnit.SECONDS), -// Duration.of(titleMessage.getFadeOut(), ChronoUnit.SECONDS) -// ))); +// player.sendTitle( +// Adventure.SERIALIZER.serialize(component), +// "", +// titleMessage.getFadeIn() * 20, +// titleMessage.getDuration() * 20, +// titleMessage.getFadeOut() * 20 +// ); + this.adventure.player(player).showTitle( + Title.title( + component, + Component.empty(), + Title.Times.times( + Duration.of(titleMessage.getFadeIn(), ChronoUnit.SECONDS), + Duration.of(titleMessage.getDuration(), ChronoUnit.SECONDS), + Duration.of(titleMessage.getFadeOut(), ChronoUnit.SECONDS) + ))); } /** diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Messages.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Messages.java index 4ce99b43..d563ed3d 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Messages.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/message/Messages.java @@ -1,7 +1,6 @@ package io.github.fisher2911.hmccosmetics.message; import io.github.fisher2911.hmccosmetics.gui.ArmorItem; -import org.bukkit.ChatColor; public class Messages { @@ -48,20 +47,20 @@ public class Messages { public static final Message INVALID_TYPE = new Message("invalid-type", "Invalid type"); public static final Message INVALID_USER = - new Message("invalid-user", ChatColor.RED + "That user's data cannot be found!"); + new Message("invalid-user", "That user's data cannot be found!"); public static final Message ITEM_NOT_FOUND = - new Message("item-not-found", ChatColor.RED + "That item could not be found!"); + new Message("item-not-found", "That item could not be found!"); public static final Message HOOK_NOT_ENABLED = - new Message("hook-not-enabled", ChatColor.RED + Placeholder.TYPE + " is not enabled!"); + new Message("hook-not-enabled", "" + Placeholder.TYPE + " is not enabled!"); public static final Message NPC_NOT_FOUND = - new Message("npc-not-found", ChatColor.RED + "NPC with id " + Placeholder.ID + " not found!"); + new Message("npc-not-found", "NPC with id " + Placeholder.ID + " not found!"); public static final Message SET_NPC_COSMETIC = - new Message("set-npc-cosmetic", ChatColor.GREEN + "Set " + Placeholder.TYPE + " of " + + new Message("set-npc-cosmetic", "Set " + Placeholder.TYPE + " of " + Placeholder.ID + " to " + Placeholder.ITEM); public static final Message HID_COSMETICS = - new Message("hid-cosmetics", ChatColor.GREEN + "You have hidden your cosmetics"); + new Message("hid-cosmetics", "You have hidden your cosmetics"); public static final Message SHOWN_COSMETICS = - new Message("showed-cosmetics", ChatColor.GREEN + "You have shown your cosmetics"); + new Message("showed-cosmetics", "You have shown your cosmetics"); public static final Message HELP_COMMAND = new Message("help-command", """ @@ -78,44 +77,44 @@ public class Messages { """); public static final Message OPENED_WARDROBE = - new Message("opened-wardrobe", ChatColor.GREEN + "Viewing wardrobe!"); + new Message("opened-wardrobe", "Viewing wardrobe!"); public static final Message CLOSED_WARDROBE = - new Message("closed-wardrobe", ChatColor.GREEN + "Closing wardrobe!"); + new Message("closed-wardrobe", "Closing wardrobe!"); public static final Message WARDROBE_ALREADY_OPEN = - new Message("wardrobe-already-open", ChatColor.RED + "The wardrobe is already open!"); + new Message("wardrobe-already-open", "The wardrobe is already open!"); public static final Message NOT_NEAR_WARDROBE = - new Message("not-near-wardrobe", ChatColor.RED + "You are not near the wardrobe!"); + new Message("not-near-wardrobe", "You are not near the wardrobe!"); public static final Message CANNOT_USE_PORTABLE_WARDROBE = - new Message("cannot-use-portable-wardrobe", ChatColor.RED + "You cannot use the portable wardrobe!"); + new Message("cannot-use-portable-wardrobe", "You cannot use the portable wardrobe!"); public static final Message OPENED_OTHER_WARDROBE = - new Message("opened-other-wardrobe", ChatColor.GREEN + "Opening " + Placeholder.PLAYER + "'s wardrobe."); + new Message("opened-other-wardrobe", "Opening " + Placeholder.PLAYER + "'s wardrobe."); public static final Message SET_OTHER_BACKPACK = new Message( - "set-other-backpack", ChatColor.GREEN + "You have set the backpack of " + + "set-other-backpack", "You have set the backpack of " + Placeholder.PLAYER + " to " + Placeholder.TYPE + "." ); public static final Message SET_OTHER_HAT = new Message( - "set-other-backpack", ChatColor.GREEN + "You have set the helmet of " + + "set-other-backpack", "You have set the helmet of " + Placeholder.PLAYER + " to " + Placeholder.TYPE + "." ); public static final Message SET_OTHER_OFF_HAND = new Message( - "set-other-off-hand", ChatColor.GREEN + "You have set the off hand of " + + "set-other-off-hand", "You have set the off hand of " + Placeholder.PLAYER + " to " + Placeholder.TYPE + "." ); public static final Message SET_OTHER_CHEST_PLATE = new Message( - "set-other-chest-plate", ChatColor.GREEN + "You have set the chest plate of " + + "set-other-chest-plate", "You have set the chest plate of " + Placeholder.PLAYER + " to " + Placeholder.TYPE + "." ); public static final Message SET_OTHER_PANTS = new Message( - "set-other-pants", ChatColor.GREEN + "You have set the pants of " + + "set-other-pants", "You have set the pants of " + Placeholder.PLAYER + " to " + Placeholder.TYPE + "." ); public static final Message SET_OTHER_BOOTS = new Message( - "set-other-boots", ChatColor.GREEN + "You have set the boots of " + + "set-other-boots", "You have set the boots of " + Placeholder.PLAYER + " to " + Placeholder.TYPE + "." ); public static final Message SET_OTHER_BALLOON = new Message( - "set-other-balloon", ChatColor.GREEN + "You have set the balloon of " + + "set-other-balloon", "You have set the balloon of " + Placeholder.PLAYER + " to " + Placeholder.TYPE + "." ); diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/packet/PacketManager.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/packet/PacketManager.java index bc32beff..54e0b5cc 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/packet/PacketManager.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/packet/PacketManager.java @@ -118,6 +118,16 @@ public class PacketManager { return packet; } + public static PacketContainer getMovePacket(final int entityId, final Location from, final Location to) { + final PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE); + final short x = (short) ((to.getX() * 32 - from.getX() * 32) * 128); + final short y = (short) ((to.getY() * 32 - from.getY() * 32) * 128); + final short z = (short) ((to.getZ() * 32 - from.getZ() * 32) * 128); + packet.getIntegers().write(0, entityId); + packet.getShorts().write(0, x).write(1, y).write(2, y); + return packet; + } + public static PacketContainer getLeashPacket(final int balloonId, final int entityId) { final PacketContainer packet = new PacketContainer(PacketType.Play.Server.ATTACH_ENTITY); packet.getIntegers().write(0, balloonId).write(1, entityId); diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/BaseUser.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/BaseUser.java index 8469122c..83665953 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/BaseUser.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/BaseUser.java @@ -125,19 +125,20 @@ public abstract class BaseUser { final HookManager hookManager = HookManager.getInstance(); if (id.isBlank() || !hookManager.isEnabled(ModelEngineHook.class)) return; this.balloon.setAlive(true); - this.viewingBalloon.add(other.getUniqueId()); - this.balloon.setLocation(actual); - - final ModelEngineHook hook = hookManager.getModelEngineHook(); - hook.spawnModel(id, this.balloon); - hook.addPlayerToModel(other, id, this.balloon); + if (!this.viewingBalloon.contains(other.getUniqueId())) { + this.viewingBalloon.add(other.getUniqueId()); + this.balloon.setLocation(actual); + final ModelEngineHook hook = hookManager.getModelEngineHook(); + hook.spawnModel(id, this.balloon); + hook.addPlayerToModel(other, id, this.balloon); + } this.updateBalloon(other, location, settings); PacketManager.sendPacket( other, PacketManager.getEntitySpawnPacket( actual, this.getBalloonId(), - EntityType.PIG + this.balloon.getType() ), PacketManager.getInvisibilityPacket(this.getBalloonId()), PacketManager.getLeashPacket( @@ -153,10 +154,13 @@ public abstract class BaseUser { return; } final Location actual = location.clone().add(settings.getBalloonOffset()); + final Location previous = this.balloon.getLocation(); this.balloon.setLocation(actual); + this.balloon.setVelocity(actual.clone().subtract(previous.clone()).toVector()); PacketManager.sendPacket( other, - PacketManager.getTeleportPacket(this.getBalloonId(), actual) + PacketManager.getTeleportPacket(this.getBalloonId(), actual), + PacketManager.getLeashPacket(this.getBalloonId(), this.getEntityId()) ); } diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserFactory.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserFactory.java index ff8729f5..f7425a60 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserFactory.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserFactory.java @@ -21,7 +21,7 @@ public class UserFactory { @SuppressWarnings("unchecked") @Nullable - public static T createUser( + public static > T createUser( final Class type, final Entity entity, final int armorStandId,