Added Artifact Apple.

This commit is contained in:
FabioZumbi12 2015-03-06 03:03:22 -03:00
parent 919d78a04d
commit 098ab1cd44
2 changed files with 99 additions and 8 deletions

View File

@ -1,6 +1,8 @@
package org.jakub1221.herobrineai;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
@ -43,7 +45,7 @@ public class HerobrineAI extends JavaPlugin implements Listener {
private Support support;
private EntityManager entMng;
private NPCCore NPCCore;
public Map<Player, Long> PlayerApple = new HashMap<Player, Long>();
public static HumanNPC herobrineNPC;
public static long herobrineEntityID;
public static int HerobrineHP = 200;

View File

@ -1,5 +1,6 @@
package org.jakub1221.herobrineai.listeners;
import java.util.ArrayList;
import java.util.Random;
import net.minecraft.server.v1_8_R1.EntityPlayer;
@ -7,14 +8,17 @@ import net.minecraft.server.v1_8_R1.EnumPlayerInfoAction;
import net.minecraft.server.v1_8_R1.PacketPlayOutPlayerInfo;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Jukebox;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
@ -28,11 +32,88 @@ import org.bukkit.inventory.ItemStack;
import org.jakub1221.herobrineai.HerobrineAI;
import org.jakub1221.herobrineai.AI.AICore;
import org.jakub1221.herobrineai.AI.Core;
import org.jakub1221.herobrineai.misc.ItemName;
public class PlayerListener implements Listener {
private ArrayList<String> equalsLoreS = new ArrayList<String>();
private ArrayList<String> equalsLoreA = new ArrayList<String>();
private ArrayList<LivingEntity> LivingEntities = new ArrayList<LivingEntity>();
private Location le_loc = null;
private Location p_loc = null;
private long timestamp = 0L;
private boolean canUse = false;
public PlayerListener() {
this.equalsLoreS.add("Herobrine´s artifact");
this.equalsLoreS.add("Sword of Lighting");
this.equalsLoreA.add("Herobrine´s artifact");
this.equalsLoreA.add("Apple of Death");
}
@EventHandler
public void onPlayerInteract(final PlayerInteractEvent event) {
if (((event.getAction() == Action.LEFT_CLICK_BLOCK) || (event.getAction() == Action.RIGHT_CLICK_BLOCK)) &&
(event.getClickedBlock() != null) && (event.getPlayer().getItemInHand() != null))
{
ItemStack itemInHand = event.getPlayer().getItemInHand();
if ((event.getPlayer().getItemInHand().getType() != null) &&
((itemInHand.getType() == Material.DIAMOND_SWORD) || (itemInHand.getType() == Material.GOLDEN_APPLE)) &&
(ItemName.getLore(itemInHand) != null)) {
if ((ItemName.getLore(itemInHand).containsAll(this.equalsLoreS)) && (HerobrineAI.getPluginCore().getConfigDB().UseArtifactSword))
{
if (new Random().nextBoolean()) {
event.getPlayer().getLocation().getWorld().strikeLightning(event.getClickedBlock().getLocation());
}
}
else if ((ItemName.getLore(itemInHand).containsAll(this.equalsLoreA)) && (HerobrineAI.getPluginCore().getConfigDB().UseArtifactApple))
{
this.timestamp = (System.currentTimeMillis() / 1000L);
this.canUse = false;
if (HerobrineAI.getPluginCore().PlayerApple.containsKey(event.getPlayer()))
{
if (((Long)HerobrineAI.getPluginCore().PlayerApple.get(event.getPlayer())).longValue() < this.timestamp)
{
HerobrineAI.getPluginCore().PlayerApple.remove(event.getPlayer());
this.canUse = true;
}
else
{
this.canUse = false;
}
}
else {
this.canUse = true;
}
if (this.canUse)
{
event.getPlayer().getWorld().createExplosion(event.getPlayer().getLocation(), 0.0F);
this.LivingEntities = ((ArrayList<LivingEntity>)event.getPlayer().getLocation().getWorld().getLivingEntities());
HerobrineAI.getPluginCore().PlayerApple.put(event.getPlayer(), Long.valueOf(this.timestamp + 60L));
for (int i = 0; i <= this.LivingEntities.size() - 1; i++) {
if ((!(this.LivingEntities.get(i) instanceof Player)) && (this.LivingEntities.get(i).getEntityId() != HerobrineAI.herobrineEntityID))
{
this.le_loc = this.LivingEntities.get(i).getLocation();
this.p_loc = event.getPlayer().getLocation();
if ((this.le_loc.getBlockX() < this.p_loc.getBlockX() + 20) && (this.le_loc.getBlockX() > this.p_loc.getBlockX() - 20) &&
(this.le_loc.getBlockY() < this.p_loc.getBlockY() + 10) && (this.le_loc.getBlockY() > this.p_loc.getBlockY() - 10) &&
(this.le_loc.getBlockZ() < this.p_loc.getBlockZ() + 20) && (this.le_loc.getBlockZ() > this.p_loc.getBlockZ() - 20))
{
event.getPlayer().getWorld().createExplosion(this.LivingEntities.get(i).getLocation(), 0.0F);
this.LivingEntities.get(i).damage(10000);
}
}
}
}
else
{
event.getPlayer().sendMessage(ChatColor.RED + "Apple of Death is recharging!");
}
}
}
}
if ((event.getClickedBlock() != null) && (event.getPlayer().getItemInHand() != null) && (event.getClickedBlock().getType() == Material.JUKEBOX)) {
final ItemStack item = event.getPlayer().getItemInHand();
final Jukebox block = (Jukebox) event.getClickedBlock().getState();
@ -86,13 +167,21 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
if (event.getPlayer().getEntityId() == HerobrineAI.herobrineEntityID) {
if (event.getFrom().getWorld() != event.getTo().getWorld()) {
HerobrineAI.getPluginCore().removeHerobrine();
HerobrineAI.getPluginCore().spawnHerobrine(event.getTo());
event.setCancelled(true);
return;
}
}
if (event.getFrom().getWorld() != event.getTo().getWorld()) {
HerobrineAI.getPluginCore().removeHerobrine();
HerobrineAI.getPluginCore().spawnHerobrine(event.getTo());
event.setCancelled(true);
return;
}
if ((HerobrineAI.getPluginCore().getAICore().getCoreTypeNow() == Core.CoreType.RANDOM_POSITION) &&
(HerobrineAI.herobrineNPC.getNMSEntity().getBukkitEntity().getLocation().getBlockX() > HerobrineAI.getPluginCore().getConfigDB().WalkingModeXRadius) &&
(HerobrineAI.herobrineNPC.getNMSEntity().getBukkitEntity().getLocation().getBlockX() < -HerobrineAI.getPluginCore().getConfigDB().WalkingModeXRadius) &&
(HerobrineAI.herobrineNPC.getNMSEntity().getBukkitEntity().getLocation().getBlockZ() > HerobrineAI.getPluginCore().getConfigDB().WalkingModeZRadius) &&
(HerobrineAI.herobrineNPC.getNMSEntity().getBukkitEntity().getLocation().getBlockZ() < -HerobrineAI.getPluginCore().getConfigDB().WalkingModeZRadius)) {
HerobrineAI.getPluginCore().getAICore().cancelTarget(Core.CoreType.RANDOM_POSITION);
HerobrineAI.herobrineNPC.moveTo(new Location(Bukkit.getServer().getWorlds().get(0), 0.0D, -20.0D, 0.0D));
}
}
}
@EventHandler