3
0
Mirror von https://github.com/TheSilentPro/HeadDB.git synchronisiert 2024-12-27 11:20:05 +01:00

4.3 Add hidden option

Dieser Commit ist enthalten in:
Silent 2022-03-30 01:12:46 +02:00
Ursprung 2aed521382
Commit c21a8c68e7
5 geänderte Dateien mit 50 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -6,7 +6,7 @@
<groupId>tsp.headdb</groupId> <groupId>tsp.headdb</groupId>
<artifactId>HeadDB</artifactId> <artifactId>HeadDB</artifactId>
<version>4.2.4</version> <version>4.3.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>

Datei anzeigen

@ -13,6 +13,7 @@ import java.lang.reflect.Field;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Pattern;
/** /**
* Represents a Head that a player can obtain via the database * Represents a Head that a player can obtain via the database
@ -21,6 +22,7 @@ import java.util.UUID;
*/ */
public class Head { public class Head {
public static final Pattern SPLIT = Pattern.compile(",");
private String name; private String name;
private UUID uuid; private UUID uuid;
private String value; private String value;
@ -121,7 +123,7 @@ public class Head {
} }
public Head tags(String tags) { public Head tags(String tags) {
this.tags = Arrays.asList(tags.split(",")); this.tags = Arrays.asList(SPLIT.split(tags));
return this; return this;
} }

Datei anzeigen

@ -183,7 +183,7 @@ public class HeadDatabase {
* @throws IOException error * @throws IOException error
* @throws ParseException error * @throws ParseException error
*/ */
private List<Head> gather(String url, Category category) throws IOException, ParseException { protected List<Head> gather(String url, Category category) throws IOException, ParseException {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
List<Head> headList = new ArrayList<>(); List<Head> headList = new ArrayList<>();
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
@ -199,14 +199,13 @@ public class HeadDatabase {
uuid = UUID.randomUUID(); uuid = UUID.randomUUID();
} }
Head head = new Head(nextId) Head head = new Head(nextId++)
.name(obj.get("name").toString()) .name(obj.get("name").toString())
.uniqueId(uuid) .uniqueId(uuid)
.value(obj.get("value").toString()) .value(obj.get("value").toString())
.tags(obj.get("tags") != null ? obj.get("tags").toString() : "None") .tags(obj.get("tags") != null ? obj.get("tags").toString() : "None")
.category(category); .category(category);
nextId++;
headList.add(head); headList.add(head);
} }
@ -223,7 +222,7 @@ public class HeadDatabase {
* @return JSON-string response * @return JSON-string response
* @throws IOException error * @throws IOException error
*/ */
private String fetch(String url) throws IOException { protected String fetch(String url) throws IOException {
String line; String line;
StringBuilder response = new StringBuilder(); StringBuilder response = new StringBuilder();

Datei anzeigen

@ -2,6 +2,7 @@ package tsp.headdb.inventory;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
@ -24,6 +25,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Collectors;
/** /**
* Class for handling the "dirty" work * Class for handling the "dirty" work
@ -32,6 +34,7 @@ import java.util.function.Consumer;
public class InventoryUtils { public class InventoryUtils {
private InventoryUtils() {} private InventoryUtils() {}
private static final FileConfiguration config = HeadDB.getInstance().getConfig();
private static final Localization localization = HeadDB.getInstance().getLocalization(); private static final Localization localization = HeadDB.getInstance().getLocalization();
private static final Map<String, Integer> uiLocation = new HashMap<>(); private static final Map<String, Integer> uiLocation = new HashMap<>();
@ -62,7 +65,7 @@ public class InventoryUtils {
} }
public static void openFavoritesMenu(Player player) { public static void openFavoritesMenu(Player player) {
List<Head> heads = HeadAPI.getFavoriteHeads(player.getUniqueId()); List<Head> heads = config.getBoolean("hidden.hideFavorites") ? filter(HeadAPI.getFavoriteHeads(player.getUniqueId())) : HeadAPI.getFavoriteHeads(player.getUniqueId());
PagedPane pane = new PagedPane(4, 6, PagedPane pane = new PagedPane(4, 6,
replace(localization.getMessage("menu.favorites"), heads.size(), "Favorites", "None", player)); replace(localization.getMessage("menu.favorites"), heads.size(), "Favorites", "None", player));
@ -87,7 +90,7 @@ public class InventoryUtils {
} }
public static PagedPane openSearchDatabase(Player player, String search) { public static PagedPane openSearchDatabase(Player player, String search) {
List<Head> heads = HeadAPI.getHeadsByName(search); List<Head> heads = filter(HeadAPI.getHeadsByName(search));
PagedPane pane = new PagedPane(4, 6, PagedPane pane = new PagedPane(4, 6,
replace(localization.getMessage("menu.search"), heads.size(), "None", search, player)); replace(localization.getMessage("menu.search"), heads.size(), "None", search, player));
@ -118,7 +121,7 @@ public class InventoryUtils {
} }
public static void openTagSearchDatabase(Player player, String tag) { public static void openTagSearchDatabase(Player player, String tag) {
List<Head> heads = HeadAPI.getHeadsByTag(tag); List<Head> heads = filter(HeadAPI.getHeadsByTag(tag));
PagedPane pane = new PagedPane(4, 6, PagedPane pane = new PagedPane(4, 6,
replace(localization.getMessage("menu.tagSearch"), heads.size(), "None", tag, player)); replace(localization.getMessage("menu.tagSearch"), heads.size(), "None", tag, player));
@ -148,7 +151,7 @@ public class InventoryUtils {
} }
public static void openCategoryDatabase(Player player, Category category) { public static void openCategoryDatabase(Player player, Category category) {
List<Head> heads = HeadAPI.getHeads(category); List<Head> heads = filter(HeadAPI.getHeads(category));
PagedPane pane = new PagedPane(4, 6, PagedPane pane = new PagedPane(4, 6,
replace(localization.getMessage("menu.category"), heads.size(), category.getName(), "None", player)); replace(localization.getMessage("menu.category"), heads.size(), category.getName(), "None", player));
@ -375,4 +378,27 @@ public class InventoryUtils {
.replace("%player%", player.getName()); .replace("%player%", player.getName());
} }
private static List<Head> filter(List<Head> source) {
if (!config.getBoolean("hidden.enabled")) {
return source;
}
List<Head> result = new ArrayList<>();
List<String> tags = config.getStringList("hidden.tags");
List<String> names = config.getStringList("hidden.names");
for (Head head : source) {
if (!names.contains(head.getName()) && !contains(head.getTags(), tags)) {
result.add(head);
}
}
return result;
}
private static boolean contains(List<String> list1, List<String> list2) {
return list1.stream().anyMatch(list2.stream().collect(Collectors.toSet())::contains);
}
} }

Datei anzeigen

@ -8,6 +8,18 @@ localHeads: true
# Permission: headdb.category.<category> # Permission: headdb.category.<category>
requireCategoryPermission: false requireCategoryPermission: false
# Hidden heads from the menu
hidden:
enabled: false
# If enabled it will also hide any heads matching these tags in the favorites menu
hideFavorites: true
# If the head name matches any of the listen words it will be hidden (case-sensitive)
names:
- ""
# If the head has one of the listed tags it will be hidden
tags:
- ""
# Economy options # Economy options
economy: economy:
enable: false enable: false
@ -16,7 +28,7 @@ economy:
# Providers like treasury support multiple currencies # Providers like treasury support multiple currencies
# Set the ID of the one used for head purchasing below. # Set the ID of the one used for head purchasing below.
# Leave empty to use the primary currency or if the provider does not support multiple currencies # Leave empty to use the primary currency or if the provider does not support multiple currencies
currency: '' currency: ""
cost: cost:
alphabet: 100 alphabet: 100
animals: 100 animals: 100