Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5458036

Browse files
committed
Version 1.4
1 parent 71fece5 commit 5458036

16 files changed

+365
-75
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ compileJava {
1515
}
1616

1717
group = 'me.Asleepp'
18-
version = '1.3'
18+
version = '1.4'
1919

2020
repositories {
2121
mavenCentral()
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package me.asleepp.SkriptItemsAdder.elements.conditions;
2+
3+
import ch.njol.skript.Skript;
4+
import ch.njol.skript.doc.Description;
5+
import ch.njol.skript.doc.Examples;
6+
import ch.njol.skript.doc.Name;
7+
import ch.njol.skript.doc.Since;
8+
import ch.njol.skript.lang.Condition;
9+
import ch.njol.skript.lang.Expression;
10+
import ch.njol.skript.lang.SkriptParser;
11+
import ch.njol.util.Kleenean;
12+
import org.bukkit.event.Event;
13+
import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
14+
import org.bukkit.event.block.Action;
15+
16+
import javax.annotation.Nullable;
17+
@Name("Is Action")
18+
@Description({"This condition checks if the player has interacted with a custom block with either a left or a right click."})
19+
@Examples({"on interact with custom block: /tif interact action is right click: /t/tkill event-player "})
20+
@Since("1.4")
21+
public class CondGetAction extends Condition {
22+
23+
static {
24+
Skript.registerCondition(CondGetAction.class, "[custom|ia|itemsadder] [interact] action is (:right|:left) click");
25+
}
26+
27+
private boolean isLeft;
28+
29+
@Override
30+
public boolean check(Event e) {
31+
CustomBlockInteractEvent event = (CustomBlockInteractEvent) e;
32+
if (isLeft) {
33+
return event.getAction() == Action.LEFT_CLICK_BLOCK;
34+
} else {
35+
return event.getAction() == Action.RIGHT_CLICK_BLOCK;
36+
}
37+
}
38+
39+
@Override
40+
public String toString(@Nullable Event e, boolean debug) {
41+
return "interact action is " + (isLeft ? "left" : "right") + " click";
42+
}
43+
44+
@Override
45+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
46+
isLeft = parseResult.hasTag("left");
47+
return true;
48+
}
49+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package me.asleepp.SkriptItemsAdder.elements.conditions;
2+
3+
import ch.njol.skript.Skript;
4+
import ch.njol.skript.doc.Description;
5+
import ch.njol.skript.doc.Examples;
6+
import ch.njol.skript.doc.Name;
7+
import ch.njol.skript.doc.Since;
8+
import ch.njol.skript.lang.Condition;
9+
import ch.njol.skript.lang.Expression;
10+
import ch.njol.skript.lang.SkriptParser;
11+
import ch.njol.util.Kleenean;
12+
import org.bukkit.event.Event;
13+
import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
14+
15+
import javax.annotation.Nullable;
16+
@Name("Is Block Clicked")
17+
@Description({"This condition checks what block the player clicked."})
18+
@Examples({"on interact with custom block: /tif clicked block is \"diamond_tiles\" /t/tsend \"That's quite valuable.\" "})
19+
@Since("1.4")
20+
public class CondGetBlockClicked extends Condition {
21+
22+
private Expression<String> block;
23+
24+
static {
25+
Skript.registerCondition(CondGetBlockClicked.class, "[the] block clicked is %strings%");
26+
}
27+
28+
@Override
29+
public boolean check(Event e) {
30+
if (e instanceof CustomBlockInteractEvent) {
31+
CustomBlockInteractEvent event = (CustomBlockInteractEvent) e;
32+
String clickedBlock = event.getBlockClicked().getType().toString();
33+
return clickedBlock.equals(block.getSingle(e));
34+
}
35+
return false;
36+
}
37+
38+
@Override
39+
public String toString(@Nullable Event e, boolean debug) {
40+
return "[the] block clicked is " + block.toString(e, debug);
41+
}
42+
43+
@Override
44+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
45+
block = (Expression<String>) exprs[0];
46+
return true;
47+
}
48+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package me.asleepp.SkriptItemsAdder.elements.conditions;
2+
3+
import ch.njol.skript.Skript;
4+
import ch.njol.skript.doc.Description;
5+
import ch.njol.skript.doc.Examples;
6+
import ch.njol.skript.doc.Name;
7+
import ch.njol.skript.doc.Since;
8+
import ch.njol.skript.lang.Condition;
9+
import ch.njol.skript.lang.Expression;
10+
import ch.njol.skript.lang.SkriptParser;
11+
import ch.njol.util.Kleenean;
12+
import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
13+
import org.bukkit.block.BlockFace;
14+
import org.bukkit.event.Event;
15+
16+
import javax.annotation.Nullable;
17+
@Name("Is Block Face")
18+
@Description({"This condition checks what face of a block the player has interacted with."})
19+
@Examples({"on interact with custom block: /tif clicked block face is south: /t/tsend \"Why are you doing that?\" "})
20+
@Since("1.4")
21+
public class CondGetBlockFace extends Condition {
22+
23+
static {
24+
Skript.registerCondition(CondGetBlockFace.class, "[clicked] block face is (:down|:north|:south|:east|:west|:up)");
25+
}
26+
27+
private BlockFace face;
28+
29+
@Override
30+
public boolean check(Event e) {
31+
CustomBlockInteractEvent event = (CustomBlockInteractEvent) e;
32+
return event.getBlockFace() == face;
33+
}
34+
35+
@Override
36+
public String toString(@Nullable Event e, boolean debug) {
37+
return "clicked block face is " + face.toString();
38+
}
39+
40+
@Override
41+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
42+
if (parseResult.hasTag("north")) {
43+
face = BlockFace.NORTH;
44+
} else if (parseResult.hasTag("south")) {
45+
face = BlockFace.SOUTH;
46+
} else if (parseResult.hasTag("east")) {
47+
face = BlockFace.EAST;
48+
} else if (parseResult.hasTag("west")) {
49+
face = BlockFace.WEST;
50+
} else if (parseResult.hasTag("up")) {
51+
face = BlockFace.UP;
52+
} else if (parseResult.hasTag("down")) {
53+
face = BlockFace.DOWN;
54+
}
55+
return true;
56+
}
57+
}

