Skip to content

Commit

Permalink
Merge pull request #896 from Morphan1/master
Browse files Browse the repository at this point in the history
Pull request for things
  • Loading branch information
mcmonkey4eva committed Dec 12, 2014
2 parents 5c00f42 + 6b9eaec commit 33253eb
Show file tree
Hide file tree
Showing 15 changed files with 800 additions and 130 deletions.
6 changes: 6 additions & 0 deletions src/main/java/net/aufdemrand/denizen/Denizen.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.aufdemrand.denizen.scripts.commands.BukkitCommandRegistry;
import net.aufdemrand.denizen.scripts.queues.ScriptQueue;
import net.aufdemrand.denizen.utilities.*;
import net.aufdemrand.denizen.utilities.maps.DenizenMapManager;
import net.aufdemrand.denizencore.interfaces.dExternal;
import net.aufdemrand.denizen.listeners.ListenerRegistry;
import net.aufdemrand.denizen.npc.dNPCRegistry;
Expand Down Expand Up @@ -468,6 +469,9 @@ public void reloadSaves() {
// Load entities from entities.yml
EntityScriptHelper.reloadEntities();

// Load maps from maps.yml
DenizenMapManager.reloadMaps();

Bukkit.getServer().getPluginManager().callEvent(new SavesReloadEvent());
}

