185 lines
5.8 KiB
Java
185 lines
5.8 KiB
Java
package eu.univento.lobby.listeners;
|
|
|
|
import eu.univento.commons.player.Rank;
|
|
import eu.univento.core.api.Config;
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import eu.univento.lobby.Lobby;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Effect;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.Sound;
|
|
import org.bukkit.block.Block;
|
|
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.util.Vector;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
/**
|
|
* fun for player
|
|
* @author joethei
|
|
* @version 1.0
|
|
*/
|
|
public class Jumppads implements Listener{
|
|
|
|
/**
|
|
* contains players flying from premium lobby to spawn
|
|
*/
|
|
private ArrayList<CustomPlayer> flySpawn = new ArrayList<>();
|
|
/**
|
|
* contains players flying from spawn to premium lobby
|
|
*/
|
|
private ArrayList<CustomPlayer> flyPremium = new ArrayList<>();
|
|
|
|
/**
|
|
* lets players jump over pads
|
|
* @param e PlayerMoveEvent
|
|
* @throws InterruptedException thread closed
|
|
*/
|
|
@EventHandler
|
|
public void onMove(PlayerMoveEvent e) throws InterruptedException {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
|
|
|
|
Block block = p.getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock();
|
|
|
|
if(p.getLocation().getBlock().getType() == Material.STONE_PLATE) {
|
|
|
|
if(block.getType() == Material.REDSTONE_BLOCK) {
|
|
Vector v = p.getLocation().getDirection().multiply(3D).setY(1D);
|
|
p.setVelocity(v);
|
|
p.playSound(p.getEyeLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F);
|
|
}
|
|
|
|
if(block.getType() == Material.BEDROCK) {
|
|
Vector v = p.getLocation().getDirection().multiply(0D).setY(3D);
|
|
p.setVelocity(v);
|
|
p.playSound(p.getEyeLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F);
|
|
}
|
|
|
|
if(block.getType() == Material.IRON_BLOCK) {
|
|
Vector v = p.getLocation().getDirection().multiply(3D).setY(4D);
|
|
p.setVelocity(v);
|
|
p.playSound(p.getEyeLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F);
|
|
}
|
|
|
|
if(block.getType() == Material.DIAMOND_BLOCK) {
|
|
if(p.getDatabasePlayer().isAllowed(Rank.Premium)) {
|
|
if(!flyPremium.contains(p)) {
|
|
Vector v = p.getLocation().getDirection().multiply(1D).setY(3D);
|
|
p.setVelocity(v);
|
|
p.setHealth(1.0);
|
|
flyPremium.add(p);
|
|
runTimer(p);
|
|
p.playEffect(p.getLocation(), Effect.BLAZE_SHOOT, 10);
|
|
p.playSound(p.getEyeLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1.0F, 1.0F);
|
|
}
|
|
}
|
|
}
|
|
|
|
if(block.getType() == Material.OBSIDIAN) {
|
|
Vector v = p.getLocation().getDirection().multiply(4D).setY(1D);
|
|
p.setVelocity(v);
|
|
p.playSound(p.getEyeLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F);
|
|
}
|
|
|
|
if(block.getType() == Material.WOOL) {
|
|
p.setWalkSpeed(0.2F);
|
|
|
|
Vector v = p.getLocation().getDirection().multiply(1.5D).setY(1D);
|
|
p.setVelocity(v);
|
|
p.playSound(p.getEyeLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F);
|
|
}
|
|
|
|
if(block.getType() == Material.LAPIS_BLOCK) {
|
|
Vector v = p.getLocation().getDirection().multiply(6D).setY(1D);
|
|
p.setVelocity(v);
|
|
p.playSound(p.getEyeLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F);
|
|
}
|
|
|
|
if(block.getType() == Material.EMERALD_BLOCK) {
|
|
if(!flySpawn.contains(p)) {
|
|
Vector v = p.getLocation().getDirection().multiply(3.0D).setY(1.0D);
|
|
p.setVelocity(v);
|
|
flySpawn.add(p);
|
|
p.setHealth(1.0);
|
|
runTimer(p);
|
|
}
|
|
|
|
}
|
|
}
|
|
if(block.getType() == Material.STATIONARY_WATER) {
|
|
if(flySpawn.contains(p)) {
|
|
flySpawn.remove(p);
|
|
teleport("Spawn", p);
|
|
}
|
|
if(flyPremium.contains(p)) {
|
|
flyPremium.remove(p);
|
|
teleport("PremiumHub", p);
|
|
}
|
|
}
|
|
if(block.getType() == Material.SPONGE) {
|
|
Vector v = p.getLocation().getDirection().multiply(0.0D).setY(1.0D);
|
|
Block b = p.getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock();
|
|
p.setVelocity(v);
|
|
p.playSound(p.getEyeLocation(), Sound.ENTITY_PLAYER_SPLASH, 5.0F, 1.0F);
|
|
p.playEffect(p.getEyeLocation(), Effect.BLAZE_SHOOT, 200);
|
|
Block tempBlock = p.getLocation().add(0.0D, 5.0D, 0.0D).getBlock();
|
|
tempBlock.setType(Material.WATER);
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Lobby.getInstance(), () -> tempBlock.setType(Material.AIR), 20L);
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Lobby.getInstance(), () -> {
|
|
b.setType(Material.SPONGE);
|
|
for(Player players : Bukkit.getOnlinePlayers()) {
|
|
players.playSound(b.getLocation(), Sound.BLOCK_PISTON_EXTEND, 5.0F, 1.0F);
|
|
players.playEffect(b.getLocation(), Effect.BOW_FIRE, 200);
|
|
}
|
|
}, 100L);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* cancels fall damage
|
|
* @param e EntityDamageEvent
|
|
*/
|
|
@EventHandler
|
|
public void onDamage(EntityDamageEvent e) {
|
|
if(e.getEntity() instanceof Player) {
|
|
if(e.getCause() == DamageCause.FALL) {
|
|
e.setCancelled(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* teleports player to location
|
|
* @param loc name of location
|
|
* @param p CustomPlayer
|
|
*/
|
|
private void teleport(String loc, CustomPlayer p) {
|
|
p.teleport(Config.readLocation("Lobby.Locs." + loc));
|
|
p.playSound(p.getEyeLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 5.0F, 1.0F);
|
|
p.playEffect(p.getLocation(), Effect.ENDER_SIGNAL, 20);
|
|
p.playEffect(p.getEyeLocation(), Effect.BLAZE_SHOOT, 20);
|
|
p.setHealth(10.0);
|
|
}
|
|
|
|
/**
|
|
* runs cancel timer
|
|
* @param p CustomPlayer
|
|
*/
|
|
private void runTimer(CustomPlayer p) {
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Lobby.getInstance(), () -> {
|
|
if(flyPremium.contains(p)) {
|
|
teleport("PremiumHub", p);
|
|
flyPremium.remove(p);
|
|
}
|
|
if(flySpawn.contains(p)) {
|
|
teleport("Spawn", p);
|
|
flySpawn.remove(p);
|
|
}
|
|
}, 20L * 10);
|
|
}
|
|
} |