mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-27 02:49:22 +00:00
Added flight and hunger loss multiplier effects
This commit is contained in:
@@ -11,6 +11,7 @@ import com.willfp.ecoarmor.commands.CommandEareload;
|
||||
import com.willfp.ecoarmor.commands.TabcompleterEagive;
|
||||
import com.willfp.ecoarmor.config.EcoArmorConfigs;
|
||||
import com.willfp.ecoarmor.display.ArmorDisplay;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import com.willfp.ecoarmor.effects.Effects;
|
||||
import com.willfp.ecoarmor.sets.ArmorSets;
|
||||
import com.willfp.ecoarmor.sets.util.EffectiveDurabilityListener;
|
||||
@@ -47,7 +48,8 @@ public class EcoArmorPlugin extends AbstractEcoPlugin {
|
||||
public void enable() {
|
||||
Display.registerDisplayModule(new DisplayModule(ArmorDisplay::display, 1, this.getPluginName()));
|
||||
Display.registerRevertModule(ArmorDisplay::revertDisplay);
|
||||
Effects.values().forEach(effect -> this.getEventManager().registerListener(effect));
|
||||
Effects.values().stream().filter(Effect::isEnabled).forEach(effect -> this.getEventManager().registerListener(effect));
|
||||
ArmorSets.update();
|
||||
this.onReload();
|
||||
}
|
||||
|
||||
@@ -72,6 +74,8 @@ public class EcoArmorPlugin extends AbstractEcoPlugin {
|
||||
*/
|
||||
@Override
|
||||
public void onReload() {
|
||||
Effects.values().forEach(effect -> this.getEventManager().unregisterListener(effect));
|
||||
Effects.values().stream().filter(Effect::isEnabled).forEach(effect -> this.getEventManager().registerListener(effect));
|
||||
this.getLog().info(ArmorSets.values().size() + " Sets Loaded");
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,12 @@ public abstract class Effect<T> implements Listener {
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* If the effect is enabled.
|
||||
*/
|
||||
@Getter
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* Create a new effect.
|
||||
*
|
||||
@@ -27,6 +33,14 @@ public abstract class Effect<T> implements Listener {
|
||||
protected Effect(@NotNull final String name) {
|
||||
this.name = name;
|
||||
|
||||
update();
|
||||
Effects.addNewEffect(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update if the effect is enabled.
|
||||
*/
|
||||
public void update() {
|
||||
enabled = this.getPlugin().getConfigYml().getBool("effects." + name + ".enabled");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import com.willfp.ecoarmor.effects.effects.DamageTakenMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.EvadeChance;
|
||||
import com.willfp.ecoarmor.effects.effects.ExperienceMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.FallDamageMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.Flight;
|
||||
import com.willfp.ecoarmor.effects.effects.HungerLossMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.MeleeDamageMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.RegenerationMultiplier;
|
||||
import com.willfp.ecoarmor.effects.effects.SpeedMutiplier;
|
||||
@@ -42,6 +44,8 @@ public class Effects {
|
||||
public static final Effect<?> REGENERATION_MULTIPLIER = new RegenerationMultiplier();
|
||||
public static final Effect<?> WARP_CHANCE = new WarpChance();
|
||||
public static final Effect<?> ATTACK_SPEED_MULTIPLIER = new AttackSpeedMultiplier();
|
||||
public static final Effect<?> FLIGHT = new Flight();
|
||||
public static final Effect<?> HUNGER_LOSS_MULTIPLIER = new HungerLossMultiplier();
|
||||
|
||||
/**
|
||||
* Get effect matching name.
|
||||
|
||||
@@ -20,7 +20,7 @@ public class AttackSpeedMultiplier extends Effect<Double> {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
public void listener(@NotNull final ArmorEquipEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
|
||||
|
||||
@@ -20,7 +20,7 @@ public class BonusHearts extends Effect<Integer> {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
public void listener(@NotNull final ArmorEquipEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
|
||||
@@ -16,7 +16,7 @@ public class BowDamageMultiplier extends Effect<Double> {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||
public void listener(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class DamageMultiplier extends Effect<Double> {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||
public void listener(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class DamageTakenMultiplier extends Effect<Double> {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(@NotNull final EntityDamageEvent event) {
|
||||
public void listener(@NotNull final EntityDamageEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class DurabilityMultiplier extends Effect<Double> {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(@NotNull final PlayerItemDamageEvent event) {
|
||||
public void listener(@NotNull final PlayerItemDamageEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class EvadeChance extends Effect<Double> {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(@NotNull final EntityDamageEvent event) {
|
||||
public void listener(@NotNull final EntityDamageEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class FallDamageMultiplier extends Effect<Double> {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(@NotNull final EntityDamageEvent event) {
|
||||
public void listener(@NotNull final EntityDamageEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Flight extends Effect<Boolean> {
|
||||
public Flight() {
|
||||
super("flight");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
Boolean flight = ArmorUtils.getEffectStrength(player, this);
|
||||
if (flight == null) {
|
||||
if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) {
|
||||
player.setAllowFlight(false);
|
||||
}
|
||||
} else {
|
||||
if (flight) {
|
||||
player.setAllowFlight(true);
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.willfp.ecoarmor.effects.effects;
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HungerLossMultiplier extends Effect<Double> {
|
||||
public HungerLossMultiplier() {
|
||||
super("hunger-loss-multiplier");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void listener(@NotNull final FoodLevelChangeEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
Double multiplier = ArmorUtils.getEffectStrength(player, this);
|
||||
|
||||
if (multiplier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getFoodLevel() > player.getFoodLevel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (multiplier < 1) {
|
||||
if (NumberUtils.randFloat(0, 1) > multiplier) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
int difference = player.getFoodLevel() - event.getFoodLevel();
|
||||
difference = (int) Math.ceil(difference * multiplier);
|
||||
event.setFoodLevel(player.getFoodLevel() - difference);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public class MeleeDamageMultiplier extends Effect<Double> {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||
public void listener(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class RegenerationMultiplier extends Effect<Double> {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(@NotNull final EntityRegainHealthEvent event) {
|
||||
public void listener(@NotNull final EntityRegainHealthEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class SpeedMutiplier extends Effect<Double> {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
public void listener(@NotNull final ArmorEquipEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
|
||||
|
||||
@@ -16,7 +16,7 @@ public class TridentDamageMultiplier extends Effect<Double> {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||
public void listener(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class WarpChance extends Effect<Double> {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||
public void listener(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class EffectiveDurabilityListener extends PluginDependent implements List
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onDamage(@NotNull final PlayerItemDamageEvent event) {
|
||||
public void listener(@NotNull final PlayerItemDamageEvent event) {
|
||||
ItemStack itemStack = event.getItem();
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
|
||||
@@ -2,3 +2,55 @@
|
||||
# EcoArmor
|
||||
# by Auxilor
|
||||
#
|
||||
|
||||
|
||||
# Effects are passive abilities that happen when wearing a full set with the effect present.
|
||||
effects:
|
||||
attack-speed-multiplier:
|
||||
# Changes attack speed by some multiplier
|
||||
enabled: true
|
||||
bonus-hearts:
|
||||
# Extra hearts given to a player
|
||||
enabled: true
|
||||
bow-damage-multipier:
|
||||
# Changes bow damage by some multiplier
|
||||
enabled: true
|
||||
damage-multipier:
|
||||
# Changes damage from any form by some multiplier
|
||||
enabled: true
|
||||
damage-taken-multipier:
|
||||
# Changes incoming damage by some multiplier
|
||||
enabled: true
|
||||
durability-multiplier:
|
||||
# Changes durability for **all items in inventory** by some multiplier
|
||||
enabled: true
|
||||
evade-chance:
|
||||
# Chance of avoiding attack, as a percentage
|
||||
enabled: true
|
||||
experience-multiplier:
|
||||
# Changes experience gained by some multiplier
|
||||
enabled: true
|
||||
fall-damage-multiplier:
|
||||
# Changes fall damage by some multiplier
|
||||
enabled: true
|
||||
flight:
|
||||
# Allows flight
|
||||
enabled: true
|
||||
melee-damage-multiplier:
|
||||
# Changes melee damage by some multiplier
|
||||
enabled: true
|
||||
regeneration-multiplier:
|
||||
# Changes regeneration by some multiplier
|
||||
enabled: true
|
||||
speed-multiplier:
|
||||
# Changes movement speed by some multiplier
|
||||
enabled: true
|
||||
trident-damage-multiplier:
|
||||
# Changes trident damage by some multiplier
|
||||
enabled: true
|
||||
warp-chance:
|
||||
# Chance to warp behind your opponent after damaging them, as a percentage
|
||||
enabled: true
|
||||
hunger-loss-multiplier:
|
||||
# Modify hunger loss by some multiplier
|
||||
enabled: true
|
||||
Reference in New Issue
Block a user