mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-01 22:22:10 +00:00
refactor
This commit is contained in:
1 parent
b3292337d5
commit
d7b303d5ea
13 files changed
+357
-295
No files matched your search
+1
-3
@@ -2,8 +2,6 @@
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="lib" path="E:/1 SEASON 2/spigot.jar"/>
|
||||
<classpathentry kind="lib" path="E:/1 SEASON 2/plugins/LibsDisguises.jar"/>
|
||||
<classpathentry kind="lib" path="E:/1 SEASON 2/plugins/ProtocolLib (3).jar"/>
|
||||
<classpathentry kind="lib" path="E:/4 1.19.4 test/spigot-api-1.19.4-R0.1-SNAPSHOT-shaded.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,254 @@
|
||||
package siegeCore;
|
||||
|
||||
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.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
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.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.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class ClickHandler implements Listener {
|
||||
|
||||
|
||||
public HashMap<UUID, SiegeProjectile> projectiles = new HashMap<UUID, SiegeProjectile>();
|
||||
|
||||
@EventHandler
|
||||
public void onHit(ProjectileHitEvent event) {
|
||||
if ((event.getEntity() instanceof Snowball) && projectiles.containsKey(event.getEntity().getUniqueId())) {
|
||||
SiegeProjectile proj = projectiles.get(event.getEntity().getUniqueId());
|
||||
Entity snowball = event.getEntity();
|
||||
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);
|
||||
TNTPrimed tntEnt = (TNTPrimed) tnt;
|
||||
tntEnt.setFuseTicks(0);
|
||||
tntEnt.setYield(proj.Radius);
|
||||
|
||||
projectiles.remove(event.getEntity().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
public void Search(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Collection<Entity> yeet = player.getLocation().getWorld().getNearbyEntities(player.getLocation(), 10, 10, 10);
|
||||
for (Entity entity : yeet ) {
|
||||
if (CrunchSiegeCore.equipment.containsKey(entity.getUniqueId())){
|
||||
player.sendMessage("§eNow controlling the equipment.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (Entity entity : yeet ) {
|
||||
if (entity.getCustomName() == "Trebuchet" && entity.getType() == EntityType.ARMOR_STAND){
|
||||
LivingEntity living = (LivingEntity) entity;
|
||||
if (living.getEquipment().getHelmet() != null && living.getEquipment().getHelmet().getType() == Material.CARVED_PUMPKIN) {
|
||||
|
||||
SiegeEquipment equip = new SiegeEquipment(entity.getUniqueId());
|
||||
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||
equip.ReadyModelNumber = 122;
|
||||
equip.ModelNumberToFireAt = 135;
|
||||
equip.MillisecondsBetweenFiringStages = 2;
|
||||
equip.MillisecondsBetweenReloadingStages = 50;
|
||||
equip.FiringModelNumbers = new ArrayList<>(Arrays.asList(
|
||||
123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139
|
||||
));
|
||||
equip.Entity = entity;
|
||||
entity.setCustomName("Trebuchet");
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setCustomModelData(equip.ReadyModelNumber);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
stand.setSmall(true);
|
||||
((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2000000, 1));
|
||||
living.getEquipment().setHelmet(item);
|
||||
if (CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
List<Entity> entities = CrunchSiegeCore.TrackedStands.get(player.getUniqueId());
|
||||
entities.add(entity);
|
||||
CrunchSiegeCore.TrackedStands.put(player.getUniqueId(), entities);
|
||||
}
|
||||
else {
|
||||
List<Entity> newList = new ArrayList<Entity>();
|
||||
newList.add(entity);
|
||||
CrunchSiegeCore.TrackedStands.put(player.getUniqueId(), newList);
|
||||
}
|
||||
CrunchSiegeCore.equipment.put(entity.getUniqueId(), equip);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Shoot(Player player) {
|
||||
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())){{
|
||||
|
||||
double distance = player.getLocation().distance(ent.getLocation());
|
||||
if (distance >= 250) {
|
||||
player.sendMessage("Too far away to fire");
|
||||
return;
|
||||
}
|
||||
SiegeEquipment siege = CrunchSiegeCore.equipment.get(ent.getUniqueId());
|
||||
|
||||
if (System.currentTimeMillis() < siege.NextShotTime) {
|
||||
player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(siege.NextShotTime - System.currentTimeMillis()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getInventory().containsAtLeast(new ItemStack(Material.COBBLESTONE), 10)) {
|
||||
player.getInventory().remove(new ItemStack(Material.COBBLESTONE, 10));
|
||||
}
|
||||
else {
|
||||
player.sendMessage("Cannot fire, missing cobblestone, requires 10 per shot");
|
||||
return;
|
||||
}
|
||||
LivingEntity living = (LivingEntity) ent;
|
||||
Location loc = living.getEyeLocation();
|
||||
loc.setPitch(-30);
|
||||
loc.setY(loc.getY() + 2);
|
||||
loc.getPitch();
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
float randomVar = random.nextFloat() * (7 - -7) + -7;
|
||||
loc.setYaw(loc.getYaw() + randomVar);
|
||||
siege.NextModelNumber = 0;
|
||||
siege.location = loc;
|
||||
siege.NextShotTime = System.currentTimeMillis() + 6000;
|
||||
player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(siege.NextShotTime - System.currentTimeMillis()));
|
||||
siege.WorldName = ent.getWorld().getName();
|
||||
Bukkit.getServer().getWorld(siege.WorldName).playSound(siege.location, Sound.ENTITY_BAT_DEATH, 20, 2);
|
||||
siege.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> {
|
||||
//player.sendMessage("task");
|
||||
if (siege.HasFired) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(siege.TaskNumber);
|
||||
siege.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> {
|
||||
// player.sendMessage("task");
|
||||
if (siege.HasReloaded) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(siege.TaskNumber);
|
||||
siege.HasReloaded = false;
|
||||
siege.HasFired = false;
|
||||
siege.NextModelNumber = 0;
|
||||
}
|
||||
else {
|
||||
//firing stages
|
||||
if (siege.NextModelNumber - 1 <= siege.FiringModelNumbers.size() && siege.NextModelNumber - 1 >= 0) {
|
||||
int modelData = siege.FiringModelNumbers.get(siege.NextModelNumber - 1);
|
||||
// player.sendMessage("" + modelData);
|
||||
CrunchSiegeCore.UpdateEntityIdModel(siege.Entity, modelData, siege.WorldName);
|
||||
siege.NextModelNumber -= 1;
|
||||
|
||||
}else {
|
||||
// plugin.getLogger().log(Level.INFO, "its reloaded");
|
||||
siege.HasReloaded = true;
|
||||
}
|
||||
}
|
||||
}, 0, siege.MillisecondsBetweenReloadingStages);
|
||||
|
||||
}
|
||||
else {
|
||||
//firing stages
|
||||
if (siege.NextModelNumber < siege.FiringModelNumbers.size()) {
|
||||
|
||||
int modelData = siege.FiringModelNumbers.get(siege.NextModelNumber);
|
||||
// player.sendMessage("" + modelData);
|
||||
CrunchSiegeCore.UpdateEntityIdModel(siege.Entity, modelData, siege.WorldName);
|
||||
if (modelData == siege.ModelNumberToFireAt) {
|
||||
Entity tnt = Bukkit.getServer().getWorld(siege.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
|
||||
|
||||
projectiles.put(tnt.getUniqueId(), siege.projectile);
|
||||
tnt.setVelocity(loc.getDirection().multiply(siege.Velocity));
|
||||
|
||||
}
|
||||
siege.NextModelNumber += 1;
|
||||
|
||||
}else {
|
||||
siege.HasFired = true;
|
||||
|
||||
}
|
||||
}
|
||||
}, 0, siege.MillisecondsBetweenFiringStages);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void rightClick(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) {
|
||||
CrunchSiegeCore.CreateTrebuchet(player);
|
||||
ItemInHand.setAmount(ItemInHand.getAmount() - 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ItemInHand.getType() == Material.CLOCK && player.isSneaking()) {
|
||||
Search(event);
|
||||
}
|
||||
|
||||
if (event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
if (ItemInHand.getType() != Material.STICK) {
|
||||
return;
|
||||
}
|
||||
|
||||
Shoot(player);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onEntityClick(PlayerInteractEntityEvent event) {
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (event.getRightClicked() instanceof ArmorStand) {
|
||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (itemInHand == null) {
|
||||
return;
|
||||
}
|
||||
if (itemInHand.getType() == Material.STICK) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,10 +47,6 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||
|
||||
public class CrunchSiegeCore extends JavaPlugin {
|
||||
public static Plugin plugin;
|
||||
@@ -61,9 +57,11 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
plugin = this;
|
||||
|
||||
this.getCommand("siegetest").setExecutor(new SiegeCommand());
|
||||
getServer().getPluginManager().registerEvents(new PlayerMoving(), this);
|
||||
}
|
||||
getServer().getPluginManager().registerEvents(new RotationHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new ClickHandler(), this);
|
||||
|
||||
}
|
||||
|
||||
public class SiegeCommand implements CommandExecutor {
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@@ -73,21 +71,18 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (player.isOp()) {
|
||||
CreateTrebuchet(player);
|
||||
CreateTrebuchet(player);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<UUID, Entity> TrackedStands = new HashMap<UUID, Entity>();
|
||||
public static HashMap<UUID, List<Entity>> TrackedStands = new HashMap<UUID, List<Entity>>();
|
||||
|
||||
public HashMap<UUID, SiegeEquipment> equipment = new HashMap<UUID, SiegeEquipment>();
|
||||
public static HashMap<UUID, SiegeEquipment> equipment = new HashMap<UUID, SiegeEquipment>();
|
||||
|
||||
public HashMap<UUID, SiegeProjectile> projectiles = new HashMap<UUID, SiegeProjectile>();
|
||||
public String convertTime(long time){
|
||||
public static String convertTime(long time){
|
||||
|
||||
long days = TimeUnit.MILLISECONDS.toDays(time);
|
||||
time -= TimeUnit.DAYS.toMillis(days);
|
||||
@@ -104,7 +99,7 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
return timeLeftFormatted;
|
||||
}
|
||||
|
||||
public void CreateTrebuchet(Player player) {
|
||||
public static void CreateTrebuchet(Player player) {
|
||||
Location l = player.getLocation();
|
||||
Entity entity2 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
|
||||
SiegeEquipment equip = new SiegeEquipment(entity2.getUniqueId());
|
||||
@@ -112,17 +107,17 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
equip.ReadyModelNumber = 122;
|
||||
equip.ModelNumberToFireAt = 135;
|
||||
equip.MillisecondsBetweenFiringStages = 2;
|
||||
equip.MillisecondsBetweenReloadingStages = 50;
|
||||
equip.MillisecondsBetweenReloadingStages = 30;
|
||||
equip.FiringModelNumbers = new ArrayList<>(Arrays.asList(
|
||||
123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139
|
||||
));
|
||||
123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139
|
||||
));
|
||||
equip.Entity = entity2;
|
||||
|
||||
|
||||
entity2.setCustomName("Trebuchet");
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setCustomModelData(equip.ReadyModelNumber);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
|
||||
LivingEntity ent = (LivingEntity) entity2;
|
||||
ArmorStand stand = (ArmorStand) ent;
|
||||
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
|
||||
@@ -130,287 +125,39 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
|
||||
ent.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2000000, 1));
|
||||
// stand.setSmall(true);
|
||||
// stand.setSmall(true);
|
||||
stand.setVisible(true);
|
||||
ent.getEquipment().setHelmet(item);
|
||||
TrackedStands.put(player.getUniqueId(), entity2);
|
||||
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);
|
||||
}
|
||||
|
||||
public 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?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class PlayerMoving implements Listener {
|
||||
@EventHandler
|
||||
public void playerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (TrackedStands.containsKey(player.getUniqueId())) {
|
||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||
if (itemInHand != null) {
|
||||
if (itemInHand.getType() != Material.STICK) {
|
||||
// TrackedStands.remove(player.getUniqueId());
|
||||
|
||||
return;
|
||||
}
|
||||
Entity ent= TrackedStands.get(player.getUniqueId());
|
||||
if (ent != null) {
|
||||
|
||||
double distance = player.getLocation().distance(ent.getLocation());
|
||||
if (distance <= 5) {
|
||||
// player.sendMessage("got id");
|
||||
LivingEntity living = (LivingEntity) ent;
|
||||
Location loc = ent.getLocation();
|
||||
loc.setDirection(player.getLocation().getDirection());
|
||||
loc.setYaw(player.getLocation().getYaw());
|
||||
loc.setPitch(player.getLocation().getPitch());
|
||||
ArmorStand stand = (ArmorStand) living;
|
||||
|
||||
living.teleport(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onHit(ProjectileHitEvent event) {
|
||||
if ((event.getEntity() instanceof Snowball) && projectiles.containsKey(event.getEntity().getUniqueId())) {
|
||||
SiegeProjectile proj = projectiles.get(event.getEntity().getUniqueId());
|
||||
Entity snowball = event.getEntity();
|
||||
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);
|
||||
TNTPrimed tntEnt = (TNTPrimed) tnt;
|
||||
tntEnt.setFuseTicks(0);
|
||||
tntEnt.setYield(proj.Radius);
|
||||
|
||||
projectiles.remove(event.getEntity().getUniqueId());
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void rightClick(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
ItemStack ItemInHand = event.getPlayer().getInventory().getItemInMainHand();
|
||||
if (ItemInHand == null) {
|
||||
return;
|
||||
}
|
||||
Entity ent= TrackedStands.get(player.getUniqueId());
|
||||
if (ent == null) {
|
||||
if (ItemInHand.getType() == Material.PAPER) {
|
||||
ItemMeta meta = ItemInHand.getItemMeta();
|
||||
if (meta.hasCustomModelData() && meta.getCustomModelData() == 505050505) {
|
||||
CreateTrebuchet(player);
|
||||
ItemInHand.setAmount(ItemInHand.getAmount() - 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ItemInHand.getType() == Material.CLOCK && player.isSneaking()) {
|
||||
Collection<Entity> yeet = player.getLocation().getWorld().getNearbyEntities(player.getLocation(), 10, 10, 10);
|
||||
for (Entity entity : yeet ) {
|
||||
if (equipment.containsKey(entity.getUniqueId())){
|
||||
player.sendMessage("§eNow controlling the equipment.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (Entity entity : yeet ) {
|
||||
if (entity.getCustomName() == "Trebuchet" && entity.getType() == EntityType.ARMOR_STAND){
|
||||
LivingEntity living = (LivingEntity) entity;
|
||||
if (living.getEquipment().getHelmet() != null && living.getEquipment().getHelmet().getType() == Material.CARVED_PUMPKIN) {
|
||||
|
||||
SiegeEquipment equip = new SiegeEquipment(entity.getUniqueId());
|
||||
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||
equip.ReadyModelNumber = 122;
|
||||
equip.ModelNumberToFireAt = 135;
|
||||
equip.MillisecondsBetweenFiringStages = 2;
|
||||
equip.MillisecondsBetweenReloadingStages = 50;
|
||||
equip.FiringModelNumbers = new ArrayList<>(Arrays.asList(
|
||||
123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139
|
||||
));
|
||||
equip.Entity = entity;
|
||||
entity.setCustomName("Trebuchet");
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setCustomModelData(equip.ReadyModelNumber);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
|
||||
ArmorStand stand = (ArmorStand) ent;
|
||||
stand.setSmall(true);
|
||||
((LivingEntity) ent).addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2000000, 1));
|
||||
living.getEquipment().setHelmet(item);
|
||||
TrackedStands.put(player.getUniqueId(), entity);
|
||||
equipment.put(entity.getUniqueId(), equip);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ent.isDead()) {
|
||||
equipment.remove(ent.getUniqueId());
|
||||
return;
|
||||
}
|
||||
if (ItemInHand.getType() == Material.BOOK) {
|
||||
if (equipment.containsKey(ent.getUniqueId())) {
|
||||
SiegeEquipment siege = equipment.get(ent.getUniqueId());
|
||||
DecimalFormat df = new DecimalFormat("#.#");
|
||||
|
||||
if (event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
siege.Velocity += 0.1;
|
||||
player.sendMessage("§eProjectile Speed set to " + df.format(siege.Velocity) );
|
||||
return;
|
||||
}
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
siege.Velocity -= 0.1;
|
||||
player.sendMessage("§eProjectile Speed set to " + df.format(siege.Velocity));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
if (ItemInHand.getType() != Material.STICK) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ent != null) {
|
||||
double distance = player.getLocation().distance(ent.getLocation());
|
||||
if (distance >= 5) {
|
||||
player.sendMessage("Too far away to fire");
|
||||
return;
|
||||
}
|
||||
SiegeEquipment siege = equipment.get(ent.getUniqueId());
|
||||
|
||||
if (System.currentTimeMillis() < siege.NextShotTime) {
|
||||
player.sendMessage("Cannot fire for another " + convertTime(siege.NextShotTime - System.currentTimeMillis()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getInventory().containsAtLeast(new ItemStack(Material.COBBLESTONE), 10)) {
|
||||
player.getInventory().remove(new ItemStack(Material.COBBLESTONE, 10));
|
||||
}
|
||||
else {
|
||||
player.sendMessage("Cannot fire, missing cobblestone, requires 10 per shot");
|
||||
return;
|
||||
}
|
||||
LivingEntity living = (LivingEntity) ent;
|
||||
Location loc = living.getEyeLocation();
|
||||
loc.setPitch(-30);
|
||||
loc.setY(loc.getY() + 2);
|
||||
loc.getPitch();
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
float randomVar = random.nextFloat() * (7 - -7) + -7;
|
||||
loc.setYaw(loc.getYaw() + randomVar);
|
||||
siege.NextModelNumber = 0;
|
||||
siege.location = loc;
|
||||
siege.NextShotTime = System.currentTimeMillis() + 60000;
|
||||
player.sendMessage("Cannot fire for another " + convertTime(siege.NextShotTime - System.currentTimeMillis()));
|
||||
siege.WorldName = ent.getWorld().getName();
|
||||
Bukkit.getServer().getWorld(siege.WorldName).playSound(siege.location, Sound.ENTITY_BAT_DEATH, 20, 2);
|
||||
siege.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
//player.sendMessage("task");
|
||||
if (siege.HasFired) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(siege.TaskNumber);
|
||||
siege.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
// player.sendMessage("task");
|
||||
if (siege.HasReloaded) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(siege.TaskNumber);
|
||||
siege.HasReloaded = false;
|
||||
siege.HasFired = false;
|
||||
siege.NextModelNumber = 0;
|
||||
}
|
||||
else {
|
||||
//firing stages
|
||||
if (siege.NextModelNumber - 1 <= siege.FiringModelNumbers.size() && siege.NextModelNumber - 1 >= 0) {
|
||||
int modelData = siege.FiringModelNumbers.get(siege.NextModelNumber - 1);
|
||||
// player.sendMessage("" + modelData);
|
||||
UpdateEntityIdModel(siege.Entity, modelData, siege.WorldName);
|
||||
siege.NextModelNumber -= 1;
|
||||
|
||||
}else {
|
||||
// plugin.getLogger().log(Level.INFO, "its reloaded");
|
||||
siege.HasReloaded = true;
|
||||
}
|
||||
}
|
||||
}, 0, siege.MillisecondsBetweenReloadingStages);
|
||||
|
||||
}
|
||||
else {
|
||||
//firing stages
|
||||
if (siege.NextModelNumber < siege.FiringModelNumbers.size()) {
|
||||
|
||||
int modelData = siege.FiringModelNumbers.get(siege.NextModelNumber);
|
||||
// player.sendMessage("" + modelData);
|
||||
UpdateEntityIdModel(siege.Entity, modelData, siege.WorldName);
|
||||
if (modelData == siege.ModelNumberToFireAt) {
|
||||
Entity tnt = Bukkit.getServer().getWorld(siege.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
|
||||
|
||||
projectiles.put(tnt.getUniqueId(), siege.projectile);
|
||||
tnt.setVelocity(loc.getDirection().multiply(siege.Velocity));
|
||||
|
||||
}
|
||||
siege.NextModelNumber += 1;
|
||||
|
||||
}else {
|
||||
siege.HasFired = true;
|
||||
|
||||
}
|
||||
}
|
||||
}, 0, siege.MillisecondsBetweenFiringStages);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onEntityClick(PlayerInteractEntityEvent event) {
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (event.getRightClicked() instanceof ArmorStand) {
|
||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (itemInHand == null) {
|
||||
return;
|
||||
}
|
||||
if (itemInHand.getType() == Material.STICK) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
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?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package siegeCore;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
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.util.EulerAngle;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class RotationHandler implements Listener {
|
||||
@EventHandler
|
||||
public void playerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||
if (itemInHand != null) {
|
||||
if (itemInHand.getType() != Material.STICK) {
|
||||
// TrackedStands.remove(player.getUniqueId());
|
||||
|
||||
return;
|
||||
}
|
||||
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) {
|
||||
if (ent != null) {
|
||||
|
||||
double distance = player.getLocation().distance(ent.getLocation());
|
||||
if (distance <= 250) {
|
||||
// player.sendMessage("got id");
|
||||
LivingEntity living = (LivingEntity) ent;
|
||||
Location loc = ent.getLocation();
|
||||
|
||||
Location direction = player.getLocation().add(player.getLocation().getDirection().multiply(50));
|
||||
|
||||
Vector dirBetweenLocations = direction.toVector().subtract(loc.toVector());
|
||||
|
||||
loc.setDirection(dirBetweenLocations);
|
||||
// loc.setYaw(player.getLocation().getYaw());
|
||||
//loc.setPitch(player.getLocation().getPitch());
|
||||
ArmorStand stand = (ArmorStand) living;
|
||||
|
||||
stand.setHeadPose(new EulerAngle(player.getLocation().getDirection().getY()*(-1),0,0));
|
||||
|
||||
living.teleport(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,9 @@ public class SiegeEquipment {
|
||||
public Location location;
|
||||
public int ModelNumberToFireAt;
|
||||
|
||||
public Boolean RotateSideways = false;
|
||||
public Boolean RoateUpDown = true;
|
||||
|
||||
public Boolean HasFired = false;
|
||||
public Boolean HasReloaded = false;
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package siegeCore;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class SiegeProjectile {
|
||||
|
||||
public int Radius = 5;
|
||||
@@ -10,4 +13,5 @@ public class SiegeProjectile {
|
||||
DoFire = fire;
|
||||
}
|
||||
|
||||
public ItemStack AmmoItem = new ItemStack(Material.COBBLESTONE, 1);
|
||||
}
|
||||
Reference in new issue
Block a user