Search in sources :

Example 1 with MaterialData

use of org.bukkit.material.MaterialData in project Denizen-For-Bukkit by DenizenScript.

the class ItemChangeMessage method sendMessage.

public static void sendMessage(Player player, String message) {
    ItemStack item = NMSHandler.getInstance().getEntityHelper().getItemInHand(player);
    // which is probably the least intrusive
    if (item == null || item.getType() == Material.AIR) {
        item = new MaterialData(Material.STAINED_GLASS_PANE, DyeColor.GRAY.getDyeData()).toItemStack();
    } else {
        item = item.clone();
    }
    ItemMeta meta = item.getItemMeta();
    meta.setDisplayName(message);
    item.setItemMeta(meta);
    int slot = player.getInventory().getHeldItemSlot() + 36;
    NMSHandler.getInstance().getPacketHelper().setSlot(player, slot, item, true);
    slotChanged.put(player.getUniqueId(), slot);
}
Also used : MaterialData(org.bukkit.material.MaterialData) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 2 with MaterialData

use of org.bukkit.material.MaterialData in project Denizen-For-Bukkit by DenizenScript.

the class Particle_v1_8_R3 method playFor.

@Override
public <T> void playFor(Player player, Location location, int count, Vector offset, double extra, T data) {
    int[] dataArray;
    if (data instanceof ItemStack) {
        dataArray = new int[] { ((ItemStack) data).getType().getId(), ((ItemStack) data).getDurability() };
    } else if (data instanceof MaterialData) {
        dataArray = new int[] { ((MaterialData) data).getItemTypeId() + (((MaterialData) data).getData() << 12) };
    }
    PacketHelper_v1_8_R3.sendPacket(player, new PacketPlayOutWorldParticles(particle, true, (float) location.getX(), (float) location.getY(), (float) location.getZ(), (float) offset.getX(), (float) offset.getY(), (float) offset.getZ(), (float) extra, count));
}
Also used : PacketPlayOutWorldParticles(net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles) MaterialData(org.bukkit.material.MaterialData) ItemStack(org.bukkit.inventory.ItemStack)

Example 3 with MaterialData

use of org.bukkit.material.MaterialData in project Denizen-For-Bukkit by DenizenScript.

the class PlayEffectCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Extract objects from ScriptEntry
    List<dLocation> locations = (List<dLocation>) scriptEntry.getObject("location");
    List<dPlayer> targets = (List<dPlayer>) scriptEntry.getObject("targets");
    Effect effect = (Effect) scriptEntry.getObject("effect");
    Particle particleEffect = (Particle) scriptEntry.getObject("particleeffect");
    Element iconcrack = scriptEntry.getElement("iconcrack");
    Element iconcrack_data = scriptEntry.getElement("iconcrack_data");
    Element iconcrack_type = scriptEntry.getElement("iconcrack_type");
    Element radius = scriptEntry.getElement("radius");
    Element data = scriptEntry.getElement("data");
    Element qty = scriptEntry.getElement("qty");
    dLocation offset = scriptEntry.getdObject("offset");
    // Report to dB
    dB.report(scriptEntry, getName(), (effect != null ? aH.debugObj("effect", effect.getName()) : particleEffect != null ? aH.debugObj("special effect", particleEffect.getName()) : iconcrack_type.debug() + iconcrack.debug() + (iconcrack_data != null ? iconcrack_data.debug() : "")) + aH.debugObj("locations", locations.toString()) + (targets != null ? aH.debugObj("targets", targets.toString()) : "") + radius.debug() + data.debug() + qty.debug() + offset.debug());
    for (dLocation location : locations) {
        // Slightly increase the location's Y so effects don't seem to come out of the ground
        location.add(0, 1, 0);
        // Play the Bukkit effect the number of times specified
        if (effect != null) {
            for (int n = 0; n < qty.asInt(); n++) {
                if (targets != null) {
                    for (dPlayer player : targets) {
                        if (player.isValid() && player.isOnline()) {
                            effect.playFor(player.getPlayerEntity(), location, data.asInt());
                        }
                    }
                } else {
                    effect.play(location, data.asInt(), radius.asInt());
                }
            }
        } else // Play a ParticleEffect
        if (particleEffect != null) {
            float osX = (float) offset.getX();
            float osY = (float) offset.getY();
            float osZ = (float) offset.getZ();
            List<Player> players = new ArrayList<Player>();
            if (targets == null) {
                float rad = radius.asFloat();
                for (Player player : location.getWorld().getPlayers()) {
                    if (player.getLocation().distanceSquared(location) < rad * rad) {
                        players.add(player);
                    }
                }
            } else {
                for (dPlayer player : targets) {
                    if (player.isValid() && player.isOnline()) {
                        players.add(player.getPlayerEntity());
                    }
                }
            }
            for (Player player : players) {
                particleEffect.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat());
            }
        } else // Play an iconcrack (item break) effect
        {
            List<Player> players = new ArrayList<Player>();
            if (targets == null) {
                float rad = radius.asFloat();
                for (Player player : location.getWorld().getPlayers()) {
                    if (player.getLocation().distanceSquared(location) < rad * rad) {
                        players.add(player);
                    }
                }
            } else {
                for (dPlayer player : targets) {
                    if (player.isValid() && player.isOnline()) {
                        players.add(player.getPlayerEntity());
                    }
                }
            }
            // TODO: better this all
            if (iconcrack_type.asString().equalsIgnoreCase("iconcrack")) {
                ItemStack itemStack = new ItemStack(iconcrack.asInt(), 1, (short) (iconcrack_data != null ? iconcrack_data.asInt() : 0));
                Particle particle = NMSHandler.getInstance().getParticleHelper().getParticle("ITEM_CRACK");
                for (Player player : players) {
                    particle.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat(), itemStack);
                }
            } else if (iconcrack_type.asString().equalsIgnoreCase("blockcrack")) {
                MaterialData materialData = new MaterialData(iconcrack.asInt(), (byte) (iconcrack_data != null ? iconcrack_data.asInt() : 0));
                Particle particle = NMSHandler.getInstance().getParticleHelper().getParticle("BLOCK_CRACK");
                for (Player player : players) {
                    particle.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat(), materialData);
                }
            } else {
                // blockdust
                MaterialData materialData = new MaterialData(iconcrack.asInt(), (byte) (iconcrack_data != null ? iconcrack_data.asInt() : 0));
                Particle particle = NMSHandler.getInstance().getParticleHelper().getParticle("BLOCK_DUST");
                for (Player player : players) {
                    particle.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat(), materialData);
                }
            }
        }
    }
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) Element(net.aufdemrand.denizencore.objects.Element) Particle(net.aufdemrand.denizen.nms.interfaces.Particle) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) ArrayList(java.util.ArrayList) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Effect(net.aufdemrand.denizen.nms.interfaces.Effect) MaterialData(org.bukkit.material.MaterialData) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) ItemStack(org.bukkit.inventory.ItemStack)

