Skip to content

Instantly share code, notes, and snippets.

@DarkBlade12
Last active December 28, 2015 08:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarkBlade12/7472992 to your computer and use it in GitHub Desktop.
Save DarkBlade12/7472992 to your computer and use it in GitHub Desktop.
These classes provide a way to store a ParticleEffect with methods for serializing/deserializing.
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* This class is part of the ParticleEffect library and follows the same usage conditions
*
* @author DarkBlade12
*/
public class BlockCrackData extends ParticleEffectData {
private static final String FORMAT = "\\d+@\\d+(@\\d+(\\.\\d+)?){3}@\\d+";
private final int id;
private final byte data;
public BlockCrackData(int id, byte data, float offsetX, float offsetY, float offsetZ, int amount) {
super(offsetX, offsetY, offsetZ, amount);
this.id = id;
this.data = data;
}
public static BlockCrackData fromString(String s) throws IllegalArgumentException {
if (!s.matches(FORMAT))
throw new IllegalArgumentException("Invalid format");
String[] p = s.split("@");
return new BlockCrackData(Integer.parseInt(p[0]), Byte.parseByte(p[1]), Float.parseFloat(p[2]), Float.parseFloat(p[3]), Float.parseFloat(p[4]), Integer.parseInt(p[5]));
}
@Override
public void displayEffect(Location center, Player... players) {
ParticleEffect.displayBlockCrack(center, id, data, offsetX, offsetY, offsetZ, amount, players);
}
@Override
public void displayEffect(Location center) {
ParticleEffect.displayBlockCrack(center, id, data, offsetX, offsetY, offsetZ, amount);
}
@Override
public void displayEffect(Location center, double range) {
ParticleEffect.displayBlockCrack(center, range, id, data, offsetX, offsetY, offsetZ, amount);
}
public int getId() {
return this.id;
}
public byte getData() {
return this.data;
}
@Override
public String toString() {
return id + "@" + data + "@" + super.toString();
}
}
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* This class is part of the ParticleEffect library and follows the same usage conditions
*
* @author DarkBlade12
*/
public class BlockDustData extends ParticleEffectData {
private static final String FORMAT = "\\d+@\\d+(@\\d+(\\.\\d+)?){3}@\\d+@\\d+(\\.\\d+)?";
private final int id;
private final byte data;
private final float speed;
public BlockDustData(int id, byte data, float offsetX, float offsetY, float offsetZ, int amount, float speed) {
super(offsetX, offsetY, offsetZ, amount);
this.id = id;
this.data = data;
this.speed = speed;
}
public static BlockDustData fromString(String s) throws IllegalArgumentException {
if (!s.matches(FORMAT))
throw new IllegalArgumentException("Invalid format");
String[] p = s.split("@");
return new BlockDustData(Integer.parseInt(p[0]), Byte.parseByte(p[1]), Float.parseFloat(p[2]), Float.parseFloat(p[3]), Float.parseFloat(p[4]), Integer.parseInt(p[5]), Float.parseFloat(p[6]));
}
@Override
public void displayEffect(Location center, Player... players) {
ParticleEffect.displayBlockDust(center, id, data, offsetX, offsetY, offsetZ, speed, amount, players);
}
@Override
public void displayEffect(Location center) {
ParticleEffect.displayBlockDust(center, id, data, offsetX, offsetY, offsetZ, speed, amount);
}
@Override
public void displayEffect(Location center, double range) {
ParticleEffect.displayBlockDust(center, range, id, data, offsetX, offsetY, offsetZ, speed, amount);
}
public int getId() {
return this.id;
}
public byte getData() {
return this.data;
}
public float getSpeed() {
return this.speed;
}
@Override
public String toString() {
return id + "@" + data + "@" + super.toString() + "@" + speed;
}
}
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* This class is part of the ParticleEffect library and follows the same usage conditions
*
* @author DarkBlade12
*/
public class IconCrackData extends ParticleEffectData {
private static final String FORMAT = "\\d+(@\\d+(\\.\\d+)?){3}@\\d+@\\d+(\\.\\d+)?";
private final int id;
private final float speed;
public IconCrackData(int id, float offsetX, float offsetY, float offsetZ, int amount, float speed) {
super(offsetX, offsetY, offsetZ, amount);
this.id = id;
this.speed = speed;
}
public static IconCrackData fromString(String s) throws IllegalArgumentException {
if (!s.matches(FORMAT))
throw new IllegalArgumentException("Invalid format");
String[] p = s.split("@");
return new IconCrackData(Integer.parseInt(p[0]), Float.parseFloat(p[1]), Float.parseFloat(p[2]), Float.parseFloat(p[3]), Integer.parseInt(p[4]), Float.parseFloat(p[5]));
}
@Override
public void displayEffect(Location center, Player... players) {
ParticleEffect.displayIconCrack(center, id, offsetX, offsetY, offsetZ, speed, amount, players);
}
@Override
public void displayEffect(Location center) {
ParticleEffect.displayIconCrack(center, id, offsetX, offsetY, offsetZ, speed, amount);
}
@Override
public void displayEffect(Location center, double range) {
ParticleEffect.displayIconCrack(center, range, id, offsetX, offsetY, offsetZ, speed, amount);
}
public int getId() {
return this.id;
}
public float getSpeed() {
return this.speed;
}
@Override
public String toString() {
return id + "@" + super.toString() + "@" + speed;
}
}
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* This class is part of the ParticleEffect library and follows the same usage conditions
*
* @author DarkBlade12
*/
public class NormalEffectData extends ParticleEffectData {
private static final String FORMAT = "\\w+(@\\d+(\\.\\d+)?){3}@\\d+@\\d+(\\.\\d+)?";
private final ParticleEffect effect;
private final float speed;
public NormalEffectData(ParticleEffect effect, float offsetX, float offsetY, float offsetZ, int amount, float speed) {
super(offsetX, offsetY, offsetZ, amount);
this.effect = effect;
this.speed = speed;
}
public static NormalEffectData fromString(String s) throws IllegalArgumentException {
if (!s.matches(FORMAT))
throw new IllegalArgumentException("Invalid format");
String[] p = s.split("@");
ParticleEffect effect = ParticleEffect.fromName(p[0]);
if (effect == null)
throw new IllegalArgumentException("Contains an invalid particle effect name");
return new NormalEffectData(effect, Float.parseFloat(p[1]), Float.parseFloat(p[2]), Float.parseFloat(p[3]), Integer.parseInt(p[4]), Float.parseFloat(p[5]));
}
@Override
public void displayEffect(Location center, Player... players) {
effect.display(center, offsetX, offsetY, offsetZ, speed, amount, players);
}
@Override
public void displayEffect(Location center) {
effect.display(center, offsetX, offsetY, offsetZ, speed, amount);
}
@Override
public void displayEffect(Location center, double range) {
effect.display(center, range, offsetX, offsetY, offsetZ, speed, amount);
}
public ParticleEffect getEffect() {
return this.effect;
}
public float getSpeed() {
return this.speed;
}
@Override
public String toString() {
return effect.getName() + "@" + super.toString() + "@" + speed;
}
}
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* This class is part of the ParticleEffect library and follows the same usage conditions
*
* @author DarkBlade12
*/
public abstract class ParticleEffectData {
protected final float offsetX, offsetY, offsetZ;
protected final int amount;
public ParticleEffectData(float offsetX, float offsetY, float offsetZ, int amount) {
this.offsetX = offsetX;
this.offsetY = offsetY;
this.offsetZ = offsetZ;
this.amount = amount;
}
public abstract void displayEffect(Location center, Player... players);
public abstract void displayEffect(Location center);
public abstract void displayEffect(Location center, double range);
public float getOffsetX() {
return this.offsetX;
}
public float getOffsetY() {
return this.offsetY;
}
public float getOffsetZ() {
return this.offsetZ;
}
public int getAmount() {
return this.amount;
}
@Override
public String toString() {
return offsetX + "@" + offsetY + "@" + offsetZ + "@" + amount;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment