mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-01 22:22:10 +00:00
placement
This commit is contained in:
1 parent
49ec9c788d
commit
98b8abd01a
8 files changed
+116
-52
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2
-2
@@ -3,7 +3,7 @@ main: siegeCore.CrunchSiegeCore
|
||||
version: 1.0
|
||||
api-version: 1.18
|
||||
commands:
|
||||
siegetest:
|
||||
crunchsiege:
|
||||
description: show event details and progress
|
||||
default: false
|
||||
usage: siegetest
|
||||
usage: crunchsiege
|
||||
@@ -15,6 +15,7 @@ import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
@@ -71,6 +72,22 @@ public class ClickHandler implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent event) {
|
||||
Player thePlayer = event.getPlayer();
|
||||
if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.CARVED_PUMPKIN)
|
||||
{
|
||||
ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
|
||||
if (item.getItemMeta() != null && item.getItemMeta().hasCustomModelData()) {
|
||||
int customModel = item.getItemMeta().getCustomModelData();
|
||||
CrunchSiegeCore.CreateTrebuchet(thePlayer, customModel, event.getBlockAgainst().getLocation());
|
||||
event.setCancelled(true);
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
thePlayer.getInventory().setItemInMainHand(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Shoot(Player player, long delay) {
|
||||
float actualDelay = delay;
|
||||
@@ -110,14 +127,14 @@ public class ClickHandler implements Listener {
|
||||
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.PAPER) {
|
||||
// ItemMeta meta = ItemInHand.getItemMeta();
|
||||
// if (meta.hasCustomModelData() && meta.getCustomModelData() == 505050505) {
|
||||
// CrunchSiegeCore.CreateTrebuchet(player);
|
||||
// ItemInHand.setAmount(ItemInHand.getAmount() - 1);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
if (event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
@@ -167,7 +184,7 @@ public class ClickHandler implements Listener {
|
||||
}
|
||||
else {
|
||||
equip = CrunchSiegeCore.CreateClone(living.getEquipment().getHelmet().getItemMeta().getCustomModelData());
|
||||
|
||||
|
||||
equip.AmmoHolder = new EquipmentMagazine();
|
||||
equip.Entity = entity;
|
||||
equip.EntityId = entity.getUniqueId();
|
||||
@@ -291,13 +308,13 @@ public class ClickHandler implements Listener {
|
||||
player.sendMessage("Releasing the cannons!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
|
||||
if (player.isSneaking()) {
|
||||
SaveCannons(player, event.getClickedBlock());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
NamespacedKey key = new NamespacedKey(CrunchSiegeCore.plugin, "cannons");
|
||||
TileState state = (TileState) sign.getBlock().getState();
|
||||
CrunchSiegeCore.TrackedStands.remove(player.getUniqueId());
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.ArmorStand.LockType;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -56,16 +57,16 @@ import CrunchProjectiles.PotionProjectile;
|
||||
|
||||
public class CrunchSiegeCore extends JavaPlugin {
|
||||
public static Plugin plugin;
|
||||
|
||||
|
||||
public static Random random = new Random();
|
||||
private static String Path;
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
Path = this.getDataFolder().getAbsolutePath();
|
||||
this.getCommand("siegetest").setExecutor(new SiegeCommand());
|
||||
this.getCommand("crunchsiege").setExecutor(new SiegeCommand());
|
||||
getServer().getPluginManager().registerEvents(new RotationHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new ClickHandler(), this);
|
||||
StorageManager.setup(Path, plugin);
|
||||
@@ -77,28 +78,72 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
}
|
||||
DefinedEquipment.clear();
|
||||
}
|
||||
LoadConfigs();
|
||||
}
|
||||
|
||||
public static void LoadConfigs() {
|
||||
|
||||
File folder = new File(Path);
|
||||
File[] listOfFiles = folder.listFiles();
|
||||
|
||||
for (int i = 0; i < listOfFiles.length; i++) {
|
||||
if (listOfFiles[i].isFile()) {
|
||||
SiegeEquipment equip = StorageManager.load(listOfFiles[i].getAbsolutePath());
|
||||
DefinedEquipment.put(equip.ReadyModelNumber, equip);
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SiegeCommand implements CommandExecutor {
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
public class SiegeCommand implements CommandExecutor {
|
||||
@Override
|
||||
@EventHandler
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
Player player = null;
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (player.isOp()) {
|
||||
CreateTrebuchet(player);
|
||||
player = (Player) sender;
|
||||
}
|
||||
if (args != null && args.length > 0) {
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "get":
|
||||
if (player == null) {
|
||||
sender.sendMessage("only a player can use this command.");
|
||||
return true;
|
||||
}
|
||||
if (!sender.hasPermission("crunchsiege.get")) {
|
||||
sender.sendMessage("No perms to crunchsiege.get");
|
||||
return true;
|
||||
}
|
||||
for (SiegeEquipment 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");
|
||||
List<String> Lore = new ArrayList<String>();
|
||||
Lore.add("§ePlace as a block to spawn a " + i.EquipmentName + " or put on an armour 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");
|
||||
return true;
|
||||
}
|
||||
LoadConfigs();
|
||||
sender.sendMessage("Crunch siege configs reloaded");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
sender.sendMessage("Incorrect usage, /crunchsiege get, /crunchsiege reload");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -109,14 +154,14 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
return DefinedEquipment.get(ModelId).clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static HashMap<Integer, SiegeEquipment> DefinedEquipment = new HashMap<Integer, SiegeEquipment>();
|
||||
|
||||
|
||||
public static HashMap<UUID, List<Entity>> TrackedStands = new HashMap<UUID, List<Entity>>();
|
||||
|
||||
public static HashMap<UUID, SiegeEquipment> equipment = new HashMap<UUID, SiegeEquipment>();
|
||||
@@ -160,7 +205,7 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
fireProj.ParticleType = Particle.WHITE_ASH;
|
||||
fireProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
|
||||
equip.Projectiles.put(Material.DIAMOND, fireProj);
|
||||
|
||||
|
||||
EntityProjectile pig = new EntityProjectile();
|
||||
pig.EntityCount = 100;
|
||||
pig.DelayedFire = true;
|
||||
@@ -179,30 +224,31 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139
|
||||
));
|
||||
equip.CycleThroughModelsBeforeFiring = false;
|
||||
|
||||
|
||||
DefinedEquipment.put(equip.ReadyModelNumber, equip);
|
||||
}
|
||||
|
||||
public static void CreateTrebuchet(Player player) {
|
||||
Location l = player.getLocation();
|
||||
l.setY(l.getY() - 1);
|
||||
public static Location getCenter(Location loc) {
|
||||
return new Location(loc.getWorld(),
|
||||
getRelativeCoord(loc.getBlockX()),
|
||||
getRelativeCoord(loc.getBlockY()),
|
||||
getRelativeCoord(loc.getBlockZ()));
|
||||
}
|
||||
|
||||
private static double getRelativeCoord(int i) {
|
||||
double d = i;
|
||||
d = d < 0 ? d - .5 : d + .5;
|
||||
return d;
|
||||
}
|
||||
public static void CreateTrebuchet(Player player, int CustomModelData, Location l) {
|
||||
//l.setY(l.getY() - 1);
|
||||
l.add(0.5, 0, 0.5);
|
||||
l.setDirection(player.getLocation().getDirection());
|
||||
Entity entity2 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
|
||||
SiegeEquipment equip = new SiegeEquipment();
|
||||
SiegeEquipment equip = CreateClone(CustomModelData);
|
||||
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||
equip.ReadyModelNumber = 122;
|
||||
equip.ModelNumberToFireAt = 135;
|
||||
equip.MillisecondsBetweenFiringStages = 2;
|
||||
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
|
||||
));
|
||||
equip.CycleThroughModelsBeforeFiring = false;
|
||||
equip.Entity = entity2;
|
||||
equip.EntityId = entity2.getUniqueId();
|
||||
entity2.setCustomName("Weapon");
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
meta.setCustomModelData(equip.ReadyModelNumber);
|
||||
|
||||
meta.setCustomModelData(CustomModelData);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
LivingEntity ent = (LivingEntity) entity2;
|
||||
@@ -214,6 +260,7 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
ent.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2000000, 1));
|
||||
// stand.setSmall(true);
|
||||
stand.setVisible(true);
|
||||
stand.setGravity(false);
|
||||
//stand.setSmall(true);
|
||||
ent.getEquipment().setHelmet(item);
|
||||
if (TrackedStands.containsKey(player.getUniqueId())) {
|
||||
|
||||
@@ -32,14 +32,14 @@ public class SiegeEquipment implements Cloneable {
|
||||
public SiegeEquipment clone() throws CloneNotSupportedException {
|
||||
return (SiegeEquipment)super.clone();
|
||||
}
|
||||
|
||||
public Boolean Enabled = false;
|
||||
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 MaxFuel = 5;
|
||||
|
||||
Reference in new issue
Block a user