Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add map scripts and make maps save to maps.yml
Maps are currently not actually attached to their script
- Loading branch information
Showing
11 changed files
with
700 additions
and
119 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
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
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
84 changes: 84 additions & 0 deletions
84
src/main/java/net/aufdemrand/denizen/scripts/containers/core/MapScriptContainer.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,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); | ||
} | ||
|
||
} |
Oops, something went wrong.