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);
}
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));
}
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);
}
}
}
}
}
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);
}
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();
}
}
Aggregations