Search in sources :

Example 16 with Configuration

use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.

the class ShootHandler method shoot.

/**
 * Shoots using weapon.
 * Does not use ammo nor check for it.
 */
public void shoot(EntityWrapper entityWrapper, String weaponTitle, ItemStack weaponStack, Location shootLocation, boolean mainHand, boolean updateSpreadChange, boolean isMelee) {
    Configuration config = getConfigurations();
    LivingEntity livingEntity = entityWrapper.getEntity();
    if (!isMelee) {
        HandData handData = mainHand ? entityWrapper.getMainHandData() : entityWrapper.getOffHandData();
        handData.setLastShotTime(System.currentTimeMillis());
        if (getConfigurations().getBool(weaponTitle + ".Info.Show_Cooldown.Delay_Between_Shots") && entityWrapper.getEntity().getType() == EntityType.PLAYER) {
            CompatibilityAPI.getEntityCompatibility().setCooldown((Player) entityWrapper, weaponStack.getType(), config.getInt(weaponTitle + ".Shoot.Delay_Between_Shots") / 50);
        }
    }
    Mechanics shootMechanics = config.getObject(weaponTitle + ".Shoot.Mechanics", Mechanics.class);
    if (shootMechanics != null)
        shootMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack));
    if (entityWrapper instanceof PlayerWrapper) {
        WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class);
        if (weaponInfoDisplay != null)
            weaponInfoDisplay.send((PlayerWrapper) entityWrapper, mainHand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND);
    }
    Projectile projectile = config.getObject(weaponTitle + ".Projectile", Projectile.class);
    if (projectile == null || isMelee) {
        // No projectile defined or was melee trigger
        return;
    }
    Spread spread = config.getObject(weaponTitle + ".Shoot.Spread", Spread.class);
    Recoil recoil = config.getObject(weaponTitle + ".Shoot.Recoil", Recoil.class);
    double projectileSpeed = config.getDouble(weaponTitle + ".Shoot.Projectile_Speed");
    for (int i = 0; i < config.getInt(weaponTitle + ".Shoot.Projectiles_Per_Shot"); ++i) {
        // i == 0
        // -> Only allow spread changing on first shot
        Vector motion = spread != null ? spread.getNormalizedSpreadDirection(entityWrapper, mainHand, i == 0 && updateSpreadChange).multiply(projectileSpeed) : livingEntity.getLocation().getDirection().multiply(projectileSpeed);
        if (recoil != null && i == 0 && livingEntity instanceof Player) {
            recoil.start((Player) livingEntity, mainHand);
        }
        // Only create bullet first if WeaponShootEvent changes
        WeaponProjectile bullet = projectile.create(livingEntity, shootLocation, motion, weaponStack, weaponTitle);
        WeaponShootEvent shootEvent = new WeaponShootEvent(bullet);
        Bukkit.getPluginManager().callEvent(shootEvent);
        bullet = shootEvent.getProjectile();
        // Shoot the given bullet
        projectile.shoot(bullet, shootLocation);
    }
}
Also used : CastData(me.deecaad.weaponmechanics.mechanics.CastData) Player(org.bukkit.entity.Player) Configuration(me.deecaad.core.file.Configuration) WeaponShootEvent(me.deecaad.weaponmechanics.weapon.weaponevents.WeaponShootEvent) Recoil(me.deecaad.weaponmechanics.weapon.shoot.recoil.Recoil) PlayerWrapper(me.deecaad.weaponmechanics.wrappers.PlayerWrapper) Projectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile) WeaponProjectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile) LivingEntity(org.bukkit.entity.LivingEntity) Spread(me.deecaad.weaponmechanics.weapon.shoot.spread.Spread) WeaponProjectile(me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.WeaponProjectile) Mechanics(me.deecaad.weaponmechanics.mechanics.Mechanics) WeaponMechanics(me.deecaad.weaponmechanics.WeaponMechanics) WeaponInfoDisplay(me.deecaad.weaponmechanics.weapon.info.WeaponInfoDisplay) Vector(org.bukkit.util.Vector) HandData(me.deecaad.weaponmechanics.wrappers.HandData)

Example 17 with Configuration

use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.

the class WeaponDamageEntityEvent method getFinalDamage.

