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

Commit 859dc77

Browse files
committed
Touch-ups
1 parent 61b78b7 commit 859dc77

22 files changed

+181
-165
lines changed

src/main/java/me/asleepp/SkriptItemsAdder/elements/conditions/CondIsCustomEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
@Description({"Checks if the entity is an ItemsAdder entity."})
2020
@Examples({
2121
"on damage:",
22-
"\tif event-entity is a custom entity:",
22+
"\tif event-entity is an itemsadder entity:",
2323
"\t\tsend \"how could you?\" to player",
24-
"\tif event-entity is not a custom entity:",
24+
"\telse if event-entity is not an itemsadder entity:",
2525
"\t\t send \"Incredible!\" to player "})
2626
@Since("1.0, 1.5 (Negative Comparison)")
2727
@RequiredPlugins("ItemsAdder")

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
package me.asleepp.SkriptItemsAdder.elements.effects;
22

33
import ch.njol.skript.Skript;
4+
import ch.njol.skript.doc.Examples;
5+
import ch.njol.skript.doc.RequiredPlugins;
6+
import ch.njol.skript.doc.Since;
47
import ch.njol.skript.lang.Effect;
58
import ch.njol.skript.lang.Expression;
69
import ch.njol.skript.lang.SkriptParser;
710
import ch.njol.util.Kleenean;
811
import dev.lone.itemsadder.api.CustomEntity;
12+
import jdk.jfr.Description;
13+
import jdk.jfr.Name;
914
import org.bukkit.entity.Entity;
1015
import org.bukkit.event.Event;
1116

1217
import javax.annotation.Nullable;
1318

