diff --git a/scripts/build.sh b/scripts/build.sh index 2d9065ac1..c6a7ca9e2 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -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 diff --git a/src/main/java/net/minecraft/server/AkarinUserCache.java b/src/main/java/net/minecraft/server/AkarinUserCache.java index d7753ccc7..ae8bce83c 100644 --- a/src/main/java/net/minecraft/server/AkarinUserCache.java +++ b/src/main/java/net/minecraft/server/AkarinUserCache.java @@ -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 entries() { + protected List entries() { return Lists.newArrayList(profiles.asMap().values()); } } \ No newline at end of file diff --git a/src/main/java/net/minecraft/server/ArgumentProfile.java b/src/main/java/net/minecraft/server/ArgumentProfile.java new file mode 100644 index 000000000..02231684f --- /dev/null +++ b/src/main/java/net/minecraft/server/ArgumentProfile.java @@ -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 { + + private static final Collection 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 a(CommandContext 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 CompletableFuture listSuggestions(CommandContext 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 getExamples() { + return ArgumentProfile.b; + } + + public static class b implements ArgumentProfile.a { + + private final EntitySelector a; + + public b(EntitySelector entityselector) { + this.a = entityselector; + } + + public Collection getNames(CommandListenerWrapper commandlistenerwrapper) throws CommandSyntaxException { + List list = this.a.d(commandlistenerwrapper); + + if (list.isEmpty()) { + throw ArgumentEntity.e.create(); + } else { + List 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 getNames(CommandListenerWrapper commandlistenerwrapper) throws CommandSyntaxException; + } +}