public double getFinalDamage() {
    if (Double.isNaN(finalDamage)) {
        Configuration config = WeaponMechanics.getConfigurations();
        // Calculate the final damage and save its value
        // Final damage value is reset if set point, damage
        // critical or backstab methods are used
        double damage = this.baseDamage;
        if (point != null) {
            damage += config.getDouble(weaponTitle + ".Damage." + point.getReadable() + ".Bonus_Damage");
        }
        // Damage changes based on how far the projectile travelled
        DamageDropoff dropoff = config.getObject(weaponTitle + ".Damage.Dropoff", DamageDropoff.class);
        if (dropoff != null) {
            damage += dropoff.getDamage(distanceTravelled);
        }
        // Critical Hit chance
        if (isCritical) {
            damage += config.getDouble(weaponTitle + ".Damage.Critical_Hit.Bonus_Damage");
        }
        // Backstab damage
        if (isBackstab) {
            damage += config.getDouble(weaponTitle + ".Damage.Backstab.Bonus_Damage");
        }
        if (damage < 0) {
            damage = 0;
        }
        return finalDamage = DamageUtil.calculateFinalDamage(getShooter(), victim, damage, point, isBackstab);
    }
    return finalDamage;
}
Also used : DamageDropoff(me.deecaad.weaponmechanics.weapon.damage.DamageDropoff) Configuration(me.deecaad.core.file.Configuration)

Example 18 with Configuration

use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.

the class WeaponMechanics method writeFiles.

void writeFiles() {
    // Create files
    if (!getDataFolder().exists() || getDataFolder().listFiles() == null || getDataFolder().listFiles().length == 0) {
        debug.info("Copying files from jar (This process may take up to 30 seconds during the first load!)");
        try {
            FileUtil.copyResourcesTo(getClassLoader().getResource("WeaponMechanics"), getDataFolder().toPath());
        } catch (IOException | URISyntaxException e) {
            e.printStackTrace();
        }
    }
    try {
    // TODO bad programmars comment out broken code
    // FileUtil.ensureDefaults(getClassLoader(), "WeaponMechanics/config.yml", new File(getDataFolder(), "config.yml"));
    } catch (YAMLException e) {
        debug.error("WeaponMechanics jar corruption... This is most likely caused by using /reload after building jar!");
    }
    // Fill config.yml mappings
    File configyml = new File(getDataFolder(), "config.yml");
    if (configyml.exists()) {
        List<IValidator> validators = new ArrayList<>();
        // No need for other validators here as this is only for config.yml
        validators.add(new HitBox());
        FileReader basicConfigurationReader = new FileReader(debug, null, validators);
        Configuration filledMap = basicConfigurationReader.fillOneFile(configyml);
        basicConfiguration = basicConfigurationReader.usePathToSerializersAndValidators(filledMap);
    } else {
        // Just creates empty map to prevent other issues
        basicConfiguration = new LinkedConfig();
        debug.log(LogLevel.WARN, "Could not locate config.yml?", "Make sure it exists in path " + getDataFolder() + "/config.yml");
    }
    // Ensure that the resource pack exists in the folder
    if (basicConfiguration.getBool("Resource_Pack_Download.Enabled")) {
        String link = basicConfiguration.getString("Resource_Pack_Download.Link");
        int connection = basicConfiguration.getInt("Resource_Pack_Download.Connection_Timeout");
        int read = basicConfiguration.getInt("Resource_Pack_Download.Read_Timeout");
        File pack = new File(getDataFolder(), "WeaponMechanicsResourcePack.zip");
        if (!pack.exists()) {
            FileUtil.downloadFile(pack, link, connection, read);
        }
    }
}
Also used : HitBox(me.deecaad.weaponmechanics.weapon.projectile.HitBox) Configuration(me.deecaad.core.file.Configuration) LinkedConfig(me.deecaad.core.file.LinkedConfig) ArrayList(java.util.ArrayList) YAMLException(org.yaml.snakeyaml.error.YAMLException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IValidator(me.deecaad.core.file.IValidator) FileReader(me.deecaad.core.file.FileReader) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 19 with Configuration

use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.

the class HitboxCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    if (!(sender instanceof Player)) {
        sender.sendMessage(ChatColor.RED + "This command is only available for players.");
        return;
    }
    Player player = (Player) sender;
    Location location = player.getLocation();
    int ticks = (args.length > 0) ? Integer.parseInt(args[0]) : 200;
    Collection<Entity> entities = location.getWorld().getNearbyEntities(location, 16, 16, 16);
    Configuration basicConfiguration = WeaponMechanics.getBasicConfigurations();
    new BukkitRunnable() {

        int ticksPassed = 0;

        public void run() {
            for (Entity entity : entities) {
                if (!(entity instanceof LivingEntity))
                    continue;
                if (entity.equals(player))
                    continue;
                EntityType type = entity.getType();
                double head = basicConfiguration.getDouble("Entity_Hitboxes." + type.name() + "." + DamagePoint.HEAD.name(), -1);
                double body = basicConfiguration.getDouble("Entity_Hitboxes." + type.name() + "." + DamagePoint.BODY.name(), -1);
                double legs = basicConfiguration.getDouble("Entity_Hitboxes." + type.name() + "." + DamagePoint.LEGS.name(), -1);
                double feet = basicConfiguration.getDouble("Entity_Hitboxes." + type.name() + "." + DamagePoint.FEET.name(), -1);
                if (head == -1 || body == -1 || legs == -1 || feet == -1) {
                    debug.log(LogLevel.ERROR, "Entity type " + type.name() + " is missing some of its damage point values, please add it", "Located at file /WeaponMechanics/config.yml in Entity_Hitboxes." + type.name() + " in configurations", "Its missing one of these: HEAD, BODY, LEGS or FEET");
                    continue;
                }
                double sumOf = head + body + legs + feet;
                if (Math.abs(sumOf - 1.0) > 1e-5) {
                    // If the numbers are not super close together (floating point issues)
                    debug.log(LogLevel.ERROR, "Entity type " + type.name() + " hit box values sum doesn't match 1.0", "Located at file /WeaponMechanics/config.yml in Entity_Hitboxes." + type.name() + " in configurations", "Now the total sum was " + sumOf + ", please make it 1.0.");
                    continue;
                }
                BoundingBox box = entity.getBoundingBox();
                double max = box.getMaxY();
                double height = box.getHeight();
                double headY = max - (height * head);
                double bodyY = max - (height * (head + body));
                double legsY = max - (height * (head + body + legs));
                // this could also be just box.getMinY()
                double feetY = max - (height * (head + body + legs + feet));
                for (double x = box.getMinX(); x <= box.getMaxX(); x += 0.25) {
                    for (double z = box.getMinZ(); z <= box.getMaxZ(); z += 0.25) {
                        if (head > 0.0) {
                            entity.getWorld().spawnParticle(Particle.REDSTONE, x, headY, z, 1, 0, 0, 0, 0.0001, new Particle.DustOptions(Color.RED, 1.0f), true);
                        }
                        if (body > 0.0) {
                            entity.getWorld().spawnParticle(Particle.REDSTONE, x, bodyY, z, 1, 0, 0, 0, 0.0001, new Particle.DustOptions(Color.ORANGE, 1.0f), true);
                        }
                        if (legs > 0.0) {
                            entity.getWorld().spawnParticle(Particle.REDSTONE, x, legsY, z, 1, 0, 0, 0, 0.0001, new Particle.DustOptions(Color.YELLOW, 1.0f), true);
                        }
                        if (feet > 0.0) {
                            entity.getWorld().spawnParticle(Particle.REDSTONE, x, feetY, z, 1, 0, 0, 0, 0.0001, new Particle.DustOptions(Color.GREEN, 1.0f), true);
                        }
                    }
                }
            }
            ticksPassed += 5;
            if (ticksPassed >= ticks) {
                cancel();
            }
        }
    }.runTaskTimerAsynchronously(WeaponMechanics.getPlugin(), 0, 5);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) EntityType(org.bukkit.entity.EntityType) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Configuration(me.deecaad.core.file.Configuration) BoundingBox(org.bukkit.util.BoundingBox) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) DamagePoint(me.deecaad.weaponmechanics.weapon.damage.DamagePoint) Location(org.bukkit.Location)

