Search in sources :

Example 1 with MapView

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));
            }
        }
    }
}
Also used : MapImage(net.aufdemrand.denizen.utilities.maps.MapImage) MapAnimatedImage(net.aufdemrand.denizen.utilities.maps.MapAnimatedImage) net.aufdemrand.denizencore.objects.dScript(net.aufdemrand.denizencore.objects.dScript) DenizenMapRenderer(net.aufdemrand.denizen.utilities.maps.DenizenMapRenderer) MapRenderer(org.bukkit.map.MapRenderer) Element(net.aufdemrand.denizencore.objects.Element) MapView(org.bukkit.map.MapView) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException) DenizenMapRenderer(net.aufdemrand.denizen.utilities.maps.DenizenMapRenderer) net.aufdemrand.denizen.objects.dWorld(net.aufdemrand.denizen.objects.dWorld) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 2 with MapView

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);
}
Also used : MapView(org.bukkit.map.MapView) Nullable(javax.annotation.Nullable)

Example 3 with 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;
}
Also used : MapView(org.bukkit.map.MapView)

Example 4 with MapView

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;
}
Also used : Entity(org.bukkit.entity.Entity) Art(org.bukkit.Art) ItemFrame(org.bukkit.entity.ItemFrame) Horse(org.bukkit.entity.Horse) Villager(org.bukkit.entity.Villager) MapView(org.bukkit.map.MapView) Wolf(org.bukkit.entity.Wolf) DyeColor(org.bukkit.DyeColor) DyeColor(org.bukkit.DyeColor) Painting(org.bukkit.entity.Painting) EntityType(org.bukkit.entity.EntityType) Ocelot(org.bukkit.entity.Ocelot) EntityType(org.bukkit.entity.EntityType) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Sheep(org.bukkit.entity.Sheep) ItemStack(org.bukkit.inventory.ItemStack)

Example 5 with MapView

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;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MapImage(com.denizenscript.denizen.utilities.maps.MapImage) DenizenMapRenderer(com.denizenscript.denizen.utilities.maps.DenizenMapRenderer) MapRenderer(org.bukkit.map.MapRenderer) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) MapView(org.bukkit.map.MapView) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) WorldTag(com.denizenscript.denizen.objects.WorldTag) DenizenMapRenderer(com.denizenscript.denizen.utilities.maps.DenizenMapRenderer) MapScriptContainer(com.denizenscript.denizen.scripts.containers.core.MapScriptContainer)

Aggregations

MapView (org.bukkit.map.MapView)14 MapRenderer (org.bukkit.map.MapRenderer)6 Nullable (javax.annotation.Nullable)3 DyeColor (org.bukkit.DyeColor)3 ItemStack (org.bukkit.inventory.ItemStack)3 org.bukkit (org.bukkit)2 Art (org.bukkit.Art)2 World (org.bukkit.World)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 EntityType (org.bukkit.entity.EntityType)2 Horse (org.bukkit.entity.Horse)2 ItemFrame (org.bukkit.entity.ItemFrame)2 Ocelot (org.bukkit.entity.Ocelot)2 Painting (org.bukkit.entity.Painting)2 Sheep (org.bukkit.entity.Sheep)2 Villager (org.bukkit.entity.Villager)2 Wolf (org.bukkit.entity.Wolf)2 ImprovedOfflinePlayer (com.denizenscript.denizen.nms.abstracts.ImprovedOfflinePlayer)1 LocationTag (com.denizenscript.denizen.objects.LocationTag)1 WorldTag (com.denizenscript.denizen.objects.WorldTag)1