Skip to content

Commit

Permalink
1.2.2 release
Browse files Browse the repository at this point in the history
- Should fix #19
  • Loading branch information
onebeastchris committed Dec 2, 2023
1 parent cd0d9b2 commit 4c84bd2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.onebeastchris.geyser.extension.pickpack;

import net.onebeastchris.geyser.extension.pickpack.Util.LanguageManager;
import net.onebeastchris.geyser.extension.pickpack.util.LanguageManager;
import org.geysermc.cumulus.component.ToggleComponent;
import org.geysermc.cumulus.form.CustomForm;
import org.geysermc.cumulus.form.ModalForm;
Expand Down Expand Up @@ -148,7 +148,7 @@ private String getPacks(String xuid) {
String name = loader.PACKS_INFO.get(packId).header().name();
packs.append(" - ").append(name).append("\n");
}
if (packs.length() == 0) packs.append(LanguageManager.getLocaleString(lang, "no_packs.warning"));
if (packs.isEmpty()) packs.append(LanguageManager.getLocaleString(lang, "no_packs.warning"));
return packs.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.onebeastchris.geyser.extension.pickpack;

import net.onebeastchris.geyser.extension.pickpack.Util.*;
import net.onebeastchris.geyser.extension.pickpack.util.*;
import org.geysermc.event.subscribe.Subscribe;
import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.api.connection.GeyserConnection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.onebeastchris.geyser.extension.pickpack.Util;
package net.onebeastchris.geyser.extension.pickpack.util;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.DeserializationFeature;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package net.onebeastchris.geyser.extension.pickpack.Util;
package net.onebeastchris.geyser.extension.pickpack.util;

import net.onebeastchris.geyser.extension.pickpack.PickPack;
import org.geysermc.geyser.api.pack.ResourcePack;

import java.io.*;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import static net.onebeastchris.geyser.extension.pickpack.PickPack.loader;
import static net.onebeastchris.geyser.extension.pickpack.PickPack.logger;
Expand All @@ -21,18 +18,12 @@ public static void save(List<String> list, String xuid) {

public static List<String> load(Path filepath) {
List<String> packs = readFromFile(filepath);
AtomicBoolean changed = new AtomicBoolean(false);
packs.forEach(packId -> {
ResourcePack pack = loader.getPack(packId);
if (pack == null) {
logger.debug("Could not find pack with UUID " + packId + " in cache, removing from file");
packs.remove(packId);
changed.set(true);
}
});
if (changed.get()) {

// Remove packs that no longer exist
if (packs.removeIf(packId -> loader.getPack(packId) == null)) {
saveToFile(packs, filepath);
}

return packs;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.onebeastchris.geyser.extension.pickpack.Util;
package net.onebeastchris.geyser.extension.pickpack.util;

import net.onebeastchris.geyser.extension.pickpack.PickPack;

Expand All @@ -14,7 +14,7 @@
public class LanguageManager {
public static String DEFAULT_LOCALE = "en_us";
public static final String EN_US_PROPERTIES = "en_US.properties";
public static Map<String, Properties> LOCALE_PROPERTIES = new HashMap<>();
public static final Map<String, Properties> LOCALE_PROPERTIES = new HashMap<>();

@SuppressWarnings("resource")
public static void init(Path languageFolder) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.onebeastchris.geyser.extension.pickpack.Util;
package net.onebeastchris.geyser.extension.pickpack.util;

import net.onebeastchris.geyser.extension.pickpack.PickPack;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand All @@ -20,7 +20,8 @@ public class PlayerStorage {
/**
* This is a map of XUIDs to a list of resource packs.
*/
public Map<String, List<String>> cache;
public final Map<String, List<String>> cache;

public PlayerStorage() {
cache = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.onebeastchris.geyser.extension.pickpack.Util;
package net.onebeastchris.geyser.extension.pickpack.util;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.pack.PackCodec;
import org.geysermc.geyser.api.pack.ResourcePack;
import org.geysermc.geyser.api.pack.ResourcePackManifest;
Expand All @@ -15,10 +16,11 @@
public class ResourcePackLoader {
public Map<String, ResourcePack> DEFAULT = new HashMap<>();
public Map<String, ResourcePack> OPTIONAL = new HashMap<>();
public Map<String, ResourcePackManifest> PACKS_INFO = new HashMap<>();
public final Map<String, ResourcePackManifest> PACKS_INFO = new HashMap<>();

private final Path optionalPacksPath;
private final Path defaultPacksPath;

public ResourcePackLoader(Path optionalPacksPath, Path defaultPacksPath) {
this.optionalPacksPath = optionalPacksPath;
this.defaultPacksPath = defaultPacksPath;
Expand All @@ -44,7 +46,7 @@ public void loadPacks() {
}
}

public ResourcePack getPack(String packId) {
public @Nullable ResourcePack getPack(String packId) {
return DEFAULT.getOrDefault(packId, OPTIONAL.get(packId));
}

Expand Down

0 comments on commit 4c84bd2

Please sign in to comment.