Permalink
Browse files

Add new particle types: SQUID_INK, BUBBLE_POP, CURRENT_DOWN, BUBBLE_C…

…OLUMN_UP, NAUTILUS, DOLPHIN
  • Loading branch information...
PseudoKnight committed Aug 3, 2018
1 parent ae88091 commit 684994522199f35e7d1c3f8222618ced184613c8
@@ -64,7 +64,7 @@ public int getDurationOnUse() {
@Override
public MCParticle getParticle() {
return BukkitMCParticle.getConvertor().getAbstractedEnum(aec.getParticle());
return BukkitMCParticle.valueOfConcrete(aec.getParticle());
}
@Override
@@ -135,7 +135,7 @@ public void setDurationOnUse(int ticks) {
@Override
public void setParticle(MCParticle particle) {
aec.setParticle(BukkitMCParticle.getConvertor().getConcreteEnum(particle));
aec.setParticle(((BukkitMCParticle) particle).getConcrete());
}
@Override
@@ -1,56 +1,144 @@
package com.laytonsmith.abstraction.enums;
import com.laytonsmith.PureUtilities.ClassLoading.DynamicEnum;
import com.laytonsmith.annotations.MDynamicEnum;
import com.laytonsmith.annotations.MEnum;
import com.laytonsmith.core.Static;
@MEnum("Particle")
public enum MCParticle {
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,
FOOTSTEP,
CLOUD,
REDSTONE,
SNOWBALL,
SNOW_SHOVEL,
SLIME,
HEART,
BARRIER,
ITEM_CRACK,
BLOCK_CRACK,
BLOCK_DUST,
WATER_DROP,
ITEM_TAKE,
MOB_APPEARANCE,
DRAGON_BREATH,
END_ROD,
DAMAGE_INDICATOR,
SWEEP_ATTACK,
FALLING_DUST,
TOTEM,
SPIT
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@MDynamicEnum("Particle")
public abstract class MCParticle<Concrete> extends DynamicEnum<MCParticle.MCVanillaParticle, Concrete> {
protected static final Map<String, MCParticle> MAP = new HashMap<>();
@SuppressWarnings("checkstyle:staticvariablename") // Fixing this violation might break dependents.
public static MCParticle NULL = null;
public MCParticle(MCVanillaParticle mcVanillaParticle, Concrete concrete) {
super(mcVanillaParticle, concrete);
}
public static MCParticle valueOf(String test) throws IllegalArgumentException {
MCParticle ret = MAP.get(test);
if(ret == null) {
throw new IllegalArgumentException("Unknown particle type: " + test);
}
return ret;
}
/**
* @return Names of available particles
*/
public static Set<String> types() {
if(NULL == null) { // docs mode
Set<String> dummy = new HashSet<>();
for(final MCVanillaParticle t : MCVanillaParticle.values()) {
dummy.add(t.name());
}
return dummy;
}
return MAP.keySet();
}
/**
* @return Our own MCParticle list
*/
public static Collection<MCParticle> values() {
if(NULL == null) { // docs mode
ArrayList<MCParticle> dummy = new ArrayList<>();
for(final MCParticle.MCVanillaParticle p : MCParticle.MCVanillaParticle.values()) {
dummy.add(new MCParticle<Object>(p, null) {
@Override
public String name() {
return p.name();
}
@Override
public String concreteName() {
return p.name();
}
});
}
return dummy;
}
return MAP.values();
}
@MEnum("VanillaParticle")
public enum MCVanillaParticle {
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,
SNOWBALL,
SNOW_SHOVEL,
SLIME,
HEART,
BARRIER,
ITEM_CRACK,
BLOCK_CRACK,
BLOCK_DUST,
WATER_DROP,
MOB_APPEARANCE,
DRAGON_BREATH,
END_ROD,
DAMAGE_INDICATOR,
SWEEP_ATTACK,
FALLING_DUST,
TOTEM,
SPIT,
SQUID_INK,
BUBBLE_POP,
CURRENT_DOWN,
BUBBLE_COLUMN_UP,
NAUTILUS,
DOLPHIN,
UNKNOWN(MCVersion.NEVER);
private final MCVersion since;
MCVanillaParticle() {
this(MCVersion.MC1_0);
}
MCVanillaParticle(MCVersion since) {
this.since = since;
}
public boolean existsInCurrent() {
return Static.getServer().getMinecraftVersion().gte(since);
}
}
}
@@ -1,34 +1,70 @@
package com.laytonsmith.abstraction.enums.bukkit;
import com.laytonsmith.abstraction.Implementation;
import com.laytonsmith.abstraction.enums.EnumConvertor;
import com.laytonsmith.abstraction.enums.MCParticle;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.annotations.abstractionenum;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.CHLog;
import com.laytonsmith.core.constructs.Target;
import org.bukkit.Particle;
@abstractionenum(
implementation = Implementation.Type.BUKKIT,
forAbstractEnum = MCParticle.class,
forConcreteEnum = Particle.class
)
public class BukkitMCParticle extends EnumConvertor<MCParticle, Particle> {
import java.util.HashMap;
import java.util.Map;
private static BukkitMCParticle instance;
public class BukkitMCParticle extends MCParticle<Particle> {
public static BukkitMCParticle getConvertor() {
if(instance == null) {
instance = new BukkitMCParticle();
}
return instance;
private static final Map<Particle, MCParticle> BUKKIT_MAP = new HashMap<>();
public BukkitMCParticle(MCVanillaParticle vanillaParticle, Particle particle) {
super(vanillaParticle, particle);
}
@Override
protected Particle getConcreteEnumCustom(MCParticle abstracted) {
if(Static.getServer().getMinecraftVersion().lt(MCVersion.MC1_9)) {
return null;
public String name() {
return getAbstracted() == MCVanillaParticle.UNKNOWN ? concreteName() : getAbstracted().name();
}
@Override
public String concreteName() {
Particle b = getConcrete();
if(b == null) {
return "null";
}
return b.name();
}
public static MCParticle valueOfConcrete(Particle test) {
MCParticle type = BUKKIT_MAP.get(test);
if(type == null) {
return NULL;
}
return type;
}
// This way we don't take up extra memory on non-bukkit implementations
public static void build() {
NULL = new BukkitMCParticle(MCVanillaParticle.UNKNOWN, null);
for(MCVanillaParticle v : MCVanillaParticle.values()) {
if(v.existsInCurrent()) {
Particle type;
try {
type = getBukkitType(v);
} catch (IllegalArgumentException | NoSuchFieldError ex) {
CHLog.GetLogger().w(CHLog.Tags.RUNTIME, "Could not find a Bukkit Particle for " + v.name(), Target.UNKNOWN);
continue;
}
BukkitMCParticle wrapper = new BukkitMCParticle(v, type);
BUKKIT_MAP.put(type, wrapper);
MAP.put(v.name(), wrapper);
}
}
return super.getConcreteEnumCustom(abstracted);
for(Particle b : Particle.values()) {
if(!BUKKIT_MAP.containsKey(b)) {
MAP.put(b.name(), new BukkitMCParticle(MCVanillaParticle.UNKNOWN, b));
BUKKIT_MAP.put(b, new BukkitMCParticle(MCVanillaParticle.UNKNOWN, b));
}
}
}
private static Particle getBukkitType(MCVanillaParticle v) {
// remap name changes
return Particle.valueOf(v.name());
}
}

0 comments on commit 6849945

Please sign in to comment.