9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-28 19:39:14 +00:00

clean: annotation & variable modifier changes

This commit is contained in:
Craftinators
2023-02-24 17:46:39 -05:00
parent 0c7e740d7a
commit b5ae6e65a1
11 changed files with 77 additions and 44 deletions

View File

@@ -3,6 +3,8 @@ package com.hibiscusmc.hmccosmetics.util;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import org.bukkit.inventory.EquipmentSlot;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class InventoryUtils {
@@ -58,6 +60,8 @@ public class InventoryUtils {
};
}
@Contract(pure = true)
@Nullable
public static CosmeticSlot BukkitCosmeticSlot(int slot) {
switch (slot) {
case 36 -> {
@@ -81,6 +85,8 @@ public class InventoryUtils {
}
}
@Contract(pure = true)
@Nullable
public static CosmeticSlot NMSCosmeticSlot(int slot) {
switch (slot) {
case 5 -> {
@@ -104,7 +110,9 @@ public class InventoryUtils {
}
}
public static EquipmentSlot getEquipmentSlot(CosmeticSlot slot) {
@Contract(pure = true)
@Nullable
public static EquipmentSlot getEquipmentSlot(@NotNull CosmeticSlot slot) {
switch (slot) {
case HELMET -> {
return EquipmentSlot.HEAD;

View File

@@ -15,6 +15,8 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.title.Title;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.configurate.ConfigurationNode;
import java.time.Duration;
@@ -24,9 +26,9 @@ import java.util.logging.Level;
public class MessagesUtil {
private static String prefix;
private static HashMap<String, String> messages = new HashMap<>();
private static final HashMap<String, String> messages = new HashMap<>();
public static void setup(ConfigurationNode config) {
public static void setup(@NotNull ConfigurationNode config) {
prefix = config.node("prefix").getString("");
for (ConfigurationNode node : config.childrenMap().values()) {
if (node.virtual()) continue;
@@ -35,7 +37,7 @@ public class MessagesUtil {
}
}
public static void sendMessage(CosmeticUser user, String key) {
public static void sendMessage(@NotNull CosmeticUser user, String key) {
sendMessage(user.getPlayer(), key);
}
@@ -92,6 +94,7 @@ public class MessagesUtil {
return processString(player, key, null);
}
@Nullable
public static Component processString(Player player, String key, TagResolver placeholders) {
if (!messages.containsKey(key)) return null;
if (messages.get(key) == null) return null;
@@ -104,14 +107,17 @@ public class MessagesUtil {
return Adventure.MINI_MESSAGE.deserialize(message);
}
@NotNull
public static Component processStringNoKey(String message) {
return processStringNoKey(null, message, null);
}
@NotNull
public static Component processStringNoKey(Player player, String message) {
return processStringNoKey(player, message, null);
}
@NotNull
public static Component processStringNoKey(Player player, String message, TagResolver placeholders) {
message = message.replaceAll("%prefix%", prefix);
if (Hooks.isActiveHook("PlaceholderAPI") && player != null) message = PlaceholderAPI.setPlaceholders(player, message);

View File

@@ -6,12 +6,15 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class PlayerUtils {
@Nullable
public static WrappedSignedProperty getSkin(Player player) {
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
.get("textures").stream().findAny().orElse(null);
@@ -22,11 +25,13 @@ public class PlayerUtils {
return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature());
}
public static List<Player> getNearbyPlayers(Player player) {
@NotNull
public static List<Player> getNearbyPlayers(@NotNull Player player) {
return getNearbyPlayers(player.getLocation());
}
public static List<Player> getNearbyPlayers(Location location) {
@NotNull
public static List<Player> getNearbyPlayers(@NotNull Location location) {
List<Player> players = new ArrayList<>();
int viewDistance = Settings.getViewDistance();
for (Entity entity : location.getWorld().getNearbyEntities(location, viewDistance, viewDistance, viewDistance)) {

View File

@@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.jetbrains.annotations.NotNull;
public class ColorBuilder {
@@ -13,7 +14,7 @@ public class ColorBuilder {
return canBeColored(new ItemStack(material));
}
public static boolean canBeColored(final ItemStack itemStack) {
public static boolean canBeColored(final @NotNull ItemStack itemStack) {
final ItemMeta itemMeta = itemStack.getItemMeta();
return (itemMeta instanceof LeatherArmorMeta ||

View File

@@ -8,6 +8,8 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
@@ -33,7 +35,7 @@ public class ItemBuilder {
* @param itemStack builder ItemStack
*/
ItemBuilder(final ItemStack itemStack) {
ItemBuilder(final @NotNull ItemStack itemStack) {
this.material = itemStack.getType();
this.itemMeta = itemStack.hasItemMeta() ? itemStack.getItemMeta()
: Bukkit.getItemFactory().getItemMeta(this.material);
@@ -44,6 +46,8 @@ public class ItemBuilder {
* @return
*/
@Contract("_ -> new")
@NotNull
public static ItemBuilder from(final Material material) {
return new ItemBuilder(material);
}
@@ -52,7 +56,8 @@ public class ItemBuilder {
* @param itemStack builder ItemStack
* @return
*/
@Contract("_ -> new")
@NotNull
public static ItemBuilder from(final ItemStack itemStack) {
return new ItemBuilder(itemStack);
}

View File

@@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;
public class Keys {
@@ -13,7 +14,7 @@ public class Keys {
public static final NamespacedKey ITEM_KEY = new NamespacedKey(plugin, "cosmetic");
public static final NamespacedKey TOKEN_KEY = new NamespacedKey(plugin, "token-key");
public static void setKey(final ItemStack itemStack) {
public static void setKey(final @NotNull ItemStack itemStack) {
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
@@ -26,7 +27,7 @@ public class Keys {
}
public static <T, Z> void setKey(
final ItemStack itemStack,
final @NotNull ItemStack itemStack,
final NamespacedKey key,
final PersistentDataType<T, Z> type,
final Z value) {
@@ -41,7 +42,7 @@ public class Keys {
itemStack.setItemMeta(itemMeta);
}
public static boolean hasKey(final ItemStack itemStack) {
public static boolean hasKey(final @NotNull ItemStack itemStack) {
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
@@ -51,7 +52,7 @@ public class Keys {
return itemMeta.getPersistentDataContainer().has(ITEM_KEY, PersistentDataType.BYTE);
}
public static <T, Z> boolean hasKey(final ItemStack itemStack, final NamespacedKey key, final PersistentDataType<T, Z> type) {
public static <T, Z> boolean hasKey(final @NotNull ItemStack itemStack, final NamespacedKey key, final PersistentDataType<T, Z> type) {
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
@@ -62,7 +63,7 @@ public class Keys {
}
@Nullable
public static <T, Z> Z getValue(final ItemStack itemStack, final NamespacedKey key, final PersistentDataType<T, Z> type) {
public static <T, Z> Z getValue(final @NotNull ItemStack itemStack, final NamespacedKey key, final PersistentDataType<T, Z> type) {
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {

View File

@@ -1,6 +1,7 @@
package com.hibiscusmc.hmccosmetics.util.misc;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
public class StringUtils {
@@ -8,15 +9,17 @@ public class StringUtils {
* @param parsed message to be parsed
* @return MiniMessage parsed string
*/
@NotNull
public static Component parse(final String parsed) {
return Adventure.MINI_MESSAGE.deserialize(parsed);
}
@NotNull
public static String parseStringToString(final String parsed) {
return Adventure.SERIALIZER.serialize(Adventure.MINI_MESSAGE.deserialize(parsed));
}
@NotNull
public static String formatArmorItemType(String type) {
type = type.toLowerCase();
final String[] parts = type.split(" ");

View File

@@ -29,7 +29,7 @@ public class Utils {
return original;
}
public static <T> T replaceIf(final @Nullable T original, final T replacement, final Predicate<T> predicate) {
public static <T> T replaceIf(final @Nullable T original, final T replacement, final @NotNull Predicate<T> predicate) {
if (predicate.test(original)) return replacement;
return original;
}

View File

@@ -22,6 +22,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
@@ -31,11 +32,11 @@ import java.util.UUID;
public class PacketManager extends BasePacket {
public static void sendEntitySpawnPacket(
final Location location,
final @NotNull Location location,
final int entityId,
final EntityType entityType,
final UUID uuid,
final List<Player> sendTo
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
packet.getModifier().writeDefaults();
@@ -64,7 +65,7 @@ public class PacketManager extends BasePacket {
public static void ridingMountPacket(
int mountId,
int passengerId,
List<Player> sendTo
@NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
packet.getIntegers().write(0, mountId);
@@ -84,7 +85,7 @@ public class PacketManager extends BasePacket {
}
}
public static void equipmentSlotUpdate(
Player player,
@NotNull Player player,
CosmeticSlot cosmetic,
List<Player> sendTo
) {
@@ -111,7 +112,7 @@ public class PacketManager extends BasePacket {
}
public static void armorStandMetaPacket(
Entity entity,
@NotNull Entity entity,
List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
@@ -147,9 +148,9 @@ public class PacketManager extends BasePacket {
}
public static void sendLookPacket(
int entityId,
Location location,
List<Player> sendTo
int entityId,
@NotNull Location location,
@NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
packet.getIntegers().write(0, entityId);
@@ -166,10 +167,10 @@ public class PacketManager extends BasePacket {
}
public static void sendRotationPacket(
int entityId,
Location location,
boolean onGround,
List<Player> sendTo
int entityId,
@NotNull Location location,
boolean onGround,
@NotNull List<Player> sendTo
) {
float ROTATION_FACTOR = 256.0F / 360.0F;
float yaw = location.getYaw() * ROTATION_FACTOR;
@@ -188,7 +189,7 @@ public class PacketManager extends BasePacket {
int entityId,
int yaw,
boolean onGround,
List<Player> sendTo
@NotNull List<Player> sendTo
) {
float ROTATION_FACTOR = 256.0F / 360.0F;
float yaw2 = yaw * ROTATION_FACTOR;
@@ -225,7 +226,7 @@ public class PacketManager extends BasePacket {
public static void sendRidingPacket(
final int mountId,
final int passengerId,
final List<Player> sendTo
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
packet.getIntegers().write(0, mountId);
@@ -240,7 +241,7 @@ public class PacketManager extends BasePacket {
* @param entityId The entity to delete for a player
* @param sendTo The players the packet should be sent to
*/
public static void sendEntityDestroyPacket(final int entityId, List<Player> sendTo) {
public static void sendEntityDestroyPacket(final int entityId, @NotNull List<Player> sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
packet.getModifier().write(0, new IntArrayList(new int[]{entityId}));
for (final Player p : sendTo) sendPacket(p, packet);
@@ -251,7 +252,7 @@ public class PacketManager extends BasePacket {
* @param entityId The Entity ID that camera will go towards
* @param sendTo The players that will be sent this packet
*/
public static void sendCameraPacket(final int entityId, List<Player> sendTo) {
public static void sendCameraPacket(final int entityId, @NotNull List<Player> sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.CAMERA);
packet.getIntegers().write(0, entityId);
for (final Player p : sendTo) sendPacket(p, packet);
@@ -266,10 +267,10 @@ public class PacketManager extends BasePacket {
* @param sendTo Who should it send the packet to?
*/
public static void sendFakePlayerSpawnPacket(
final Location location,
final @NotNull Location location,
final UUID uuid,
final int entityId,
final List<Player> sendTo
final @NotNull List<Player> sendTo
) {
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
wrapper.setEntityID(entityId);
@@ -326,7 +327,7 @@ public class PacketManager extends BasePacket {
*/
public static void sendPlayerOverlayPacket(
final int playerId,
final List<Player> sendTo
final @NotNull List<Player> sendTo
) {
/*
0x01 = Is on fire
@@ -398,7 +399,7 @@ public class PacketManager extends BasePacket {
public static void sendLeashPacket(
final int leashedEntity,
final int entityId,
final List<Player> sendTo
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ATTACH_ENTITY);
packet.getIntegers().write(0, leashedEntity);
@@ -417,9 +418,9 @@ public class PacketManager extends BasePacket {
*/
public static void sendTeleportPacket(
final int entityId,
final Location location,
final @NotNull Location location,
boolean onGround,
final List<Player> sendTo
final @NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
packet.getIntegers().write(0, entityId);
@@ -444,10 +445,10 @@ public class PacketManager extends BasePacket {
*/
public static void sendMovePacket(
final int entityId,
final Location from,
final Location to,
final @NotNull Location from,
final @NotNull Location to,
final boolean onGround,
List<Player> sendTo
@NotNull List<Player> sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
WrapperPlayServerRelEntityMove wrapper = new WrapperPlayServerRelEntityMove(packet);
@@ -470,6 +471,7 @@ public class PacketManager extends BasePacket {
sendMovePacket(entityId, from, to, onGround, getViewers(to));
}
@NotNull
public static List<Player> getViewers(Location location) {
ArrayList<Player> viewers = new ArrayList();
if (Settings.getViewDistance() <= 0) {

View File

@@ -6,6 +6,7 @@ import com.comphenix.protocol.events.PacketEvent;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
@@ -58,7 +59,7 @@ public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket {
* @param event - the packet event.
* @return The spawned entity.
*/
public Entity getEntity(PacketEvent event) {
public Entity getEntity(@NotNull PacketEvent event) {
return getEntity(event.getPlayer().getWorld());
}
@@ -96,7 +97,7 @@ public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket {
*
* @param position - the new position.
*/
public void setPosition(Vector position) {
public void setPosition(@NotNull Vector position) {
setX(position.getX());
setY(position.getY());
setZ(position.getZ());

View File

@@ -5,6 +5,7 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
public class WrapperPlayServerRelEntityMove extends AbstractPacket {
public static final PacketType TYPE =
@@ -55,7 +56,7 @@ public class WrapperPlayServerRelEntityMove extends AbstractPacket {
* @param event - the packet event.
* @return The spawned entity.
*/
public Entity getEntity(PacketEvent event) {
public Entity getEntity(@NotNull PacketEvent event) {
return getEntity(event.getPlayer().getWorld());
}