more treasure stuff, really basic holograms

This commit is contained in:
Shaun Bennett 2014-09-02 18:33:40 -05:00
parent df882012e5
commit 4ad034b8d9
15 changed files with 411 additions and 301 deletions

View File

@ -0,0 +1,123 @@
package mineplex.core.hologram;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_7_R4.EntityFireball;
import net.minecraft.server.v1_7_R4.EntityHorse;
import net.minecraft.server.v1_7_R4.EntitySmallFireball;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutAttachEntity;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
import net.minecraft.server.v1_7_R4.World;
import mineplex.core.common.util.UtilServer;
/**
* Created by Shaun on 8/29/2014.
*/
public class SimpleHologram
{
/**
* SimpleHologram creates the required entities to spawn in a hologram. It is possible to send the packets for the entities to a player,
* but it is also possible to add the entities to the nmsWorld to keep them loaded into the server.
*/
private Location _location;
private String _text;
private World _nmsWorld;
private EntityFireball _fireball;
private EntityHorse _horse;
public SimpleHologram(Location location, String text)
{
_location = location;
_text = text;
_nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
// Create Entities
_fireball = new EntitySmallFireball(_nmsWorld);
_horse = new EntityHorse(_nmsWorld);
// Location Data
_fireball.setLocation(_location.getX(), _location.getY() + 55.25, _location.getZ(), 0, 0);
_horse.setLocation(_location.getX(), _location.getY() + 55.25, _location.getZ(), 0, 0);
_horse.setAge(-1700000);
_horse.setCustomName(_text);
_horse.setCustomNameVisible(true);
}
public void spawnWithPackets()
{
Packet fireballSpawn = getFireballSpawnPacket();
Packet horseSpawn = getHorseSpawnPacket();
Packet attachPacket = getAttachEntityPacket();
for (Player player : UtilServer.getPlayers())
{
sendPacket(player, fireballSpawn);
sendPacket(player, horseSpawn);
sendPacket(player, attachPacket);
}
}
public void removeWithPackets()
{
Packet horseDestroy = getHorseDestroyPacket();
Packet fireballDestroy = getFireballDestroyPacket();
for (Player player : UtilServer.getPlayers())
{
sendPacket(player, horseDestroy);
sendPacket(player, fireballDestroy);
}
}
public void setText(String text)
{
_text = text;
_horse.setCustomName(_text);
}
public String getText()
{
return _text;
}
private Packet getHorseSpawnPacket()
{
return new PacketPlayOutSpawnEntityLiving(_horse);
}
private Packet getFireballSpawnPacket()
{
return new PacketPlayOutSpawnEntity(_fireball, 64);
}
private Packet getAttachEntityPacket()
{
return new PacketPlayOutAttachEntity(0, _horse, _fireball);
}
private Packet getHorseDestroyPacket()
{
return new PacketPlayOutEntityDestroy(_horse.getId());
}
private Packet getFireballDestroyPacket()
{
return new PacketPlayOutEntityDestroy(_fireball.getId());
}
private void sendPacket(Player player, Packet packet)
{
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}

View File

@ -100,16 +100,22 @@ public class HorseMount extends Mount<Horse>
horse.setMaxDomestication(1);
horse.setJumpStrength(_jump);
horse.getInventory().setSaddle(new ItemStack(Material.SADDLE));
if (horse.getVariant() == Variant.MULE)
horse.setCarryingChest(true);
if (_armor != null)
horse.getInventory().setArmor(new ItemStack(_armor));
horse.setCustomName(player.getName() + "'s " + GetName());
horse.setCustomNameVisible(true);
if (player.getName().equals("Phinary"))
{
horse.setCustomName("Dinnerbone");
}
else
{
horse.setCustomName(player.getName() + "'s " + GetName());
horse.setCustomNameVisible(true);
}
//Inform
UtilPlayer.message(player, F.main("Mount", "You spawned " + F.elem(GetName()) + "."));

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction;
import mineplex.core.common.util.UtilServer;
import mineplex.core.treasure.reward.ITreasureReward;
/**
* Created by Shaun on 8/29/2014.
@ -15,12 +16,16 @@ import mineplex.core.common.util.UtilServer;
public class ChestData
{
private Block _block;
private ITreasureReward _reward;
private boolean _opened;
private boolean _finishedOpen;
public ChestData(Block block)
public ChestData(Block block, ITreasureReward reward)
{
_block = block;
_opened = false;
_finishedOpen = false;
_reward = reward;
}
public boolean isOpened()
@ -28,24 +33,29 @@ public class ChestData
return _opened;
}
public boolean isFinishedOpen()
{
return _finishedOpen;
}
public void setOpened(boolean opened)
{
_opened = opened;
}
public void setFinishedOpen(boolean finishedOpen)
{
_finishedOpen = finishedOpen;
}
public Block getBlock()
{
return _block;
}
public void open()
public ITreasureReward getReward()
{
if (!isOpened())
{
PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction(_block.getX(), _block.getY(), _block.getZ(), CraftMagicNumbers.getBlock(_block), 1, 1);
for (Player other : UtilServer.getPlayers())
{
((CraftPlayer) other).getHandle().playerConnection.sendPacket(packet);
other.playSound(_block.getLocation(), Sound.CHEST_OPEN, 1, 1);
}
_opened = true;
}
return _reward;
}
}

View File

@ -14,10 +14,12 @@ import org.bukkit.entity.Player;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.treasure.animation.ChestTask;
import mineplex.core.treasure.animation.ItemTask;
import mineplex.core.treasure.animation.ParticleTask;
import mineplex.core.treasure.animation.Task;
import mineplex.core.treasure.animation.ChestSpawnAnimation;
import mineplex.core.treasure.animation.ChestOpenAnimation;
import mineplex.core.treasure.animation.ParticleAnimation;
import mineplex.core.treasure.animation.Animation;
import mineplex.core.treasure.reward.ExampleReward;
import mineplex.core.treasure.reward.ITreasureReward;
/**
* Created by Shaun on 8/27/2014.
@ -30,8 +32,9 @@ public class Treasure
private Block _centerBlock;
private int _tickCount;
private ChestData[] _chestData;
private ITreasureReward[] _rewards;
private LinkedList<Task> _tasks;
private LinkedList<Animation> _animations;
private TreasureStyle _style;
@ -48,15 +51,15 @@ public class Treasure
_style = TreasureStyle.values()[_random.nextInt(TreasureStyle.values().length)];
_centerBlock = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
_tasks = new LinkedList<Task>();
_animations = new LinkedList<Animation>();
_tasks.add(new ParticleTask(this));
// _animations.add(new ParticleAnimation(this));
_chestData = new ChestData[4];
_chestData[0] = new ChestData(_centerBlock.getRelative(2, 1, 0));
_chestData[1] = new ChestData(_centerBlock.getRelative(-2, 1, 0));
_chestData[2] = new ChestData(_centerBlock.getRelative(0, 1, 2));
_chestData[3] = new ChestData(_centerBlock.getRelative(0, 1, -2));
_chestData[0] = new ChestData(_centerBlock.getRelative(2, 1, 0), new ExampleReward());
_chestData[1] = new ChestData(_centerBlock.getRelative(-2, 1, 0), new ExampleReward());
_chestData[2] = new ChestData(_centerBlock.getRelative(0, 1, 2), new ExampleReward());
_chestData[3] = new ChestData(_centerBlock.getRelative(0, 1, -2), new ExampleReward());
}
private void createCenterClay()
@ -119,57 +122,6 @@ public class Treasure
}
}
private void dropChests()
{
for (int z = -2; z <= 2; z++)
{
for (int x = -2; x <= 2; x++)
{
if ((Math.abs(x) == 2 || Math.abs(z) == 2) && (x == 0 || z == 0))
{
byte direction;
if (x == 2)
direction = (byte) 4;
else if (x == -2)
direction = (byte) 5;
else if (z == 2)
direction = (byte) 2;
else
direction = (byte) 3;
Block block = getPlayerBlock().getRelative(x, 0, z);
ChestTask task = new ChestTask(this, block, direction);
_tasks.add(task);
}
}
}
}
// private void updateParticles()
// {
// double modifier;
// if (_tickCount % 2 == 0)
// modifier = 0.5;
// else
// modifier = 0;
//
// for (int x = -2; x <= 2; x++)
// {
// for (int z = -2; z <= 2; z++)
// {
// if (Math.abs(x) == 2 || Math.abs(z) == 2)
// {
// if (Math.abs(x) == 2)
// z += modifier;
// else
// x += modifier;
//
// UtilParticle.PlayParticle(_style., getCenterBlock().getLocation().add(x, 7, z), 0F, 0F, 0F, 1, 1);
// }
// }
// }
// }
public void update()
{
@ -193,26 +145,26 @@ public class Treasure
else if (_tickCount == 50)
{
Block block = getPlayerBlock().getRelative(2, 0, 0);
ChestTask task = new ChestTask(this, block, (byte)4);
_tasks.add(task);
ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)4);
_animations.add(task);
}
else if (_tickCount == 80)
{
Block block = getPlayerBlock().getRelative(-2, 0, 0);
ChestTask task = new ChestTask(this, block, (byte)5);
_tasks.add(task);
ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)5);
_animations.add(task);
}
else if (_tickCount == 110)
{
Block block = getPlayerBlock().getRelative(0, 0, 2);
ChestTask task = new ChestTask(this, block, (byte)2);
_tasks.add(task);
ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)2);
_animations.add(task);
}
else if (_tickCount == 140)
{
Block block = getPlayerBlock().getRelative(0, 0, -2);
ChestTask task = new ChestTask(this, block, (byte)3);
_tasks.add(task);
ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)3);
_animations.add(task);
}
Block block = _player.getTargetBlock(null, 3);
@ -225,14 +177,14 @@ public class Treasure
}
}
Iterator<Task> taskIterator = _tasks.iterator();
Iterator<Animation> taskIterator = _animations.iterator();
while (taskIterator.hasNext())
{
Task task = taskIterator.next();
Animation animation = taskIterator.next();
if (task.isRunning())
if (animation.isRunning())
{
task.run();
animation.run();
}
else
{
@ -266,9 +218,15 @@ public class Treasure
ChestData data = getChestData(block);
if (data != null && !data.isOpened())
{
data.open();
ItemTask itemTask = new ItemTask(this, block, ChatColor.GREEN + "100 Gems", Material.EMERALD, (byte) 0);
_tasks.add(itemTask);
data.setOpened(true);
ChestOpenAnimation chestOpenTask = new ChestOpenAnimation(this, data);
_animations.add(chestOpenTask);
if (isFinished())
{
System.out.println("finished");
}
}
}
@ -296,7 +254,7 @@ public class Treasure
return allOpened;
}
public void clean()
public void finish()
{
for (Map.Entry<Block, BlockInfo> entry : _blockRestoreMap.entrySet())
{
@ -307,11 +265,11 @@ public class Treasure
block.setData(data.getData());
}
for (Task task : _tasks)
for (Animation animation : _animations)
{
task.cancel();
animation.finish();
}
_tasks.clear();
_animations.clear();
}
public TreasureStyle getStyle()

View File

@ -23,9 +23,12 @@ import org.bukkit.plugin.java.JavaPlugin;
import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -49,7 +52,7 @@ public class TreasureManager extends MiniPlugin
{
for (Treasure treasure : _playerTreasureMap.values())
{
treasure.clean();
treasure.finish();
}
}
@ -61,10 +64,33 @@ public class TreasureManager extends MiniPlugin
Treasure treasure = new Treasure(player);
_playerTreasureMap.put(player, treasure);
Location teleportLocation = treasure.getPlayerBlock().getLocation().add(0.5, 0, 0.5);
teleportLocation.setPitch(player.getLocation().getPitch());
teleportLocation.setYaw(player.getLocation().getYaw());
player.teleport(teleportLocation);
}
private boolean checkNearbyBlocks(Player player)
{
Block centerBlock = player.getLocation().getBlock();
for (int y = 0; y <= 3; y++)
{
for (int x = -3; x <= 3; x++)
{
for (int z = -3; z <= 3; z++)
{
Block block = centerBlock.getRelative(x, y, z);
if (UtilBlock.solid(block))
{
UtilPlayer.message(player, F.main("Treasure", "You can not open a treasure at this spot. Please find a more open location"));
return false;
}
}
}
}
return true;
}
@ -81,32 +107,13 @@ public class TreasureManager extends MiniPlugin
}
}
@EventHandler
public void checkFinish(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOW)
return;
Iterator<Map.Entry<Player, Treasure>> iterator = _playerTreasureMap.entrySet().iterator();
while (iterator.hasNext())
{
Treasure treasure = iterator.next().getValue();
if (treasure.isFinished())
{
iterator.remove();
treasure.clean();
}
}
}
@EventHandler
public void quit(PlayerQuitEvent event)
{
if (_playerTreasureMap.containsKey(event.getPlayer()))
{
Treasure treasure = _playerTreasureMap.remove(event.getPlayer());
treasure.clean();
treasure.finish();
}
}
@ -116,9 +123,9 @@ public class TreasureManager extends MiniPlugin
Player player = event.getPlayer();
if (_playerTreasureMap.containsKey(player))
{
Treasure treasure = _playerTreasureMap.get(player);
Block playerBlock = treasure.getPlayerBlock();
if (!event.getTo().getBlock().equals(playerBlock))
Location to = event.getTo();
Location from = event.getFrom();
if (to.getX() != from.getX() || to.getY() != from.getY() || to.getZ() != from.getZ())
{
Location newTo = event.getFrom().clone();
newTo.setPitch(event.getTo().getPitch());
@ -131,11 +138,10 @@ public class TreasureManager extends MiniPlugin
for (Treasure treasure : _playerTreasureMap.values())
{
Location centerLocation = treasure.getCenterBlock().getLocation().add(0.5, 1.5, 0.5);
if (centerLocation.distanceSquared(event.getTo()) <= 4)
if (centerLocation.distanceSquared(event.getTo()) <= 6)
{
UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), centerLocation).multiply(-1), 1.5, true, 0.8, 0, 1.0, true);
event.setTo(event.getFrom());
// event.setCancelled(true);
}
}
}
@ -172,10 +178,12 @@ public class TreasureManager extends MiniPlugin
@EventHandler
public void command(PlayerCommandPreprocessEvent event)
{
//TODO Remove
if (event.getMessage().startsWith("/treasure"))
{
attemptOpenTreasure(event.getPlayer());
event.getPlayer().sendMessage("Attempting to open treasure...");
attemptOpenTreasure(event.getPlayer());
event.setCancelled(true);
}
}

View File

@ -2,26 +2,30 @@ package mineplex.core.treasure;
import org.bukkit.Material;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.treasure.animation.ParticleTask;
import mineplex.core.common.util.UtilParticle.ParticleType;
/**
* Created by Shaun on 8/28/2014.
*/
public enum TreasureStyle
{
/**
* These are examples, not final!
*/
RED(Material.STAINED_CLAY, (byte) 14,
Material.STAINED_CLAY, (byte) 6,
Material.STAINED_GLASS_PANE, (byte) 14,
UtilParticle.ParticleType.HEART,
UtilParticle.ParticleType.HAPPY_VILLAGER),
ParticleType.HEART,
ParticleType.HAPPY_VILLAGER,
ParticleType.FLAME),
GREEN(Material.STAINED_CLAY,(byte) 5,
Material.STAINED_CLAY, (byte) 13,
Material.STAINED_GLASS_PANE, (byte) 5,
UtilParticle.ParticleType.FLAME,
UtilParticle.ParticleType.RED_DUST);
ParticleType.FLAME,
ParticleType.RED_DUST,
ParticleType.LAVA);
private Material _primaryMaterial;
private byte _primaryData;
@ -32,19 +36,24 @@ public enum TreasureStyle
private Material _wallMaterial;
private byte _wallData;
private UtilParticle.ParticleType _primaryParticle;
private UtilParticle.ParticleType _secondaryParticle;
private ParticleType _primaryParticle;
private ParticleType _secondaryParticle;
private ParticleType _chestSpawnParticle;
TreasureStyle(Material primaryMaterial, byte primaryData, Material secondaryMaterial, byte secondaryData, Material wallMaterial, byte wallData, UtilParticle.ParticleType primaryParticle, UtilParticle.ParticleType secondaryParticle)
TreasureStyle(Material primaryMaterial, byte primaryData, Material secondaryMaterial, byte secondaryData, Material wallMaterial, byte wallData, ParticleType primaryParticle, ParticleType secondaryParticle, ParticleType chestSpawnParticle)
{
_primaryMaterial = primaryMaterial;
_primaryData = primaryData;
_secondaryMaterial = secondaryMaterial;
_secondaryData = secondaryData;
_wallMaterial = wallMaterial;
_wallData = wallData;
_primaryParticle = primaryParticle;
_secondaryParticle = secondaryParticle;
_chestSpawnParticle = chestSpawnParticle;
}
public Material getPrimaryMaterial()
@ -77,13 +86,18 @@ public enum TreasureStyle
return _wallData;
}
public UtilParticle.ParticleType getPrimaryParticle()
public ParticleType getPrimaryParticle()
{
return _primaryParticle;
}
public UtilParticle.ParticleType getSecondaryParticle()
public ParticleType getSecondaryParticle()
{
return _secondaryParticle;
}
public ParticleType getChestSpawnParticle()
{
return _chestSpawnParticle;
}
}

View File

@ -5,13 +5,13 @@ import mineplex.core.treasure.Treasure;
/**
* Created by Shaun on 8/29/2014.
*/
public abstract class Task
public abstract class Animation
{
private Treasure _treasure;
private boolean _running;
private int _ticks;
public Task(Treasure treasure)
public Animation(Treasure treasure)
{
_treasure = treasure;
_running = true;
@ -25,12 +25,15 @@ public abstract class Task
protected abstract void tick();
protected abstract void cleanup();
protected abstract void onFinish();
public void cancel()
public void finish()
{
_running = false;
cleanup();
if (_running)
{
_running = false;
onFinish();
}
}
public boolean isRunning()

View File

@ -0,0 +1,71 @@
package mineplex.core.treasure.animation;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R4.util.CraftMagicNumbers;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction;
import mineplex.core.common.util.UtilServer;
import mineplex.core.hologram.SimpleHologram;
import mineplex.core.treasure.ChestData;
import mineplex.core.treasure.Treasure;
/**
* Created by Shaun on 8/29/2014.
*/
public class ChestOpenAnimation extends Animation
{
private ChestData _chestData;
private Item _itemEntity;
private SimpleHologram _hologram;
public ChestOpenAnimation(Treasure treasure, ChestData chestData)
{
super(treasure);
_chestData = chestData;
// Send chest open packet
Block block = chestData.getBlock();
PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction(block.getX(), block.getY(), block.getZ(), CraftMagicNumbers.getBlock(block), 1, 1);
for (Player other : UtilServer.getPlayers())
{
((CraftPlayer) other).getHandle().playerConnection.sendPacket(packet);
other.playSound(block.getLocation(), Sound.CHEST_OPEN, 1, 1);
}
}
@Override
protected void tick()
{
if (getTicks() == 5)
{
Location location = _chestData.getBlock().getLocation().add(0.5, 0.8, 0.5);
_itemEntity = location.getWorld().dropItem(location, _chestData.getReward().getItem());
_itemEntity.setVelocity(new Vector(0, 0, 0));
_itemEntity.setPickupDelay(Integer.MAX_VALUE);
}
else if (getTicks() == 15)
{
_hologram = new SimpleHologram(_chestData.getBlock().getLocation().add(0.5, 1.1, 0.5), _chestData.getReward().getText());
_hologram.spawnWithPackets();
_chestData.setFinishedOpen(true);
}
}
public void onFinish()
{
if (_hologram != null)
{
_hologram.removeWithPackets();
_itemEntity.remove();
}
}
}

View File

@ -11,7 +11,7 @@ import mineplex.core.treasure.Treasure;
/**
* Created by Shaun on 8/29/2014.
*/
public class ChestTask extends Task
public class ChestSpawnAnimation extends Animation
{
private static final int ANIMATION_DURATION = 30;
@ -19,7 +19,7 @@ public class ChestTask extends Task
private byte _direction;
private Location _centerLocation;
public ChestTask(Treasure tresure, Block block, byte direction)
public ChestSpawnAnimation(Treasure tresure, Block block, byte direction)
{
super(tresure);
_block = block;
@ -31,33 +31,31 @@ public class ChestTask extends Task
@Override
public void tick()
{
int ticks = getTicks();
float scale = (float)((double)(ANIMATION_DURATION - ticks)/(double)ANIMATION_DURATION);
float scale = (float)((double)(ANIMATION_DURATION - getTicks()) / (double)ANIMATION_DURATION);
float y = 5 * scale;
double width = 1.4 * ((double)ticks / (double)ANIMATION_DURATION);
double width = 1.4 * ((double) getTicks() / (double) ANIMATION_DURATION);
for (int i=0 ; i < 2 ; i++)
{
double lead = i * ((2d * Math.PI)/2);
float x = (float) (Math.sin(ticks/4D + lead));
float z = (float) (Math.cos(ticks/4D + lead));
float x = (float) (Math.sin(getTicks()/4D + lead));
float z = (float) (Math.cos(getTicks()/4D + lead));
UtilParticle.PlayParticle(getTreasure().getStyle().getSecondaryParticle(), _centerLocation.clone().add(x * width, y, z * width), 0f, 0f, 0f, 0, 1);
}
if (ticks >= ANIMATION_DURATION)
if (getTicks() >= ANIMATION_DURATION)
{
getTreasure().setBlock(_block, Material.CHEST, _direction);
_block.getLocation().getWorld().playSound(_centerLocation, Sound.ANVIL_LAND, 0.5f, 1f);
UtilParticle.PlayParticle(UtilParticle.ParticleType.LAVA, _centerLocation, 0.2f, 0.2f, 0.2f, 0, 50);
cancel();
UtilParticle.PlayParticle(getTreasure().getStyle().getChestSpawnParticle(), _centerLocation, 0.2f, 0.2f, 0.2f, 0, 50);
finish();
}
}
@Override
protected void cleanup()
protected void onFinish()
{
}

View File

@ -1,83 +0,0 @@
package mineplex.core.treasure.animation;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_7_R4.EntityFireball;
import net.minecraft.server.v1_7_R4.EntityHorse;
import net.minecraft.server.v1_7_R4.EntityLargeFireball;
import net.minecraft.server.v1_7_R4.EntitySmallFireball;
import net.minecraft.server.v1_7_R4.EntityWither;
import net.minecraft.server.v1_7_R4.EntityWitherSkull;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutAttachEntity;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
import net.minecraft.server.v1_7_R4.PlayerConnection;
import net.minecraft.server.v1_7_R4.World;
import mineplex.core.common.util.UtilServer;
/**
* Created by Shaun on 8/29/2014.
*/
public class Hologram
{
private Location _location;
private String _text;
private boolean spawned;
private int horseId;
private int fireballId;
public Hologram(Location location, String text)
{
_location = location;
_text = text;
}
public void spawn()
{
World nmsWorld = ((CraftWorld) _location.getWorld()).getHandle();
EntityWitherSkull fireball = new EntityWitherSkull(nmsWorld);
fireball.setLocation(_location.getX(), _location.getY() + 55, _location.getZ(), 0, 0);
PacketPlayOutSpawnEntity fireballPacket = new PacketPlayOutSpawnEntity(fireball, 64);
fireballId = fireball.getId();
EntityHorse horse = new EntityHorse(nmsWorld);
horse.setLocation(_location.getX(), _location.getY() + 55, _location.getZ(), 0, 0);
horse.setAge(-1700000);
horse.setCustomName(_text);
horse.setCustomNameVisible(true);
PacketPlayOutSpawnEntityLiving horsePacket = new PacketPlayOutSpawnEntityLiving(horse);
horseId = horse.getId();
for (Player player : UtilServer.getPlayers())
{
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
connection.sendPacket(horsePacket);
connection.sendPacket(fireballPacket);
PacketPlayOutAttachEntity attachPacket = new PacketPlayOutAttachEntity(0, horse, fireball);
connection.sendPacket(attachPacket);
}
}
public void remove()
{
PacketPlayOutEntityDestroy horseDestroy = new PacketPlayOutEntityDestroy(horseId);
PacketPlayOutEntityDestroy fireballDestroy = new PacketPlayOutEntityDestroy(fireballId);
for (Player player : UtilServer.getPlayers())
{
PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
connection.sendPacket(horseDestroy);
connection.sendPacket(fireballDestroy);
}
}
}

View File

@ -1,58 +0,0 @@
package mineplex.core.treasure.animation;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import mineplex.core.treasure.Treasure;
/**
* Created by Shaun on 8/29/2014.
*/
public class ItemTask extends Task
{
private String _itemName;
private Material _material;
private byte _data;
private Item _itemEntity;
private Block _chestBlock;
private Hologram _hologram;
public ItemTask(Treasure treasure, Block chestBlock, String itemName, Material material, byte data)
{
super(treasure);
_itemName = itemName;
_material = material;
_data = data;
_chestBlock = chestBlock;
}
@Override
protected void tick()
{
if (getTicks() == 5)
{
Location location = _chestBlock.getLocation().add(0.5, 0.8, 0.5);
_itemEntity = location.getWorld().dropItem(location, new ItemStack(_material, 1, _data));
_itemEntity.setVelocity(new Vector(0, 0, 0));
_itemEntity.setPickupDelay(Integer.MAX_VALUE);
}
else if (getTicks() == 15)
{
_hologram = new Hologram(_chestBlock.getLocation().add(0.5, 1.5, 0.5), _itemName);
_hologram.spawn();
}
}
public void cleanup()
{
if (_hologram != null)
{
_hologram.remove();
_itemEntity.remove();
}
}
}

View File

@ -10,7 +10,7 @@ import mineplex.core.treasure.Treasure;
/**
* Created by Shaun on 8/29/2014.
*/
public class ParticleTask extends Task
public class ParticleAnimation extends Animation
{
private static double MODIFIER = 0.5;
private static ArrayList<Vector> PATH = new ArrayList<Vector>();
@ -26,19 +26,16 @@ public class ParticleTask extends Task
PATH.add(new Vector(x, y, z));
}
z = 3;
for (x = 3; x >= -3; x -= MODIFIER)
{
PATH.add(new Vector(x, y, z));
}
x = -3;
for (z = 3; z >= -3; z -= MODIFIER)
{
PATH.add(new Vector(x, y, z));
}
z = -3;
for (x = -3; x <= 3; x += MODIFIER)
{
PATH.add(new Vector(x, y, z));
@ -47,7 +44,7 @@ public class ParticleTask extends Task
private int pathPosition = 0;
public ParticleTask(Treasure treasure)
public ParticleAnimation(Treasure treasure)
{
super(treasure);
}
@ -63,7 +60,7 @@ public class ParticleTask extends Task
}
@Override
protected void cleanup()
protected void onFinish()
{
}

View File

@ -0,0 +1,30 @@
package mineplex.core.treasure.reward;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
/**
* Created by Shaun on 9/2/2014.
*/
public class ExampleReward implements ITreasureReward
{
@Override
public String getText()
{
return C.cGreen + "100 Gems";
}
@Override
public ItemStack getItem()
{
return new ItemStack(Material.EMERALD);
}
@Override
public RewardRarity getRarity()
{
return RewardRarity.COMMON;
}
}

View File

@ -0,0 +1,16 @@
package mineplex.core.treasure.reward;
import org.bukkit.inventory.ItemStack;
/**
* Created by Shaun on 9/2/2014.
*/
public interface ITreasureReward
{
public String getText();
public ItemStack getItem();
public RewardRarity getRarity();
}

View File

@ -0,0 +1,17 @@
package mineplex.core.treasure.reward;
/**
* Created by Shaun on 9/2/2014.
*/
public enum RewardRarity
{
/**
* This will probably be used to figure out what effects are shown when the chest is opened
*
* (Fireworks, sounds, etc)
*/
COMMON, UNCOMMON, RARE, VERY_RARE;
}