74 lines
2.6 KiB
Java
74 lines
2.6 KiB
Java
/*
|
|
* Copyright (c) 2017 univento.eu - All rights reserved
|
|
* You are not allowed to use, distribute or modify this code
|
|
*/
|
|
|
|
package eu.univento.core.listeners;
|
|
|
|
import eu.univento.core.Core;
|
|
import eu.univento.core.api.npc.NPC;
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import net.minecraft.server.v1_12_R1.PacketPlayOutAnimation;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.block.Action;
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
|
import org.bukkit.event.player.PlayerKickEvent;
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
|
|
|
import java.util.Random;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 0.5
|
|
*/
|
|
|
|
public class NPCEvents implements Listener {
|
|
|
|
@EventHandler
|
|
public void onJoin(PlayerJoinEvent e) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
|
for(NPC npc : NPC.getNpcs()) p.sendPacket(npc.packet);
|
|
}
|
|
|
|
@EventHandler
|
|
public void onPlayerInteract(PlayerInteractEvent e) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
|
if(e.getAction() == Action.LEFT_CLICK_AIR ||e.getAction() == Action.LEFT_CLICK_BLOCK) {
|
|
for(NPC npc : NPC.getNpcs()) {
|
|
if(npc.detect.equals(p)) {
|
|
PacketPlayOutAnimation animationPacket = new PacketPlayOutAnimation(npc.getBukkitEntity().getHandle(), 0);
|
|
for(CustomPlayer player : Core.getOnlinePlayers()) player.sendPacket(animationPacket);
|
|
}
|
|
}
|
|
}
|
|
if(p.getItemInHand() != null && p.getItemInHand().getType() == Material.NETHER_STAR && (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
|
|
for(NPC npc : NPC.getNpcs())
|
|
if(npc.detect.equals(p)) {
|
|
npc.remove();
|
|
return;
|
|
}
|
|
Random random = new Random();
|
|
NPC.spawn(p, p.getProfile(), new Location(p.getWorld(), p.getLocation().getX() + random.nextInt(10), p.getLocation().getY(), p.getLocation().getZ() - random.nextInt(10)));
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onPlayerQuit(PlayerQuitEvent e) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
|
for(NPC npc : NPC.getNpcs()) {
|
|
if (npc.detect.equals(p)) npc.remove();
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
public void onPlayerKick(PlayerKickEvent e) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
|
for(NPC npc : NPC.getNpcs()) {
|
|
if(npc.detect.equals(p)) npc.remove();
|
|
}
|
|
}
|
|
} |