Example 4 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockLog2 method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    // No Tree2 MaterialData
    MaterialData data = state.getData();
    data.setData(setTree(face, (byte) holding.getDurability()));
    state.setData(data);
}
Also used : MaterialData(org.bukkit.material.MaterialData)

Example 5 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockDispenser method updatePhysics.

@Override
public void updatePhysics(GlowBlock block) {
    GlowBlock up = block.getRelative(BlockFace.UP);
    boolean powered = block.isBlockPowered() || block.isBlockIndirectlyPowered() || up.isBlockPowered() || up.isBlockIndirectlyPowered();
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (!(data instanceof Dispenser)) {
        return;
    }
    boolean isTriggered = (data.getData() >> 3 & 1) != 0;
    if (powered && !isTriggered) {
        new BukkitRunnable() {

            @Override
            public void run() {
                trigger(block);
            }
        }.runTaskLater(null, 4);
        // TODO replace this with dispenser materialdata class (as soon as it provides access to this property)
        data.setData((byte) (data.getData() | 0x8));
        state.update();
    } else if (!powered && isTriggered) {
        data.setData((byte) (data.getData() & ~0x8));
        state.update();
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Dispenser(org.bukkit.material.Dispenser) GlowDispenser(net.glowstone.block.state.GlowDispenser) GlowBlockState(net.glowstone.block.GlowBlockState) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MaterialData(org.bukkit.material.MaterialData)

Aggregations

MaterialData (org.bukkit.material.MaterialData)124 ItemStack (org.bukkit.inventory.ItemStack)32 Material (org.bukkit.Material)23 GlowBlockState (net.glowstone.block.GlowBlockState)20 Block (org.bukkit.block.Block)16 ArrayList (java.util.ArrayList)13 BlockState (org.bukkit.block.BlockState)13 GlowBlock (net.glowstone.block.GlowBlock)10 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)9 TagCompound (de.keyle.knbt.TagCompound)9 Location (org.bukkit.Location)9 BlockFace (org.bukkit.block.BlockFace)9 EventHandler (org.bukkit.event.EventHandler)6 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)6 IOException (java.io.IOException)5 GlowBed (net.glowstone.block.entity.state.GlowBed)5 Player (org.bukkit.entity.Player)5 Bed (org.bukkit.material.Bed)5 Button (org.bukkit.material.Button)5 Entry (com.google.common.collect.Multiset.Entry)4