版本更新至 3.82

新增:/tlib sounds 命令打开音效库
This commit is contained in:
坏黑 2018-03-18 21:28:46 +08:00
parent f9a405a5ca
commit 6aa5dbc5bd
5 changed files with 153 additions and 0 deletions

View File

@ -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);

View File

@ -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指令错误");
}

View File

@ -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更改变量");

View File

@ -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]));
}
}
}
}

View File

@ -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<Sound> 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<Integer, Sound> SOUNDS_DATA = new HashMap<>();
public SoundLibraryHolder(int page) {
this.PAGE = page;
}
@Override
public Inventory getInventory() {
return null;
}
}
}