Search in sources :

Example 1 with CircleMarker

use of org.dynmap.markers.CircleMarker in project MagicPlugin by elBukkit.

the class DynmapController method showCastMarker.

public void showCastMarker(Mage mage, Spell spell, SpellResult result) {
    if (dynmap != null && dynmap.markerAPIInitialized()) {
        MarkerAPI markers = dynmap.getMarkerAPI();
        MarkerSet spellSet = markers.getMarkerSet("Spells");
        if (spellSet == null) {
            spellSet = markers.createMarkerSet("Spells", "Spell Casts", null, false);
        }
        final String markerId = "Spell-" + mage.getId();
        final String targetId = "SpellTarget-" + mage.getId();
        int range = 32;
        double radius = 3.0 * mage.getPower() + 3;
        int width = (int) (2.0 * mage.getPower()) + 2;
        radius = Math.min(64, radius);
        width = Math.min(8, width);
        final Location location = spell.getLocation();
        if (location == null)
            return;
        Color mageColor = mage.getEffectColor();
        mageColor = mageColor == null ? Color.PURPLE : mageColor;
        Color spellColor = spell.getColor();
        spellColor = spellColor == null ? mageColor : spellColor;
        final String worldName = location.getWorld().getName();
        Date now = new Date();
        String label = spell.getName() + " : " + mage.getName() + " @ " + dateFormatter.format(now);
        // Create a circular disc for a spell cast
        CircleMarker marker = spellSet.findCircleMarker(markerId);
        if (marker != null) {
            marker.setCenter(worldName, location.getX(), location.getY(), location.getZ());
            marker.setLabel(label);
        } else {
            marker = spellSet.createCircleMarker(markerId, label, false, worldName, location.getX(), location.getY(), location.getZ(), radius, radius, false);
        }
        marker.setRadius(radius, radius);
        marker.setLineStyle(1, 0.9, spellColor.asRGB());
        marker.setFillStyle(0.5, mageColor.asRGB());
        // Create a targeting indicator line
        Location target = spell.getTargetLocation();
        if (target == null) {
            target = location.clone();
            Vector direction = location.getDirection();
            direction.normalize().multiply(range);
            target.add(direction);
        }
        PolyLineMarker targetMarker = spellSet.findPolyLineMarker(targetId);
        if (targetMarker != null) {
            targetMarker.setCornerLocation(0, location.getX(), location.getY(), location.getZ());
            targetMarker.setCornerLocation(1, target.getX(), target.getY(), target.getZ());
            targetMarker.setLabel(label);
        } else {
            double[] x = { location.getX(), target.getX() };
            double[] y = { location.getY(), target.getY() };
            double[] z = { location.getZ(), target.getZ() };
            targetMarker = spellSet.createPolyLineMarker(targetId, label, false, worldName, x, y, z, false);
        }
        targetMarker.setLineStyle(width, 0.8, spellColor.asRGB());
    }
}
Also used : MarkerSet(org.dynmap.markers.MarkerSet) CircleMarker(org.dynmap.markers.CircleMarker) Color(org.bukkit.Color) MarkerAPI(org.dynmap.markers.MarkerAPI) PolyLineMarker(org.dynmap.markers.PolyLineMarker) Vector(org.bukkit.util.Vector) Date(java.util.Date) Location(org.bukkit.Location)

Aggregations

Date (java.util.Date)1 Color (org.bukkit.Color)1 Location (org.bukkit.Location)1 Vector (org.bukkit.util.Vector)1 CircleMarker (org.dynmap.markers.CircleMarker)1 MarkerAPI (org.dynmap.markers.MarkerAPI)1 MarkerSet (org.dynmap.markers.MarkerSet)1 PolyLineMarker (org.dynmap.markers.PolyLineMarker)1