Aggregations

Configuration (me.deecaad.core.file.Configuration)19 CastData (me.deecaad.weaponmechanics.mechanics.CastData)7 Mechanics (me.deecaad.weaponmechanics.mechanics.Mechanics)6 LivingEntity (org.bukkit.entity.LivingEntity)6 WeaponMechanics (me.deecaad.weaponmechanics.WeaponMechanics)5 PlayerWrapper (me.deecaad.weaponmechanics.wrappers.PlayerWrapper)5 Location (org.bukkit.Location)5 WeaponInfoDisplay (me.deecaad.weaponmechanics.weapon.info.WeaponInfoDisplay)4 HandData (me.deecaad.weaponmechanics.wrappers.HandData)4 ItemStack (org.bukkit.inventory.ItemStack)4 Vector (org.bukkit.util.Vector)4 ReloadHandler (me.deecaad.weaponmechanics.weapon.reload.ReloadHandler)3 Trigger (me.deecaad.weaponmechanics.weapon.trigger.Trigger)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 IOException (java.io.IOException)2 JarFile (java.util.jar.JarFile)2 FileReader (me.deecaad.core.file.FileReader)2 IValidator (me.deecaad.core.file.IValidator)2 LinkedConfig (me.deecaad.core.file.LinkedConfig)2 FirearmAction (me.deecaad.weaponmechanics.weapon.firearm.FirearmAction)2