mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2026-01-04 15:41:45 +00:00
Fixed balloons
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package io.github.fisher2911.hmccosmetics.command;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.config.CosmeticSettings;
|
||||
import io.github.fisher2911.hmccosmetics.config.Settings;
|
||||
import io.github.fisher2911.hmccosmetics.config.WardrobeSettings;
|
||||
import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager;
|
||||
@@ -42,6 +43,7 @@ public class CosmeticsCommand extends CommandBase {
|
||||
private final CosmeticsMenu cosmeticsMenu;
|
||||
private final CosmeticManager cosmeticManager;
|
||||
private final Settings settings;
|
||||
private final CosmeticSettings cosmeticSettings;
|
||||
|
||||
public CosmeticsCommand(final HMCCosmetics plugin) {
|
||||
this.plugin = plugin;
|
||||
@@ -50,19 +52,20 @@ public class CosmeticsCommand extends CommandBase {
|
||||
this.cosmeticsMenu = this.plugin.getCosmeticsMenu();
|
||||
this.cosmeticManager = this.plugin.getCosmeticManager();
|
||||
this.settings = this.plugin.getSettings();
|
||||
this.cosmeticSettings = this.settings.getCosmeticSettings();
|
||||
}
|
||||
|
||||
@Default
|
||||
@Permission(io.github.fisher2911.hmccosmetics.message.Permission.DEFAULT_COMMAND)
|
||||
public void defaultCommand(final Player player) {
|
||||
this.defaultCommand(player, CosmeticsMenu.DEFAULT_MAIN_MENU);
|
||||
this.defaultCommand(player, this.cosmeticSettings.getDefaultMenu());
|
||||
}
|
||||
|
||||
@SubCommand("menu")
|
||||
@Permission(io.github.fisher2911.hmccosmetics.message.Permission.DEFAULT_COMMAND)
|
||||
public void defaultCommand(final Player player, @Completion("#menus") @me.mattstudios.mf.annotations.Optional String menu) {
|
||||
final Optional<User> optionalUser = this.userManager.get(player.getUniqueId());
|
||||
if (menu == null) menu = CosmeticsMenu.DEFAULT_MAIN_MENU;
|
||||
if (menu == null) menu = this.cosmeticSettings.getDefaultMenu();
|
||||
if (optionalUser.isEmpty()) {
|
||||
this.cosmeticsMenu.openMenu(menu, player);
|
||||
return;
|
||||
|
||||
@@ -1,27 +1,29 @@
|
||||
package io.github.fisher2911.hmccosmetics.config;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import io.github.fisher2911.hmccosmetics.gui.CosmeticsMenu;
|
||||
import io.github.fisher2911.hmccosmetics.util.Utils;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
|
||||
@ConfigSerializable
|
||||
public class CosmeticSettings {
|
||||
|
||||
private static final transient String COSMETIC_SETTINGS_PATH = "cosmetic-settings";
|
||||
private static final transient String REQUIRE_EMPTY_HELMET_PATH = "require-empty-helmet";
|
||||
private static final transient String REQUIRE_EMPTY_OFF_HAND_PATH = "require-empty-off-hand";
|
||||
private static final transient String REQUIRE_EMPTY_CHEST_PLATE_PATH = "require-empty-chest-plate";
|
||||
private static final transient String REQUIRE_EMPTY_PANTS_PATH = "require-empty-pants";
|
||||
private static final transient String REQUIRE_EMPTY_BOOTS_PATH = "require-empty-boots";
|
||||
private static final transient String BALLOON_OFFSET = "balloon-offset";
|
||||
private static final String DEFAULT_MENU = "default-menu";
|
||||
private static final String COSMETIC_SETTINGS_PATH = "cosmetic-settings";
|
||||
private static final String REQUIRE_EMPTY_HELMET_PATH = "require-empty-helmet";
|
||||
private static final String REQUIRE_EMPTY_OFF_HAND_PATH = "require-empty-off-hand";
|
||||
private static final String REQUIRE_EMPTY_CHEST_PLATE_PATH = "require-empty-chest-plate";
|
||||
private static final String REQUIRE_EMPTY_PANTS_PATH = "require-empty-pants";
|
||||
private static final String REQUIRE_EMPTY_BOOTS_PATH = "require-empty-boots";
|
||||
private static final String BALLOON_OFFSET = "balloon-offset";
|
||||
|
||||
private static final transient String LOOK_DOWN_PITCH_PATH = "look-down-backpack-remove";
|
||||
private static final String VIEW_DISTANCE_PATH = "view-distance";
|
||||
|
||||
private String defaultMenu;
|
||||
private boolean requireEmptyHelmet;
|
||||
private boolean requireEmptyOffHand;
|
||||
private boolean requireEmptyChestPlate;
|
||||
@@ -32,6 +34,7 @@ public class CosmeticSettings {
|
||||
private Vector balloonOffset;
|
||||
|
||||
public void load(final FileConfiguration config) {
|
||||
this.defaultMenu = Utils.replaceIf(config.getString(DEFAULT_MENU), CosmeticsMenu.DEFAULT_MAIN_MENU, null, "");
|
||||
this.requireEmptyHelmet = config.getBoolean(COSMETIC_SETTINGS_PATH + "." + REQUIRE_EMPTY_HELMET_PATH);
|
||||
this.requireEmptyOffHand = config.getBoolean(COSMETIC_SETTINGS_PATH + "." + REQUIRE_EMPTY_OFF_HAND_PATH);
|
||||
this.requireEmptyChestPlate = config.getBoolean(COSMETIC_SETTINGS_PATH + "." + REQUIRE_EMPTY_CHEST_PLATE_PATH);
|
||||
@@ -104,6 +107,10 @@ public class CosmeticSettings {
|
||||
return viewDistance;
|
||||
}
|
||||
|
||||
public String getDefaultMenu() {
|
||||
return defaultMenu;
|
||||
}
|
||||
|
||||
public boolean requireEmpty(final EquipmentSlot slot) {
|
||||
return switch (slot) {
|
||||
case OFF_HAND -> this.isRequireEmptyOffHand();
|
||||
|
||||
@@ -3,9 +3,9 @@ package io.github.fisher2911.hmccosmetics.gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.config.ArmorItemSerializer;
|
||||
import io.github.fisher2911.hmccosmetics.config.CosmeticSettings;
|
||||
import io.github.fisher2911.hmccosmetics.config.DyeGuiSerializer;
|
||||
import io.github.fisher2911.hmccosmetics.config.GuiSerializer;
|
||||
import io.github.fisher2911.hmccosmetics.config.ItemSerializer;
|
||||
import io.github.fisher2911.hmccosmetics.config.TokenGuiSerializer;
|
||||
import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
@@ -21,10 +21,8 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -36,6 +34,7 @@ public class CosmeticsMenu {
|
||||
public static final String DEFAULT_TOKEN_MENU = "token-menu";
|
||||
|
||||
private final HMCCosmetics plugin;
|
||||
private final CosmeticSettings settings;
|
||||
private final CosmeticManager cosmeticManager;
|
||||
|
||||
private final Map<String, CosmeticGui> guiMap = new HashMap<>();
|
||||
@@ -44,6 +43,7 @@ public class CosmeticsMenu {
|
||||
|
||||
public CosmeticsMenu(final HMCCosmetics plugin) {
|
||||
this.plugin = plugin;
|
||||
this.settings = this.plugin.getSettings().getCosmeticSettings();
|
||||
this.cosmeticManager = this.plugin.getCosmeticManager();
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class CosmeticsMenu {
|
||||
}
|
||||
|
||||
public void openDefault(final HumanEntity humanEntity) {
|
||||
this.openMenu(DEFAULT_MAIN_MENU, humanEntity);
|
||||
this.openMenu(this.settings.getDefaultMenu(), humanEntity);
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
@@ -100,7 +100,7 @@ public class CosmeticsMenu {
|
||||
final Wardrobe wardrobe = user.getWardrobe();
|
||||
if (wardrobe.isActive()) user = wardrobe;
|
||||
|
||||
final CosmeticGui gui = this.getGui(DEFAULT_DYE_MENU);
|
||||
final CosmeticGui gui = this.getGui(this.settings.getDefaultMenu());
|
||||
|
||||
if (gui instanceof final DyeSelectorGui dyeSelectorGui) {
|
||||
dyeSelectorGui.getGui(user, type).open(player);
|
||||
@@ -126,9 +126,9 @@ public class CosmeticsMenu {
|
||||
|
||||
if (!Path.of(this.plugin.getDataFolder().getPath(),
|
||||
"menus",
|
||||
DEFAULT_MAIN_MENU + ".yml").toFile().exists()) {
|
||||
this.settings.getDefaultMenu() + ".yml").toFile().exists()) {
|
||||
this.plugin.saveResource(
|
||||
new File("menus", DEFAULT_MAIN_MENU + ".yml").getPath(),
|
||||
new File("menus", this.settings.getDefaultMenu() + ".yml").getPath(),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,14 @@ public class ModelEngineHook implements Hook {
|
||||
|
||||
private static final String ID = "model-engine";
|
||||
|
||||
public void updateModel(final BalloonEntity entity) {
|
||||
final ModeledEntity model = ModelEngineAPI.getModeledEntity(entity.getUuid());
|
||||
|
||||
if (model == null) return;
|
||||
|
||||
if (model.getEntity() instanceof final MEGEntity e) e.update(entity);
|
||||
}
|
||||
|
||||
public void spawnModel(final String id, final BalloonEntity entity) {
|
||||
this.spawnModel(id, new MEGEntity(entity));
|
||||
}
|
||||
|
||||
@@ -48,6 +48,12 @@ public class MEGEntity implements BaseEntity<MEGEntity> {
|
||||
this.alive = true;
|
||||
}
|
||||
|
||||
public void update(final BalloonEntity entity) {
|
||||
this.velocity = entity.getVelocity();
|
||||
this.location = entity.getLocation();
|
||||
this.alive = entity.isAlive();
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
@@ -72,194 +78,194 @@ public class MEGEntity implements BaseEntity<MEGEntity> {
|
||||
return entityData;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public MEGEntity getBase() {
|
||||
return this;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public boolean isOnGround() {
|
||||
return false;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return this.location.getWorld();
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public List<Entity> getNearbyEntities(final double v, final double v1, final double v2) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public int getEntityId() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public void remove() {
|
||||
this.alive = false;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public boolean isCustomNameVisible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public boolean isDead() {
|
||||
return !this.alive;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public EntityType getType() {
|
||||
return EntityType.PUFFERFISH;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public boolean isInvulnerable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public boolean hasGravity() {
|
||||
return false;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public void setGravity(final boolean flag) {
|
||||
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public double getHealth() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public double getMaxHealth() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public String getCustomName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public void setCustomName(final String s) {
|
||||
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public double getMovementSpeed() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public ItemStack getItemInMainHand() {
|
||||
return null;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public ItemStack getItemInOffHand() {
|
||||
return null;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public boolean isLivingEntity() {
|
||||
return false;
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public void addPotionEffect(final PotionEffect potion) {
|
||||
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public void removePotionEffect(final PotionEffectType potion) {
|
||||
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public void setEntitySize(final float width, final float height, final float eye) {
|
||||
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public void sendDespawnPacket(final ModeledEntity modeledEntity) {
|
||||
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public void sendSpawnPacket(final ModeledEntity modeledEntity) {
|
||||
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public double getLastX() {
|
||||
return this.location.getX();
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public double getLastY() {
|
||||
return this.location.getY();
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public double getLastZ() {
|
||||
return this.location.getZ();
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public double getWantedX() {
|
||||
return this.location.getX();
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public double getWantedY() {
|
||||
return this.location.getY();
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public double getWantedZ() {
|
||||
return this.location.getZ();
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public void saveModelList(final Map<String, ActiveModel> models) {
|
||||
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public void saveModelInfo(final ModeledEntity model) {
|
||||
|
||||
}
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public List<String> getModelList() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final EntityData entityData = new EntityData();
|
||||
|
||||
//@Override
|
||||
@Override
|
||||
public EntityData loadModelInfo() {
|
||||
return this.entityData;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ public class JoinListener implements Listener {
|
||||
final Wardrobe wardrobe = user.getWardrobe();
|
||||
|
||||
user.despawnAttached();
|
||||
user.despawnBalloon();
|
||||
|
||||
if (wardrobe.isActive()) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(
|
||||
|
||||
@@ -94,12 +94,13 @@ public abstract class BaseUser<T> {
|
||||
this.updateOutsideCosmetics(other, location, settings);
|
||||
}
|
||||
|
||||
protected void despawnBalloon() {
|
||||
public void despawnBalloon() {
|
||||
final HookManager hookManager = HookManager.getInstance();
|
||||
if (!hookManager.isEnabled(ModelEngineHook.class)) return;
|
||||
hookManager.getModelEngineHook().remove(this.balloon.getUuid());
|
||||
PacketManager.sendPacketToOnline(PacketManager.getEntityDestroyPacket(this.getBalloonId()));
|
||||
this.viewingBalloon.clear();
|
||||
this.balloon.setAlive(false);
|
||||
}
|
||||
|
||||
protected void despawnBalloon(final Player other) {
|
||||
@@ -147,6 +148,8 @@ public abstract class BaseUser<T> {
|
||||
}
|
||||
|
||||
protected void updateBalloon(final Player other, final Location location, final CosmeticSettings settings) {
|
||||
final HookManager hookManager = HookManager.getInstance();
|
||||
if (!hookManager.isEnabled(ModelEngineHook.class)) return;
|
||||
if (!this.viewingBalloon.contains(other.getUniqueId())) {
|
||||
this.spawnBalloon(other, location, settings);
|
||||
return;
|
||||
@@ -155,6 +158,7 @@ public abstract class BaseUser<T> {
|
||||
final Location previous = this.balloon.getLocation();
|
||||
this.balloon.setLocation(actual);
|
||||
this.balloon.setVelocity(actual.clone().subtract(previous.clone()).toVector());
|
||||
hookManager.getModelEngineHook().updateModel(this.balloon);
|
||||
PacketManager.sendPacket(
|
||||
other,
|
||||
PacketManager.getTeleportPacket(this.getBalloonId(), actual),
|
||||
@@ -181,15 +185,18 @@ public abstract class BaseUser<T> {
|
||||
final UUID otherUUID = other.getUniqueId();
|
||||
final boolean hasBackpack = !this.playerArmor.getItem(ArmorItem.Type.BACKPACK).isEmpty();
|
||||
if (!this.viewingArmorStand.contains(otherUUID)) {
|
||||
if (!inViewDistance || !shouldShow || !hasBackpack) {
|
||||
if (!inViewDistance || !shouldShow) {
|
||||
if (this.viewingBalloon.contains(otherUUID)) {
|
||||
this.despawnAttached(other);
|
||||
this.despawnBalloon(other);
|
||||
}
|
||||
this.despawnAttached();
|
||||
return;
|
||||
}
|
||||
this.spawnArmorStand(other, location);
|
||||
this.viewingArmorStand.add(otherUUID);
|
||||
} else if (!inViewDistance || !shouldShow || !hasBackpack) {
|
||||
if (hasBackpack) {
|
||||
this.spawnArmorStand(other, location);
|
||||
this.viewingArmorStand.add(otherUUID);
|
||||
}
|
||||
} else if (!inViewDistance || !shouldShow) {
|
||||
this.despawnAttached(other);
|
||||
if (this.viewingBalloon.contains(otherUUID)) {
|
||||
this.despawnBalloon(other);
|
||||
|
||||
@@ -182,7 +182,7 @@ public class UserManager {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public void setItem(final BaseUser user, final ArmorItem armorItem) {
|
||||
public void setItem(final BaseUser<?> user, final ArmorItem armorItem) {
|
||||
ArmorItem previous = user.getPlayerArmor().getItem(armorItem.getType());
|
||||
|
||||
final CosmeticChangeEvent event =
|
||||
@@ -190,12 +190,12 @@ public class UserManager {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
final ArmorItem.Type type = armorItem.getType();
|
||||
if (type == ArmorItem.Type.BALLOON) user.despawnBalloon();
|
||||
user.setItem(event.getCosmeticItem().getArmorItem());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
switch (armorItem.getType()) {
|
||||
case HAT, OFF_HAND, CHEST_PLATE, PANTS, BOOTS -> {
|
||||
this.updateCosmetics(user);
|
||||
}
|
||||
switch (type) {
|
||||
case HAT, OFF_HAND, CHEST_PLATE, PANTS, BOOTS -> this.updateCosmetics(user);
|
||||
case BACKPACK -> {
|
||||
if (user instanceof Wardrobe) user.updateOutsideCosmetics(settings);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,13 @@ public class Utils {
|
||||
});
|
||||
}
|
||||
|
||||
public static <T> T replaceIf(final @Nullable T original, final T replacement, final @Nullable T... checks) {
|
||||
for (final T check : checks) {
|
||||
if (original == check) return replacement;
|
||||
}
|
||||
return original;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param original Object to be checked if null
|
||||
* @param replacement Object returned if original is null
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
default-menu: main
|
||||
cosmetic-settings:
|
||||
require-empty-helmet: false
|
||||
require-empty-off-hand: true
|
||||
|
||||
Reference in New Issue
Block a user