-
-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Starter Commit * Requested Changes * Doc Fix * cleanup * Remove Beacon Values * Changes * Requested Changes * Revert Test * Fix JUnit * Requested Changes * Requested Changes * :) * Requested Changes * More Changes * Requested Changes * Change * Requested Changes * Miniscule Changes --------- Co-authored-by: Moderocky <admin@moderocky.com>
- Loading branch information
1 parent
2b12125
commit e301294
Showing
9 changed files
with
652 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package ch.njol.skript.events; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.*; | ||
import ch.njol.skript.lang.Literal; | ||
import ch.njol.skript.lang.SkriptEvent; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import com.destroystokyo.paper.event.block.BeaconEffectEvent; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.potion.PotionEffectType; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Beacon Effect") | ||
@Description("Called when a player gets an effect from a beacon.") | ||
@Examples({ | ||
"on beacon effect:", | ||
"\tbroadcast applied effect", | ||
"\tbroadcast event-player", | ||
"\tbroadcast event-block", | ||
"on primary beacon effect apply of haste:", | ||
"on application of secondary beacon effect:", | ||
"on beacon effect of speed:" | ||
}) | ||
@RequiredPlugins("Paper") | ||
@Since("INSERT VERSION") | ||
public class EvtBeaconEffect extends SkriptEvent { | ||
|
||
static { | ||
if (Skript.classExists("com.destroystokyo.paper.event.block.BeaconEffectEvent")) | ||
Skript.registerEvent("Beacon Effect", EvtBeaconEffect.class, BeaconEffectEvent.class, | ||
"[:primary|:secondary] beacon effect [of %-potioneffecttypes%]", | ||
"application of [:primary|:secondary] beacon effect [of %-potioneffecttypes%]", | ||
"[:primary|:secondary] beacon effect apply [of %-potioneffecttypes%]"); | ||
|
||
} | ||
|
||
private @Nullable Literal<PotionEffectType> potionTypes; | ||
private @Nullable Boolean primaryCheck; | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) { | ||
potionTypes = (Literal<PotionEffectType>) exprs[0]; | ||
if (parseResult.hasTag("primary")) { | ||
primaryCheck = true; | ||
} else if (parseResult.hasTag("secondary")) { | ||
primaryCheck = false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean check(Event event) { | ||
if (!(event instanceof BeaconEffectEvent effectEvent)) | ||
return false; | ||
if (primaryCheck != null && effectEvent.isPrimary() != primaryCheck) | ||
return false; | ||
if (potionTypes != null) | ||
return potionTypes.check(event, type -> effectEvent.getEffect().getType() == type); | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return (primaryCheck == null ? "" : primaryCheck ? "primary " : "secondary ") + | ||
"beacon effect" + (potionTypes == null ? "" : " of " + potionTypes.toString(event, debug)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ch.njol.skript.events; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.*; | ||
import ch.njol.skript.lang.Literal; | ||
import ch.njol.skript.lang.SkriptEvent; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import io.papermc.paper.event.block.BeaconActivatedEvent; | ||
import io.papermc.paper.event.block.BeaconDeactivatedEvent; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Beacon Toggle") | ||
@Description("Called when a beacon is activated or deactivated.") | ||
@Examples({ | ||
"on beacon toggle:", | ||
"on beacon activate:", | ||
"on beacon deactivate:" | ||
}) | ||
@RequiredPlugins("Paper") | ||
@Since("INSERT VERSION") | ||
public class EvtBeaconToggle extends SkriptEvent { | ||
|
||
static { | ||
if (Skript.classExists("io.papermc.paper.event.block.BeaconActivatedEvent")) | ||
Skript.registerEvent("Beacon Toggle", EvtBeaconToggle.class, new Class[] {BeaconActivatedEvent.class, BeaconDeactivatedEvent.class}, | ||
"beacon toggle", | ||
"beacon activat(e|ion)", | ||
"beacon deactivat(e|ion)"); | ||
} | ||
|
||
private boolean isActivate, isToggle; | ||
|
||
@Override | ||
public boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) { | ||
isToggle = matchedPattern == 0; | ||
isActivate = matchedPattern == 1; | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean check(Event event) { | ||
if (!isToggle) { | ||
if (event instanceof BeaconActivatedEvent) { | ||
return isActivate; | ||
} else if (event instanceof BeaconDeactivatedEvent) { | ||
return !isActivate; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "beacon " + (isToggle ? "toggle" : isActivate ? "activate" : "deactivate"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/ch/njol/skript/expressions/ExprAppliedEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package ch.njol.skript.expressions; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.*; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import com.destroystokyo.paper.event.block.BeaconEffectEvent; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.potion.PotionEffectType; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Applied Beacon Effect") | ||
@Description("The type of effect applied by a beacon.") | ||
@Examples({ | ||
"on beacon effect:", | ||
"\tif the applied effect is primary beacon effect:", | ||
"\t\tbroadcast \"Is Primary\"", | ||
"\telse if applied effect = secondary effect:", | ||
"\t\tbroadcast \"Is Secondary\"" | ||
}) | ||
@Events("Beacon Effect") | ||
@RequiredPlugins("Paper") | ||
@Since("INSERT VERSION") | ||
public class ExprAppliedEffect extends SimpleExpression<PotionEffectType> { | ||
|
||
static { | ||
if (Skript.classExists("com.destroystokyo.paper.event.block.BeaconEffectEvent")) { | ||
Skript.registerExpression(ExprAppliedEffect.class, PotionEffectType.class, ExpressionType.SIMPLE, "[the] applied [beacon] effect"); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
if (!getParser().isCurrentEvent(BeaconEffectEvent.class)) { | ||
Skript.error("You can only use 'applied effect' in a beacon effect event."); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
protected PotionEffectType @Nullable [] get(Event event) { | ||
if (!(event instanceof BeaconEffectEvent effectEvent)) | ||
return null; | ||
return new PotionEffectType[]{effectEvent.getEffect().getType()}; | ||
} | ||
|
||
@Override | ||
public Class<PotionEffectType> getReturnType() { | ||
return PotionEffectType.class; | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "applied effect"; | ||
} | ||
|
||
} |
Oops, something went wrong.