mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-03 22:21:12 +00:00
aim signs
This commit is contained in:
1 parent
e4350c7452
commit
b405f10553
4 files changed
+134
-47
No files matched your search
Binary file not shown.
Binary file not shown.
+101
-30
@@ -40,10 +40,12 @@ import org.bukkit.metadata.MetadataValue;
|
|||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.bukkit.util.EulerAngle;
|
||||||
|
|
||||||
public class ClickHandler implements Listener {
|
public class ClickHandler implements Listener {
|
||||||
|
|
||||||
|
public float MinDelay = 5;
|
||||||
|
|
||||||
public static HashMap<UUID, SiegeProjectile> projectiles = new HashMap<UUID, SiegeProjectile>();
|
public static HashMap<UUID, SiegeProjectile> projectiles = new HashMap<UUID, SiegeProjectile>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -66,10 +68,11 @@ public class ClickHandler implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Shoot(Player player) {
|
public void Shoot(Player player, long delay) {
|
||||||
int delay = 6;
|
float actualDelay = 0;
|
||||||
|
Boolean FirstShot = true;
|
||||||
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())){{
|
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())){{
|
||||||
|
|
||||||
if (ent == null || ent.isDead()) {
|
if (ent == null || ent.isDead()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -82,7 +85,7 @@ public class ClickHandler implements Listener {
|
|||||||
|
|
||||||
if (System.currentTimeMillis() < siege.NextShotTime) {
|
if (System.currentTimeMillis() < siege.NextShotTime) {
|
||||||
player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(siege.NextShotTime - System.currentTimeMillis()));
|
player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(siege.NextShotTime - System.currentTimeMillis()));
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.getInventory().containsAtLeast(new ItemStack(Material.COBBLESTONE), 10)) {
|
if (player.getInventory().containsAtLeast(new ItemStack(Material.COBBLESTONE), 10)) {
|
||||||
@@ -92,10 +95,10 @@ public class ClickHandler implements Listener {
|
|||||||
player.sendMessage("Cannot fire, missing cobblestone, requires 10 per shot");
|
player.sendMessage("Cannot fire, missing cobblestone, requires 10 per shot");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
siege.Fire(player, delay);
|
player.sendMessage(String.format("§e" +actualDelay));
|
||||||
delay += 6;
|
siege.Fire(player, actualDelay);
|
||||||
|
actualDelay += delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,33 +127,26 @@ public class ClickHandler implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shoot(player);
|
Shoot(player, 6);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onManualLock(SignChangeEvent event){
|
public void onSignChange(SignChangeEvent event){
|
||||||
String topline = event.getLine(0);
|
String topline = event.getLine(0);
|
||||||
if (topline == null) topline = "";
|
if (topline == null) topline = "";
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
String toplinetrimmed = topline.trim();
|
String toplinetrimmed = topline.trim();
|
||||||
event.getPlayer().sendMessage("1");
|
event.getPlayer().sendMessage("1");
|
||||||
if (toplinetrimmed.equals("[Cannon]")) {
|
if (toplinetrimmed.equals("[Cannon]")) {
|
||||||
Block block = event.getBlock();
|
SaveCannons(player, event.getBlock());
|
||||||
List<String> Ids = new ArrayList<String>();
|
|
||||||
for (Entity ent : CrunchSiegeCore.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();
|
|
||||||
event.getPlayer().sendMessage("Saving cannons!");
|
|
||||||
}
|
}
|
||||||
event.getPlayer().sendMessage("2");
|
event.getPlayer().sendMessage("2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void TakeControl(Player player, Entity entity) {
|
public static void TakeControl(Player player, Entity entity) {
|
||||||
LivingEntity living = (LivingEntity) entity;
|
LivingEntity living = (LivingEntity) entity;
|
||||||
if (living.getEquipment().getHelmet() != null && living.getEquipment().getHelmet().getType() == Material.CARVED_PUMPKIN) {
|
if (living.getEquipment().getHelmet() != null && living.getEquipment().getHelmet().getType() == Material.CARVED_PUMPKIN) {
|
||||||
@@ -177,38 +173,113 @@ public class ClickHandler implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SaveCannons(Player player, Block block) {
|
||||||
|
List<String> Ids = new ArrayList<String>();
|
||||||
|
if (!CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Entity ent : CrunchSiegeCore.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!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AimUp(Player player, float amount) {
|
||||||
|
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) {
|
||||||
|
Location loc = ent.getLocation();
|
||||||
|
ArmorStand stand = (ArmorStand) ent;
|
||||||
|
|
||||||
|
loc.setPitch((float) (loc.getPitch() - amount));
|
||||||
|
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
|
||||||
|
ent.teleport(loc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AimDown(Player player, float amount) {
|
||||||
|
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) {
|
||||||
|
Location loc = ent.getLocation();
|
||||||
|
ArmorStand stand = (ArmorStand) ent;
|
||||||
|
|
||||||
|
loc.setPitch((float) (loc.getPitch() + amount));
|
||||||
|
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
|
||||||
|
ent.teleport(loc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerClickSign(PlayerInteractEvent event){
|
public void onPlayerClickSign(PlayerInteractEvent event){
|
||||||
Player p = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if(event.getClickedBlock() != null && event.getClickedBlock().getType().toString().contains("SIGN")){
|
if(event.getClickedBlock() != null && event.getClickedBlock().getType().toString().contains("SIGN")){
|
||||||
Sign sign = (Sign) event.getClickedBlock().getState();
|
Sign sign = (Sign) event.getClickedBlock().getState();
|
||||||
|
if(sign.getLine(0).equalsIgnoreCase( "[Fire]") && event.getAction() == Action.RIGHT_CLICK_BLOCK){
|
||||||
|
try {
|
||||||
|
Long delay = Long.parseLong(sign.getLine(1));
|
||||||
|
if (delay < 6){
|
||||||
|
delay = 6l;
|
||||||
|
}
|
||||||
|
Shoot(player, delay);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Shoot(player, 6);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sign.getLine(0).equalsIgnoreCase( "[Aim]")){
|
||||||
|
float amount;
|
||||||
|
try {
|
||||||
|
amount = Float.parseFloat(sign.getLine(1));
|
||||||
|
if (player.isSneaking()) {
|
||||||
|
AimDown(player, amount);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AimUp(player, amount);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
player.sendMessage("Could not parse number on second line.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(sign.getLine(0).equalsIgnoreCase( "[Cannon]")){
|
if(sign.getLine(0).equalsIgnoreCase( "[Cannon]")){
|
||||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
|
if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
|
||||||
|
if (player.isSneaking()) {
|
||||||
|
SaveCannons(player, event.getClickedBlock());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||||
|
CrunchSiegeCore.TrackedStands.remove(player.getUniqueId());
|
||||||
|
player.sendMessage("Releasing the cannons!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
NamespacedKey key = new NamespacedKey(CrunchSiegeCore.plugin, "cannons");
|
NamespacedKey key = new NamespacedKey(CrunchSiegeCore.plugin, "cannons");
|
||||||
TileState state = (TileState) sign.getBlock().getState();
|
TileState state = (TileState) sign.getBlock().getState();
|
||||||
CrunchSiegeCore.TrackedStands.remove(p.getUniqueId());
|
CrunchSiegeCore.TrackedStands.remove(player.getUniqueId());
|
||||||
List<UUID> temp = new ArrayList<UUID>();
|
List<UUID> temp = new ArrayList<UUID>();
|
||||||
if (!state.getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
|
if (!state.getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String[] split = state.getPersistentDataContainer().get(key, PersistentDataType.STRING).replace("[", "").replace("]", "").split(",");
|
String[] split = state.getPersistentDataContainer().get(key, PersistentDataType.STRING).replace("[", "").replace("]", "").split(",");
|
||||||
for (String s : split) {
|
for (String s : split) {
|
||||||
p.sendMessage(s.trim());
|
player.sendMessage(s.trim());
|
||||||
temp.add(UUID.fromString(s.trim()));
|
temp.add(UUID.fromString(s.trim()));
|
||||||
}
|
}
|
||||||
for (UUID Id : temp) {
|
for (UUID Id : temp) {
|
||||||
List<Entity> entities = new ArrayList<Entity>();
|
List<Entity> entities = new ArrayList<Entity>();
|
||||||
Entity ent = Bukkit.getEntity(Id);
|
Entity ent = Bukkit.getEntity(Id);
|
||||||
if (ent != null) {
|
if (ent != null) {
|
||||||
TakeControl(p, ent);
|
TakeControl(player, ent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
|
||||||
CrunchSiegeCore.TrackedStands.remove(p.getUniqueId());
|
|
||||||
p.sendMessage("Releasing the cannons!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,35 +60,37 @@ public class SiegeEquipment implements Cloneable {
|
|||||||
|
|
||||||
public List<Integer> FiringModelNumbers = new ArrayList<Integer>();
|
public List<Integer> FiringModelNumbers = new ArrayList<Integer>();
|
||||||
|
|
||||||
public SiegeProjectile projectile = new SiegeProjectile(1, false);
|
public SiegeProjectile projectile = new SiegeProjectile(2, false);
|
||||||
|
|
||||||
public SiegeEquipment(UUID id) {
|
public SiegeEquipment(UUID id) {
|
||||||
EntityId = id;
|
EntityId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Fire(Player player, int delay) {
|
public void Fire(Player player, float delay) {
|
||||||
LivingEntity living = (LivingEntity) Entity;
|
|
||||||
Location loc = living.getEyeLocation();
|
|
||||||
Vector direction = Entity.getLocation().getDirection().multiply(XOffset);
|
|
||||||
loc.add(direction);
|
|
||||||
Random random = new Random();
|
|
||||||
|
|
||||||
float randomVar = random.nextFloat() * (7 - -7) + -7;
|
|
||||||
|
|
||||||
this.NextModelNumber = 0;
|
|
||||||
this.location = loc;
|
|
||||||
this.NextShotTime = System.currentTimeMillis() + 6000;
|
|
||||||
player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
|
|
||||||
this.WorldName = Entity.getWorld().getName();
|
this.WorldName = Entity.getWorld().getName();
|
||||||
|
this.NextShotTime = System.currentTimeMillis() + 6000;
|
||||||
if (this.CycleThroughModelsBeforeFiring) {
|
if (this.CycleThroughModelsBeforeFiring) {
|
||||||
|
|
||||||
|
|
||||||
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> {
|
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> {
|
||||||
|
LivingEntity living = (LivingEntity) Entity;
|
||||||
|
Location loc = living.getEyeLocation();
|
||||||
|
Vector direction = Entity.getLocation().getDirection().multiply(XOffset);
|
||||||
|
loc.add(direction);
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
float randomVar = random.nextFloat() * (7 - -7) + -7;
|
||||||
|
|
||||||
|
this.NextModelNumber = 0;
|
||||||
|
this.location = loc;
|
||||||
|
|
||||||
|
// player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
|
||||||
//player.sendMessage("task");
|
//player.sendMessage("task");
|
||||||
if (this.HasFired) {
|
if (this.HasFired) {
|
||||||
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
|
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
|
||||||
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> {
|
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> {
|
||||||
|
|
||||||
// player.sendMessage("task");
|
// player.sendMessage("task");
|
||||||
if (this.HasReloaded) {
|
if (this.HasReloaded) {
|
||||||
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
|
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
|
||||||
@@ -125,6 +127,7 @@ public class SiegeEquipment implements Cloneable {
|
|||||||
ClickHandler.projectiles.put(tnt.getUniqueId(), this.projectile);
|
ClickHandler.projectiles.put(tnt.getUniqueId(), this.projectile);
|
||||||
tnt.setVelocity(loc.getDirection().multiply(this.Velocity));
|
tnt.setVelocity(loc.getDirection().multiply(this.Velocity));
|
||||||
Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_BAT_DEATH, 20, 2);
|
Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_BAT_DEATH, 20, 2);
|
||||||
|
this.NextShotTime = System.currentTimeMillis() + 6000;
|
||||||
}
|
}
|
||||||
this.NextModelNumber += 1;
|
this.NextModelNumber += 1;
|
||||||
|
|
||||||
@@ -136,15 +139,28 @@ public class SiegeEquipment implements Cloneable {
|
|||||||
}, 0, this.MillisecondsBetweenFiringStages);
|
}, 0, this.MillisecondsBetweenFiringStages);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CrunchSiegeCore.plugin, () -> {
|
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CrunchSiegeCore.plugin, () -> {
|
||||||
//player.sendMessage("task");
|
//player.sendMessage("task");
|
||||||
|
LivingEntity living = (LivingEntity) Entity;
|
||||||
|
Location loc = living.getEyeLocation();
|
||||||
|
Vector direction = Entity.getLocation().getDirection().multiply(XOffset);
|
||||||
|
loc.add(direction);
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
float randomVar = random.nextFloat() * (7 - -7) + -7;
|
||||||
|
|
||||||
|
this.NextModelNumber = 0;
|
||||||
|
this.location = loc;
|
||||||
|
|
||||||
|
// player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
|
||||||
Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
|
Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
|
||||||
ClickHandler.projectiles.put(tnt.getUniqueId(), this.projectile);
|
ClickHandler.projectiles.put(tnt.getUniqueId(), this.projectile);
|
||||||
tnt.setVelocity(loc.getDirection().multiply(this.Velocity));
|
tnt.setVelocity(loc.getDirection().multiply(this.Velocity));
|
||||||
Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_GENERIC_EXPLODE, 20, 2);
|
Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_GENERIC_EXPLODE, 20, 2);
|
||||||
Bukkit.getServer().getWorld(this.WorldName).spawnParticle(Particle.EXPLOSION_LARGE, loc.getX(), loc.getY(), loc.getZ(), 0);
|
Bukkit.getServer().getWorld(this.WorldName).spawnParticle(Particle.EXPLOSION_LARGE, loc.getX(), loc.getY(), loc.getZ(), 0);
|
||||||
}, delay);
|
this.NextShotTime = System.currentTimeMillis() + 6000;
|
||||||
|
}, (long) delay);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user