Skip to content

Commit

Permalink
More progress on particle system
Browse files Browse the repository at this point in the history
  • Loading branch information
bensku committed Apr 10, 2016
1 parent 0b4e174 commit 1c0e963
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
40 changes: 26 additions & 14 deletions src/main/java/ch/njol/skript/util/VisualEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.bukkit.EntityEffect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -89,19 +90,19 @@ public Object getData(final @Nullable Object raw, final Location l) {
MAGIC_CRIT(Effect.MAGIC_CRIT),
POTION_SWIRL(Effect.POTION_SWIRL) {
@Override
public boolean supportsColors() {
public boolean isColorable() {
return true;
}
},
POTION_SWIRL_TRANSPARENT(Effect.POTION_SWIRL_TRANSPARENT) {
@Override
public boolean supportsColors() {
public boolean isColorable() {
return true;
}
},
SPELL(Effect.SPELL),
INSTANT_SPELL(Effect.INSTANT_SPELL),
WITCH_MAGIC(Effect.WITCH_MAGIC),
WITCH_SPELL(Effect.WITCH_MAGIC),
NOTE(Effect.NOTE),
PORTAL(Effect.PORTAL),
FLYING_GLYPH(Effect.FLYING_GLYPH),
Expand All @@ -118,7 +119,7 @@ public boolean supportsColors() {
CLOUD(Effect.CLOUD),
COLOURED_DUST(Effect.COLOURED_DUST) {
@Override
public boolean supportsColors() {
public boolean isColorable() {
return true;
}
},
Expand All @@ -131,7 +132,7 @@ public boolean supportsColors() {
ANGRY_VILLAGER(Effect.VILLAGER_THUNDERCLOUD),
HAPPY_VILLAGER(Effect.HAPPY_VILLAGER),
LARGE_SMOKE(Effect.LARGE_SMOKE),
ITEM_BREAK(Effect.ITEM_BREAK) {
ITEM_CRACK(Effect.ITEM_BREAK) {
@Override
public Object getData(final @Nullable Object raw, final Location l) {
if (raw == null)
Expand All @@ -147,7 +148,7 @@ else if (raw instanceof ItemType) {
}
}
},
TILE_BREAK(Effect.TILE_BREAK) {
BLOCK_BREAK(Effect.TILE_BREAK) {
@SuppressWarnings("null")
@Override
public Object getData(final @Nullable Object raw, final Location l) {
Expand All @@ -164,7 +165,7 @@ else if (raw instanceof ItemType) {
}
}
},
TILE_DUST(Effect.TILE_DUST) {
BLOCK_DUST(Effect.TILE_DUST) {
@SuppressWarnings("null")
@Override
public Object getData(final @Nullable Object raw, final Location l) {
Expand Down Expand Up @@ -204,7 +205,7 @@ public Object getData(final @Nullable Object raw, final Location l) {
/**
* Checks if this effect has color support.
*/
public boolean supportsColors() {
public boolean isColorable() {
return false;
}
}
Expand Down Expand Up @@ -235,7 +236,7 @@ public void onLanguageChange() {
Skript.warning("Missing pattern at '" + (node + ".pattern") + "' in the " + Language.getName() + " language file");
} else {
types.add(ts[i]);
if (ts[i].supportsColors())
if (ts[i].isColorable())
patterns.add(pattern);
else {
String dVarExpr = Language.get_(LANGUAGE_NODE + ".area_expression");
Expand Down Expand Up @@ -272,7 +273,7 @@ public VisualEffect() {}
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
type = types.get(matchedPattern);

if (type.supportsColors()) {
if (type.isColorable()) {
for (Expression<?> expr : exprs) {
if (expr.getReturnType() == Color.class)
color = (Color) expr.getSingle(null);
Expand Down Expand Up @@ -322,19 +323,30 @@ public final static VisualEffect parse(final String s) {
}

public void play(final @Nullable Player[] ps, final Location l, final @Nullable Entity e) {
play(ps, l, e, 0);
play(ps, l, e, 0, 0);
}

public void play(final @Nullable Player[] ps, final Location l, final @Nullable Entity e, final int radius) {
@SuppressWarnings({"deprecation", "null"})
public void play(final @Nullable Player[] ps, final Location l, final @Nullable Entity e, final int count, final int radius) {
assert e == null || l.equals(e.getLocation());
if (isEntityEffect()) {
if (e != null)
e.playEffect((EntityEffect) type.effect);
} else {
if (ps == null) {
if (radius == 0)
int id = 0;
int dt = 0;

if (data instanceof Material) {
id = ((Material) data).getId();
} else if (data instanceof MaterialData) {
id = ((MaterialData) data).getItemTypeId();
dt = ((MaterialData) data).getData();
}

if (radius == 0) {
l.getWorld().playEffect(l, (Effect) type.effect, type.getData(data, l));
else
} else
l.getWorld().playEffect(l, (Effect) type.effect, type.getData(data, l), radius);
} else {
for (final Player p : ps)
Expand Down
24 changes: 12 additions & 12 deletions src/main/resources/lang/english.lang
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,9 @@ visual effects:
instant_spell:
name: spell @a
pattern: instant (spell|thrown potion)
witch_magic:
name: witch magic @-
pattern: witch magic|purple sparks
witch_spell:
name: witch spell @-
pattern: witch (magic|spell)|purple sparks
note:
name: note @a
pattern: note
Expand All @@ -889,8 +889,8 @@ visual effects:
name: lava pop @a
pattern: lava [pop]
footstep:
name: footstep @a
pattern: footstep
name: footstep @x
pattern: footsteps
splash:
name: water splash @a
pattern: [water] splash
Expand Down Expand Up @@ -945,14 +945,14 @@ visual effects:
large_smoke:
name: large smoke @-
pattern: large smoke
item_break:
name: item break @-
pattern: %itemtype% item break[ing]
tile_break:
name: tile break @-
item_crack:
name: item crack @-
pattern: %itemtype% item (break|crack)[ing]
block_break:
name: block break @-
pattern: %itemtype% break[ing]
tile_dust:
name: tile dust @-
block_dust:
name: block dust @-
pattern: [sprinting] dust of [%itemtype%]
area_expression: [with] [area of %number%, %number%(,| and) %number%][[ and] speed of %number%]

Expand Down

0 comments on commit 1c0e963

Please sign in to comment.