mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-23 04:47:34 +01:00
CustomSound Stat and previous page support
Still little wip
This commit is contained in:
parent
bab3a0eee7
commit
cd806985f2
@ -45,6 +45,7 @@ import net.Indyuce.mmoitems.gui.PluginInventory;
|
||||
import net.Indyuce.mmoitems.gui.listener.GuiListener;
|
||||
import net.Indyuce.mmoitems.listener.AdvancedWorkbenchListener;
|
||||
import net.Indyuce.mmoitems.listener.CustomDurability;
|
||||
import net.Indyuce.mmoitems.listener.CustomSoundListener;
|
||||
import net.Indyuce.mmoitems.listener.DisableInteractions;
|
||||
import net.Indyuce.mmoitems.listener.ElementListener;
|
||||
import net.Indyuce.mmoitems.listener.ItemUse;
|
||||
@ -155,6 +156,7 @@ public class MMOItems extends JavaPlugin {
|
||||
Bukkit.getPluginManager().registerEvents(new ItemUse(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new MitigationListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new CustomSoundListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new CustomDurability(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new DisableInteractions(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new GuiListener(), this);
|
||||
|
38
src/main/java/net/Indyuce/mmoitems/api/CustomSound.java
Normal file
38
src/main/java/net/Indyuce/mmoitems/api/CustomSound.java
Normal file
@ -0,0 +1,38 @@
|
||||
package net.Indyuce.mmoitems.api;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public enum CustomSound {
|
||||
ON_ATTACK(Material.IRON_SWORD, 19, "On Attack", new String[] { "Plays when attacking an entity." }),
|
||||
ON_RIGHT_CLICK(Material.STONE_HOE, 22, "On Right Click", new String[] { "Plays when item is right-clicked." }),
|
||||
ON_BLOCK_BREAK(Material.STONE, 25, "On Block Break", new String[] { "Plays when a block is broken with the item." });
|
||||
|
||||
private ItemStack item;
|
||||
private String name;
|
||||
private String[] lore;
|
||||
private int slot;
|
||||
|
||||
private CustomSound(Material material, int slot, String name, String[] lore) {
|
||||
this.item = new ItemStack(material);
|
||||
this.name = name;
|
||||
this.lore = lore;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String[] getLore() {
|
||||
return lore;
|
||||
}
|
||||
|
||||
public int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ public abstract class EditionInventory extends PluginInventory {
|
||||
protected Type type;
|
||||
protected String id;
|
||||
|
||||
private int prevPage;
|
||||
private ItemStack cached;
|
||||
|
||||
public EditionInventory(Player player, Type type, String id) {
|
||||
@ -90,4 +91,13 @@ public abstract class EditionInventory extends PluginInventory {
|
||||
inv.setItem(2, get);
|
||||
inv.setItem(4, getCachedItem());
|
||||
}
|
||||
|
||||
public void open(int page) {
|
||||
prevPage = page;
|
||||
open();
|
||||
}
|
||||
|
||||
public int getPreviousPage() {
|
||||
return prevPage;
|
||||
}
|
||||
}
|
||||
|
@ -117,4 +117,7 @@ public class ItemEdition extends EditionInventory {
|
||||
if (!tag.equals(""))
|
||||
MMOItems.plugin.getStats().get(tag).whenClicked(this, event);
|
||||
}
|
||||
|
||||
public ItemEdition onPage(int value)
|
||||
{ page = value; return this; }
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
package net.Indyuce.mmoitems.gui.edition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.ConfigFile;
|
||||
import net.Indyuce.mmoitems.api.CustomSound;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.edition.StatEdition;
|
||||
import net.Indyuce.mmoitems.api.util.AltChar;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
|
||||
public class SoundsEdition extends EditionInventory {
|
||||
public static Map<Integer, String> correspondingSlot = new HashMap<>();
|
||||
|
||||
public SoundsEdition(Player player, Type type, String id) {
|
||||
super(player, type, id);
|
||||
|
||||
if (correspondingSlot.isEmpty()) {
|
||||
for (CustomSound sound : CustomSound.values()) {
|
||||
correspondingSlot.put(sound.getSlot(), sound.getName().replace(" ", "-").toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
Inventory inv = Bukkit.createInventory(this, 54, ChatColor.UNDERLINE + "Custom Sounds: " + id);
|
||||
int[] slots = { 19, 22, 25 };
|
||||
int n = 0;
|
||||
|
||||
FileConfiguration config = type.getConfigFile().getConfig();
|
||||
for (CustomSound sound : CustomSound.values()) {
|
||||
ItemStack soundEvent = sound.getItem().clone();
|
||||
ItemMeta soundEventMeta = soundEvent.getItemMeta();
|
||||
soundEventMeta.setDisplayName(ChatColor.GREEN + sound.getName());
|
||||
List<String> eventLore = new ArrayList<String>();
|
||||
for(String lore : sound.getLore())
|
||||
eventLore.add(ChatColor.GRAY + lore);
|
||||
eventLore.add("");
|
||||
String configSoundName = sound.getName().replace(" ", "-").toLowerCase();
|
||||
String value = config.getString(id + ".sounds." + configSoundName + ".sound");
|
||||
if(value != null)
|
||||
{
|
||||
eventLore.add(ChatColor.GRAY + "Current Values:");
|
||||
eventLore.add(ChatColor.GRAY + " - Sound Name: '" + ChatColor.GREEN + config.getString(id + ".sounds." + configSoundName + ".sound") + ChatColor.GRAY + "'");
|
||||
eventLore.add(ChatColor.GRAY + " - Volume: " + ChatColor.GREEN + config.getDouble(id + ".sounds." + configSoundName + ".volume"));
|
||||
eventLore.add(ChatColor.GRAY + " - Pitch: " + ChatColor.GREEN + config.getDouble(id + ".sounds." + configSoundName + ".pitch"));
|
||||
}
|
||||
else
|
||||
eventLore.add(ChatColor.GRAY + "Current Values: " + ChatColor.RED + "None");
|
||||
eventLore.add("");
|
||||
eventLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value.");
|
||||
eventLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove this value.");
|
||||
soundEventMeta.setLore(eventLore);
|
||||
soundEvent.setItemMeta(soundEventMeta);
|
||||
|
||||
inv.setItem(slots[n], soundEvent);
|
||||
n += 1;
|
||||
}
|
||||
|
||||
addEditionInventoryItems(inv, true);
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(InventoryClickEvent event) {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
|
||||
event.setCancelled(true);
|
||||
if (event.getInventory() != event.getClickedInventory() || !MMOUtils.isPluginItem(item, false))
|
||||
return;
|
||||
|
||||
if (correspondingSlot.containsKey(event.getSlot())) {
|
||||
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
||||
new StatEdition(this, ItemStat.CUSTOM_SOUNDS, event.getSlot()).enable("Write in the chat the custom sound you want to add.", ChatColor.AQUA + "Format: [SOUND NAME] [VOLUME] [PITCH]");
|
||||
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||
ConfigFile config = type.getConfigFile();
|
||||
String soundPath = correspondingSlot.get(event.getSlot());
|
||||
config.getConfig().set(id + ".sounds." + soundPath, null);
|
||||
|
||||
// clear sound config section
|
||||
if (config.getConfig().getConfigurationSection(id).contains("sounds")) {
|
||||
if (config.getConfig().getConfigurationSection(id + ".sounds").contains(soundPath))
|
||||
if (config.getConfig().getConfigurationSection(id + ".sounds." + soundPath).getKeys(false).isEmpty())
|
||||
config.getConfig().set(id + ".sounds." + soundPath, null);
|
||||
if (config.getConfig().getConfigurationSection(id + ".sounds").getKeys(false).isEmpty())
|
||||
config.getConfig().set(id + ".sounds", null);
|
||||
}
|
||||
|
||||
registerItemEdition(config);
|
||||
new SoundsEdition(player, type, id).open();
|
||||
player.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + MMOUtils.caseOnWords(soundPath.replace("-", " ")) + " Sound" + ChatColor.GRAY + " successfully removed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ public class GuiListener implements Listener {
|
||||
String id = ((EditionInventory) inventory).getItemId();
|
||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + AltChar.rightArrow + " Back")) {
|
||||
if(inventory instanceof ItemEdition) new ItemBrowser(player, type).open();
|
||||
else new ItemEdition(player, type, id).open();
|
||||
else new ItemEdition(player, type, id).onPage(((EditionInventory) inventory).getPreviousPage()).open();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
package net.Indyuce.mmoitems.listener;
|
||||
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.NBTItem;
|
||||
|
||||
public class CustomSoundListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void a(EntityDamageByEntityEvent event) {
|
||||
if(!(event.getDamager() instanceof Player) || !(event.getEntity() instanceof LivingEntity))
|
||||
return;
|
||||
|
||||
Player player = (Player) event.getDamager();
|
||||
playSound(player.getInventory().getItemInMainHand(), "ON_ATTACK", player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void b(BlockBreakEvent event) {
|
||||
playSound(event.getPlayer().getInventory().getItemInMainHand(), "ON_BLOCK_BREAK", event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void b(PlayerInteractEvent event) {
|
||||
if(event.getAction().equals(Action.RIGHT_CLICK_AIR)
|
||||
|| event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
|
||||
playSound(event.getItem(), "ON_RIGHT_CLICK", event.getPlayer());
|
||||
}
|
||||
|
||||
void playSound(ItemStack item, String sound, Player player) {
|
||||
if(item == null) return;
|
||||
NBTItem nbt = NBTItem.get(item);
|
||||
if(nbt.hasTag("MMOITEMS_" + sound))
|
||||
{
|
||||
player.playSound(player.getLocation(),
|
||||
nbt.getString("MMOITEMS_" + sound),
|
||||
(float) nbt.getDouble("MMOITEMS_" + sound + "_VOL"),
|
||||
(float) nbt.getDouble("MMOITEMS_" + sound + "_PIT"));
|
||||
}
|
||||
}
|
||||
}
|
@ -82,7 +82,7 @@ public class Abilities extends ItemStat {
|
||||
|
||||
@Override
|
||||
public boolean whenClicked(EditionInventory inv, InventoryClickEvent event) {
|
||||
new AbilityListEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open();
|
||||
new AbilityListEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open(inv.getPage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ public class Advanced_Crafting_Recipe extends StringStat {
|
||||
public boolean whenClicked(EditionInventory inv, InventoryClickEvent event) {
|
||||
ConfigFile config = inv.getItemType().getConfigFile();
|
||||
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
||||
new AdvancedRecipeEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open();
|
||||
new AdvancedRecipeEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open(inv.getPage());
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF)
|
||||
if (config.getConfig().getConfigurationSection(inv.getItemId()).contains("advanced-craft")) {
|
||||
config.getConfig().set(inv.getItemId() + ".advanced-craft", null);
|
||||
|
@ -98,7 +98,7 @@ public class Arrow_Particles extends StringStat {
|
||||
|
||||
@Override
|
||||
public boolean whenClicked(EditionInventory inv, InventoryClickEvent event) {
|
||||
new ArrowParticlesEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open();
|
||||
new ArrowParticlesEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open(inv.getPage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ public class Commands extends ItemStat {
|
||||
|
||||
@Override
|
||||
public boolean whenClicked(EditionInventory inv, InventoryClickEvent event) {
|
||||
new CommandListEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open();
|
||||
new CommandListEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open(inv.getPage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class Crafting_Recipe extends StringStat {
|
||||
public boolean whenClicked(EditionInventory inv, InventoryClickEvent event) {
|
||||
ConfigFile config = inv.getItemType().getConfigFile();
|
||||
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
||||
new RecipeEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open();
|
||||
new RecipeEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open(inv.getPage());
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF)
|
||||
if (config.getConfig().getConfigurationSection(inv.getItemId()).contains("craft")) {
|
||||
config.getConfig().set(inv.getItemId() + ".craft", null);
|
||||
|
204
src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java
Normal file
204
src/main/java/net/Indyuce/mmoitems/stat/CustomSounds.java
Normal file
@ -0,0 +1,204 @@
|
||||
package net.Indyuce.mmoitems.stat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.ConfigFile;
|
||||
import net.Indyuce.mmoitems.api.CustomSound;
|
||||
import net.Indyuce.mmoitems.api.item.MMOItem;
|
||||
import net.Indyuce.mmoitems.api.item.NBTItem;
|
||||
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.api.util.AltChar;
|
||||
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
|
||||
import net.Indyuce.mmoitems.gui.edition.SoundsEdition;
|
||||
import net.Indyuce.mmoitems.stat.data.StatData;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import net.Indyuce.mmoitems.version.nms.ItemTag;
|
||||
|
||||
public class CustomSounds extends ItemStat {
|
||||
public CustomSounds() {
|
||||
super(new ItemStack(Material.JUKEBOX), "Custom Sounds", new String[] { "The custom sounds your item will use.", "Requires a custom resourcepack!" }, "sounds", new String[] { "all" });
|
||||
}
|
||||
//inv.getPlayer().playSound(inv.getPlayer().getLocation(), sound, vol, p);
|
||||
|
||||
@Override
|
||||
public boolean whenClicked(EditionInventory inv, InventoryClickEvent event) {
|
||||
ConfigFile config = inv.getItemType().getConfigFile();
|
||||
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
||||
new SoundsEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open(inv.getPage());
|
||||
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF)
|
||||
if (config.getConfig().getConfigurationSection(inv.getItemId()).contains("sounds")) {
|
||||
config.getConfig().set(inv.getItemId() + ".sounds", null);
|
||||
inv.registerItemEdition(config);
|
||||
inv.open();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Custom Sounds successfully removed.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean whenInput(EditionInventory inv, ConfigFile config, String message, Object... info) {
|
||||
String soundsPath = SoundsEdition.correspondingSlot.get(info[0]);
|
||||
String[] split = message.split("\\ ");
|
||||
if (split.length != 3) {
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + message + " is not a valid [SOUND NAME] [VOLUME] [PITCH].");
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Example: 'mob.giant.roar 1 1'");
|
||||
return false;
|
||||
}
|
||||
|
||||
String soundName = split[0].replace("-", "_");
|
||||
|
||||
double volume = 0;
|
||||
try {
|
||||
volume = Double.parseDouble(split[1]);
|
||||
} catch (Exception e1) {
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + split[1] + " is not a valid number!");
|
||||
return false;
|
||||
}
|
||||
|
||||
double pitch = 0;
|
||||
try {
|
||||
pitch = Double.parseDouble(split[2]);
|
||||
} catch (Exception e1) {
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + split[2] + " is not a valid number!");
|
||||
return false;
|
||||
}
|
||||
|
||||
config.getConfig().set(inv.getItemId() + ".sounds." + soundsPath + ".sound", soundName);
|
||||
config.getConfig().set(inv.getItemId() + ".sounds." + soundsPath + ".volume", volume);
|
||||
config.getConfig().set(inv.getItemId() + ".sounds." + soundsPath + ".pitch", pitch);
|
||||
|
||||
inv.registerItemEdition(config);
|
||||
inv.open();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + MMOUtils.caseOnWords(soundsPath.replace(".", " ")) + ChatColor.GRAY + " successfully changed to '" + soundName + "'.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenDisplayed(List<String> lore, FileConfiguration config, String path) {
|
||||
lore.add("");
|
||||
lore.add(ChatColor.GRAY + "Current Values:");
|
||||
if (!config.getConfigurationSection(path).contains("sounds"))
|
||||
lore.add(ChatColor.RED + "No custom sounds.");
|
||||
else if (config.getConfigurationSection(path + ".sounds").getKeys(false).isEmpty())
|
||||
lore.add(ChatColor.RED + "No custom sounds.");
|
||||
else
|
||||
for (String s1 : config.getConfigurationSection(path + ".sounds").getKeys(false)) {
|
||||
String sounds = MMOUtils.caseOnWords(s1.replace("-", " "));
|
||||
lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + sounds + ChatColor.GRAY + ": " + ChatColor.RED + config.getString(path + ".sounds." + s1 + ".sound"));
|
||||
}
|
||||
lore.add("");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to access the sounds edition menu.");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove all custom sounds.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean whenLoaded(MMOItem item, ConfigurationSection config) {
|
||||
SoundListData sounds = new SoundListData();
|
||||
|
||||
for (CustomSound sound : CustomSound.values()) {
|
||||
String path = sound.getName().replace(" ", "-").toLowerCase();
|
||||
if (!config.getConfigurationSection("sounds").contains(path))
|
||||
continue;
|
||||
|
||||
String soundName = config.getString("sounds." + path + ".sound");
|
||||
double vol = config.getDouble("sounds." + path + ".volume");
|
||||
double pit = config.getDouble("sounds." + path + ".pitch");
|
||||
if (!soundName.isEmpty() && vol != 0 && pit != 0)
|
||||
sounds.set(sound, soundName, vol, pit);
|
||||
}
|
||||
|
||||
item.setData(ItemStat.CUSTOM_SOUNDS, sounds);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean whenApplied(MMOItemBuilder item, StatData data) {
|
||||
SoundListData sounds = (SoundListData) data;
|
||||
|
||||
sounds.getCustomSounds().forEach(sound -> {
|
||||
SoundData value = sounds.get(sound);
|
||||
String s = sound.getName().replace(" ", "_").toUpperCase();
|
||||
|
||||
item.addItemTag(new ItemTag("MMOITEMS_" + s, value.getSound()));
|
||||
item.addItemTag(new ItemTag("MMOITEMS_" + s + "_VOL", value.getVolume()));
|
||||
item.addItemTag(new ItemTag("MMOITEMS_" + s + "_PIT", value.getPitch()));
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenLoaded(MMOItem mmoitem, NBTItem item) {
|
||||
SoundListData sounds = new SoundListData();
|
||||
|
||||
String soundName;
|
||||
String s;
|
||||
for (CustomSound sound : CustomSound.values())
|
||||
{
|
||||
s = sound.getName().replace(" ", "_").toUpperCase();
|
||||
soundName = item.getString("MMOITEMS_" + s);
|
||||
if (soundName != null && !soundName.isEmpty())
|
||||
{
|
||||
double vol = item.getDouble("MMOITEMS_" + s + "_VOL");
|
||||
double pit = item.getDouble("MMOITEMS_" + s + "_PIT");
|
||||
sounds.set(sound, soundName, vol, pit);
|
||||
}
|
||||
}
|
||||
|
||||
if (sounds.total() > 0)
|
||||
mmoitem.setData(ItemStat.CUSTOM_SOUNDS, sounds);
|
||||
}
|
||||
|
||||
public class SoundListData extends StatData {
|
||||
private Map<CustomSound, SoundData> stats = new HashMap<>();
|
||||
|
||||
public SoundListData() {
|
||||
}
|
||||
|
||||
public Set<CustomSound> getCustomSounds() {
|
||||
return stats.keySet();
|
||||
}
|
||||
|
||||
public SoundData get(CustomSound sound) {
|
||||
return stats.get(sound);
|
||||
}
|
||||
|
||||
public void set(CustomSound sound, String s, double v, double p) {
|
||||
this.stats.put(sound, new SoundData(s, v, p));
|
||||
}
|
||||
|
||||
public int total()
|
||||
{ return stats.size(); }
|
||||
}
|
||||
|
||||
public class SoundData
|
||||
{
|
||||
private String sound;
|
||||
private double volume, pitch;
|
||||
|
||||
public SoundData() {}
|
||||
public SoundData(String s, double v, double p)
|
||||
{ this.sound = s; this.volume = v; this.pitch = p; }
|
||||
|
||||
public void setSound(String value) { this.sound = value; }
|
||||
public void setVolume(double value) { this.volume = value; }
|
||||
public void setPitch(double value) { this.pitch = value; }
|
||||
public String getSound() { return this.sound; }
|
||||
public double getVolume() { return this.volume; }
|
||||
public double getPitch() { return this.pitch; }
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@ public class Elements extends ItemStat {
|
||||
public boolean whenClicked(EditionInventory inv, InventoryClickEvent event) {
|
||||
ConfigFile config = inv.getItemType().getConfigFile();
|
||||
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
||||
new ElementsEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open();
|
||||
new ElementsEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open(inv.getPage());
|
||||
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF)
|
||||
if (config.getConfig().getConfigurationSection(inv.getItemId()).contains("element")) {
|
||||
|
@ -35,7 +35,7 @@ public class Item_Particles extends ItemStat {
|
||||
|
||||
@Override
|
||||
public boolean whenClicked(EditionInventory inv, InventoryClickEvent event) {
|
||||
new ParticlesEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open();
|
||||
new ParticlesEdition(inv.getPlayer(), inv.getItemType(), inv.getItemId()).open(inv.getPage());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ import net.Indyuce.mmoitems.stat.Attack_Speed;
|
||||
import net.Indyuce.mmoitems.stat.Commands;
|
||||
import net.Indyuce.mmoitems.stat.Consume_Sound;
|
||||
import net.Indyuce.mmoitems.stat.Crafting_Recipe;
|
||||
import net.Indyuce.mmoitems.stat.CustomSounds;
|
||||
import net.Indyuce.mmoitems.stat.Custom_Model_Data;
|
||||
import net.Indyuce.mmoitems.stat.Disable_AdvancedEnchantments;
|
||||
import net.Indyuce.mmoitems.stat.Display_Name;
|
||||
@ -141,6 +142,7 @@ public abstract class ItemStat {
|
||||
public static final ItemStat CRAFTING_RECIPE = new Crafting_Recipe(), FURNACE_RECIPE = new Furnace_Recipe(), SHAPELESS_RECIPE = new Shapeless_Recipe(), ADVANCED_CRAFTING_RECIPE = new Advanced_Crafting_Recipe(), ADVANCED_CRAFTING_RECIPE_PERMISSION = new Advanced_Crafting_Recipe_Permission();
|
||||
public static final ItemStat AUTOSMELT = new BooleanStat(new ItemStack(Material.COAL), "Autosmelt", new String[] { "If set to true, your tool will", "automaticaly smelt mined ores." }, "autosmelt", new String[] { "tool" });
|
||||
public static final ItemStat BOUNCING_CRACK = new BooleanStat(new ItemStack(VersionMaterial.COBBLESTONE_WALL.toMaterial()), "Bouncing Crack", new String[] { "If set to true, your tool will", "also break nearby blocks." }, "bouncing-crack", new String[] { "tool" });
|
||||
public static final ItemStat CUSTOM_SOUNDS = new CustomSounds();
|
||||
public static final ItemStat ELEMENTS = new Elements();
|
||||
public static final ItemStat COMMANDS = new Commands(), STAFF_SPIRIT = new Staff_Spirit(), LUTE_ATTACK_SOUND = new Lute_Attack_Sound(), LUTE_ATTACK_EFFECT = new Lute_Attack_Effect();
|
||||
public static final ItemStat NOTE_WEIGHT = new DoubleStat(new ItemStack(VersionMaterial.MUSIC_DISC_MALL.toMaterial()), "Note Weight", new String[] { "Defines how the projectile cast", "by your lute tilts downwards." }, "note-weight", new String[] { "lute" });
|
||||
|
@ -13,7 +13,7 @@ import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
|
||||
public class DefaultDurability extends DoubleStat {
|
||||
public DefaultDurability() {
|
||||
super(new ItemStack(Material.FISHING_ROD), "DefaultDurability/ID", new String[] { "The durability of your item." }, "durability", new String[] { "all" });
|
||||
super(new ItemStack(Material.FISHING_ROD), "Default Durability/ID", new String[] { "The durability of your item." }, "durability", new String[] { "all" });
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,7 +13,7 @@ import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
|
||||
public class LegacyDurability extends DoubleStat {
|
||||
public LegacyDurability() {
|
||||
super(new ItemStack(Material.FISHING_ROD), "DefaultDurability/ID", new String[] { "The durability of your item." }, "durability", new String[] { "all" });
|
||||
super(new ItemStack(Material.FISHING_ROD), "Default Durability/ID", new String[] { "The durability of your item." }, "durability", new String[] { "all" });
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user