mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-01 22:22:10 +00:00
GunnersCore1.0 by C_Corp2002
This commit is contained in:
1 parent
04ac406117
commit
46504b4166
39 files changed
+949
-672
No files matched your search
+280
-135
@@ -1,4 +1,4 @@
|
||||
package siegeCore;
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -16,6 +16,7 @@ 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;
|
||||
@@ -41,8 +42,10 @@ 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;
|
||||
@@ -50,11 +53,11 @@ 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 com.palmergames.bukkit.towny.TownyAPI;
|
||||
//import com.palmergames.bukkit.towny.event.actions.TownyDestroyEvent;
|
||||
//import com.palmergames.bukkit.towny.object.TownBlock;
|
||||
|
||||
import CrunchProjectiles.ExplosiveProjectile;
|
||||
//import GunnersProjectiles.ExplosiveProjectile;
|
||||
|
||||
public class ClickHandler implements Listener {
|
||||
|
||||
@@ -66,7 +69,7 @@ public class ClickHandler implements Listener {
|
||||
for (Entity entity : e.getEntity().getNearbyEntities(e.getYield() + 1, e.getYield()+ 1, e.getYield()+ 1)) {
|
||||
if(entity instanceof ArmorStand) {
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
if (CrunchSiegeCore.towny != null) {
|
||||
/*if (GunnersCore.towny != null) {
|
||||
TownBlock block = TownyAPI.getInstance().getTownBlock(stand.getLocation());
|
||||
if (block != null) {
|
||||
if (block.hasTown()) {
|
||||
@@ -75,7 +78,8 @@ public class ClickHandler implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
stand.eject();
|
||||
stand.remove();
|
||||
}
|
||||
}
|
||||
@@ -87,9 +91,9 @@ public class ClickHandler implements Listener {
|
||||
ExplosiveProjectile proj = projectiles.get(event.getEntity().getUniqueId());
|
||||
Entity snowball = event.getEntity();
|
||||
Snowball ball = (Snowball) snowball;
|
||||
Player player = (Player) ball.getShooter();
|
||||
if (player != null) {
|
||||
player.sendMessage("Distance to impact: " + String.format("%.2f",player.getLocation().distance(ball.getLocation())));
|
||||
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();
|
||||
@@ -102,7 +106,7 @@ public class ClickHandler implements Listener {
|
||||
TNTPrimed tntEnt = (TNTPrimed) tnt;
|
||||
tntEnt.setYield(0);
|
||||
tntEnt.setFuseTicks(0);
|
||||
if (CrunchSiegeCore.towny != null) {
|
||||
/*if (GunnersCore.towny != null) {
|
||||
TownBlock block = TownyAPI.getInstance().getTownBlock(loc);
|
||||
if (block != null) {
|
||||
if (block.hasTown()) {
|
||||
@@ -111,12 +115,12 @@ public class ClickHandler implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
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(Material.COBWEB);
|
||||
replace.setType(proj.BlockToPlace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,21 +129,23 @@ public class ClickHandler implements Listener {
|
||||
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++)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -149,22 +155,20 @@ public class ClickHandler implements Listener {
|
||||
return list.get(rand.nextInt(list.size()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@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)
|
||||
{
|
||||
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 = CrunchSiegeCore.CreateTrebuchet(thePlayer, customModel, event.getBlockAgainst().getLocation());
|
||||
Boolean created = GunnersCore.CreateCannon(thePlayer, customModel, event.getBlockAgainst().getLocation());
|
||||
if (created) {
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
thePlayer.getInventory().setItemInMainHand(item);
|
||||
thePlayer.sendMessage("Equipment spawned!");
|
||||
}
|
||||
else {
|
||||
thePlayer.sendMessage("Equipment could not be spawned, is it enabled?");
|
||||
thePlayer.sendMessage("§eGunner Equipment spawned!");
|
||||
} else {
|
||||
thePlayer.sendMessage("§eGunner Equipment could not be spawned, is it enabled?");
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@@ -172,37 +176,72 @@ public class ClickHandler implements Listener {
|
||||
}
|
||||
|
||||
|
||||
public void Shoot(Player player, long delay) {
|
||||
public void Shoot(Entity player, long delay) {
|
||||
float actualDelay = delay;
|
||||
Boolean FirstShot = true;
|
||||
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())){{
|
||||
|
||||
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 >= 250) {
|
||||
|
||||
if (distance >= 127) {
|
||||
continue;
|
||||
}
|
||||
SiegeEquipment siege = CrunchSiegeCore.equipment.get(ent.getUniqueId());
|
||||
|
||||
GunnerEquipment siege = GunnersCore.equipment.get(ent.getUniqueId());
|
||||
|
||||
if (siege.isLoaded()) {
|
||||
siege.Fire(player, actualDelay);
|
||||
actualDelay += delay;
|
||||
if (player instanceof Player) {
|
||||
siege.Fire(player, actualDelay,0);
|
||||
actualDelay += delay;
|
||||
} else {
|
||||
siege.Fire(player,15,1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage("Equipment is not loaded");
|
||||
if (player instanceof Player) {}
|
||||
//player.sendMessage("§eAmmunition Not Loaded");
|
||||
}
|
||||
// player.sendMessage(String.format("§e" +actualDelay));
|
||||
// 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 rightClick(PlayerInteractEvent event) {
|
||||
public void interact(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
ItemStack ItemInHand = event.getPlayer().getInventory().getItemInMainHand();
|
||||
@@ -213,19 +252,97 @@ public class ClickHandler implements Listener {
|
||||
// if (ItemInHand.getType() == Material.PAPER) {
|
||||
// ItemMeta meta = ItemInHand.getItemMeta();
|
||||
// if (meta.hasCustomModelData() && meta.getCustomModelData() == 505050505) {
|
||||
// CrunchSiegeCore.CreateTrebuchet(player);
|
||||
// GunnersCore.CreateCannon(player);
|
||||
// ItemInHand.setAmount(ItemInHand.getAmount() - 1);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
if (event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
if (ItemInHand.getType() != Material.CLOCK) {
|
||||
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;
|
||||
}
|
||||
|
||||
Shoot(player, 6);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -254,10 +371,10 @@ public class ClickHandler implements Listener {
|
||||
|
||||
|
||||
|
||||
public static void TakeControl(Player player, Entity entity) {
|
||||
public static void TakeControl(Entity player, Entity entity) {
|
||||
LivingEntity living = (LivingEntity) entity;
|
||||
if (CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
List<Entity> entities = CrunchSiegeCore.TrackedStands.get(player.getUniqueId());
|
||||
if (GunnersCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
List<Entity> entities = GunnersCore.TrackedStands.get(player.getUniqueId());
|
||||
if (entities.contains(entity)) {
|
||||
return;
|
||||
}
|
||||
@@ -269,16 +386,21 @@ public class ClickHandler implements Listener {
|
||||
}
|
||||
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
SiegeEquipment equip;
|
||||
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 (CrunchSiegeCore.equipment.containsKey(entity.getUniqueId())) {
|
||||
equip = CrunchSiegeCore.equipment.get(entity.getUniqueId());
|
||||
if (GunnersCore.equipment.containsKey(entity.getUniqueId())) {
|
||||
equip = GunnersCore.equipment.get(entity.getUniqueId());
|
||||
if (equip == null || !equip.Enabled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
equip = CrunchSiegeCore.CreateClone(living.getEquipment().getHelmet().getItemMeta().getCustomModelData());
|
||||
equip = GunnersCore.CreateClone(living.getEquipment().getHelmet().getItemMeta().getCustomModelData());
|
||||
if (equip == null || !equip.Enabled) {
|
||||
return;
|
||||
}
|
||||
@@ -291,50 +413,41 @@ public class ClickHandler implements Listener {
|
||||
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
|
||||
stand.setBasePlate(false);
|
||||
if (CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
List<Entity> entities = CrunchSiegeCore.TrackedStands.get(player.getUniqueId());
|
||||
if (GunnersCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
List<Entity> entities = GunnersCore.TrackedStands.get(player.getUniqueId());
|
||||
entities.add(entity);
|
||||
CrunchSiegeCore.TrackedStands.put(player.getUniqueId(), entities);
|
||||
GunnersCore.TrackedStands.put(player.getUniqueId(), entities);
|
||||
}
|
||||
else {
|
||||
List<Entity> newList = new ArrayList<Entity>();
|
||||
newList.add(entity);
|
||||
CrunchSiegeCore.TrackedStands.put(player.getUniqueId(), newList);
|
||||
GunnersCore.TrackedStands.put(player.getUniqueId(), newList);
|
||||
}
|
||||
CrunchSiegeCore.equipment.put(entity.getUniqueId(), equip);
|
||||
player.sendMessage("§eNow controlling the equipment.");
|
||||
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 (!CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
if (!GunnersCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) {
|
||||
|
||||
for (Entity ent : GunnersCore.TrackedStands.get(player.getUniqueId())) {
|
||||
Ids.add(ent.getUniqueId().toString());
|
||||
}
|
||||
TileState state = (TileState) block.getState();
|
||||
NamespacedKey key = new NamespacedKey(CrunchSiegeCore.plugin, "cannons");
|
||||
state.getPersistentDataContainer().set(key, PersistentDataType.STRING, String.join(",", Ids));
|
||||
state.update();
|
||||
player.sendMessage("Saving cannons!");
|
||||
}
|
||||
TileState state = ((TileState) block.getState());
|
||||
NamespacedKey key = new NamespacedKey(GunnersCore.plugin, "cannons");
|
||||
|
||||
public void AimUp(Player player, float amount) {
|
||||
|
||||
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) {
|
||||
for (Entity ent : GunnersCore.TrackedStands.get(player.getUniqueId())) {
|
||||
if (ent.isDead()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DoAimUp(ent, amount, player);
|
||||
|
||||
DoAimUp(ent, 0, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DoAimUp(Entity ent, float amount, Player player) {
|
||||
public void DoAimUp(Entity ent, float amount, Entity player) {
|
||||
Location loc = ent.getLocation();
|
||||
ArmorStand stand = (ArmorStand) ent;
|
||||
// player.sendMessage(String.format("" + loc.getPitch()));
|
||||
@@ -342,32 +455,48 @@ public class ClickHandler implements Listener {
|
||||
return;
|
||||
}
|
||||
loc.setPitch((float) (loc.getPitch() - amount));
|
||||
SiegeEquipment equipment = CrunchSiegeCore.equipment.get(ent.getUniqueId());
|
||||
GunnerEquipment equipment = GunnersCore.equipment.get(ent.getUniqueId());
|
||||
if (equipment != null) {
|
||||
|
||||
equipment.ShowFireLocation(player);
|
||||
if (player instanceof Player)
|
||||
equipment.ShowFireLocation(player);
|
||||
if (equipment.RotateStandHead) {
|
||||
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
|
||||
}
|
||||
|
||||
ent.teleport(loc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ent.teleport(loc);
|
||||
}
|
||||
|
||||
public void DoAimDown(Entity ent, float amount, Player player) {
|
||||
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;
|
||||
}
|
||||
SiegeEquipment equipment = CrunchSiegeCore.equipment.get(ent.getUniqueId());
|
||||
GunnerEquipment equipment = GunnersCore.equipment.get(ent.getUniqueId());
|
||||
if (equipment != null) {
|
||||
|
||||
equipment.ShowFireLocation(player);
|
||||
if (player instanceof Player) {
|
||||
equipment.ShowFireLocation((Player)player);
|
||||
}
|
||||
if (equipment.RotateStandHead) {
|
||||
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
|
||||
|
||||
@@ -377,7 +506,8 @@ public class ClickHandler implements Listener {
|
||||
|
||||
ent.teleport(loc);
|
||||
}
|
||||
NamespacedKey key = new NamespacedKey(CrunchSiegeCore.plugin, "cannons");
|
||||
NamespacedKey key = new NamespacedKey(GunnersCore.plugin, "cannons");
|
||||
|
||||
@EventHandler
|
||||
public void DeathEvent(EntityDeathEvent event) {
|
||||
Boolean removeStands = false;
|
||||
@@ -387,13 +517,13 @@ public class ClickHandler implements Listener {
|
||||
Entity base = Bukkit.getEntity(UUID.fromString(event.getEntity().getPersistentDataContainer().get(key, PersistentDataType.STRING)));
|
||||
base.remove();
|
||||
}
|
||||
if (CrunchSiegeCore.equipment.containsKey(event.getEntity().getUniqueId())) {
|
||||
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 (CrunchSiegeCore.DefinedEquipment.containsKey(i.getItemMeta().getCustomModelData())) {
|
||||
if (GunnersCore.DefinedEquipment.containsKey(i.getItemMeta().getCustomModelData())) {
|
||||
removeStands = true;
|
||||
break;
|
||||
}
|
||||
@@ -412,37 +542,45 @@ public class ClickHandler implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public void AimDown(Player player, float amount) {
|
||||
public void AimUp(Entity player, float amount) {
|
||||
|
||||
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) {
|
||||
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(Player player) {
|
||||
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) {
|
||||
public void LoadCannonsWithPowder(Entity player) {
|
||||
for (Entity ent : GunnersCore.TrackedStands.get(player.getUniqueId())) {
|
||||
if (ent.isDead()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SiegeEquipment equipment = CrunchSiegeCore.equipment.get(ent.getUniqueId());
|
||||
GunnerEquipment equipment = GunnersCore.equipment.get(ent.getUniqueId());
|
||||
if (equipment != null) {
|
||||
equipment.LoadFuel(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadCannonsWithProjectile(Player player, ItemStack projectile) {
|
||||
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) {
|
||||
public void LoadCannonsWithProjectile(Entity player, ItemStack projectile) {
|
||||
for (Entity ent : GunnersCore.TrackedStands.get(player.getUniqueId())) {
|
||||
if (ent.isDead()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SiegeEquipment equipment = CrunchSiegeCore.equipment.get(ent.getUniqueId());
|
||||
GunnerEquipment equipment = GunnersCore.equipment.get(ent.getUniqueId());
|
||||
if (equipment != null) {
|
||||
equipment.LoadProjectile(player, projectile);
|
||||
}
|
||||
@@ -455,7 +593,7 @@ public class ClickHandler implements Listener {
|
||||
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 (!CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
if (!GunnersCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -463,15 +601,15 @@ public class ClickHandler implements Listener {
|
||||
if (delay < 6){
|
||||
delay = 6l;
|
||||
}
|
||||
Shoot(player, delay);
|
||||
Shoot((Entity)player, delay);
|
||||
} catch (Exception e) {
|
||||
Shoot(player, 6);
|
||||
Shoot((Entity)player, 6);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(sign.getLine(0).equalsIgnoreCase( "[Load]")){
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
LoadCannonsWithPowder(player);
|
||||
LoadCannonsWithPowder((Entity)player);
|
||||
return;
|
||||
}
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
@@ -482,27 +620,26 @@ public class ClickHandler implements Listener {
|
||||
}
|
||||
|
||||
|
||||
LoadCannonsWithProjectile(player, player.getInventory().getItemInMainHand());
|
||||
LoadCannonsWithProjectile((Entity)player, player.getInventory().getItemInMainHand());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(sign.getLine(0).equalsIgnoreCase( "[Aim]")){
|
||||
if (!CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
if (!GunnersCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
float amount;
|
||||
try {
|
||||
amount = Float.parseFloat(sign.getLine(1));
|
||||
if (player.isSneaking()) {
|
||||
AimDown(player, amount);
|
||||
}
|
||||
else {
|
||||
AimUp(player, amount);
|
||||
AimDown((Entity)player, amount);
|
||||
} else {
|
||||
AimUp((Entity)player, amount);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
player.sendMessage("Could not parse number on second line.");
|
||||
player.sendMessage("§eCould not parse number on second line.");
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -510,8 +647,8 @@ public class ClickHandler implements Listener {
|
||||
|
||||
if(sign.getLine(0).equalsIgnoreCase( "[Cannon]")){
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
CrunchSiegeCore.TrackedStands.remove(player.getUniqueId());
|
||||
player.sendMessage("Releasing the equipment!");
|
||||
GunnersCore.TrackedStands.remove(player.getUniqueId());
|
||||
player.sendMessage("§eReleasing the equipment!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -521,9 +658,9 @@ public class ClickHandler implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
NamespacedKey key = new NamespacedKey(CrunchSiegeCore.plugin, "cannons");
|
||||
NamespacedKey key = new NamespacedKey(GunnersCore.plugin, "cannons");
|
||||
TileState state = (TileState) sign.getBlock().getState();
|
||||
CrunchSiegeCore.TrackedStands.remove(player.getUniqueId());
|
||||
GunnersCore.TrackedStands.remove(player.getUniqueId());
|
||||
List<UUID> temp = new ArrayList<UUID>();
|
||||
if (!state.getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
|
||||
return;
|
||||
@@ -539,6 +676,7 @@ public class ClickHandler implements Listener {
|
||||
TakeControl(player, ent);
|
||||
}
|
||||
}
|
||||
player.sendMessage("§eNow controlling nearby equipment.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -556,7 +694,7 @@ public class ClickHandler implements Listener {
|
||||
}
|
||||
if (entity.getType() == EntityType.ARMOR_STAND){
|
||||
TakeControl(player, entity);
|
||||
if (CrunchSiegeCore.equipment.containsKey(entity.getUniqueId())) {
|
||||
if (GunnersCore.equipment.containsKey(entity.getUniqueId())) {
|
||||
if (itemInHand.getType() == Material.RECOVERY_COMPASS) {
|
||||
if (player.isSneaking()) {
|
||||
DoAimDown(entity, 1, player);
|
||||
@@ -567,42 +705,49 @@ public class ClickHandler implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
SiegeEquipment equipment = CrunchSiegeCore.equipment.get(entity.getUniqueId());
|
||||
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("Equipment is now breakable");
|
||||
player.sendMessage("§eEquipment is now breakable");
|
||||
}
|
||||
else{
|
||||
if (equipment.AllowInvisibleStand) {
|
||||
stand.setInvisible(true);
|
||||
player.sendMessage("Equipment is no longer breakable");
|
||||
player.sendMessage("§eEquipment is no longer breakable");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (itemInHand.getType().equals(equipment.FuelMaterial)) {
|
||||
if (!equipment.LoadFuel(player)) {
|
||||
player.sendMessage("Could not load Fuel.");
|
||||
}
|
||||
}
|
||||
if (itemInHand.getType().equals(Material.FLINT)) {
|
||||
if (equipment.isLoaded()) {
|
||||
equipment.Fire(player, 6);
|
||||
}
|
||||
else {
|
||||
player.sendMessage("Equipment is not loaded");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (equipment.Projectiles.containsKey(itemInHand.getType()) && equipment.AmmoHolder.LoadedProjectile == 0){
|
||||
equipment.AmmoHolder.LoadedProjectile = 1;
|
||||
equipment.AmmoHolder.MaterialName = (Material) itemInHand.getType();
|
||||
player.sendMessage("Adding projectile to equipment");
|
||||
itemInHand.setAmount(itemInHand.getAmount() - 1);
|
||||
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;
|
||||
}
|
||||
}
|
||||
+8
-9
@@ -1,4 +1,4 @@
|
||||
package CrunchProjectiles;
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -13,9 +13,8 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import siegeCore.CrunchSiegeCore;
|
||||
|
||||
public class EntityProjectile implements CrunchProjectile{
|
||||
public class EntityProjectile implements GunnersProjectile{
|
||||
|
||||
public String ProjectileType = "Entity";
|
||||
public int EntityCount = 20;
|
||||
@@ -27,13 +26,13 @@ public class EntityProjectile implements CrunchProjectile{
|
||||
public Particle ParticleType = Particle.EXPLOSION_LARGE;
|
||||
public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE;
|
||||
@Override
|
||||
public void Shoot(Player player, Entity entity, Location FireLocation, Float velocity) {
|
||||
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(CrunchSiegeCore.plugin, () -> {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(GunnersCore.plugin, () -> {
|
||||
|
||||
CreateEntity(entity, FireLocation, velocity, player);
|
||||
}, (long) baseDelay);
|
||||
@@ -47,10 +46,9 @@ public class EntityProjectile implements CrunchProjectile{
|
||||
}
|
||||
}
|
||||
private boolean PlaySound = true;
|
||||
private void CreateEntity(Entity entity, Location loc, Float velocity, Player player) {
|
||||
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) {
|
||||
@@ -64,7 +62,8 @@ public class EntityProjectile implements CrunchProjectile{
|
||||
if (arrow instanceof Arrow) {
|
||||
Arrow arr = (Arrow) arrow;
|
||||
arr.setDamage(8);
|
||||
arr.setShooter(player);
|
||||
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);
|
||||
@@ -80,7 +79,7 @@ public class EntityProjectile implements CrunchProjectile{
|
||||
}
|
||||
|
||||
private Vector Randomise() {
|
||||
return new Vector(CrunchSiegeCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),CrunchSiegeCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),CrunchSiegeCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
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);
|
||||
}
|
||||
+10
-13
@@ -1,4 +1,4 @@
|
||||
package CrunchProjectiles;
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -14,12 +14,10 @@ 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;
|
||||
import siegeCore.ClickHandler;
|
||||
import siegeCore.CrunchSiegeCore;
|
||||
//import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
//import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||
|
||||
public class ExplosiveProjectile implements CrunchProjectile {
|
||||
public class ExplosiveProjectile implements GunnersProjectile {
|
||||
|
||||
public String ProjectileType = "Explosive";
|
||||
public Boolean PlaceBlocks = false;
|
||||
@@ -35,18 +33,17 @@ public class ExplosiveProjectile implements CrunchProjectile {
|
||||
private boolean PlaySound = true;
|
||||
public Boolean AlertOnLanding = false;
|
||||
@Override
|
||||
public void Shoot(Player player, Entity entity, Location loc, Float velocity) {
|
||||
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(CrunchSiegeCore.plugin, () -> {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(GunnersCore.plugin, () -> {
|
||||
CreateEntity(entity, loc, velocity, player);
|
||||
}, (long) baseDelay);
|
||||
}
|
||||
else {
|
||||
|
||||
CreateEntity(entity,loc, velocity, player);
|
||||
}
|
||||
|
||||
@@ -54,13 +51,13 @@ public class ExplosiveProjectile implements CrunchProjectile {
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateEntity(Entity entity, Location loc, Float velocity, Player 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;
|
||||
|
||||
ball.setShooter(player);
|
||||
if (player instanceof org.bukkit.projectiles.ProjectileSource)
|
||||
ball.setShooter((org.bukkit.projectiles.ProjectileSource)player);
|
||||
ClickHandler.projectiles.put(tnt.getUniqueId(), this);
|
||||
|
||||
if (Inaccuracy != 0f) {
|
||||
@@ -85,7 +82,7 @@ public class ExplosiveProjectile implements CrunchProjectile {
|
||||
}
|
||||
|
||||
private Vector Randomise() {
|
||||
return new Vector(CrunchSiegeCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),CrunchSiegeCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),CrunchSiegeCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,273 @@
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+135
-90
@@ -1,10 +1,11 @@
|
||||
package siegeCore;
|
||||
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;
|
||||
@@ -53,34 +54,34 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
//import com.palmergames.bukkit.towny.Towny;
|
||||
|
||||
import CrunchProjectiles.EntityProjectile;
|
||||
import CrunchProjectiles.CrunchProjectile;
|
||||
import CrunchProjectiles.ExplosiveProjectile;
|
||||
import CrunchProjectiles.PotionProjectile;
|
||||
//import GunnersProjectiles.EntityProjectile;
|
||||
//import GunnersProjectiles.GunnersProjectile;
|
||||
//import GunnersProjectiles.ExplosiveProjectile;
|
||||
//import GunnersProjectiles.PotionProjectile;
|
||||
|
||||
public class CrunchSiegeCore extends JavaPlugin {
|
||||
public class GunnersCore extends JavaPlugin {
|
||||
public static Plugin plugin;
|
||||
|
||||
public static Random random = new Random();
|
||||
private static String Path;
|
||||
|
||||
public static Towny towny;
|
||||
//public static Towny towny;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onDisable() {
|
||||
for (SiegeEquipment equip : equipment.values()) {
|
||||
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 +" spawn item");
|
||||
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 armour stand.");
|
||||
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand.");
|
||||
meta.setLore(Lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
@@ -94,42 +95,26 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
Path = this.getDataFolder().getAbsolutePath();
|
||||
this.getCommand("crunchsiege").setExecutor(new SiegeCommand());
|
||||
this.getCommand("gunnerscore").setExecutor(new GunnersCommand());
|
||||
getServer().getPluginManager().registerEvents(new RotationHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new ClickHandler(), this);
|
||||
StorageManager.setup(Path, plugin);
|
||||
AddDefined();
|
||||
File f = new File(Path + "/Trebuchet.Json");
|
||||
if (!f.exists()) {
|
||||
for (SiegeEquipment i : DefinedEquipment.values()) {
|
||||
StorageManager.Save(i);
|
||||
}
|
||||
DefinedEquipment.clear();
|
||||
}
|
||||
LoadConfigs();
|
||||
towny = (Towny) Bukkit.getServer().getPluginManager().getPlugin("Towny");
|
||||
}
|
||||
|
||||
public static void LoadConfigs() {
|
||||
|
||||
File folder = new File(Path);
|
||||
File[] listOfFiles = folder.listFiles();
|
||||
//StorageManager.setup(Path, plugin);
|
||||
equipment.clear();
|
||||
TrackedStands.clear();
|
||||
for (int i = 0; i < listOfFiles.length; i++) {
|
||||
if (listOfFiles[i].isFile()) {
|
||||
SiegeEquipment equip = StorageManager.load(listOfFiles[i].getAbsolutePath());
|
||||
if (equip.Enabled) {
|
||||
DefinedEquipment.put(equip.ReadyModelNumber, equip);
|
||||
}
|
||||
else {
|
||||
plugin.getLogger().log(Level.ALL, "Equipment is not enabled, set Enabled to true to load it");
|
||||
}
|
||||
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 SiegeCommand implements CommandExecutor {
|
||||
public class GunnersCommand implements CommandExecutor {
|
||||
@Override
|
||||
@EventHandler
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
@@ -142,46 +127,58 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "get":
|
||||
if (player == null) {
|
||||
sender.sendMessage("only a player can use this command.");
|
||||
sender.sendMessage("§eonly a player can use this command.");
|
||||
return true;
|
||||
}
|
||||
if (!sender.hasPermission("crunchsiege.get")) {
|
||||
sender.sendMessage("No perms to crunchsiege.get");
|
||||
if (!sender.hasPermission("gunnerscore.get")) {
|
||||
sender.sendMessage("§eNo perms to gunnerscore.get");
|
||||
return true;
|
||||
}
|
||||
for (SiegeEquipment i : DefinedEquipment.values()) {
|
||||
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 +" spawn item");
|
||||
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 armour stand.");
|
||||
Lore.add("§eRight click to toggle visibility of stand.");
|
||||
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("crunchsiege.reload")) {
|
||||
sender.sendMessage("No perms to crunchsiege.reload");
|
||||
if (!sender.hasPermission("gunnerscore.reload")) {
|
||||
sender.sendMessage("§eNo perms to gunnerscore.reload");
|
||||
return true;
|
||||
}
|
||||
LoadConfigs();
|
||||
sender.sendMessage("Crunch siege configs reloaded");
|
||||
}
|
||||
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("Incorrect usage, /crunchsiege get, /crunchsiege reload");
|
||||
sender.sendMessage("§eIncorrect usage, /gunnerscore get, /gunnerscore reload");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static SiegeEquipment CreateClone(Integer ModelId) {
|
||||
public static GunnerEquipment CreateClone(Integer ModelId) {
|
||||
try {
|
||||
return DefinedEquipment.get(ModelId).clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
@@ -192,11 +189,11 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, SiegeEquipment> DefinedEquipment = new HashMap<Integer, SiegeEquipment>();
|
||||
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, SiegeEquipment> equipment = new HashMap<UUID, SiegeEquipment>();
|
||||
public static HashMap<UUID, GunnerEquipment> equipment = new HashMap<UUID, GunnerEquipment>();
|
||||
|
||||
public static String convertTime(long time){
|
||||
|
||||
@@ -210,13 +207,55 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
time -= TimeUnit.MINUTES.toMillis(minutes);
|
||||
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(time);
|
||||
String timeLeftFormatted = String.format("§e" + minutes + " Minutes " +seconds +" Seconds§f");
|
||||
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 AddDefined() {
|
||||
SiegeEquipment equip = new SiegeEquipment();
|
||||
public static void AddDefaults() {
|
||||
GunnerEquipment equip = new GunnerEquipment();
|
||||
equip.EquipmentName = "Trebuchet";
|
||||
equip.XOffset = 5;
|
||||
equip.YOffset = 5;
|
||||
@@ -225,8 +264,8 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
proj.ExplodePower = 2;
|
||||
equip.RotateStandHead = false;
|
||||
equip.RotateSideways = true;
|
||||
equip.FuelMaterial = Material.STRING;
|
||||
equip.Projectiles.put(Material.COBBLESTONE, proj);
|
||||
equip.FuelMaterial = new ItemStack(Material.STRING);
|
||||
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
|
||||
equip.ReadyModelNumber = 122;
|
||||
equip.ModelNumberToFireAt = 135;
|
||||
equip.MillisecondsBetweenFiringStages = 2;
|
||||
@@ -237,9 +276,9 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
equip.CycleThroughModelsBeforeFiring = true;
|
||||
DefinedEquipment.put(equip.ReadyModelNumber, equip);
|
||||
|
||||
equip = new SiegeEquipment();
|
||||
equip = new GunnerEquipment();
|
||||
equip.EquipmentName = "Naval Cannon";
|
||||
equip.Projectiles.put(Material.COBBLESTONE, proj);
|
||||
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
|
||||
equip.PlacementOffsetY = -1;
|
||||
equip.ReadyModelNumber = 142;
|
||||
equip.ModelNumberToFireAt = 142;
|
||||
@@ -250,24 +289,24 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
proj.ExplodePower = 1;
|
||||
proj.ProjectilesCount = 3;
|
||||
proj.DelayedFire = true;
|
||||
proj.Inaccuracy = 0.5f;
|
||||
equip.Projectiles.put(Material.TNT, proj);
|
||||
proj.Inaccuracy = 0.75f;
|
||||
equip.Projectiles.put(new ItemStack(Material.TNT), proj);
|
||||
proj = new ExplosiveProjectile();
|
||||
proj.ExplodePower = 4;
|
||||
proj.ProjectilesCount = 1;
|
||||
equip.Projectiles.put(Material.COPPER_BLOCK, proj);
|
||||
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(Material.FIRE_CHARGE, fireProj);
|
||||
equip.Projectiles.put(new ItemStack(Material.FIRE_CHARGE), fireProj);
|
||||
DefinedEquipment.put(equip.ReadyModelNumber, equip);
|
||||
equip = new SiegeEquipment();
|
||||
equip = new GunnerEquipment();
|
||||
equip.EquipmentName = "Siege Cannon";
|
||||
proj.ExplodePower = 2;
|
||||
equip.Projectiles.put(Material.COBBLESTONE, proj);
|
||||
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
|
||||
equip.PlacementOffsetY = -1;
|
||||
equip.ReadyModelNumber = 141;
|
||||
equip.ModelNumberToFireAt = 141;
|
||||
@@ -279,12 +318,12 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
proj.ProjectilesCount = 3;
|
||||
proj.DelayedFire = true;
|
||||
proj.Inaccuracy = 0.5f;
|
||||
equip.Projectiles.put(Material.TNT, proj);
|
||||
equip.Projectiles.put(new ItemStack(Material.TNT), proj);
|
||||
proj = new ExplosiveProjectile();
|
||||
proj.ExplodePower = 4;
|
||||
proj.ProjectilesCount = 1;
|
||||
equip.Projectiles.put(Material.COPPER_BLOCK, proj);
|
||||
equip.Projectiles.put(Material.GRAVEL, new EntityProjectile());
|
||||
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;
|
||||
@@ -298,21 +337,20 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
|
||||
}
|
||||
|
||||
public static Boolean CreateTrebuchet(Player player, int CustomModelData, Location l) {
|
||||
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(CrunchSiegeCore.plugin, "cannons");
|
||||
SiegeEquipment equip = CreateClone(CustomModelData);
|
||||
if (equip == null || !equip.Enabled) {
|
||||
return false;
|
||||
}
|
||||
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());
|
||||
|
||||
l.setDirection(player.getFacing().getDirection());
|
||||
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
String id = "";
|
||||
String id = "";
|
||||
equip.AmmoHolder = new EquipmentMagazine();
|
||||
if (equip.HaseBaseStand) {
|
||||
|
||||
@@ -329,23 +367,27 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
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.setInvisible(equip.AllowInvisibleStand);
|
||||
ent.getEquipment().setHelmet(item);
|
||||
stand.setGravity(false);
|
||||
stand.setMarker(true);
|
||||
}
|
||||
l.setY(l.getY() + equip.PlacementOffsetY);
|
||||
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 +" spawn item");
|
||||
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 armour stand.");
|
||||
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand.");
|
||||
meta.setLore(Lore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
@@ -360,11 +402,14 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
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.setInvisible(equip.AllowInvisibleStand);
|
||||
|
||||
stand.setGravity(false);
|
||||
//stand.setSmall(true);
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
package CrunchProjectiles;
|
||||
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 CrunchProjectile {
|
||||
|
||||
public void Shoot(Player player, Entity entity, Location fireLocation, Float velocity);
|
||||
public interface GunnersProjectile {
|
||||
public void Shoot(Entity player, Entity entity, Location fireLocation, Float velocity);
|
||||
public String ProjectileType = "Default";
|
||||
}
|
||||
|
||||
+5
-6
@@ -1,4 +1,4 @@
|
||||
package CrunchProjectiles;
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -20,9 +20,8 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import siegeCore.CrunchSiegeCore;
|
||||
|
||||
public class PotionProjectile implements CrunchProjectile {
|
||||
public class PotionProjectile implements GunnersProjectile {
|
||||
public String ProjectileType = "Potion";
|
||||
public int EntityCount = 3;
|
||||
public Boolean DelayedFire = false;
|
||||
@@ -32,13 +31,13 @@ public class PotionProjectile implements CrunchProjectile {
|
||||
public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE;
|
||||
|
||||
@Override
|
||||
public void Shoot(Player player, Entity entity, Location loc, Float velocity) {
|
||||
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(CrunchSiegeCore.plugin, () -> {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(GunnersCore.plugin, () -> {
|
||||
|
||||
CreateEntity(entity,loc, velocity);
|
||||
}, (long) baseDelay);
|
||||
@@ -76,6 +75,6 @@ public class PotionProjectile implements CrunchProjectile {
|
||||
}
|
||||
|
||||
private Vector Randomise() {
|
||||
return new Vector(CrunchSiegeCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),CrunchSiegeCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1),CrunchSiegeCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1));
|
||||
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));
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,4 +1,4 @@
|
||||
package siegeCore;
|
||||
package com.gunners.GunnersCore;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.UUID;
|
||||
@@ -27,24 +27,24 @@ public class RotationHandler implements Listener {
|
||||
@EventHandler
|
||||
public void playerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
NamespacedKey key = new NamespacedKey(CrunchSiegeCore.plugin, "cannons");
|
||||
if (CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
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.CLOCK) {
|
||||
if (itemInHand.getType() != Material.BOOK) {
|
||||
// TrackedStands.remove(player.getUniqueId());
|
||||
|
||||
return;
|
||||
}
|
||||
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) {
|
||||
for (Entity ent : GunnersCore.TrackedStands.get(player.getUniqueId())) {
|
||||
if (ent != null) {
|
||||
SiegeEquipment equipment = CrunchSiegeCore.equipment.get(ent.getUniqueId());
|
||||
GunnerEquipment equipment = GunnersCore.equipment.get(ent.getUniqueId());
|
||||
if (ent.isDead()) {
|
||||
continue;
|
||||
}
|
||||
double distance = player.getLocation().distance(ent.getLocation());
|
||||
if (distance <= 250) {
|
||||
// player.sendMessage("got id");
|
||||
// player.sendMessage("§egot id");
|
||||
LivingEntity living = (LivingEntity) ent;
|
||||
Location loc = ent.getLocation();
|
||||
|
||||
Binary file not shown.
Whitespace-only changes.
@@ -0,0 +1,31 @@
|
||||
/crunchsiege get - To get the items to sell in shops or etc use
|
||||
/crunchsiege reload - To reload configs
|
||||
|
||||
crunchsiege.get
|
||||
crunchsiege.reload
|
||||
|
||||
For movecraft compatibility, add this to your craft files
|
||||
onlyMovePlayers: false
|
||||
|
||||
Multi model capability for only 1 rotating part! :D
|
||||
|
||||
|
||||
|
||||
|
||||
To save controlled equipment to a sign use a [Cannon] sign
|
||||
Right click to take control, left click to release, Shift right click to resave
|
||||
[IMG]
|
||||
|
||||
To fire all cannons using a sign, use a [Fire] sign, with the second line being the sequence delay in integer, equipment can also be right clicked with a Flint to fire them.
|
||||
[IMG]
|
||||
|
||||
To rotate up/down use an [Aim] sign, with the second line being the amount to rotate by, shift right click and right click to use
|
||||
[IMG]
|
||||
|
||||
Aiming and firing can also be done with a clock.
|
||||
|
||||
Equipment must be loaded with gunpowder/string/other configured items and a projectile to be fired.
|
||||
|
||||
They can also be loaded with a [Load] sign, Left click to load the fuel, right click with the projectile in hand to load the projectile
|
||||
|
||||
[IMG]
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 63 KiB |
@@ -0,0 +1,9 @@
|
||||
name: GunnersCore
|
||||
main: com.gunners.GunnersCore.GunnersCore
|
||||
version: 0.3.0A
|
||||
api-version: 1.19
|
||||
commands:
|
||||
gunnerscore:
|
||||
description: GunnersCore Commands
|
||||
default: false
|
||||
usage: gunnerscore
|
||||
@@ -1,9 +0,0 @@
|
||||
package siegeCore;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class EquipmentMagazine {
|
||||
public int LoadedFuel = 0;
|
||||
public int LoadedProjectile = 0;
|
||||
public Material MaterialName = Material.BEDROCK;
|
||||
}
|
||||
@@ -1,255 +0,0 @@
|
||||
package siegeCore;
|
||||
|
||||
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 CrunchProjectiles.CrunchProjectile;
|
||||
import CrunchProjectiles.ExplosiveProjectile;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||
|
||||
public class SiegeEquipment implements Cloneable {
|
||||
|
||||
@Override
|
||||
public SiegeEquipment clone() throws CloneNotSupportedException {
|
||||
return (SiegeEquipment)super.clone();
|
||||
}
|
||||
public Boolean Enabled = true;
|
||||
public UUID EntityId;
|
||||
public Entity Entity;
|
||||
|
||||
public HashMap<Material, CrunchProjectile> Projectiles = new HashMap<Material, CrunchProjectile>() ;
|
||||
|
||||
public String WorldName;
|
||||
public String EquipmentName = "Cannon";
|
||||
public int XOffset = 7;
|
||||
public int YOffset = 0;
|
||||
public int PitchOffset = 0;
|
||||
public int MaxFuel = 5;
|
||||
public double PlacementOffsetY = 0;
|
||||
public float VelocityPerFuel = 0.75f;
|
||||
public Material FuelMaterial = 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() {
|
||||
return (AmmoHolder.LoadedFuel > 0 && AmmoHolder.LoadedProjectile >= 1);
|
||||
}
|
||||
|
||||
public Boolean CanLoadFuel() {
|
||||
return AmmoHolder.LoadedFuel < MaxFuel;
|
||||
}
|
||||
|
||||
public Boolean LoadFuel(Player player) {
|
||||
ItemStack fuelItem = new ItemStack(this.FuelMaterial, 1);
|
||||
if (AmmoHolder.LoadedFuel == this.MaxFuel) {
|
||||
return true;
|
||||
}
|
||||
if (player.getInventory().containsAtLeast(fuelItem, 1) || fuelItem.getType() == Material.AIR) {
|
||||
if (CanLoadFuel()) {
|
||||
AmmoHolder.LoadedFuel += 1;
|
||||
SaveState();
|
||||
player.getInventory().removeItem(fuelItem);
|
||||
player.sendMessage("Loaded " + this.AmmoHolder.LoadedFuel + "/" + this.MaxFuel);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public Boolean LoadProjectile(Player player, ItemStack itemInHand) {
|
||||
if (itemInHand.getAmount() <= 0) {
|
||||
return false;
|
||||
}
|
||||
if (this.Projectiles.containsKey(itemInHand.getType()) && this.AmmoHolder.LoadedProjectile == 0){
|
||||
this.AmmoHolder.LoadedProjectile = 1;
|
||||
this.AmmoHolder.MaterialName = (Material) itemInHand.getType();
|
||||
player.sendMessage("Adding projectile to cannon");
|
||||
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(Player player) {
|
||||
LivingEntity living = (LivingEntity) this.Entity;
|
||||
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.spawnParticle(Particle.CLOUD, spawn, 1, 0,0,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Fire(Player player, float delay) {
|
||||
if (System.currentTimeMillis() < this.NextShotTime) {
|
||||
player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
|
||||
return;
|
||||
}
|
||||
float loadedFuel = this.AmmoHolder.LoadedFuel;
|
||||
Material 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) {
|
||||
player.sendMessage("Cannot fire yet!");
|
||||
return;
|
||||
}
|
||||
this.AmmoHolder.LoadedFuel = 0;
|
||||
this.AmmoHolder.LoadedProjectile = 0;
|
||||
this.AmmoHolder.MaterialName = Material.BEDROCK;
|
||||
|
||||
this.WorldName = Entity.getWorld().getName();
|
||||
this.NextShotTime = System.currentTimeMillis() + 1000;
|
||||
if (this.CycleThroughModelsBeforeFiring) {
|
||||
|
||||
|
||||
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> {
|
||||
|
||||
if (this.HasFired) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
|
||||
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> {
|
||||
|
||||
// player.sendMessage("task");
|
||||
if (this.HasReloaded) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
|
||||
this.HasReloaded = false;
|
||||
this.HasFired = false;
|
||||
this.NextModelNumber = 0;
|
||||
CrunchSiegeCore.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("" + modelData);
|
||||
CrunchSiegeCore.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("" + modelData);
|
||||
CrunchSiegeCore.UpdateEntityIdModel(this.Entity, modelData, this.WorldName);
|
||||
if (modelData == this.ModelNumberToFireAt) {
|
||||
// player.sendMessage("firing" + 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(CrunchSiegeCore.plugin, () -> {
|
||||
//player.sendMessage("task");
|
||||
|
||||
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,112 +0,0 @@
|
||||
package siegeCore;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
import CrunchProjectiles.CrunchProjectile;
|
||||
import CrunchProjectiles.EntityProjectile;
|
||||
import CrunchProjectiles.ExplosiveProjectile;
|
||||
import CrunchProjectiles.PotionProjectile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
|
||||
public class StorageManager {
|
||||
|
||||
private static File folder;
|
||||
private static File storage;
|
||||
private static Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
private static Plugin plugin;
|
||||
public static void setup(String path, Plugin pluginInput) {
|
||||
plugin = pluginInput;
|
||||
folder = new File(path);
|
||||
if (!folder.exists()) folder.mkdir();
|
||||
}
|
||||
|
||||
//put this stuff in a try catch so i dont need a try catch everytime i call the methods
|
||||
public static SiegeEquipment load(String s) {
|
||||
storage = new File(s);
|
||||
FileReader reader;
|
||||
Deserializer deserializer = new Deserializer();
|
||||
gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(CrunchProjectile.class, deserializer).create();
|
||||
SiegeEquipment data = null;
|
||||
if (!storage.exists()) {
|
||||
try {
|
||||
storage.createNewFile();
|
||||
FileWriter writer = new FileWriter(storage, false);
|
||||
writer.write(gson.toJson(new SiegeEquipment()));
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
reader = new FileReader(storage);
|
||||
JsonReader test = new JsonReader(reader);
|
||||
test.setLenient(true);
|
||||
Type temp = new TypeToken<SiegeEquipment>() {}.getType();
|
||||
data = gson.fromJson(test, temp);
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static void Save(SiegeEquipment equipment) {
|
||||
|
||||
storage = new File(folder, equipment.EquipmentName + ".json");
|
||||
FileWriter writer;
|
||||
try {
|
||||
writer = new FileWriter(storage, false);
|
||||
writer.write(gson.toJson(equipment));
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public static class Deserializer implements JsonDeserializer<CrunchProjectile> {
|
||||
private String TypeName = "ProjectileType";
|
||||
private Gson gson = new Gson();
|
||||
|
||||
@Override
|
||||
public CrunchProjectile deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
|
||||
JsonObject Object = json.getAsJsonObject();
|
||||
JsonElement type = Object.get(TypeName);
|
||||
|
||||
switch (type.getAsString()) {
|
||||
case "Entity":
|
||||
return gson.fromJson(Object, EntityProjectile.class);
|
||||
case "Explosive":
|
||||
return gson.fromJson(Object, ExplosiveProjectile.class);
|
||||
case "Potion":
|
||||
return gson.fromJson(Object, PotionProjectile.class);
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user