From 6aa5dbc5bd83270247732019e69dc0bf289b9e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Sun, 18 Mar 2018 21:28:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=E8=87=B3?= =?UTF-8?q?=203.82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增:/tlib sounds 命令打开音效库 --- src/main/java/me/skymc/taboolib/Main.java | 3 + .../skymc/taboolib/commands/MainCommands.java | 4 + .../taboolib/commands/sub/HelpCommand.java | 1 + .../commands/sub/sounds/SoundsCommand.java | 31 +++++ .../sounds/listener/SoundsLibraryPatch.java | 114 ++++++++++++++++++ 5 files changed, 153 insertions(+) create mode 100644 src/main/java/me/skymc/taboolib/commands/sub/sounds/SoundsCommand.java create mode 100644 src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java diff --git a/src/main/java/me/skymc/taboolib/Main.java b/src/main/java/me/skymc/taboolib/Main.java index 1a4658b..4a28b26 100644 --- a/src/main/java/me/skymc/taboolib/Main.java +++ b/src/main/java/me/skymc/taboolib/Main.java @@ -18,6 +18,7 @@ import me.skymc.taboolib.client.LogClient; import me.skymc.taboolib.commands.MainCommands; import me.skymc.taboolib.commands.language.Language2Command; import me.skymc.taboolib.commands.sub.itemlist.listener.ItemLibraryPatch; +import me.skymc.taboolib.commands.sub.sounds.listener.SoundsLibraryPatch; import me.skymc.taboolib.database.PlayerDataManager; import me.skymc.taboolib.database.GlobalDataManager; import me.skymc.taboolib.economy.EcoUtils; @@ -307,6 +308,8 @@ public class Main extends JavaPlugin implements Listener { getServer().getPluginManager().registerEvents(new ListenerPluginDisable(), this); getServer().getPluginManager().registerEvents(new PlayerDataManager(), this); getServer().getPluginManager().registerEvents(new ItemLibraryPatch(), this); + getServer().getPluginManager().registerEvents(new SoundsLibraryPatch(), this); + if (TabooLib.getVerint() > 10700) { getServer().getPluginManager().registerEvents(new EntityUtils(), this); diff --git a/src/main/java/me/skymc/taboolib/commands/MainCommands.java b/src/main/java/me/skymc/taboolib/commands/MainCommands.java index 6682b78..febe076 100644 --- a/src/main/java/me/skymc/taboolib/commands/MainCommands.java +++ b/src/main/java/me/skymc/taboolib/commands/MainCommands.java @@ -27,6 +27,7 @@ import me.skymc.taboolib.commands.sub.VariableSetCommand; import me.skymc.taboolib.commands.sub.cycle.CycleCommand; import me.skymc.taboolib.commands.sub.itemlist.ItemListCommand; import me.skymc.taboolib.commands.sub.shell.ShellCommand; +import me.skymc.taboolib.commands.sub.sounds.SoundsCommand; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.message.MsgUtils; @@ -84,6 +85,9 @@ public class MainCommands implements CommandExecutor{ else if (args[0].equalsIgnoreCase("cycle") || args[0].equalsIgnoreCase("c")) { new CycleCommand(sender, args); } + else if (args[0].equalsIgnoreCase("sounds")) { + new SoundsCommand(sender, args); + } else { MsgUtils.send(sender, "&4指令错误"); } diff --git a/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java index dc18f75..6831cb9 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/HelpCommand.java @@ -32,6 +32,7 @@ public class HelpCommand extends SubCommand { helps.put("/taboolib potions", "§e查看所有药水"); helps.put("/taboolib flags", "§e查看所有标签"); helps.put("/taboolib slots", "§e查看所有部位"); + helps.put("/taboolib sounds", "§e查看所有音效"); helps.put("§b", null); helps.put("/taboolib getvariable §8[§7-s|a§8] §8[§7键§8]", "§e查看变量"); helps.put("/taboolib setvariable §8[§7-s|a§8] §8[§7键§8] §8[§7值§8]", "§e更改变量"); diff --git a/src/main/java/me/skymc/taboolib/commands/sub/sounds/SoundsCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/sounds/SoundsCommand.java new file mode 100644 index 0000000..4e2762e --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/sub/sounds/SoundsCommand.java @@ -0,0 +1,31 @@ +package me.skymc.taboolib.commands.sub.sounds; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.commands.sub.sounds.listener.SoundsLibraryPatch; +import me.skymc.taboolib.other.NumberUtils; + +/** + * @author sky + * @since 2018-03-18 21:02:26 + */ +public class SoundsCommand extends SubCommand { + + /** + * @param sender + * @param args + */ + public SoundsCommand(CommandSender sender, String[] args) { + super(sender, args); + if (isPlayer()) { + if (args.length == 1) { + SoundsLibraryPatch.openInventory((Player) sender, 1); + } + else { + SoundsLibraryPatch.openInventory((Player) sender, NumberUtils.getInteger(args[1])); + } + } + } +} diff --git a/src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java b/src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java new file mode 100644 index 0000000..2268189 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/commands/sub/sounds/listener/SoundsLibraryPatch.java @@ -0,0 +1,114 @@ +package me.skymc.taboolib.commands.sub.sounds.listener; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.skymc.taboolib.inventory.InventoryUtil; +import me.skymc.taboolib.inventory.ItemUtils; + +/** + * @author sky + * @since 2018年2月4日 下午4:35:00 + */ +public class SoundsLibraryPatch implements Listener { + + @EventHandler + public void inventoryClick(InventoryClickEvent e) { + if (e.getInventory().getHolder() instanceof SoundLibraryHolder) { + e.setCancelled(true); + + if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR) || e.getRawSlot() >= e.getInventory().getSize()) { + return; + } + + if (e.getRawSlot() == 47) { + openInventory((Player) e.getWhoClicked(), ((SoundLibraryHolder) e.getInventory().getHolder()).PAGE - 1); + } + else if (e.getRawSlot() == 51) { + openInventory((Player) e.getWhoClicked(), ((SoundLibraryHolder) e.getInventory().getHolder()).PAGE + 1); + } + else { + Sound sound = ((SoundLibraryHolder) e.getInventory().getHolder()).SOUNDS_DATA.get(e.getRawSlot()); + if (e.getClick().isLeftClick()) { + ((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 1f); + } + else { + ((Player) e.getWhoClicked()).playSound(e.getWhoClicked().getLocation(), sound, 1f, 2f); + } + } + } + } + + /** + * 打开物品库界面 + * + * @param player + * @param page + */ + public static void openInventory(Player player, int page) { + SoundLibraryHolder holder = new SoundLibraryHolder(page); + Inventory inventory = Bukkit.createInventory(holder, 54, "音效库 " + page); + + int loop = 0; + Iterator iterator = Arrays.asList(Sound.values()).iterator(); + while (iterator.hasNext()) { + Sound sound = iterator.next(); + if (loop >= (page - 1) * 28) { + if (loop < page * 28) { + int slot = InventoryUtil.SLOT_OF_CENTENTS.get(loop - ((page - 1) * 28)); + ItemStack item = new ItemStack(Material.MAP); { + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName("§f" + sound.name()); + meta.setLore(Arrays.asList("", "§f左键: §71 音调", "§f左键: §72 音调")); + item.setItemMeta(meta); + inventory.setItem(slot, item); + } + holder.SOUNDS_DATA.put(slot, sound); + } + else { + break; + } + } + loop++; + } + + if (page > 1) { + inventory.setItem(47, ItemUtils.setName(new ItemStack(Material.ARROW), "§f上一页")); + } + if (((int) Math.ceil(Sound.values().length / 28D)) > page) { + inventory.setItem(51, ItemUtils.setName(new ItemStack(Material.ARROW), "§f下一页")); + } + player.openInventory(inventory); + } + + public static class SoundLibraryHolder implements InventoryHolder { + + public final int PAGE; + public final HashMap SOUNDS_DATA = new HashMap<>(); + + public SoundLibraryHolder(int page) { + this.PAGE = page; + } + + @Override + public Inventory getInventory() { + return null; + } + } +}