2013-08-29 08:13:05 +02:00
|
|
|
package nautilus.game.arcade.kit.perks;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
import mineplex.core.common.util.C;
|
2013-09-01 04:18:48 +02:00
|
|
|
import mineplex.core.common.util.F;
|
2013-08-29 08:13:05 +02:00
|
|
|
import mineplex.core.common.util.UtilAction;
|
|
|
|
import mineplex.core.common.util.UtilBlock;
|
|
|
|
import mineplex.core.common.util.UtilEnt;
|
|
|
|
import mineplex.core.common.util.UtilEvent;
|
|
|
|
import mineplex.core.common.util.UtilGear;
|
2013-09-01 04:18:48 +02:00
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
2013-08-29 08:13:05 +02:00
|
|
|
import mineplex.core.common.util.UtilServer;
|
|
|
|
import mineplex.core.common.util.UtilEvent.ActionType;
|
|
|
|
import mineplex.core.projectile.IThrown;
|
|
|
|
import mineplex.core.projectile.ProjectileUser;
|
|
|
|
import mineplex.core.updater.UpdateType;
|
|
|
|
import mineplex.core.updater.event.UpdateEvent;
|
|
|
|
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
2015-01-29 01:54:59 +01:00
|
|
|
import nautilus.game.arcade.kit.SmashPerk;
|
2013-09-02 06:40:06 +02:00
|
|
|
import nautilus.game.arcade.kit.perks.data.BlockTossData;
|
2013-08-29 08:13:05 +02:00
|
|
|
import nautilus.game.arcade.kit.perks.event.PerkBlockGrabEvent;
|
|
|
|
import nautilus.game.arcade.kit.perks.event.PerkBlockThrowEvent;
|
|
|
|
|
|
|
|
import org.bukkit.Effect;
|
|
|
|
import org.bukkit.block.Block;
|
2013-09-01 04:18:48 +02:00
|
|
|
import org.bukkit.block.BlockFace;
|
2013-08-29 08:13:05 +02:00
|
|
|
import org.bukkit.entity.FallingBlock;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
public class PerkBlockToss extends SmashPerk implements IThrown
|
2013-08-29 08:13:05 +02:00
|
|
|
{
|
2013-09-02 06:40:06 +02:00
|
|
|
private HashMap<Player, BlockTossData> _hold = new HashMap<Player, BlockTossData>();
|
2013-08-29 08:13:05 +02:00
|
|
|
private HashMap<Player, Long> _charge = new HashMap<Player, Long>();
|
|
|
|
private HashSet<Player> _charged = new HashSet<Player>();
|
|
|
|
private HashMap<FallingBlock, Player> _falling = new HashMap<FallingBlock, Player>();
|
|
|
|
|
|
|
|
public PerkBlockToss()
|
|
|
|
{
|
|
|
|
super("Block Toss", new String[]
|
|
|
|
{
|
|
|
|
C.cYellow + "Hold Block" + C.cGray + " to " + C.cGreen + "Grab Block",
|
|
|
|
C.cYellow + "Release Block" + C.cGray + " to " + C.cGreen + "Throw Block"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Grab(PlayerInteractEvent event)
|
|
|
|
{
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
if (!UtilEvent.isAction(event, ActionType.R_BLOCK))
|
|
|
|
return;
|
2015-01-29 01:54:59 +01:00
|
|
|
|
|
|
|
if (isSuperActive(player))
|
|
|
|
return;
|
2013-08-29 08:13:05 +02:00
|
|
|
|
|
|
|
if (!Kit.HasKit(player))
|
|
|
|
return;
|
2013-09-01 04:18:48 +02:00
|
|
|
|
2013-08-29 08:13:05 +02:00
|
|
|
if (!UtilGear.isSword(player.getItemInHand()))
|
|
|
|
return;
|
|
|
|
|
2013-09-02 06:40:06 +02:00
|
|
|
if (_hold.containsKey(player))
|
2013-08-29 08:13:05 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
Block grab = event.getClickedBlock();
|
|
|
|
|
|
|
|
if (UtilBlock.usable(grab))
|
|
|
|
return;
|
|
|
|
|
2013-09-01 04:18:48 +02:00
|
|
|
if (!UtilBlock.airFoliage(grab.getRelative(BlockFace.UP)) || Manager.GetBlockRestore().Contains(grab.getRelative(BlockFace.UP)))
|
|
|
|
{
|
|
|
|
UtilPlayer.message(player, F.main("Game", "You can only pick up blocks with Air above them."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-29 08:13:05 +02:00
|
|
|
//Event
|
|
|
|
PerkBlockGrabEvent blockEvent = new PerkBlockGrabEvent(player, grab.getTypeId(), grab.getData());
|
|
|
|
UtilServer.getServer().getPluginManager().callEvent(blockEvent);
|
2013-09-01 04:18:48 +02:00
|
|
|
|
2013-09-02 06:40:06 +02:00
|
|
|
//Block to Data
|
|
|
|
int id = grab.getTypeId();
|
|
|
|
byte data = grab.getData();
|
|
|
|
|
|
|
|
//Remove Block
|
2013-08-29 08:13:05 +02:00
|
|
|
Manager.GetBlockRestore().Add(event.getClickedBlock(), 0, (byte)0, 10000);
|
2013-09-02 06:40:06 +02:00
|
|
|
|
|
|
|
_hold.put(player, new BlockTossData(id, data));
|
|
|
|
|
2013-08-29 08:13:05 +02:00
|
|
|
_charge.put(player, System.currentTimeMillis());
|
|
|
|
|
|
|
|
//Effect
|
2013-09-02 06:40:06 +02:00
|
|
|
player.getWorld().playEffect(event.getClickedBlock().getLocation(), Effect.STEP_SOUND, id);
|
2013-08-29 08:13:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Throw(UpdateEvent event)
|
|
|
|
{
|
|
|
|
if (event.getType() != UpdateType.TICK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
HashSet<Player> throwSet = new HashSet<Player>();
|
|
|
|
|
2013-09-02 06:40:06 +02:00
|
|
|
for (Player cur : _hold.keySet())
|
2013-08-29 08:13:05 +02:00
|
|
|
{
|
|
|
|
//Throw
|
|
|
|
if (!cur.isBlocking())
|
|
|
|
throwSet.add(cur);
|
|
|
|
|
|
|
|
//Charged Tick
|
|
|
|
if (!_charged.contains(cur))
|
2015-01-29 01:54:59 +01:00
|
|
|
if (System.currentTimeMillis() - _charge.get(cur) > 1200)
|
2013-08-29 08:13:05 +02:00
|
|
|
{
|
|
|
|
_charged.add(cur);
|
|
|
|
cur.playEffect(cur.getLocation(), Effect.CLICK1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Player cur : throwSet)
|
|
|
|
{
|
2013-09-02 06:40:06 +02:00
|
|
|
BlockTossData data = _hold.remove(cur);
|
|
|
|
|
|
|
|
FallingBlock block = cur.getWorld().spawnFallingBlock(cur.getEyeLocation().add(cur.getLocation().getDirection()), data.Type, data.Data);
|
|
|
|
|
|
|
|
_falling.put(block, cur);
|
|
|
|
|
2013-08-29 08:13:05 +02:00
|
|
|
_charged.remove(cur);
|
2013-09-02 06:40:06 +02:00
|
|
|
|
2013-08-29 08:13:05 +02:00
|
|
|
long charge = System.currentTimeMillis() - _charge.remove(cur);
|
|
|
|
|
|
|
|
//Throw
|
2014-01-18 02:34:24 +01:00
|
|
|
double mult = 1.4;
|
2015-01-29 01:54:59 +01:00
|
|
|
if (charge < 1200)
|
|
|
|
mult = mult * ((double)charge/1200d);
|
2014-01-18 02:34:24 +01:00
|
|
|
|
2013-08-29 08:13:05 +02:00
|
|
|
//Action
|
2013-09-02 06:40:06 +02:00
|
|
|
UtilAction.velocity(block, cur.getLocation().getDirection(), mult, false, 0.2, 0, 1, true);
|
2013-08-29 08:13:05 +02:00
|
|
|
Manager.GetProjectile().AddThrow(block, cur, this, -1, true, true, true,
|
|
|
|
null, 0, 0, null, 0, UpdateType.FASTEST, 2d);
|
2013-09-01 04:18:48 +02:00
|
|
|
|
2013-08-29 08:13:05 +02:00
|
|
|
//Event
|
|
|
|
PerkBlockThrowEvent blockEvent = new PerkBlockThrowEvent(cur);
|
|
|
|
UtilServer.getServer().getPluginManager().callEvent(blockEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void Collide(LivingEntity target, Block block, ProjectileUser data)
|
|
|
|
{
|
|
|
|
if (target == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//Damage Event
|
|
|
|
Manager.GetDamage().NewDamageEvent(target, data.GetThrower(), null,
|
2015-01-29 01:54:59 +01:00
|
|
|
DamageCause.PROJECTILE, data.GetThrown().getVelocity().length() * 10, true, true, false,
|
2013-08-29 08:13:05 +02:00
|
|
|
UtilEnt.getName(data.GetThrower()), GetName());
|
|
|
|
|
|
|
|
//Block to Item
|
|
|
|
if (data.GetThrown() instanceof FallingBlock)
|
|
|
|
{
|
|
|
|
FallingBlock thrown = (FallingBlock) data.GetThrown();
|
|
|
|
|
|
|
|
FallingBlock newThrown = data.GetThrown().getWorld().spawnFallingBlock(data.GetThrown().getLocation(), thrown.getMaterial(), (byte)0);
|
|
|
|
|
|
|
|
//Remove Old
|
|
|
|
_falling.remove(thrown);
|
|
|
|
thrown.remove();
|
|
|
|
|
|
|
|
//Add New
|
|
|
|
if (data.GetThrower() instanceof Player)
|
|
|
|
_falling.put(newThrown, (Player)data.GetThrower());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void Idle(ProjectileUser data)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void Expire(ProjectileUser data)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void BlockForm(EntityChangeBlockEvent event)
|
|
|
|
{
|
|
|
|
if (!(event.getEntity() instanceof FallingBlock))
|
|
|
|
return;
|
|
|
|
|
|
|
|
FallingBlock falling = (FallingBlock)event.getEntity();
|
|
|
|
|
|
|
|
falling.getWorld().playEffect(event.getBlock().getLocation(), Effect.STEP_SOUND, falling.getBlockId());
|
|
|
|
|
|
|
|
_falling.remove(falling);
|
|
|
|
falling.remove();
|
|
|
|
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2013-09-01 04:18:48 +02:00
|
|
|
|
2013-08-29 08:13:05 +02:00
|
|
|
@EventHandler
|
|
|
|
public void Knockback(CustomDamageEvent event)
|
|
|
|
{
|
|
|
|
if (event.GetReason() == null || !event.GetReason().contains(GetName()))
|
|
|
|
return;
|
2013-09-01 04:18:48 +02:00
|
|
|
|
2013-08-29 08:13:05 +02:00
|
|
|
event.AddKnockback(GetName(), 2.5);
|
|
|
|
}
|
|
|
|
}
|