Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand entity shoots bow event for paper and fix arrow color property
- Loading branch information
Showing
5 changed files
with
78 additions
and
3 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
48 changes: 48 additions & 0 deletions
48
...main/java/com/denizenscript/denizen/paper/events/EntityShootsBowPaperScriptEventImpl.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,48 @@ | ||
package com.denizenscript.denizen.paper.events; | ||
|
||
import com.denizenscript.denizen.events.entity.EntityShootsBowEvent; | ||
import com.denizenscript.denizen.objects.ItemTag; | ||
import com.denizenscript.denizen.utilities.DenizenAPI; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.utilities.CoreUtilities; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
|
||
public class EntityShootsBowPaperScriptEventImpl extends EntityShootsBowEvent { | ||
|
||
@Override | ||
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) { | ||
if (determinationObj instanceof ElementTag && !isDefaultDetermination(determinationObj)) { | ||
String determination = determinationObj.toString(); | ||
String lower = CoreUtilities.toLowerCase(determination); | ||
if (lower.equals("keep_item")) { | ||
event.setConsumeArrow(false); | ||
return true; | ||
} | ||
} | ||
return super.applyDetermination(path, determinationObj); | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
if (name.equals("item")) { | ||
return new ItemTag(event.getArrowItem()); | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
@Override | ||
public void fire() { | ||
super.fire(); | ||
if (!event.getConsumeArrow() && entity.isPlayer()) { | ||
final Player p = entity.getPlayer(); | ||
Bukkit.getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(), new Runnable() { | ||
@Override | ||
public void run() { | ||
p.updateInventory(); | ||
} | ||
}, 1); | ||
} | ||
} | ||
} |
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