Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thunder changes event #2317

Merged
merged 3 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public static void registerMainEvents() {
ScriptEvent.registerScriptEvent(PotionSplashScriptEvent.class);
ScriptEvent.registerScriptEvent(SpawnChangeScriptEvent.class);
ScriptEvent.registerScriptEvent(StructureGrowsScriptEvent.class);
ScriptEvent.registerScriptEvent(ThunderChangesScriptEvent.class);
ScriptEvent.registerScriptEvent(TimeChangeScriptEvent.class);
ScriptEvent.registerScriptEvent(WeatherChangesScriptEvent.class);
ScriptEvent.registerScriptEvent(WorldInitsScriptEvent.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.denizenscript.denizen.events.world;

import com.denizenscript.denizen.objects.WorldTag;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.weather.ThunderChangeEvent;

public class ThunderChangesScriptEvent extends BukkitScriptEvent implements Listener {

// <--[event]
// @Events
// thunder changes|begins|clears (in <world>)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This says (in <world>) but the matches doesn't appear to implement that

//
// @Group World
//
// @Cancellable true
//
// @Triggers when thunder changes in a world.
//
// @Context
// <context.world> returns the WorldTag the thunder changed in.
// <context.thunder> returns an ElementTag(Boolean) with the new state of thunder.
//
// -->

public ThunderChangesScriptEvent() {
instance = this;
registerCouldMatcher("thunder changes|begins|clears (in <world>)");
}

public static ThunderChangesScriptEvent instance;
public ThunderChangeEvent event;

@Override
public boolean matches(ScriptPath path) {
String changeType = path.eventArgLowerAt(1);
if (changeType.equals("clears")) {
if (event.toThunderState()) {
return false;
}
}
else if (changeType.equals("begins")) {
if (!event.toThunderState()) {
return false;
}
}
else if (!changeType.equals("changes")) {
return false;
}
if (path.eventArgLowerAt(2).equals("in") && !tryWorld(new WorldTag(event.getWorld()), path.eventArgLowerAt(3))) {
return false;
}
return super.matches(path);
}

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

@Override
public ObjectTag getContext(String name) {
switch(name) {
case "world":
return new WorldTag(event.getWorld());
case "thunder":
return new ElementTag(event.toThunderState());
}
return super.getContext(name);
}

@EventHandler
public void onThunderChanges(ThunderChangeEvent event) {
this.event = event;
fire(event);
}
}