19+
@Name("Damage Effect")
20+
@Description("Play the red damage effect on an ItemsAdder entity.")
21+
@Examples("play damage effect on custom itemsadder entity {_iaentity}")
22+
@Since("1.6")
23+
@RequiredPlugins("ItemsAdder")
1424
public class EffDamageEffect extends Effect {
1525

1626
private Expression<Entity> entitiesExpr;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
@Description({"Makes an ItemsAdder entity play an animation."})
2020
@Examples({
2121
"on right click:",
22-
"\tif clicked entity is a custom entity",
22+
"\tif clicked entity is an itemsadder entity",
2323
"\t\tmake clicked entity play itemsadder animation \"fortnite:default_dance\""})
2424
@Since("1.0")
2525
@RequiredPlugins("ItemsAdder")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import javax.annotation.Nullable;
1818
@Name("Open ItemsAdder Inventory")
1919
@Description("Opens an ItemsAdder inventory to a player(s), made using the ItemsAdder inventory section.")
20-
@Examples("open custom inventory {votegui} to all players")
20+
@Examples("open custom itemsadder inventory {votegui} to all players")
2121
@Since("1.5")
2222
@RequiredPlugins("ItemsAdder")
2323
public class EffOpenCustomInventory extends Effect {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import javax.annotation.Nullable;
1818
@Name("Spawn ItemsAdder Entity")
1919
@Description({"Spawns an ItemsAdder entity."})
20-
@Examples({"spawn custom entity \"bosses:john_wick\" at player's location"})
20+
@Examples({"spawn itemsadder entity \"bosses:john_wick\" at player's location"})
2121
@Since("1.0")
2222
@RequiredPlugins("ItemsAdder")
2323
public class EffSpawnCustomEntity extends Effect {

src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffPlaceBlockOrCrop.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
@Description({"Places a custom block or crop at a location."})
2727
@Examples({
2828
"set block at player's location to itemsadder block \"iasurvival:ruby_block\"",
29-
"set block at player's location to custom crop \"bestcrops:best_seed\""})
29+
"set block at player's location to custom itemsadder crop best seed"})
3030
@Since("1.0, 1.5 (Placing Crops & Syntax rework)")
3131
@RequiredPlugins("ItemsAdder")
3232
public class EffPlaceBlockOrCrop extends Effect {

src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/blocks/EffSetBlocksBetween.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import dev.lone.itemsadder.api.CustomBlock;
1414
import me.asleepp.SkriptItemsAdder.SkriptItemsAdder;
1515
import me.asleepp.SkriptItemsAdder.other.aliases.AliasesGenerator;
16-
import me.asleepp.SkriptItemsAdder.other.aliases.CustomItemType;
16+
import me.asleepp.SkriptItemsAdder.other.util.Util;
1717
import org.bukkit.Location;
1818
import org.bukkit.event.Event;
1919

@@ -24,7 +24,7 @@
2424

2525
@Name("Set Custom Blocks Within")
2626
@Description({"Sets the blocks within 2 locations to ItemsAdder custom blocks."})
27-
@Examples({"set all blocks within location(0, 100, 0) and player's location to custom block \"iasurvival:ruby_block\""})
27+
@Examples({"set all blocks within location(0, 100, 0) and player's location to itemsadder block \"iasurvival:ruby_block\""})
2828
@Since("1.0")
2929
@RequiredPlugins("ItemsAdder")
3030
public class EffSetBlocksBetween extends Effect {
@@ -47,12 +47,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
4747
.filter(expr -> expr instanceof Expression)
4848
.map(expr -> {
4949
Object value = ((Expression<?>) expr).getSingle(null);
50-
if (value instanceof CustomItemType) {
51-
return ((CustomItemType) value).getNamespacedID();
52-
} else if (value instanceof String) {
53-
return (String) value;
54-
}
55-
return null;
50+
return Util.getCustomBlockId(value);
5651
})
5752
.filter(name -> name != null)
5853
.collect(Collectors.toList());
@@ -64,13 +59,7 @@ protected void execute(Event e) {
6459
Location location1 = location1Expr.getSingle(e);
6560
Location location2 = location2Expr.getSingle(e);
6661
Object customBlockIdObj = customBlockIdExpr.getSingle(e);
67-
String customBlockId = null;
68-
69-
if (customBlockIdObj instanceof CustomItemType) {
70-
customBlockId = ((CustomItemType) customBlockIdObj).getNamespacedID();
71-
} else if (customBlockIdObj instanceof String) {
72-
customBlockId = (String) customBlockIdObj;
73-
}
62+
String customBlockId = Util.getCustomBlockId(customBlockIdObj);
7463

7564
if (location1 == null || location2 == null || customBlockId == null) {
7665
return;

src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffPlaceCustomFurniture.java

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,73 @@
1010
import ch.njol.skript.lang.Expression;
1111
import ch.njol.skript.lang.SkriptParser;
1212
import ch.njol.util.Kleenean;
13-
import org.bukkit.entity.Entity;
14-
import org.bukkit.event.Event;
1513
import dev.lone.itemsadder.api.CustomFurniture;
14+
import me.asleepp.SkriptItemsAdder.other.util.Util;
1615
import org.bukkit.Location;
16+
import org.bukkit.entity.Entity;
17+
import org.bukkit.event.Event;
1718
import org.bukkit.plugin.java.JavaPlugin;
1819
import org.bukkit.scheduler.BukkitRunnable;
1920

2021
import javax.annotation.Nullable;
22+
import java.util.ArrayList;
23+
import java.util.List;
2124

2225
@Name("Place Custom Furniture")
23-
@Description({"Place a custom furniture at a location."})
24-
@Examples({"place custom furniture \"coolfurniture:comfy_chair\" at player's location"})
25-
@Since("1.3")
26+
@Description({
27+
"Place a custom furniture at a location.",
28+
"If there is a furniture at the same location, this effect will replace it."
29+
})
30+
@Examples({"place itemsadder furniture \"coolfurniture:comfy_chair\" at player's location"})
31+
@Since("1.3, 1.6 (Replacing)")
2632
@RequiredPlugins("ItemsAdder")
2733
public class EffPlaceCustomFurniture extends Effect {
2834

29-
private Expression<String> furnitureId;
30-
private Expression<Location> location;
35+
private Expression<?> furnitureIdExpr;
36+
private Expression<Location> locationExpr;
3137
private JavaPlugin plugin;
3238

3339
static {
34-
Skript.registerEffect(EffPlaceCustomFurniture.class, "(set|place) [custom] (ia|itemsadder) furniture %string% at %location%");
40+
Skript.registerEffect(EffPlaceCustomFurniture.class, "(set|place) [custom] (ia|itemsadder) furniture %customitemtypes/strings% at %location%");
3541
}
3642

3743
@Override
3844
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
39-
furnitureId = (Expression<String>) exprs[0];
40-
location = (Expression<Location>) exprs[1];
45+
furnitureIdExpr = exprs[0];
46+
locationExpr = (Expression<Location>) exprs[1];
4147
return true;
4248
}
4349

4450
@Override
4551
protected void execute(Event e) {
46-
String id = furnitureId.getSingle(e);
47-
Location loc = location.getSingle(e);
52+
if (furnitureIdExpr == null || locationExpr == null) {
53+
return;
54+
}
55+
56+
List<String> furnitureIds = new ArrayList<>();
57+
if (furnitureIdExpr.isSingle()) {
58+
Object itemType = furnitureIdExpr.getSingle(e);
59+
furnitureIds.add(Util.getCustomBlockId(itemType));
60+
} else {
61+
for (Object itemType : furnitureIdExpr.getArray(e)) {
62+
furnitureIds.add(Util.getCustomBlockId(itemType));
63+
}
64+
}
65+
66+
Location location = locationExpr.getSingle(e);
67+
if (location == null) {
68+
return;
69+
}
70+
71+
for (String furnitureId : furnitureIds) {
72+
if (furnitureId == null) {
73+
Skript.error("Invalid custom furniture ID.");
74+
continue;
75+
}
4876

49-
CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(loc.getBlock());
50-
if (id != null && loc != null) {
77+
CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(location.getBlock());
5178
if (customFurniture == null) {
52-
CustomFurniture.spawn(id, loc.getBlock());
79+
CustomFurniture.spawn(furnitureId, location.getBlock());
5380
} else {
5481
Entity armorStand = customFurniture.getArmorstand();
5582
if (armorStand != null) {
@@ -58,7 +85,7 @@ protected void execute(Event e) {
5885
new BukkitRunnable() {
5986
@Override
6087
public void run() {
61-
customFurniture.teleport(originalLocation);
88+
CustomFurniture.spawn(furnitureId, originalLocation.getBlock());
6289
}
6390
}.runTaskLater(plugin, 3);
6491
}
@@ -68,7 +95,7 @@ public void run() {
6895

6996
@Override
7097
public String toString(@Nullable Event e, boolean debug) {
71-
return "(set|place) [custom] (ia|itemsadder) furniture " + furnitureId.toString(e, debug) + " at " + location.toString(e, debug);
98+
return "(set|place) [custom] (ia|itemsadder) furniture " + furnitureIdExpr.toString(e, debug) + " at " + locationExpr.toString(e, debug);
7299
}
73100

74101
}

src/main/java/me/asleepp/SkriptItemsAdder/elements/effects/furniture/EffRemoveCustomFurniture.java

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,60 @@
1111
import ch.njol.skript.lang.SkriptParser;
1212
import ch.njol.util.Kleenean;
1313
import dev.lone.itemsadder.api.CustomFurniture;
14+
import me.asleepp.SkriptItemsAdder.other.util.Util;
1415
import org.bukkit.Location;
1516
import org.bukkit.event.Event;
1617

1718
import javax.annotation.Nullable;
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
1822
@Name("Remove Custom Furniture")
1923
@Description({"If there is furniture at a location, this effect will remove it."})
20-
@Examples({"remove custom furniture at player's location"})
24+
@Examples({"remove itemsadder furniture at player's location"})
2125
@Since("1.4")
2226
@RequiredPlugins("ItemsAdder")
2327
public class EffRemoveCustomFurniture extends Effect {
2428

2529
static {
26-
Skript.registerEffect(EffRemoveCustomFurniture.class, "(remove|delete) [custom] (ia|itemsadder) furniture [%string%] at %locations%");
30+
Skript.registerEffect(EffRemoveCustomFurniture.class, "(remove|delete) [custom] (ia|itemsadder) furniture [%customitemtypes/strings%] at %locations%");
2731
}
2832

2933
private Expression<String> furnitureId;
3034
private Expression<Location> locations;
3135

36+
@SuppressWarnings("unchecked")
37+
@Override
38+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
39+
furnitureId = (Expression<String>) exprs[0];
40+
locations = (Expression<Location>) exprs[1];
41+
return true;
42+
}
43+
3244
@Override
3345
protected void execute(Event e) {
3446
Location[] locs = locations.getAll(e);
35-
String id = furnitureId != null ? furnitureId.getSingle(e) : null;
47+
List<String> customFurnitureIds = new ArrayList<>();
48+
49+
if (furnitureId != null) {
50+
if (furnitureId.isSingle()) {
51+
Object itemType = furnitureId.getSingle(e);
52+
customFurnitureIds.add(Util.getCustomBlockId(itemType));
53+
} else {
54+
for (Object itemType : furnitureId.getArray(e)) {
55+
customFurnitureIds.add(Util.getCustomBlockId(itemType));
56+
}
57+
}
58+
}
3659

3760
for (Location loc : locs) {
38-
if (id != null && loc != null) {
39-
CustomFurniture existingFurniture = CustomFurniture.byAlreadySpawned(loc.getBlock());
61+
for (String id : customFurnitureIds) {
62+
if (id != null && loc != null) {
63+
CustomFurniture existingFurniture = CustomFurniture.byAlreadySpawned(loc.getBlock());
4064

41-
if (existingFurniture != null) {
42-
existingFurniture.remove(false);
65+
if (existingFurniture != null) {
66+
existingFurniture.remove(false);
67+
}
4368
}
4469
}
4570
}
@@ -49,12 +74,4 @@ protected void execute(Event e) {
4974
public String toString(@Nullable Event e, boolean debug) {
5075
return "remove custom furniture " + (furnitureId != null ? furnitureId.toString(e, debug) : "") + " at " + locations.toString(e, debug);
5176
}
52-
53-
@SuppressWarnings("unchecked")
54-
@Override
55-
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
56-
furnitureId = (Expression<String>) exprs[0];
57-
locations = (Expression<Location>) exprs[1];
58-
return true;
59-
}
6077
}

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

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

0 commit comments

Comments
 (0)