Mirror von
https://github.com/TheSilentPro/HeadDB.git
synchronisiert 2024-12-27 11:20:05 +01:00
close option and commands on purchase
Dieser Commit ist enthalten in:
Ursprung
aaef1d4056
Commit
a90023a26a
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>tsp.headdb</groupId>
|
<groupId>tsp.headdb</groupId>
|
||||||
<artifactId>HeadDB</artifactId>
|
<artifactId>HeadDB</artifactId>
|
||||||
<version>4.3.1</version>
|
<version>4.4.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -23,6 +23,8 @@ import java.util.UUID;
|
|||||||
*
|
*
|
||||||
* @author TheSilentPro
|
* @author TheSilentPro
|
||||||
*/
|
*/
|
||||||
|
// TODO: Optional instead of null.
|
||||||
|
// TODO: Remove stream, use loop.
|
||||||
public final class HeadAPI {
|
public final class HeadAPI {
|
||||||
|
|
||||||
private HeadAPI() {}
|
private HeadAPI() {}
|
||||||
|
@ -33,6 +33,7 @@ import javax.annotation.Nonnull;
|
|||||||
*
|
*
|
||||||
* @author TheSilentPro
|
* @author TheSilentPro
|
||||||
*/
|
*/
|
||||||
|
// TODO: Optionals instead of null.
|
||||||
public class HeadDatabase {
|
public class HeadDatabase {
|
||||||
|
|
||||||
private final JavaPlugin plugin;
|
private final JavaPlugin plugin;
|
||||||
@ -120,7 +121,8 @@ public class HeadDatabase {
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public List<Head> getHeads(Category category) {
|
public List<Head> getHeads(Category category) {
|
||||||
return heads.get(category) != null ? Collections.unmodifiableList(heads.get(category)) : new ArrayList<>();
|
List<Head> result = heads.get(category);
|
||||||
|
return result != null ? Collections.unmodifiableList(result) : Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -186,6 +188,7 @@ public class HeadDatabase {
|
|||||||
protected 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<>();
|
||||||
|
// TODO: gson
|
||||||
JSONParser parser = new JSONParser();
|
JSONParser parser = new JSONParser();
|
||||||
JSONArray array = (JSONArray) parser.parse(fetch(url));
|
JSONArray array = (JSONArray) parser.parse(fetch(url));
|
||||||
for (Object o : array) {
|
for (Object o : array) {
|
||||||
|
@ -31,6 +31,7 @@ import java.util.stream.Collectors;
|
|||||||
* Class for handling the "dirty" work
|
* Class for handling the "dirty" work
|
||||||
* such as inventories and economy.
|
* such as inventories and economy.
|
||||||
*/
|
*/
|
||||||
|
// TODO: Rewrite
|
||||||
public class InventoryUtils {
|
public class InventoryUtils {
|
||||||
|
|
||||||
private InventoryUtils() {}
|
private InventoryUtils() {}
|
||||||
@ -356,6 +357,10 @@ public class InventoryUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void purchaseHead(Player player, Head head, int amount, String category, String description) {
|
public static void purchaseHead(Player player, Head head, int amount, String category, String description) {
|
||||||
|
if (config.getBoolean("closeOnPurchase", false)) {
|
||||||
|
player.closeInventory();
|
||||||
|
}
|
||||||
|
|
||||||
Utils.sendMessage(player, String.format(localization.getMessage("processPayment"), amount, head.getName()));
|
Utils.sendMessage(player, String.format(localization.getMessage("processPayment"), amount, head.getName()));
|
||||||
processPayment(player, amount, category, description, result -> {
|
processPayment(player, amount, category, description, result -> {
|
||||||
if (Boolean.TRUE.equals(result)) {
|
if (Boolean.TRUE.equals(result)) {
|
||||||
@ -365,11 +370,25 @@ public class InventoryUtils {
|
|||||||
ItemStack item = head.getMenuItem();
|
ItemStack item = head.getMenuItem();
|
||||||
item.setAmount(amount);
|
item.setAmount(amount);
|
||||||
player.getInventory().addItem(item);
|
player.getInventory().addItem(item);
|
||||||
|
|
||||||
|
// Commands can only be ran on main thread
|
||||||
|
Bukkit.getScheduler().runTask(HeadDB.getInstance(), InventoryUtils::runPurchaseCommands);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void runPurchaseCommands() {
|
||||||
|
// Backwards compatability
|
||||||
|
if (!config.contains("commands.purchase")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String cmd : config.getStringList("commands.purchase")) {
|
||||||
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String replace(String message, int size, String category, String search, Player player) {
|
private static String replace(String message, int size, String category, String search, Player player) {
|
||||||
return message
|
return message
|
||||||
.replace("%size%", String.valueOf(size))
|
.replace("%size%", String.valueOf(size))
|
||||||
|
@ -8,6 +8,9 @@ localHeads: true
|
|||||||
# Permission: headdb.category.<category>
|
# Permission: headdb.category.<category>
|
||||||
requireCategoryPermission: false
|
requireCategoryPermission: false
|
||||||
|
|
||||||
|
# If enabled, the menu will close after purchasing a head (even if the purchase fails)
|
||||||
|
closeOnPurchase: false
|
||||||
|
|
||||||
# Hidden heads from the menu
|
# Hidden heads from the menu
|
||||||
hidden:
|
hidden:
|
||||||
enabled: false
|
enabled: false
|
||||||
@ -136,6 +139,12 @@ ui:
|
|||||||
volume: 1
|
volume: 1
|
||||||
pitch: 1
|
pitch: 1
|
||||||
|
|
||||||
|
# Command Configuration
|
||||||
|
commands:
|
||||||
|
# Commands to run ONLY if the purchase is successful.
|
||||||
|
purchase:
|
||||||
|
- ""
|
||||||
|
|
||||||
# If the original fetching fails and this is enabled,
|
# If the original fetching fails and this is enabled,
|
||||||
# the plugin will attempt to fetch the heads from an archive.
|
# the plugin will attempt to fetch the heads from an archive.
|
||||||
fallback: true
|
fallback: true
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren