More treasure bug fixes and animation touches

This commit is contained in:
Shaun Bennett 2014-09-16 15:04:42 -05:00
parent 6eed36f0ee
commit 918a817283
7 changed files with 158 additions and 64 deletions

View File

@ -1,17 +1,27 @@
package mineplex.core.treasure;
import org.bukkit.block.Block;
/**
* Created by Shaun on 8/28/2014.
*/
public class BlockInfo
{
private Block _block;
private int _id;
private byte _data;
public BlockInfo(int id, byte data)
public BlockInfo(Block block)
{
_id = id;
_data = data;
_block = block;
_id = block.getTypeId();
_data = block.getData();
}
public Block getBlock()
{
return _block;
}
public int getId()
@ -23,4 +33,10 @@ public class BlockInfo
{
return _data;
}
@Override
public int hashCode()
{
return _block.hashCode();
}
}

View File

@ -1,9 +1,10 @@
package mineplex.core.treasure;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
@ -16,7 +17,6 @@ import org.bukkit.entity.Player;
import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.treasure.animation.Animation;
import mineplex.core.treasure.animation.ChestExplodeAnimation;
@ -33,7 +33,13 @@ import mineplex.core.treasure.reward.RewardRarity;
*/
public class Treasure
{
private NautHashMap<Block, BlockInfo> _blockRestoreMap = new NautHashMap<Block, BlockInfo>();
// Decay Sets
private HashSet<BlockInfo> _wallsBlockInfo = new HashSet<>();
private HashSet<BlockInfo> _outerRingBlockInfo = new HashSet<>();
private HashSet<BlockInfo> _centerBlockInfo = new HashSet<>();
private HashSet<BlockInfo> _chestBlockInfo = new HashSet<>();
private Player _player;
private Random _random;
private Block _centerBlock;
@ -80,6 +86,7 @@ public class Treasure
if (Math.abs(x) == 1 || Math.abs(z) == 1)
{
Block block = _centerBlock.getRelative(x, 0, z);
_centerBlockInfo.add(new BlockInfo(block));
setBlock(block, _style.getPrimaryMaterial(), _style.getPrimaryData());
}
}
@ -92,11 +99,13 @@ public class Treasure
{
{
Block block = _centerBlock.getRelative(x, 0, -2);
_outerRingBlockInfo.add(new BlockInfo(block));
setBlock(block, _style.getSecondaryMaterial(), _style.getSecondaryData());
}
{
Block block = _centerBlock.getRelative(x, 0, 2);
_outerRingBlockInfo.add(new BlockInfo(block));
setBlock(block, _style.getSecondaryMaterial(), _style.getSecondaryData());
}
}
@ -105,17 +114,19 @@ public class Treasure
{
{
Block block = _centerBlock.getRelative(-2, 0, z);
_outerRingBlockInfo.add(new BlockInfo(block));
setBlock(block, _style.getSecondaryMaterial(), _style.getSecondaryData());
}
{
Block block = _centerBlock.getRelative(2, 0, z);
_outerRingBlockInfo.add(new BlockInfo(block));
setBlock(block, _style.getSecondaryMaterial(), _style.getSecondaryData());
}
}
}
private void createGlass()
private void createWalls()
{
for (int z = -2; z <= 2; z++)
{
@ -125,6 +136,7 @@ public class Treasure
{
Block playerBlock = getPlayerBlock();
Block block = playerBlock.getRelative(x, 0, z);
_wallsBlockInfo.add(new BlockInfo(block));
setBlock(block, _style.getWallMaterial(), _style.getWallData());
}
}
@ -146,7 +158,10 @@ public class Treasure
if (_tickCount == 5)
{
Block block = _centerBlock;
setBlock(block, _style.getPrimaryMaterial(), _style.getPrimaryData());
_centerBlockInfo.add(new BlockInfo(block));
_centerBlockInfo.add(new BlockInfo(block.getRelative(BlockFace.DOWN)));
setBlock(block, Material.REDSTONE_LAMP_ON, (byte) 0);
setBlock(block.getRelative(BlockFace.DOWN), Material.REDSTONE_TORCH_ON, (byte) 0);
}
else if (_tickCount == 10)
{
@ -158,30 +173,30 @@ public class Treasure
}
else if (_tickCount == 30)
{
createGlass();
createWalls();
}
else if (_tickCount == 50)
{
Block block = getPlayerBlock().getRelative(2, 0, 0);
ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)4);
ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)4, _chestBlockInfo);
_animations.add(task);
}
else if (_tickCount == 80)
{
Block block = getPlayerBlock().getRelative(-2, 0, 0);
ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)5);
ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)5, _chestBlockInfo);
_animations.add(task);
}
else if (_tickCount == 110)
{
Block block = getPlayerBlock().getRelative(0, 0, 2);
ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)2);
ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)2, _chestBlockInfo);
_animations.add(task);
}
else if (_tickCount == 140)
{
Block block = getPlayerBlock().getRelative(0, 0, -2);
ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)3);
ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)3, _chestBlockInfo);
_animations.add(task);
}
@ -223,21 +238,13 @@ public class Treasure
return _centerBlock.getRelative(BlockFace.UP);
}
public void setBlock(Block block, Material material, byte data, boolean addToBlockRestoreMap)
public void setBlock(Block block, Material material, byte data)
{
if (addToBlockRestoreMap)
_blockRestoreMap.put(block, new BlockInfo(block.getTypeId(), block.getData()));
block.setType(material);
block.setData(data);
block.getLocation().getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
}
public void setBlock(Block block, Material material, byte data)
{
setBlock(block, material, data, true);
}
public void openChest(Block block)
{
ChestData data = getChestData(block);
@ -257,17 +264,17 @@ public class Treasure
else if (data.getReward().getRarity() == RewardRarity.RARE)
{
_animations.add(new CircleAnimation(this, data.getBlock().getLocation().add(0.5, 1.5, 0.5)));
Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " opened a Rare treasure!"));
Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " opened the Rare treasure " + text));
}
else if (data.getReward().getRarity() == RewardRarity.VERY_RARE)
{
_animations.add(new ChestExplodeAnimation(this, data.getBlock()));
Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " opened a Legendary treasure!"));
Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " opened the Legendary treasure " + text));
}
if (isFinished())
{
TreasureRemoveAnimation animation = new TreasureRemoveAnimation(this, _blockRestoreMap);
TreasureRemoveAnimation animation = new TreasureRemoveAnimation(this, _centerBlockInfo, _outerRingBlockInfo, _wallsBlockInfo);
_animations.add(animation);
_finished = true;
}
@ -337,20 +344,11 @@ public class Treasure
}
}
for (Map.Entry<Block, BlockInfo> entry : _blockRestoreMap.entrySet())
{
Block block = entry.getKey();
BlockInfo data = entry.getValue();
if (block.getType().equals(Material.CHEST))
{
block.getLocation().getWorld().createExplosion(block.getLocation().add(0.5, 0.5, 0.5), 0F);
}
block.getLocation().getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
block.setTypeId(data.getId());
block.setData(data.getData());
}
// Remove any extra blocks
resetBlockInfo(_wallsBlockInfo);
resetBlockInfo(_centerBlockInfo);
resetBlockInfo(_outerRingBlockInfo);
resetBlockInfo(_chestBlockInfo);
for (Animation animation : _animations)
{
@ -359,6 +357,25 @@ public class Treasure
_animations.clear();
}
public void resetBlockInfo(Set<BlockInfo> blockInfoSet)
{
for (BlockInfo blockInfo : blockInfoSet)
{
Block block = blockInfo.getBlock();
if (block.getType().equals(Material.CHEST))
{
block.getLocation().getWorld().createExplosion(block.getLocation().add(0.5, 0.5, 0.5), 0F);
}
block.getLocation().getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
block.setTypeId(blockInfo.getId());
block.setData(blockInfo.getData());
}
blockInfoSet.clear();
}
public TreasureStyle getStyle()
{
return _style;

View File

@ -11,12 +11,14 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerVelocityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
@ -31,6 +33,7 @@ import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.donation.DonationManager;
import mineplex.core.event.StackerEvent;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.treasure.event.TreasureFinishEvent;
import mineplex.core.treasure.event.TreasureStartEvent;
@ -66,7 +69,7 @@ public class TreasureManager extends MiniPlugin
{
// Coins
{
_rewardManager.addReward(new CoinReward(donationManager, 2000, 5000, 25, RewardRarity.VERY_RARE));
_rewardManager.addReward(new CoinReward(donationManager, 10000, 20000, 25, RewardRarity.VERY_RARE));
}
// Mounts
{
@ -330,7 +333,7 @@ public class TreasureManager extends MiniPlugin
treasure.update();
if (treasure.isFinished() && treasure.getFinishedTickCount() >= 100)
if (treasure.isFinished() && treasure.getFinishedTickCount() >= 80)
{
treasure.cleanup();
iterator.remove();
@ -391,8 +394,17 @@ public class TreasureManager extends MiniPlugin
{
for (Treasure treasure : _playerTreasureMap.values())
{
Location fromLocation = event.getFrom();
Location toLocation = event.getTo();
Location centerLocation = treasure.getCenterBlock().getLocation().add(0.5, 1.5, 0.5);
if (centerLocation.distanceSquared(event.getTo()) <= 9)
double toDistanceFromCenter = centerLocation.distanceSquared(toLocation);
if (toDistanceFromCenter <= 9)
{
// Only cancel movement if they are moving towards the center
double fromDistanceFromCenter = centerLocation.distanceSquared(fromLocation);
if (toDistanceFromCenter < fromDistanceFromCenter)
{
UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), centerLocation).multiply(-1), 1.5, true, 0.8, 0, 1.0, true);
event.setTo(event.getFrom());
@ -400,8 +412,34 @@ public class TreasureManager extends MiniPlugin
}
}
}
}
@EventHandler
public void cancelVelocity(PlayerVelocityEvent event)
{
// Need to prevent players
Player player = event.getPlayer();
if (_playerTreasureMap.containsKey(player))
{
event.setCancelled(true);
}
}
@EventHandler
public void cancelStacker(StackerEvent event)
{
if (event.getEntity() instanceof Player)
{
Player player = ((Player) event.getEntity());
if (_playerTreasureMap.containsKey(player))
{
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void interact(PlayerInteractEvent event)
{
Player player = event.getPlayer();
@ -409,11 +447,12 @@ public class TreasureManager extends MiniPlugin
{
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.CHEST)
{
event.setCancelled(true);
Treasure treasure = _playerTreasureMap.get(player);
treasure.openChest(event.getClickedBlock());
}
// Always cancel interact for treasure players, prevents players from being able to open up cosmetic menu and other menus
event.setCancelled(true);
}
else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.CHEST)
{

View File

@ -1,15 +1,16 @@
package mineplex.core.treasure.animation;
import java.util.HashSet;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import net.minecraft.server.v1_7_R4.MathHelper;
import net.minecraft.server.v1_7_R4.PacketPlayOutWorldEvent;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.treasure.BlockInfo;
import mineplex.core.treasure.Treasure;
/**
@ -23,13 +24,16 @@ public class ChestSpawnAnimation extends Animation
private byte _direction;
private Location _centerLocation;
public ChestSpawnAnimation(Treasure tresure, Block block, byte direction)
private HashSet<BlockInfo> _chestBlockInfo;
public ChestSpawnAnimation(Treasure tresure, Block block, byte direction, HashSet<BlockInfo> chestBlockInfo)
{
super(tresure);
_block = block;
_direction = direction;
_centerLocation = block.getLocation().clone().add(0.5, 0.5, 0.5);
_centerLocation.getWorld().playSound(_centerLocation, Sound.LAVA, 1, 1);
_chestBlockInfo = chestBlockInfo;
}
@Override
@ -50,6 +54,7 @@ public class ChestSpawnAnimation extends Animation
if (getTicks() >= ANIMATION_DURATION)
{
_chestBlockInfo.add(new BlockInfo(_block));
getTreasure().setBlock(_block, Material.CHEST, _direction);
_block.getLocation().getWorld().playSound(_centerLocation, Sound.ANVIL_LAND, 0.5f, 1f);

View File

@ -1,11 +1,8 @@
package mineplex.core.treasure.animation;
import java.util.HashSet;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.block.Block;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.treasure.BlockInfo;
import mineplex.core.treasure.Treasure;
@ -16,21 +13,43 @@ public class TreasureRemoveAnimation extends Animation
{
private Random _random = new Random();
private NautHashMap<Block, BlockInfo> _blockRestoreMap;
private HashSet<BlockInfo> _wallsBlockInfo;
private HashSet<BlockInfo> _outerRingBlockInfo;
private HashSet<BlockInfo> _centerBlockInfo;
public TreasureRemoveAnimation(Treasure treasure, NautHashMap<Block, BlockInfo> blockRestoreMap)
public TreasureRemoveAnimation(Treasure treasure, HashSet<BlockInfo> centerBlockInfo, HashSet<BlockInfo> outerRingBlockInfo, HashSet<BlockInfo> wallsBlockInfo)
{
super(treasure);
_blockRestoreMap = blockRestoreMap;
_wallsBlockInfo = wallsBlockInfo;
_centerBlockInfo = centerBlockInfo;
_outerRingBlockInfo = outerRingBlockInfo;
}
@Override
protected void tick()
{
// first wait for 1 second
if (getTicks() <= 20)
return;
// Chests go away at 100 ticks
HashSet<BlockInfo> blockInfoSet = null;
if (getTicks() == 40)
{
blockInfoSet = _wallsBlockInfo;
}
else if (getTicks() == 50)
{
blockInfoSet = _outerRingBlockInfo;
}
else if (getTicks() == 60)
{
blockInfoSet = _centerBlockInfo;
}
if (blockInfoSet != null)
{
getTreasure().resetBlockInfo(blockInfoSet);
}
/*
if (getTicks() % 2 == 0)
{
if (_blockRestoreMap.size() > 4)
@ -52,6 +71,7 @@ public class TreasureRemoveAnimation extends Animation
finish();
}
}
*/
}
@Override

View File

@ -6,11 +6,9 @@ package mineplex.core.treasure.reward.rewards;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.donation.DonationManager;
import mineplex.core.treasure.reward.RewardRarity;
@ -32,7 +30,7 @@ public class CoinReward extends AbstractReward
public CoinReward(DonationManager donationManager, int minCoinCount, int maxCoinCount, int weight, RewardRarity rarity, Random random)
{
super(new ItemStack(Material.GOLD_INGOT), rarity, weight);
super(new ItemStack(175), rarity, weight);
_donationManager = donationManager;
_minCoinCount = minCoinCount;
_maxCoinCount = maxCoinCount;

View File

@ -1,6 +1,5 @@
package mineplex.core.treasure.reward.rewards;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -35,7 +34,7 @@ public class UnknownPackageReward extends AbstractReward
@Override
public boolean canGiveReward(Player player)
{
return _donationManager.Get(player.getName()).OwnsUnknownPackage(_packageName);
return !_donationManager.Get(player.getName()).OwnsUnknownPackage(_packageName);
}
protected String getPackageName()