mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-01 14:38:55 +00:00
Added root directory
This commit is contained in:
1 parent
43f63daa26
commit
08208fdeaf
16 files changed
No files matched your search
@@ -1,755 +0,0 @@
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.ArmorStand.LockType;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.Snowball;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
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.block.SignChangeEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.entity.ItemDisplay;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
|
||||
//import com.palmergames.bukkit.towny.TownyAPI;
|
||||
//import com.palmergames.bukkit.towny.event.actions.TownyDestroyEvent;
|
||||
//import com.palmergames.bukkit.towny.object.TownBlock;
|
||||
|
||||
//import GunnersProjectiles.ExplosiveProjectile;
|
||||
|
||||
public class ClickHandler implements Listener {
|
||||
|
||||
public float MinDelay = 5;
|
||||
|
||||
public static HashMap<UUID, ExplosiveProjectile> projectiles = new HashMap<UUID, ExplosiveProjectile>();
|
||||
@EventHandler
|
||||
public void onExplode(EntityExplodeEvent e) {
|
||||
for (Entity entity : e.getEntity().getNearbyEntities(e.getYield() + 1, e.getYield()+ 1, e.getYield()+ 1)) {
|
||||
if(entity instanceof ArmorStand) {
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
/*if (GunnersCore.towny != null) {
|
||||
TownBlock block = TownyAPI.getInstance().getTownBlock(stand.getLocation());
|
||||
if (block != null) {
|
||||
if (block.hasTown()) {
|
||||
if (!block.getTownBlockOwner().getPermissions().explosion) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
stand.eject();
|
||||
stand.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onHit(ProjectileHitEvent event) {
|
||||
if ((event.getEntity() instanceof Snowball) && projectiles.containsKey(event.getEntity().getUniqueId())) {
|
||||
ExplosiveProjectile proj = projectiles.get(event.getEntity().getUniqueId());
|
||||
Entity snowball = event.getEntity();
|
||||
Snowball ball = (Snowball) snowball;
|
||||
Entity player = (Entity) ball.getShooter();
|
||||
if (player instanceof Player) {
|
||||
player.sendMessage("§eDistance to impact: " + String.format("%.2f",player.getLocation().distance(ball.getLocation())));
|
||||
}
|
||||
Location loc = snowball.getLocation();
|
||||
World world = event.getEntity().getWorld();
|
||||
// world.createExplosion(loc, proj.Radius, proj.DoFire);
|
||||
Entity tnt = event.getEntity().getWorld().spawnEntity(loc, EntityType.PRIMED_TNT);
|
||||
|
||||
projectiles.remove(event.getEntity().getUniqueId());
|
||||
|
||||
if (proj.PlaceBlocks) {
|
||||
TNTPrimed tntEnt = (TNTPrimed) tnt;
|
||||
tntEnt.setYield(0);
|
||||
tntEnt.setFuseTicks(0);
|
||||
/*if (GunnersCore.towny != null) {
|
||||
TownBlock block = TownyAPI.getInstance().getTownBlock(loc);
|
||||
if (block != null) {
|
||||
if (block.hasTown()) {
|
||||
if (!block.getTownBlockOwner().getPermissions().explosion) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if (event.getHitBlock() != null) {
|
||||
List<Block> Blocks = sphere(event.getHitBlock().getLocation(), (int) proj.ExplodePower);
|
||||
for (int i = 0; i < proj.BlocksToPlaceAmount; i++) {
|
||||
Block replace = getRandomElement(Blocks);
|
||||
replace.setType(proj.BlockToPlace);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
TNTPrimed tntEnt = (TNTPrimed) tnt;
|
||||
tntEnt.setYield(proj.ExplodePower);
|
||||
tntEnt.setFuseTicks(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Block> sphere(final Location center, final int radius) {
|
||||
ArrayList<Block> sphere = new ArrayList<Block>();
|
||||
for (int Y = -radius; Y < radius; Y++) {
|
||||
for (int X = -radius; X < radius; X++) {
|
||||
for (int Z = -radius; Z < radius; Z++) {
|
||||
if (Math.sqrt((X * X) + (Y * Y) + (Z * Z)) <= radius) {
|
||||
final Block block = center.getWorld().getBlockAt(X + center.getBlockX(), Y + center.getBlockY(), Z + center.getBlockZ());
|
||||
if (block.getType() == Material.AIR) {
|
||||
sphere.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return sphere;
|
||||
}
|
||||
|
||||
public Block getRandomElement(List<Block> list)
|
||||
{
|
||||
Random rand = new Random();
|
||||
return list.get(rand.nextInt(list.size()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent event) {
|
||||
Player thePlayer = event.getPlayer();
|
||||
if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.CARVED_PUMPKIN) {
|
||||
ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
|
||||
if (item.getItemMeta() != null && item.getItemMeta().hasCustomModelData()) {
|
||||
int customModel = item.getItemMeta().getCustomModelData();
|
||||
Boolean created = GunnersCore.CreateCannon(thePlayer, customModel, event.getBlockAgainst().getLocation());
|
||||
if (created) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
thePlayer.getInventory().setItemInMainHand(item);
|
||||
thePlayer.sendMessage("§eGunner Equipment spawned!");
|
||||
} else {
|
||||
thePlayer.sendMessage("§eGunner Equipment could not be spawned, is it enabled?");
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Shoot(Entity player, long delay) {
|
||||
float actualDelay = delay;
|
||||
Boolean FirstShot = true;
|
||||
|
||||
if (GunnersCore.TrackedStands.get(player.getUniqueId()) == null) {
|
||||
for (Entity ent : player.getNearbyEntities(5, 5, 5)) {
|
||||
if(ent instanceof ArmorStand) {
|
||||
TakeControl(player,ent);
|
||||
}
|
||||
}
|
||||
if (player instanceof Player) {
|
||||
player.sendMessage("§eNow controlling nearby equipment.");
|
||||
}
|
||||
}
|
||||
if (GunnersCore.TrackedStands.get(player.getUniqueId()) == null)
|
||||
return;
|
||||
for (Entity ent : GunnersCore.TrackedStands.get(player.getUniqueId())){
|
||||
|
||||
if (ent == null || ent.isDead()) {
|
||||
continue;
|
||||
}
|
||||
double distance = player.getLocation().distance(ent.getLocation());
|
||||
if (distance >= 127) {
|
||||
continue;
|
||||
}
|
||||
GunnerEquipment siege = GunnersCore.equipment.get(ent.getUniqueId());
|
||||
|
||||
if (siege.isLoaded()) {
|
||||
if (player instanceof Player) {
|
||||
siege.Fire(player, actualDelay,0);
|
||||
actualDelay += delay;
|
||||
} else {
|
||||
siege.Fire(player,15,1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (player instanceof Player) {}
|
||||
//player.sendMessage("§eAmmunition Not Loaded");
|
||||
}
|
||||
// player.sendMessage(String.format("§e" +actualDelay));
|
||||
|
||||
}
|
||||
}
|
||||
public static ItemStack[] updateContents(Inventory inv, ItemStack m, int toRemove) {
|
||||
ItemStack[] contents = inv.getStorageContents();
|
||||
for(int i = 0; i < contents.length; i++) {
|
||||
if(contents[i] == null) continue;
|
||||
if(contents[i].isSimilar(m)) {
|
||||
System.out.println(m.toString());
|
||||
int amountInInv = contents[i].getAmount();
|
||||
if(toRemove >= amountInInv) {
|
||||
contents[i].setType(Material.AIR);
|
||||
toRemove -= amountInInv;
|
||||
} else {
|
||||
contents[i].setAmount(amountInInv-toRemove);
|
||||
toRemove = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(toRemove <= 0) break;
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void interact(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
ItemStack ItemInHand = event.getPlayer().getInventory().getItemInMainHand();
|
||||
if (ItemInHand == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if (ItemInHand.getType() == Material.PAPER) {
|
||||
// ItemMeta meta = ItemInHand.getItemMeta();
|
||||
// if (meta.hasCustomModelData() && meta.getCustomModelData() == 505050505) {
|
||||
// GunnersCore.CreateCannon(player);
|
||||
// ItemInHand.setAmount(ItemInHand.getAmount() - 1);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
if (ItemInHand.getType() != Material.BOOK) {
|
||||
return;
|
||||
}
|
||||
if (!player.isSneaking())
|
||||
Shoot((Entity)player, 7);
|
||||
if (GunnersCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
List<Entity> entities = GunnersCore.TrackedStands.get(player.getUniqueId());
|
||||
for (Entity entity : entities) {
|
||||
boolean foundAmmo = false;
|
||||
if (GunnersCore.equipment.containsKey(entity.getUniqueId())) {
|
||||
GunnerEquipment equip = GunnersCore.equipment.get(entity.getUniqueId());
|
||||
if (equip == null || !equip.Enabled) {
|
||||
continue;
|
||||
}
|
||||
if (entity.getLocation().getBlock().getType() == Material.BARREL || entity.getLocation().getBlock().getType() == Material.CHEST) {
|
||||
Block inv = entity.getLocation().getBlock();
|
||||
Container state = ((Container)inv.getState());
|
||||
for (ItemStack stack : equip.Projectiles.keySet()) {
|
||||
if (foundAmmo)
|
||||
continue;
|
||||
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
|
||||
//state.update(true,true);
|
||||
equip.AmmoHolder.LoadedProjectile = 1;
|
||||
equip.AmmoHolder.MaterialName = stack;
|
||||
foundAmmo = true;
|
||||
}
|
||||
//state.update(true,true);
|
||||
}
|
||||
if (foundAmmo)
|
||||
continue;
|
||||
if (entity.getLocation().getBlock().getRelative(0,-1,0).getType() == Material.BARREL || entity.getLocation().getBlock().getRelative(0,-1,0).getType() == Material.CHEST) {
|
||||
Block inv = entity.getLocation().getBlock().getRelative(0,-1,0);
|
||||
Container state = ((Container)inv.getState());
|
||||
for (ItemStack stack : equip.Projectiles.keySet()) {
|
||||
if (foundAmmo)
|
||||
continue;
|
||||
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
|
||||
//state.update(true,true);
|
||||
equip.AmmoHolder.LoadedProjectile = 1;
|
||||
equip.AmmoHolder.MaterialName = stack;
|
||||
foundAmmo = true;
|
||||
}
|
||||
//state.update(true,true);
|
||||
}
|
||||
if (foundAmmo)
|
||||
continue;
|
||||
if (entity.getLocation().getBlock().getRelative(0,1,0).getType() == Material.BARREL || entity.getLocation().getBlock().getRelative(0,1,0).getType() == Material.CHEST) {
|
||||
Block inv = entity.getLocation().getBlock().getRelative(0,1,0);
|
||||
Container state = ((Container)inv.getState());
|
||||
for (ItemStack stack : equip.Projectiles.keySet()) {
|
||||
if (foundAmmo)
|
||||
continue;
|
||||
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
|
||||
//state.update(true,true);
|
||||
equip.AmmoHolder.LoadedProjectile = 1;
|
||||
equip.AmmoHolder.MaterialName = stack;
|
||||
foundAmmo = true;
|
||||
}
|
||||
//state.update(true,true);
|
||||
}
|
||||
if (foundAmmo)
|
||||
continue;
|
||||
if (!player.isSneaking())
|
||||
return;
|
||||
if (!foundAmmo) {
|
||||
for (ItemStack inventoryItem : event.getPlayer().getInventory().getContents()) {
|
||||
for (ItemStack stack : equip.Projectiles.keySet()) {
|
||||
if (foundAmmo)
|
||||
continue;
|
||||
if (stack.isSimilar(inventoryItem) && equip.AmmoHolder.LoadedProjectile == 0){
|
||||
equip.AmmoHolder.LoadedProjectile = 1;
|
||||
equip.AmmoHolder.MaterialName = stack;
|
||||
inventoryItem.setAmount(inventoryItem.getAmount() - 1);
|
||||
foundAmmo = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
player.sendMessage("§eReloading Ammunition");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onSignChange(SignChangeEvent event){
|
||||
String topline = event.getLine(0);
|
||||
if (topline == null) topline = "";
|
||||
Player player = event.getPlayer();
|
||||
String toplinetrimmed = topline.trim();
|
||||
if (toplinetrimmed.equals("[Cannon]")) {
|
||||
SaveCannons(player, event.getBlock());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void damage(EntityDamageByEntityEvent event){
|
||||
if (event.getEntity() instanceof ArmorStand) {
|
||||
if (event.getDamager() instanceof Projectile) {
|
||||
event.setDamage(0);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void TakeControl(Entity player, Entity entity) {
|
||||
LivingEntity living = (LivingEntity) entity;
|
||||
if (GunnersCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
List<Entity> entities = GunnersCore.TrackedStands.get(player.getUniqueId());
|
||||
if (entities.contains(entity)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (living.getEquipment().getHelmet() != null && living.getEquipment().getHelmet().getType() == Material.CARVED_PUMPKIN) {
|
||||
if (living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
GunnerEquipment equip;
|
||||
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
|
||||
stand.setBasePlate(false);
|
||||
|
||||
if (GunnersCore.equipment.containsKey(entity.getUniqueId())) {
|
||||
equip = GunnersCore.equipment.get(entity.getUniqueId());
|
||||
if (equip == null || !equip.Enabled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
equip = GunnersCore.CreateClone(living.getEquipment().getHelmet().getItemMeta().getCustomModelData());
|
||||
if (equip == null || !equip.Enabled) {
|
||||
return;
|
||||
}
|
||||
equip.AmmoHolder = new EquipmentMagazine();
|
||||
equip.Entity = entity;
|
||||
equip.EntityId = entity.getUniqueId();
|
||||
}
|
||||
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
|
||||
stand.setBasePlate(false);
|
||||
if (GunnersCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
List<Entity> entities = GunnersCore.TrackedStands.get(player.getUniqueId());
|
||||
entities.add(entity);
|
||||
GunnersCore.TrackedStands.put(player.getUniqueId(), entities);
|
||||
}
|
||||
else {
|
||||
List<Entity> newList = new ArrayList<Entity>();
|
||||
newList.add(entity);
|
||||
GunnersCore.TrackedStands.put(player.getUniqueId(), newList);
|
||||
}
|
||||
GunnersCore.equipment.put(entity.getUniqueId(), equip);
|
||||
//player.sendMessage("§eNow controlling the equipment.");
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveCannons(Player player, Block block) {
|
||||
List<String> Ids = new ArrayList<String>();
|
||||
if (!GunnersCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
for (Entity ent : GunnersCore.TrackedStands.get(player.getUniqueId())) {
|
||||
Ids.add(ent.getUniqueId().toString());
|
||||
}
|
||||
TileState state = ((TileState) block.getState());
|
||||
NamespacedKey key = new NamespacedKey(GunnersCore.plugin, "cannons");
|
||||
|
||||
for (Entity ent : GunnersCore.TrackedStands.get(player.getUniqueId())) {
|
||||
if (ent.isDead()) {
|
||||
continue;
|
||||
}
|
||||
DoAimUp(ent, 0, player);
|
||||
}
|
||||
}
|
||||
|
||||
public void DoAimUp(Entity ent, float amount, Entity player) {
|
||||
Location loc = ent.getLocation();
|
||||
ArmorStand stand = (ArmorStand) ent;
|
||||
// player.sendMessage(String.format("" + loc.getPitch()));
|
||||
if (loc.getPitch() == -85 || loc.getPitch() - amount < -85) {
|
||||
return;
|
||||
}
|
||||
loc.setPitch((float) (loc.getPitch() - amount));
|
||||
GunnerEquipment equipment = GunnersCore.equipment.get(ent.getUniqueId());
|
||||
if (equipment != null) {
|
||||
if (player instanceof Player)
|
||||
equipment.ShowFireLocation(player);
|
||||
if (equipment.RotateStandHead) {
|
||||
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
|
||||
}
|
||||
ent.teleport(loc);
|
||||
}
|
||||
}
|
||||
|
||||
public void DoAimDown(Entity ent, float amount, Entity player) {
|
||||
Location loc = ent.getLocation();
|
||||
ArmorStand stand = (ArmorStand) ent;
|
||||
// player.sendMessage(String.format("" + loc.getPitch()));
|
||||
if (loc.getPitch() == 85 || loc.getPitch() - amount < 65) {
|
||||
return;
|
||||
}
|
||||
loc.setPitch((float) (loc.getPitch() - amount));
|
||||
GunnerEquipment equipment = GunnersCore.equipment.get(ent.getUniqueId());
|
||||
if (equipment != null) {
|
||||
if (player instanceof Player)
|
||||
equipment.ShowFireLocation(player);
|
||||
if (equipment.RotateStandHead) {
|
||||
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
|
||||
}
|
||||
ent.teleport(loc);
|
||||
}
|
||||
}
|
||||
|
||||
public void FirstShotDoAimDown(Entity ent, float amount, Entity player) {
|
||||
Location loc = ent.getLocation();
|
||||
ArmorStand stand = (ArmorStand) ent;
|
||||
// player.sendMessage(String.format("" + loc.getPitch()));
|
||||
if (loc.getPitch() == 85 || loc.getPitch() + amount > 85) {
|
||||
return;
|
||||
}
|
||||
GunnerEquipment equipment = GunnersCore.equipment.get(ent.getUniqueId());
|
||||
if (equipment != null) {
|
||||
if (player instanceof Player) {
|
||||
equipment.ShowFireLocation((Player)player);
|
||||
}
|
||||
if (equipment.RotateStandHead) {
|
||||
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
|
||||
|
||||
}
|
||||
}
|
||||
loc.setPitch((float) (loc.getPitch() + amount));
|
||||
|
||||
ent.teleport(loc);
|
||||
}
|
||||
NamespacedKey key = new NamespacedKey(GunnersCore.plugin, "cannons");
|
||||
|
||||
@EventHandler
|
||||
public void DeathEvent(EntityDeathEvent event) {
|
||||
Boolean removeStands = false;
|
||||
List<ItemStack> items = event.getDrops();
|
||||
if (event.getEntity() instanceof ArmorStand) {
|
||||
if (event.getEntity().getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
|
||||
Entity base = Bukkit.getEntity(UUID.fromString(event.getEntity().getPersistentDataContainer().get(key, PersistentDataType.STRING)));
|
||||
base.remove();
|
||||
}
|
||||
if (GunnersCore.equipment.containsKey(event.getEntity().getUniqueId())) {
|
||||
removeStands = true;
|
||||
}
|
||||
else {
|
||||
for (ItemStack i : items) {
|
||||
if (i.getType() == Material.CARVED_PUMPKIN && i.hasItemMeta() && i.getItemMeta().hasCustomModelData()) {
|
||||
if (GunnersCore.DefinedEquipment.containsKey(i.getItemMeta().getCustomModelData())) {
|
||||
removeStands = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (removeStands) {
|
||||
for (ItemStack i : items) {
|
||||
if (i.getType() == Material.ARMOR_STAND) {
|
||||
i.setAmount(0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AimUp(Entity player, float amount) {
|
||||
|
||||
for (Entity ent : GunnersCore.TrackedStands.get(player.getUniqueId())) {
|
||||
if (ent.isDead()) {
|
||||
continue;
|
||||
}
|
||||
DoAimUp(ent, amount, player);
|
||||
}
|
||||
}
|
||||
|
||||
public void AimDown(Entity player, float amount) {
|
||||
|
||||
for (Entity ent : GunnersCore.TrackedStands.get(player.getUniqueId())) {
|
||||
if (ent.isDead()) {
|
||||
continue;
|
||||
}
|
||||
DoAimDown(ent, amount, player);
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadCannonsWithPowder(Entity player) {
|
||||
for (Entity ent : GunnersCore.TrackedStands.get(player.getUniqueId())) {
|
||||
if (ent.isDead()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
GunnerEquipment equipment = GunnersCore.equipment.get(ent.getUniqueId());
|
||||
if (equipment != null) {
|
||||
equipment.LoadFuel(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadCannonsWithProjectile(Entity player, ItemStack projectile) {
|
||||
for (Entity ent : GunnersCore.TrackedStands.get(player.getUniqueId())) {
|
||||
if (ent.isDead()) {
|
||||
continue;
|
||||
}
|
||||
GunnerEquipment equipment = GunnersCore.equipment.get(ent.getUniqueId());
|
||||
if (equipment != null) {
|
||||
equipment.LoadProjectile(player, projectile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerClickSign(PlayerInteractEvent event){
|
||||
Player player = event.getPlayer();
|
||||
if(event.getClickedBlock() != null && event.getClickedBlock().getType().toString().contains("SIGN")){
|
||||
Sign sign = (Sign) event.getClickedBlock().getState();
|
||||
if(sign.getLine(0).equalsIgnoreCase( "[Fire]") && event.getAction() == Action.RIGHT_CLICK_BLOCK){
|
||||
if (!GunnersCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Long delay = Long.parseLong(sign.getLine(1));
|
||||
if (delay < 6){
|
||||
delay = 6l;
|
||||
}
|
||||
Shoot((Entity)player, delay);
|
||||
} catch (Exception e) {
|
||||
Shoot((Entity)player, 6);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(sign.getLine(0).equalsIgnoreCase( "[Load]")){
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
LoadCannonsWithPowder((Entity)player);
|
||||
return;
|
||||
}
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
//load proj
|
||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||
if (itemInHand == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
LoadCannonsWithProjectile((Entity)player, player.getInventory().getItemInMainHand());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(sign.getLine(0).equalsIgnoreCase( "[Aim]")){
|
||||
if (!GunnersCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
float amount;
|
||||
try {
|
||||
amount = Float.parseFloat(sign.getLine(1));
|
||||
if (player.isSneaking()) {
|
||||
AimDown((Entity)player, amount);
|
||||
} else {
|
||||
AimUp((Entity)player, amount);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
player.sendMessage("§eCould not parse number on second line.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(sign.getLine(0).equalsIgnoreCase( "[Cannon]")){
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
GunnersCore.TrackedStands.remove(player.getUniqueId());
|
||||
player.sendMessage("§eReleasing the equipment!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
|
||||
if (player.isSneaking()) {
|
||||
SaveCannons(player, event.getClickedBlock());
|
||||
return;
|
||||
}
|
||||
|
||||
NamespacedKey key = new NamespacedKey(GunnersCore.plugin, "cannons");
|
||||
TileState state = (TileState) sign.getBlock().getState();
|
||||
GunnersCore.TrackedStands.remove(player.getUniqueId());
|
||||
List<UUID> temp = new ArrayList<UUID>();
|
||||
if (!state.getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
|
||||
return;
|
||||
}
|
||||
String[] split = state.getPersistentDataContainer().get(key, PersistentDataType.STRING).replace("[", "").replace("]", "").split(",");
|
||||
for (String s : split) {
|
||||
temp.add(UUID.fromString(s.trim()));
|
||||
}
|
||||
for (UUID Id : temp) {
|
||||
List<Entity> entities = new ArrayList<Entity>();
|
||||
Entity ent = Bukkit.getEntity(Id);
|
||||
if (ent != null) {
|
||||
TakeControl(player, ent);
|
||||
}
|
||||
}
|
||||
player.sendMessage("§eNow controlling nearby equipment.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityClick(PlayerInteractAtEntityEvent event) {
|
||||
|
||||
Player player = event.getPlayer();
|
||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||
Entity entity = event.getRightClicked();
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
if (entity.getType() == EntityType.ARMOR_STAND){
|
||||
TakeControl(player, entity);
|
||||
if (GunnersCore.equipment.containsKey(entity.getUniqueId())) {
|
||||
if (itemInHand.getType() == Material.RECOVERY_COMPASS) {
|
||||
if (player.isSneaking()) {
|
||||
DoAimDown(entity, 1, player);
|
||||
}
|
||||
else {
|
||||
DoAimUp(entity, 1, player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
GunnerEquipment equipment = GunnersCore.equipment.get(entity.getUniqueId());
|
||||
event.setCancelled(true);
|
||||
|
||||
if (itemInHand == null || itemInHand.getType() == Material.AIR) {
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
if (stand.isInvisible()) {
|
||||
stand.setInvisible(false);
|
||||
player.sendMessage("§eEquipment is now breakable");
|
||||
}
|
||||
else{
|
||||
if (equipment.AllowInvisibleStand) {
|
||||
stand.setInvisible(true);
|
||||
player.sendMessage("§eEquipment is no longer breakable");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (itemInHand.isSimilar(equipment.FuelMaterial)) {
|
||||
if (!equipment.LoadFuel(player)) {
|
||||
player.sendMessage("§eCould not load Propellant.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
/*if (itemInHand.isSimilar(new ItemStack(Material.FLINT))) {
|
||||
if (equipment.isLoaded()) {
|
||||
equipment.Fire((Entity) player, 6, 1);
|
||||
}
|
||||
else {
|
||||
player.sendMessage("§eEquipment is not loaded");
|
||||
}
|
||||
return;
|
||||
}*/
|
||||
for (ItemStack stack : equipment.Projectiles.keySet()) {
|
||||
if (stack.isSimilar(itemInHand) && equipment.AmmoHolder.LoadedProjectile == 0){
|
||||
equipment.AmmoHolder.LoadedProjectile = 1;
|
||||
equipment.AmmoHolder.MaterialName = stack;
|
||||
player.sendMessage("§eAdding Ammo to Weapon");
|
||||
itemInHand.setAmount(itemInHand.getAmount() - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
player.sendMessage("§eNow controlling this equipment.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Fireball;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
|
||||
public class EntityProjectile implements GunnersProjectile{
|
||||
|
||||
public String ProjectileType = "Entity";
|
||||
public int EntityCount = 20;
|
||||
public int ArrowOnlyDamage = 6;
|
||||
public Boolean DelayedFire = false;
|
||||
public int DelayTime = 6;
|
||||
public EntityType EntityTyp = EntityType.ARROW;
|
||||
public float Inaccuracy = 0.2f;
|
||||
public Particle ParticleType = Particle.EXPLOSION_LARGE;
|
||||
public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE;
|
||||
@Override
|
||||
public void Shoot(Entity player, Entity entity, Location FireLocation, Float velocity) {
|
||||
PlaySound = true;
|
||||
int baseDelay = 0;
|
||||
for (int i = 0; i < EntityCount; i++) {
|
||||
if (DelayedFire) {
|
||||
baseDelay += DelayTime;
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(GunnersCore.plugin, () -> {
|
||||
|
||||
CreateEntity(entity, FireLocation, velocity, player);
|
||||
}, (long) baseDelay);
|
||||
}
|
||||
else {
|
||||
|
||||
CreateEntity(entity, FireLocation, velocity, player);
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
}
|
||||
private boolean PlaySound = true;
|
||||
private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) {
|
||||
World world = entity.getLocation().getWorld();
|
||||
LivingEntity living = (LivingEntity) entity;
|
||||
|
||||
Entity arrow = world.spawnEntity(loc, EntityTyp);
|
||||
if (Inaccuracy != 0f) {
|
||||
arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
|
||||
.subtract(Randomise()));
|
||||
}
|
||||
else {
|
||||
arrow.setVelocity(loc.getDirection().multiply(velocity));
|
||||
}
|
||||
|
||||
if (arrow instanceof Arrow) {
|
||||
Arrow arr = (Arrow) arrow;
|
||||
arr.setDamage(8);
|
||||
if (player instanceof org.bukkit.projectiles.ProjectileSource)
|
||||
arr.setShooter((org.bukkit.projectiles.ProjectileSource)player);
|
||||
//arr.setBasePotionData(arg0);
|
||||
}
|
||||
// MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.DROPPED_ITEM, Material.IRON_NUGGET);
|
||||
// DisguiseAPI.disguiseEntity(arrow, miscDisguise);
|
||||
if (PlaySound) {
|
||||
world.playSound(loc, this.SoundType, 20, 2);
|
||||
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
|
||||
if (!DelayedFire) {
|
||||
PlaySound = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Vector Randomise() {
|
||||
return new Vector(GunnersCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),GunnersCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),GunnersCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EquipmentMagazine {
|
||||
public int LoadedFuel = 0;
|
||||
public int LoadedProjectile = 0;
|
||||
public ItemStack MaterialName = new ItemStack(Material.AIR, 1);
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Snowball;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
//import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
//import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||
|
||||
public class ExplosiveProjectile implements GunnersProjectile {
|
||||
|
||||
public String ProjectileType = "Explosive";
|
||||
public Boolean PlaceBlocks = false;
|
||||
public Material BlockToPlace = Material.COBWEB;
|
||||
public int BlocksToPlaceAmount = 3;
|
||||
public float ExplodePower = 2;
|
||||
public float Inaccuracy = 0.3f;
|
||||
public int ProjectilesCount = 1;
|
||||
public Boolean DelayedFire = false;
|
||||
public int DelayTime = 6;
|
||||
public Particle ParticleType = Particle.EXPLOSION_LARGE;
|
||||
public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE;
|
||||
private boolean PlaySound = true;
|
||||
public Boolean AlertOnLanding = false;
|
||||
@Override
|
||||
public void Shoot(Entity player, Entity entity, Location loc, Float velocity) {
|
||||
PlaySound = true;
|
||||
int baseDelay = 0;
|
||||
for (int i = 0; i < ProjectilesCount; i++) {
|
||||
if (DelayedFire) {
|
||||
baseDelay += DelayTime;
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(GunnersCore.plugin, () -> {
|
||||
CreateEntity(entity, loc, velocity, player);
|
||||
}, (long) baseDelay);
|
||||
}
|
||||
else {
|
||||
CreateEntity(entity,loc, velocity, player);
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) {
|
||||
LivingEntity living = (LivingEntity) entity;
|
||||
World world = entity.getLocation().getWorld();
|
||||
Entity tnt = world.spawnEntity(loc, EntityType.SNOWBALL);
|
||||
Snowball ball = (Snowball) tnt;
|
||||
if (player instanceof org.bukkit.projectiles.ProjectileSource)
|
||||
ball.setShooter((org.bukkit.projectiles.ProjectileSource)player);
|
||||
ClickHandler.projectiles.put(tnt.getUniqueId(), this);
|
||||
|
||||
if (Inaccuracy != 0f) {
|
||||
tnt.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
|
||||
.subtract(Randomise()));
|
||||
}
|
||||
else {
|
||||
tnt.setVelocity(loc.getDirection().multiply(velocity));
|
||||
}
|
||||
|
||||
if (PlaySound) {
|
||||
world.playSound(loc, this.SoundType, 20, 2);
|
||||
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
|
||||
if (!DelayedFire) {
|
||||
PlaySound = false;
|
||||
}
|
||||
}
|
||||
// MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.ARROW);
|
||||
// miscDisguise.setEntity(tnt);
|
||||
// miscDisguise.startDisguise();
|
||||
|
||||
}
|
||||
|
||||
private Vector Randomise() {
|
||||
return new Vector(GunnersCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),GunnersCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),GunnersCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,273 +0,0 @@
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
//import GunnersProjectiles.GunnersProjectile;
|
||||
//import GunnersProjectiles.ExplosiveProjectile;
|
||||
//import me.libraryaddict.disguise.DisguiseAPI;
|
||||
//import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
//import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||
|
||||
public class GunnerEquipment implements Cloneable {
|
||||
|
||||
@Override
|
||||
public GunnerEquipment clone() throws CloneNotSupportedException {
|
||||
return (GunnerEquipment)super.clone();
|
||||
}
|
||||
public Boolean Enabled = true;
|
||||
public UUID EntityId;
|
||||
public Entity Entity;
|
||||
public Integer shotAmount = 3;
|
||||
|
||||
public HashMap<ItemStack, GunnersProjectile> Projectiles = new HashMap<ItemStack, GunnersProjectile>();
|
||||
|
||||
public String WorldName;
|
||||
public String EquipmentName = "Basic Cannon";
|
||||
public int XOffset = 7;
|
||||
public int YOffset = 0;
|
||||
public int PitchOffset = 0;
|
||||
public int MaxFuel = 5;
|
||||
public double PlacementOffsetY = 0;
|
||||
public float VelocityPerFuel = 1.75f;
|
||||
public ItemStack FuelMaterial = new ItemStack(Material.GUNPOWDER);
|
||||
public long NextShotTime = System.currentTimeMillis();
|
||||
|
||||
public int MillisecondsBetweenFiringStages;
|
||||
public int MillisecondsBetweenReloadingStages;
|
||||
|
||||
public int MillisecondsToLoad;
|
||||
public int ModelNumberToFireAt;
|
||||
public Boolean CycleThroughModelsBeforeFiring = false;
|
||||
public Boolean RotateSideways = false;
|
||||
public Boolean RotateUpDown = true;
|
||||
public Boolean RotateStandHead = true;
|
||||
public Boolean HasFired = false;
|
||||
public Boolean HasReloaded = false;
|
||||
public Boolean AllowInvisibleStand = true;
|
||||
public Boolean HaseBaseStand = false;
|
||||
public double BaseStandOffset = 0;
|
||||
public int BaseStandModelNumber = 147;
|
||||
public int TaskNumber;
|
||||
|
||||
public int ReadyModelNumber;
|
||||
|
||||
public int NextModelNumber = 0;
|
||||
|
||||
public List<Integer> FiringModelNumbers = new ArrayList<Integer>();
|
||||
|
||||
public EquipmentMagazine AmmoHolder = new EquipmentMagazine();
|
||||
|
||||
public Boolean isLoaded() {
|
||||
if (this.MaxFuel <= 0 && AmmoHolder.LoadedProjectile >= 1)
|
||||
return true;
|
||||
return (AmmoHolder.LoadedFuel > 0 && AmmoHolder.LoadedProjectile >= 1);
|
||||
}
|
||||
|
||||
public Boolean CanLoadFuel() {
|
||||
return AmmoHolder.LoadedFuel < MaxFuel;
|
||||
}
|
||||
|
||||
public Boolean LoadFuel(Entity player) {
|
||||
ItemStack fuelItem = this.FuelMaterial;
|
||||
if (this.AmmoHolder.LoadedFuel == this.MaxFuel) {
|
||||
return true;
|
||||
}
|
||||
if (!(player instanceof Player)) {
|
||||
this.AmmoHolder.LoadedFuel = this.MaxFuel;
|
||||
return true;
|
||||
}
|
||||
if (((Player)player).getInventory().containsAtLeast(fuelItem, 1) || fuelItem.getType() == Material.AIR) {
|
||||
if (CanLoadFuel()) {
|
||||
this.AmmoHolder.LoadedFuel += 1;
|
||||
SaveState();
|
||||
((Player)player).getInventory().removeItem(fuelItem);
|
||||
((Player)player).sendMessage("§eLoaded " + this.AmmoHolder.LoadedFuel + "/" + this.MaxFuel);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public Boolean LoadProjectile(Entity player, ItemStack itemInHand) {
|
||||
if (itemInHand.getAmount() <= 0) {
|
||||
return false;
|
||||
}
|
||||
if (!(player instanceof Player)) {
|
||||
this.AmmoHolder.LoadedProjectile = 1;
|
||||
this.AmmoHolder.LoadedFuel = this.MaxFuel;
|
||||
this.AmmoHolder.MaterialName = itemInHand;
|
||||
return true;
|
||||
}
|
||||
if (this.Projectiles.containsKey(itemInHand.getType()) && this.AmmoHolder.LoadedProjectile == 0){
|
||||
this.AmmoHolder.LoadedProjectile = 1;
|
||||
this.AmmoHolder.MaterialName = itemInHand;
|
||||
((Player)player).sendMessage("§eAdding Ammo to Weapon");
|
||||
itemInHand.setAmount(itemInHand.getAmount() - 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SaveState() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Location GetFireLocation(LivingEntity living) {
|
||||
Location loc = living.getEyeLocation();
|
||||
Vector direction = living.getLocation().getDirection().multiply(XOffset);
|
||||
loc.add(direction);
|
||||
if (this.YOffset > 0) {
|
||||
loc.setY(loc.getY() + this.YOffset);
|
||||
}
|
||||
else {
|
||||
loc.setY(loc.getY() - this.YOffset);
|
||||
}
|
||||
loc.setPitch(loc.getPitch() + this.PitchOffset);
|
||||
return loc;
|
||||
}
|
||||
|
||||
public void ShowFireLocation(Entity player) {
|
||||
LivingEntity living = (LivingEntity) this.Entity;
|
||||
if (player instanceof Player) {
|
||||
if (living != null) {
|
||||
Location origin = this.GetFireLocation(living);
|
||||
Vector direction = origin.getDirection();
|
||||
direction.multiply(5 /* the range */);
|
||||
Location destination = origin.clone().add(direction);
|
||||
|
||||
direction.normalize();
|
||||
for (int i = 0; i < 3 /* range */; i+= 1) {
|
||||
Location spawn = origin.add(direction);
|
||||
((Player)player).spawnParticle(Particle.CLOUD, spawn, 1, 0,0,0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Fire(Entity player, float delay, Integer amount) {
|
||||
if (amount == null || amount == 0)
|
||||
amount = this.shotAmount;
|
||||
this.shotAmount = amount;
|
||||
if (System.currentTimeMillis() < this.NextShotTime) {
|
||||
return;
|
||||
}
|
||||
if (this.AmmoHolder.LoadedFuel <= 0)
|
||||
this.AmmoHolder.LoadedFuel = 3;
|
||||
float loadedFuel = this.AmmoHolder.LoadedFuel;
|
||||
ItemStack LoadedProjectile = this.AmmoHolder.MaterialName;
|
||||
|
||||
|
||||
LivingEntity living = (LivingEntity) Entity;
|
||||
if (living == null || living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (living.getEquipment().getHelmet().getItemMeta().getCustomModelData() != this.ReadyModelNumber) {
|
||||
if (player instanceof Player) {
|
||||
((Player)player).sendMessage("§eCannot fire yet!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.AmmoHolder.LoadedFuel = 0;
|
||||
this.AmmoHolder.LoadedProjectile = 0;
|
||||
this.AmmoHolder.MaterialName = new ItemStack(Material.AIR, 1);
|
||||
|
||||
this.WorldName = Entity.getWorld().getName();
|
||||
this.NextShotTime = System.currentTimeMillis() + 1000;
|
||||
for (int i = 0; i <= this.shotAmount /* range */; i+= 1) {
|
||||
if (this.CycleThroughModelsBeforeFiring) {
|
||||
|
||||
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(GunnersCore.plugin, () -> {
|
||||
|
||||
if (this.HasFired) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
|
||||
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(GunnersCore.plugin, () -> {
|
||||
|
||||
// player.sendMessage("§etask");
|
||||
if (this.HasReloaded) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
|
||||
this.HasReloaded = false;
|
||||
this.HasFired = false;
|
||||
this.NextModelNumber = 0;
|
||||
GunnersCore.UpdateEntityIdModel(this.Entity, this.ReadyModelNumber, this.WorldName);
|
||||
this.TaskNumber = 0;
|
||||
}
|
||||
else {
|
||||
//firing stages
|
||||
if (this.NextModelNumber - 1 <= this.FiringModelNumbers.size() && this.NextModelNumber - 1 >= 0) {
|
||||
int modelData = this.FiringModelNumbers.get(this.NextModelNumber - 1);
|
||||
// player.sendMessage("§e" + modelData);
|
||||
GunnersCore.UpdateEntityIdModel(this.Entity, modelData, this.WorldName);
|
||||
this.NextModelNumber -= 1;
|
||||
|
||||
}else {
|
||||
// plugin.getLogger().log(Level.INFO, "its reloaded");
|
||||
this.HasReloaded = true;
|
||||
}
|
||||
}
|
||||
}, 0, this.MillisecondsBetweenReloadingStages);
|
||||
|
||||
}
|
||||
else {
|
||||
//firing stages
|
||||
if (this.NextModelNumber < this.FiringModelNumbers.size()) {
|
||||
|
||||
int modelData = this.FiringModelNumbers.get(this.NextModelNumber);
|
||||
// player.sendMessage("§e" + modelData);
|
||||
GunnersCore.UpdateEntityIdModel(this.Entity, modelData, this.WorldName);
|
||||
if (modelData == this.ModelNumberToFireAt) {
|
||||
// player.sendMessage("§efiring" + modelData);
|
||||
Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, this.GetFireLocation(living), loadedFuel * this.VelocityPerFuel);
|
||||
}
|
||||
this.NextModelNumber += 1;
|
||||
|
||||
}else {
|
||||
this.HasFired = true;
|
||||
|
||||
}
|
||||
}
|
||||
}, 0, this.MillisecondsBetweenFiringStages);
|
||||
} else {
|
||||
|
||||
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(GunnersCore.plugin, () -> {
|
||||
//player.sendMessage("§etask");
|
||||
|
||||
Location loc = living.getEyeLocation();
|
||||
Vector direction = Entity.getLocation().getDirection().multiply(XOffset);
|
||||
|
||||
loc.add(direction);
|
||||
|
||||
this.NextModelNumber = 0;
|
||||
|
||||
Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, this.GetFireLocation(living), loadedFuel * this.VelocityPerFuel);
|
||||
}, (long) delay);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,449 +0,0 @@
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.ArmorStand.LockType;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Mule;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Snowball;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.inventory.InventoryType.SlotType;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
|
||||
//import com.palmergames.bukkit.towny.Towny;
|
||||
|
||||
//import GunnersProjectiles.EntityProjectile;
|
||||
//import GunnersProjectiles.GunnersProjectile;
|
||||
//import GunnersProjectiles.ExplosiveProjectile;
|
||||
//import GunnersProjectiles.PotionProjectile;
|
||||
|
||||
public class GunnersCore extends JavaPlugin {
|
||||
public static Plugin plugin;
|
||||
|
||||
public static Random random = new Random();
|
||||
private static String Path;
|
||||
|
||||
//public static Towny towny;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onDisable() {
|
||||
for (GunnerEquipment equip : equipment.values()) {
|
||||
if (equip.Entity != null) {
|
||||
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
equip.AmmoHolder = new EquipmentMagazine();
|
||||
|
||||
meta.setCustomModelData(equip.ReadyModelNumber);
|
||||
meta.setDisplayName("§e" + equip.EquipmentName +" Item");
|
||||
List<String> Lore = new ArrayList<String>();
|
||||
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand.");
|
||||
meta.setLore(Lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
((LivingEntity) equip.Entity).getEquipment().setHelmet(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
Path = this.getDataFolder().getAbsolutePath();
|
||||
this.getCommand("gunnerscore").setExecutor(new GunnersCommand());
|
||||
getServer().getPluginManager().registerEvents(new RotationHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new ClickHandler(), this);
|
||||
//StorageManager.setup(Path, plugin);
|
||||
equipment.clear();
|
||||
TrackedStands.clear();
|
||||
DefinedEquipment.clear();
|
||||
AddDefaults();
|
||||
HashMap<ItemStack,GunnersProjectile> projObj = new HashMap<>();
|
||||
GunnerEquipment equip = CreateNewGun(null, null, null, null, null, null, projObj);
|
||||
for (GunnerEquipment i : DefinedEquipment.values()) {
|
||||
System.out.println("§eEnabled Weapon : "+i.EquipmentName);
|
||||
System.out.println("§eWeapon Propellant/\"Fuel\" ItemStacks : "+i.FuelMaterial);
|
||||
for (ItemStack proj : i.Projectiles.keySet()) {
|
||||
System.out.println("§eWeapon Projectile ItemStacks : "+proj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class GunnersCommand implements CommandExecutor {
|
||||
@Override
|
||||
@EventHandler
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
Player player = null;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
}
|
||||
if (args != null && args.length > 0) {
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "get":
|
||||
if (player == null) {
|
||||
sender.sendMessage("§eonly a player can use this command.");
|
||||
return true;
|
||||
}
|
||||
if (!sender.hasPermission("gunnerscore.get")) {
|
||||
sender.sendMessage("§eNo perms to gunnerscore.get");
|
||||
return true;
|
||||
}
|
||||
for (GunnerEquipment i : DefinedEquipment.values()) {
|
||||
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setCustomModelData(i.ReadyModelNumber);
|
||||
meta.setDisplayName("§e" + i.EquipmentName +" Item");
|
||||
List<String> Lore = new ArrayList<String>();
|
||||
Lore.add("§ePlace as a block to spawn a " + i.EquipmentName);
|
||||
Lore.add("§eor put on an Armor Stand.");
|
||||
Lore.add("§eRight click to toggle visibility of stand.");
|
||||
meta.setLore(Lore);
|
||||
item.setItemMeta(meta);
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
break;
|
||||
case "reload":
|
||||
if (!sender.hasPermission("gunnerscore.reload")) {
|
||||
sender.sendMessage("§eNo perms to gunnerscore.reload");
|
||||
return true;
|
||||
}
|
||||
equipment.clear();
|
||||
TrackedStands.clear();
|
||||
DefinedEquipment.clear();
|
||||
AddDefaults();
|
||||
HashMap<ItemStack,GunnersProjectile> projObj = new HashMap<>();
|
||||
GunnerEquipment equip = CreateNewGun(null, null, null, null, null, null, projObj);
|
||||
for (GunnerEquipment i : DefinedEquipment.values()) {
|
||||
sender.sendMessage("§eEnabled Weapon : "+i.EquipmentName);
|
||||
sender.sendMessage("§eWeapon Propellant/\"Fuel\" ItemStacks : "+i.FuelMaterial);
|
||||
for (ItemStack proj : i.Projectiles.keySet()) {
|
||||
sender.sendMessage("§eWeapon Projectile ItemStacks : "+proj);
|
||||
}
|
||||
}
|
||||
sender.sendMessage("§eGunners Core configs reloaded");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
sender.sendMessage("§eIncorrect usage, /gunnerscore get, /gunnerscore reload");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static GunnerEquipment CreateClone(Integer ModelId) {
|
||||
try {
|
||||
return DefinedEquipment.get(ModelId).clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, GunnerEquipment> DefinedEquipment = new HashMap<Integer, GunnerEquipment>();
|
||||
|
||||
public static HashMap<UUID, List<Entity>> TrackedStands = new HashMap<UUID, List<Entity>>();
|
||||
|
||||
public static HashMap<UUID, GunnerEquipment> equipment = new HashMap<UUID, GunnerEquipment>();
|
||||
|
||||
public static String convertTime(long time){
|
||||
|
||||
long days = TimeUnit.MILLISECONDS.toDays(time);
|
||||
time -= TimeUnit.DAYS.toMillis(days);
|
||||
|
||||
long hours = TimeUnit.MILLISECONDS.toHours(time);
|
||||
time -= TimeUnit.HOURS.toMillis(hours);
|
||||
|
||||
long minutes = TimeUnit.MILLISECONDS.toMinutes(time);
|
||||
time -= TimeUnit.MINUTES.toMillis(minutes);
|
||||
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(time);
|
||||
String timeLeftFormatted = String.format("§e" + minutes + " Minutes " +seconds +" Seconds§f");
|
||||
|
||||
return timeLeftFormatted;
|
||||
}
|
||||
public static GunnerEquipment CreateNewGun(String name, Integer XOffset, Integer YOffset, Integer fuelMax, Float fuelVelocityMod, Integer customModelId, HashMap<ItemStack,GunnersProjectile> projObj) {
|
||||
GunnerEquipment equip = new GunnerEquipment();
|
||||
if (customModelId == null || customModelId == 0)
|
||||
customModelId = 150;
|
||||
if (name == null)
|
||||
name = "Peckle Gun";
|
||||
if (XOffset == null)
|
||||
XOffset = 0;
|
||||
if (YOffset == null)
|
||||
YOffset = 0;
|
||||
if (fuelMax == null)
|
||||
fuelMax = 0;
|
||||
if (fuelVelocityMod == null)
|
||||
fuelVelocityMod = 0.95f;
|
||||
equip.EquipmentName = name;
|
||||
equip.XOffset = XOffset;
|
||||
equip.YOffset = YOffset;
|
||||
equip.RotateStandHead = true;
|
||||
equip.RotateSideways = true;
|
||||
equip.PlacementOffsetY = -1.125f;
|
||||
equip.ReadyModelNumber = customModelId;
|
||||
equip.ModelNumberToFireAt = customModelId;
|
||||
equip.FiringModelNumbers = new ArrayList<Integer>();
|
||||
equip.VelocityPerFuel = fuelVelocityMod;
|
||||
equip.FuelMaterial = new ItemStack(Material.GUNPOWDER);
|
||||
equip.CycleThroughModelsBeforeFiring = false;
|
||||
equip.MaxFuel = fuelMax;
|
||||
equip.shotAmount = 1;
|
||||
equip.AmmoHolder.LoadedFuel = fuelMax;
|
||||
EntityProjectile defaultProj = new EntityProjectile();
|
||||
defaultProj.EntityCount = 6;
|
||||
defaultProj.EntityTyp = EntityType.SHULKER_BULLET;
|
||||
defaultProj.ParticleType = Particle.WHITE_ASH;
|
||||
defaultProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
|
||||
if (projObj.keySet().isEmpty() || projObj.isEmpty())
|
||||
projObj.put(new ItemStack(Material.GUNPOWDER),defaultProj);
|
||||
for (ItemStack mat : projObj.keySet()) {
|
||||
equip.Projectiles.put(mat,projObj.get(mat));
|
||||
}
|
||||
DefinedEquipment.put(equip.ReadyModelNumber,equip);
|
||||
return equip;
|
||||
}
|
||||
|
||||
public static void AddDefaults() {
|
||||
GunnerEquipment equip = new GunnerEquipment();
|
||||
equip.EquipmentName = "Trebuchet";
|
||||
equip.XOffset = 5;
|
||||
equip.YOffset = 5;
|
||||
equip.VelocityPerFuel = 0.3f;
|
||||
ExplosiveProjectile proj = new ExplosiveProjectile();
|
||||
proj.ExplodePower = 2;
|
||||
equip.RotateStandHead = false;
|
||||
equip.RotateSideways = true;
|
||||
equip.FuelMaterial = new ItemStack(Material.STRING);
|
||||
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
|
||||
equip.ReadyModelNumber = 122;
|
||||
equip.ModelNumberToFireAt = 135;
|
||||
equip.MillisecondsBetweenFiringStages = 2;
|
||||
equip.MillisecondsBetweenReloadingStages = 10;
|
||||
equip.FiringModelNumbers = new ArrayList<>(Arrays.asList(
|
||||
123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139
|
||||
));
|
||||
equip.CycleThroughModelsBeforeFiring = true;
|
||||
DefinedEquipment.put(equip.ReadyModelNumber, equip);
|
||||
|
||||
equip = new GunnerEquipment();
|
||||
equip.EquipmentName = "Naval Cannon";
|
||||
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
|
||||
equip.PlacementOffsetY = -1;
|
||||
equip.ReadyModelNumber = 142;
|
||||
equip.ModelNumberToFireAt = 142;
|
||||
equip.FiringModelNumbers = new ArrayList<Integer>();
|
||||
equip.RotateStandHead = true;
|
||||
equip.RotateSideways = false;
|
||||
proj = new ExplosiveProjectile();
|
||||
proj.ExplodePower = 1;
|
||||
proj.ProjectilesCount = 3;
|
||||
proj.DelayedFire = true;
|
||||
proj.Inaccuracy = 0.75f;
|
||||
equip.Projectiles.put(new ItemStack(Material.TNT), proj);
|
||||
proj = new ExplosiveProjectile();
|
||||
proj.ExplodePower = 4;
|
||||
proj.ProjectilesCount = 1;
|
||||
equip.Projectiles.put(new ItemStack(Material.COPPER_BLOCK), proj);
|
||||
|
||||
EntityProjectile fireProj = new EntityProjectile();
|
||||
fireProj.EntityCount = 2;
|
||||
fireProj.EntityTyp = EntityType.SMALL_FIREBALL;
|
||||
fireProj.ParticleType = Particle.WHITE_ASH;
|
||||
fireProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
|
||||
equip.Projectiles.put(new ItemStack(Material.FIRE_CHARGE), fireProj);
|
||||
DefinedEquipment.put(equip.ReadyModelNumber, equip);
|
||||
equip = new GunnerEquipment();
|
||||
equip.EquipmentName = "Siege Cannon";
|
||||
proj.ExplodePower = 2;
|
||||
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
|
||||
equip.PlacementOffsetY = -1;
|
||||
equip.ReadyModelNumber = 141;
|
||||
equip.ModelNumberToFireAt = 141;
|
||||
equip.FiringModelNumbers = new ArrayList<Integer>();
|
||||
equip.RotateStandHead = true;
|
||||
equip.RotateSideways = true;
|
||||
proj = new ExplosiveProjectile();
|
||||
proj.ExplodePower = 1;
|
||||
proj.ProjectilesCount = 3;
|
||||
proj.DelayedFire = true;
|
||||
proj.Inaccuracy = 0.5f;
|
||||
equip.Projectiles.put(new ItemStack(Material.TNT), proj);
|
||||
proj = new ExplosiveProjectile();
|
||||
proj.ExplodePower = 4;
|
||||
proj.ProjectilesCount = 1;
|
||||
equip.Projectiles.put(new ItemStack(Material.COPPER_BLOCK), proj);
|
||||
equip.Projectiles.put(new ItemStack(Material.GRAVEL), new EntityProjectile());
|
||||
DefinedEquipment.put(equip.ReadyModelNumber, equip);
|
||||
// EntityProjectile pig = new EntityProjectile();
|
||||
// pig.EntityCount = 100;
|
||||
// pig.DelayedFire = true;
|
||||
// pig.DelayTime = 3;
|
||||
// pig.EntityTyp = EntityType.ARROW;
|
||||
// pig.SoundType = Sound.ITEM_CROSSBOW_SHOOT;
|
||||
// pig.ParticleType = Particle.GLOW;
|
||||
// equip.Projectiles.put(Material.PORKCHOP, pig);
|
||||
// equip.Projectiles.put(Material.BONE, new PotionProjectile());
|
||||
|
||||
}
|
||||
|
||||
public static Boolean CreateCannon(Entity player, int CustomModelData, Location l) {
|
||||
//l.setY(l.getY() - 1);
|
||||
l.add(0.5, 0, 0.5);
|
||||
NamespacedKey key = new NamespacedKey(GunnersCore.plugin, "cannons");
|
||||
GunnerEquipment equip = CreateClone(CustomModelData);
|
||||
if (equip == null || !equip.Enabled) {
|
||||
return false;
|
||||
}
|
||||
l.setY(l.getY() + 1);
|
||||
|
||||
l.setDirection(player.getFacing().getDirection());
|
||||
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
String id = "";
|
||||
equip.AmmoHolder = new EquipmentMagazine();
|
||||
if (equip.HaseBaseStand) {
|
||||
|
||||
|
||||
Location l2 = l;
|
||||
l2.setY(l.getY() + equip.BaseStandOffset);
|
||||
Entity entity3 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
|
||||
|
||||
LivingEntity ent = (LivingEntity) entity3;
|
||||
ArmorStand stand = (ArmorStand) ent;
|
||||
id = entity3.getUniqueId().toString();
|
||||
meta.setCustomModelData(equip.BaseStandModelNumber);
|
||||
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.REMOVING_OR_CHANGING);
|
||||
stand.setBasePlate(false);
|
||||
// stand.setSmall(true);
|
||||
item.setItemMeta(meta);
|
||||
stand.setInvisible(equip.AllowInvisibleStand);
|
||||
ent.getEquipment().setHelmet(item);
|
||||
stand.setGravity(false);
|
||||
stand.setMarker(true);
|
||||
}
|
||||
l.setY(l.getY() + equip.PlacementOffsetY);
|
||||
Entity entity2 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
|
||||
if (id != "") {
|
||||
entity2.getPersistentDataContainer().set(key, PersistentDataType.STRING, id);
|
||||
}
|
||||
meta.setCustomModelData(equip.ReadyModelNumber);
|
||||
meta.setDisplayName("§e" + equip.EquipmentName +" Item");
|
||||
List<String> Lore = new ArrayList<String>();
|
||||
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand.");
|
||||
meta.setLore(Lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
// entity3.addPassenger(entity2);
|
||||
|
||||
LivingEntity ent = (LivingEntity) entity2;
|
||||
ArmorStand stand = (ArmorStand) ent;
|
||||
equip.Entity = entity2;
|
||||
|
||||
equip.EntityId = entity2.getUniqueId();
|
||||
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.REMOVING_OR_CHANGING);
|
||||
stand.setInvisible(equip.AllowInvisibleStand);
|
||||
stand.setBasePlate(false);
|
||||
ent.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2000000, 1));
|
||||
// stand.setSmall(true);
|
||||
|
||||
stand.setGravity(false);
|
||||
//stand.setSmall(true);
|
||||
ent.getEquipment().setHelmet(item);
|
||||
if (TrackedStands.containsKey(player.getUniqueId())) {
|
||||
List<Entity> entities = TrackedStands.get(player.getUniqueId());
|
||||
entities.add(entity2);
|
||||
TrackedStands.put(player.getUniqueId(), entities);
|
||||
}
|
||||
else {
|
||||
List<Entity> newList = new ArrayList<Entity>();
|
||||
newList.add(entity2);
|
||||
TrackedStands.put(player.getUniqueId(), newList);
|
||||
}
|
||||
equipment.put(entity2.getUniqueId(), equip);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void UpdateEntityIdModel(Entity ent, int modelNumber, String WorldName) {
|
||||
if (ent instanceof LivingEntity)
|
||||
{
|
||||
LivingEntity liv = (LivingEntity) ent;
|
||||
ItemStack Helmet = liv.getEquipment().getHelmet();
|
||||
if (Helmet != null) {
|
||||
ItemMeta meta = Helmet.getItemMeta();
|
||||
meta.setCustomModelData(modelNumber);
|
||||
Helmet.setItemMeta(meta);
|
||||
liv.getEquipment().setHelmet(Helmet);
|
||||
// plugin.getLogger().log(Level.INFO, "Updating stand?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public interface GunnersProjectile {
|
||||
public void Shoot(Entity player, Entity entity, Location fireLocation, Float velocity);
|
||||
public String ProjectileType = "Default";
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.SplashPotion;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
|
||||
public class PotionProjectile implements GunnersProjectile {
|
||||
public String ProjectileType = "Potion";
|
||||
public int EntityCount = 3;
|
||||
public Boolean DelayedFire = false;
|
||||
public int DelayTime = 6;
|
||||
public float Inaccuracy = 0.1f;
|
||||
public Particle ParticleType = Particle.EXPLOSION_LARGE;
|
||||
public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE;
|
||||
|
||||
@Override
|
||||
public void Shoot(Entity player, Entity entity, Location loc, Float velocity) {
|
||||
// TODO Auto-generated method stub
|
||||
int baseDelay = 0;
|
||||
for (int i = 0; i < EntityCount; i++) {
|
||||
if (DelayedFire) {
|
||||
baseDelay += DelayTime;
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(GunnersCore.plugin, () -> {
|
||||
|
||||
CreateEntity(entity,loc, velocity);
|
||||
}, (long) baseDelay);
|
||||
}
|
||||
else {
|
||||
|
||||
CreateEntity(entity, loc, velocity);
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
}
|
||||
private void CreateEntity(Entity entity, Location loc, Float velocity) {
|
||||
World world = entity.getLocation().getWorld();
|
||||
LivingEntity living = (LivingEntity) entity;
|
||||
|
||||
Entity arrow = world.spawnEntity(loc, EntityType.SPLASH_POTION);
|
||||
if (Inaccuracy != 0f) {
|
||||
arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
|
||||
.subtract(Randomise()));
|
||||
}
|
||||
else {
|
||||
arrow.setVelocity(loc.getDirection().multiply(velocity));
|
||||
}
|
||||
ItemStack itemStack = new ItemStack(Material.SPLASH_POTION);
|
||||
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
|
||||
potionMeta.addCustomEffect(new PotionEffect(PotionEffectType.HARM, 100, 3, true), true);
|
||||
itemStack.setItemMeta(potionMeta);
|
||||
ThrownPotion potion = (ThrownPotion) arrow;
|
||||
potion.setItem(itemStack);
|
||||
// MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.DROPPED_ITEM, Material.IRON_NUGGET);
|
||||
// DisguiseAPI.disguiseEntity(arrow, miscDisguise);
|
||||
world.playSound(loc, this.SoundType, 20, 2);
|
||||
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
|
||||
}
|
||||
|
||||
private Vector Randomise() {
|
||||
return new Vector(GunnersCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),GunnersCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),GunnersCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1));
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.util.BlockIterator;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class RotationHandler implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void playerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
NamespacedKey key = new NamespacedKey(GunnersCore.plugin, "cannons");
|
||||
if (GunnersCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||
if (itemInHand != null) {
|
||||
if (itemInHand.getType() != Material.BOOK) {
|
||||
// TrackedStands.remove(player.getUniqueId());
|
||||
|
||||
return;
|
||||
}
|
||||
for (Entity ent : GunnersCore.TrackedStands.get(player.getUniqueId())) {
|
||||
if (ent != null) {
|
||||
GunnerEquipment equipment = GunnersCore.equipment.get(ent.getUniqueId());
|
||||
if (ent.isDead()) {
|
||||
continue;
|
||||
}
|
||||
double distance = player.getLocation().distance(ent.getLocation());
|
||||
if (distance <= 250) {
|
||||
// player.sendMessage("§egot id");
|
||||
LivingEntity living = (LivingEntity) ent;
|
||||
Location loc = ent.getLocation();
|
||||
|
||||
if (equipment.RotateSideways) {
|
||||
Location direction = player.getLocation().add(player.getLocation().getDirection().multiply(50));
|
||||
|
||||
Vector dirBetweenLocations = direction.toVector().subtract(loc.toVector());
|
||||
if (ent.getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
|
||||
Entity base = Bukkit.getEntity(UUID.fromString(ent.getPersistentDataContainer().get(key, PersistentDataType.STRING)));
|
||||
Location baseloc = base.getLocation();
|
||||
baseloc.setDirection(dirBetweenLocations);
|
||||
base.teleport(baseloc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
loc.setDirection(dirBetweenLocations);
|
||||
}
|
||||
// loc.setYaw(player.getLocation().getYaw());
|
||||
//loc.setPitch(player.getLocation().getPitch());
|
||||
|
||||
|
||||
ArmorStand stand = (ArmorStand) living;
|
||||
|
||||
if (equipment.RotateUpDown) {
|
||||
loc.setPitch(player.getLocation().getPitch());
|
||||
if (loc.getPitch() < -85) {
|
||||
loc.setPitch(-85);
|
||||
}
|
||||
if (loc.getPitch() > 85) {
|
||||
loc.setPitch(85);
|
||||
}
|
||||
if (equipment.RotateStandHead) {
|
||||
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
living.teleport(loc);
|
||||
equipment.ShowFireLocation(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector getDirectionBetweenLocations(Location Start, Location End) {
|
||||
Vector from = Start.toVector();
|
||||
Vector to = End.toVector();
|
||||
return to.subtract(from);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user