use of me.deecaad.weaponmechanics.wrappers.HandData in project MechanicsMain by WeaponMechanics.
the class WeaponListeners method equip.
@EventHandler
public void equip(EntityEquipmentEvent e) {
if (e.isArmor())
return;
LivingEntity entity = (LivingEntity) e.getEntity();
EntityWrapper entityWrapper = WeaponMechanics.getEntityWrapper(entity);
ItemStack weaponStack = e.getEquipped();
// Also try auto converting to weapon
String weaponTitle = weaponHandler.getInfoHandler().getWeaponTitle(weaponStack, true);
boolean alreadyUsedEquipMechanics = false;
boolean mainhand = e.getSlot() == EquipmentSlot.HAND;
HandData handData = mainhand ? entityWrapper.getMainHandData() : entityWrapper.getOffHandData();
handData.setCurrentWeaponTitle(weaponTitle);
if (weaponTitle != null) {
if (e.getEntityType() == EntityType.PLAYER) {
WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class);
if (weaponInfoDisplay != null)
weaponInfoDisplay.send((PlayerWrapper) entityWrapper, e.getSlot());
}
weaponHandler.getSkinHandler().tryUse(entityWrapper, weaponTitle, weaponStack, e.getSlot());
Mechanics equipMechanics = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Equip_Mechanics", Mechanics.class);
if (equipMechanics != null) {
equipMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack));
alreadyUsedEquipMechanics = true;
}
handData.setLastEquipTime(System.currentTimeMillis());
if (getConfigurations().getBool(weaponTitle + ".Info.Show_Cooldown.Weapon_Equip_Delay") && e.getEntityType() == EntityType.PLAYER) {
CompatibilityAPI.getEntityCompatibility().setCooldown((Player) entity, weaponStack.getType(), getConfigurations().getInt(weaponTitle + ".Info.Weapon_Equip_Delay") / 50);
} else if (CompatibilityAPI.getEntityCompatibility().hasCooldown((Player) entity, weaponStack.getType())) {
CompatibilityAPI.getEntityCompatibility().setCooldown((Player) entity, weaponStack.getType(), 0);
}
Bukkit.getPluginManager().callEvent(new WeaponEquipEvent(weaponTitle, weaponStack, entity, e.getSlot() == EquipmentSlot.HAND));
}
ItemStack dequipped = e.getDequipped();
String dequippedWeapon = weaponHandler.getInfoHandler().getWeaponTitle(dequipped, false);
if (dequippedWeapon != null) {
// Don't use holster mechanics is equip mechanics were already used
if (!alreadyUsedEquipMechanics) {
Mechanics holsterMechanics = getConfigurations().getObject(dequippedWeapon + ".Info.Weapon_Holster_Mechanics", Mechanics.class);
if (holsterMechanics != null)
holsterMechanics.use(new CastData(entityWrapper, dequippedWeapon, dequipped));
}
if (weaponTitle == null && CompatibilityAPI.getEntityCompatibility().hasCooldown((Player) entity, dequipped.getType())) {
CompatibilityAPI.getEntityCompatibility().setCooldown((Player) entity, dequipped.getType(), 0);
}
}
}
use of me.deecaad.weaponmechanics.wrappers.HandData 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.weaponmechanics.wrappers.HandData in project MechanicsMain by WeaponMechanics.
the class ScopeHandler method zoomOutWithoutTiming.
/**
* @return true if successfully zoomed out
*/
private boolean zoomOutWithoutTiming(ItemStack weaponStack, String weaponTitle, EntityWrapper entityWrapper, ZoomData zoomData, EquipmentSlot slot) {
if (!zoomData.isZooming())
return false;
LivingEntity entity = entityWrapper.getEntity();
// Zoom amount and stack 0 because zooming out
WeaponScopeEvent weaponScopeEvent = new WeaponScopeEvent(weaponTitle, weaponStack, entity, WeaponScopeEvent.ScopeType.OUT, 0, 0);
Bukkit.getPluginManager().callEvent(weaponScopeEvent);
if (weaponScopeEvent.isCancelled()) {
return false;
}
updateZoom(entityWrapper, zoomData, weaponScopeEvent.getZoomAmount());
zoomData.setZoomStacks(0);
Mechanics zoomOffMechanics = getConfigurations().getObject(weaponTitle + ".Scope.Zoom_Off.Mechanics", Mechanics.class);
if (zoomOffMechanics != null)
zoomOffMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack));
WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class);
if (weaponInfoDisplay != null)
weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot);
weaponHandler.getSkinHandler().tryUse(entityWrapper, weaponTitle, weaponStack, slot);
if (zoomData.hasZoomNightVision())
useNightVision(entityWrapper, zoomData);
HandData handData = slot == EquipmentSlot.HAND ? entityWrapper.getMainHandData() : entityWrapper.getOffHandData();
handData.setLastScopeTime(System.currentTimeMillis());
if (getConfigurations().getBool(weaponTitle + ".Info.Show_Cooldown.Shoot_Delay_After_Scope")) {
CompatibilityAPI.getEntityCompatibility().setCooldown((Player) entity, weaponStack.getType(), getConfigurations().getInt(weaponTitle + ".Scope.Shoot_Delay_After_Scope") / 50);
}
return true;
}
use of me.deecaad.weaponmechanics.wrappers.HandData in project MechanicsMain by WeaponMechanics.
the class ChangingSpread method applyChanges.
/**
* Applies all changes based on this changing spread.
* After changes are applied, also entity wrapper's {@link HandData#getSpreadChange()} is modified
* based on circumstances. This basically means that changes are always made for NEXT shot, not current.
*
* @param entityWrapper the entity wrapper used to check circumstances
* @param tempSpread the spread
* @param mainHand whether main hand was used
* @param updateSpreadChange whether to allow updating current spread change
* @return the modifier holder with updated horizontal and vertical values
*/
public double applyChanges(EntityWrapper entityWrapper, double tempSpread, boolean mainHand, boolean updateSpreadChange) {
HandData handData = mainHand ? entityWrapper.getMainHandData() : entityWrapper.getOffHandData();
// Reset if required
if (handData.shouldReset())
handData.setSpreadChange(startingAmount);
// Check bounds of spread change
boolean didReset = false;
if (bounds != null)
didReset = bounds.checkBounds(handData, startingAmount);
// Add the current spread before doing modifications to it
tempSpread += handData.getSpreadChange();
// If bounds didn't reset it
if (updateSpreadChange && !didReset) {
handData.setSpreadChange(increaseChangeWhen.applyChanges(entityWrapper, handData.getSpreadChange()));
}
return tempSpread;
}
use of me.deecaad.weaponmechanics.wrappers.HandData in project MechanicsMain by WeaponMechanics.
the class SkinHandler method tryUse.
public boolean tryUse(TriggerType triggerType, EntityWrapper entityWrapper, String weaponTitle, ItemStack weaponStack, EquipmentSlot slot) {
HandData hand = slot == EquipmentSlot.HAND ? entityWrapper.getMainHandData() : entityWrapper.getOffHandData();
Map<String, Skin> skins = getConfigurations().getObject(weaponTitle + ".Skin", Map.class);
if (skins == null)
return false;
if (hand.getZoomData().isZooming()) {
Skin zoomSkin = skins.get("Scope");
Skin stackySkin = skins.get("Scope_" + hand.getZoomData().getZoomStacks());
if (stackySkin != null) {
zoomSkin = stackySkin;
}
if (zoomSkin != null) {
zoomSkin.apply(weaponStack);
return true;
}
}
if (hand.isReloading()) {
Skin reloadSkin = skins.get("Reload");
if (reloadSkin != null) {
reloadSkin.apply(weaponStack);
return true;
}
}
// it doesn't do anything if its cancelled anyway :p
if (triggerType == TriggerType.START_SPRINT || triggerType == null && entityWrapper.isSprinting()) {
Skin sprintSkin = skins.get("Sprint");
if (sprintSkin != null) {
sprintSkin.apply(weaponStack);
return true;
}
}
Skin defaultSkin = skins.get("Default");
if (defaultSkin != null) {
defaultSkin.apply(weaponStack);
return true;
}
return false;
}
Aggregations