1.16.1
This commit is contained in:
parent
131c242e5c
commit
dfd0cd597f
9 changed files with 118 additions and 89 deletions
|
|
@ -144,6 +144,7 @@ public class KitsConfigManager {
|
||||||
config.set("one_time",kit.isOneTime());
|
config.set("one_time",kit.isOneTime());
|
||||||
config.set("auto_armor",kit.isAutoArmor());
|
config.set("auto_armor",kit.isAutoArmor());
|
||||||
config.set("permission_required",kit.isPermissionRequired());
|
config.set("permission_required",kit.isPermissionRequired());
|
||||||
|
config.set("clear_inventory",kit.isClearInventory());
|
||||||
config.set("custom_permission",kit.getCustomPermission());
|
config.set("custom_permission",kit.getCustomPermission());
|
||||||
config.set("save_original_items",kit.isSaveOriginalItems());
|
config.set("save_original_items",kit.isSaveOriginalItems());
|
||||||
|
|
||||||
|
|
@ -234,9 +235,10 @@ public class KitsConfigManager {
|
||||||
String customPermission = config.contains(mainPath+"custom_permission") ? config.getString(mainPath+"custom_permission") : null;
|
String customPermission = config.contains(mainPath+"custom_permission") ? config.getString(mainPath+"custom_permission") : null;
|
||||||
boolean autoArmor = config.contains(mainPath+"auto_armor") ? config.getBoolean(mainPath+"auto_armor") : false;
|
boolean autoArmor = config.contains(mainPath+"auto_armor") ? config.getBoolean(mainPath+"auto_armor") : false;
|
||||||
boolean oneTime = config.contains(mainPath+"one_time") ? config.getBoolean(mainPath+"one_time") : false;
|
boolean oneTime = config.contains(mainPath+"one_time") ? config.getBoolean(mainPath+"one_time") : false;
|
||||||
|
boolean clearInventory = config.contains(mainPath+"clear_inventory") ? config.getBoolean(mainPath+"clear_inventory") : false;
|
||||||
boolean saveOriginalItems = config.contains(mainPath+"save_original_items") ? config.getBoolean(mainPath+"save_original_items") : false;
|
boolean saveOriginalItems = config.contains(mainPath+"save_original_items") ? config.getBoolean(mainPath+"save_original_items") : false;
|
||||||
|
|
||||||
ArrayList<KitItem> items = new ArrayList<KitItem>();
|
ArrayList<KitItem> items = new ArrayList<>();
|
||||||
if(config.contains(mainPath+"items")){
|
if(config.contains(mainPath+"items")){
|
||||||
for(String key : config.getConfigurationSection(mainPath+"items").getKeys(false)){
|
for(String key : config.getConfigurationSection(mainPath+"items").getKeys(false)){
|
||||||
KitItem item = kitItemManager.getKitItemFromConfig(config,mainPath+"items."+key);
|
KitItem item = kitItemManager.getKitItemFromConfig(config,mainPath+"items."+key);
|
||||||
|
|
@ -273,6 +275,7 @@ public class KitsConfigManager {
|
||||||
kit.setAutoArmor(autoArmor);
|
kit.setAutoArmor(autoArmor);
|
||||||
kit.setOneTime(oneTime);
|
kit.setOneTime(oneTime);
|
||||||
kit.setPermissionRequired(permissionRequired);
|
kit.setPermissionRequired(permissionRequired);
|
||||||
|
kit.setClearInventory(clearInventory);
|
||||||
kit.setCustomPermission(customPermission);
|
kit.setCustomPermission(customPermission);
|
||||||
kit.setItems(items);
|
kit.setItems(items);
|
||||||
kit.setClaimActions(claimActions);
|
kit.setClaimActions(claimActions);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@ import pk.ajneb97.model.PlayerDataKit;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PlayersConfigManager {
|
public class PlayersConfigManager {
|
||||||
private ArrayList<CustomConfig> configFiles;
|
private ArrayList<CustomConfig> configFiles;
|
||||||
|
|
@ -96,12 +99,12 @@ public class PlayersConfigManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadConfigs(){
|
public void loadConfigs(){
|
||||||
ArrayList<PlayerData> players = new ArrayList<>();
|
Map<UUID, PlayerData> players = new HashMap<>();
|
||||||
|
|
||||||
for(CustomConfig configFile : configFiles) {
|
for(CustomConfig configFile : configFiles) {
|
||||||
FileConfiguration config = configFile.getConfig();
|
FileConfiguration config = configFile.getConfig();
|
||||||
|
|
||||||
String uuid = configFile.getPath().replace(".yml", "");
|
String uuidString = configFile.getPath().replace(".yml", "");
|
||||||
String name = config.getString("name");
|
String name = config.getString("name");
|
||||||
ArrayList<PlayerDataKit> playerDataKits = new ArrayList<>();
|
ArrayList<PlayerDataKit> playerDataKits = new ArrayList<>();
|
||||||
|
|
||||||
|
|
@ -120,10 +123,11 @@ public class PlayersConfigManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerData playerData = new PlayerData(name,uuid);
|
UUID uuid = UUID.fromString(uuidString);
|
||||||
|
PlayerData playerData = new PlayerData(uuid,name);
|
||||||
playerData.setKits(playerDataKits);
|
playerData.setKits(playerDataKits);
|
||||||
|
|
||||||
players.add(playerData);
|
players.put(uuid,playerData);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getPlayerDataManager().setPlayers(players);
|
plugin.getPlayerDataManager().setPlayers(players);
|
||||||
|
|
@ -152,13 +156,17 @@ public class PlayersConfigManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveConfigs(){
|
public void saveConfigs(){
|
||||||
ArrayList<PlayerData> players = plugin.getPlayerDataManager().getPlayers();
|
Map<UUID, PlayerData> players = plugin.getPlayerDataManager().getPlayers();
|
||||||
for(PlayerData playerData : players) {
|
boolean isMySQL = plugin.getConfigsManager().getMainConfigManager().isMySQL();
|
||||||
|
if(!isMySQL){
|
||||||
|
for(Map.Entry<UUID, PlayerData> entry : players.entrySet()) {
|
||||||
|
PlayerData playerData = entry.getValue();
|
||||||
if(playerData.isModified()){
|
if(playerData.isModified()){
|
||||||
saveConfig(playerData);
|
saveConfig(playerData);
|
||||||
}
|
}
|
||||||
playerData.setModified(false);
|
playerData.setModified(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ public class MySQLConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadData(){
|
public void loadData(){
|
||||||
ArrayList<PlayerData> players = new ArrayList<>();
|
Map<UUID, PlayerData> playerMap = new HashMap<>();
|
||||||
try(Connection connection = getConnection()){
|
try(Connection connection = getConnection()){
|
||||||
PreparedStatement statement = connection.prepareStatement(
|
PreparedStatement statement = connection.prepareStatement(
|
||||||
"SELECT playerkits_players.UUID, playerkits_players.PLAYER_NAME, " +
|
"SELECT playerkits_players.UUID, playerkits_players.PLAYER_NAME, " +
|
||||||
|
|
@ -74,9 +74,8 @@ public class MySQLConnection {
|
||||||
|
|
||||||
ResultSet result = statement.executeQuery();
|
ResultSet result = statement.executeQuery();
|
||||||
|
|
||||||
Map<String, PlayerData> playerMap = new HashMap<>();
|
|
||||||
while(result.next()){
|
while(result.next()){
|
||||||
String uuid = result.getString("UUID");
|
UUID uuid = UUID.fromString(result.getString("UUID"));
|
||||||
String playerName = result.getString("PLAYER_NAME");
|
String playerName = result.getString("PLAYER_NAME");
|
||||||
String kitName = result.getString("NAME");
|
String kitName = result.getString("NAME");
|
||||||
long cooldown = result.getLong("COOLDOWN");
|
long cooldown = result.getLong("COOLDOWN");
|
||||||
|
|
@ -84,11 +83,9 @@ public class MySQLConnection {
|
||||||
boolean bought = result.getBoolean("BOUGHT");
|
boolean bought = result.getBoolean("BOUGHT");
|
||||||
|
|
||||||
PlayerData player = playerMap.get(uuid);
|
PlayerData player = playerMap.get(uuid);
|
||||||
|
|
||||||
if(player == null){
|
if(player == null){
|
||||||
//Create and add it
|
//Create and add it
|
||||||
player = new PlayerData(playerName,uuid);
|
player = new PlayerData(uuid,playerName);
|
||||||
players.add(player);
|
|
||||||
playerMap.put(uuid, player);
|
playerMap.put(uuid, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,7 +101,7 @@ public class MySQLConnection {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getPlayerDataManager().setPlayers(players);
|
plugin.getPlayerDataManager().setPlayers(playerMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createTables() {
|
public void createTables() {
|
||||||
|
|
@ -153,14 +150,14 @@ public class MySQLConnection {
|
||||||
|
|
||||||
boolean firstFind = true;
|
boolean firstFind = true;
|
||||||
while(result.next()){
|
while(result.next()){
|
||||||
|
UUID uuid = UUID.fromString(result.getString("UUID"));
|
||||||
String playerName = result.getString("PLAYER_NAME");
|
String playerName = result.getString("PLAYER_NAME");
|
||||||
String kitName = result.getString("NAME");
|
String kitName = result.getString("NAME");
|
||||||
long cooldown = result.getLong("COOLDOWN");
|
long cooldown = result.getLong("COOLDOWN");
|
||||||
boolean oneTime = result.getBoolean("ONE_TIME");
|
boolean oneTime = result.getBoolean("ONE_TIME");
|
||||||
boolean bought = result.getBoolean("BOUGHT");
|
boolean bought = result.getBoolean("BOUGHT");
|
||||||
if(firstFind){
|
if(player == null){
|
||||||
firstFind = false;
|
player = new PlayerData(uuid,playerName);
|
||||||
player = new PlayerData(playerName,uuid);
|
|
||||||
}
|
}
|
||||||
if(kitName != null){
|
if(kitName != null){
|
||||||
PlayerDataKit playerDataKit = new PlayerDataKit(kitName);
|
PlayerDataKit playerDataKit = new PlayerDataKit(kitName);
|
||||||
|
|
@ -194,7 +191,7 @@ public class MySQLConnection {
|
||||||
"INSERT INTO playerkits_players " +
|
"INSERT INTO playerkits_players " +
|
||||||
"(UUID, PLAYER_NAME) VALUE (?,?)");
|
"(UUID, PLAYER_NAME) VALUE (?,?)");
|
||||||
|
|
||||||
statement.setString(1, player.getUuid());
|
statement.setString(1, player.getUuid().toString());
|
||||||
statement.setString(2, player.getName());
|
statement.setString(2, player.getName());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
|
|
||||||
|
|
@ -221,7 +218,7 @@ public class MySQLConnection {
|
||||||
"PLAYER_NAME=? WHERE UUID=?");
|
"PLAYER_NAME=? WHERE UUID=?");
|
||||||
|
|
||||||
statement.setString(1, player.getName());
|
statement.setString(1, player.getName());
|
||||||
statement.setString(2, player.getUuid());
|
statement.setString(2, player.getUuid().toString());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
@ -242,7 +239,7 @@ public class MySQLConnection {
|
||||||
"INSERT INTO playerkits_players_kits " +
|
"INSERT INTO playerkits_players_kits " +
|
||||||
"(UUID, NAME, COOLDOWN, ONE_TIME, BOUGHT) VALUE (?,?,?,?,?)");
|
"(UUID, NAME, COOLDOWN, ONE_TIME, BOUGHT) VALUE (?,?,?,?,?)");
|
||||||
|
|
||||||
statement.setString(1, player.getUuid());
|
statement.setString(1, player.getUuid().toString());
|
||||||
statement.setString(2, kit.getName());
|
statement.setString(2, kit.getName());
|
||||||
statement.setLong(3, kit.getCooldown());
|
statement.setLong(3, kit.getCooldown());
|
||||||
statement.setBoolean(4, kit.isOneTime());
|
statement.setBoolean(4, kit.isOneTime());
|
||||||
|
|
@ -256,7 +253,7 @@ public class MySQLConnection {
|
||||||
statement.setLong(1, kit.getCooldown());
|
statement.setLong(1, kit.getCooldown());
|
||||||
statement.setBoolean(2, kit.isOneTime());
|
statement.setBoolean(2, kit.isOneTime());
|
||||||
statement.setBoolean(3, kit.isBought());
|
statement.setBoolean(3, kit.isBought());
|
||||||
statement.setString(4, player.getUuid());
|
statement.setString(4, player.getUuid().toString());
|
||||||
statement.setString(5, kit.getName());
|
statement.setString(5, kit.getName());
|
||||||
}
|
}
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
|
|
|
||||||
|
|
@ -286,12 +286,17 @@ public class KitsManager {
|
||||||
|
|
||||||
boolean enoughSpace = freeSlots < inventoryKitItems;
|
boolean enoughSpace = freeSlots < inventoryKitItems;
|
||||||
boolean dropItemsIfFullInventory = configFile.getBoolean("drop_items_if_full_inventory");
|
boolean dropItemsIfFullInventory = configFile.getBoolean("drop_items_if_full_inventory");
|
||||||
|
boolean clearInventory = kit.isClearInventory();
|
||||||
|
|
||||||
if(enoughSpace && !dropItemsIfFullInventory){
|
if(enoughSpace && !dropItemsIfFullInventory && !clearInventory){
|
||||||
sendKitActions(kit.getErrorActions(),player,false);
|
sendKitActions(kit.getErrorActions(),player,false);
|
||||||
return PlayerKitsMessageResult.error(messagesFile.getString("noSpaceError"));
|
return PlayerKitsMessageResult.error(messagesFile.getString("noSpaceError"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(clearInventory){
|
||||||
|
player.getInventory().clear();
|
||||||
|
}
|
||||||
|
|
||||||
//Actions before
|
//Actions before
|
||||||
sendKitActions(kit.getClaimActions(),player,true);
|
sendKitActions(kit.getClaimActions(),player,true);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import pk.ajneb97.model.item.KitItemSkullData;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class MigrationManager {
|
public class MigrationManager {
|
||||||
|
|
||||||
|
|
@ -130,7 +131,7 @@ public class MigrationManager {
|
||||||
try {
|
try {
|
||||||
String path = "Players."+uuid;
|
String path = "Players."+uuid;
|
||||||
String name = config.getString(path+".name");
|
String name = config.getString(path+".name");
|
||||||
PlayerData playerData = new PlayerData(name,uuid);
|
PlayerData playerData = new PlayerData(UUID.fromString(uuid),name);
|
||||||
for(String kitName : config.getConfigurationSection(path).getKeys(false)){
|
for(String kitName : config.getConfigurationSection(path).getKeys(false)){
|
||||||
if(kitName.equals("name")){
|
if(kitName.equals("name")){
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -8,65 +8,68 @@ import pk.ajneb97.model.internal.PlayerKitsMessageResult;
|
||||||
import pk.ajneb97.utils.OtherUtils;
|
import pk.ajneb97.utils.OtherUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PlayerDataManager {
|
public class PlayerDataManager {
|
||||||
|
|
||||||
private PlayerKits2 plugin;
|
private PlayerKits2 plugin;
|
||||||
private ArrayList<PlayerData> players;
|
private Map<UUID, PlayerData> players;
|
||||||
|
private Map<String,UUID> playerNames;
|
||||||
|
|
||||||
public PlayerDataManager(PlayerKits2 plugin){
|
public PlayerDataManager(PlayerKits2 plugin){
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.playerNames = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<PlayerData> getPlayers() {
|
public Map<UUID,PlayerData> getPlayers() {
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayers(ArrayList<PlayerData> players) {
|
public void setPlayers(Map<UUID,PlayerData> players) {
|
||||||
this.players = players;
|
this.players = players;
|
||||||
|
for(Map.Entry<UUID, PlayerData> entry : players.entrySet()){
|
||||||
|
playerNames.put(entry.getValue().getName(),entry.getKey());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlayerData getPlayer(Player player,boolean create){
|
public void addPlayer(PlayerData p){
|
||||||
for(PlayerData playerData : players){
|
players.put(p.getUuid(),p);
|
||||||
if(playerData.getUuid().equals(player.getUniqueId().toString())){
|
playerNames.put(p.getName(), p.getUuid());
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerData getPlayer(Player player, boolean create){
|
||||||
|
PlayerData playerData = players.get(player.getUniqueId());
|
||||||
|
if(playerData == null && create){
|
||||||
|
playerData = new PlayerData(player.getUniqueId(),player.getName());
|
||||||
|
addPlayer(playerData);
|
||||||
|
}
|
||||||
return playerData;
|
return playerData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updatePlayerName(String oldName,String newName,UUID uuid){
|
||||||
|
if(oldName != null){
|
||||||
|
playerNames.remove(oldName);
|
||||||
|
}
|
||||||
|
playerNames.put(newName,uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(create){
|
public PlayerData getPlayerByUUID(UUID uuid){
|
||||||
PlayerData playerData = new PlayerData(player.getName(),player.getUniqueId().toString());
|
return players.get(uuid);
|
||||||
playerData.setModified(true);
|
|
||||||
players.add(playerData);
|
|
||||||
return playerData;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerData getPlayerByUUID(String uuid){
|
private UUID getPlayerUUID(String name){
|
||||||
for(PlayerData player : players){
|
return playerNames.get(name);
|
||||||
if(player.getUuid().equals(uuid)){
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removePlayerByUUID(String uuid){
|
|
||||||
for(int i=0;i<players.size();i++){
|
|
||||||
if(players.get(i).getUuid().equals(uuid)){
|
|
||||||
players.remove(i);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerData getPlayerByName(String name){
|
public PlayerData getPlayerByName(String name){
|
||||||
for(PlayerData player : players){
|
UUID uuid = getPlayerUUID(name);
|
||||||
if(player.getName() != null && player.getName().equals(name)){
|
return players.get(uuid);
|
||||||
return player;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
public void removePlayerByUUID(UUID uuid){
|
||||||
|
players.remove(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKitCooldown(Player player,String kitName,long cooldown){
|
public void setKitCooldown(Player player,String kitName,long cooldown){
|
||||||
|
|
@ -79,7 +82,7 @@ public class PlayerDataManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getKitCooldown(Player player,String kitName){
|
public long getKitCooldown(Player player,String kitName){
|
||||||
PlayerData playerData = getPlayerByUUID(player.getUniqueId().toString());
|
PlayerData playerData = getPlayerByUUID(player.getUniqueId());
|
||||||
if(playerData == null){
|
if(playerData == null){
|
||||||
return 0;
|
return 0;
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -104,7 +107,7 @@ public class PlayerDataManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isKitOneTime(Player player,String kitName){
|
public boolean isKitOneTime(Player player,String kitName){
|
||||||
PlayerData playerData = getPlayerByUUID(player.getUniqueId().toString());
|
PlayerData playerData = getPlayerByUUID(player.getUniqueId());
|
||||||
if(playerData == null){
|
if(playerData == null){
|
||||||
return false;
|
return false;
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -122,7 +125,7 @@ public class PlayerDataManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isKitBought(Player player,String kitName){
|
public boolean isKitBought(Player player,String kitName){
|
||||||
PlayerData playerData = getPlayerByUUID(player.getUniqueId().toString());
|
PlayerData playerData = getPlayerByUUID(player.getUniqueId());
|
||||||
if(playerData == null){
|
if(playerData == null){
|
||||||
return false;
|
return false;
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -139,8 +142,8 @@ public class PlayerDataManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(all){
|
if(all){
|
||||||
for(PlayerData p : players){
|
for(Map.Entry<UUID, PlayerData> entry : players.entrySet()){
|
||||||
p.resetKit(kitName);
|
entry.getValue().resetKit(kitName);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
playerData.resetKit(kitName);
|
playerData.resetKit(kitName);
|
||||||
|
|
@ -150,7 +153,7 @@ public class PlayerDataManager {
|
||||||
if(all){
|
if(all){
|
||||||
plugin.getMySQLConnection().resetKit(null,kitName,true);
|
plugin.getMySQLConnection().resetKit(null,kitName,true);
|
||||||
}else{
|
}else{
|
||||||
plugin.getMySQLConnection().resetKit(playerData.getUuid(),kitName,false);
|
plugin.getMySQLConnection().resetKit(playerData.getUuid().toString(),kitName,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -162,33 +165,35 @@ public class PlayerDataManager {
|
||||||
// Create or update data
|
// Create or update data
|
||||||
if(plugin.getMySQLConnection() != null){
|
if(plugin.getMySQLConnection() != null){
|
||||||
MySQLConnection mySQLConnection = plugin.getMySQLConnection();
|
MySQLConnection mySQLConnection = plugin.getMySQLConnection();
|
||||||
String uuid = player.getUniqueId().toString();
|
UUID uuid = player.getUniqueId();
|
||||||
mySQLConnection.getPlayer(uuid, playerData -> {
|
mySQLConnection.getPlayer(uuid.toString(), playerData -> {
|
||||||
removePlayerByUUID(uuid); //Remove data if already exists
|
removePlayerByUUID(uuid); //Remove data if already exists
|
||||||
if(playerData != null) {
|
if(playerData != null) {
|
||||||
players.add(playerData);
|
addPlayer(playerData);
|
||||||
//Update name if different
|
//Update name if different
|
||||||
if (!playerData.getName().equals(player.getName())) {
|
if (!playerData.getName().equals(player.getName())) {
|
||||||
|
updatePlayerName(playerData.getName(), player.getName(), player.getUniqueId());
|
||||||
playerData.setName(player.getName());
|
playerData.setName(player.getName());
|
||||||
mySQLConnection.updatePlayerName(playerData);
|
mySQLConnection.updatePlayerName(playerData);
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
playerData = new PlayerData(player.getName(),uuid);
|
playerData = new PlayerData(uuid, player.getName());
|
||||||
players.add(playerData);
|
addPlayer(playerData);
|
||||||
|
|
||||||
//Create if it doesn't exist
|
//Create if it doesn't exist
|
||||||
mySQLConnection.createPlayer(playerData, () -> plugin.getKitsManager().giveFirstJoinKit(player));
|
mySQLConnection.createPlayer(playerData, () -> plugin.getKitsManager().giveFirstJoinKit(player));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
PlayerData playerData = getPlayerByUUID(player.getUniqueId().toString());
|
PlayerData playerData = getPlayer(player,false);
|
||||||
if(playerData == null){
|
if(playerData == null){
|
||||||
playerData = new PlayerData(player.getName(),player.getUniqueId().toString());
|
playerData = new PlayerData(player.getUniqueId(),player.getName());
|
||||||
playerData.setModified(true);
|
playerData.setModified(true);
|
||||||
players.add(playerData);
|
addPlayer(playerData);
|
||||||
plugin.getKitsManager().giveFirstJoinKit(player);
|
plugin.getKitsManager().giveFirstJoinKit(player);
|
||||||
}else{
|
}else{
|
||||||
if(playerData.getName() == null || !playerData.getName().equals(player.getName())){
|
if(playerData.getName() == null || !playerData.getName().equals(player.getName())){
|
||||||
|
updatePlayerName(playerData.getName(),player.getName(),player.getUniqueId());
|
||||||
playerData.setName(player.getName());
|
playerData.setName(player.getName());
|
||||||
playerData.setModified(true);
|
playerData.setModified(true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package pk.ajneb97.model;
|
package pk.ajneb97.model;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import pk.ajneb97.model.item.KitItem;
|
import pk.ajneb97.model.item.KitItem;
|
||||||
import pk.ajneb97.utils.PlayerUtils;
|
import pk.ajneb97.utils.PlayerUtils;
|
||||||
|
|
||||||
|
|
@ -11,6 +10,7 @@ public class Kit {
|
||||||
private String name;
|
private String name;
|
||||||
private int cooldown;
|
private int cooldown;
|
||||||
private boolean permissionRequired;
|
private boolean permissionRequired;
|
||||||
|
private boolean clearInventory;
|
||||||
private String customPermission;
|
private String customPermission;
|
||||||
private boolean oneTime;
|
private boolean oneTime;
|
||||||
private ArrayList<KitItem> items;
|
private ArrayList<KitItem> items;
|
||||||
|
|
@ -164,6 +164,14 @@ public class Kit {
|
||||||
this.saveOriginalItems = saveOriginalItems;
|
this.saveOriginalItems = saveOriginalItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isClearInventory() {
|
||||||
|
return clearInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClearInventory(boolean clearInventory) {
|
||||||
|
this.clearInventory = clearInventory;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean playerHasPermission(CommandSender player){
|
public boolean playerHasPermission(CommandSender player){
|
||||||
if(permissionRequired){
|
if(permissionRequired){
|
||||||
if(customPermission != null){
|
if(customPermission != null){
|
||||||
|
|
@ -178,6 +186,7 @@ public class Kit {
|
||||||
public void setDefaults(Kit defaultKit){
|
public void setDefaults(Kit defaultKit){
|
||||||
cooldown = defaultKit.getCooldown();
|
cooldown = defaultKit.getCooldown();
|
||||||
oneTime = defaultKit.isOneTime();
|
oneTime = defaultKit.isOneTime();
|
||||||
|
clearInventory = defaultKit.isClearInventory();
|
||||||
permissionRequired = defaultKit.isPermissionRequired();
|
permissionRequired = defaultKit.isPermissionRequired();
|
||||||
if(defaultKit.getClaimActions() != null){
|
if(defaultKit.getClaimActions() != null){
|
||||||
ArrayList<KitAction> actions = new ArrayList<>();
|
ArrayList<KitAction> actions = new ArrayList<>();
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,31 @@
|
||||||
package pk.ajneb97.model;
|
package pk.ajneb97.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PlayerData {
|
public class PlayerData {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String uuid;
|
private UUID uuid;
|
||||||
|
|
||||||
private ArrayList<PlayerDataKit> kits;
|
private ArrayList<PlayerDataKit> kits;
|
||||||
private boolean modified;
|
private boolean modified;
|
||||||
|
|
||||||
public PlayerData(String name,String uuid){
|
public PlayerData(UUID uuid, String name){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.kits = new ArrayList<PlayerDataKit>();
|
this.kits = new ArrayList<>();
|
||||||
this.modified = false;
|
this.modified = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UUID getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUuid(UUID uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
@ -25,14 +34,6 @@ public class PlayerData {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUuid(String uuid) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<PlayerDataKit> getKits() {
|
public ArrayList<PlayerDataKit> getKits() {
|
||||||
return kits;
|
return kits;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
main: pk.ajneb97.PlayerKits2
|
main: pk.ajneb97.PlayerKits2
|
||||||
version: 1.15.3
|
version: 1.16.1
|
||||||
name: PlayerKits2
|
name: PlayerKits2
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
softdepend: [Vault,PlaceholderAPI]
|
softdepend: [Vault,PlaceholderAPI]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue