use of me.deecaad.weaponmechanics.mechanics.Mechanics 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.mechanics.Mechanics in project MechanicsMain by WeaponMechanics.
the class AmmoTypes method hasAmmo.
public boolean hasAmmo(String weaponTitle, ItemStack weaponStack, PlayerWrapper playerWrapper) {
int index = getCurrentAmmoIndex(weaponStack);
if (ammoTypes.get(index).hasAmmo(playerWrapper)) {
return true;
}
if (ammoTypes.size() == 1)
return false;
int ammoLeft = CustomTag.AMMO_LEFT.getInteger(weaponStack);
// player is out of ammo
if (ammoLeft > 0)
return false;
// Check from top to bottom for other ammo types
for (int i = 0; i < ammoTypes.size(); ++i) {
// Don't try checking for that ammo type anymore
if (i == index)
continue;
if (!ammoTypes.get(i).hasAmmo(playerWrapper))
continue;
// Update the index automatically to use this new one
setCurrentAmmoIndex(weaponStack, i);
Mechanics ammoTypeSwitchMechanics = getConfigurations().getObject(weaponTitle + ".Reload.Ammo.Ammo_Type_Switch.Mechanics", Mechanics.class);
if (ammoTypeSwitchMechanics != null)
ammoTypeSwitchMechanics.use(new CastData(playerWrapper, weaponTitle, weaponStack));
return true;
}
return false;
}
use of me.deecaad.weaponmechanics.mechanics.Mechanics 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.mechanics.Mechanics in project MechanicsMain by WeaponMechanics.
the class ScopeHandler method zoomInWithoutTiming.
/**
* @return true if successfully zoomed in or stacked
*/
private boolean zoomInWithoutTiming(ItemStack weaponStack, String weaponTitle, EntityWrapper entityWrapper, ZoomData zoomData, EquipmentSlot slot) {
Configuration config = getConfigurations();
LivingEntity entity = entityWrapper.getEntity();
if (zoomData.isZooming()) {
// zoom stack
int increaseZoomPerStack = config.getInt(weaponTitle + ".Scope.Zoom_Stacking.Increase_Zoom_Per_Stack");
if (increaseZoomPerStack != 0) {
int zoomStack = zoomData.getZoomStacks() + 1;
int zoomAmount = config.getInt(weaponTitle + ".Scope.Zoom_Amount");
WeaponScopeEvent weaponScopeEvent = new WeaponScopeEvent(weaponTitle, weaponStack, entity, WeaponScopeEvent.ScopeType.STACK, zoomAmount + (zoomStack * increaseZoomPerStack), zoomStack);
Bukkit.getPluginManager().callEvent(weaponScopeEvent);
if (weaponScopeEvent.isCancelled()) {
return false;
}
updateZoom(entityWrapper, zoomData, weaponScopeEvent.getZoomAmount());
zoomData.setZoomStacks(zoomStack);
weaponHandler.getSkinHandler().tryUse(entityWrapper, weaponTitle, weaponStack, slot);
Mechanics zoomStackingMechanics = config.getObject(weaponTitle + ".Scope.Zoom_Stacking.Mechanics", Mechanics.class);
if (zoomStackingMechanics != null)
zoomStackingMechanics.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);
return true;
} else {
debug.log(LogLevel.WARN, "For some reason zoom in was called on entity when it shouldn't have.", "Entity was already zooming so it should have stacked zoom, but not zoom stacking wasn't used at all?", "Ignoring this call, but this shouldn't even happen...", "Are you sure you have defined both Maximum_Stacks and Increase_Zoom_Per_Stack for weapon " + weaponTitle + "?");
return false;
}
}
int zoomAmount = config.getInt(weaponTitle + ".Scope.Zoom_Amount");
if (zoomAmount == 0)
return false;
// zoom stack = 0, because its not used OR this is first zoom in
WeaponScopeEvent weaponScopeEvent = new WeaponScopeEvent(weaponTitle, weaponStack, entity, WeaponScopeEvent.ScopeType.IN, zoomAmount, 0);
Bukkit.getPluginManager().callEvent(weaponScopeEvent);
if (weaponScopeEvent.isCancelled()) {
return false;
}
updateZoom(entityWrapper, zoomData, weaponScopeEvent.getZoomAmount());
Mechanics zoomMechanics = config.getObject(weaponTitle + ".Scope.Mechanics", Mechanics.class);
if (zoomMechanics != null)
zoomMechanics.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 (config.getBool(weaponTitle + ".Scope.Night_Vision"))
useNightVision(entityWrapper, zoomData);
return true;
}
use of me.deecaad.weaponmechanics.mechanics.Mechanics in project MechanicsMain by WeaponMechanics.
the class DualWield method serialize.
@Override
@Nonnull
public DualWield serialize(SerializeData data) throws SerializerException {
List<String[]> weaponsList = data.ofList("Weapons").addArgument(String.class, true, true).assertExists().assertList().get();
Set<String> weapons = new HashSet<>();
// Saves weapons in lower case
weaponsList.forEach(weaponTitle -> weapons.add(weaponTitle[0].toLowerCase()));
boolean whitelist = data.of("Whitelist").getBool(false);
Mechanics mechanics = data.of("Mechanics_On_Deny").serialize(Mechanics.class);
return new DualWield(whitelist, weapons, mechanics);
}
Aggregations