Skip to content

Commit

Permalink
Version 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Asleeepp committed Feb 16, 2024
1 parent 791787a commit ec09af5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package me.asleepp.SkriptItemsAdder.elements.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
Expand All @@ -11,12 +15,17 @@

import javax.annotation.Nullable;


@Name("Play Break Effect")
@Description({"Play the breaking effect on a custom block."})
@Examples({"play the break effect on custom block \"chiseled_diamond_block\" "})
@Since("1.2")
public class EffPlayBreakEffect extends Effect {

private Expression<String> customBlockId;

static {
Skript.registerEffect(EffPlayBreakEffect.class, new String[] {"(play|make) [the] break effect on (custom|ia|itemsadder) block %string%"});
Skript.registerEffect(EffPlayBreakEffect.class, new String[] {"(play|make) [the] break[ing] effect on (custom|ia|itemsadder) block %string%"});
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
package me.asleepp.SkriptItemsAdder.elements.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import dev.lone.itemsadder.api.CustomBlock;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;

import javax.annotation.Nullable;

import org.bukkit.entity.Entity;

@Name("Play Break Sound")
@Description({"Play the breaking sound from a custom block to a player(s)"})
@Examples({"play the break sound from custom block \"ruby_block\" to all players"})
@Since("1.2")
public class EffPlayBreakSound extends Effect {

private Expression<String> customBlockId;
private Expression<Entity> entities;
private Expression<Player> players;

static {
Skript.registerEffect(EffPlayBreakSound.class, new String[] {"play [the] break sound from (custom|ia|itemsadder) block %string% to %entities%"});
Skript.registerEffect(EffPlayBreakSound.class, new String[] {"play [the] break[ing] sound from (custom|ia|itemsadder) block %string% to %players%"});
}

@Override
protected void execute(Event e) {
String customBlockId = this.customBlockId.getSingle(e);
Entity[] entities = this.entities.getArray(e);
Player[] players = this.players.getArray(e);

if (customBlockId != null) {
CustomBlock customBlock = CustomBlock.getInstance(customBlockId);
if (customBlock != null) {
Block bukkitBlock = customBlock.getBlock();
if (bukkitBlock != null) {
for (Entity entity : entities) {
if (entity.getLocation().distance(bukkitBlock.getLocation()) <= 16) { // probably not 16 blocks but whatever
for (Player player : players) {
if (player.getLocation().distance(bukkitBlock.getLocation()) <= 5) { // probably not 5 blocks but whatever
CustomBlock.playBreakSound(bukkitBlock);
}
}
Expand All @@ -44,13 +52,13 @@ protected void execute(Event e) {

@Override
public String toString(@Nullable Event e, boolean debug) {
return "play the break sound from custom block " + customBlockId.toString(e, debug) + " to " + entities.toString(e, debug);
return "play the break sound from custom block " + customBlockId.toString(e, debug) + " to " + players.toString(e, debug);
}

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
this.customBlockId = (Expression<String>) exprs[0];
this.entities = (Expression<Entity>) exprs[1];
this.players = (Expression<Player>) exprs[1];
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
package me.asleepp.SkriptItemsAdder.elements.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import dev.lone.itemsadder.api.CustomBlock;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;

import javax.annotation.Nullable;

import org.bukkit.entity.Entity;


@Name("Play Place Sound")
@Description({"Play the placing sound from a custom block to a player(s)"})
@Examples({"play the place sound from custom block \"ruby_block\" to all players"})
@Since("1.2")
public class EffPlayPlaceSound extends Effect {

private Expression<String> customBlockId;
private Expression<Entity> entities;
private Expression<Player> players;

static {
Skript.registerEffect(EffPlayPlaceSound.class, new String[] {"play [the] place sound from (custom|ia|itemsadder) block %string% to %entities%"});
Skript.registerEffect(EffPlayPlaceSound.class, new String[] {"play [the] plac[e|ing] sound from (custom|ia|itemsadder) block %string% to %players%"});
}

@Override
protected void execute(Event e) {
String customBlockId = this.customBlockId.getSingle(e);
Entity[] entities = this.entities.getArray(e);
Player[] players = this.players.getArray(e);

if (customBlockId != null) {
CustomBlock customBlock = CustomBlock.getInstance(customBlockId);
if (customBlock != null) {
Block bukkitBlock = customBlock.getBlock();
if (bukkitBlock != null) {
for (Entity entity : entities) {
if (entity.getLocation().distance(bukkitBlock.getLocation()) <= 16) {
for (Player player : players) {
if (player.getLocation().distance(bukkitBlock.getLocation()) <= 5) {
CustomBlock.playPlaceSound(bukkitBlock);
}
}
Expand All @@ -44,13 +54,13 @@ protected void execute(Event e) {

@Override
public String toString(@Nullable Event e, boolean debug) {
return "play the place sound from custom block " + customBlockId.toString(e, debug) + " to " + entities.toString(e, debug);
return "play the place sound from custom block " + customBlockId.toString(e, debug) + " to " + players.toString(e, debug);
}

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
this.customBlockId = (Expression<String>) exprs[0];
this.entities = (Expression<Entity>) exprs[1];
this.players = (Expression<Player>) exprs[1];
return true;
}
}
Expand Down

0 comments on commit ec09af5

Please sign in to comment.