Java Code Examples for org.bukkit.Sound#valueOf()
The following examples show how to use
org.bukkit.Sound#valueOf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoundMachine.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
public static Sound get(String v18, String v19) { Sound finalSound = null; try { if (BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")) { finalSound = Sound.valueOf(v18); } else { finalSound = Sound.valueOf(v19); } } catch (Exception ex) { BedwarsRel.getInstance().getBugsnag().notify(ex); // just compatibility } return finalSound; }
Example 2
Source File: EffectManager.java From ce with GNU Lesser General Public License v3.0 | 6 votes |
public static void playSound(Location loc, String sound, float volume, float pitch) { Sound s; try { s = Sound.valueOf(sound); } catch (IllegalArgumentException ex) { try { //Try to resolve the 1.8 Sounds s = Sound.valueOf(sound.substring(sound.indexOf("_") + 1, sound.length()).replace("_AMBIENT", "").replace("GENERIC_", "").replace("EXPERIENCE_", "").replace("PLAYER_", "")); } catch (IllegalArgumentException ex2) { return; } } loc.getWorld().playSound(loc, s, volume, pitch); }
Example 3
Source File: NoGUIOpener.java From CratesPlus with GNU General Public License v3.0 | 6 votes |
@Override public void doOpen(Player player, Crate crate, Location location) { if (chestSound) { Sound sound = null; try { sound = Sound.valueOf("CHEST_OPEN"); } catch (Exception e) { try { sound = Sound.valueOf("BLOCK_CHEST_OPEN"); } catch (Exception ee) { // This should never happen! } } if (sound != null) player.playSound(player.getLocation(), sound, (float) 0.5, 1); } crate.handleWin(player); finish(player); }
Example 4
Source File: NMS_1_14.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public Sound getSound(CommandContext cmdCtx, String key) { MinecraftKey minecraftKey = ArgumentMinecraftKeyRegistered.c(cmdCtx, key); for (CraftSound sound : CraftSound.values()) { try { if (CommandAPIHandler.getField(CraftSound.class, "minecraftKey").get(sound) .equals(minecraftKey.getKey())) { return Sound.valueOf(sound.name()); } } catch (IllegalArgumentException | IllegalAccessException e1) { e1.printStackTrace(); } } return null; }
Example 5
Source File: Sounds.java From TradePlus with GNU General Public License v3.0 | 5 votes |
public static void loadSounds() { try { if (version < 19) { pling = Sound.valueOf("NOTE_PLING"); click = Sound.valueOf("CLICK"); levelUp = Sound.valueOf("LEVEL_UP"); villagerHit = Sound.valueOf("VILLAGER_HIT"); villagerHmm = Sound.valueOf("VILLAGER_IDLE"); } else if (version < 113) { pling = Sound.valueOf("BLOCK_NOTE_PLING"); click = Sound.valueOf("UI_BUTTON_CLICK"); levelUp = Sound.valueOf("ENTITY_PLAYER_LEVELUP"); villagerHit = Sound.valueOf("ENTITY_VILLAGER_HURT"); villagerHmm = Sound.valueOf("ENTITY_VILLAGER_AMBIENT"); } else { pling = Sound.valueOf("BLOCK_NOTE_BLOCK_PLING"); click = Sound.valueOf("UI_BUTTON_CLICK"); levelUp = Sound.valueOf("ENTITY_PLAYER_LEVELUP"); villagerHit = Sound.valueOf("ENTITY_VILLAGER_HURT"); villagerHmm = Sound.valueOf("ENTITY_VILLAGER_AMBIENT"); } } catch (IllegalArgumentException | NullPointerException | NoSuchFieldError ex) { Bukkit.getConsoleSender() .sendMessage( ChatColor.DARK_RED + "Unable to load sounds! Sound effects will be disabled."); } }
Example 6
Source File: EffPlaySound.java From Skript with GNU General Public License v3.0 | 5 votes |
private static void playSound(Location location, String[] sounds, SoundCategory category, float volume, float pitch) { World w = location.getWorld(); for (String sound : sounds) { Sound soundEnum = null; try { soundEnum = Sound.valueOf(sound.toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException ignored) {} if (SOUND_CATEGORIES_EXIST) { if (soundEnum == null) { sound = sound.toLowerCase(Locale.ENGLISH); if (!SOUND_VALID_PATTERN.matcher(sound).matches()) continue; w.playSound(location, sound, category, volume, pitch); } else { w.playSound(location, soundEnum, category, volume, pitch); } } else { if (soundEnum == null) { sound = sound.toLowerCase(Locale.ENGLISH); if (!SOUND_VALID_PATTERN.matcher(sound).matches()) continue; w.playSound(location, sound, volume, pitch); } else { w.playSound(location, soundEnum, volume, pitch); } } } }
Example 7
Source File: EffPlaySound.java From Skript with GNU General Public License v3.0 | 5 votes |
private static void playSound(Player p, Location location, String[] sounds, SoundCategory category, float volume, float pitch) { for (String sound : sounds) { Sound soundEnum = null; try { soundEnum = Sound.valueOf(sound.toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException ignored) {} if (SOUND_CATEGORIES_EXIST) { if (soundEnum == null) { sound = sound.toLowerCase(Locale.ENGLISH); if (!SOUND_VALID_PATTERN.matcher(sound).matches()) continue; p.playSound(location, sound, category, volume, pitch); } else { p.playSound(location, soundEnum, category, volume, pitch); } } else { if (soundEnum == null) { sound = sound.toLowerCase(Locale.ENGLISH); if (!SOUND_VALID_PATTERN.matcher(sound).matches()) continue; p.playSound(location, sound, volume, pitch); } else { p.playSound(location, soundEnum, volume, pitch); } } } }
Example 8
Source File: MultiVersionLookup.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
public static Sound getHarp() { if (noteHarp == null) { try { noteHarp = Sound.valueOf("BLOCK_NOTE_HARP"); } catch (Error | Exception e) { } if (noteHarp == null) noteHarp = Sound.BLOCK_NOTE_BLOCK_HARP; } return noteHarp; }
Example 9
Source File: MultiVersionLookup.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
public static Sound getWoolSound() { if (woolsound == null) { try { woolsound = Sound.valueOf("BLOCK_CLOTH_BREAK"); } catch (Error | Exception e) { } if (woolsound == null) woolsound = Sound.BLOCK_WOOL_BREAK; } return woolsound; }
Example 10
Source File: MultiVersionLookup.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
public static Sound getDragonGrowl() { if (enderdrag == null) { try { enderdrag = Sound.valueOf("ENTITY_ENDERDRAGON_GROWL"); } catch (Error | Exception e) { } if (enderdrag == null) enderdrag = Sound.ENTITY_ENDER_DRAGON_GROWL; } return enderdrag; }
Example 11
Source File: MultiVersionLookup.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
public static Sound getPling() { if (pliung == null) { try { pliung = Sound.valueOf("BLOCK_NOTE_PLING"); } catch (Error | Exception e) { } if (pliung == null) pliung = Sound.BLOCK_NOTE_BLOCK_PLING; } return pliung; }
Example 12
Source File: NMS_1_13_1.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public Sound getSound(CommandContext cmdCtx, String key) { MinecraftKey minecraftKey = ArgumentMinecraftKeyRegistered.c(cmdCtx, key); for(CraftSound sound : CraftSound.values()) { try { if(CommandAPIHandler.getField(CraftSound.class, "minecraftKey").get(sound).equals(minecraftKey.getKey())) { return Sound.valueOf(sound.name()); } } catch (IllegalArgumentException | IllegalAccessException e1) { e1.printStackTrace(); } } return null; }
Example 13
Source File: NMS_1_14_3.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public Sound getSound(CommandContext cmdCtx, String key) { MinecraftKey minecraftKey = ArgumentMinecraftKeyRegistered.c(cmdCtx, key); for(CraftSound sound : CraftSound.values()) { try { if(CommandAPIHandler.getField(CraftSound.class, "minecraftKey").get(sound).equals(minecraftKey.getKey())) { return Sound.valueOf(sound.name()); } } catch (IllegalArgumentException | IllegalAccessException e1) { e1.printStackTrace(); } } return null; }
Example 14
Source File: NMS_1_14_4.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public Sound getSound(CommandContext cmdCtx, String key) { MinecraftKey minecraftKey = ArgumentMinecraftKeyRegistered.c(cmdCtx, key); for(CraftSound sound : CraftSound.values()) { try { if(CommandAPIHandler.getField(CraftSound.class, "minecraftKey").get(sound).equals(minecraftKey.getKey())) { return Sound.valueOf(sound.name()); } } catch (IllegalArgumentException | IllegalAccessException e1) { e1.printStackTrace(); } } return null; }
Example 15
Source File: NMS_1_13_2.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public Sound getSound(CommandContext cmdCtx, String key) { MinecraftKey minecraftKey = ArgumentMinecraftKeyRegistered.c(cmdCtx, key); for(CraftSound sound : CraftSound.values()) { try { if(CommandAPIHandler.getField(CraftSound.class, "minecraftKey").get(sound).equals(minecraftKey.getKey())) { return Sound.valueOf(sound.name()); } } catch (IllegalArgumentException | IllegalAccessException e1) { e1.printStackTrace(); } } return null; }
Example 16
Source File: NMS_1_15.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public Sound getSound(CommandContext cmdCtx, String key) { MinecraftKey minecraftKey = ArgumentMinecraftKeyRegistered.d(cmdCtx, key); for (CraftSound sound : CraftSound.values()) { try { if (CommandAPIHandler.getField(CraftSound.class, "minecraftKey").get(sound) .equals(minecraftKey.getKey())) { return Sound.valueOf(sound.name()); } } catch (IllegalArgumentException | IllegalAccessException e1) { e1.printStackTrace(); } } return null; }
Example 17
Source File: NMS_1_13.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public Sound getSound(CommandContext cmdCtx, String key) { MinecraftKey minecraftKey = ArgumentMinecraftKeyRegistered.c(cmdCtx, key); for(CraftSound sound : CraftSound.values()) { try { if(CommandAPIHandler.getField(CraftSound.class, "minecraftKey").get(sound).equals(minecraftKey.getKey())) { return Sound.valueOf(sound.name()); } } catch (IllegalArgumentException | IllegalAccessException e1) { e1.printStackTrace(); } } return null; }
Example 18
Source File: NMS_1_16_R1.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public Sound getSound(CommandContext cmdCtx, String key) { MinecraftKey minecraftKey = ArgumentMinecraftKeyRegistered.e(cmdCtx, key); for (CraftSound sound : CraftSound.values()) { try { if (CommandAPIHandler.getField(CraftSound.class, "minecraftKey").get(sound) .equals(minecraftKey.getKey())) { return Sound.valueOf(sound.name()); } } catch (IllegalArgumentException | IllegalAccessException e1) { e1.printStackTrace(); } } return null; }
Example 19
Source File: LevelManager.java From SkyWarsReloaded with GNU General Public License v3.0 | 4 votes |
public void loadWinSounds() { winSoundList.clear(); File soundFile = new File(SkyWarsReloaded.get().getDataFolder(), "winsounds.yml"); if (!soundFile.exists()) { if (SkyWarsReloaded.getNMS().getVersion() < 9) { SkyWarsReloaded.get().saveResource("winsounds18.yml", false); File sf = new File(SkyWarsReloaded.get().getDataFolder(), "winsounds18.yml"); if (sf.exists()) { sf.renameTo(new File(SkyWarsReloaded.get().getDataFolder(), "winsounds.yml")); } } else { SkyWarsReloaded.get().saveResource("winsounds.yml", false); } } if (soundFile.exists()) { FileConfiguration storage = YamlConfiguration.loadConfiguration(soundFile); if (storage.getConfigurationSection("sounds") != null) { for (String key: storage.getConfigurationSection("sounds").getKeys(false)) { String sound = storage.getString("sounds." + key + ".sound"); String name = storage.getString("sounds." + key + ".displayName"); int volume = storage.getInt("sounds." + key + ".volume"); int pitch = storage.getInt("sounds." + key + ".pitch"); String material = storage.getString("sounds." + key + ".icon"); int level = storage.getInt("sounds." + key + ".level"); int cost = storage.getInt("sounds." + key + ".cost"); boolean isCustom = storage.getBoolean("sounds." + key + ".isCustomSound"); Material mat = Material.matchMaterial(material); if (mat != null) { if (!isCustom) { try { Sound s = Sound.valueOf(sound); if (s != null) { winSoundList.add(new SoundItem(key, sound, name, level, cost, volume, pitch, mat, isCustom)); } } catch (IllegalArgumentException e) { SkyWarsReloaded.get().getServer().getLogger().info(sound + " is not a valid sound in winsounds.yml"); } } else { winSoundList.add(new SoundItem(key, sound, name, level, cost, volume, pitch, mat, isCustom)); } } else { SkyWarsReloaded.get().getServer().getLogger().info(mat + " is not a valid Material in winsounds.yml"); } } } } Collections.<SoundItem>sort(winSoundList); }
Example 20
Source File: LevelManager.java From SkyWarsReloaded with GNU General Public License v3.0 | 4 votes |
public void loadKillSounds() { killSoundList.clear(); File soundFile = new File(SkyWarsReloaded.get().getDataFolder(), "killsounds.yml"); if (!soundFile.exists()) { if (SkyWarsReloaded.getNMS().getVersion() < 8) { SkyWarsReloaded.get().saveResource("killsounds18.yml", false); File sf = new File(SkyWarsReloaded.get().getDataFolder(), "killsounds18.yml"); if (sf.exists()) { sf.renameTo(new File(SkyWarsReloaded.get().getDataFolder(), "killsounds.yml")); } } else { SkyWarsReloaded.get().saveResource("killsounds.yml", false); } } if (soundFile.exists()) { FileConfiguration storage = YamlConfiguration.loadConfiguration(soundFile); if (storage.getConfigurationSection("sounds") != null) { for (String key: storage.getConfigurationSection("sounds").getKeys(false)) { String sound = storage.getString("sounds." + key + ".sound"); String name = storage.getString("sounds." + key + ".displayName"); int volume = storage.getInt("sounds." + key + ".volume"); int pitch = storage.getInt("sounds." + key + ".pitch"); String material = storage.getString("sounds." + key + ".icon"); int level = storage.getInt("sounds." + key + ".level"); int cost = storage.getInt("sounds." + key + ".cost"); boolean isCustom = storage.getBoolean("sounds." + key + ".isCustomSound"); Material mat = Material.matchMaterial(material); if (mat != null) { if (!isCustom) { try { Sound s = Sound.valueOf(sound); if (s != null) { killSoundList.add(new SoundItem(key, sound, name, level, cost, volume, pitch, mat, isCustom)); } } catch (IllegalArgumentException e) { SkyWarsReloaded.get().getServer().getLogger().info(sound + " is not a valid sound in killsounds.yml"); } } else { killSoundList.add(new SoundItem(key, sound, name, level, cost, volume, pitch, mat, isCustom)); } } else { SkyWarsReloaded.get().getServer().getLogger().info(mat + " is not a valid Material in killsounds.yml"); } } } } Collections.<SoundItem>sort(killSoundList); }