2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.fun;
|
2013-08-13 14:05:37 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
import com.google.common.collect.Maps;
|
2013-08-13 20:54:20 +00:00
|
|
|
import java.util.Map;
|
2015-10-19 17:43:46 +00:00
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
2015-10-19 17:43:46 +00:00
|
|
|
import net.pravian.aero.component.service.AbstractService;
|
2013-08-13 14:05:37 +00:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Player;
|
2015-10-19 17:43:46 +00:00
|
|
|
import org.bukkit.event.EventHandler;
|
2013-08-13 14:05:37 +00:00
|
|
|
import org.bukkit.event.player.PlayerMoveEvent;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Jumppads extends AbstractService<TotalFreedomMod>
|
2013-08-13 14:05:37 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
public static final Material BLOCK_ID = Material.WOOL;
|
|
|
|
public static final double DAMPING_COEFFICIENT = 0.8;
|
|
|
|
//
|
|
|
|
private final Map<Player, Boolean> pushMap = Maps.newHashMap();
|
|
|
|
//
|
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
private JumpPadMode mode = JumpPadMode.MADGEEK;
|
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
private double strength = 0.4;
|
|
|
|
|
|
|
|
public Jumppads(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStart()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2013-08-13 14:05:37 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@Override
|
|
|
|
public void onStop()
|
2014-05-19 17:32:25 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
|
2014-05-19 17:32:25 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@EventHandler
|
|
|
|
public void onPlayerMove(PlayerMoveEvent event)
|
2013-08-13 14:05:37 +00:00
|
|
|
{
|
2013-08-13 18:53:33 +00:00
|
|
|
if (mode == JumpPadMode.OFF)
|
2013-08-13 14:05:37 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-13 18:53:33 +00:00
|
|
|
final Player player = event.getPlayer();
|
|
|
|
final Block block = event.getTo().getBlock();
|
|
|
|
final Vector velocity = player.getVelocity().clone();
|
2013-08-13 14:05:37 +00:00
|
|
|
|
2013-08-13 20:54:20 +00:00
|
|
|
if (mode == JumpPadMode.MADGEEK)
|
2013-08-13 14:05:37 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
Boolean canPush = pushMap.get(player);
|
2013-08-13 20:54:20 +00:00
|
|
|
if (canPush == null)
|
2013-08-13 14:05:37 +00:00
|
|
|
{
|
2013-08-13 20:54:20 +00:00
|
|
|
canPush = true;
|
2013-08-13 14:05:37 +00:00
|
|
|
}
|
2013-08-13 20:54:20 +00:00
|
|
|
if (block.getRelative(0, -1, 0).getType() == BLOCK_ID)
|
2013-08-13 14:05:37 +00:00
|
|
|
{
|
2013-08-13 20:54:20 +00:00
|
|
|
if (canPush)
|
|
|
|
{
|
|
|
|
velocity.multiply(strength + 0.85).multiply(-1.0);
|
|
|
|
}
|
|
|
|
canPush = false;
|
2013-08-13 14:05:37 +00:00
|
|
|
}
|
2013-08-13 20:54:20 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
canPush = true;
|
|
|
|
}
|
2015-10-19 17:43:46 +00:00
|
|
|
pushMap.put(player, canPush);
|
2013-08-13 20:54:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (block.getRelative(0, -1, 0).getType() == BLOCK_ID)
|
2013-08-13 14:05:37 +00:00
|
|
|
{
|
2013-08-13 20:54:20 +00:00
|
|
|
velocity.add(new Vector(0.0, strength, 0.0));
|
2013-08-13 14:05:37 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 20:54:20 +00:00
|
|
|
if (mode == JumpPadMode.NORMAL_AND_SIDEWAYS)
|
2013-08-13 14:05:37 +00:00
|
|
|
{
|
2013-08-13 20:54:20 +00:00
|
|
|
if (block.getRelative(1, 0, 0).getType() == BLOCK_ID)
|
|
|
|
{
|
|
|
|
velocity.add(new Vector(-DAMPING_COEFFICIENT * strength, 0.0, 0.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block.getRelative(-1, 0, 0).getType() == BLOCK_ID)
|
|
|
|
{
|
|
|
|
velocity.add(new Vector(DAMPING_COEFFICIENT * strength, 0.0, 0.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block.getRelative(0, 0, 1).getType() == BLOCK_ID)
|
|
|
|
{
|
|
|
|
velocity.add(new Vector(0.0, 0.0, -DAMPING_COEFFICIENT * strength));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block.getRelative(0, 0, -1).getType() == BLOCK_ID)
|
|
|
|
{
|
|
|
|
velocity.add(new Vector(0.0, 0.0, DAMPING_COEFFICIENT * strength));
|
|
|
|
}
|
2013-08-13 14:05:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-13 18:53:33 +00:00
|
|
|
if (!player.getVelocity().equals(velocity))
|
2013-08-13 14:05:37 +00:00
|
|
|
{
|
2013-08-13 18:53:33 +00:00
|
|
|
player.setFallDistance(0.0f);
|
|
|
|
player.setVelocity(velocity);
|
2013-08-13 14:05:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-13 18:53:33 +00:00
|
|
|
public static enum JumpPadMode
|
2013-08-13 14:05:37 +00:00
|
|
|
{
|
2013-08-13 20:54:20 +00:00
|
|
|
OFF(false), NORMAL(true), NORMAL_AND_SIDEWAYS(true), MADGEEK(true);
|
2015-10-19 17:43:46 +00:00
|
|
|
private final boolean on;
|
2013-08-13 14:05:37 +00:00
|
|
|
|
2014-04-21 17:00:39 +00:00
|
|
|
private JumpPadMode(boolean on)
|
2013-08-13 14:05:37 +00:00
|
|
|
{
|
|
|
|
this.on = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isOn()
|
|
|
|
{
|
|
|
|
return on;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|