mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-28 19:39:14 +00:00
gradle kotlin = best
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -125,8 +125,7 @@ public class DyeGuiSerializer implements TypeSerializer<DyeSelectorGui> {
|
||||
}
|
||||
|
||||
@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 {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +75,7 @@ public class GuiSerializer implements TypeSerializer<CosmeticGui> {
|
||||
}
|
||||
|
||||
@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 {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -246,8 +246,7 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
}
|
||||
|
||||
@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 {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package io.github.fisher2911.hmccosmetics.database;
|
||||
public enum DatabaseType {
|
||||
|
||||
MYSQL,
|
||||
|
||||
SQLITE
|
||||
|
||||
}
|
||||
|
||||
@@ -265,9 +265,7 @@ public class ArmorItem extends GuiItem {
|
||||
public enum Type {
|
||||
|
||||
HAT,
|
||||
|
||||
BACKPACK,
|
||||
|
||||
OFF_HAND
|
||||
|
||||
}
|
||||
|
||||
@@ -52,9 +52,7 @@ public class Message {
|
||||
public enum Type {
|
||||
|
||||
MESSAGE,
|
||||
|
||||
ACTION_BAR,
|
||||
|
||||
TITLE
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Pair<EnumWrappers.ItemSlot, ItemStack>> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user