Expand Down Expand Up @@ -572,6 +576,8 @@ public void saveSaves() {
ScoreboardHelper._saveScoreboards();
// Save entities to entities.yml
EntityScriptHelper.saveEntities();
// Save maps to maps.yml
DenizenMapManager.saveMaps();
try {
savesConfig.save(savesConfigFile);
} catch (IOException ex) {
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dEllipsoid.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.aufdemrand.denizen.objects;

import net.aufdemrand.denizen.objects.notable.Notable;
import net.aufdemrand.denizen.objects.notable.NotableManager;
import net.aufdemrand.denizen.objects.notable.Note;
import net.aufdemrand.denizen.objects.properties.Property;
import net.aufdemrand.denizen.objects.properties.PropertyParser;
import net.aufdemrand.denizen.tags.Attribute;
Expand All @@ -9,7 +12,7 @@
import java.util.List;


public class dEllipsoid implements dObject {
public class dEllipsoid implements dObject, Notable {
//////////////////
// OBJECT FETCHER
////////////////
Expand All @@ -23,7 +26,8 @@ public class dEllipsoid implements dObject {
@Fetchable("ellipsoid")
public static dEllipsoid valueOf(String string) {

string = string.substring("ellipsoid@".length());
if (string.startsWith("ellipsoid@"))
string = string.substring(10);

List<String> split = CoreUtilities.Split(string, ',');

Expand Down Expand Up @@ -111,6 +115,22 @@ public boolean isUnique() {
return false;
}

@Override
@Note("Ellipsoids")
public Object getSaveObject() {
return identify().substring(10);
}

@Override
public void makeUnique(String id) {
NotableManager.saveAs(this, id);
}

@Override
public void forget() {
NotableManager.remove(this);
}

@Override
public String getObjectType() {
return "Ellipsoid";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class NotableManager {

public NotableManager() {
registerWithNotableManager(dCuboid.class);
registerWithNotableManager(dEllipsoid.class);
registerWithNotableManager(dInventory.class);
registerWithNotableManager(dItem.class);
registerWithNotableManager(dLocation.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static void _registerCoreTypes() {
_registerType("player listener", PlayerListenerScriptContainer.class);
_registerType("command", CommandScriptContainer.class);
_registerType("yaml data", YamlDataScriptContainer.class);
_registerType("map", MapScriptContainer.class);
}

public static boolean containsScript(String id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package net.aufdemrand.denizen.scripts.commands.item;

import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dWorld;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.DenizenMapRenderer;
import net.aufdemrand.denizen.scripts.containers.core.MapScriptContainer;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.maps.DenizenMapManager;
import net.aufdemrand.denizen.utilities.maps.DenizenMapRenderer;
import net.aufdemrand.denizen.utilities.maps.MapAnimatedImage;
import net.aufdemrand.denizen.utilities.maps.MapImage;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import org.bukkit.Bukkit;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;

import java.io.File;
import java.util.List;

public class MapCommand extends AbstractCommand {

@Override
Expand All @@ -31,10 +28,16 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
scriptEntry.addObject("new", arg.asType(dWorld.class));
}

else if (!scriptEntry.hasObject("reset")
else if (!scriptEntry.hasObject("reset-loc")
&& arg.matchesPrefix("r", "reset")
&& arg.matchesArgumentType(dLocation.class)) {
scriptEntry.addObject("reset", arg.asType(dLocation.class));
scriptEntry.addObject("reset-loc", arg.asType(dLocation.class));
scriptEntry.addObject("reset", Element.TRUE);
}

else if (!scriptEntry.hasObject("reset")
&& arg.matches("reset")) {
scriptEntry.addObject("reset", Element.TRUE);
}

else if (!scriptEntry.hasObject("image")
Expand All @@ -47,9 +50,10 @@ else if (!scriptEntry.hasObject("resize")
scriptEntry.addObject("resize", Element.TRUE);
}

else if (!scriptEntry.hasObject("text")
&& arg.matchesPrefix("t", "text")) {
scriptEntry.addObject("text", arg.asElement());
else if (!scriptEntry.hasObject("script")
&& arg.matchesPrefix("s", "script")
&& arg.matchesArgumentType(dScript.class)) {
scriptEntry.addObject("script", arg.asType(dScript.class));
}

else if (!scriptEntry.hasObject("x-value")
Expand All @@ -75,12 +79,13 @@ else if (!scriptEntry.hasObject("map-id")
throw new InvalidArgumentsException("Must specify a map ID or create a new map!");

if (!scriptEntry.hasObject("reset")
&& !scriptEntry.hasObject("reset-loc")
&& !scriptEntry.hasObject("image")
&& !scriptEntry.hasObject("text"))
throw new InvalidArgumentsException("Must specify value to modify!");
&& !scriptEntry.hasObject("script"))
throw new InvalidArgumentsException("Must specify a valid action to perform!");

scriptEntry.defaultObject("x-value", new Element(0)).defaultObject("y-value", new Element(0))
.defaultObject("resize", Element.FALSE);
scriptEntry.defaultObject("reset", Element.FALSE).defaultObject("resize", Element.FALSE)
.defaultObject("x-value", new Element(0)).defaultObject("y-value", new Element(0));

}

Expand All @@ -89,16 +94,17 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

Element id = scriptEntry.getElement("map-id");
dWorld create = scriptEntry.getdObject("new");
dLocation reset = scriptEntry.getdObject("reset");
Element reset = scriptEntry.getElement("reset");
dLocation resetLoc = scriptEntry.getdObject("reset-loc");
Element image = scriptEntry.getElement("image");
dScript script = scriptEntry.getdObject("script");
Element resize = scriptEntry.getElement("resize");
Element text = scriptEntry.getElement("text");
Element x = scriptEntry.getElement("x-value");
Element y = scriptEntry.getElement("y-value");

dB.report(scriptEntry, getName(), (id != null ? id.debug() : "") + (create != null ? create.debug() : "")
+ (reset != null ? reset.debug() : "") + (image != null ? image.debug() : "") + resize.debug()
+ (text != null ? text.debug() : "") + x.debug() + y.debug());
+ reset.debug() + (resetLoc != null ? resetLoc.debug() : "") + (image != null ? image.debug() : "")
+ (script != null ? script.debug() : "") + resize.debug() + x.debug() + y.debug());

MapView map = null;
if (create != null) {
Expand All @@ -114,36 +120,33 @@ else if (id != null) {
throw new CommandExecutionException("The map command failed somehow! Report this to a developer!");
}

if (reset != null) {
if (reset.asBoolean()) {
for (MapRenderer renderer : map.getRenderers()) {
if (renderer instanceof DenizenMapRenderer) {
map.removeRenderer(renderer);
for (MapRenderer oldRenderer : ((DenizenMapRenderer) renderer).getOldRenderers())
map.addRenderer(oldRenderer);
map.setCenterX(reset.getBlockX());
map.setCenterZ(reset.getBlockZ());
map.setWorld(reset.getWorld());
if (resetLoc != null) {
map.setCenterX(resetLoc.getBlockX());
map.setCenterZ(resetLoc.getBlockZ());
map.setWorld(resetLoc.getWorld());
}
}
}
}
else if (script != null) {
((MapScriptContainer) script.getContainer()).applyTo(map);
}
else {
DenizenMapRenderer dmr = null;
List<MapRenderer> oldRendererList = map.getRenderers();
for (MapRenderer renderer : oldRendererList) {
if (!(renderer instanceof DenizenMapRenderer) || dmr != null)
map.removeRenderer(renderer);
DenizenMapRenderer dmr = DenizenMapManager.getDenizenRenderer(map);
if (image != null) {
if (image.asString().toLowerCase().endsWith(".gif"))
dmr.addObject(new MapAnimatedImage(x.asString(), y.asString(), "true", false, image.asString(),
resize.asBoolean() ? 128 : 0, resize.asBoolean() ? 128 : 0));
else
dmr = (DenizenMapRenderer) renderer;
}
if (dmr == null) {
dmr = new DenizenMapRenderer(oldRendererList);
map.addRenderer(dmr);
dmr.addObject(new MapImage(x.asString(), y.asString(), "true", false, image.asString(),
resize.asBoolean() ? 128 : 0, resize.asBoolean() ? 128 : 0));
}
if (image != null)
dmr.addImage(x.asInt(), y.asInt(), new File(DenizenAPI.getCurrentInstance().getDataFolder(),
image.asString()).getPath(), resize.asBoolean());
else if (text != null)
dmr.addText(x.asInt(), y.asInt(), text.asString());
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package net.aufdemrand.denizen.scripts.containers.core;

import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.utilities.NaturalOrderComparator;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.maps.*;
import net.aufdemrand.denizencore.utilities.YamlConfiguration;
import org.bukkit.map.MapView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MapScriptContainer extends ScriptContainer {

public MapScriptContainer(YamlConfiguration configurationSection, String scriptContainerName) {
super(configurationSection, scriptContainerName);
}

public void applyTo(MapView mapView) {
DenizenMapRenderer renderer = new DenizenMapRenderer(mapView.getRenderers(),
aH.getBooleanFrom(getString("AUTO UPDATE", "true")));
boolean debug = true;
if (contains("DEBUG")) {
debug = aH.getBooleanFrom(getString("DEBUG"));
}
if (contains("OBJECTS")) {
YamlConfiguration objectsSection = getConfigurationSection("OBJECTS");
List<String> objectKeys = new ArrayList<String>(objectsSection.getKeys(false));
Collections.sort(objectKeys, new NaturalOrderComparator());
for (String objectKey : objectKeys) {
YamlConfiguration objectSection = objectsSection.getConfigurationSection(objectKey);
if (!objectSection.contains("TYPE")) {
dB.echoError("Map script '" + getName() + "' has an object without a specified type!");
return;
}
String type = objectSection.getString("TYPE").toUpperCase();
String x = objectSection.getString("X", "0");
String y = objectSection.getString("Y", "0");
String visible = objectSection.getString("VISIBLE", "true");
if (type.equals("IMAGE")) {
if (!objectSection.contains("IMAGE")) {
dB.echoError("Map script '" + getName() + "'s image '" + objectKey
+ "' has no specified image location!");
return;
}
String image = objectSection.getString("IMAGE");
int width = aH.getIntegerFrom(objectSection.getString("WIDTH", "0"));
int height = aH.getIntegerFrom(objectSection.getString("HEIGHT", "0"));
if (image.toLowerCase().endsWith(".gif"))
renderer.addObject(new MapAnimatedImage(x, y, visible, debug, image, width, height));
else
renderer.addObject(new MapImage(x, y, visible, debug, image, width, height));
}
else if (type.equals("TEXT")) {
if (!objectSection.contains("TEXT")) {
dB.echoError("Map script '" + getName() + "'s text object '" + objectKey
+ "' has no specified text!");
return;
}
String text = objectSection.getString("TEXT");
renderer.addObject(new MapText(x, y, visible, debug, text));
}
else if (type.equals("CURSOR")) {
if (!objectSection.contains("CURSOR")) {
dB.echoError("Map script '" + getName() + "'s cursor '" + objectKey
+ "' has no specified cursor type!");
return;
}
String cursor = objectSection.getString("CURSOR");
if (cursor == null) {
dB.echoError("Map script '" + getName() + "'s cursor '" + objectKey
+ "' is missing a cursor type!");
return;
}
renderer.addObject(new MapCursor(x, y, visible, debug, objectSection.getString("DIRECTION", "0"), cursor));
}
}
}
DenizenMapManager.setMap(mapView, renderer);
}

}

0 comments on commit 33253eb

Please sign in to comment.