use of org.bukkit.map.MapView in project Denizen-For-Bukkit by DenizenScript.
the class MapCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element id = scriptEntry.getElement("map-id");
dWorld create = scriptEntry.getdObject("new");
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 width = scriptEntry.getElement("width");
Element height = scriptEntry.getElement("height");
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.debug() + (resetLoc != null ? resetLoc.debug() : "") + (image != null ? image.debug() : "") + (script != null ? script.debug() : "") + resize.debug() + (width != null ? width.debug() : "") + (height != null ? height.debug() : "") + x.debug() + y.debug());
MapView map = null;
if (create != null) {
map = Bukkit.getServer().createMap(create.getWorld());
scriptEntry.addObject("created_map", new Element(map.getId()));
} else if (id != null) {
map = Bukkit.getServer().getMap((short) id.asInt());
if (map == null) {
throw new CommandExecutionException("No map found for ID '" + id.asInt() + "'!");
}
} else {
throw new CommandExecutionException("The map command failed somehow! Report this to a developer!");
}
if (reset.asBoolean()) {
List<MapRenderer> oldRenderers = DenizenMapManager.removeDenizenRenderers(map);
for (MapRenderer renderer : oldRenderers) {
map.addRenderer(renderer);
}
if (resetLoc != null) {
map.setCenterX(resetLoc.getBlockX());
map.setCenterZ(resetLoc.getBlockZ());
map.setWorld(resetLoc.getWorld());
}
} else if (script != null) {
DenizenMapManager.removeDenizenRenderers(map);
((MapScriptContainer) script.getContainer()).applyTo(map);
} else {
DenizenMapRenderer dmr = DenizenMapManager.getDenizenRenderer(map);
if (image != null) {
int wide = width != null ? width.asInt() : resize.asBoolean() ? 128 : 0;
int high = height != null ? height.asInt() : resize.asBoolean() ? 128 : 0;
if (CoreUtilities.toLowerCase(image.asString()).endsWith(".gif")) {
dmr.addObject(new MapAnimatedImage(x.asString(), y.asString(), "true", false, image.asString(), wide, high));
} else {
dmr.addObject(new MapImage(x.asString(), y.asString(), "true", false, image.asString(), wide, high));
}
}
}
}
use of org.bukkit.map.MapView in project MagicPlugin by elBukkit.
the class MapController method getPlayerPortrait.
/**
* Get an ItemStack that is a headshot of a player's skin.
*/
@Nullable
@Override
public ItemStack getPlayerPortrait(String worldName, String playerName, Integer priority, String photoLabel) {
photoLabel = photoLabel == null ? playerName : photoLabel;
String url = SkinUtils.getOnlineSkinURL(playerName);
if (url != null) {
MapView mapView = getURL(worldName, url, photoLabel, 8, 8, 40, 8, 8, 8, priority, playerName);
return getMapItem(photoLabel, mapView);
}
MapView mapView = getURL(worldName, null, photoLabel, 8, 8, 40, 8, 8, 8, priority, playerName);
return getMapItem(photoLabel, mapView);
}
use of org.bukkit.map.MapView in project MagicPlugin by elBukkit.
the class URLMap method fix.
@SuppressWarnings("deprecation")
@Override
public boolean fix(World world, int maxIds) {
if (enabled)
return true;
MapView mapView = Bukkit.getMap(id);
if (mapView != null) {
enabled = true;
return true;
}
int retry = 0;
boolean matched = false;
while (!matched && retry < maxIds) {
MapView newView = Bukkit.createMap(world);
short newId = newView.getId();
matched = newId == id;
if (newId < 0 || newId > id)
break;
retry++;
}
mapView = getMapView();
if (mapView == null) {
controller.warning("Failed to fix map id " + id + " for key " + getKey());
} else {
enabled = true;
}
return enabled;
}
use of org.bukkit.map.MapView in project MagicPlugin by elBukkit.
the class CycleEntityAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity entity = context.getTargetEntity();
EntityType entityType = entity.getType();
Mage mage = context.getMage();
switch(entityType) {
case PAINTING:
context.registerModified(entity);
Painting painting = (Painting) entity;
Art[] artValues = Art.values();
Art oldArt = painting.getArt();
Art newArt = oldArt;
int ordinal = (oldArt.ordinal() + 1);
for (int i = 0; i < artValues.length; i++) {
newArt = artValues[ordinal++ % artValues.length];
painting.setArt(newArt);
newArt = painting.getArt();
if (oldArt != newArt) {
break;
}
}
if (oldArt == newArt) {
return SpellResult.FAIL;
}
mage.sendDebugMessage("Altering art from " + oldArt + " to " + newArt);
break;
case ITEM_FRAME:
ItemFrame itemFrame = (ItemFrame) entity;
ItemStack frameItem = itemFrame.getItem();
if (frameItem == null || frameItem.getType() != Material.MAP) {
return SpellResult.NO_TARGET;
}
short data = frameItem.getDurability();
data++;
MapView mapView = DeprecatedUtils.getMap(data);
if (mapView == null) {
data = 0;
mapView = DeprecatedUtils.getMap(data);
if (mapView == null) {
return SpellResult.NO_TARGET;
}
}
context.registerModified(entity);
frameItem.setDurability(data);
itemFrame.setItem(frameItem);
break;
case HORSE:
context.registerModified(entity);
Horse horse = (Horse) entity;
Horse.Color color = horse.getColor();
Horse.Color[] colorValues = Horse.Color.values();
color = colorValues[(color.ordinal() + 1) % colorValues.length];
Horse.Style horseStyle = horse.getStyle();
Horse.Style[] styleValues = Horse.Style.values();
horseStyle = styleValues[(horseStyle.ordinal() + 1) % styleValues.length];
horse.setStyle(horseStyle);
horse.setColor(color);
break;
case OCELOT:
context.registerModified(entity);
Ocelot ocelot = (Ocelot) entity;
Ocelot.Type catType = ocelot.getCatType();
Ocelot.Type[] typeValues = Ocelot.Type.values();
catType = typeValues[(catType.ordinal() + 1) % typeValues.length];
ocelot.setCatType(catType);
break;
case VILLAGER:
context.registerModified(entity);
Villager villager = (Villager) entity;
Villager.Profession profession = villager.getProfession();
Villager.Profession[] professionValues = Villager.Profession.values();
int villagerOrdinal = (profession.ordinal() + 1) % professionValues.length;
// Special-cases for zombie-reserved professions
if (villagerOrdinal == 0 || villagerOrdinal == 7) {
villagerOrdinal = 1;
}
profession = professionValues[villagerOrdinal];
villager.setProfession(profession);
break;
case WOLF:
context.registerModified(entity);
Wolf wolf = (Wolf) entity;
DyeColor wolfColor = wolf.getCollarColor();
DyeColor[] wolfColorValues = DyeColor.values();
wolfColor = wolfColorValues[(wolfColor.ordinal() + 1) % wolfColorValues.length];
wolf.setCollarColor(wolfColor);
break;
case SHEEP:
context.registerModified(entity);
Sheep sheep = (Sheep) entity;
DyeColor dyeColor = sheep.getColor();
DyeColor[] dyeColorValues = DyeColor.values();
dyeColor = dyeColorValues[(dyeColor.ordinal() + 1) % dyeColorValues.length];
sheep.setColor(dyeColor);
break;
default:
return SpellResult.NO_TARGET;
}
;
return SpellResult.CAST;
}
use of org.bukkit.map.MapView in project Denizen-For-Bukkit by DenizenScript.
the class MapCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag id = scriptEntry.getElement("map-id");
WorldTag create = scriptEntry.getObjectTag("new");
ElementTag reset = scriptEntry.getElement("reset");
LocationTag resetLoc = scriptEntry.getObjectTag("reset-loc");
ElementTag image = scriptEntry.getElement("image");
ScriptTag script = scriptEntry.getObjectTag("script");
ElementTag resize = scriptEntry.getElement("resize");
ElementTag width = scriptEntry.getElement("width");
ElementTag height = scriptEntry.getElement("height");
ElementTag scale = scriptEntry.getElement("scale");
ElementTag tracking = scriptEntry.getElement("tracking");
ElementTag x = scriptEntry.getElement("x-value");
ElementTag y = scriptEntry.getElement("y-value");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), id, create, reset, resetLoc, image, script, resize, width, height, x, y);
}
MapView map;
if (create != null) {
map = Bukkit.getServer().createMap(create.getWorld());
scriptEntry.addObject("created_map", new ElementTag(map.getId()));
Debug.echoDebug(scriptEntry, "Created map with id " + map.getId() + ".");
} else if (id != null) {
map = Bukkit.getServer().getMap((short) id.asInt());
if (map == null) {
Debug.echoError("No map found for ID '" + id.asInt() + "'!");
return;
}
} else {
// not possible
return;
}
if (reset.asBoolean()) {
if (tracking != null) {
map.setTrackingPosition(true);
}
if (scale != null) {
map.setScale(MapView.Scale.valueOf(scale.asString().toUpperCase()));
}
List<MapRenderer> oldRenderers = DenizenMapManager.removeDenizenRenderers(map);
for (MapRenderer renderer : oldRenderers) {
map.addRenderer(renderer);
}
if (resetLoc != null) {
map.setCenterX(resetLoc.getBlockX());
map.setCenterZ(resetLoc.getBlockZ());
map.setWorld(resetLoc.getWorld());
}
}
if (script != null) {
DenizenMapManager.removeDenizenRenderers(map);
((MapScriptContainer) script.getContainer()).applyTo(map);
}
if (image != null) {
DenizenMapRenderer dmr = DenizenMapManager.getDenizenRenderer(map);
int wide = width != null ? width.asInt() : resize.asBoolean() ? 128 : 0;
int high = height != null ? height.asInt() : resize.asBoolean() ? 128 : 0;
if (CoreUtilities.toLowerCase(image.asString()).endsWith(".gif")) {
dmr.autoUpdate = true;
}
dmr.addObject(new MapImage(dmr, x.asString(), y.asString(), "true", false, image.asString(), wide, high));
dmr.hasChanged = true;
}
}
Aggregations