WhitelistMigration class
Пакет: com.hypixel.hytale.server.core.modules.accesscontrol
Файл: com/hypixel/hytale/server/core/modules/accesscontrol/WhitelistMigration.java
Поля (7)
| Модификаторы | Тип | Имя |
|---|---|---|
|
BsonDocument |
var2 |
|
|
var2 |
|
BsonValue |
var2 |
|
BsonArray |
var2 |
|
boolean |
var3 |
|
List |
var3 |
|
int |
var4 |
Методы (11)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
throw new |
IllegalStateExceptionthrow new IllegalStateException("Failed to read " + var0 + ". Fix it or delete it, then start the server again", var5) |
abstract |
throw new |
IllegalStateExceptionthrow new IllegalStateException(var0 + " cannot be read. Fix it or delete it, then start the server again") |
abstract |
throw new |
IllegalStateExceptionthrow new IllegalStateException("Failed to rename " + var4 + ", which would be read again on the next start", var6) |
|
|
for for(BsonValue var5 : var2) |
|
|
if if(var2 == null) |
|
|
if if(var3) |
|
|
if if(var3) |
static |
boolean |
isEnabledboolean isEnabled(@Nonnull BsonDocument var0, @Nonnull Path var1) |
static |
void |
migratevoid migrate(@Nonnull Path var0) |
abstract |
|
migrate migrate(var0) |
static |
void |
runvoid run(@Nonnull Path var0, @Nonnull AccessControlModule var1) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.modules.accesscontrol;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.server.core.permissions.HytalePermissions;
class="kw">import com.hypixel.hytale.server.core.util.BsonUtil;
class="kw">import java.nio.file.Files;
class="kw">import java.nio.file.Path;
class="kw">import java.nio.file.StandardCopyOption;
class="kw">import java.util.ArrayList;
class="kw">import java.util.List;
class="kw">import java.util.UUID;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import org.bson.BsonArray;
class="kw">import org.bson.BsonDocument;
class="kw">import org.bson.BsonValue;
class="kw">final class WhitelistMigration {
@Nonnull
class="kw">static class="kw">final String WHITELIST_FILE_PATH = "whitelist.json";
@Nonnull
class="kw">private class="kw">static class="kw">final String MIGRATED_SUFFIX = ".migrated";
@Nonnull
class="kw">private class="kw">static class="kw">final String BACKUP_SUFFIX = ".bak";
class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
class="kw">private WhitelistMigration() {
}
class="kw">static void run(@Nonnull Path var0, @Nonnull AccessControlModule var1) {
BsonDocument var2;
try {
var2 = BsonUtil.readDocument(var0).join();
} catch (Exception var5) {
throw new IllegalStateException("Failed to read " + var0 + ". Fix it or delete it, then start the server again", var5);
}
if (var2 == null) {
if (Files.exists(var0) || Files.exists(backupOf(var0))) {
throw new IllegalStateException(var0 + " cannot be read. Fix it or delete it, then start the server again");
}
} else {
boolean var3 = isEnabled(var2, var0);
int var4 = var1.allowJoin(readPlayers(var2, var0));
if (var3) {
var1.setJoinPermissionRequired(true).join();
}
migrate(var0);
LOGGER.at(Level.INFO)
.log("Granted %s to %d players from %s, which is now %s%s", HytalePermissions.SERVER_JOIN, var4, var0, var0.getFileName(), ".migrated");
if (var3) {
LOGGER.at(Level.WARNING)
.log(
"%s replaces %s, and a group or a wildcard satisfies it as well as a grant. A player the list kept out can connect if a group grants them the permission. Check the groups in permissions.json",
HytalePermissions.SERVER_JOIN,
var0.getFileName()
);
}
}
}
class="kw">private class="kw">static void migrate(@Nonnull Path var0) {
for (Path var4 : new Path[]{var0, backupOf(var0)}) {
try {
if (Files.exists(var4)) {
Files.move(var4, var4.resolveSibling(var4.getFileName() + ".migrated"), StandardCopyOption.REPLACE_EXISTING);
}
} catch (Exception var6) {
throw new IllegalStateException("Failed to rename " + var4 + ", which would be read again on the next start", var6);
}
}
}
@Nonnull
class="kw">private class="kw">static Path backupOf(@Nonnull Path var0) {
class="kw">return var0.resolveSibling(var0.getFileName() + ".bak");
}
class="kw">static boolean isEnabled(@Nonnull BsonDocument var0, @Nonnull Path var1) {
BsonValue var2 = var0.get("enabled");
if (var2 != null && var2.isBoolean()) {
class="kw">return var2.asBoolean().getValue();
}
LOGGER.at(Level.WARNING)
.log(
"%s does not say whether it was enabled, so the players it lists are the only ones that may connect. Use /whitelist disable to admit everyone",
var1
);
class="kw">return true;
}
@Nonnull
class="kw">static List<UUID> readPlayers(@Nonnull BsonDocument var0, @Nonnull Path var1) {
BsonArray var2 = var0.getArray("list", new BsonArray());
List var3 = new ArrayList<>(var2.size());
for (BsonValue var5 : var2) {
try {
var3.add(UUID.fromString(var5.asString().getValue()));
} catch (RuntimeException var7) {
((HytaleLogger.Api)LOGGER.at(Level.WARNING).withCause(var7)).log("Could not read an entry of %s, leaving it out: %s", var1, var5);
}
}
class="kw">return var3;
}
}