258 lines
11 KiB
Java
258 lines
11 KiB
Java
package eu.univento.woolget.listeners;
|
|
|
|
import eu.univento.commons.server.ServerType;
|
|
import eu.univento.core.api.Config;
|
|
import eu.univento.core.api.game.Team;
|
|
import eu.univento.core.api.game.TeamManager;
|
|
import eu.univento.core.api.map.Map;
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import eu.univento.core.api.schematic.Cuboid;
|
|
import eu.univento.woolget.WoolGet;
|
|
import eu.univento.woolget.game.GameStage;
|
|
import eu.univento.woolget.utils.Shop;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.TreeType;
|
|
import org.bukkit.World;
|
|
import org.bukkit.entity.Item;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.entity.Snowball;
|
|
import org.bukkit.entity.Villager;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.block.Action;
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
|
import org.bukkit.event.player.*;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 0.1
|
|
*/
|
|
public class PlayerEvents implements Listener {
|
|
|
|
private static ServerType serverType = ServerType.GAME_WOOLGET;
|
|
private static Team blue;
|
|
private static Team yellow;
|
|
|
|
public static void setTeams() {
|
|
blue =
|
|
yellow = TeamManager.getTeam("yellow");
|
|
}
|
|
|
|
@EventHandler
|
|
public void onDeath(PlayerDeathEvent e) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getEntity());
|
|
if (Shop.mobileShop().contains(p)) Shop.mobileShop().remove(p);
|
|
if (WoolGet.getGameStage() == GameStage.Game) {
|
|
if (p.getKiller() != null) {
|
|
CustomPlayer killer = CustomPlayer.getPlayer(p.getKiller());
|
|
e.setDeathMessage(p.getDisplayName() + " wurde von " + killer.getDisplayName() + " gebasht");
|
|
e.getDrops().clear();
|
|
e.setDroppedExp(0);
|
|
} else {
|
|
e.setDeathMessage(p.getDisplayName() + " ist nun tot");
|
|
}
|
|
} else {
|
|
e.setDeathMessage(null);
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onRespawn(PlayerRespawnEvent e) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
|
if (WoolGet.getGameStage() == GameStage.Game || WoolGet.getGameStage() == GameStage.Warmup) {
|
|
Map map = WoolGet.getVoting().getWinningMap();
|
|
if (blue.isPlayer(p)) {
|
|
Cuboid cb = new Cuboid(Config.readLocation("Strive." + map.getName() + ".Blue.MinPos"), Config.readLocation("Strive." + map.getName() + ".Blue.MaxPos"));
|
|
e.setRespawnLocation(cb.getRandomLocation());
|
|
}
|
|
if (yellow.isPlayer(p)) {
|
|
Cuboid cb = new Cuboid(Config.readLocation("Strive." + map.getName() + ".Yellow.MinPos"), Config.readLocation("Strive." + map.getName() + ".Yellow.MaxPos"));
|
|
e.setRespawnLocation(cb.getRandomLocation());
|
|
}
|
|
} else {
|
|
e.setRespawnLocation(Config.readLocation("Strive.Spawn"));
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onEntityInteract(PlayerInteractEntityEvent e) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
|
if (e.getRightClicked() instanceof Villager) {
|
|
e.setCancelled(true);
|
|
p.openInventory(Shop.getInventory(p));
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onMove(PlayerMoveEvent e) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
|
if (WoolGet.getGameStage() == GameStage.Warmup) {
|
|
Map map = WoolGet.getVoting().getWinningMap();
|
|
if (blue.isPlayer(p)) {
|
|
Cuboid cb = new Cuboid(Config.readLocation("Strive." + map.getName() + ".Blue.MinPos"), Config.readLocation("Strive." + map.getName() + ".Blue.MaxPos"));
|
|
if (!cb.containsLocation(p.getLocation())) {
|
|
p.setVelocity(p.getLocation().getDirection().multiply(-2).setY(0.2F));
|
|
}
|
|
}
|
|
if (yellow.isPlayer(p)) {
|
|
Cuboid cb = new Cuboid(Config.readLocation("Strive." + map.getName() + ".Yellow.MinPos"), Config.readLocation("Strive." + map.getName() + ".Yellow.MaxPos"));
|
|
if (!cb.containsLocation(p.getLocation())) {
|
|
p.setVelocity(p.getLocation().getDirection().multiply(-2).setY(0.2F));
|
|
}
|
|
}
|
|
}
|
|
if(WoolGet.getGameStage() == GameStage.Lobby) {
|
|
if(p.getEyeLocation().getBlock().getType() == Material.WATER || p.getEyeLocation().getBlock().getType() == Material.STATIONARY_WATER) {
|
|
p.teleport(Config.readLocation("Strive.Spawn"));
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
@EventHandler
|
|
public void onRodLand(ProjectileHitEvent e) {
|
|
if (e.getEntityType() == EntityType.FISHING_HOOK) {
|
|
Bukkit.getWorld(e.getEntity().getWorld().getName()).getNearbyEntities(e.getEntity().getLocation(), 2.0, 2.0, 2.0).stream().filter(entity -> entity instanceof Player).forEach(entity -> {
|
|
FishHook hock = (FishHook) e.getEntity();
|
|
Player rodder = (Player) hock.getShooter();
|
|
Player player = (Player) entity;
|
|
player.damage(1.0);
|
|
player.getLocation().add(0.0D, 1.0D, 0.0D);
|
|
player.setVelocity(rodder.getLocation().getDirection().multiply(0.3D));
|
|
e.getEntity().remove();
|
|
});
|
|
}
|
|
}
|
|
*/
|
|
|
|
@EventHandler
|
|
public void onInteract(PlayerInteractEvent e) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
|
if (WoolGet.getGameStage() == GameStage.Game) {
|
|
Map map = WoolGet.getVoting().getWinningMap();
|
|
Cuboid yellow = new Cuboid(Config.readLocation("Strive." + map.getName() + ".Blue.MinPos"), Config.readLocation("Strive." + map.getName() + ".Blue.MaxPos"));
|
|
Cuboid blue = new Cuboid(Config.readLocation("Strive." + map.getName() + ".Blue.MinPos"), Config.readLocation("Strive." + map.getName() + ".Blue.MaxPos"));
|
|
if (e.getAction() == Action.PHYSICAL && e.getClickedBlock().getType() == Material.STONE_PLATE) {
|
|
e.getClickedBlock().getWorld().createExplosion(e.getClickedBlock().getLocation(), 0.0F);
|
|
e.getClickedBlock().setType(Material.AIR);
|
|
p.damage(5.0D);
|
|
}
|
|
if (e.getAction() == Action.PHYSICAL && e.getClickedBlock().getType() == Material.IRON_PLATE) {
|
|
if (PlayerEvents.blue.isPlayer(p)) p.teleport(blue.getRandomLocation());
|
|
if (PlayerEvents.yellow.isPlayer(p)) p.teleport(yellow.getRandomLocation());
|
|
e.getClickedBlock().setType(Material.AIR);
|
|
}
|
|
if (e.getAction() == Action.PHYSICAL && e.getClickedBlock().getType() == Material.WOOD_PLATE) {
|
|
e.getClickedBlock().setType(Material.AIR);
|
|
e.getClickedBlock().getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock().setType(Material.GRASS);
|
|
e.getClickedBlock().getWorld().generateTree(e.getClickedBlock().getLocation(), TreeType.BIRCH);
|
|
}
|
|
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
|
if (p.getItemInHand().getType() == Material.FIREBALL) {
|
|
Item grenade = p.getWorld().dropItem(p.getEyeLocation(), new ItemStack(Material.FIREBALL));
|
|
grenade.setPickupDelay(4);
|
|
grenade.setVelocity(p.getEyeLocation().getDirection().multiply(1.5));
|
|
p.getInventory().remove(p.getItemInHand());
|
|
|
|
new BukkitRunnable() {
|
|
public void run() {
|
|
if (grenade.isOnGround()) {
|
|
grenade.getLocation().getWorld().createExplosion(grenade.getLocation(), 0.0F);
|
|
grenade.getWorld().getLivingEntities().stream().filter(entity -> entity.getLocation().distance(grenade.getLocation()) <= 1.5D).forEach(entity -> {
|
|
entity.damage(2.0D);
|
|
entity.sendMessage("Kabum");
|
|
});
|
|
grenade.remove();
|
|
}
|
|
}
|
|
}.runTaskTimer(WoolGet.getInstance(), 2L, 2L);
|
|
}
|
|
}
|
|
if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) {
|
|
if (p.getItemInHand().getType() == Material.COMPASS) {
|
|
p.sendMessage("Neues Ziel gesetzt.");
|
|
getAreaBlocks(p.getLocation(), 15).stream().filter(loc -> loc.getBlock().getType() == Material.WOOL).forEach(p::setCompassTarget);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onItemPickup(PlayerPickupItemEvent e) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
|
if(WoolGet.getGameStage() == GameStage.Warmup || WoolGet.getGameStage() == GameStage.Game) {
|
|
ItemStack item = e.getItem().getItemStack();
|
|
if(item.getType() == Material.FIREBALL) {
|
|
e.getItem().remove();
|
|
e.setCancelled(true);
|
|
p.getWorld().createExplosion(p.getLocation(), 0.0F);
|
|
p.damage(3.0D);
|
|
}
|
|
}else{
|
|
e.setCancelled(true);
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onItemDrop(PlayerDropItemEvent e) {
|
|
if(WoolGet.getGameStage() == GameStage.Lobby) {
|
|
e.setCancelled(true);
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onEntityDamage(EntityDamageByEntityEvent e) {
|
|
if (e.getEntity() instanceof Player && e.getDamager() instanceof Snowball && WoolGet.getGameStage() == GameStage.Game) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getEntity().getName());
|
|
Snowball snowball = (Snowball) e.getDamager();
|
|
if (snowball.getShooter() instanceof Player) {
|
|
CustomPlayer shooter = CustomPlayer.getPlayer(((Player) snowball.getShooter()).getName());
|
|
if (TeamManager.getTeam(p) != TeamManager.getTeam(shooter)) {
|
|
Location pLoc = p.getLocation().clone();
|
|
Location shooterLoc = shooter.getLocation().clone();
|
|
p.teleport(shooterLoc);
|
|
shooter.teleport(pLoc);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onTramp(PlayerInteractEvent e) {
|
|
if(e.getAction() == Action.PHYSICAL && e.getClickedBlock().getType() == Material.SOIL) {
|
|
e.setCancelled(true);
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onEntityDamage(EntityDamageEvent e) {
|
|
if (e.getEntity() instanceof Villager) e.setCancelled(true);
|
|
if(e.getEntity() instanceof Player && WoolGet.getGameStage() != GameStage.Game) e.setCancelled(true);
|
|
}
|
|
|
|
|
|
private static List<Location> getAreaBlocks(Location loc, int radius) {
|
|
World w = loc.getWorld();
|
|
double xCord = loc.getX();
|
|
double YCord = loc.getY();
|
|
double zCord = loc.getZ();
|
|
|
|
List<Location> tempList = new ArrayList<>();
|
|
for (int x = -radius; x <= radius; x++) {
|
|
for (int z = -radius; z <= radius; z++) {
|
|
for (int y = -radius; y <= radius; y++) {
|
|
tempList.add(new Location(w, xCord + x, YCord + y, zCord + z));
|
|
}
|
|
}
|
|
}
|
|
return tempList;
|
|
}
|
|
} |