Skip to content

Commit

Permalink
Rewrote "on spawn changes" in ScriptEvent format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Talamar1 committed Jun 30, 2015
1 parent de0c244 commit ed08ebe
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -656,6 +656,7 @@ public void onEnable() {
ScriptEvent.registerScriptEvent(new ResourcePackStatusScriptEvent());
ScriptEvent.registerScriptEvent(new SheepDyedScriptEvent());
ScriptEvent.registerScriptEvent(new SheepRegrowsScriptEvent());
ScriptEvent.registerScriptEvent(new SpawnChangeScriptEvent());
ScriptEvent.registerScriptEvent(new SlimeSplitsScriptEvent());
ScriptEvent.registerScriptEvent(new VehicleCollidesBlockScriptEvent());
ScriptEvent.registerScriptEvent(new VehicleCollidesEntityScriptEvent());
Expand Down
@@ -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();
}
}
Expand Up @@ -2129,33 +2129,6 @@ public void portalCreate(PortalCreateEvent event) {
event.setCancelled(true);
}

// <--[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.
//
// -->
@EventHandler
public void spawnChange(SpawnChangeEvent event) {

Map<String, dObject> context = new HashMap<String, dObject>();
dWorld world = new dWorld(event.getWorld());

context.put("world", world);
context.put("old_location", new dLocation(event.getPreviousLocation()));
context.put("new_location", new dLocation(world.getWorld().getSpawnLocation()));

doEvents(Arrays.asList
("spawn changes",
"spawn changes in " + world.identifySimple()),
null, null, context, true);
}

// <--[event]
// @Events
// structure grows (naturally/from bonemeal) (in <world>)
Expand Down

0 comments on commit ed08ebe

Please sign in to comment.