9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-30 12:29:16 +00:00

clean: several annotation & naming changes

This commit is contained in:
Craftinators
2023-02-24 13:33:45 -05:00
parent d508ecd4c0
commit 1b7462becc
15 changed files with 74 additions and 81 deletions

View File

@@ -322,7 +322,7 @@ public class CosmeticCommand implements CommandExecutor {
}
player.sendMessage("Passengers -> " + player.getPassengers());
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getArmorstand().getLocation());
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getArmorStand().getLocation());
}
player.sendMessage("Cosmetics -> " + user.getCosmetic());
player.sendMessage("EntityId -> " + player.getEntityId());

View File

@@ -6,6 +6,8 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.lang3.EnumUtils;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.ConfigurationNode;
@@ -17,7 +19,7 @@ import java.util.logging.Level;
public class Cosmetics {
private static HashBiMap<String, Cosmetic> COSMETICS = HashBiMap.create();
private static final HashBiMap<String, Cosmetic> COSMETICS = HashBiMap.create();
public static void addCosmetic(Cosmetic cosmetic) {
COSMETICS.put(cosmetic.getId(), cosmetic);
@@ -35,10 +37,14 @@ public class Cosmetics {
return COSMETICS.get(id);
}
@Contract(pure = true)
@NotNull
public static Set<Cosmetic> values() {
return COSMETICS.values();
}
@Contract(pure = true)
@NotNull
public static Set<String> keys() {
return COSMETICS.keySet();
}
@@ -76,7 +82,7 @@ public class Cosmetics {
}
}
private static void setupCosmetics(CommentedConfigurationNode config) {
private static void setupCosmetics(@NotNull CommentedConfigurationNode config) {
for (ConfigurationNode cosmeticConfig : config.childrenMap().values()) {
try {
String id = cosmeticConfig.key().toString();

View File

@@ -29,15 +29,15 @@ public class CosmeticBackpackType extends Cosmetic {
Location loc = player.getLocation().clone().add(0, 2, 0);
if (user.isInWardrobe() || !user.isBackupSpawned()) return;
if (loc.getWorld() != user.getUserBackpackManager().getArmorstand().getWorld()) {
user.getUserBackpackManager().getArmorstand().teleport(loc);
if (loc.getWorld() != user.getUserBackpackManager().getArmorStand().getWorld()) {
user.getUserBackpackManager().getArmorStand().teleport(loc);
}
user.getUserBackpackManager().getArmorstand().teleport(loc);
user.getUserBackpackManager().getArmorStand().teleport(loc);
PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getFirstArmorstandId(), loc);
PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
user.getUserBackpackManager().getArmorstand().setRotation(loc.getYaw(), loc.getPitch());
user.getUserBackpackManager().getArmorStand().setRotation(loc.getYaw(), loc.getPitch());
user.getUserBackpackManager().showBackpack();
}

View File

@@ -16,22 +16,20 @@ public class Database {
private static Data data;
@Deprecated
private static InternalData INTERNAL_DATA = new InternalData();
private static MySQLData MYSQL_DATA = new MySQLData();
private static SQLiteData SQLITE_DATA = new SQLiteData();
private static final MySQLData MYSQL_DATA = new MySQLData();
private static final SQLiteData SQLITE_DATA = new SQLiteData();
public Database() {
String databaseType = DatabaseSettings.getDatabaseType();
data = INTERNAL_DATA; // default
if (databaseType.equalsIgnoreCase("INTERNAL")) {
data = INTERNAL_DATA;
}
if (databaseType.equalsIgnoreCase("MySQL")) {
data = MYSQL_DATA;
}
if (databaseType.equalsIgnoreCase("sqlite")) {
data = SQLITE_DATA;
}
MessagesUtil.sendDebugMessages("Database is " + data);

View File

@@ -10,6 +10,7 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
@@ -36,7 +37,7 @@ public class Data {
// Override
}
// BACKPACK=colorfulbackpack&RRGGBB,HELMET=niftyhat,BALLOON=colorfulballoon,CHESTPLATE=niftychestplate
public String steralizeData(CosmeticUser user) {
public String serializeData(@NotNull CosmeticUser user) {
String data = "";
if (user.getHidden()) {
if (shouldHiddenSave(user.getHiddenReason())) {
@@ -56,7 +57,7 @@ public class Data {
return data;
}
public Map<CosmeticSlot, Map<Cosmetic, Color>> desteralizedata(CosmeticUser user, String raw) {
public Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw) {
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = new HashMap<>();
boolean checkPermission = Settings.getForcePermissionJoin();
@@ -102,7 +103,7 @@ public class Data {
return cosmetics;
}
private boolean shouldHiddenSave(CosmeticUser.HiddenReason reason) {
private boolean shouldHiddenSave(CosmeticUser.@NotNull HiddenReason reason) {
switch (reason) {
case EMOTE, NONE -> {
return false;

View File

@@ -14,6 +14,7 @@ import org.bukkit.persistence.PersistentDataType;
import java.util.Map;
import java.util.UUID;
@Deprecated
public class InternalData extends Data {
NamespacedKey key = new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmetics");
@@ -27,7 +28,7 @@ public class InternalData extends Data {
public void save(CosmeticUser user) {
Player player = Bukkit.getPlayer(user.getUniqueId());
player.getPersistentDataContainer().set(key, PersistentDataType.STRING, steralizeData(user));
player.getPersistentDataContainer().set(key, PersistentDataType.STRING, serializeData(user));
}
@Override
@@ -38,7 +39,7 @@ public class InternalData extends Data {
if (!player.getPersistentDataContainer().has(key, PersistentDataType.STRING)) return user;
String rawData = player.getPersistentDataContainer().get(key, PersistentDataType.STRING);
Map<CosmeticSlot, Map<Cosmetic, Color>> a = desteralizedata(user, rawData);
Map<CosmeticSlot, Map<Cosmetic, Color>> a = deserializeData(user, rawData);
for (Map<Cosmetic, Color> cosmeticColors : a.values()) {
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {

View File

@@ -58,7 +58,7 @@ public class MySQLData extends Data {
try {
PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
preparedSt.setString(1, user.getUniqueId().toString());
preparedSt.setString(2, steralizeData(user));
preparedSt.setString(2, serializeData(user));
preparedSt.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
@@ -82,7 +82,7 @@ public class MySQLData extends Data {
ResultSet rs = preparedStatement.executeQuery();
if (rs.next()) {
String rawData = rs.getString("COSMETICS");
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = desteralizedata(user, rawData);
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = deserializeData(user, rawData);
for (Map<Cosmetic, Color> cosmeticColors : cosmetics.values()) {
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
@@ -160,11 +160,7 @@ public class MySQLData extends Data {
private boolean isConnectionOpen() {
try {
if (connection == null || connection.isClosed()) {
return false;
} else {
return true;
}
return connection != null && !connection.isClosed();
} catch (SQLException e) {
throw new RuntimeException(e);
}

View File

@@ -52,7 +52,7 @@ public class SQLiteData extends Data {
try {
PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
preparedSt.setString(1, user.getUniqueId().toString());
preparedSt.setString(2, steralizeData(user));
preparedSt.setString(2, serializeData(user));
preparedSt.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
@@ -76,7 +76,7 @@ public class SQLiteData extends Data {
ResultSet rs = preparedStatement.executeQuery();
if (rs.next()) {
String rawData = rs.getString("COSMETICS");
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = desteralizedata(user, rawData);
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = deserializeData(user, rawData);
for (Map<Cosmetic, Color> cosmeticColors : cosmetics.values()) {
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
@@ -114,9 +114,6 @@ public class SQLiteData extends Data {
//Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
//close Connection if still active
if (connection != null) {
//close();
}
File dataFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder(), "database.db");
@@ -151,11 +148,7 @@ public class SQLiteData extends Data {
private boolean isConnectionOpen() {
try {
if (connection == null || connection.isClosed()) {
return false;
} else {
return true;
}
return connection != null && !connection.isClosed();
} catch (SQLException e) {
throw new RuntimeException(e);
}

View File

@@ -23,7 +23,6 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Entity;
@@ -105,7 +104,7 @@ public class PlayerGameListener implements Listener {
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
user.getUserBackpackManager().hideBackpack();
user.getUserBackpackManager().getArmorstand().teleport(event.getTo());
user.getUserBackpackManager().getArmorStand().teleport(event.getTo());
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
user.updateCosmetic();

View File

@@ -401,7 +401,7 @@ public class CosmeticUser {
PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), -1, viewer);
}
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
userBackpackManager.getArmorstand().getEquipment().clear();
userBackpackManager.getArmorStand().getEquipment().clear();
}
updateCosmetic();
MessagesUtil.sendDebugMessages("HideCosmetics");
@@ -427,7 +427,7 @@ public class CosmeticUser {
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK);
ItemStack item = getUserCosmeticItem(cosmeticBackpackType);
userBackpackManager.getArmorstand().getEquipment().setHelmet(item);
userBackpackManager.getArmorStand().getEquipment().setHelmet(item);
}
updateCosmetic();
MessagesUtil.sendDebugMessages("ShowCosmetics");

View File

@@ -17,8 +17,8 @@ import java.util.logging.Level;
public class UserBackpackManager {
private boolean hideBackpack;
private ArmorStand invisibleArmorstand;
private CosmeticUser user;
private ArmorStand invisibleArmorStand;
private final CosmeticUser user;
private BackpackType backpackType;
public UserBackpackManager(CosmeticUser user) {
@@ -27,27 +27,27 @@ public class UserBackpackManager {
backpackType = BackpackType.NORMAL;
}
public int getFirstArmorstandId() {
return invisibleArmorstand.getEntityId();
public int getFirstArmorStandId() {
return invisibleArmorStand.getEntityId();
}
public ArmorStand getArmorstand() {
return invisibleArmorstand;
public ArmorStand getArmorStand() {
return invisibleArmorStand;
}
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Start");
if (this.invisibleArmorstand != null) return;
if (this.invisibleArmorStand != null) return;
this.invisibleArmorstand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType);
this.invisibleArmorStand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType);
if (cosmeticBackpackType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
return;
}
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(invisibleArmorstand);
ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(invisibleArmorStand);
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName()));
model.setCanHurt(false);
modeledEntity.addModel(model, false);
@@ -57,23 +57,23 @@ public class UserBackpackManager {
}
public void despawnBackpack() {
if (invisibleArmorstand == null) return;
invisibleArmorstand.setHealth(0);
invisibleArmorstand.remove();
this.invisibleArmorstand = null;
if (invisibleArmorStand == null) return;
invisibleArmorStand.setHealth(0);
invisibleArmorStand.remove();
this.invisibleArmorStand = null;
}
public void hideBackpack() {
if (user.getHidden() == true) return;
getArmorstand().getEquipment().clear();
if (user.getHidden()) return;
getArmorStand().getEquipment().clear();
hideBackpack = true;
}
public void showBackpack() {
if (hideBackpack == false) return;
if (!hideBackpack) return;
CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK);
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
getArmorstand().getEquipment().setHelmet(item);
getArmorStand().getEquipment().setHelmet(item);
hideBackpack = false;
}

View File

@@ -15,6 +15,7 @@ import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
import java.util.logging.Level;
@@ -26,13 +27,13 @@ public class UserBalloonManager {
private final UUID uniqueID;
private final ArmorStand modelEntity;
public UserBalloonManager(Location location) {
public UserBalloonManager(@NotNull Location location) {
this.uniqueID = UUID.randomUUID();
this.balloonID = NMSHandlers.getHandler().getNextEntityId();
this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset()));
}
public void spawnModel(CosmeticBalloonType cosmeticBalloonType, Color color) {
public void spawnModel(@NotNull CosmeticBalloonType cosmeticBalloonType, Color color) {
// redo this
if (cosmeticBalloonType.getModelName() != null && HMCCosmeticsPlugin.hasModelEngine()) {
balloonType = BalloonType.MODELENGINE;

View File

@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.jetbrains.annotations.NotNull;
public class UserEmoteManager {
@@ -13,7 +14,7 @@ public class UserEmoteManager {
this.user = user;
}
public void playEmote(CosmeticEmoteType cosmeticEmoteType) {
public void playEmote(@NotNull CosmeticEmoteType cosmeticEmoteType) {
MessagesUtil.sendDebugMessages("playEmote " + cosmeticEmoteType.getAnimationId());
playEmote(cosmeticEmoteType.getAnimationId());
}

View File

@@ -14,29 +14,27 @@ import org.bukkit.Location;
import org.bukkit.Material;
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.HashMap;
import java.util.List;
import java.util.UUID;
public class UserEmoteModel extends PlayerModel {
private CosmeticUser user;
private final CosmeticUser user;
private String emotePlaying;
private int armorstandId;
private final int armorStandId;
private GameMode originalGamemode;
public UserEmoteModel(CosmeticUser user) {
public UserEmoteModel(@NotNull CosmeticUser user) {
super(user.getPlayer());
this.user = user;
armorstandId = NMSHandlers.getHandler().getNextEntityId();
armorStandId = NMSHandlers.getHandler().getNextEntityId();
getRangeManager().setRenderDistance(Settings.getViewDistance());
}
@Override
public void playAnimation(String id) {
public void playAnimation(@NotNull String id) {
if (id.contains(":")) id = id.split(":", 2)[1];
if (!id.contains(".")) id = id + "." + id + "." + id; // Make into a format that playerAnimator works with. Requires 3 splits.
super.playAnimation(id);
@@ -63,12 +61,12 @@ public class UserEmoteModel extends PlayerModel {
originalGamemode = player.getGameMode();
PacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorstandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
PacketManager.sendInvisibilityPacket(armorstandId, viewer);
PacketManager.sendLookPacket(armorstandId, player.getLocation(), viewer);
PacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
PacketManager.sendInvisibilityPacket(armorStandId, viewer);
PacketManager.sendLookPacket(armorStandId, player.getLocation(), viewer);
PacketManager.gamemodeChangePacket(player, 3);
PacketManager.sendCameraPacket(armorstandId, viewer);
PacketManager.sendCameraPacket(armorStandId, viewer);
MessagesUtil.sendDebugMessages("playAnimation run");
}
@@ -99,7 +97,7 @@ public class UserEmoteModel extends PlayerModel {
int entityId = player.getEntityId();
PacketManager.sendCameraPacket(entityId, viewer);
PacketManager.sendEntityDestroyPacket(armorstandId, viewer);
PacketManager.sendEntityDestroyPacket(armorStandId, viewer);
if (this.originalGamemode != null) {
PacketManager.gamemodeChangePacket(player, ServerUtils.convertGamemode(this.originalGamemode));
player.setGameMode(this.originalGamemode);
@@ -113,7 +111,6 @@ public class UserEmoteModel extends PlayerModel {
}
public boolean isPlayingAnimation() {
if (emotePlaying == null) return false;
return true;
return emotePlaying != null;
}
}

View File

@@ -114,8 +114,8 @@ public class UserWardrobeManager {
// Misc
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
user.getUserBackpackManager().getArmorstand().teleport(npcLocation.clone().add(0, 2, 0));
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorstandId(), viewer);
user.getUserBackpackManager().getArmorStand().teleport(npcLocation.clone().add(0, 2, 0));
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
}
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
@@ -251,10 +251,10 @@ public class UserWardrobeManager {
}
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
PacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstArmorstandId(), location, false, viewer);
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorstandId(), viewer);
user.getUserBackpackManager().getArmorstand().setRotation(nextyaw, 0);
PacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorstandId(), outsideViewers);
PacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstArmorStandId(), location, false, viewer);
PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
user.getUserBackpackManager().getArmorStand().setRotation(nextyaw, 0);
PacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
}
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {