use of org.bukkit.Effect in project Glowstone by GlowstoneMC.
the class FlintAndSteelDispenseBehavior method playDispenseSound.
@Override
protected void playDispenseSound(GlowBlock block) {
Effect effect = successful ? Effect.CLICK2 : Effect.CLICK1;
block.getWorld().playEffect(block.getLocation(), effect, 0);
}
use of org.bukkit.Effect in project Denizen-For-Bukkit by DenizenScript.
the class PlayEffectCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
ParticleHelper particleHelper = NMSHandler.getParticleHelper();
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("location") && arg.matchesArgumentList(LocationTag.class) && (arg.matchesPrefix("at") || !arg.hasPrefix())) {
if (arg.matchesPrefix("at")) {
scriptEntry.addObject("no_offset", new ElementTag(true));
}
scriptEntry.addObject("location", arg.asType(ListTag.class).filter(LocationTag.class, scriptEntry));
continue;
} else if (!scriptEntry.hasObject("effect") && !scriptEntry.hasObject("particleeffect") && !scriptEntry.hasObject("iconcrack")) {
if (particleHelper.hasParticle(arg.getValue())) {
scriptEntry.addObject("particleeffect", particleHelper.getParticle(arg.getValue()));
continue;
} else if (arg.matches("barrier") && NMSHandler.getVersion().isAtLeast(NMSVersion.v1_18)) {
scriptEntry.addObject("particleeffect", particleHelper.getParticle("block_marker"));
scriptEntry.addObject("special_data", new ElementTag("barrier"));
continue;
} else if (arg.matches("random")) {
// Get another effect if "RANDOM" is used
List<Particle> visible = particleHelper.getVisibleParticles();
scriptEntry.addObject("particleeffect", visible.get(CoreUtilities.getRandom().nextInt(visible.size())));
continue;
} else if (arg.startsWith("iconcrack_")) {
Deprecations.oldPlayEffectSpecials.warn(scriptEntry);
// Allow iconcrack_[item] for item break effects (ex: iconcrack_stone)
String shrunk = arg.getValue().substring("iconcrack_".length());
ItemTag item = ItemTag.valueOf(shrunk, scriptEntry.context);
if (item != null) {
scriptEntry.addObject("iconcrack", item);
} else {
Debug.echoError("Invalid iconcrack_[item]. Must be a valid ItemTag!");
}
continue;
} else if (arg.matchesEnum(Effect.class)) {
scriptEntry.addObject("effect", Effect.valueOf(arg.getValue().toUpperCase()));
continue;
}
}
if (!scriptEntry.hasObject("radius") && arg.matchesFloat() && arg.matchesPrefix("visibility", "v", "radius", "r")) {
scriptEntry.addObject("radius", arg.asElement());
} else if (!scriptEntry.hasObject("data") && arg.matchesFloat() && arg.matchesPrefix("data", "d")) {
scriptEntry.addObject("data", arg.asElement());
} else if (!scriptEntry.hasObject("special_data") && arg.matchesPrefix("special_data")) {
scriptEntry.addObject("special_data", arg.asElement());
} else if (!scriptEntry.hasObject("quantity") && arg.matchesInteger() && arg.matchesPrefix("qty", "q", "quantity")) {
if (arg.matchesPrefix("q", "qty")) {
Deprecations.qtyTags.warn(scriptEntry);
}
scriptEntry.addObject("quantity", arg.asElement());
} else if (!scriptEntry.hasObject("offset") && arg.matchesFloat() && arg.matchesPrefix("offset", "o")) {
double offset = arg.asElement().asDouble();
scriptEntry.addObject("offset", new LocationTag(null, offset, offset, offset));
} else if (!scriptEntry.hasObject("offset") && arg.matchesArgumentType(LocationTag.class) && arg.matchesPrefix("offset", "o")) {
scriptEntry.addObject("offset", arg.asType(LocationTag.class));
} else if (!scriptEntry.hasObject("velocity") && arg.matchesArgumentType(LocationTag.class) && arg.matchesPrefix("velocity")) {
scriptEntry.addObject("velocity", arg.asType(LocationTag.class));
} else if (!scriptEntry.hasObject("targets") && arg.matchesArgumentList(PlayerTag.class) && arg.matchesPrefix("targets", "target", "t")) {
scriptEntry.addObject("targets", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("data", new ElementTag(0));
scriptEntry.defaultObject("radius", new ElementTag(15));
scriptEntry.defaultObject("quantity", new ElementTag(1));
scriptEntry.defaultObject("offset", new LocationTag(null, 0.5, 0.5, 0.5));
if (!scriptEntry.hasObject("effect") && !scriptEntry.hasObject("particleeffect") && !scriptEntry.hasObject("iconcrack")) {
throw new InvalidArgumentsException("Missing effect argument!");
}
if (!scriptEntry.hasObject("location")) {
throw new InvalidArgumentsException("Missing location argument!");
}
}
use of org.bukkit.Effect in project Denizen-For-Bukkit by DenizenScript.
the class PlayEffectCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
List<LocationTag> locations = (List<LocationTag>) scriptEntry.getObject("location");
List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
Effect effect = (Effect) scriptEntry.getObject("effect");
Particle particleEffect = (Particle) scriptEntry.getObject("particleeffect");
ItemTag iconcrack = scriptEntry.getObjectTag("iconcrack");
ElementTag radius = scriptEntry.getElement("radius");
ElementTag data = scriptEntry.getElement("data");
ElementTag quantity = scriptEntry.getElement("quantity");
ElementTag no_offset = scriptEntry.getElement("no_offset");
boolean should_offset = no_offset == null || !no_offset.asBoolean();
LocationTag offset = scriptEntry.getObjectTag("offset");
ElementTag special_data = scriptEntry.getElement("special_data");
LocationTag velocity = scriptEntry.getObjectTag("velocity");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (effect != null ? db("effect", effect.name()) : particleEffect != null ? db("special effect", particleEffect.getName()) : iconcrack), db("locations", locations), db("targets", targets), radius, data, quantity, offset, special_data, velocity, (should_offset ? db("note", "Location will be offset 1 block-height upward (see documentation)") : ""));
}
for (LocationTag location : locations) {
if (should_offset) {
// Slightly increase the location's Y so effects don't seem to come out of the ground
location = new LocationTag(location.clone().add(0, 1, 0));
}
// Play the Bukkit effect the number of times specified
if (effect != null) {
for (int n = 0; n < quantity.asInt(); n++) {
if (targets != null) {
for (PlayerTag player : targets) {
if (player.isValid() && player.isOnline()) {
// TODO: 1.13
player.getPlayerEntity().playEffect(location, effect, data.asInt());
}
}
} else {
location.getWorld().playEffect(location, effect, data.asInt(), radius.asInt());
}
}
} else // Play a ParticleEffect
if (particleEffect != null) {
List<Player> players = new ArrayList<>();
if (targets == null) {
float rad = radius.asFloat();
for (Player player : location.getWorld().getPlayers()) {
if (player.getLocation().distanceSquared(location) < rad * rad) {
players.add(player);
}
}
} else {
for (PlayerTag player : targets) {
if (player.isValid() && player.isOnline()) {
players.add(player.getPlayerEntity());
}
}
}
Class clazz = particleEffect.neededData();
Object dataObject = null;
if (clazz != null) {
if (special_data == null) {
Debug.echoError("Missing required special data for particle: " + particleEffect.getName());
return;
} else if (clazz == org.bukkit.Particle.DustOptions.class) {
ListTag dataList = ListTag.valueOf(special_data.asString(), scriptEntry.getContext());
if (dataList.size() != 2) {
Debug.echoError("DustOptions special_data must have 2 list entries for particle: " + particleEffect.getName());
return;
} else {
float size = Float.parseFloat(dataList.get(0));
ColorTag color = ColorTag.valueOf(dataList.get(1), scriptEntry.context);
dataObject = new org.bukkit.Particle.DustOptions(color.getColor(), size);
}
} else if (clazz == BlockData.class) {
MaterialTag blockMaterial = MaterialTag.valueOf(special_data.asString(), scriptEntry.getContext());
dataObject = blockMaterial.getModernData();
} else if (clazz == ItemStack.class) {
ItemTag itemType = ItemTag.valueOf(special_data.asString(), scriptEntry.getContext());
dataObject = itemType.getItemStack();
} else // Intentionally list last due to requiring 1.17+
if (clazz == org.bukkit.Particle.DustTransition.class) {
ListTag dataList = ListTag.valueOf(special_data.asString(), scriptEntry.getContext());
if (dataList.size() != 3) {
Debug.echoError("DustTransition special_data must have 3 list entries for particle: " + particleEffect.getName());
return;
} else {
float size = Float.parseFloat(dataList.get(0));
ColorTag fromColor = ColorTag.valueOf(dataList.get(1), scriptEntry.context);
ColorTag toColor = ColorTag.valueOf(dataList.get(2), scriptEntry.context);
dataObject = new org.bukkit.Particle.DustTransition(fromColor.getColor(), toColor.getColor(), size);
}
} else {
Debug.echoError("Unknown particle data type: " + clazz.getCanonicalName() + " for particle: " + particleEffect.getName());
return;
}
} else if (special_data != null) {
Debug.echoError("Particles of type '" + particleEffect.getName() + "' cannot take special_data as input.");
return;
}
Random random = CoreUtilities.getRandom();
int quantityInt = quantity.asInt();
for (Player player : players) {
if (velocity == null) {
particleEffect.playFor(player, location, quantityInt, offset.toVector(), data.asDouble(), dataObject);
} else {
Vector velocityVector = velocity.toVector();
for (int i = 0; i < quantityInt; i++) {
LocationTag singleLocation = location.clone().add((random.nextDouble() - 0.5) * offset.getX(), (random.nextDouble() - 0.5) * offset.getY(), (random.nextDouble() - 0.5) * offset.getZ());
particleEffect.playFor(player, singleLocation, 0, velocityVector, 1f, dataObject);
}
}
}
} else // Play an iconcrack (item break) effect
{
List<Player> players = new ArrayList<>();
if (targets == null) {
float rad = radius.asFloat();
for (Player player : location.getWorld().getPlayers()) {
if (player.getLocation().distanceSquared(location) < rad * rad) {
players.add(player);
}
}
} else {
for (PlayerTag player : targets) {
if (player.isValid() && player.isOnline()) {
players.add(player.getPlayerEntity());
}
}
}
if (iconcrack != null) {
ItemStack itemStack = iconcrack.getItemStack();
Particle particle = NMSHandler.getParticleHelper().getParticle("ITEM_CRACK");
for (Player player : players) {
particle.playFor(player, location, quantity.asInt(), offset.toVector(), data.asFloat(), itemStack);
}
}
}
}
}
Aggregations