mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-23 18:45:34 +01:00
add particle compatiblity handler, more config adapter methods
This commit is contained in:
parent
d04de3159c
commit
ed30cfcedd
@ -1,5 +1,6 @@
|
||||
package com.songoda.core.compatibility;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
@ -7,7 +8,165 @@ import org.bukkit.Particle;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
public class ParticleHandler {
|
||||
|
||||
|
||||
public static enum ParticleType {
|
||||
EXPLOSION_NORMAL(),
|
||||
EXPLOSION_LARGE,
|
||||
EXPLOSION_HUGE,
|
||||
FIREWORKS_SPARK,
|
||||
WATER_BUBBLE,
|
||||
WATER_SPLASH,
|
||||
WATER_WAKE,
|
||||
SUSPENDED,
|
||||
SUSPENDED_DEPTH,
|
||||
CRIT,
|
||||
CRIT_MAGIC,
|
||||
SMOKE_NORMAL,
|
||||
SMOKE_LARGE,
|
||||
SPELL,
|
||||
SPELL_INSTANT,
|
||||
SPELL_MOB,
|
||||
SPELL_MOB_AMBIENT,
|
||||
SPELL_WITCH,
|
||||
DRIP_WATER,
|
||||
DRIP_LAVA,
|
||||
VILLAGER_ANGRY,
|
||||
VILLAGER_HAPPY,
|
||||
TOWN_AURA,
|
||||
NOTE,
|
||||
PORTAL,
|
||||
ENCHANTMENT_TABLE,
|
||||
FLAME,
|
||||
LAVA,
|
||||
CLOUD,
|
||||
REDSTONE(), //DustOptions
|
||||
SNOWBALL,
|
||||
SNOW_SHOVEL,
|
||||
SLIME,
|
||||
HEART,
|
||||
BARRIER,
|
||||
ITEM_CRACK(), // ItemStack
|
||||
BLOCK_CRACK(), // BlockData
|
||||
BLOCK_DUST(), // BlockData
|
||||
WATER_DROP,
|
||||
// 1.9-1.12 included ITEM_TAKE
|
||||
MOB_APPEARANCE,
|
||||
DRAGON_BREATH,
|
||||
END_ROD,
|
||||
DAMAGE_INDICATOR,
|
||||
SWEEP_ATTACK,
|
||||
/// End 1.9 particles ///
|
||||
FALLING_DUST(ServerVersion.V1_10, "BLOCK_DUST"), // BlockData
|
||||
/// End 1.10 ///
|
||||
TOTEM(ServerVersion.V1_11, "VILLAGER_HAPPY"),
|
||||
SPIT(ServerVersion.V1_11, "REDSTONE"),
|
||||
/// End 1.11-1.12 ///
|
||||
SQUID_INK(ServerVersion.V1_13, "CRIT"),
|
||||
BUBBLE_POP(ServerVersion.V1_13, "CRIT"),
|
||||
CURRENT_DOWN(ServerVersion.V1_13, "CRIT"),
|
||||
BUBBLE_COLUMN_UP(ServerVersion.V1_13, "CRIT"),
|
||||
NAUTILUS(ServerVersion.V1_13, "END_ROD"),
|
||||
DOLPHIN(ServerVersion.V1_13, "TOWN_AURA"),
|
||||
/// End 1.13 ///
|
||||
SNEEZE(ServerVersion.V1_14, "REDSTONE"),
|
||||
CAMPFIRE_COSY_SMOKE(ServerVersion.V1_14, "SMOKE_NORMAL"),
|
||||
CAMPFIRE_SIGNAL_SMOKE(ServerVersion.V1_14, "SMOKE_LARGE"),
|
||||
COMPOSTER(ServerVersion.V1_14, "CRIT"),
|
||||
FLASH(ServerVersion.V1_14, "EXPLOSION_NORMAL"), // idk
|
||||
FALLING_LAVA(ServerVersion.V1_14, "DRIP_LAVA"),
|
||||
LANDING_LAVA(ServerVersion.V1_14, "LAVA"),
|
||||
FALLING_WATER(ServerVersion.V1_14, "DRIP_WATER"),
|
||||
/// End 1.14 ///
|
||||
;
|
||||
|
||||
final boolean compatibilityMode;
|
||||
final LegacyParticleEffects.Type compatibleEffect;
|
||||
final Object particle;
|
||||
|
||||
private ParticleType() {
|
||||
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
|
||||
this.compatibilityMode = true;
|
||||
this.particle = null;
|
||||
this.compatibleEffect = LegacyParticleEffects.Type.valueOf(name());
|
||||
} else {
|
||||
this.compatibleEffect = null;
|
||||
// does this particle exist in our version?
|
||||
Particle check = Stream.of(Particle.values()).filter(p -> p.name().equals(name())).findFirst().orElse(null);
|
||||
if (check != null) {
|
||||
this.particle = check;
|
||||
this.compatibilityMode = false;
|
||||
} else {
|
||||
// this shouldn't happen, really
|
||||
this.particle = Particle.END_ROD;
|
||||
this.compatibilityMode = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ParticleType(ServerVersion minVersion, String compatible) {
|
||||
// Particle class doesn't exist in 1.8
|
||||
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
|
||||
this.compatibilityMode = true;
|
||||
this.compatibleEffect = LegacyParticleEffects.Type.valueOf(compatible);
|
||||
this.particle = null;
|
||||
} else if (ServerVersion.isServerVersionBelow(minVersion)) {
|
||||
this.compatibilityMode = true;
|
||||
this.compatibleEffect = null;
|
||||
this.particle = Particle.valueOf(compatible);
|
||||
} else {
|
||||
this.compatibleEffect = null;
|
||||
// does this particle exist in our version?
|
||||
Particle check = Stream.of(Particle.values()).filter(p -> p.name().equals(name())).findFirst().orElse(null);
|
||||
if (check != null) {
|
||||
this.particle = check;
|
||||
this.compatibilityMode = false;
|
||||
} else {
|
||||
// this shouldn't happen, really
|
||||
this.particle = Particle.END_ROD;
|
||||
this.compatibilityMode = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void spawnParticles(ParticleType type, Location location) {
|
||||
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
|
||||
LegacyParticleEffects.createParticle(location, type.compatibleEffect);
|
||||
} else {
|
||||
location.getWorld().spawnParticle((Particle) type.particle, location, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void spawnParticles(ParticleType type, Location location, int count) {
|
||||
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
|
||||
LegacyParticleEffects.createParticle(location, type.compatibleEffect);
|
||||
for (int i = 0; i < count; i++) {
|
||||
float xx = (float) (1 * (Math.random() - Math.random()));
|
||||
float yy = (float) (1 * (Math.random() - Math.random()));
|
||||
float zz = (float) (1 * (Math.random() - Math.random()));
|
||||
Location at = location.clone().add(xx, yy, zz);
|
||||
LegacyParticleEffects.createParticle(at, LegacyParticleEffects.Type.REDSTONE);
|
||||
}
|
||||
} else {
|
||||
location.getWorld().spawnParticle((Particle) type.particle, location, count);
|
||||
}
|
||||
}
|
||||
|
||||
public static void spawnParticles(ParticleType type, Location location, int count, double offsetX, double offsetY, double offsetZ) {
|
||||
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8)) {
|
||||
LegacyParticleEffects.createParticle(location, type.compatibleEffect);
|
||||
for (int i = 0; i < count; i++) {
|
||||
float xx = (float) (offsetX * (Math.random() - Math.random()));
|
||||
float yy = (float) (offsetY * (Math.random() - Math.random()));
|
||||
float zz = (float) (offsetZ * (Math.random() - Math.random()));
|
||||
Location at = location.clone().add(xx, yy, zz);
|
||||
LegacyParticleEffects.createParticle(at, LegacyParticleEffects.Type.REDSTONE);
|
||||
}
|
||||
} else {
|
||||
location.getWorld().spawnParticle((Particle) type.particle, location, count, offsetX, offsetY, offsetZ);
|
||||
}
|
||||
}
|
||||
|
||||
public static void redstoneParticles(Location location, int red, int green, int blue) {
|
||||
redstoneParticles(location, red, green, blue, 1F, 1, 0);
|
||||
}
|
||||
|
@ -49,10 +49,18 @@ public enum ServerVersion {
|
||||
return ArrayUtils.contains(versions, serverVersion);
|
||||
}
|
||||
|
||||
public static boolean isServerVersionAbove(ServerVersion version) {
|
||||
return serverVersion.ordinal() > version.ordinal();
|
||||
}
|
||||
|
||||
public static boolean isServerVersionAtLeast(ServerVersion version) {
|
||||
return serverVersion.ordinal() >= version.ordinal();
|
||||
}
|
||||
|
||||
public static boolean isServerVersionAtOrBelow(ServerVersion version) {
|
||||
return serverVersion.ordinal() <= version.ordinal();
|
||||
}
|
||||
|
||||
public static boolean isServerVersionBelow(ServerVersion version) {
|
||||
return serverVersion.ordinal() < version.ordinal();
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.songoda.core.configuration;
|
||||
|
||||
import com.songoda.core.compatibility.LegacyMaterials;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@ -7,6 +10,8 @@ import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ConfigFileConfigurationAdapter extends FileConfiguration {
|
||||
|
||||
@ -116,4 +121,153 @@ public class ConfigFileConfigurationAdapter extends FileConfiguration {
|
||||
return config.createSection(path, map);
|
||||
}
|
||||
|
||||
// Other non-FileConfiguration methods
|
||||
|
||||
@NotNull
|
||||
public ConfigSection createDefaultSection(@NotNull String path) {
|
||||
return config.createDefaultSection(path);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection createDefaultSection(@NotNull String path, String... comment) {
|
||||
return config.createDefaultSection(path, comment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection createDefaultSection(@NotNull String path, ConfigFormattingRules.CommentStyle commentStyle, String... comment) {
|
||||
return config.createDefaultSection(path, commentStyle, comment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setComment(@NotNull String path, @Nullable ConfigFormattingRules.CommentStyle commentStyle, String... lines) {
|
||||
return config.setComment(path, commentStyle, lines);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setComment(@NotNull String path, @Nullable ConfigFormattingRules.CommentStyle commentStyle, @Nullable List<String> lines) {
|
||||
return config.setComment(path, commentStyle, lines);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setDefaultComment(@NotNull String path, String... lines) {
|
||||
return config.setDefaultComment(path, lines);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setDefaultComment(@NotNull String path, @Nullable List<String> lines) {
|
||||
return config.setDefaultComment(path, lines);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setDefaultComment(@NotNull String path, ConfigFormattingRules.CommentStyle commentStyle, String... lines) {
|
||||
return config.setDefaultComment(path, commentStyle, lines);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setDefaultComment(@NotNull String path, ConfigFormattingRules.CommentStyle commentStyle, @Nullable List<String> lines) {
|
||||
return config.setDefaultComment(path, commentStyle, lines);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Comment getComment(@NotNull String path) {
|
||||
return config.getComment(path);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getCommentString(@NotNull String path) {
|
||||
return config.getCommentString(path);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<ConfigSection> getSections(String path) {
|
||||
return config.getSections(path);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection set(@NotNull String path, @Nullable Object value, String... comment) {
|
||||
return config.set(path, value, comment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection set(@NotNull String path, @Nullable Object value, List<String> comment) {
|
||||
return config.set(path, value, comment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection set(@NotNull String path, @Nullable Object value, @Nullable ConfigFormattingRules.CommentStyle commentStyle, String... comment) {
|
||||
return config.set(path, value, commentStyle, comment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection set(@NotNull String path, @Nullable Object value, @Nullable ConfigFormattingRules.CommentStyle commentStyle, List<String> comment) {
|
||||
return config.set(path, value, commentStyle, comment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setDefault(@NotNull String path, @Nullable Object value) {
|
||||
return config.setDefault(path, value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setDefault(@NotNull String path, @Nullable Object value, String... comment) {
|
||||
return config.setDefault(path, value, comment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setDefault(@NotNull String path, @Nullable Object value, List<String> comment) {
|
||||
return config.setDefault(path, value, comment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setDefault(@NotNull String path, @Nullable Object value, ConfigFormattingRules.CommentStyle commentStyle, String... comment) {
|
||||
return config.setDefault(path, value, commentStyle, comment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection setDefault(@NotNull String path, @Nullable Object value, ConfigFormattingRules.CommentStyle commentStyle, List<String> comment) {
|
||||
return config.setDefault(path, value, commentStyle, comment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection createSection(@NotNull String path, String... comment) {
|
||||
return config.createSection(path, comment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection createSection(@NotNull String path, @Nullable List<String> comment) {
|
||||
return config.createSection(path, comment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection createSection(@NotNull String path, @Nullable ConfigFormattingRules.CommentStyle commentStyle, String... comment) {
|
||||
return config.createSection(path, commentStyle, comment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection createSection(@NotNull String path, @Nullable ConfigFormattingRules.CommentStyle commentStyle, @Nullable List<String> comment) {
|
||||
return config.createSection(path, commentStyle, comment);
|
||||
}
|
||||
|
||||
public char getChar(@NotNull String path) {
|
||||
return config.getChar(path);
|
||||
}
|
||||
|
||||
public char getChar(@NotNull String path, char def) {
|
||||
return config.getChar(path, def);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LegacyMaterials getMaterial(@NotNull String path) {
|
||||
return config.getMaterial(path);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LegacyMaterials getMaterial(@NotNull String path, @Nullable LegacyMaterials def) {
|
||||
return config.getMaterial(path, def);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection getOrCreateConfigurationSection(@NotNull String path) {
|
||||
return config.getOrCreateConfigurationSection(path);
|
||||
}
|
||||
}
|
||||
|
@ -629,6 +629,7 @@ public class ConfigSection extends MemoryConfiguration {
|
||||
return result instanceof ConfigSection ? (ConfigSection) result : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConfigSection getOrCreateConfigurationSection(@NotNull String path) {
|
||||
Object result = get(path);
|
||||
return result instanceof ConfigSection ? (ConfigSection) result : createSection(path);
|
||||
|
Loading…
Reference in New Issue
Block a user