mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2026-01-03 14:22:14 +00:00
clean: several annotation & naming changes
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(), () -> {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user