Mirror von
https://github.com/TheSilentPro/HeadDB.git
synchronisiert 2024-12-26 19:02:39 +01:00
4.3 Add hidden option
Dieser Commit ist enthalten in:
Ursprung
2aed521382
Commit
c21a8c68e7
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>tsp.headdb</groupId>
|
||||
<artifactId>HeadDB</artifactId>
|
||||
<version>4.2.4</version>
|
||||
<version>4.3.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
|
@ -13,6 +13,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Represents a Head that a player can obtain via the database
|
||||
@ -21,6 +22,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class Head {
|
||||
|
||||
public static final Pattern SPLIT = Pattern.compile(",");
|
||||
private String name;
|
||||
private UUID uuid;
|
||||
private String value;
|
||||
@ -121,7 +123,7 @@ public class Head {
|
||||
}
|
||||
|
||||
public Head tags(String tags) {
|
||||
this.tags = Arrays.asList(tags.split(","));
|
||||
this.tags = Arrays.asList(SPLIT.split(tags));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ public class HeadDatabase {
|
||||
* @throws IOException 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();
|
||||
List<Head> headList = new ArrayList<>();
|
||||
JSONParser parser = new JSONParser();
|
||||
@ -199,14 +199,13 @@ public class HeadDatabase {
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
Head head = new Head(nextId)
|
||||
Head head = new Head(nextId++)
|
||||
.name(obj.get("name").toString())
|
||||
.uniqueId(uuid)
|
||||
.value(obj.get("value").toString())
|
||||
.tags(obj.get("tags") != null ? obj.get("tags").toString() : "None")
|
||||
.category(category);
|
||||
|
||||
nextId++;
|
||||
headList.add(head);
|
||||
}
|
||||
|
||||
@ -223,7 +222,7 @@ public class HeadDatabase {
|
||||
* @return JSON-string response
|
||||
* @throws IOException error
|
||||
*/
|
||||
private String fetch(String url) throws IOException {
|
||||
protected String fetch(String url) throws IOException {
|
||||
String line;
|
||||
StringBuilder response = new StringBuilder();
|
||||
|
||||
|
@ -2,6 +2,7 @@ package tsp.headdb.inventory;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -24,6 +25,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Class for handling the "dirty" work
|
||||
@ -32,6 +34,7 @@ import java.util.function.Consumer;
|
||||
public class InventoryUtils {
|
||||
|
||||
private InventoryUtils() {}
|
||||
private static final FileConfiguration config = HeadDB.getInstance().getConfig();
|
||||
|
||||
private static final Localization localization = HeadDB.getInstance().getLocalization();
|
||||
private static final Map<String, Integer> uiLocation = new HashMap<>();
|
||||
@ -62,7 +65,7 @@ public class InventoryUtils {
|
||||
}
|
||||
|
||||
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,
|
||||
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) {
|
||||
List<Head> heads = HeadAPI.getHeadsByName(search);
|
||||
List<Head> heads = filter(HeadAPI.getHeadsByName(search));
|
||||
|
||||
PagedPane pane = new PagedPane(4, 6,
|
||||
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) {
|
||||
List<Head> heads = HeadAPI.getHeadsByTag(tag);
|
||||
List<Head> heads = filter(HeadAPI.getHeadsByTag(tag));
|
||||
|
||||
PagedPane pane = new PagedPane(4, 6,
|
||||
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) {
|
||||
List<Head> heads = HeadAPI.getHeads(category);
|
||||
List<Head> heads = filter(HeadAPI.getHeads(category));
|
||||
|
||||
PagedPane pane = new PagedPane(4, 6,
|
||||
replace(localization.getMessage("menu.category"), heads.size(), category.getName(), "None", player));
|
||||
@ -375,4 +378,27 @@ public class InventoryUtils {
|
||||
.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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,18 @@ localHeads: true
|
||||
# Permission: headdb.category.<category>
|
||||
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:
|
||||
enable: false
|
||||
@ -16,7 +28,7 @@ economy:
|
||||
# Providers like treasury support multiple currencies
|
||||
# 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
|
||||
currency: ''
|
||||
currency: ""
|
||||
cost:
|
||||
alphabet: 100
|
||||
animals: 100
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren