diff --git a/build.gradle.kts b/build.gradle.kts index 1154352d..3ed3dc1e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "io.github.fisher2911" -version = "1.6.1" +version = "1.6.2" description = "The ultimate cosmetic plugin for your server." repositories { diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java b/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java index 6c35e5b0..940986da 100644 --- a/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java +++ b/src/main/java/io/github/fisher2911/hmccosmetics/command/CosmeticsCommand.java @@ -180,12 +180,8 @@ public class CosmeticsCommand extends CommandBase { Placeholder.TYPE, "none") ); } catch (final IllegalArgumentException exception) { - this.messageHandler.sendMessage( - player, - Messages.INVALID_TYPE); + this.messageHandler.sendMessage(player, Messages.INVALID_TYPE); } - - } } diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/config/CosmeticSettings.java b/src/main/java/io/github/fisher2911/hmccosmetics/config/CosmeticSettings.java index 9fd1f8bd..95c3d403 100644 --- a/src/main/java/io/github/fisher2911/hmccosmetics/config/CosmeticSettings.java +++ b/src/main/java/io/github/fisher2911/hmccosmetics/config/CosmeticSettings.java @@ -1,8 +1,10 @@ package io.github.fisher2911.hmccosmetics.config; +import io.github.fisher2911.hmccosmetics.HMCCosmetics; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.inventory.EquipmentSlot; import org.spongepowered.configurate.objectmapping.ConfigSerializable; +import org.spongepowered.configurate.objectmapping.meta.Setting; @ConfigSerializable public class CosmeticSettings { @@ -10,29 +12,34 @@ 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 LOOK_DOWN_PITCH_PATH = "look-down-backpack-remove"; private boolean requireEmptyHelmet; private boolean requireEmptyOffHand; + private int lookDownPitch; public void load(final FileConfiguration config) { - this.requireEmptyHelmet = config.getBoolean( - COSMETIC_SETTINGS_PATH + "." + REQUIRE_EMPTY_HELMET_PATH); - this.requireEmptyOffHand = config.getBoolean( - COSMETIC_SETTINGS_PATH + "." + REQUIRE_EMPTY_OFF_HAND_PATH); + this.requireEmptyHelmet = config.getBoolean(COSMETIC_SETTINGS_PATH + "." + REQUIRE_EMPTY_HELMET_PATH); + this.requireEmptyOffHand = config.getBoolean(COSMETIC_SETTINGS_PATH + "." + REQUIRE_EMPTY_OFF_HAND_PATH); + this.lookDownPitch = config.getInt(COSMETIC_SETTINGS_PATH + "." + LOOK_DOWN_PITCH_PATH); } public boolean isRequireEmptyHelmet() { return requireEmptyHelmet; } - public void setRequireEmptyHelmet(final boolean requireEmptyHelmet) { - this.requireEmptyHelmet = requireEmptyHelmet; - } - public boolean isRequireEmptyOffHand() { return requireEmptyOffHand; } + public int getLookDownPitch() { + return lookDownPitch; + } + + public void setRequireEmptyHelmet(final boolean requireEmptyHelmet) { + this.requireEmptyHelmet = requireEmptyHelmet; + } + public void setRequireEmptyOffHand(final boolean requireEmptyOffHand) { this.requireEmptyOffHand = requireEmptyOffHand; } @@ -44,5 +51,4 @@ public class CosmeticSettings { default -> false; }; } - } diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java b/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java index fd42c790..78a2c28f 100644 --- a/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java +++ b/src/main/java/io/github/fisher2911/hmccosmetics/config/DyeGuiSerializer.java @@ -125,8 +125,7 @@ public class DyeGuiSerializer implements TypeSerializer { } @Override - public void serialize(final Type type, @Nullable final DyeSelectorGui obj, - final ConfigurationNode node) throws SerializationException { + public void serialize(final Type type, @Nullable final DyeSelectorGui obj, final ConfigurationNode node) throws SerializationException { } diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/config/GuiSerializer.java b/src/main/java/io/github/fisher2911/hmccosmetics/config/GuiSerializer.java index 0c10c5bc..a7d79529 100644 --- a/src/main/java/io/github/fisher2911/hmccosmetics/config/GuiSerializer.java +++ b/src/main/java/io/github/fisher2911/hmccosmetics/config/GuiSerializer.java @@ -75,8 +75,7 @@ public class GuiSerializer implements TypeSerializer { } @Override - public void serialize(final Type type, @Nullable final CosmeticGui obj, - final ConfigurationNode node) throws SerializationException { + public void serialize(final Type type, @Nullable final CosmeticGui obj, final ConfigurationNode node) throws SerializationException { } diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/config/ItemSerializer.java b/src/main/java/io/github/fisher2911/hmccosmetics/config/ItemSerializer.java index 18875f57..58f40e67 100644 --- a/src/main/java/io/github/fisher2911/hmccosmetics/config/ItemSerializer.java +++ b/src/main/java/io/github/fisher2911/hmccosmetics/config/ItemSerializer.java @@ -246,8 +246,7 @@ public class ItemSerializer implements TypeSerializer { } @Override - public void serialize(final Type type, @Nullable final GuiItem obj, - final ConfigurationNode node) throws SerializationException { + public void serialize(final Type type, @Nullable final GuiItem obj, final ConfigurationNode node) throws SerializationException { } diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/database/DatabaseType.java b/src/main/java/io/github/fisher2911/hmccosmetics/database/DatabaseType.java index 1e91aeb0..5a1035d9 100644 --- a/src/main/java/io/github/fisher2911/hmccosmetics/database/DatabaseType.java +++ b/src/main/java/io/github/fisher2911/hmccosmetics/database/DatabaseType.java @@ -3,7 +3,6 @@ package io.github.fisher2911.hmccosmetics.database; public enum DatabaseType { MYSQL, - SQLITE } diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/gui/ArmorItem.java b/src/main/java/io/github/fisher2911/hmccosmetics/gui/ArmorItem.java index 7300d5e0..41852ab0 100644 --- a/src/main/java/io/github/fisher2911/hmccosmetics/gui/ArmorItem.java +++ b/src/main/java/io/github/fisher2911/hmccosmetics/gui/ArmorItem.java @@ -265,9 +265,7 @@ public class ArmorItem extends GuiItem { public enum Type { HAT, - BACKPACK, - OFF_HAND } diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/message/Message.java b/src/main/java/io/github/fisher2911/hmccosmetics/message/Message.java index d5f149b8..b013d1cc 100644 --- a/src/main/java/io/github/fisher2911/hmccosmetics/message/Message.java +++ b/src/main/java/io/github/fisher2911/hmccosmetics/message/Message.java @@ -52,9 +52,7 @@ public class Message { public enum Type { MESSAGE, - ACTION_BAR, - TITLE } diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java b/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java index 52bb6fbc..deaae76b 100644 --- a/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java +++ b/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java @@ -6,26 +6,31 @@ import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.Pair; import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer; +import io.github.fisher2911.hmccosmetics.config.Settings; import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; import io.github.fisher2911.hmccosmetics.packet.PacketManager; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + public class User { private final UUID uuid; private final PlayerArmor playerArmor; - private final int armorStandId; + private ArmorItem lastSetItem = ArmorItem.empty(ArmorItem.Type.HAT); + private boolean hasArmorStand; + private final int armorStandId; public User(final UUID uuid, final PlayerArmor playerArmor, final int armorStandId) { this.uuid = uuid; @@ -73,22 +78,18 @@ public class User { public void spawnArmorStand(final Player other) { final Player player = this.getPlayer(); - if (player == null) { - return; - } + if (player == null) return; final Location location = player.getLocation(); - final PacketContainer packet = PacketManager.getEntitySpawnPacket(location, - this.armorStandId, - EntityType.ARMOR_STAND); + final PacketContainer packet = PacketManager.getEntitySpawnPacket(location, this.armorStandId, EntityType.ARMOR_STAND); PacketManager.sendPacket(other, packet); } - public void spawnArmorStand() { + public void spawnArmorStand(final Settings settings) { if (this.hasArmorStand) { - this.updateArmorStand(); + this.updateArmorStand(settings); return; } @@ -99,17 +100,14 @@ public class User { this.hasArmorStand = true; } - public void updateArmorStand() { + public void updateArmorStand(final Settings settings) { if (!this.hasArmorStand) { - this.spawnArmorStand(); -// return; + this.spawnArmorStand(settings); } final Player player = this.getPlayer(); - if (player == null) { - return; - } + if (player == null) return; final List> equipmentList = new ArrayList<>(); equipmentList.add(new Pair<>(EnumWrappers.ItemSlot.HEAD, @@ -118,29 +116,38 @@ public class User { final Location location = player.getLocation(); - final PacketContainer armorPacket = PacketManager.getEquipmentPacket(equipmentList, - this.armorStandId); - final PacketContainer rotationPacket = PacketManager.getRotationPacket(this.armorStandId, - location); - final PacketContainer ridingPacket = PacketManager.getRidingPacket(player.getEntityId(), - this.armorStandId); + final PacketContainer armorPacket = PacketManager.getEquipmentPacket(equipmentList, this.armorStandId); + final PacketContainer rotationPacket = PacketManager.getRotationPacket(this.armorStandId, location); + final PacketContainer ridingPacket = PacketManager.getRidingPacket(player.getEntityId(), this.armorStandId); - final PacketContainer metaContainer = new PacketContainer( - PacketType.Play.Server.ENTITY_METADATA); + final PacketContainer metaContainer = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); WrappedDataWatcher metaData = new WrappedDataWatcher(); final Serializer byteSerializer = WrappedDataWatcher.Registry.get(Byte.class); - metaData.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, byteSerializer), - (byte) (0x20)); - metaData.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, byteSerializer), - (byte) (0x10)); + metaData.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, byteSerializer), (byte) (0x20)); + metaData.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, byteSerializer), (byte) (0x10)); metaContainer.getIntegers().write(0, this.armorStandId); metaContainer.getWatchableCollectionModifier().write(0, metaData.getWatchableObjects()); PacketManager.sendPacketToOnline(armorPacket, metaContainer, rotationPacket, ridingPacket); + + final int lookDownPitch = settings.getCosmeticSettings().getLookDownPitch(); + + if (lookDownPitch != -1 && + this.isFacingDown(location, lookDownPitch)) { + equipmentList.set(0, new Pair<>(EnumWrappers.ItemSlot.HEAD, + new ItemStack(Material.AIR) + )); + + PacketManager.sendPacket(player, PacketManager.getEquipmentPacket(equipmentList, this.armorStandId)); + } + } + + private boolean isFacingDown(final Location location, final int pitchLimit) { + return location.getPitch() > pitchLimit; } public void despawnAttached() { @@ -155,5 +162,4 @@ public class User { public ArmorItem getLastSetItem() { return lastSetItem; } - } diff --git a/src/main/java/io/github/fisher2911/hmccosmetics/user/UserManager.java b/src/main/java/io/github/fisher2911/hmccosmetics/user/UserManager.java index 7056f630..98103ee8 100644 --- a/src/main/java/io/github/fisher2911/hmccosmetics/user/UserManager.java +++ b/src/main/java/io/github/fisher2911/hmccosmetics/user/UserManager.java @@ -89,7 +89,7 @@ public class UserManager { this.plugin, () -> { for (final User user : this.userMap.values()) { - user.updateArmorStand(); + user.updateArmorStand(this.plugin.getSettings()); } }, 1, @@ -227,9 +227,7 @@ public class UserManager { final Message removeMessage, final Message setMessage) { final Player player = user.getPlayer(); - final ArmorItem.Type type = armorItem.getType(); - final ArmorItem empty = ArmorItem.empty(type); if (player == null) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ffa639b5..dfedb3fd 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,3 +1,6 @@ cosmetic-settings: require-empty-helmet: false - require-empty-off-hand: true \ No newline at end of file + require-empty-off-hand: true + # The pitch the player must look down for the backpack to be removed + # Set to -1 for no removal + look-down-backpack-remove: 70 \ No newline at end of file