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

Sound customization & per category permission

Dieser Commit ist enthalten in:
Silent 2022-01-11 22:44:05 +01:00
Ursprung 9adafdc57b
Commit 1bd19efd20
5 geänderte Dateien mit 119 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -6,7 +6,7 @@
<groupId>tsp.headdb</groupId> <groupId>tsp.headdb</groupId>
<artifactId>HeadDB</artifactId> <artifactId>HeadDB</artifactId>
<version>3.0.2</version> <version>3.1.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HeadDB</name> <name>HeadDB</name>

Datei anzeigen

@ -93,7 +93,6 @@ public class InventoryUtils {
return; return;
} }
if (e.getClick() == ClickType.RIGHT) { if (e.getClick() == ClickType.RIGHT) {
player.closeInventory();
Utils.sendMessage(player, "&cLocal heads can not be added to favorites!"); Utils.sendMessage(player, "&cLocal heads can not be added to favorites!");
} }
})); }));
@ -119,6 +118,7 @@ public class InventoryUtils {
HeadAPI.removeFavoriteHead(player.getUniqueId(), head.getValue()); HeadAPI.removeFavoriteHead(player.getUniqueId(), head.getValue());
openFavoritesMenu(player); openFavoritesMenu(player);
Utils.sendMessage(player, "&7Removed &e" + head.getName() + " &7from favorites."); Utils.sendMessage(player, "&7Removed &e" + head.getName() + " &7from favorites.");
Utils.playSound(player, "removeFavorite");
} }
})); }));
} }
@ -140,8 +140,15 @@ public class InventoryUtils {
purchaseHead(player, head, 1, head.getCategory().getName(), head.getName()); purchaseHead(player, head, 1, head.getCategory().getName(), head.getName());
} }
if (e.getClick() == ClickType.RIGHT) { if (e.getClick() == ClickType.RIGHT) {
if (!player.hasPermission("headdb.favorites")) {
Utils.sendMessage(player, "&cYou do not have permission for favorites!");
Utils.playSound(player, "noPermission");
return;
}
HeadAPI.addFavoriteHead(player.getUniqueId(), head.getValue()); HeadAPI.addFavoriteHead(player.getUniqueId(), head.getValue());
Utils.sendMessage(player, "&7Added &e" + head.getName() + " &7to favorites."); Utils.sendMessage(player, "&7Added &e" + head.getName() + " &7to favorites.");
Utils.playSound(player, "addFavorite");
} }
})); }));
} }
@ -164,8 +171,15 @@ public class InventoryUtils {
purchaseHead(player, head, 1, head.getCategory().getName(), head.getName()); purchaseHead(player, head, 1, head.getCategory().getName(), head.getName());
} }
if (e.getClick() == ClickType.RIGHT) { if (e.getClick() == ClickType.RIGHT) {
if (!player.hasPermission("headdb.favorites")) {
Utils.sendMessage(player, "&cYou do not have permission for favorites!");
Utils.playSound(player, "noPermission");
return;
}
HeadAPI.addFavoriteHead(player.getUniqueId(), head.getValue()); HeadAPI.addFavoriteHead(player.getUniqueId(), head.getValue());
Utils.sendMessage(player, "&7Added &e" + head.getName() + " &7to favorites."); Utils.sendMessage(player, "&7Added &e" + head.getName() + " &7to favorites.");
Utils.playSound(player, "addFavorite");
} }
})); }));
} }
@ -187,8 +201,15 @@ public class InventoryUtils {
purchaseHead(player, head, 1, head.getCategory().getName(), head.getName()); purchaseHead(player, head, 1, head.getCategory().getName(), head.getName());
} }
if (e.getClick() == ClickType.RIGHT) { if (e.getClick() == ClickType.RIGHT) {
if (!player.hasPermission("headdb.favorites")) {
Utils.sendMessage(player, "&cYou do not have permission for favorites!");
Utils.playSound(player, "noPermission");
return;
}
HeadAPI.addFavoriteHead(player.getUniqueId(), head.getValue()); HeadAPI.addFavoriteHead(player.getUniqueId(), head.getValue());
Utils.sendMessage(player, "&7Added &e" + head.getName() + " &7to favorites."); Utils.sendMessage(player, "&7Added &e" + head.getName() + " &7to favorites.");
Utils.playSound(player, "addFavorite");
} }
})); }));
} }
@ -287,6 +308,7 @@ public class InventoryUtils {
// Don't mention receiving it for free in this case, since it is always free. // Don't mention receiving it for free in this case, since it is always free.
if (economy == null) { if (economy == null) {
Utils.sendMessage(player, String.format("&7You received &e%d &7x &e%s&7!", amount, description)); Utils.sendMessage(player, String.format("&7You received &e%d &7x &e%s&7!", amount, description));
Utils.playSound(player, "noEconomy");
return true; return true;
} }
@ -296,20 +318,24 @@ public class InventoryUtils {
if (cost > 0) { if (cost > 0) {
if (economy.has(player, cost)) { if (economy.has(player, cost)) {
economy.withdrawPlayer(player, cost); economy.withdrawPlayer(player, cost);
Utils.sendMessage(player, String.format("&7You purchased &e%d &7x &e%s &7for &e%.2f %s&7!", amount, description, cost, economy.currencyNamePlural())); Utils.sendMessage(player, String.format("&7You purchased &e%d &7x &e%s &7for &e%.2f&7!", amount, description, cost));
Utils.playSound(player, "paid");
return true; return true;
} }
Utils.sendMessage(player, String.format("&7You do not have enough &e%s &cto purchase &e%d &cx &e%s&7.", economy.currencyNamePlural(), amount, description)); Utils.sendMessage(player, String.format("&cYou do not have enough to purchase &e%d &cx &e%s&7.", amount, description));
Utils.playSound(player, "unavailable");
return false; return false;
} }
// Otherwise, the item is free. // Otherwise, the item is free.
Utils.sendMessage(player, String.format("&7You received &e%d &7x &e%s &7for &efree&7!", amount, description)); Utils.sendMessage(player, String.format("&7You received &e%d &7x &e%s &7for &efree&7!", amount, description));
Utils.playSound(player, "free");
return true; return true;
} }
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 (!processPayment(player, amount, category, description)) return; if (!processPayment(player, amount, category, description)) return;
PlayerHeadPurchaseEvent event = new PlayerHeadPurchaseEvent(player, head, getCategoryCost(player, category)); PlayerHeadPurchaseEvent event = new PlayerHeadPurchaseEvent(player, head, getCategoryCost(player, category));
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {

Datei anzeigen

@ -40,23 +40,34 @@ public class MenuListener implements Listener {
String name = ChatColor.stripColor(item.getItemMeta().getDisplayName().toLowerCase()); String name = ChatColor.stripColor(item.getItemMeta().getDisplayName().toLowerCase());
if (name.equalsIgnoreCase("favorites")) { if (name.equalsIgnoreCase("favorites")) {
if (!player.hasPermission("headdb.favorites")) { if (!player.hasPermission("headdb.favorites")) {
Utils.sendMessage(player, "&cYou do not have permission for favorites!");
player.closeInventory(); player.closeInventory();
Utils.sendMessage(player, "&cYou do not have permission for favorites!");
Utils.playSound(player, "noPermission");
return; return;
} }
InventoryUtils.openFavoritesMenu(player); InventoryUtils.openFavoritesMenu(player);
Utils.playSound(player, "open");
return; return;
} }
if (name.equalsIgnoreCase("local")) { if (name.equalsIgnoreCase("local")) {
if (!player.hasPermission("headdb.local")) { if (!player.hasPermission("headdb.local")) {
Utils.sendMessage(player, "&cYou do not have permission to view local heads!");
player.closeInventory(); player.closeInventory();
Utils.sendMessage(player, "&cYou do not have permission to view local heads!");
Utils.playSound(player, "noPermission");
return; return;
} }
InventoryUtils.openLocalMenu(player); InventoryUtils.openLocalMenu(player);
Utils.playSound(player, "open");
return; return;
} }
if (name.equalsIgnoreCase("search")) { if (name.equalsIgnoreCase("search")) {
if (!player.hasPermission("headdb.search")) {
player.closeInventory();
Utils.sendMessage(player, "&cYou do not have permission for the search function!");
Utils.playSound(player, "noPermission");
return;
}
new AnvilGUI.Builder() new AnvilGUI.Builder()
.onComplete((p, text) -> { .onComplete((p, text) -> {
InventoryUtils.openSearchDatabase(p, text); InventoryUtils.openSearchDatabase(p, text);
@ -66,12 +77,20 @@ public class MenuListener implements Listener {
.text("Name...") .text("Name...")
.plugin(HeadDB.getInstance()) .plugin(HeadDB.getInstance())
.open(player); .open(player);
Utils.playSound(player, "open");
return; return;
} }
Category category = Category.getByName(name); Category category = Category.getByName(name);
if (category != null) { if (category != null) {
if (HeadDB.getInstance().getConfig().getBoolean("requireCategoryPermission") && !player.hasPermission("headdb.category." + category)) {
Utils.sendMessage(player, "&cYou do not have permission for this category! (&e" + category.getName() + "&c)");
Utils.playSound(player, "noPermission");
return;
}
Utils.playSound(player, "open");
HeadAPI.openCategoryDatabase(player, category); HeadAPI.openCategoryDatabase(player, category);
} }
} }

Datei anzeigen

@ -1,12 +1,17 @@
package tsp.headdb.util; package tsp.headdb.util;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import tsp.headdb.HeadDB;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class Utils { public class Utils {
private static final FileConfiguration config = HeadDB.getInstance().getConfig();
public static final Pattern UUID_PATTERN = Pattern.compile("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"); public static final Pattern UUID_PATTERN = Pattern.compile("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}");
/** /**
@ -19,6 +24,18 @@ public class Utils {
return UUID_PATTERN.matcher(uuid).matches(); return UUID_PATTERN.matcher(uuid).matches();
} }
public static void playSound(Player player, String key) {
// Check if sound is enabled
if (!config.getBoolean("ui.sound.enabled")) {
return;
}
player.playSound(player.getLocation(),
Sound.valueOf(config.getString("ui.sound." + key + ".name")),
(float) config.getDouble("ui.sound." + key + ".volume"),
(float) config.getDouble("ui.sound." + key + ".pitch"));
}
public static void sendMessage(CommandSender sender, String message) { public static void sendMessage(CommandSender sender, String message) {
sender.sendMessage(colorize(message)); sender.sendMessage(colorize(message));
} }

Datei anzeigen

@ -4,6 +4,10 @@ refresh: 3600
# If local heads should be enabled. Only starts keeping track of joined players when enabled! # If local heads should be enabled. Only starts keeping track of joined players when enabled!
localHeads: true localHeads: true
# If enabled categories will require a permission to be used
# Permission: headdb.category.<category>
requireCategoryPermission: false
# Economy options # Economy options
economy: economy:
enable: false enable: false
@ -67,6 +71,52 @@ ui:
# Item used to fill unused slots in the categories menu. AIR is supported. You can use head: instead of item: here. # Item used to fill unused slots in the categories menu. AIR is supported. You can use head: instead of item: here.
fill: fill:
item: BLACK_STAINED_GLASS_PANE item: BLACK_STAINED_GLASS_PANE
sound:
# Whether the sounds should be played
enabled: true
# Played when a head is taken with no economy plugin
noEconomy:
# The name of the sound.
# Must be one from: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html
name: ENTITY_EXPERIENCE_ORB_PICKUP
volume: 1
pitch: 1
# Played when the player doesn't have permission for the menu
noPermission:
name: BLOCK_ANVIL_BREAK
volume: 1
pitch: 1
# Played when they purchase a head
paid:
name: ENTITY_EXPERIENCE_ORB_PICKUP
volume: 1
pitch: 1
# Played when the head is free
free:
name: ENTITY_EXPERIENCE_ORB_PICKUP
volume: 1
pitch: 1
# Played when the player does not have enough funds for the head
unavailable:
name: BLOCK_ANVIL_BREAK
volume: 1
pitch: 1
# Played when a category/menu is opened
open:
name: ENTITY_EXPERIENCE_ORB_PICKUP
volume: 1
pitch: 1
# Played when a head is added to the favorites list
addFavorite:
name: ENTITY_EXPERIENCE_ORB_PICKUP
volume: 1
pitch: 1
# Played when a head is removed to from favorites list
removeFavorite:
name: BLOCK_ANVIL_BREAK
volume: 1
pitch: 1
# Debug Mode # Debug Mode
debug: false debug: false