Skip to content

Commit

Permalink
Document map scripts, add 'original' option
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 22, 2017
1 parent 26eb9d9 commit 0b06dbc
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 10 deletions.
Expand Up @@ -20,10 +20,63 @@ public MapScriptContainer(YamlConfiguration configurationSection, String scriptC
super(configurationSection, scriptContainerName);
}

// <--[language]
// @name Map Script Containers
// @group Script Container System
// @description
// Map scripts allow you define custom in-game map items, for usage with the map command.
//
// The following is the format for the container.
//
// <code>
// # The name of the map script is used by the map command.
// Item Script Name:
//
// type: map
//
// # Whether to display the original map below the custom values.
// original: true/false
//
// # The 'custom name' can be anything you wish. Use color tags to make colored custom names.
// display name: custom name
//
// # Lists all contained objects.
// objects:
//
// # The first object...
// 1:
// # Specify the object type
// type: image
// # Specify an HTTP url or file path within Denizen/images/ for the image. Supports animated .gif!
// image: my_image.png
// # Optionally add width/height numbers.
//
// 2:
// type: text
// # Specify any text, with tags.
// text: Hello <player.name>
// # Specify a tag to show or hide custom content! Valid for all objects.
// visible: <player.name.contains[bob].not>
//
// 3:
// type: cursor
// # Specify a cursor - {RED|GREEN|WHITE|BLUE)_POINTER, WHITE_CROSS, WHITE_CIRCLE, RED_MARKER, SMALL_WHITE_CIRCLE,
// # MANSION, TEMPLE
// cursor: red_marker
// # Supported on all objects: x/y positions.
// x: 5
// y: 5
// </code>
//
// -->

public void applyTo(MapView mapView) {
DenizenMapRenderer renderer = new DenizenMapRenderer(mapView.getRenderers(),
aH.getBooleanFrom(getString("AUTO UPDATE", "true")));
boolean debug = true;
if (contains("ORIGINAL")) {
renderer.displayOriginal = aH.getBooleanFrom(getString("ORIGINAL"));
}
if (contains("DEBUG")) {
debug = aH.getBooleanFrom(getString("DEBUG"));
}
Expand Down
Expand Up @@ -66,6 +66,7 @@ public static void reloadMaps() {
}
DenizenMapRenderer renderer = new DenizenMapRenderer(oldRenderers,
mapsSection.getBoolean(key + ".auto update", false));
renderer.displayOriginal = mapsSection.getBoolean(key + ".original", true);
List<String> objects = new ArrayList<String>(objectsData.getKeys(false));
Collections.sort(objects, new NaturalOrderComparator());
for (String objectKey : objects) {
Expand Down
Expand Up @@ -12,15 +12,20 @@

public class DenizenMapRenderer extends MapRenderer {

private final List<MapObject> mapObjects = new ArrayList<MapObject>();
private final List<MapRenderer> oldMapRenderers;
private final boolean autoUpdate;
private List<MapObject> mapObjects = new ArrayList<MapObject>();
private List<MapRenderer> oldMapRenderers;
private boolean autoUpdate;

public boolean displayOriginal = true;

private boolean active;

public DenizenMapRenderer(List<MapRenderer> oldMapRenderers, boolean autoUpdate) {
super(true);
this.oldMapRenderers = oldMapRenderers;
if (oldMapRenderers.size() == 1 && oldMapRenderers.get(0) instanceof DenizenMapRenderer) {
this.oldMapRenderers = ((DenizenMapRenderer) oldMapRenderers.get(0)).oldMapRenderers;
}
this.autoUpdate = autoUpdate;
this.active = true;
}
Expand Down Expand Up @@ -61,6 +66,7 @@ public Map<String, Object> getSaveData() {
}
data.put("objects", objects);
data.put("auto update", autoUpdate);
data.put("original", displayOriginal);
return data;
}
throw new IllegalStateException("DenizenMapRenderer is not active");
Expand All @@ -74,6 +80,14 @@ public void render(MapView mapView, MapCanvas mapCanvas, Player player) {
}
if (active) {
try {
while (mapCanvas.getCursors().size() > 0) {
mapCanvas.getCursors().removeCursor(mapCanvas.getCursors().getCursor(0));
}
if (displayOriginal) {
for (MapRenderer oldR : oldMapRenderers) {
oldR.render(mapView, mapCanvas, player);
}
}
UUID uuid = player.getUniqueId();
dPlayer p = dPlayer.mirrorBukkitPlayer(player);
for (MapObject object : mapObjects) {
Expand Down
Expand Up @@ -57,13 +57,11 @@ public Map<String, Object> getSaveData() {

@Override
public void render(MapView mapView, MapCanvas mapCanvas, dPlayer player, UUID uuid) {
if (!cursors.containsKey(uuid)) {
org.bukkit.map.MapCursor cursor = new org.bukkit.map.MapCursor((byte) getX(player, uuid),
(byte) getY(player, uuid), getDirection(player), getType(player).getValue(),
isVisibleTo(player, uuid));
mapCanvas.getCursors().addCursor(cursor);
cursors.put(uuid, cursor);
}
org.bukkit.map.MapCursor cursor = new org.bukkit.map.MapCursor((byte) getX(player, uuid),
(byte) getY(player, uuid), getDirection(player), getType(player).getValue(),
isVisibleTo(player, uuid));
mapCanvas.getCursors().addCursor(cursor);
cursors.put(uuid, cursor);
}

}

0 comments on commit 0b06dbc

Please sign in to comment.