2014-10-23 05:05:35 +02:00
|
|
|
package nautilus.game.arcade.managers;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import mineplex.core.common.util.UtilBlock;
|
2015-04-03 11:31:23 +02:00
|
|
|
import mineplex.core.common.util.UtilEvent;
|
|
|
|
import mineplex.core.common.util.UtilEvent.ActionType;
|
2014-10-23 05:05:35 +02:00
|
|
|
import mineplex.core.common.util.UtilMath;
|
|
|
|
import mineplex.core.common.util.UtilParticle;
|
2015-04-03 11:31:23 +02:00
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
2014-10-23 05:05:35 +02:00
|
|
|
import mineplex.core.common.util.UtilServer;
|
|
|
|
import mineplex.core.common.util.UtilParticle.ParticleType;
|
2015-05-03 23:37:00 +02:00
|
|
|
import mineplex.core.common.util.UtilParticle.ViewDist;
|
2014-10-23 05:05:35 +02:00
|
|
|
import mineplex.core.common.util.UtilTime;
|
|
|
|
import mineplex.core.common.util.UtilWorld;
|
2015-04-03 11:31:23 +02:00
|
|
|
import mineplex.core.itemstack.ItemStackFactory;
|
2015-10-10 09:23:37 +02:00
|
|
|
import mineplex.core.titangiveaway.TitanGiveawayAnimation;
|
2015-10-10 04:14:10 +02:00
|
|
|
import mineplex.core.titangiveaway.TitanGiveawayManager;
|
2014-10-23 05:05:35 +02:00
|
|
|
import mineplex.core.updater.UpdateType;
|
|
|
|
import mineplex.core.updater.event.UpdateEvent;
|
|
|
|
import nautilus.game.arcade.ArcadeManager;
|
|
|
|
import nautilus.game.arcade.events.GameStateChangeEvent;
|
|
|
|
import nautilus.game.arcade.game.Game;
|
|
|
|
import nautilus.game.arcade.game.Game.GameState;
|
2015-10-13 08:49:15 +02:00
|
|
|
import net.minecraft.server.v1_8_R3.BlockPosition;
|
|
|
|
import net.minecraft.server.v1_8_R3.PacketPlayOutBlockAction;
|
|
|
|
import net.minecraft.server.v1_8_R3.TileEntity;
|
|
|
|
import net.minecraft.server.v1_8_R3.TileEntityEnderChest;
|
2014-10-23 05:05:35 +02:00
|
|
|
|
|
|
|
import org.bukkit.Effect;
|
2015-10-10 09:23:37 +02:00
|
|
|
import org.bukkit.Location;
|
2014-10-23 05:05:35 +02:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.Sound;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.BlockFace;
|
2015-10-13 08:49:15 +02:00
|
|
|
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
|
|
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
|
|
|
import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers;
|
2014-10-23 05:05:35 +02:00
|
|
|
import org.bukkit.entity.Item;
|
2015-04-03 11:31:23 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2014-10-23 05:05:35 +02:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.block.BlockDamageEvent;
|
2015-10-11 05:48:02 +02:00
|
|
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
2015-04-03 11:31:23 +02:00
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
2014-10-23 05:05:35 +02:00
|
|
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
2015-04-01 07:56:13 +02:00
|
|
|
public class HolidayManager implements Listener
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
2015-04-03 11:31:23 +02:00
|
|
|
public enum HolidayType
|
|
|
|
{
|
2015-12-07 03:42:59 +01:00
|
|
|
Christmas(Material.CHEST, "Present", Sound.CAT_MEOW),
|
2015-04-03 11:31:23 +02:00
|
|
|
Halloween(Material.PUMPKIN, "Pumpkin", Sound.ZOMBIE_REMEDY),
|
|
|
|
Easter(Material.CHEST, "Egg Basket", Sound.CAT_MEOW);
|
|
|
|
|
|
|
|
private Material _blockType;
|
|
|
|
private String _blockName;
|
|
|
|
private Sound _blockBreakSound;
|
|
|
|
|
|
|
|
HolidayType(Material blockType, String blockName, Sound blockBreakSound)
|
|
|
|
{
|
|
|
|
_blockType = blockType;
|
|
|
|
_blockName = blockName;
|
|
|
|
_blockBreakSound = blockBreakSound;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getBlockName()
|
|
|
|
{
|
|
|
|
return _blockName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Sound getBlockSound()
|
|
|
|
{
|
|
|
|
return _blockBreakSound;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Material getBlockType()
|
|
|
|
{
|
|
|
|
return _blockType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-07 03:25:32 +01:00
|
|
|
private HolidayType type = HolidayType.Christmas;
|
|
|
|
private String _statName = "Christmas Presents 2015";
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
ArcadeManager Manager;
|
2015-10-10 04:14:10 +02:00
|
|
|
private TitanGiveawayManager _titanManager;
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
public HashSet<Block> _active = new HashSet<Block>();
|
2015-04-03 11:31:23 +02:00
|
|
|
|
|
|
|
private HashSet<Item> _eggs = new HashSet<Item>();
|
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
private HashSet<Item> _coins = new HashSet<Item>();
|
2015-10-10 09:23:37 +02:00
|
|
|
private HashSet<Item> _gems = new HashSet<Item>();
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
public long _lastSpawn = System.currentTimeMillis();
|
|
|
|
|
2015-10-10 04:14:10 +02:00
|
|
|
public HolidayManager(ArcadeManager manager, TitanGiveawayManager titanManager)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
|
|
|
Manager = manager;
|
2015-10-10 04:14:10 +02:00
|
|
|
_titanManager = titanManager;
|
2014-10-23 05:05:35 +02:00
|
|
|
|
2015-02-26 06:07:07 +01:00
|
|
|
Manager.getPluginManager().registerEvents(this, Manager.getPlugin());
|
2014-10-23 05:05:35 +02:00
|
|
|
}
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
@EventHandler
|
|
|
|
public void reset(GameStateChangeEvent event)
|
|
|
|
{
|
|
|
|
_active.clear();
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
_lastSpawn = System.currentTimeMillis();
|
|
|
|
}
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
@EventHandler
|
2015-04-03 11:31:23 +02:00
|
|
|
public void blockEffect(UpdateEvent event)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
|
|
|
if (event.getType() == UpdateType.TICK)
|
|
|
|
return;
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2015-04-01 07:56:13 +02:00
|
|
|
Iterator<Block> blockIterator = _active.iterator();
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2015-04-01 07:56:13 +02:00
|
|
|
while (blockIterator.hasNext())
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
2015-04-01 07:56:13 +02:00
|
|
|
Block block = blockIterator.next();
|
2015-04-03 11:31:23 +02:00
|
|
|
|
|
|
|
//Break
|
|
|
|
if (block.getType() != Material.PUMPKIN &&
|
|
|
|
block.getType() != Material.JACK_O_LANTERN &&
|
|
|
|
block.getType() != Material.CHEST)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
2015-10-10 04:14:10 +02:00
|
|
|
specialBlockBreak(null, block);
|
2015-04-01 07:56:13 +02:00
|
|
|
blockIterator.remove();
|
2014-10-23 05:05:35 +02:00
|
|
|
continue;
|
|
|
|
}
|
2015-04-03 11:31:23 +02:00
|
|
|
|
|
|
|
if (type == HolidayType.Halloween)
|
|
|
|
{
|
2015-05-03 23:37:00 +02:00
|
|
|
UtilParticle.PlayParticle(ParticleType.FLAME, block.getLocation().add(0.5, 0.5, 0.5), 0, 0, 0, 0.06f, 4,
|
|
|
|
ViewDist.LONG, UtilServer.getPlayers());
|
2015-04-03 11:31:23 +02:00
|
|
|
if (Math.random() > 0.90)
|
|
|
|
{
|
|
|
|
if (block.getType() == Material.PUMPKIN)
|
|
|
|
{
|
|
|
|
block.setType(Material.JACK_O_LANTERN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
block.setType(Material.PUMPKIN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == HolidayType.Easter)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
2015-05-03 23:37:00 +02:00
|
|
|
UtilParticle.PlayParticle(ParticleType.HAPPY_VILLAGER, block.getLocation().add(0.5, 0.2, 0.5), 0.3f, 0.2f, 0.3f, 0, 1,
|
|
|
|
ViewDist.LONG, UtilServer.getPlayers());
|
2015-10-11 05:48:02 +02:00
|
|
|
|
2015-04-03 11:31:23 +02:00
|
|
|
if (Math.random() > 0.90)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
2015-04-03 11:31:23 +02:00
|
|
|
Item egg = block.getWorld().dropItem(block.getLocation().add(0.5, 0.8, 0.5),
|
|
|
|
ItemStackFactory.Instance.CreateStack(Material.EGG, (byte)0, 1, System.currentTimeMillis() + "Egg"));
|
|
|
|
egg.setVelocity(new Vector((Math.random()-0.5)*0.3, Math.random()-0.4, (Math.random()-0.5)*0.3));
|
|
|
|
|
|
|
|
_eggs.add(egg);
|
|
|
|
|
|
|
|
block.getWorld().playSound(block.getLocation(), Sound.CHICKEN_EGG_POP, 0.25f + (float)Math.random() * 0.75f, 0.75f + (float)Math.random() * 0.5f);
|
2014-10-23 05:05:35 +02:00
|
|
|
}
|
2015-10-11 05:48:02 +02:00
|
|
|
|
2015-04-03 11:31:23 +02:00
|
|
|
if (Math.random() > 0.95)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
2015-04-03 11:31:23 +02:00
|
|
|
sendChestPackets(block);
|
2014-10-23 05:05:35 +02:00
|
|
|
}
|
|
|
|
}
|
2015-12-07 03:25:32 +01:00
|
|
|
else if (type == HolidayType.Christmas)
|
|
|
|
{
|
2015-12-07 03:42:59 +01:00
|
|
|
UtilParticle.PlayParticle(ParticleType.SNOW_SHOVEL, block.getLocation().add(0.5, 1, 0.5), 0.5f, 0.5f, 0.5f, 0, 3,
|
2015-12-07 03:25:32 +01:00
|
|
|
ViewDist.LONG, UtilServer.getPlayers());
|
|
|
|
}
|
2014-10-23 05:05:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
2015-04-03 11:31:23 +02:00
|
|
|
public void spawnSpecialBlockUpdate(UpdateEvent event)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
|
|
|
if (event.getType() != UpdateType.SEC)
|
|
|
|
return;
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
if (Manager.GetGame() == null)
|
|
|
|
return;
|
2014-10-24 10:05:57 +02:00
|
|
|
|
2015-10-10 13:47:19 +02:00
|
|
|
if (Manager.GetGameHostManager().isPrivateServer())
|
|
|
|
return;
|
2015-10-11 05:48:02 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
Game game = Manager.GetGame();
|
2014-10-24 10:05:57 +02:00
|
|
|
|
2015-04-03 11:31:23 +02:00
|
|
|
int requirement = (int)((double)Manager.GetPlayerFull() * 0.5d);
|
2014-10-24 10:05:57 +02:00
|
|
|
if (UtilServer.getPlayers().length < requirement)
|
|
|
|
return;
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
if (game.GetState() != GameState.Live)
|
|
|
|
return;
|
2014-10-24 10:05:57 +02:00
|
|
|
|
2015-04-03 11:31:23 +02:00
|
|
|
if (!UtilTime.elapsed(_lastSpawn, 90000))
|
2014-10-23 05:05:35 +02:00
|
|
|
return;
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-24 10:05:57 +02:00
|
|
|
if (Math.random() > 0.01)
|
2014-10-23 05:05:35 +02:00
|
|
|
return;
|
2014-10-24 10:05:57 +02:00
|
|
|
|
|
|
|
int toDrop = Math.max(1, game.GetPlayers(false).size()/6);
|
|
|
|
for (int i=0 ; i< toDrop ; i++)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
|
|
|
double interval = 1 / (double)(toDrop);
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
if (Math.random() >= (i * interval)) // Diminishing per growth
|
|
|
|
{
|
2015-04-03 11:31:23 +02:00
|
|
|
spawnSpecialBlock(findSpecialBlockLocation(game));
|
2014-10-23 05:05:35 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
_lastSpawn = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
|
2015-04-03 11:31:23 +02:00
|
|
|
private void spawnSpecialBlock(Block block)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
|
|
|
if (block == null)
|
2014-10-24 10:05:57 +02:00
|
|
|
{
|
2015-04-03 11:31:23 +02:00
|
|
|
System.out.println("Holiday Block: Could Not Find Suitable Block");
|
2014-10-23 05:05:35 +02:00
|
|
|
return;
|
2014-10-24 10:05:57 +02:00
|
|
|
}
|
2015-04-03 11:31:23 +02:00
|
|
|
|
|
|
|
block.setType(type.getBlockType());
|
|
|
|
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, type.getBlockType());
|
|
|
|
|
|
|
|
if (type.getBlockType() == Material.CHEST)
|
|
|
|
{
|
|
|
|
sendChestPackets(block);
|
|
|
|
}
|
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
_active.add(block);
|
2015-04-03 11:31:23 +02:00
|
|
|
|
|
|
|
System.out.println("Spawned Holiday Block: " + UtilWorld.locToStrClean(block.getLocation()));
|
2014-10-23 05:05:35 +02:00
|
|
|
}
|
2015-04-03 11:31:23 +02:00
|
|
|
|
|
|
|
private void sendChestPackets(Block block)
|
|
|
|
{
|
2015-10-13 08:49:15 +02:00
|
|
|
PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction(new BlockPosition(block.getX(), block.getY(), block.getZ()),
|
2015-04-03 11:31:23 +02:00
|
|
|
CraftMagicNumbers.getBlock(block), 1, 1);
|
|
|
|
|
|
|
|
for (Player other : UtilServer.getPlayers())
|
2015-10-30 07:12:04 +01:00
|
|
|
UtilPlayer.sendPacket(other, packet);
|
2015-04-03 11:31:23 +02:00
|
|
|
}
|
2015-10-11 05:48:02 +02:00
|
|
|
|
2015-04-03 11:31:23 +02:00
|
|
|
private Block findSpecialBlockLocation(Game game)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
|
|
|
Block block = null;
|
2014-10-24 10:05:57 +02:00
|
|
|
int attempts = 2000;
|
2014-10-23 05:05:35 +02:00
|
|
|
while (attempts > 0)
|
|
|
|
{
|
|
|
|
attempts--;
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
int x = game.WorldData.MinX + UtilMath.r(Math.abs(game.WorldData.MaxX - game.WorldData.MinX));
|
|
|
|
int z = game.WorldData.MinZ + UtilMath.r(Math.abs(game.WorldData.MaxZ - game.WorldData.MinZ));
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
block = UtilBlock.getHighest(game.WorldData.World, x, z, null);
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
if (block.getLocation().getY() <= 2 || block.getLocation().getY() < game.WorldData.MinY || block.getLocation().getY() > game.WorldData.MaxY)
|
|
|
|
continue;
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
if (block.getRelative(BlockFace.DOWN).isLiquid())
|
|
|
|
continue;
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
if (!UtilBlock.airFoliage(block) || !UtilBlock.airFoliage(block.getRelative(BlockFace.UP)))
|
|
|
|
continue;
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
if (!UtilBlock.solid(block.getRelative(BlockFace.DOWN)))
|
|
|
|
continue;
|
2015-04-03 11:31:23 +02:00
|
|
|
|
|
|
|
boolean nextToChest = false;
|
|
|
|
for (Block other : UtilBlock.getSurrounding(block, false))
|
|
|
|
{
|
|
|
|
if (other.getType() == Material.CHEST)
|
|
|
|
nextToChest = true;
|
|
|
|
}
|
|
|
|
if (nextToChest)
|
|
|
|
continue;
|
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2015-10-11 05:48:02 +02:00
|
|
|
}
|
2015-04-03 11:31:23 +02:00
|
|
|
|
|
|
|
@EventHandler
|
2015-12-07 11:53:34 +01:00
|
|
|
public void specialBlockDamage(PlayerInteractEvent event)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
2015-12-07 11:53:34 +01:00
|
|
|
if (!UtilEvent.isAction(event, ActionType.L_BLOCK))
|
|
|
|
return;
|
|
|
|
|
2015-04-03 11:31:23 +02:00
|
|
|
if (UtilPlayer.isSpectator(event.getPlayer()))
|
|
|
|
return;
|
2015-10-11 05:48:02 +02:00
|
|
|
|
2015-10-10 01:35:48 +02:00
|
|
|
if (Manager.GetGame() != null && !Manager.GetGame().IsAlive(event.getPlayer()))
|
|
|
|
return;
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2015-12-07 11:53:34 +01:00
|
|
|
if (!_active.contains(event.getClickedBlock()))
|
2015-04-03 11:31:23 +02:00
|
|
|
return;
|
2015-10-11 05:48:02 +02:00
|
|
|
|
2015-12-07 11:53:34 +01:00
|
|
|
specialBlockBreak(event.getPlayer(), event.getClickedBlock());
|
2015-04-03 11:31:23 +02:00
|
|
|
}
|
|
|
|
|
2015-10-10 09:23:37 +02:00
|
|
|
private void specialBlockBreak(Player player, final Block block)
|
2015-04-03 11:31:23 +02:00
|
|
|
{
|
|
|
|
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, type.getBlockType());
|
|
|
|
block.setType(Material.AIR);
|
|
|
|
|
2015-10-11 05:48:02 +02:00
|
|
|
if (player != null && Manager.GetGame() != null)
|
|
|
|
{
|
|
|
|
Manager.GetGame().AddStat(player, _statName, 1, false, true);
|
|
|
|
System.out.println("Recording Pumpkin Break for " + player.getName());
|
|
|
|
}
|
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
//Coins
|
2015-10-10 09:23:37 +02:00
|
|
|
for (int i=0 ; i < 4 + Math.random()*8 ; i++)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
2015-04-03 11:31:23 +02:00
|
|
|
Item coin = block.getWorld().dropItem(block.getLocation().add(0.5, 1, 0.5),
|
|
|
|
ItemStackFactory.Instance.CreateStack(175, (byte)0, 1, UtilMath.r(999999) + "Coin"));
|
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
Vector vel = new Vector(
|
|
|
|
(Math.random() - 0.5) * 0.5,
|
|
|
|
0.1 + Math.random() * 0.3,
|
|
|
|
(Math.random() - 0.5) * 0.5);
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
coin.setVelocity(vel);
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
coin.setPickupDelay(20);
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
_coins.add(coin);
|
|
|
|
}
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2015-10-10 09:23:37 +02:00
|
|
|
//Gems
|
2015-10-11 02:26:09 +02:00
|
|
|
for (int i=0 ; i < 4 + Math.random()*8 ; i++)
|
2015-10-10 09:23:37 +02:00
|
|
|
{
|
|
|
|
Item gem = block.getWorld().dropItem(block.getLocation().add(0.5, 1, 0.5),
|
|
|
|
ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte)0, 1, UtilMath.r(999999) + "Gem"));
|
|
|
|
|
|
|
|
Vector vel = new Vector(
|
|
|
|
(Math.random() - 0.5) * 0.5,
|
|
|
|
0.1 + Math.random() * 0.3,
|
|
|
|
(Math.random() - 0.5) * 0.5);
|
|
|
|
|
|
|
|
gem.setVelocity(vel);
|
|
|
|
|
|
|
|
gem.setPickupDelay(20);
|
|
|
|
|
|
|
|
_gems.add(gem);
|
|
|
|
}
|
|
|
|
|
2015-10-10 04:14:10 +02:00
|
|
|
// Titan Giveaway
|
|
|
|
if (player != null)
|
|
|
|
{
|
|
|
|
_titanManager.openPumpkin(player, new Runnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
2015-10-10 09:23:37 +02:00
|
|
|
Location location = block.getLocation().add(0.5, 0.5, 0.5);
|
|
|
|
new TitanGiveawayAnimation(_titanManager, location, 3000L);
|
2015-10-10 04:14:10 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
//Effect
|
2015-04-03 11:31:23 +02:00
|
|
|
block.getWorld().playSound(block.getLocation(), type.getBlockSound(), 1f, 1f);
|
2014-10-23 05:05:35 +02:00
|
|
|
}
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
@EventHandler
|
|
|
|
public void coinPickup(PlayerPickupItemEvent event)
|
|
|
|
{
|
2015-04-04 01:54:03 +02:00
|
|
|
if (UtilPlayer.isSpectator(event.getPlayer()))
|
|
|
|
return;
|
2015-10-11 05:48:02 +02:00
|
|
|
|
2015-04-03 11:31:23 +02:00
|
|
|
if (_coins.contains(event.getItem()))
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
event.getItem().remove();
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2015-10-11 03:54:35 +02:00
|
|
|
Manager.GetDonation().RewardCoinsLater(type + " Coins", event.getPlayer(), 4 * event.getItem().getItemStack().getAmount());
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ORB_PICKUP, 1f, 2f);
|
|
|
|
}
|
2015-10-10 09:23:37 +02:00
|
|
|
else if (_gems.contains(event.getItem()))
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
event.getItem().remove();
|
|
|
|
|
2015-10-11 03:54:35 +02:00
|
|
|
Manager.GetDonation().RewardGemsLater(type + " Gems", event.getPlayer(), 4 * event.getItem().getItemStack().getAmount());
|
2015-10-10 09:23:37 +02:00
|
|
|
|
|
|
|
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ORB_PICKUP, 1f, 2f);
|
|
|
|
}
|
2015-04-03 11:31:23 +02:00
|
|
|
|
|
|
|
else if (_eggs.contains(event.getItem()))
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2014-10-23 05:05:35 +02:00
|
|
|
}
|
2015-10-11 05:48:02 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
@EventHandler
|
2015-04-03 11:31:23 +02:00
|
|
|
public void itemClean(UpdateEvent event)
|
2014-10-23 05:05:35 +02:00
|
|
|
{
|
|
|
|
if (event.getType() != UpdateType.FAST)
|
|
|
|
return;
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
Iterator<Item> coinIterator = _coins.iterator();
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
while (coinIterator.hasNext())
|
|
|
|
{
|
|
|
|
Item coin = coinIterator.next();
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2014-10-23 05:05:35 +02:00
|
|
|
if (!coin.isValid() || coin.getTicksLived() > 1200)
|
|
|
|
{
|
|
|
|
coin.remove();
|
|
|
|
coinIterator.remove();
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 11:31:23 +02:00
|
|
|
|
2015-10-10 09:23:37 +02:00
|
|
|
Iterator<Item> gemIterator = _gems.iterator();
|
|
|
|
|
|
|
|
while (gemIterator.hasNext())
|
|
|
|
{
|
|
|
|
Item gem = gemIterator.next();
|
|
|
|
|
|
|
|
if (!gem.isValid() || gem.getTicksLived() > 1200)
|
|
|
|
{
|
|
|
|
gem.remove();
|
|
|
|
gemIterator.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 11:31:23 +02:00
|
|
|
Iterator<Item> eggIterator = _eggs.iterator();
|
|
|
|
|
|
|
|
while (eggIterator.hasNext())
|
|
|
|
{
|
|
|
|
Item egg = eggIterator.next();
|
|
|
|
|
|
|
|
if (!egg.isValid() || egg.getTicksLived() > 40)
|
|
|
|
{
|
|
|
|
egg.remove();
|
|
|
|
eggIterator.remove();
|
|
|
|
}
|
|
|
|
}
|
2014-10-23 05:05:35 +02:00
|
|
|
}
|
2015-10-11 05:48:02 +02:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void spawnDebug(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
|
|
|
if (event.getPlayer().isOp() && event.getPlayer().getName().equals("Chiss") && event.getMessage().contains("pumpkin"))
|
|
|
|
{
|
|
|
|
spawnSpecialBlock(event.getPlayer().getLocation().getBlock());
|
|
|
|
}
|
|
|
|
}
|
2014-10-23 05:05:35 +02:00
|
|
|
}
|