9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2026-01-04 15:31:47 +00:00
This commit is contained in:
Xiao-MoMi
2022-11-12 12:56:37 +08:00
parent e06034e17d
commit 11892e58ca
13 changed files with 99 additions and 60 deletions

View File

@@ -4,7 +4,7 @@ plugins {
}
group = 'net.momirealms'
version = '2.1.2'
version = '2.1.3'
repositories {
mavenCentral()

View File

@@ -5,6 +5,7 @@ import net.momirealms.customnameplates.commands.AbstractSubCommand;
import net.momirealms.customnameplates.commands.SubCommand;
import net.momirealms.customnameplates.manager.MessageManager;
import net.momirealms.customnameplates.utils.AdventureUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -39,9 +40,13 @@ public class BubblesEquipCommand extends AbstractSubCommand {
AdventureUtil.playerMessage((Player) sender, MessageManager.prefix + MessageManager.bb_notAvailable);
return true;
}
CustomNameplates.plugin.getDataManager().getPlayerData(player).setBubbles(args.get(0));
CustomNameplates.plugin.getDataManager().saveData(player);
AdventureUtil.playerMessage((Player) sender, MessageManager.prefix + MessageManager.bb_equip.replace("{Bubble}", CustomNameplates.plugin.getResourceManager().getBubbleConfig(args.get(0)).name()));
Bukkit.getScheduler().runTaskAsynchronously(CustomNameplates.plugin, () -> {
CustomNameplates.plugin.getDataManager().getPlayerData(player).setBubbles(args.get(0));
CustomNameplates.plugin.getDataManager().saveData(player);
AdventureUtil.playerMessage((Player) sender, MessageManager.prefix + MessageManager.bb_equip.replace("{Bubble}", CustomNameplates.plugin.getResourceManager().getBubbleConfig(args.get(0)).name()));
});
return true;
}

View File

@@ -40,10 +40,14 @@ public class BubblesForceEquipCommand extends AbstractSubCommand {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.bb_not_exist);
return true;
}
CustomNameplates.plugin.getDataManager().getPlayerData(player).setBubbles(args.get(0));
CustomNameplates.plugin.getDataManager().saveData(player);
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.bb_force_equip.replace("{Bubble}", CustomNameplates.plugin.getResourceManager().getBubbleConfig(args.get(1)).name()).replace("{Player}", args.get(0)));
Bukkit.getScheduler().runTaskAsynchronously(CustomNameplates.plugin, () -> {
CustomNameplates.plugin.getDataManager().getPlayerData(player).setBubbles(args.get(0));
CustomNameplates.plugin.getDataManager().saveData(player);
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.bb_force_equip.replace("{Bubble}", CustomNameplates.plugin.getResourceManager().getBubbleConfig(args.get(1)).name()).replace("{Player}", args.get(0)));
});
return true;
}

View File

@@ -40,9 +40,12 @@ public class BubblesForceUnequipCommand extends AbstractSubCommand {
return true;
}
CustomNameplates.plugin.getDataManager().getPlayerData(player).setBubbles("none");
CustomNameplates.plugin.getDataManager().saveData(player);
AdventureUtil.sendMessage(sender,MessageManager.prefix + MessageManager.bb_force_unEquip.replace("{Player}", args.get(0)));
Bukkit.getScheduler().runTaskAsynchronously(CustomNameplates.plugin, () -> {
CustomNameplates.plugin.getDataManager().getPlayerData(player).setBubbles("none");
CustomNameplates.plugin.getDataManager().saveData(player);
AdventureUtil.sendMessage(sender,MessageManager.prefix + MessageManager.bb_force_unEquip.replace("{Player}", args.get(0)));
});
return true;
}

View File

@@ -5,6 +5,7 @@ import net.momirealms.customnameplates.commands.AbstractSubCommand;
import net.momirealms.customnameplates.commands.SubCommand;
import net.momirealms.customnameplates.manager.MessageManager;
import net.momirealms.customnameplates.utils.AdventureUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -30,9 +31,12 @@ public class BubblesUnequipCommand extends AbstractSubCommand {
return true;
}
CustomNameplates.plugin.getDataManager().getPlayerData(player).setBubbles("none");
CustomNameplates.plugin.getDataManager().saveData(player);
AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.bb_unEquip);
Bukkit.getScheduler().runTaskAsynchronously(CustomNameplates.plugin, () -> {
CustomNameplates.plugin.getDataManager().getPlayerData(player).setBubbles("none");
CustomNameplates.plugin.getDataManager().saveData(player);
AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.bb_unEquip);
});
return true;
}
}

