Skip to content

Commit

Permalink
Requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NotSoDelayed committed Dec 2, 2024
1 parent bdb88b4 commit 78a610b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.jetbrains.annotations.Nullable;

@Name("Leash Will Drop")
@Description("Checks whether the leash item will drop during the leash detached in an unleash event.")
@Description("Checks whether the leash item will drop during the leash detaching in an unleash event.")
@Examples({
"on unleash:",
"\tif the leash will drop:",
Expand Down Expand Up @@ -48,14 +48,14 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is

@Override
public boolean check(Event event) {
if (!(event instanceof EntityUnleashEvent))
if (!(event instanceof EntityUnleashEvent unleashEvent))
return false;
return ((EntityUnleashEvent) event).isDropLeash() ^ isNegated();
return unleashEvent.isDropLeash() ^ isNegated();
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "leash will" + (isNegated() ? " not" : "") + " be dropped";
return "the leash will" + (isNegated() ? " not" : "") + " be dropped";
}

}
7 changes: 3 additions & 4 deletions src/main/java/ch/njol/skript/effects/EffDropLeash.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.jetbrains.annotations.Nullable;

@Name("Allow / Prevent Leash Drop")
@Description("Allows or prevents the leash to drop in an unleash event.")
@Description("Allows or prevents the leash from being dropped in an unleash event.")
@Examples({
"on unleash:",
"\tif player is not set:",
Expand All @@ -30,7 +30,6 @@
public class EffDropLeash extends Effect {

static {
if (Skript.methodExists(EntityUnleashEvent.class, "setDropLeash", boolean.class))
Skript.registerEffect(EffDropLeash.class,
"(force|allow) [the] (lead|leash) [item] to drop",
"(block|disallow|prevent) [the] (lead|leash) [item] from dropping"
Expand All @@ -51,9 +50,9 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is

@Override
protected void execute(Event event) {
if (!(event instanceof EntityUnleashEvent))
if (!(event instanceof EntityUnleashEvent unleashEvent))
return;
((EntityUnleashEvent) event).setDropLeash(allowLeashDrop);
unleashEvent.setDropLeash(allowLeashDrop);
}

@Override
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/ch/njol/skript/events/EvtLeash.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class EvtLeash extends SkriptEvent {
"\tbroadcast \"<%event-entity%> I'm free\"",
"",
"on player unleash:",
"\tsend \"<%event-entity%> Thanks for free-ing me!\" to player"
"\tsend \"<%event-entity%> Thanks for freeing me!\" to player"
)
.since("INSERT VERSION");
}
Expand All @@ -56,8 +56,7 @@ public String toString() {

}

@Nullable
private EntityData<?>[] types;
private @Nullable EntityData<?>[] types;
private EventType eventType;

@Override
Expand All @@ -77,23 +76,24 @@ public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResu
public boolean check(Event event) {
Entity leashedEntity;
switch (eventType) {
case LEASH:
if (!(event instanceof PlayerLeashEntityEvent))
case LEASH -> {
if (!(event instanceof PlayerLeashEntityEvent playerLeash))
return false;
leashedEntity = ((PlayerLeashEntityEvent) event).getEntity();
break;
case UNLEASH:
if (!(event instanceof EntityUnleashEvent))
leashedEntity = playerLeash.getEntity();
}
case UNLEASH -> {
if (!(event instanceof EntityUnleashEvent entityUnleash))
return false;
leashedEntity = ((EntityUnleashEvent) event).getEntity();
break;
case UNLEASH_BY_PLAYER:
if (!(event instanceof PlayerUnleashEntityEvent))
leashedEntity = entityUnleash.getEntity();
}
case UNLEASH_BY_PLAYER -> {
if (!(event instanceof PlayerUnleashEntityEvent playerUnleash))
return false;
leashedEntity = ((PlayerUnleashEntityEvent) event).getEntity();
break;
default:
return false;
leashedEntity = playerUnleash.getEntity();
}
default -> {
return false;
}
}
if (types == null)
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ExprUnleashReason() {
}

static {
Skript.registerExpression(ExprUnleashReason.class, EntityUnleashEvent.UnleashReason.class, ExpressionType.SIMPLE, "[the] unleash reason");
Skript.registerExpression(ExprUnleashReason.class, EntityUnleashEvent.UnleashReason.class, ExpressionType.SIMPLE, "[the] unleash[ing] reason");
}

@Override
Expand All @@ -46,9 +46,9 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is

@Override
protected UnleashReason[] get(Event event) {
if (!(event instanceof EntityUnleashEvent))
if (!(event instanceof EntityUnleashEvent unleashEvent))
return new UnleashReason[0];
return CollectionUtils.array(((EntityUnleashEvent) event).getReason());
return new UnleashReason[] {unleashEvent.getReason()};
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lang/default.lang
Original file line number Diff line number Diff line change
Expand Up @@ -2278,7 +2278,7 @@ transform reasons:
# -- Unleash Reasons --
unleash reasons:
distance: distance
holder_gone: holder gone
holder_gone: holder (gone|disappeared)
player_unleash: player unleash, player unleashed, unleashed by player
unknown: unknown

Expand Down

0 comments on commit 78a610b

Please sign in to comment.