Skip to content

Commit

Permalink
cleanup and meta (damage block events, entity silent)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 20, 2023
1 parent bcb29f3 commit 5667602
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 32 deletions.
Expand Up @@ -15,14 +15,11 @@ public class PlayerDamagesBlockScriptEvent extends BukkitScriptEvent implements

// <--[event]
// @Events
// player damages block
// player damages <material>
//
// @Regex ^on player damages [^\s]+$
//
// player damages <block>
// @Group Player
//
// @Location true
//
// @Switch with:<item> to only process the event when the player is hitting the block with a specified item.
//
// @Cancellable true
Expand All @@ -41,27 +38,17 @@ public class PlayerDamagesBlockScriptEvent extends BukkitScriptEvent implements
// -->

public PlayerDamagesBlockScriptEvent() {
registerCouldMatcher("player damages <block>");
registerSwitches("with");
}

public LocationTag location;
public MaterialTag material;
public BlockDamageEvent event;

@Override
public boolean couldMatch(ScriptPath path) {
if (!path.eventLower.startsWith("player damages")) {
return false;
}
if (!couldMatchBlock(path.eventArgLowerAt(2))) {
return false;
}
return true;
}

@Override
public boolean matches(ScriptPath path) {
String mat = path.eventArgLowerAt(2);
if (!material.tryAdvancedMatcher(mat)) {
if (!path.tryArgObject(2, material)) {
return false;
}
if (!runInCheck(path, location)) {
Expand Down Expand Up @@ -91,13 +78,11 @@ public ScriptEntryData getScriptEntryData() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return location;
}
else if (name.equals("material")) {
return material;
}
return super.getContext(name);
return switch (name) {
case "location" -> location;
case "material" -> material;
default -> super.getContext(name);
};
}

@EventHandler
Expand Down
Expand Up @@ -16,8 +16,7 @@ public class PlayerStopsDamagingBlockScriptEvent extends BukkitScriptEvent imple

// <--[event]
// @Events
// player stops damaging block
// player stops damaging <material>
// player stops damaging <block>
//
// @Group Player
//
Expand All @@ -43,9 +42,9 @@ public class PlayerStopsDamagingBlockScriptEvent extends BukkitScriptEvent imple
// - spawn silverfish|silverfish|silverfish|silverfish|silverfish <context.location> persistent
// -->

LocationTag location;
MaterialTag material;
BlockDamageAbortEvent event;
public LocationTag location;
public MaterialTag material;
public BlockDamageAbortEvent event;

public PlayerStopsDamagingBlockScriptEvent() {
registerCouldMatcher("player stops damaging <block>");
Expand Down
Expand Up @@ -59,7 +59,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @mechanism EntityTag.silent
// @group attributes
// @description
// Returns whether the entity is silent. (Plays no sounds)
// Returns whether the entity is silent (Plays no sounds).
// -->
if (attribute.startsWith("silent")) {
return new ElementTag(entity.getBukkitEntity().isSilent())
Expand All @@ -77,7 +77,8 @@ public void adjust(Mechanism mechanism) {
// @name silent
// @input ElementTag(Boolean)
// @description
// Sets whether this entity is silent. (Plays no sounds)
// Sets whether this entity is silent (Plays no sounds).
// If you set a player as silent, it may also prevent the player from *hearing* sound.
// @tags
// <EntityTag.silent>
// -->
Expand Down

0 comments on commit 5667602

Please sign in to comment.