View File

@@ -6,6 +6,7 @@ import net.momirealms.customnameplates.commands.SubCommand;
import net.momirealms.customnameplates.manager.MessageManager;
import net.momirealms.customnameplates.objects.nameplates.NameplatesTeam;
import net.momirealms.customnameplates.utils.AdventureUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -37,12 +38,16 @@ public class NameplatesEquipCommand extends AbstractSubCommand {
AdventureUtil.playerMessage((Player) sender, MessageManager.prefix + MessageManager.np_not_exist);
return true;
}
CustomNameplates.plugin.getDataManager().getPlayerData(player).equipNameplate(args.get(0));
CustomNameplates.plugin.getDataManager().saveData(player);
NameplatesTeam nameplatesTeam = CustomNameplates.plugin.getNameplateManager().getTeamManager().getNameplatesTeam(player);
if (nameplatesTeam != null) nameplatesTeam.updateNameplates();
CustomNameplates.plugin.getNameplateManager().getTeamManager().sendUpdateToAll(player, true);
AdventureUtil.playerMessage((Player) sender, MessageManager.prefix + MessageManager.np_equip.replace("{Nameplate}", CustomNameplates.plugin.getResourceManager().getNameplateConfig(args.get(0)).name()));
Bukkit.getScheduler().runTaskAsynchronously(CustomNameplates.plugin, () -> {
CustomNameplates.plugin.getDataManager().getPlayerData(player).equipNameplate(args.get(0));
CustomNameplates.plugin.getDataManager().saveData(player);
NameplatesTeam nameplatesTeam = CustomNameplates.plugin.getNameplateManager().getTeamManager().getNameplatesTeam(player);
if (nameplatesTeam != null) nameplatesTeam.updateNameplates();
CustomNameplates.plugin.getNameplateManager().getTeamManager().sendUpdateToAll(player, true);
AdventureUtil.playerMessage((Player) sender, MessageManager.prefix + MessageManager.np_equip.replace("{Nameplate}", CustomNameplates.plugin.getResourceManager().getNameplateConfig(args.get(0)).name()));
});
}
else {
AdventureUtil.playerMessage((Player) sender, MessageManager.prefix + MessageManager.np_notAvailable);

View File

@@ -43,14 +43,17 @@ public class NameplatesForceEquipCommand extends AbstractSubCommand {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.np_not_exist);
return true;
}
CustomNameplates.plugin.getDataManager().getPlayerData(player).equipNameplate(args.get(1));
CustomNameplates.plugin.getDataManager().saveData(player);
NameplatesTeam nameplatesTeam = CustomNameplates.plugin.getNameplateManager().getTeamManager().getNameplatesTeam(player);
if (nameplatesTeam != null) nameplatesTeam.updateNameplates();
CustomNameplates.plugin.getNameplateManager().getTeamManager().sendUpdateToAll(player, true);
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.np_force_equip.replace("{Nameplate}", CustomNameplates.plugin.getResourceManager().getNameplateConfig(args.get(1)).name()).replace("{Player}", args.get(0)));
return super.onCommand(sender, args);
Bukkit.getScheduler().runTaskAsynchronously(CustomNameplates.plugin, () -> {
CustomNameplates.plugin.getDataManager().getPlayerData(player).equipNameplate(args.get(1));
CustomNameplates.plugin.getDataManager().saveData(player);
NameplatesTeam nameplatesTeam = CustomNameplates.plugin.getNameplateManager().getTeamManager().getNameplatesTeam(player);
if (nameplatesTeam != null) nameplatesTeam.updateNameplates();
CustomNameplates.plugin.getNameplateManager().getTeamManager().sendUpdateToAll(player, true);
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.np_force_equip.replace("{Nameplate}", CustomNameplates.plugin.getResourceManager().getNameplateConfig(args.get(1)).name()).replace("{Player}", args.get(0)));
});
return true;
}
@Override

