115 lines
3.8 KiB
Java
115 lines
3.8 KiB
Java
package pw.yumc.RocketJump;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.bukkit.Effect;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
import org.bukkit.event.player.PlayerMoveEvent;
|
|
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
|
|
|
/**
|
|
* Created by a08381 on 15-3-28.
|
|
*/
|
|
public class RocketJumpListen implements Listener {
|
|
List<String> fall = new ArrayList<String>();
|
|
List<String> efc = new ArrayList<String>();
|
|
int trng;
|
|
|
|
public void add(final String p) {
|
|
if (!fall.contains(p)) {
|
|
fall.add(p);
|
|
}
|
|
}
|
|
|
|
public void efcadd(final String p) {
|
|
if (!efc.contains(p)) {
|
|
efc.add(p);
|
|
}
|
|
}
|
|
|
|
@EventHandler(ignoreCancelled = true)
|
|
public void MoveEvent(final PlayerMoveEvent e) {
|
|
final Player p = e.getPlayer();
|
|
if (efc.contains(p.getName())) {
|
|
trng -= 1;
|
|
pEffect(p.getLocation(), trng);
|
|
}
|
|
if (p.getLocation().add(0, -1, 0).getBlock().getType() != (Material.AIR)) {
|
|
if (RocketJump.Dante.contains(p.getName())) {
|
|
p.setAllowFlight(true);
|
|
if (fall.contains(p.getName())) {
|
|
fall.remove(p.getName());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onFallDamage(final EntityDamageEvent e) {
|
|
if (e.getEntity() instanceof Player) {
|
|
final Player p = (Player) e.getEntity();
|
|
if (e.getCause() == DamageCause.FALL) {
|
|
if (fall.contains(p.getName())) {
|
|
fall.remove(p.getName());
|
|
e.setCancelled(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@EventHandler(ignoreCancelled = true)
|
|
public void ToggleFlightEvent(final PlayerToggleFlightEvent e) {
|
|
final Player p = e.getPlayer();
|
|
if (RocketJump.Dante.contains(p.getName())) {
|
|
if (p.getLocation().add(0, -1, 0).getBlock().getType() == (Material.AIR) && p.getLocation().add(0, -2, 0).getBlock().getType() == (Material.AIR)) {
|
|
e.setCancelled(true);
|
|
return;
|
|
}
|
|
if (!p.isFlying()) {
|
|
e.setCancelled(true);
|
|
pEffect(p.getLocation(), 80);
|
|
p.setVelocity(p.getVelocity().setY(1));
|
|
p.setAllowFlight(false);
|
|
RocketJump.instence.getServer().getScheduler().runTaskLaterAsynchronously(RocketJump.instence, new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
if (p.isOnline()) {
|
|
p.setVelocity(p.getVelocity().setY(10));
|
|
final String name = p.getName();
|
|
efcadd(name);
|
|
add(name);
|
|
RocketJump.instence.getServer().getScheduler().runTaskLaterAsynchronously(RocketJump.instence, new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
if (efc.contains(name)) {
|
|
efc.remove(name);
|
|
}
|
|
}
|
|
}, 30);
|
|
}
|
|
}
|
|
}, 10);
|
|
trng = 30;
|
|
}
|
|
}
|
|
}
|
|
|
|
void pEffect(final Location loc, int range) {
|
|
int i;
|
|
if (range < 2) {
|
|
range = 2;
|
|
}
|
|
for (i = 0; i < range; i++) {
|
|
loc.getWorld().playEffect(loc, Effect.LAVA_POP, 10, 100);
|
|
loc.getWorld().playEffect(loc, Effect.PORTAL, 10, 100);
|
|
}
|
|
}
|
|
}
|