mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-01-21 21:31:34 +01:00
Add the player cache class
This commit is contained in:
parent
b79f8f76a6
commit
6371c1725c
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2020 GeorgH93
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package at.pcgamingfreaks.Minepacks.Bukkit.Database;
|
||||
|
||||
import at.pcgamingfreaks.Database.Cache.ICacheablePlayer;
|
||||
import at.pcgamingfreaks.Database.Cache.IPlayerCache;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class Cache implements IPlayerCache
|
||||
{
|
||||
private final Map<UUID, MinepacksPlayerData> players = new ConcurrentHashMap<>();
|
||||
|
||||
public Cache() {}
|
||||
|
||||
public void close()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
players.clear();
|
||||
}
|
||||
|
||||
public void cache(final @NotNull MinepacksPlayerData player)
|
||||
{
|
||||
players.put(player.getUUID(), player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unCache(final @NotNull ICacheablePlayer player)
|
||||
{
|
||||
players.remove(player.getUUID());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable MinepacksPlayerData getCachedPlayer(final @NotNull UUID uuid)
|
||||
{
|
||||
return players.get(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<? extends MinepacksPlayerData> getCachedPlayers()
|
||||
{
|
||||
return players.values();
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
package at.pcgamingfreaks.Minepacks.Bukkit.Database;
|
||||
|
||||
import at.pcgamingfreaks.Bukkit.Message.IMessage;
|
||||
import at.pcgamingfreaks.Database.Cache.ICacheablePlayer;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.ExtendedAPI.MinepacksPlayerExtended;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Item.ItemConfig;
|
||||
@ -36,7 +37,7 @@
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class MinepacksPlayerData implements MinepacksPlayerExtended
|
||||
public class MinepacksPlayerData implements MinepacksPlayerExtended, ICacheablePlayer
|
||||
{
|
||||
@Getter @Setter private @NotNull String name;
|
||||
private final @NotNull UUID uuid;
|
||||
@ -100,6 +101,18 @@ public boolean isOnline()
|
||||
return bukkitPlayer != null && bukkitPlayer.isOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastPlayed()
|
||||
{
|
||||
return player.getLastPlayed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUncached()
|
||||
{
|
||||
return !isOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBackpackStyle(@NotNull String style)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user