-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 让SingleSkin的过期时间属性重新派上用场。 * 当从缓存获取的皮肤处于过期状态,将继续联网查询皮肤的过程,并只在查无此人时使用缓存的皮肤 * 若一个皮肤查无此人但是有存缓存,则缓存的皮肤将重新获得15天的过期期限
- Loading branch information
1 parent
bbe0384
commit c6d9243
Showing
7 changed files
with
136 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package xiamomc.morph.misc.skins; | ||
|
||
import com.mojang.authlib.GameProfile; | ||
import org.bukkit.Bukkit; | ||
import org.jetbrains.annotations.NotNull; | ||
import xiamomc.morph.storage.MorphJsonBasedStorage; | ||
|
||
import java.util.Optional; | ||
|
||
public class SkinCache extends MorphJsonBasedStorage<SkinCacheRoot> | ||
{ | ||
@Override | ||
protected @NotNull String getFileName() | ||
{ | ||
return "stored_skins.json"; | ||
} | ||
|
||
@Override | ||
protected @NotNull SkinCacheRoot createDefault() | ||
{ | ||
return new SkinCacheRoot(); | ||
} | ||
|
||
@Override | ||
protected @NotNull String getDisplayName() | ||
{ | ||
return "Server renderer skin store"; | ||
} | ||
|
||
public synchronized void cache(GameProfile profile) | ||
{ | ||
drop(profile.getName()); | ||
storingObject.storedSkins.add(SingleSkin.fromProfile(profile)); | ||
|
||
saveConfiguration(); | ||
} | ||
|
||
public synchronized void drop(String name) | ||
{ | ||
storingObject.storedSkins.removeIf(ss -> ss.name.equalsIgnoreCase(name)); | ||
|
||
saveConfiguration(); | ||
} | ||
|
||
public synchronized void drop(GameProfile profile) | ||
{ | ||
drop(profile.getName()); | ||
} | ||
|
||
public synchronized void drop(SingleSkin singleSkin) | ||
{ | ||
storingObject.storedSkins.remove(singleSkin); | ||
|
||
saveConfiguration(); | ||
} | ||
|
||
public record SkinRecord(Optional<GameProfile> profileOptional, boolean expired) | ||
{ | ||
} | ||
|
||
@NotNull | ||
public SkinRecord get(String name) | ||
{ | ||
var single = storingObject.storedSkins.stream().filter(ss -> | ||
ss.name.equalsIgnoreCase(name)).findFirst().orElse(null); | ||
|
||
if (single == null) return new SkinRecord(Optional.empty(), true); | ||
|
||
var profile = single.generateGameProfile(); | ||
return new SkinRecord( | ||
(profile == null ? Optional.empty() : Optional.of(profile)), | ||
System.currentTimeMillis() > single.expiresAt); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.