Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added ThunderChangesScriptEvent Adds an event that allows a user to detect when thunder changes in a world * Added newline to last end bracket Simple update to adhere better to denizen formatting * firstst attempt at corrections for thunderchangeevent pr Remove `thunder` and `world` fields, replaced the if statements in `getContext` with a switch statement, and added the `in <world>` match that i originally forgot
- Loading branch information
1 parent
a154ae8
commit 74668a4
Showing
2 changed files
with
81 additions
and
0 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
80 changes: 80 additions & 0 deletions
80
plugin/src/main/java/com/denizenscript/denizen/events/world/ThunderChangesScriptEvent.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,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>) | ||
// | ||
// @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); | ||
} | ||
} |