use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.
the class WeaponMechanics method loadConfig.
void loadConfig() {
debug.debug("Loading and serializing config");
try {
List<?> serializers = new SerializerInstancer(new JarFile(getFile())).createAllInstances(getClassLoader());
// noinspection unchecked
MechanicsCore.addSerializers(getPlugin(), (List<Serializer<?>>) serializers);
} catch (IOException e) {
e.printStackTrace();
return;
}
if (configurations == null) {
configurations = new LinkedConfig();
} else {
configurations.clear();
}
List<IValidator> validators = null;
try {
// Find all validators in WeaponMechanics
validators = new JarInstancer(new JarFile(getFile())).createAllInstances(IValidator.class, getClassLoader(), true);
} catch (IOException e) {
e.printStackTrace();
}
// Fill configuration mappings (except config.yml)
Configuration temp = new FileReader(debug, MechanicsCore.getListOfSerializers(), validators).fillAllFiles(getDataFolder(), "config.yml");
try {
configurations.add(temp);
} catch (DuplicateKeyException e) {
debug.error("Error loading config: " + e.getMessage());
}
}
use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.
the class DamageHandler method tryUse.
/**
* @return false if damaging was cancelled
*/
public boolean tryUse(LivingEntity victim, double damage, DamagePoint point, boolean isBackstab, LivingEntity shooter, String weaponTitle, ItemStack weaponStack, double distanceTravelled) {
Configuration config = getConfigurations();
boolean isFriendlyFire = config.getBool(weaponTitle + ".Damage.Enable_Friendly_Fire");
if (!isFriendlyFire && !DamageUtil.canHarm(shooter, victim)) {
return false;
}
boolean isOwnerImmune = config.getBool(weaponTitle + ".Damage.Enable_Owner_Immunity");
if (isOwnerImmune && victim.equals(shooter)) {
return false;
}
// Critical Hit chance
double chance = config.getDouble(weaponTitle + ".Damage.Critical_Hit.Chance", -1);
boolean isCritical = chance != -1 && NumberUtil.chance((chance / 100));
int armorDamage = config.getInt(weaponTitle + ".Damage.Armor_Damage");
int fireTicks = config.getInt(weaponTitle + ".Damage.Fire_Ticks");
WeaponDamageEntityEvent damageEntityEvent = new WeaponDamageEntityEvent(weaponTitle, weaponStack, shooter, victim, damage, isBackstab, isCritical, point, armorDamage, fireTicks, distanceTravelled);
Bukkit.getPluginManager().callEvent(damageEntityEvent);
if (damageEntityEvent.isCancelled())
return false;
fireTicks = damageEntityEvent.getFireTicks();
point = damageEntityEvent.getPoint();
if (DamageUtil.apply(shooter, victim, damageEntityEvent.getFinalDamage())) {
WeaponMechanics.debug.debug("Damage was cancelled");
// Damage was cancelled
return false;
}
DamageUtil.damageArmor(victim, damageEntityEvent.getArmorDamage(), point);
// Fire ticks
if (fireTicks > 0) {
victim.setFireTicks(fireTicks);
}
EntityWrapper shooterWrapper = WeaponMechanics.getEntityWrapper(shooter, true);
CastData shooterCast;
if (shooterWrapper != null) {
shooterCast = new CastData(shooterWrapper, weaponTitle, weaponStack);
} else {
shooterCast = new CastData(shooter, weaponTitle, weaponStack);
}
shooterCast.setData(CommonDataTags.TARGET_LOCATION.name(), victim.getLocation());
shooterCast.setData(CommonDataTags.SHOOTER_NAME.name(), shooter.getName());
shooterCast.setData(CommonDataTags.VICTIM_NAME.name(), victim.getName());
EntityWrapper victimWrapper = WeaponMechanics.getEntityWrapper(victim, true);
CastData victimCast;
if (victimWrapper != null) {
victimCast = new CastData(victimWrapper, weaponTitle, weaponStack);
} else {
victimCast = new CastData(victim, weaponTitle, weaponStack);
}
victimCast.setData(CommonDataTags.TARGET_LOCATION.name(), shooter.getLocation());
victimCast.setData(CommonDataTags.SHOOTER_NAME.name(), shooter.getName());
victimCast.setData(CommonDataTags.VICTIM_NAME.name(), victim.getName());
// On all damage
useMechanics(config, shooterCast, victimCast, weaponTitle + ".Damage");
// On point
if (point != null)
useMechanics(config, shooterCast, victimCast, weaponTitle + ".Damage." + point.getReadable());
// On backstab
if (damageEntityEvent.isBackstab()) {
useMechanics(config, shooterCast, victimCast, weaponTitle + ".Damage.Backstab");
}
// On critical
if (damageEntityEvent.isCritical()) {
useMechanics(config, shooterCast, victimCast, weaponTitle + ".Damage.Critical_Hit");
}
if (victim.isDead() || victim.getHealth() <= 0.0) {
Bukkit.getPluginManager().callEvent(new WeaponKillEntityEvent(weaponTitle, weaponStack, shooter, victim, damageEntityEvent));
// On kill
useMechanics(config, shooterCast, victimCast, weaponTitle + ".Damage.Kill");
}
return true;
}
use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.
the class MeleeHandler method meleeWithoutTimings.
private boolean meleeWithoutTimings(EntityWrapper entityWrapper, String weaponTitle, ItemStack weaponStack, EquipmentSlot slot, TriggerType triggerType, boolean dualWield, @Nullable LivingEntity knownVictim) {
Configuration config = getConfigurations();
HandData handData = entityWrapper.getMainHandData();
int meleeHitDelay = config.getInt(weaponTitle + ".Melee.Melee_Hit_Delay");
if (meleeHitDelay != 0 && !NumberUtil.hasMillisPassed(handData.getLastMeleeTime(), meleeHitDelay))
return false;
int meleeMissDelay = config.getInt(weaponTitle + ".Melee.Melee_Miss.Melee_Miss_Delay");
if (meleeMissDelay != 0 && !NumberUtil.hasMillisPassed(handData.getLastMeleeMissTime(), meleeMissDelay))
return false;
double meleeRange = config.getDouble(weaponTitle + ".Melee.Melee_Range");
LivingEntity shooter = entityWrapper.getEntity();
Location eyeLocation = shooter.getEyeLocation();
Vector direction = eyeLocation.getDirection();
RayTraceResult hit = getHit(shooter, eyeLocation, direction, meleeRange, knownVictim);
boolean result = false;
if (hit != null) {
result = weaponHandler.getShootHandler().shootWithoutTrigger(entityWrapper, weaponTitle, weaponStack, slot, triggerType, dualWield);
if (result) {
if (meleeHitDelay != 0) {
handData.setLastMeleeTime(System.currentTimeMillis());
if (getConfigurations().getBool(weaponTitle + ".Info.Show_Cooldown.Melee_Hit_Delay") && shooter.getType() == EntityType.PLAYER) {
CompatibilityAPI.getEntityCompatibility().setCooldown((Player) shooter, weaponStack.getType(), meleeHitDelay / 50);
}
}
hit.handleMeleeHit(shooter, direction, weaponTitle, weaponStack);
}
} else {
// Handle miss
Mechanics meleeMissMechanics = getConfigurations().getObject(weaponTitle + ".Melee.Melee_Miss.Mechanics", Mechanics.class);
if (meleeMissMechanics != null)
meleeMissMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack));
if (getConfigurations().getBool(weaponTitle + ".Melee.Melee_Miss.Consume_On_Miss")) {
weaponHandler.getShootHandler().shootWithoutTrigger(entityWrapper, weaponTitle, weaponStack, slot, triggerType, dualWield);
result = true;
}
if (meleeMissDelay != 0) {
handData.setLastMeleeMissTime(System.currentTimeMillis());
if (getConfigurations().getBool(weaponTitle + ".Info.Show_Cooldown.Melee_Miss_Delay") && shooter.getType() == EntityType.PLAYER) {
CompatibilityAPI.getEntityCompatibility().setCooldown((Player) shooter, weaponStack.getType(), meleeMissDelay / 50);
}
}
}
return result;
}
use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.
the class MeleeHandler method tryUse.
/**
* Tries to use melee
*
* @param entityWrapper the entity who used trigger
* @param weaponTitle the weapon title
* @param weaponStack the weapon stack
* @param slot the slot used on trigger
* @param triggerType the trigger type trying to activate melee
* @param dualWield whether this was dual wield
* @return true if was able to melee
*/
public boolean tryUse(EntityWrapper entityWrapper, String weaponTitle, ItemStack weaponStack, EquipmentSlot slot, TriggerType triggerType, boolean dualWield, @Nullable LivingEntity knownVictim) {
if (triggerType != TriggerType.MELEE)
return false;
Configuration config = getConfigurations();
if (!config.getBool(weaponTitle + ".Melee.Enable_Melee")) {
// Change weapon title to match the attachment
weaponTitle = config.getString(weaponTitle + ".Melee.Melee_Attachment");
// Melee isn't used for this weapon nor the melee attachment is defined
if (weaponTitle == null)
return false;
}
MCTiming meleeHandlerTiming = WeaponMechanics.timing("Melee Handler").startTiming();
boolean result = meleeWithoutTimings(entityWrapper, weaponTitle, weaponStack, slot, triggerType, dualWield, knownVictim);
meleeHandlerTiming.stopTiming();
return result;
}
use of me.deecaad.core.file.Configuration in project MechanicsMain by WeaponMechanics.
the class ScopeHandler method tryUse.
/**
* Tries to use scope
*
* @param entityWrapper the entity who used trigger
* @param weaponTitle the weapon title
* @param weaponStack the weapon stack
* @param slot the slot used on trigger
* @param triggerType the trigger type trying to activate scope
* @return true if the scope used successfully to zoom in, our or stack
*/
public boolean tryUse(EntityWrapper entityWrapper, String weaponTitle, ItemStack weaponStack, EquipmentSlot slot, TriggerType triggerType, boolean dualWield) {
Configuration config = getConfigurations();
// Don't try to scope if either one of the hands is reloading
if (entityWrapper.getMainHandData().isReloading() || entityWrapper.getOffHandData().isReloading()) {
return false;
}
ZoomData zoomData;
// Only allow using zoom at one hand at time
if (slot == EquipmentSlot.HAND) {
if (entityWrapper.getOffHandData().getZoomData().isZooming()) {
return false;
}
zoomData = entityWrapper.getMainHandData().getZoomData();
} else {
if (entityWrapper.getMainHandData().getZoomData().isZooming()) {
return false;
}
zoomData = entityWrapper.getOffHandData().getZoomData();
}
Trigger trigger = config.getObject(weaponTitle + ".Scope.Trigger", Trigger.class);
if (trigger == null)
return false;
// Check if entity is already zooming
if (zoomData.isZooming()) {
Trigger offTrigger = config.getObject(weaponTitle + ".Scope.Zoom_Off.Trigger", Trigger.class);
// If off trigger is valid -> zoom out even if stacking hasn't reached maximum stacks
if (offTrigger != null && offTrigger.check(triggerType, slot, entityWrapper)) {
return zoomOut(weaponStack, weaponTitle, entityWrapper, zoomData, slot);
}
// If trigger is valid zoom in or out depending on situation
if (trigger.check(triggerType, slot, entityWrapper)) {
int maximumStacks = config.getInt(weaponTitle + ".Scope.Zoom_Stacking.Maximum_Stacks");
if (maximumStacks <= 0) {
// Should turn off
return zoomOut(weaponStack, weaponTitle, entityWrapper, zoomData, slot);
}
if (zoomData.getZoomStacks() < maximumStacks) {
// Zoom in handles stacking on its own
return zoomIn(weaponStack, weaponTitle, entityWrapper, zoomData, slot);
}
// Should turn off (because zoom stacks have reached maximum stacks)
return zoomOut(weaponStack, weaponTitle, entityWrapper, zoomData, slot);
}
} else if (trigger.check(triggerType, slot, entityWrapper)) {
// Try zooming in since entity is not zooming
return zoomIn(weaponStack, weaponTitle, entityWrapper, zoomData, slot);
}
return false;
}
Aggregations