Skip to content

Commit

Permalink
bell ring paper event
Browse files Browse the repository at this point in the history
for #2110
  • Loading branch information
mcmonkey4eva committed Dec 4, 2021
1 parent f2bf73f commit cfcd6c4
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
Expand Up @@ -27,6 +27,7 @@ public static void init() {

// Events
ScriptEvent.registerScriptEvent(new AreaEnterExitScriptEventPaperImpl());
ScriptEvent.registerScriptEvent(new BellRingScriptEvent());
ScriptEvent.registerScriptEvent(new EntityAddToWorldScriptEvent());
ScriptEvent.registerScriptEvent(new EntityKnocksbackEntityScriptEvent());
ScriptEvent.registerScriptEvent(new EntityLoadCrossbowScriptEvent());
Expand Down
@@ -0,0 +1,80 @@
package com.denizenscript.denizen.paper.events;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import io.papermc.paper.event.block.BellRingEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class BellRingScriptEvent extends BukkitScriptEvent implements Listener {

// <--[event]
// @Events
// bell rings
//
// @Location true
//
// @Plugin Paper
//
// @Group Paper
//
// @Cancellable true
//
// @Triggers when a bell block rings.
//
// @Context
// <context.entity> returns the entity that rung the bell, if any.
// <context.location> returns the location of the bell being rung.
//
// @Player when the ringing entity is a player.
//
// -->

public BellRingScriptEvent() {
instance = this;
registerCouldMatcher("bell rings");
}

public static BellRingScriptEvent instance;
public BellRingEvent event;
public LocationTag location;

@Override
public boolean matches(ScriptPath path) {
if (!runInCheck(path, location)) {
return false;
}
return super.matches(path);
}

@Override
public String getName() {
return "BellRing";
}

@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(event.getEntity());
}

@Override
public ObjectTag getContext(String name) {
switch (name) {
case "entity":
return event.getEntity() == null ? null : new EntityTag(event.getEntity());
case "location": return location;
}
return super.getContext(name);
}

@EventHandler
public void bellRingEvent(BellRingEvent event) {
this.event = event;
location = new LocationTag(event.getBlock().getLocation());
fire(event);
}
}

0 comments on commit cfcd6c4

Please sign in to comment.