1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-04 23:37:49 +01:00

Simplifying method to get jobs player by name to avoid web calls

This commit is contained in:
Zrips 2022-05-25 13:00:50 +03:00
parent 9694b6b0a5
commit 2689a69c78

View File

@ -39,6 +39,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable; import org.bukkit.entity.Tameable;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.inventory.meta.FireworkMeta;
import org.jetbrains.annotations.Nullable;
import com.gamingmesh.jobs.api.JobsJoinEvent; import com.gamingmesh.jobs.api.JobsJoinEvent;
import com.gamingmesh.jobs.api.JobsLeaveEvent; import com.gamingmesh.jobs.api.JobsLeaveEvent;
@ -64,6 +65,7 @@ import com.gamingmesh.jobs.stuff.Util;
import net.Zrips.CMILib.ActionBar.CMIActionBar; import net.Zrips.CMILib.ActionBar.CMIActionBar;
import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Messages.CMIMessages;
import net.Zrips.CMILib.NBT.CMINBT; import net.Zrips.CMILib.NBT.CMINBT;
import net.Zrips.CMILib.Version.Version; import net.Zrips.CMILib.Version.Version;
@ -188,26 +190,12 @@ public class PlayerManager {
* @return {@link PlayerInfo} * @return {@link PlayerInfo}
*/ */
public PlayerInfo getPlayerInfo(String name) { public PlayerInfo getPlayerInfo(String name) {
if (Version.isCurrentEqualOrLower(Version.v1_11_R1) || !Version.isPaper()) {
JobsPlayer jPlayer = playersNameCache.get(name.toLowerCase()); JobsPlayer jPlayer = playersNameCache.get(name.toLowerCase());
if (jPlayer == null) if (jPlayer == null)
return null; return null;
return playerUUIDMap.get(jPlayer.getUniqueId()); return playerUUIDMap.get(jPlayer.getUniqueId());
} }
JobsPlayer jPlayer = playersNameCache.get(name.toLowerCase());
if (jPlayer != null) {
return playerUUIDMap.get(jPlayer.getUniqueId());
}
UUID playerUUID = Bukkit.getPlayerUniqueId(name);
if (playerUUID == null)
return null;
return playerUUIDMap.get(playerUUID);
}
/** /**
* Returns the {@link PlayerInfo} for the given identifier. This will returns * Returns the {@link PlayerInfo} for the given identifier. This will returns
* null if the player is not cached. * null if the player is not cached.
@ -388,29 +376,9 @@ public class PlayerManager {
* @return {@link JobsPlayer} the player job info of the player * @return {@link JobsPlayer} the player job info of the player
*/ */
public JobsPlayer getJobsPlayer(String playerName) { public JobsPlayer getJobsPlayer(String playerName) {
if (Version.isCurrentEqualOrLower(Version.v1_11_R1) || !Version.isPaper()) {
return playersNameCache.get(playerName.toLowerCase()); return playersNameCache.get(playerName.toLowerCase());
} }
JobsPlayer jPlayer = playersNameCache.get(playerName.toLowerCase());
if (jPlayer != null) {
return jPlayer;
}
UUID playerUUID = Bukkit.getPlayerUniqueId(playerName);
if (playerUUID == null)
return null;
jPlayer = playersUUID.get(playerUUID);
if (jPlayer != null) {
playersNameCache.put(playerName.toLowerCase(), jPlayer);
}
return jPlayer != null ? jPlayer : playersUUIDCache.get(playerUUID);
}
/** /**
* Gets the player job offline data for specific {@link PlayerInfo} * Gets the player job offline data for specific {@link PlayerInfo}
* *