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

command placeholders

Dieser Commit ist enthalten in:
Silent 2022-05-18 23:01:43 +02:00
Ursprung fb17a1f351
Commit 4b699e1351
2 geänderte Dateien mit 19 neuen und 5 gelöschten Zeilen

12
pom.xml
Datei anzeigen

@ -6,7 +6,7 @@
<groupId>tsp.headdb</groupId> <groupId>tsp.headdb</groupId>
<artifactId>HeadDB</artifactId> <artifactId>HeadDB</artifactId>
<version>4.4.2</version> <version>4.4.3</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
@ -42,6 +42,10 @@
<id>CodeMC</id> <id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url> <url>https://repo.codemc.org/repository/maven-public</url>
</repository> </repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -79,6 +83,12 @@
<version>1.1.0</version> <version>1.1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.1</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

Datei anzeigen

@ -1,5 +1,6 @@
package tsp.headdb.inventory; package tsp.headdb.inventory;
import me.clip.placeholderapi.PlaceholderAPI;
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.configuration.file.FileConfiguration;
@ -181,6 +182,7 @@ public class InventoryUtils {
pane.open(player); pane.open(player);
} }
@SuppressWarnings("ConstantConditions")
public static void openDatabase(Player player) { public static void openDatabase(Player player) {
Inventory inventory = Bukkit.createInventory(null, 54, Inventory inventory = Bukkit.createInventory(null, 54,
replace(localization.getMessage("menu.main"), HeadAPI.getHeads().size(), "Main", "None", player)); replace(localization.getMessage("menu.main"), HeadAPI.getHeads().size(), "Main", "None", player));
@ -257,6 +259,7 @@ public class InventoryUtils {
return slot; return slot;
} }
@SuppressWarnings("ConstantConditions")
private static ItemStack getUIItem(String category, ItemStack item) { private static ItemStack getUIItem(String category, ItemStack item) {
// Try to use the cached item first. // Try to use the cached item first.
if (uiItem.containsKey(category)) return uiItem.get(category); if (uiItem.containsKey(category)) return uiItem.get(category);
@ -288,7 +291,7 @@ public class InventoryUtils {
return item; return item;
} }
@SuppressWarnings("ConstantConditions")
private static ItemStack buildButton(ItemStack item, String name, String... lore) { private static ItemStack buildButton(ItemStack item, String name, String... lore) {
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
meta.setDisplayName(Utils.colorize(name)); meta.setDisplayName(Utils.colorize(name));
@ -371,16 +374,17 @@ public class InventoryUtils {
player.getInventory().addItem(item); player.getInventory().addItem(item);
// Commands can only be ran on main thread // Commands can only be ran on main thread
Bukkit.getScheduler().runTask(HeadDB.getInstance(), InventoryUtils::runPurchaseCommands); Bukkit.getScheduler().runTask(HeadDB.getInstance(), () -> runPurchaseCommands(player));
} }
} }
}); });
} }
private static void runPurchaseCommands() { private static void runPurchaseCommands(Player player) {
for (String cmd : config.getStringList("commands.purchase")) { for (String cmd : config.getStringList("commands.purchase")) {
if (cmd.isEmpty()) continue; if (cmd.isEmpty()) continue;
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd); if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) PlaceholderAPI.setPlaceholders(player, cmd);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd.replace("%player%", player.getName()));
} }
} }