This commit is contained in:
ShermansWorld committed 2024-01-06 19:45:58 -05:00
1 parent 6250d17520
commit 6e36cce455
6 files changed
+482 -516

No files matched your search

@@ -26,8 +26,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import org.bukkit.metadata.MetadataValueAdapter;
import org.bukkit.metadata.FixedMetadataValue;
@@ -71,10 +70,10 @@ public class SiegeEngines extends JavaPlugin {
TrackedStands.clear();
DefinedEquipment.clear();
AddDefaults();
for (SiegeEquipment 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()) {
for (SiegeEngine i : DefinedEquipment.values()) {
System.out.println("§eEnabled Weapon : " + i.name);
System.out.println("§eWeapon Propellant/\"Fuel\" ItemStacks : " + i.fuelItem);
for (ItemStack proj : i.projectiles.keySet()) {
System.out.println("§eWeapon Projectile ItemStacks : " + proj);
}
}
@@ -85,20 +84,20 @@ public class SiegeEngines extends JavaPlugin {
@Override
public void onDisable() {
commandHandler.onDisable();
for (SiegeEquipment equip : equipment.values()) {
if (equip.Entity != null) {
for (SiegeEngine siegeEngine : equipment.values()) {
if (siegeEngine.entity != null) {
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = item.getItemMeta();
equip.AmmoHolder = new EquipmentMagazine();
siegeEngine.ammoHolder = new EquipmentMagazine();
meta.setCustomModelData(equip.ReadyModelNumber);
meta.setDisplayName("§e" + equip.EquipmentName + " Item");
meta.setCustomModelData(siegeEngine.readyModelNumber);
meta.setDisplayName("§e" + siegeEngine.name + " Item");
List<String> Lore = new ArrayList<String>();
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand.");
Lore.add("§ePlace as a block to spawn a " + siegeEngine.name + " or put on an Armor Stand.");
meta.setLore(Lore);
item.setItemMeta(meta);
((LivingEntity) equip.Entity).getEquipment().setHelmet(item);
((LivingEntity) siegeEngine.entity).getEquipment().setHelmet(item);
}
}
}
@@ -107,7 +106,7 @@ public class SiegeEngines extends JavaPlugin {
return new FixedMetadataValue(Bukkit.getServer().getPluginManager().getPlugin("SiegeEngines"), value);
}
public static SiegeEquipment CreateClone(Integer ModelId) {
public static SiegeEngine CreateClone(Integer ModelId) {
try {
return DefinedEquipment.get(ModelId).clone();
} catch (CloneNotSupportedException e) {
@@ -117,11 +116,11 @@ public class SiegeEngines extends JavaPlugin {
return null;
}
public static HashMap<Integer, SiegeEquipment> DefinedEquipment = new HashMap<Integer, SiegeEquipment>();
public static HashMap<Integer, SiegeEngine> DefinedEquipment = new HashMap<Integer, SiegeEngine>();
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, SiegeEngine> equipment = new HashMap<UUID, SiegeEngine>();
public static String convertTime(long time) {
@@ -140,94 +139,49 @@ public class SiegeEngines extends JavaPlugin {
return timeLeftFormatted;
}
public static SiegeEquipment CreateNewGun(String name, Integer XOffset, Integer YOffset, Integer fuelMax, Float fuelVelocityMod, Integer customModelId, HashMap<ItemStack, GunnersProjectile> projObj) {
SiegeEquipment equip = new SiegeEquipment();
if (customModelId == null || customModelId == 0)
customModelId = 150;
if (name == null)
name = "Unnamed Cannon";
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.EquipmentId = equip.EquipmentName.replaceAll(" ", "_").toLowerCase();
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.AllowInvisibleStand = false;
equip.MaxFuel = fuelMax;
equip.shotAmount = 1;
equip.AmmoHolder.LoadedFuel = fuelMax;
EntityProjectile defaultProj = new EntityProjectile();
defaultProj.EntityCount = 2;
defaultProj.EntityTyp = EntityType.SHULKER_BULLET;
defaultProj.ParticleType = Particle.WHITE_ASH;
defaultProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
if (projObj.keySet().isEmpty() || projObj.isEmpty())
projObj.put(new ItemStack(Material.GUNPOWDER), defaultProj);
for (ItemStack mat : projObj.keySet()) {
equip.Projectiles.put(mat, projObj.get(mat));
}
DefinedEquipment.put(equip.ReadyModelNumber, equip);
return equip;
}
public static void AddDefaults() {
SiegeEquipment equip = new SiegeEquipment();
equip.EquipmentName = "Trebuchet";
equip.XOffset = 5;
equip.YOffset = 5;
equip.VelocityPerFuel = 0.3f;
//String name, Integer XOffset, Integer YOffset, Integer fuelMax, Float fuelVelocityMod, Integer customModelId, HashMap<ItemStack, GunnersProjectile> projObj
//@NotNull String name, @NotNull HashMap<ItemStack, GunnersProjectile> projectiles, @NotNull ItemStack fuelItem, int customModelID
SiegeEngine trebuchet = new SiegeEngine("Trebuchet", new HashMap<ItemStack, GunnersProjectile>(), new ItemStack(Material.GUNPOWDER), 150);
trebuchet.xOffset = 5;
trebuchet.yOffset = 5;
trebuchet.velocityPerFuel = 0.3f;
ExplosiveProjectile proj = new ExplosiveProjectile();
proj.ExplodePower = 1;
equip.shotAmount = 2;
equip.RotateStandHead = false;
equip.RotateSideways = true;
equip.FuelMaterial = new ItemStack(Material.STRING);
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
equip.ReadyModelNumber = 122;
equip.ModelNumberToFireAt = 135;
equip.MillisecondsBetweenFiringStages = 2;
equip.MillisecondsBetweenReloadingStages = 10;
equip.FiringModelNumbers = new ArrayList<>(Arrays.asList(
trebuchet.shotAmount = 2;
trebuchet.rotateStandHead = false;
trebuchet.rotateSideways = true;
trebuchet.fuelItem = new ItemStack(Material.STRING);
trebuchet.projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
trebuchet.readyModelNumber = 122;
trebuchet.modelNumberToFireAt = 135;
trebuchet.millisecondsBetweenFiringStages = 2;
trebuchet.millisecondsBetweenReloadingStages = 10;
trebuchet.firingModelNumbers = new ArrayList<>(Arrays.asList(
123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139
));
equip.CycleThroughModelsBeforeFiring = true;
DefinedEquipment.put(equip.ReadyModelNumber, equip);
trebuchet.cycleThroughModelsBeforeFiring = true;
DefinedEquipment.put(trebuchet.readyModelNumber, trebuchet);
equip = new SiegeEquipment();
equip.EquipmentName = "Naval Cannon";
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
equip.PlacementOffsetY = -1;
equip.shotAmount = 1;
equip.ReadyModelNumber = 142;
equip.ModelNumberToFireAt = 142;
equip.FiringModelNumbers = new ArrayList<Integer>();
equip.RotateStandHead = true;
equip.RotateSideways = false;
SiegeEngine navalCannon = new SiegeEngine("Naval Cannon", new HashMap<ItemStack, GunnersProjectile>(), new ItemStack(Material.GUNPOWDER), 142);
navalCannon.projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
navalCannon.placementOffsetY = -1;
navalCannon.shotAmount = 1;
navalCannon.readyModelNumber = 142;
navalCannon.modelNumberToFireAt = 142;
navalCannon.firingModelNumbers = new ArrayList<Integer>();
navalCannon.rotateStandHead = true;
navalCannon.rotateSideways = false;
proj = new ExplosiveProjectile();
proj.ExplodePower = 1;
proj.ProjectilesCount = 5;
proj.DelayedFire = true;
proj.Inaccuracy = 0.75f;
equip.Projectiles.put(new ItemStack(Material.TNT), proj);
navalCannon.projectiles.put(new ItemStack(Material.TNT), proj);
proj = new ExplosiveProjectile();
proj.ExplodePower = 3;
proj.ProjectilesCount = 1;
equip.Projectiles.put(new ItemStack(Material.IRON_BLOCK), proj);
navalCannon.projectiles.put(new ItemStack(Material.IRON_BLOCK), proj);
EntityProjectile fireProj = new EntityProjectile();
fireProj.EntityCount = 4;
@@ -235,43 +189,43 @@ public class SiegeEngines extends JavaPlugin {
fireProj.ParticleType = Particle.WHITE_ASH;
fireProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
fireProj.Inaccuracy = 0.75f;
equip.Projectiles.put(new ItemStack(Material.FIRE_CHARGE), fireProj);
DefinedEquipment.put(equip.ReadyModelNumber, equip);
equip = new SiegeEquipment();
equip.EquipmentName = "Siege Cannon";
navalCannon.projectiles.put(new ItemStack(Material.FIRE_CHARGE), fireProj);
DefinedEquipment.put(navalCannon.readyModelNumber, navalCannon);
SiegeEngine siegeCannon = new SiegeEngine("Siege Cannon", new HashMap<ItemStack, GunnersProjectile>(), new ItemStack(Material.GUNPOWDER), 141);
proj.ExplodePower = 2;
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
equip.shotAmount = 1;
equip.PlacementOffsetY = -1;
equip.ReadyModelNumber = 141;
equip.ModelNumberToFireAt = 141;
equip.FiringModelNumbers = new ArrayList<Integer>();
equip.RotateStandHead = true;
equip.RotateSideways = true;
siegeCannon.projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
siegeCannon.shotAmount = 1;
siegeCannon.placementOffsetY = -1;
siegeCannon.readyModelNumber = 141;
siegeCannon.modelNumberToFireAt = 141;
siegeCannon.firingModelNumbers = new ArrayList<Integer>();
siegeCannon.rotateStandHead = true;
siegeCannon.rotateSideways = true;
proj = new ExplosiveProjectile();
proj.ExplodePower = 2;
proj.ProjectilesCount = 3;
proj.DelayedFire = true;
proj.Inaccuracy = 0.75f;
equip.Projectiles.put(new ItemStack(Material.TNT), proj);
siegeCannon.projectiles.put(new ItemStack(Material.TNT), proj);
proj = new ExplosiveProjectile();
proj.ExplodePower = 3;
proj.ProjectilesCount = 1;
equip.Projectiles.put(new ItemStack(Material.IRON_BLOCK), proj);
siegeCannon.projectiles.put(new ItemStack(Material.IRON_BLOCK), proj);
EntityProjectile scatterShot = new EntityProjectile();
scatterShot.Inaccuracy = 0.5f;
scatterShot.EntityCount = 24;
scatterShot.ParticleType = Particle.ELECTRIC_SPARK;
scatterShot.SoundType = Sound.ITEM_CROSSBOW_SHOOT;
equip.Projectiles.put(new ItemStack(Material.GRAVEL), scatterShot);
DefinedEquipment.put(equip.ReadyModelNumber, equip);
siegeCannon.projectiles.put(new ItemStack(Material.GRAVEL), scatterShot);
DefinedEquipment.put(siegeCannon.readyModelNumber, siegeCannon);
}
public static Boolean placeEquipment(Entity player, int CustomModelData, Location l) {
l.add(0.5, 0, 0.5);
NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons");
SiegeEquipment equip = CreateClone(CustomModelData);
if (equip == null || !equip.Enabled) {
SiegeEngine siegeEngine = CreateClone(CustomModelData);
if (siegeEngine == null || !siegeEngine.enabled) {
return false;
}
l.setY(l.getY() + 1);
@@ -280,17 +234,17 @@ public class SiegeEngines extends JavaPlugin {
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = item.getItemMeta();
String id = "";
equip.AmmoHolder = new EquipmentMagazine();
if (equip.HasBaseStand) {
siegeEngine.ammoHolder = new EquipmentMagazine();
if (siegeEngine.hasBaseStand) {
Location l2 = l;
l2.setY(l.getY() + equip.BaseStandOffset);
l2.setY(l.getY() + siegeEngine.baseStandOffset);
Entity entity3 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
LivingEntity ent = (LivingEntity) entity3;
ArmorStand stand = (ArmorStand) ent;
id = entity3.getUniqueId().toString();
meta.setCustomModelData(equip.BaseStandModelNumber);
meta.setCustomModelData(siegeEngine.baseStandModelNumber);
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
@@ -302,20 +256,20 @@ public class SiegeEngines extends JavaPlugin {
stand.setBasePlate(false);
// stand.setSmall(true);
item.setItemMeta(meta);
stand.setInvisible(equip.AllowInvisibleStand);
stand.setInvisible(siegeEngine.allowInvisibleStand);
ent.getEquipment().setHelmet(item);
stand.setGravity(false);
stand.setMarker(true);
}
l.setY(l.getY() + equip.PlacementOffsetY);
l.setY(l.getY() + siegeEngine.placementOffsetY);
Entity entity2 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
if (id != "") {
entity2.getPersistentDataContainer().set(key, PersistentDataType.STRING, id);
}
meta.setCustomModelData(equip.ReadyModelNumber);
meta.setDisplayName("§e" + equip.EquipmentName + " Item");
meta.setCustomModelData(siegeEngine.readyModelNumber);
meta.setDisplayName("§e" + siegeEngine.name + " Item");
List<String> Lore = new ArrayList<String>();
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand.");
Lore.add("§ePlace as a block to spawn a " + siegeEngine.name + " or put on an Armor Stand.");
meta.setLore(Lore);
item.setItemMeta(meta);
@@ -323,9 +277,9 @@ public class SiegeEngines extends JavaPlugin {
LivingEntity ent = (LivingEntity) entity2;
ArmorStand stand = (ArmorStand) ent;
equip.Entity = entity2;
siegeEngine.entity = entity2;
equip.EntityId = entity2.getUniqueId();
siegeEngine.entityId = entity2.getUniqueId();
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
@@ -334,7 +288,7 @@ public class SiegeEngines extends JavaPlugin {
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.setInvisible(siegeEngine.allowInvisibleStand);
stand.setBasePlate(true);
stand.setGravity(false);
@@ -348,7 +302,7 @@ public class SiegeEngines extends JavaPlugin {
newList.add(entity2);
TrackedStands.put(player.getUniqueId(), newList);
}
equipment.put(entity2.getUniqueId(), equip);
equipment.put(entity2.getUniqueId(), siegeEngine);
return true;
}