-
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update healing event and related expressions (#6339)
* Update healing event and related expressions * Update src/main/java/ch/njol/skript/expressions/ExprHealAmount.java Co-authored-by: Ayham Al Ali <[email protected]> * Update src/main/java/ch/njol/skript/events/EvtHealing.java Co-authored-by: Ayham Al Ali <[email protected]> * Apply changes * Sync aliases with master * Add event to setTime * Update src/main/java/ch/njol/skript/events/EvtHealing.java --------- Co-authored-by: Ayham Al Ali <[email protected]> Co-authored-by: Moderocky <[email protected]> Co-authored-by: sovdee <[email protected]>
- Loading branch information
1 parent
69cd4cd
commit dfaacd6
Showing
6 changed files
with
180 additions
and
93 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
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,100 @@ | ||
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ | ||
package ch.njol.skript.events; | ||
|
||
import org.bukkit.entity.Entity; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.entity.EntityRegainHealthEvent; | ||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.entity.EntityData; | ||
import ch.njol.skript.lang.Literal; | ||
import ch.njol.skript.lang.SkriptEvent; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
|
||
public class EvtHealing extends SkriptEvent { | ||
|
||
static { | ||
Skript.registerEvent("Heal", EvtHealing.class, EntityRegainHealthEvent.class, "heal[ing] [of %-entitydatas%] [(from|due to|by) %-healreasons%]", "%entitydatas% heal[ing] [(from|due to|by) %-healreasons%]") | ||
.description("Called when an entity is healed, e.g. by eating (players), being fed (pets), or by the effect of a potion of healing (overworld mobs) or harm (nether mobs).") | ||
.examples( | ||
"on heal:", | ||
"on player healing from a regeneration potion:", | ||
"on healing of a zombie, cow or a wither:", | ||
"\theal reason is healing potion", | ||
"\tcancel event" | ||
) | ||
.since("1.0, INSERT VERSION (by reason)"); | ||
} | ||
|
||
@Nullable | ||
private Literal<EntityData<?>> entityDatas; | ||
|
||
@Nullable | ||
private Literal<RegainReason> healReasons; | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parser) { | ||
entityDatas = (Literal<EntityData<?>>) args[0]; | ||
healReasons = (Literal<RegainReason>) args[1]; | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean check(Event event) { | ||
if (!(event instanceof EntityRegainHealthEvent)) | ||
return false; | ||
EntityRegainHealthEvent healthEvent = (EntityRegainHealthEvent) event; | ||
if (entityDatas != null) { | ||
Entity compare = healthEvent.getEntity(); | ||
boolean result = false; | ||
for (EntityData<?> entityData : entityDatas.getAll()) { | ||
if (entityData.isInstance(compare)) { | ||
result = true; | ||
break; | ||
} | ||
} | ||
if (!result) | ||
return false; | ||
} | ||
if (healReasons != null) { | ||
RegainReason compare = healthEvent.getRegainReason(); | ||
boolean result = false; | ||
for (RegainReason healReason : healReasons.getAll()) { | ||
if (healReason == compare) { | ||
result = true; | ||
break; | ||
} | ||
} | ||
if (!result) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "heal" + (entityDatas != null ? " of " + entityDatas.toString(event, debug) : "") + | ||
(healReasons != null ? " by " + healReasons.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
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