mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-01 15:03:36 +01:00
Merge pull request #1337 from DoctaEnkoda/patch-2
Fix duplication Entry
This commit is contained in:
commit
a974274350
@ -18,16 +18,12 @@
|
||||
|
||||
package com.gamingmesh.jobs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.FireworkEffect.Type;
|
||||
@ -69,16 +65,13 @@ import net.Zrips.CMILib.Version.Version;
|
||||
|
||||
public class PlayerManager {
|
||||
|
||||
private final ConcurrentMap<String, JobsPlayer> playersCache = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<UUID, JobsPlayer> playersUUIDCache = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<String, JobsPlayer> players = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<UUID, JobsPlayer> playersUUID = new ConcurrentHashMap<>();
|
||||
|
||||
private final String mobSpawnerMetadata = "jobsMobSpawner";
|
||||
|
||||
private final Map<UUID, PlayerInfo> playerUUIDMap = new HashMap<>();
|
||||
private final Map<Integer, PlayerInfo> playerIdMap = new HashMap<>();
|
||||
private final Map<String, PlayerInfo> playerNameMap = new HashMap<>();
|
||||
private final Map<UUID, PlayerInfo> playerUUIDMap = new LinkedHashMap<>();
|
||||
private final Map<Integer, PlayerInfo> playerIdMap = new LinkedHashMap<>();
|
||||
|
||||
private final Jobs plugin;
|
||||
|
||||
@ -110,13 +103,10 @@ public class PlayerManager {
|
||||
public void clearMaps() {
|
||||
playerUUIDMap.clear();
|
||||
playerIdMap.clear();
|
||||
playerNameMap.clear();
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
playersCache.clear();
|
||||
playersUUIDCache.clear();
|
||||
players.clear();
|
||||
playersUUID.clear();
|
||||
}
|
||||
|
||||
@ -125,20 +115,10 @@ public class PlayerManager {
|
||||
// Checking duplicated UUID's which usually is a cause of previous bugs
|
||||
if (playerUUIDMap.containsKey(info.getUuid()) && playerUUIDMap.get(info.getUuid()).getID() != info.getID()) {
|
||||
int id = playerUUIDMap.get(info.getUuid()).getID();
|
||||
if (Jobs.getGCManager().isInformDuplicates())
|
||||
if (Jobs.getGCManager().isInformDuplicates()) {
|
||||
CMIMessages.consoleMessage("&7Duplicate! &5" + info.getName() + " &7same UUID for 2 entries in database. Please remove of one them from users table id1: &2" + id + " &7id2: &2" + info
|
||||
.getID());
|
||||
if (id < info.getID()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Checking duplicated names which usually is a cause of previous bugs
|
||||
if (playerNameMap.containsKey(info.getName().toLowerCase()) && playerNameMap.get(info.getName().toLowerCase()).getID() != info.getID()) {
|
||||
int id = playerNameMap.get(info.getName().toLowerCase()).getID();
|
||||
if (Jobs.getGCManager().isInformDuplicates())
|
||||
CMIMessages.consoleMessage("&7Name Duplicate! &5" + info.getName() + " &7same UUID for 2 entries in database. Please remove of one them from users table id1: &2" + id + " &7id2: &2" + info
|
||||
.getID());
|
||||
if (id < info.getID()) {
|
||||
return;
|
||||
}
|
||||
@ -146,41 +126,26 @@ public class PlayerManager {
|
||||
|
||||
playerUUIDMap.put(info.getUuid(), info);
|
||||
playerIdMap.put(info.getID(), info);
|
||||
playerNameMap.put(info.getName().toLowerCase(), info);
|
||||
}
|
||||
|
||||
public void addPlayerToCache(JobsPlayer jPlayer) {
|
||||
String jName = jPlayer.getName().toLowerCase();
|
||||
|
||||
playersCache.put(jName, jPlayer);
|
||||
|
||||
if (jPlayer.getUniqueId() != null) {
|
||||
playersUUIDCache.put(jPlayer.getUniqueId(), jPlayer);
|
||||
}
|
||||
playersUUIDCache.putIfAbsent(jPlayer.playerUUID, jPlayer);
|
||||
}
|
||||
|
||||
public void addPlayer(JobsPlayer jPlayer) {
|
||||
String jName = jPlayer.getName().toLowerCase();
|
||||
|
||||
players.put(jName, jPlayer);
|
||||
|
||||
if (jPlayer.getUniqueId() != null)
|
||||
playersUUID.put(jPlayer.getUniqueId(), jPlayer);
|
||||
playersUUID.putIfAbsent(jPlayer.getUniqueId(), jPlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given player from the memory.
|
||||
*
|
||||
* @param player {@link Player}
|
||||
* @return {@link JobsPlayer}
|
||||
*/
|
||||
public JobsPlayer removePlayer(Player player) {
|
||||
public void removePlayer(Player player) {
|
||||
if (player == null)
|
||||
return null;
|
||||
return;
|
||||
|
||||
players.remove(player.getName().toLowerCase());
|
||||
|
||||
return playersUUID.remove(player.getUniqueId());
|
||||
playersUUID.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
public ConcurrentMap<UUID, JobsPlayer> getPlayersCache() {
|
||||
@ -223,7 +188,8 @@ public class PlayerManager {
|
||||
* @return {@link PlayerInfo}
|
||||
*/
|
||||
public PlayerInfo getPlayerInfo(String name) {
|
||||
return playerNameMap.get(name.toLowerCase());
|
||||
UUID playerUUID = Bukkit.getPlayerUniqueId(name);
|
||||
return playerUUIDMap.get(playerUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -310,7 +276,7 @@ public class PlayerManager {
|
||||
* Removes all jobs player miscellaneous settings like boss bar.
|
||||
*/
|
||||
public void removePlayerAdditions() {
|
||||
for (JobsPlayer jPlayer : players.values()) {
|
||||
for (JobsPlayer jPlayer : playersUUID.values()) {
|
||||
jPlayer.clearBossMaps();
|
||||
jPlayer.getUpdateBossBarFor().clear();
|
||||
}
|
||||
@ -327,16 +293,10 @@ public class PlayerManager {
|
||||
* 2) Perform save on all players on copied list.
|
||||
* 3) Garbage collect the real list to remove any offline players with saved data
|
||||
*/
|
||||
for (JobsPlayer jPlayer : new ArrayList<>(players.values()))
|
||||
for (JobsPlayer jPlayer : new ArrayList<>(playersUUID.values()))
|
||||
jPlayer.save();
|
||||
|
||||
Iterator<JobsPlayer> iter = players.values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
JobsPlayer jPlayer = iter.next();
|
||||
|
||||
if (jPlayer.isSaved() && !jPlayer.isOnline())
|
||||
iter.remove();
|
||||
}
|
||||
playersUUID.values().removeIf(jPlayer -> jPlayer.isSaved() && !jPlayer.isOnline());
|
||||
|
||||
Jobs.getBpManager().saveCache();
|
||||
}
|
||||
@ -412,9 +372,9 @@ public class PlayerManager {
|
||||
* @return {@link JobsPlayer} the player job info of the player
|
||||
*/
|
||||
public JobsPlayer getJobsPlayer(String playerName) {
|
||||
playerName = playerName.toLowerCase();
|
||||
JobsPlayer jPlayer = players.get(playerName);
|
||||
return jPlayer != null ? jPlayer : playersCache.get(playerName);
|
||||
UUID playerUUID = Bukkit.getPlayerUniqueId(playerName);
|
||||
JobsPlayer jPlayer = playersUUID.get(playerUUID);
|
||||
return jPlayer != null ? jPlayer : playersUUIDCache.get(playerUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -949,7 +909,7 @@ public class PlayerManager {
|
||||
* Perform reload for all jobs players.
|
||||
*/
|
||||
public void reload() {
|
||||
for (JobsPlayer jPlayer : players.values()) {
|
||||
for (JobsPlayer jPlayer : playersUUID.values()) {
|
||||
for (JobProgression progression : jPlayer.progression) {
|
||||
Job job = Jobs.getJob(progression.getJob().getName());
|
||||
if (job != null)
|
||||
|
Loading…
Reference in New Issue
Block a user