View File

@@ -1,5 +1,6 @@
package net.momirealms.customnameplates.commands.subcmd;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.commands.AbstractSubCommand;
import net.momirealms.customnameplates.commands.SubCommand;
import net.momirealms.customnameplates.manager.MessageManager;
@@ -37,8 +38,12 @@ public class NameplatesForceUnequipCommand extends AbstractSubCommand {
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.not_online.replace("{Player}",args.get(0)));
return true;
}
super.unequipNameplate(player);
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.np_force_unEquip.replace("{Player}", args.get(0)));
Bukkit.getScheduler().runTaskAsynchronously(CustomNameplates.plugin, () -> {
super.unequipNameplate(player);
AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.np_force_unEquip.replace("{Player}", args.get(0)));
});
return true;
}

View File

@@ -1,9 +1,11 @@
package net.momirealms.customnameplates.commands.subcmd;
import net.momirealms.customnameplates.CustomNameplates;
import net.momirealms.customnameplates.commands.AbstractSubCommand;
import net.momirealms.customnameplates.commands.SubCommand;
import net.momirealms.customnameplates.manager.MessageManager;
import net.momirealms.customnameplates.utils.AdventureUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -30,8 +32,10 @@ public class NameplatesUnequipCommand extends AbstractSubCommand {
return true;
}
super.unequipNameplate(player);
AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.np_unEquip);
Bukkit.getScheduler().runTaskAsynchronously(CustomNameplates.plugin, () -> {
super.unequipNameplate(player);
AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.np_unEquip);
});
return super.onCommand(sender, args);
}
}

View File

@@ -66,6 +66,7 @@ public class DataManager extends Function {
public void onJoin(Player player) {
Bukkit.getScheduler().runTaskAsynchronously(CustomNameplates.plugin, () -> {
PlayerData playerData = dataStorageInterface.loadData(player);
if (playerData == null) return;
playerDataCache.put(player.getUniqueId(), playerData);
//wait
if (ConfigUtil.isModuleEnabled("nameplate")) {

View File

@@ -48,6 +48,7 @@ public class MySQLStorageImpl implements DataStorageInterface {
PlayerData playerData = null;
try {
Connection connection = sqlConnection.getConnectionAndCheck();
if (connection == null) return new PlayerData(player, NameplateManager.defaultNameplate, ChatBubblesManager.defaultBubble);
String sql = String.format(SqlConstants.SQL_SELECT_BY_UUID, sqlConnection.getTable_name());
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, player.getUniqueId().toString());
@@ -60,6 +61,7 @@ public class MySQLStorageImpl implements DataStorageInterface {
else {
playerData = new PlayerData(player, NameplateManager.defaultNameplate, ChatBubblesManager.defaultBubble);
}
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -79,8 +81,11 @@ public class MySQLStorageImpl implements DataStorageInterface {
private void createTableIfNotExist(String table) {
String sql = String.format(SqlConstants.SQL_CREATE_TABLE, table);
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
try {
Connection connection = sqlConnection.getConnection();
PreparedStatement statement = connection.prepareStatement(sql);
statement.executeUpdate();
connection.close();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomNameplates] Failed to create table");
}
@@ -88,11 +93,14 @@ public class MySQLStorageImpl implements DataStorageInterface {
private void insertData(UUID uuid, String nameplate, String bubbles) {
String sql = String.format(SqlConstants.SQL_INSERT, sqlConnection.getTable_name());
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
try {
Connection connection = sqlConnection.getConnection();
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, uuid.toString());
statement.setString(2, nameplate);
statement.setString(3, bubbles);
statement.executeUpdate();
connection.close();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomNameplates] Failed to insert data for " + uuid);
}
@@ -100,11 +108,14 @@ public class MySQLStorageImpl implements DataStorageInterface {
private void updateData(UUID uuid, String nameplate, String bubbles) {
String sql = String.format(SqlConstants.SQL_UPDATE_BY_UUID, sqlConnection.getTable_name());
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
try {
Connection connection = sqlConnection.getConnection();
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, nameplate);
statement.setString(2, bubbles);
statement.setString(3, uuid.toString());
statement.executeUpdate();
connection.close();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomNameplates] Failed to update data for " + uuid);
}
@@ -113,10 +124,13 @@ public class MySQLStorageImpl implements DataStorageInterface {
public boolean exists(UUID uuid) {
String sql = String.format(SqlConstants.SQL_SELECT_BY_UUID, sqlConnection.getTable_name());
boolean exist;
try (Connection connection = sqlConnection.getConnection(); PreparedStatement statement = connection.prepareStatement(sql)) {
try {
Connection connection = sqlConnection.getConnection();
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, uuid.toString());
ResultSet rs = statement.executeQuery();
exist = rs.next();
connection.close();
} catch (SQLException ex) {
AdventureUtil.consoleMessage("[CustomNameplates] Failed to select data for " + uuid);
return false;

View File

@@ -53,6 +53,7 @@ public class SqlConnection {
hikariConfig.setMaximumPoolSize(config.getInt(storageMode + ".Pool-Settings.maximum-pool-size"));
hikariConfig.setMinimumIdle(config.getInt(storageMode + ".Pool-Settings.minimum-idle"));
hikariConfig.setMaxLifetime(config.getInt(storageMode + ".Pool-Settings.maximum-lifetime"));
hikariConfig.setConnectionTimeout(5000);
for (String property : config.getConfigurationSection(storageMode + ".properties").getKeys(false)) {
hikariConfig.addDataSourceProperty(property, config.getString(storageMode + ".properties." + property));
}
@@ -64,7 +65,6 @@ public class SqlConnection {
try {
hikariDataSource = new HikariDataSource(hikariConfig);
} catch (HikariPool.PoolInitializationException e) {
AdventureUtil.consoleMessage("[CustomNameplates] Failed to create sql connection");
}
@@ -72,22 +72,13 @@ public class SqlConnection {
}
public boolean setGlobalConnection() {
try {
createNewHikariConfiguration();
Connection connection = getConnection();
connection.close();
if (secondTry) {
AdventureUtil.consoleMessage("[CustomNameplates] Successfully reconnect to SQL!");
} else {
secondTry = true;
}
return true;
} catch (SQLException e) {
AdventureUtil.consoleMessage("<red>[CustomNameplates] Error! Failed to connect to SQL!</red>");
e.printStackTrace();
close();
return false;
createNewHikariConfiguration();
if (secondTry) {
AdventureUtil.consoleMessage("[CustomNameplates] Successfully reconnect to SQL!");
} else {
secondTry = true;
}
return true;
}
public Connection getConnection() throws SQLException {

View File

@@ -28,25 +28,25 @@ import java.util.List;
public class BBPacketsHandle extends PacketsHandler {
private final ChatBubblesManager chatBubblesManager;
private EntityDestroyListener entityDestroyListener;
private EntityMoveListener entityMoveListener;
private EntitySpawnListener entitySpawnListener;
private EntityTeleportListener entityTeleportListener;
private EntityLookListener entityLookListener;
private final EntityDestroyListener entityDestroyListener;
private final EntityMoveListener entityMoveListener;
private final EntitySpawnListener entitySpawnListener;
private final EntityTeleportListener entityTeleportListener;
private final EntityLookListener entityLookListener;
public BBPacketsHandle(ChatBubblesManager chatBubblesManager) {
super(chatBubblesManager);
this.chatBubblesManager = chatBubblesManager;
}
@Override
public void load() {
super.load();
this.entityDestroyListener = new EntityDestroyListener(this);
this.entityMoveListener = new EntityMoveListener(this);
this.entitySpawnListener = new EntitySpawnListener(this);
this.entityTeleportListener = new EntityTeleportListener(this);
this.entityLookListener = new EntityLookListener(this);
}
@Override
public void load() {
super.load();
CustomNameplates.protocolManager.addPacketListener(entityDestroyListener);
CustomNameplates.protocolManager.addPacketListener(entityMoveListener);
CustomNameplates.protocolManager.addPacketListener(entitySpawnListener);