Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrote "on spawn changes" in ScriptEvent format.
- Loading branch information
Showing
3 changed files
with
95 additions
and
27 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
94 changes: 94 additions & 0 deletions
94
src/main/java/net/aufdemrand/denizen/events/world/SpawnChangeScriptEvent.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,94 @@ | ||
package net.aufdemrand.denizen.events.world; | ||
|
||
|
||
import net.aufdemrand.denizen.objects.dLocation; | ||
import net.aufdemrand.denizen.objects.dWorld; | ||
import net.aufdemrand.denizen.utilities.DenizenAPI; | ||
import net.aufdemrand.denizencore.events.ScriptEvent; | ||
import net.aufdemrand.denizencore.objects.dObject; | ||
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer; | ||
import net.aufdemrand.denizencore.utilities.CoreUtilities; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.world.SpawnChangeEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class SpawnChangeScriptEvent extends ScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// spawn changes (in <world>) | ||
// | ||
// @Triggers when the world's spawn point changes. | ||
// | ||
// @Context | ||
// <context.world> returns the dWorld that the spawn point changed in. | ||
// <context.old_location> returns the dLocation of the old spawn point. | ||
// <context.new_location> returns the dLocation of the new spawn point. | ||
// | ||
// --> | ||
|
||
public SpawnChangeScriptEvent() { | ||
instance = this; | ||
} | ||
|
||
public static SpawnChangeScriptEvent instance; | ||
public dWorld world; | ||
public dLocation old_location; | ||
public dLocation new_location; | ||
public SpawnChangeEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
return CoreUtilities.toLowerCase(s).startsWith("spawn changes"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptContainer scriptContainer, String s) { | ||
String wCheck = CoreUtilities.getXthArg(3,CoreUtilities.toLowerCase(s)); | ||
if (wCheck.length() > 0 && !wCheck.equals("world") && !wCheck.equals(CoreUtilities.toLowerCase(world.getName()))) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "SpawnChange"; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
SpawnChangeEvent.getHandlerList().unregister(this); | ||
} | ||
|
||
@Override | ||
public boolean applyDetermination(ScriptContainer container, String determination) { | ||
return super.applyDetermination(container, determination); | ||
} | ||
|
||
@Override | ||
public HashMap<String, dObject> getContext() { | ||
HashMap<String, dObject> context = super.getContext(); | ||
context.put("world", world); | ||
context.put("old_location", old_location); | ||
context.put("new_location", new_location); | ||
return context; | ||
} | ||
|
||
@EventHandler | ||
public void onSpawnChange(SpawnChangeEvent event) { | ||
world = new dWorld(event.getWorld()); | ||
old_location = new dLocation(event.getPreviousLocation()); | ||
new_location = new dLocation(event.getWorld().getSpawnLocation()); | ||
this.event = event; | ||
fire(); | ||
} | ||
} |
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