src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayBreakEffect.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayBreakSound.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,21 @@ public class EffPlayBreakSound extends Effect {
3333
@Override
3434
protected void execute(Event e) {
3535
String customBlockId = this.customBlockId.getSingle(e);
36-
Player[] players = this.players.getArray(e);
36+
Player[] players = this.players.getAll(e);
3737

3838
if (customBlockId != null) {
3939
CustomBlock customBlock = CustomBlock.getInstance(customBlockId);
4040
if (customBlock != null) {
4141
Block bukkitBlock = customBlock.getBlock();
4242
if (bukkitBlock != null) {
4343
for (Player player : players) {
44-
if (player.getLocation().distance(bukkitBlock.getLocation()) <= 5) { // probably not 5 blocks but whatever
45-
CustomBlock.playBreakSound(bukkitBlock);
44+
CustomBlock.playBreakSound(bukkitBlock);
4645
}
4746
}
4847
}
4948
}
5049
}
51-
}
50+
5251

5352
@Override
5453
public String toString(@Nullable Event e, boolean debug) {

src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffPlayPlaceSound.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,21 @@ public class EffPlayPlaceSound extends Effect {
3535
@Override
3636
protected void execute(Event e) {
3737
String customBlockId = this.customBlockId.getSingle(e);
38-
Player[] players = this.players.getArray(e);
38+
Player[] players = this.players.getAll(e);
3939

4040
if (customBlockId != null) {
4141
CustomBlock customBlock = CustomBlock.getInstance(customBlockId);
4242
if (customBlock != null) {
4343
Block bukkitBlock = customBlock.getBlock();
4444
if (bukkitBlock != null) {
4545
for (Player player : players) {
46-
if (player.getLocation().distance(bukkitBlock.getLocation()) <= 5) {
47-
CustomBlock.playPlaceSound(bukkitBlock);
46+
CustomBlock.playPlaceSound(bukkitBlock);
4847
}
4948
}
5049
}
5150
}
5251
}
53-
}
52+
5453

5554
@Override
5655
public String toString(@Nullable Event e, boolean debug) {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package me.asleepp.SkriptItemsAdder.elements.effects;
2+
3+
import ch.njol.skript.Skript;
4+
import ch.njol.skript.doc.Description;
5+
import ch.njol.skript.doc.Examples;
6+
import ch.njol.skript.doc.Name;
7+
import ch.njol.skript.doc.Since;
8+
import ch.njol.skript.lang.Effect;
9+
import ch.njol.skript.lang.Expression;
10+
import ch.njol.skript.lang.SkriptParser;
11+
import ch.njol.util.Kleenean;
12+
import dev.lone.itemsadder.api.CustomBlock;
13+
import dev.lone.itemsadder.api.CustomFurniture;
14+
import org.bukkit.Location;
15+
import org.bukkit.event.Event;
16+
17+
import javax.annotation.Nullable;
18+
@Name("Remove Custom Furniture")
19+
@Description({"If there is furniture at a location, this effect will remove it."})
20+
@Examples({"remove custom furniture at player's location"})
21+
@Since("1.4")
22+
public class EffRemoveCustomFurniture extends Effect {
23+
24+
static {
25+
Skript.registerEffect(EffRemoveCustomFurniture.class, "(remove|delete) (custom|ia|itemsadder) furniture [%string%] at %locations%");
26+
}
27+
28+
private Expression<String> furnitureId;
29+
private Expression<Location> locations;
30+
31+
@Override
32+
protected void execute(Event e) {
33+
Location[] locs = locations.getAll(e);
34+
String id = furnitureId != null ? furnitureId.getSingle(e) : null;
35+
36+
for (Location loc : locs) {
37+
if (id != null && loc != null) {
38+
CustomFurniture existingFurniture = CustomFurniture.byAlreadySpawned(loc.getBlock());
39+
40+
if (existingFurniture != null) {
41+
existingFurniture.remove(false);
42+
}
43+
}
44+
}
45+
}
46+
47+
@Override
48+
public String toString(@Nullable Event e, boolean debug) {
49+
return "remove custom furniture " + (furnitureId != null ? furnitureId.toString(e, debug) : "") + " at " + locations.toString(e, debug);
50+
}
51+
52+
@SuppressWarnings("unchecked")
53+
@Override
54+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
55+
furnitureId = (Expression<String>) exprs[0];
56+
locations = (Expression<Location>) exprs[1];
57+
return true;
58+
}
59+
}

src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/EffReplaceCustomFurniture.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import javax.annotation.Nullable;
1717

1818
@Name("Replace Custom Furniture")
19-
@Description({"Replace a custom furniture at a location."})
19+
@Description({"If there is furniture at a location, this effect will remove it and place the one you specify."})
2020
@Examples({"replace custom furniture \"comfy_chair\" at player's location"})
2121
@Since("1.4")
2222
public class EffReplaceCustomFurniture extends Effect {

src/main/java/me/asleepp/SkriptItemsAdder/elements/events/EvtCustomBlockBreak.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import ch.njol.skript.lang.SkriptParser;
1111
import ch.njol.skript.registrations.EventValues;
1212
import ch.njol.skript.util.Getter;
13+
import dev.lone.itemsadder.api.CustomBlock;
1314
import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent;
1415
import org.bukkit.block.Block;
1516
import org.bukkit.event.Event;
@@ -26,6 +27,12 @@ public class EvtCustomBlockBreak extends SkriptEvent {
2627

2728
static {
2829
Skript.registerEvent("Custom Block Break", EvtCustomBlockBreak.class, CustomBlockBreakEvent.class, "break of (custom|ia|itemsadder) block [%string%]");
30+
EventValues.registerEventValue(CustomBlockBreakEvent.class, CustomBlock.class, new Getter<CustomBlock, CustomBlockBreakEvent>() {
31+
@Override
32+
public CustomBlock get(CustomBlockBreakEvent event) {
33+
return CustomBlock.byAlreadyPlaced(event.getBlock());
34+
}
35+
}, 0);
2936
}
3037

3138
@SuppressWarnings("unchecked")
@@ -41,19 +48,19 @@ public boolean check(Event event) {
4148
return false;
4249
}
4350

44-
CustomBlockBreakEvent customBlockBreakEvent = (CustomBlockBreakEvent) event;
45-
if (customBlockBreakEvent.isCancelled()) {
51+
CustomBlockBreakEvent customEvent = (CustomBlockBreakEvent) event;
52+
if (customEvent.isCancelled()) {
4653
return false;
4754
}
4855

4956
// check block
5057
if (blockName != null) {
5158
String specifiedBlockName = blockName.getSingle(event);
52-
Block block = customBlockBreakEvent.getBlock();
59+
Block block = customEvent.getBlock();
5360
if (block == null) {
5461
return false;
5562
}
56-
String actualBlockName = customBlockBreakEvent.getNamespacedID();
63+
String actualBlockName = customEvent.getNamespacedID();
5764
if (actualBlockName == null || actualBlockName.isEmpty() || !actualBlockName.equals(specifiedBlockName)) {
5865
return false;
5966
}
@@ -62,6 +69,7 @@ public boolean check(Event event) {
6269
return true;
6370
}
6471

72+
6573
@Override
6674
public String toString(@Nullable Event e, boolean debug) {
6775
return "Custom Block Break event";

0 commit comments

Comments
 (0)