Update 5.14
This commit is contained in:
parent
c02973fe1b
commit
2a038c3baf
@ -2,6 +2,8 @@ package io.izzel.taboolib;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author 坏黑
|
* @Author 坏黑
|
||||||
* @Since 2019-07-05 14:42
|
* @Since 2019-07-05 14:42
|
||||||
@ -20,6 +22,10 @@ public enum Version {
|
|||||||
return versionInt;
|
return versionInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getBukkitVersion() {
|
||||||
|
return Bukkit.getServer().getClass().getName().split("\\.")[3];
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isAfter(Version in) {
|
public static boolean isAfter(Version in) {
|
||||||
return getCurrentVersion().getVersionInt() >= in.getVersionInt();
|
return getCurrentVersion().getVersionInt() >= in.getVersionInt();
|
||||||
}
|
}
|
||||||
@ -28,36 +34,12 @@ public enum Version {
|
|||||||
return getCurrentVersion().getVersionInt() < in.getVersionInt();
|
return getCurrentVersion().getVersionInt() < in.getVersionInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getBukkitVersion() {
|
public static int getCurrentVersionInt() {
|
||||||
return Bukkit.getServer().getClass().getName().split("\\.")[3];
|
return getCurrentVersion().versionInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Version getCurrentVersion() {
|
public static Version getCurrentVersion() {
|
||||||
String nmsVersion = getBukkitVersion();
|
String nmsVersion = getBukkitVersion();
|
||||||
if (nmsVersion.startsWith("v1_7")) {
|
return Arrays.stream(values()).filter(value -> nmsVersion.startsWith(value.name())).findFirst().orElse(vNull);
|
||||||
return v1_7;
|
|
||||||
} else if (nmsVersion.startsWith("v1_8")) {
|
|
||||||
return v1_8;
|
|
||||||
} else if (nmsVersion.startsWith("v1_9")) {
|
|
||||||
return v1_9;
|
|
||||||
} else if (nmsVersion.startsWith("v1_10")) {
|
|
||||||
return v1_10;
|
|
||||||
} else if (nmsVersion.startsWith("v1_11")) {
|
|
||||||
return v1_11;
|
|
||||||
} else if (nmsVersion.startsWith("v1_12")) {
|
|
||||||
return v1_12;
|
|
||||||
} else if (nmsVersion.startsWith("v1_13")) {
|
|
||||||
return v1_13;
|
|
||||||
} else if (nmsVersion.startsWith("v1_14")) {
|
|
||||||
return v1_14;
|
|
||||||
} else if (nmsVersion.startsWith("v1_15")) {
|
|
||||||
return v1_15;
|
|
||||||
} else {
|
|
||||||
return vNull;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getCurrentVersionInt() {
|
|
||||||
return getCurrentVersion().versionInt;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -60,12 +60,10 @@ public class Location {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSelectWorld(org.bukkit.Location location) {
|
public boolean isSelectWorld(org.bukkit.Location location) {
|
||||||
switch (mode) {
|
if (mode == Mode.AREA) {
|
||||||
case AREA:
|
|
||||||
return area != null && location.getWorld().equals(area[0].getWorld());
|
return area != null && location.getWorld().equals(area[0].getWorld());
|
||||||
default:
|
|
||||||
return points != null && Arrays.stream(points).anyMatch(p -> p.getWorld().equals(location.getWorld()));
|
|
||||||
}
|
}
|
||||||
|
return points != null && Arrays.stream(points).anyMatch(p -> p.getWorld().equals(location.getWorld()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,6 +74,7 @@ public class TInjectLoader implements TabooLibLoader.Loader {
|
|||||||
TLocaleLoader.setLocalePriority(plugin, localePriority);
|
TLocaleLoader.setLocalePriority(plugin, localePriority);
|
||||||
TLocaleLoader.load(plugin, true, true);
|
TLocaleLoader.load(plugin, true, true);
|
||||||
});
|
});
|
||||||
|
config.runListener();
|
||||||
}
|
}
|
||||||
if (Strings.nonEmpty(args.reload())) {
|
if (Strings.nonEmpty(args.reload())) {
|
||||||
try {
|
try {
|
||||||
|
@ -75,7 +75,7 @@ public class TLocaleLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void load(Plugin plugin, boolean isCover) {
|
public static void load(Plugin plugin, boolean isCover) {
|
||||||
load(plugin, isCover, false);
|
load(plugin, isCover, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void load(Plugin plugin, boolean isCover, boolean hideMessage) {
|
public static void load(Plugin plugin, boolean isCover, boolean hideMessage) {
|
||||||
|
@ -74,6 +74,14 @@ public class NBTBase {
|
|||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toJsonSimplified() {
|
||||||
|
return toJsonSimplified(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJsonSimplified(int index) {
|
||||||
|
return data instanceof String ? "\"" + data + "\"" : String.valueOf(data);
|
||||||
|
}
|
||||||
|
|
||||||
public String asString() {
|
public String asString() {
|
||||||
return (String) data;
|
return (String) data;
|
||||||
}
|
}
|
||||||
@ -123,11 +131,14 @@ public class NBTBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static NBTBase toNBT(Object obj) {
|
public static NBTBase toNBT(Object obj) {
|
||||||
if (obj instanceof String) {
|
if (obj instanceof NBTBase) {
|
||||||
|
return (NBTBase) obj;
|
||||||
|
} else if (obj instanceof String) {
|
||||||
if (SHORT_PATTERN.matcher(obj.toString()).matches()) {
|
if (SHORT_PATTERN.matcher(obj.toString()).matches()) {
|
||||||
return toNBT(Short.valueOf(obj.toString().substring(0, obj.toString().length() - 1)));
|
return toNBT(Short.valueOf(obj.toString().substring(0, obj.toString().length() - 1)));
|
||||||
}
|
} else {
|
||||||
return new NBTBase((String) obj);
|
return new NBTBase((String) obj);
|
||||||
|
}
|
||||||
} else if (obj instanceof Integer) {
|
} else if (obj instanceof Integer) {
|
||||||
return new NBTBase((int) obj);
|
return new NBTBase((int) obj);
|
||||||
} else if (obj instanceof Double) {
|
} else if (obj instanceof Double) {
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package io.izzel.taboolib.module.nms.nbt;
|
package io.izzel.taboolib.module.nms.nbt;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
import io.izzel.taboolib.module.nms.NMS;
|
import io.izzel.taboolib.module.nms.NMS;
|
||||||
|
import io.izzel.taboolib.util.Strings;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -30,6 +33,40 @@ public class NBTCompound extends NBTBase implements Map<String, NBTBase> {
|
|||||||
item.setItemMeta(NMS.handle().saveNBT(item, this).getItemMeta());
|
item.setItemMeta(NMS.handle().saveNBT(item, this).getItemMeta());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toJson() {
|
||||||
|
return new Gson().toJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJsonFormatted() {
|
||||||
|
return new GsonBuilder().setPrettyPrinting().create().toJson(new Gson().toJsonTree(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toJsonSimplified() {
|
||||||
|
return toJsonSimplified(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toJsonSimplified(int index) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("{\n");
|
||||||
|
value.forEach((k, v) -> {
|
||||||
|
builder.append(Strings.copy(" ", index + 1))
|
||||||
|
.append("\"")
|
||||||
|
.append(k)
|
||||||
|
.append("\"")
|
||||||
|
.append(": ")
|
||||||
|
.append(v.toJsonSimplified(index + 1))
|
||||||
|
.append("\n");
|
||||||
|
});
|
||||||
|
builder.append(Strings.copy(" ", index)).append("}");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NBTCompound fromJson(String json) {
|
||||||
|
return new Gson().fromJson(json, NBTCompound.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return value.size();
|
return value.size();
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package io.izzel.taboolib.module.nms.nbt;
|
package io.izzel.taboolib.module.nms.nbt;
|
||||||
|
|
||||||
|
import io.izzel.taboolib.util.Strings;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -21,6 +23,38 @@ public class NBTList extends NBTBase implements List<NBTBase> {
|
|||||||
this.data = this;
|
this.data = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static NBTList of(NBTBase... base) {
|
||||||
|
NBTList list = new NBTList();
|
||||||
|
list.addAll(Arrays.asList(base));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NBTList of(Object... base) {
|
||||||
|
NBTList list = new NBTList();
|
||||||
|
for (Object obj : base) {
|
||||||
|
list.add(NBTBase.toNBT(obj));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toJsonSimplified() {
|
||||||
|
return toJsonSimplified(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toJsonSimplified(int index) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("[\n");
|
||||||
|
value.forEach(v -> {
|
||||||
|
builder.append(Strings.copy(" ", index + 1))
|
||||||
|
.append(v.toJsonSimplified(index + 1))
|
||||||
|
.append("\n");
|
||||||
|
});
|
||||||
|
builder.append(Strings.copy(" ", index)).append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return value.size();
|
return value.size();
|
||||||
|
@ -4,9 +4,15 @@ import com.google.common.collect.Lists;
|
|||||||
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class Strings {
|
public class Strings {
|
||||||
|
|
||||||
|
public static String copy(String text, int count) {
|
||||||
|
return IntStream.range(0, count).mapToObj(i -> text).collect(Collectors.joining());
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean nonBlack(String var) {
|
public static boolean nonBlack(String var) {
|
||||||
return !isBlank(var);
|
return !isBlank(var);
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,9 @@ import com.google.common.cache.CacheBuilder;
|
|||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
import org.apache.commons.lang.WordUtils;
|
import org.apache.commons.lang3.text.WordUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package io.izzel.taboolib.util.lite;
|
package io.izzel.taboolib.util.lite;
|
||||||
|
|
||||||
import io.izzel.taboolib.TabooLib;
|
import io.izzel.taboolib.TabooLib;
|
||||||
import io.izzel.taboolib.Version;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class SoundPack {
|
public class SoundPack {
|
||||||
|
|
||||||
private Sound sound;
|
private Sound sound;
|
||||||
@ -15,7 +16,7 @@ public class SoundPack {
|
|||||||
private int delay;
|
private int delay;
|
||||||
|
|
||||||
public SoundPack() {
|
public SoundPack() {
|
||||||
this.sound = Sound.valueOf(getModifiedSound("ENTITY_VILLAGER_NO"));
|
this.sound = Sounds.ENTITY_VILLAGER_NO.parseSound();
|
||||||
this.a = 1.0F;
|
this.a = 1.0F;
|
||||||
this.b = 1.0F;
|
this.b = 1.0F;
|
||||||
}
|
}
|
||||||
@ -51,7 +52,7 @@ public class SoundPack {
|
|||||||
this.b = Float.parseFloat(split[2]);
|
this.b = Float.parseFloat(split[2]);
|
||||||
this.delay = split.length > 3 ? Integer.parseInt(split[3]) : 0;
|
this.delay = split.length > 3 ? Integer.parseInt(split[3]) : 0;
|
||||||
} catch (Exception var3) {
|
} catch (Exception var3) {
|
||||||
this.sound = Sound.valueOf(getModifiedSound("ENTITY_VILLAGER_NO"));
|
this.sound = Sounds.ENTITY_VILLAGER_NO.parseSound();
|
||||||
this.a = 1.0F;
|
this.a = 1.0F;
|
||||||
this.b = 1.0F;
|
this.b = 1.0F;
|
||||||
this.delay = 0;
|
this.delay = 0;
|
||||||
@ -59,28 +60,8 @@ public class SoundPack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getModifiedSound(String str) {
|
public static String getModifiedSound(String str) {
|
||||||
if (Version.isBefore(Version.v1_9)) {
|
Optional<Sound> sound = Sounds.parseSound(str);
|
||||||
str = str.replace("BLOCK_FIRE_EXTINGUISH", "FIZZ");
|
return sound.map(Enum::name).orElse(str);
|
||||||
str = str.replace("BLOCK_NOTE_HAT", "NOTE_STICKS");
|
|
||||||
str = str.replace("ENTITY_SHEEP_DEATH", "SHEEP_IDLE");
|
|
||||||
str = str.replace("ENTITY_LLAMA_ANGRY", "HORSE_HIT");
|
|
||||||
str = str.replace("BLOCK_BREWING_STAND_BREW", "CREEPER_HISS");
|
|
||||||
str = str.replace("ENTITY_SHULKER_TELEPORT", "ENDERMAN_TELEPORT");
|
|
||||||
str = str.replace("ENTITY_ZOMBIE_ATTACK_IRON_DOOR", "ZOMBIE_METAL");
|
|
||||||
str = str.replace("BLOCK_GRAVEL_BREAK", "DIG_GRAVEL");
|
|
||||||
str = str.replace("BLOCK_SNOW_BREAK", "DIG_SNOW");
|
|
||||||
str = str.replace("BLOCK_GRAVEL_BREAK", "DIG_GRAVEL");
|
|
||||||
str = str.replace("ENTITY_PLAYER_LEVELUP", "LEVEL_UP");
|
|
||||||
str = str.replace("ENTITY_SNOWBALL_THROW", "SHOOT_ARROW");
|
|
||||||
str = str.replace("PLAYER_ATTACK_CRIT", "ITEM_BREAK");
|
|
||||||
str = str.replace("ENDERMEN", "ENDERMAN");
|
|
||||||
str = str.replace("ARROW_SHOOT", "SHOOT_ARROW");
|
|
||||||
str = str.replace("ENDERMAN_HURT", "ENDERMAN_HIT");
|
|
||||||
str = str.replace("BLAZE_HURT", "BLAZE_HIT");
|
|
||||||
str = str.replace("_FLAP", "_WINGS");
|
|
||||||
str = str.replaceAll("ENTITY_|GENERIC_|BLOCK_|_AMBIENT|_BREAK|UI_BUTTON_|EXPERIENCE_", "");
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// *********************************
|
// *********************************
|
||||||
|
@ -23,9 +23,9 @@ import com.google.common.base.Enums;
|
|||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
import org.apache.commons.lang.WordUtils;
|
import org.apache.commons.lang3.text.WordUtils;
|
||||||
import org.bukkit.Instrument;
|
import org.bukkit.Instrument;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Note;
|
import org.bukkit.Note;
|
||||||
@ -916,6 +916,11 @@ public enum Sounds {
|
|||||||
this.legacy = legacy;
|
this.legacy = legacy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Optional<Sound> parseSound(String sound) {
|
||||||
|
Optional<Sounds> sounds = matchSounds(sound);
|
||||||
|
return sounds.map(Sounds::parseSound);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to build the string like an enum name.<br>
|
* Attempts to build the string like an enum name.<br>
|
||||||
* Removes all the spaces, numbers and extra non-English characters. Also removes some config/in-game based strings.
|
* Removes all the spaces, numbers and extra non-English characters. Also removes some config/in-game based strings.
|
||||||
@ -941,8 +946,11 @@ public enum Sounds {
|
|||||||
Validate.notEmpty(sound, "Cannot check for null or empty sound name");
|
Validate.notEmpty(sound, "Cannot check for null or empty sound name");
|
||||||
sound = format(sound);
|
sound = format(sound);
|
||||||
|
|
||||||
for (Sounds sounds : VALUES)
|
for (Sounds sounds : VALUES) {
|
||||||
if (sounds.name().equals(sound) || sounds.anyMatchLegacy(sound)) return true;
|
if (sounds.name().equals(sound) || sounds.anyMatchLegacy(sound)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -958,8 +966,11 @@ public enum Sounds {
|
|||||||
Validate.notEmpty(sound, "Cannot match Sounds of a null or empty sound name");
|
Validate.notEmpty(sound, "Cannot match Sounds of a null or empty sound name");
|
||||||
sound = format(sound);
|
sound = format(sound);
|
||||||
|
|
||||||
for (Sounds sounds : VALUES)
|
for (Sounds sounds : VALUES) {
|
||||||
if (sounds.name().equals(sound) || sounds.anyMatchLegacy(sound)) return Optional.of(sounds);
|
if (sounds.name().equals(sound) || sounds.anyMatchLegacy(sound)) {
|
||||||
|
return Optional.of(sounds);
|
||||||
|
}
|
||||||
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -974,8 +985,7 @@ public enum Sounds {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
public static Sounds matchSounds(@Nonnull Sound sound) {
|
public static Sounds matchSounds(@Nonnull Sound sound) {
|
||||||
Objects.requireNonNull(sound, "Cannot match Sounds of a null sound");
|
Objects.requireNonNull(sound, "Cannot match Sounds of a null sound");
|
||||||
return matchSounds(sound.name())
|
return matchSounds(sound.name()).orElseThrow(() -> new IllegalArgumentException("Unsupported Sound: " + sound.name()));
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Unsupported Sound: " + sound.name()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1004,7 +1014,9 @@ public enum Sounds {
|
|||||||
public static CompletableFuture<Void> playSoundFromString(@Nonnull Player player, @Nullable String sound) {
|
public static CompletableFuture<Void> playSoundFromString(@Nonnull Player player, @Nullable String sound) {
|
||||||
Objects.requireNonNull(player, "Cannot play sound to null player");
|
Objects.requireNonNull(player, "Cannot play sound to null player");
|
||||||
return CompletableFuture.runAsync(() -> {
|
return CompletableFuture.runAsync(() -> {
|
||||||
if (Strings.isNullOrEmpty(sound) || sound.equalsIgnoreCase("none")) return;
|
if (Strings.isNullOrEmpty(sound) || sound.equalsIgnoreCase("none")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String[] split = StringUtils.contains(sound, ',') ?
|
String[] split = StringUtils.contains(sound, ',') ?
|
||||||
StringUtils.split(StringUtils.deleteWhitespace(sound), ',') :
|
StringUtils.split(StringUtils.deleteWhitespace(sound), ',') :
|
||||||
@ -1015,9 +1027,13 @@ public enum Sounds {
|
|||||||
|
|
||||||
String name = split[0];
|
String name = split[0];
|
||||||
Optional<Sounds> typeOpt = matchSounds(name);
|
Optional<Sounds> typeOpt = matchSounds(name);
|
||||||
if (!typeOpt.isPresent()) return;
|
if (!typeOpt.isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Sound type = typeOpt.get().parseSound();
|
Sound type = typeOpt.get().parseSound();
|
||||||
if (type == null) return;
|
if (type == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
float volume = 1.0f;
|
float volume = 1.0f;
|
||||||
float pitch = 1.0f;
|
float pitch = 1.0f;
|
||||||
@ -1025,12 +1041,16 @@ public enum Sounds {
|
|||||||
try {
|
try {
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
volume = Float.parseFloat(split[1]);
|
volume = Float.parseFloat(split[1]);
|
||||||
if (split.length > 2) pitch = Float.parseFloat(split[2]);
|
if (split.length > 2) {
|
||||||
|
pitch = Float.parseFloat(split[2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.isOnline()) player.playSound(player.getLocation(), type, volume, pitch);
|
if (player.isOnline()) {
|
||||||
|
player.playSound(player.getLocation(), type, volume, pitch);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1059,7 +1079,9 @@ public enum Sounds {
|
|||||||
return CompletableFuture.runAsync(() -> {
|
return CompletableFuture.runAsync(() -> {
|
||||||
for (Sounds music : musics) {
|
for (Sounds music : musics) {
|
||||||
Sound sound = music.parseSound();
|
Sound sound = music.parseSound();
|
||||||
if (sound != null) player.stopSound(sound);
|
if (sound != null) {
|
||||||
|
player.stopSound(sound);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1095,7 +1117,9 @@ public enum Sounds {
|
|||||||
@SuppressWarnings({"Guava", "OptionalAssignedToNull"})
|
@SuppressWarnings({"Guava", "OptionalAssignedToNull"})
|
||||||
public Sound parseSound() {
|
public Sound parseSound() {
|
||||||
com.google.common.base.Optional<Sound> cachedSound = CACHE.getIfPresent(this);
|
com.google.common.base.Optional<Sound> cachedSound = CACHE.getIfPresent(this);
|
||||||
if (cachedSound != null) return cachedSound.orNull();
|
if (cachedSound != null) {
|
||||||
|
return cachedSound.orNull();
|
||||||
|
}
|
||||||
com.google.common.base.Optional<Sound> sound;
|
com.google.common.base.Optional<Sound> sound;
|
||||||
|
|
||||||
// Since Sound class doesn't have a getSound() method we'll use Guava so
|
// Since Sound class doesn't have a getSound() method we'll use Guava so
|
||||||
@ -1105,7 +1129,9 @@ public enum Sounds {
|
|||||||
if (!sound.isPresent()) {
|
if (!sound.isPresent()) {
|
||||||
for (String legacy : this.legacy) {
|
for (String legacy : this.legacy) {
|
||||||
sound = Enums.getIfPresent(Sound.class, legacy);
|
sound = Enums.getIfPresent(Sound.class, legacy);
|
||||||
if (sound.isPresent()) break;
|
if (sound.isPresent()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1167,7 +1193,9 @@ public enum Sounds {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
playSound(entity.getLocation(), volume, pitch);
|
playSound(entity.getLocation(), volume, pitch);
|
||||||
if (repeating-- == 0) cancel();
|
if (repeating-- == 0) {
|
||||||
|
cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.runTaskTimer(plugin, 0, delay);
|
}.runTaskTimer(plugin, 0, delay);
|
||||||
}
|
}
|
||||||
@ -1198,7 +1226,9 @@ public enum Sounds {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
player.playNote(playTo.getLocation(), instrument, Note.natural(1, Note.Tone.values()[ascendLevel - repeating]));
|
player.playNote(playTo.getLocation(), instrument, Note.natural(1, Note.Tone.values()[ascendLevel - repeating]));
|
||||||
if (repeating-- == 0) cancel();
|
if (repeating-- == 0) {
|
||||||
|
cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.runTaskTimerAsynchronously(plugin, 0, delay);
|
}.runTaskTimerAsynchronously(plugin, 0, delay);
|
||||||
}
|
}
|
||||||
@ -1214,7 +1244,9 @@ public enum Sounds {
|
|||||||
Objects.requireNonNull(player, "Cannot stop playing sound from null player");
|
Objects.requireNonNull(player, "Cannot stop playing sound from null player");
|
||||||
|
|
||||||
Sound sound = this.parseSound();
|
Sound sound = this.parseSound();
|
||||||
if (sound != null) player.stopSound(sound);
|
if (sound != null) {
|
||||||
|
player.stopSound(sound);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user