Make argument profile use our usercache
This commit is contained in:
@@ -35,7 +35,7 @@ echo "[Akarin] Ready to build"
|
||||
\cp -rf "$basedir/src/api/pom.xml" "$paperbasedir/Paper-API/"
|
||||
\cp -rf "$basedir/src" "$paperbasedir/Paper-Server/"
|
||||
\cp -rf "$basedir/pom.xml" "$paperbasedir/Paper-Server/"
|
||||
mvn clean install
|
||||
mvn clean install -DskipTests
|
||||
else
|
||||
rm -rf Paper-API/src
|
||||
rm -rf Paper-Server/src
|
||||
|
||||
@@ -58,11 +58,11 @@ public class AkarinUserCache {
|
||||
protected final Gson gson;
|
||||
private final File userCacheFile;
|
||||
|
||||
public static boolean isOnlineMode() {
|
||||
private static boolean isOnlineMode() {
|
||||
return UserCache.isOnlineMode() || (SpigotConfig.bungee && PaperConfig.bungeeOnlineMode);
|
||||
}
|
||||
|
||||
public static Date createExpireDate(boolean force) {
|
||||
private static Date createExpireDate(boolean force) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (force || (now - lastWarpExpireDate) > RECREATE_DATE_INTERVAL) {
|
||||
lastWarpExpireDate = now;
|
||||
@@ -76,15 +76,15 @@ public class AkarinUserCache {
|
||||
return lastExpireDate;
|
||||
}
|
||||
|
||||
public static boolean isExpired(UserCacheEntry entry) {
|
||||
private static boolean isExpired(UserCacheEntry entry) {
|
||||
return System.currentTimeMillis() >= entry.getExpireDate().getTime();
|
||||
}
|
||||
|
||||
public static UserCacheEntry refreshExpireDate(UserCacheEntry entry) {
|
||||
private static UserCacheEntry refreshExpireDate(UserCacheEntry entry) {
|
||||
return new UserCacheEntry(entry.getProfile(), createExpireDate(true));
|
||||
}
|
||||
|
||||
public static GameProfile lookup(GameProfileRepository profileRepo, String username, ProfileLookupCallback callback, boolean async) {
|
||||
private static GameProfile lookup(GameProfileRepository profileRepo, String username, ProfileLookupCallback callback, boolean async) {
|
||||
if (!isOnlineMode()) {
|
||||
String usernameKey = username.toLowerCase(Locale.ROOT);
|
||||
GameProfile offlineProfile = new GameProfile(EntityHuman.getOfflineUUID(usernameKey), usernameKey);
|
||||
@@ -132,11 +132,11 @@ public class AkarinUserCache {
|
||||
this.load();
|
||||
}
|
||||
|
||||
GameProfile lookupAndCache(String username, ProfileLookupCallback callback, boolean async) {
|
||||
private GameProfile lookupAndCache(String username, ProfileLookupCallback callback, boolean async) {
|
||||
return lookupAndCache(username, callback, createExpireDate(false), async);
|
||||
}
|
||||
|
||||
GameProfile lookupAndCache(String username, ProfileLookupCallback callback, Date date, boolean async) {
|
||||
private GameProfile lookupAndCache(String username, ProfileLookupCallback callback, Date date, boolean async) {
|
||||
ProfileLookupCallback callbackHandler = new ProfileLookupCallback() {
|
||||
@Override
|
||||
public void onProfileLookupSucceeded(GameProfile gameprofile) {
|
||||
@@ -187,7 +187,7 @@ public class AkarinUserCache {
|
||||
}
|
||||
return lookupAndCache(username, callback, async);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public GameProfile peek(String username) {
|
||||
String keyUsername = isOnlineMode() ? username : username.toLowerCase(Locale.ROOT);
|
||||
@@ -195,11 +195,11 @@ public class AkarinUserCache {
|
||||
return entry == null ? null : entry.getProfile();
|
||||
}
|
||||
|
||||
void offer(GameProfile profile) {
|
||||
protected void offer(GameProfile profile) {
|
||||
offer(profile, createExpireDate(false));
|
||||
}
|
||||
|
||||
void offer(GameProfile profile, Date date) {
|
||||
protected void offer(GameProfile profile, Date date) {
|
||||
String keyUsername = isOnlineMode() ? profile.getName() : profile.getName().toLowerCase(Locale.ROOT);
|
||||
UserCacheEntry entry = profiles.getIfPresent(keyUsername);
|
||||
|
||||
@@ -219,12 +219,12 @@ public class AkarinUserCache {
|
||||
this.save();
|
||||
}
|
||||
|
||||
void offer(UserCacheEntry entry) {
|
||||
private void offer(UserCacheEntry entry) {
|
||||
if (!isExpired(entry))
|
||||
profiles.put(isOnlineMode() ? entry.getProfile().getName() : entry.getProfile().getName().toLowerCase(Locale.ROOT), entry);
|
||||
}
|
||||
|
||||
String[] usernames() {
|
||||
protected String[] usernames() {
|
||||
return profiles.asMap().keySet().toArray(new String[profiles.asMap().size()]);
|
||||
}
|
||||
|
||||
@@ -250,11 +250,11 @@ public class AkarinUserCache {
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
protected void save() {
|
||||
save(true);
|
||||
}
|
||||
|
||||
public void save(boolean async) {
|
||||
protected void save(boolean async) {
|
||||
Runnable save = () -> {
|
||||
String jsonString = this.gson.toJson(this.entries());
|
||||
BufferedWriter writer = null;
|
||||
@@ -278,7 +278,7 @@ public class AkarinUserCache {
|
||||
save.run();
|
||||
}
|
||||
|
||||
List<UserCacheEntry> entries() {
|
||||
protected List<UserCacheEntry> entries() {
|
||||
return Lists.newArrayList(profiles.asMap().values());
|
||||
}
|
||||
}
|
||||
123
src/main/java/net/minecraft/server/ArgumentProfile.java
Normal file
123
src/main/java/net/minecraft/server/ArgumentProfile.java
Normal file
@@ -0,0 +1,123 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ArgumentProfile implements ArgumentType<ArgumentProfile.a> {
|
||||
|
||||
private static final Collection<String> b = Arrays.asList("Player", "0123", "dd12be42-52a9-4a91-a8a1-11c01849e498", "@e");
|
||||
public static final SimpleCommandExceptionType a = new SimpleCommandExceptionType(new ChatMessage("argument.player.unknown", new Object[0]));
|
||||
|
||||
public ArgumentProfile() {}
|
||||
|
||||
public static Collection<GameProfile> a(CommandContext<CommandListenerWrapper> commandcontext, String s) throws CommandSyntaxException {
|
||||
return ((ArgumentProfile.a) commandcontext.getArgument(s, ArgumentProfile.a.class)).getNames((CommandListenerWrapper) commandcontext.getSource());
|
||||
}
|
||||
|
||||
public static ArgumentProfile a() {
|
||||
return new ArgumentProfile();
|
||||
}
|
||||
|
||||
public ArgumentProfile.a parse(StringReader stringreader) throws CommandSyntaxException {
|
||||
if (stringreader.canRead() && stringreader.peek() == '@') {
|
||||
ArgumentParserSelector argumentparserselector = new ArgumentParserSelector(stringreader);
|
||||
EntitySelector entityselector = argumentparserselector.s();
|
||||
|
||||
if (entityselector.b()) {
|
||||
throw ArgumentEntity.c.create();
|
||||
} else {
|
||||
return new ArgumentProfile.b(entityselector);
|
||||
}
|
||||
} else {
|
||||
int i = stringreader.getCursor();
|
||||
|
||||
while (stringreader.canRead() && stringreader.peek() != ' ') {
|
||||
stringreader.skip();
|
||||
}
|
||||
|
||||
String s = stringreader.getString().substring(i, stringreader.getCursor());
|
||||
|
||||
return (commandlistenerwrapper) -> {
|
||||
GameProfile gameprofile = commandlistenerwrapper.getServer().getModernUserCache().acquire(s); // Akarin
|
||||
|
||||
if (gameprofile == null) {
|
||||
throw ArgumentProfile.a.create();
|
||||
} else {
|
||||
return Collections.singleton(gameprofile);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> commandcontext, SuggestionsBuilder suggestionsbuilder) {
|
||||
if (commandcontext.getSource() instanceof ICompletionProvider) {
|
||||
StringReader stringreader = new StringReader(suggestionsbuilder.getInput());
|
||||
|
||||
stringreader.setCursor(suggestionsbuilder.getStart());
|
||||
ArgumentParserSelector argumentparserselector = new ArgumentParserSelector(stringreader);
|
||||
|
||||
try {
|
||||
argumentparserselector.s();
|
||||
} catch (CommandSyntaxException commandsyntaxexception) {
|
||||
;
|
||||
}
|
||||
|
||||
return argumentparserselector.a(suggestionsbuilder, (suggestionsbuilder1) -> {
|
||||
ICompletionProvider.b((Iterable) ((ICompletionProvider) commandcontext.getSource()).l(), suggestionsbuilder1);
|
||||
});
|
||||
} else {
|
||||
return Suggestions.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<String> getExamples() {
|
||||
return ArgumentProfile.b;
|
||||
}
|
||||
|
||||
public static class b implements ArgumentProfile.a {
|
||||
|
||||
private final EntitySelector a;
|
||||
|
||||
public b(EntitySelector entityselector) {
|
||||
this.a = entityselector;
|
||||
}
|
||||
|
||||
public Collection<GameProfile> getNames(CommandListenerWrapper commandlistenerwrapper) throws CommandSyntaxException {
|
||||
List<EntityPlayer> list = this.a.d(commandlistenerwrapper);
|
||||
|
||||
if (list.isEmpty()) {
|
||||
throw ArgumentEntity.e.create();
|
||||
} else {
|
||||
List<GameProfile> list1 = Lists.newArrayList();
|
||||
Iterator iterator = list.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
|
||||
|
||||
list1.add(entityplayer.getProfile());
|
||||
}
|
||||
|
||||
return list1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface a {
|
||||
|
||||
Collection<GameProfile> getNames(CommandListenerWrapper commandlistenerwrapper) throws CommandSyntaxException;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user