9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-31 04:46:42 +00:00

Fixed balloon movement

This commit is contained in:
Fisher2911
2022-03-05 17:45:26 -05:00
parent 4e21945bbb
commit 8b345bc56c
16 changed files with 102 additions and 73 deletions

View File

@@ -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 ->

View File

@@ -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", "<red>" + "Invalid NPC id specified: " + npcId)
);
return;
}

View File

@@ -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<DyeSelectorGui> {
return new DyeSelectorGui(
plugin,
Adventure.SERIALIZER.serialize(
Adventure.MINI_MESSAGE.deserialize(title)),
title,
rowsNode.getInt(),
guiItemMap,
cosmeticSlots,

View File

@@ -68,8 +68,7 @@ public class GuiSerializer implements TypeSerializer<CosmeticGui> {
}
return new CosmeticGui(plugin,
Adventure.SERIALIZER.serialize(
Adventure.MINI_MESSAGE.deserialize(title)),
title,
rowsNode.getInt(),
guiItemMap);
}

View File

@@ -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;

View File

@@ -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();

View File

@@ -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;

View File

@@ -121,7 +121,7 @@ public class BalloonEntity implements BaseEntity<BalloonEntity> {
@Override
public EntityType getType() {
return EntityType.PIG;
return EntityType.PUFFERFISH;
}
@Override

View File

@@ -13,5 +13,6 @@ public class Adventure {
public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().tags(
StandardTags.defaults()
).build();
).
build();
}

View File

@@ -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)
)));
}
/**

View File

@@ -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", "<red>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", "<red>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", "<red>" + 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", "<red>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", "<green>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", "<green>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", "<green>You have shown your cosmetics");
public static final Message HELP_COMMAND =
new Message("help-command",
"""
@@ -78,44 +77,44 @@ public class Messages {
<st> </st>""");
public static final Message OPENED_WARDROBE =
new Message("opened-wardrobe", ChatColor.GREEN + "Viewing wardrobe!");
new Message("opened-wardrobe", "<green>Viewing wardrobe!");
public static final Message CLOSED_WARDROBE =
new Message("closed-wardrobe", ChatColor.GREEN + "Closing wardrobe!");
new Message("closed-wardrobe", "<green>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", "<red>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", "<red>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", "<red>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", "<green>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", "<green>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", "<green>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", "<green>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", "<green>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", "<green>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", "<green>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", "<green>You have set the balloon of " +
Placeholder.PLAYER + " to " + Placeholder.TYPE + "."
);

View File

@@ -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);

View File

@@ -125,19 +125,20 @@ public abstract class BaseUser<T> {
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<T> {
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())
);
}

View File

@@ -21,7 +21,7 @@ public class UserFactory {
@SuppressWarnings("unchecked")
@Nullable
public static <T extends BaseUser> T createUser(
public static <T extends BaseUser<?>> T createUser(
final Class<T> type,
final Entity entity,
final int armorStandId,