Continued adding base features
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
package com.willfp.ecoweapons;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.impl.PluginCommand;
|
||||
import com.willfp.eco.core.display.DisplayModule;
|
||||
import com.willfp.ecoweapons.commands.CommandEcoweapons;
|
||||
import com.willfp.ecoweapons.config.EcoWeaponsJson;
|
||||
import com.willfp.ecoweapons.display.WeaponsDisplay;
|
||||
import com.willfp.ecoweapons.effects.util.EffectListener;
|
||||
import com.willfp.ecoweapons.util.DiscoverRecipeListener;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -40,4 +45,16 @@ public class EcoWeaponsPlugin extends EcoPlugin {
|
||||
new DiscoverRecipeListener(this)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PluginCommand> loadPluginCommands() {
|
||||
return Arrays.asList(
|
||||
new CommandEcoweapons(this)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable DisplayModule createDisplayModule() {
|
||||
return new WeaponsDisplay(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Effect {
|
||||
@@ -24,7 +26,7 @@ public abstract class Effect {
|
||||
/**
|
||||
* Create a new effect.
|
||||
*
|
||||
* @param name The effect name.
|
||||
* @param name The effect name.
|
||||
*/
|
||||
protected Effect(@NotNull final String name) {
|
||||
this.name = name;
|
||||
@@ -46,4 +48,19 @@ public abstract class Effect {
|
||||
@NotNull final Object args) {
|
||||
// Override when needed.
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle {@link TriggerType#PROJECTILE_HIT}.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param projectile The projectile.
|
||||
* @param event The event.
|
||||
* @param args The effect args.
|
||||
*/
|
||||
public void handleProjectileHit(@NotNull final Player player,
|
||||
@NotNull final Projectile projectile,
|
||||
@NotNull final ProjectileHitEvent event,
|
||||
@NotNull final Object args) {
|
||||
// Override when needed.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.willfp.ecoweapons.effects;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.willfp.ecoweapons.effects.effects.StrikeLightning;
|
||||
import com.willfp.ecoweapons.effects.effects.EffectStrikeLightning;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -18,7 +18,7 @@ public class Effects {
|
||||
*/
|
||||
private static final BiMap<String, Effect> BY_NAME = HashBiMap.create();
|
||||
|
||||
public static final Effect STRIKE_LIGHTNING = new StrikeLightning();
|
||||
public static final Effect STRIKE_LIGHTNING = new EffectStrikeLightning();
|
||||
|
||||
/**
|
||||
* Get effect matching name.
|
||||
|
||||
@@ -2,17 +2,20 @@ package com.willfp.ecoweapons.effects.effects;
|
||||
|
||||
import com.willfp.eco.util.LightningUtils;
|
||||
import com.willfp.ecoweapons.effects.Effect;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class StrikeLightning extends Effect {
|
||||
public StrikeLightning() {
|
||||
super("speed-multiplier");
|
||||
public class EffectStrikeLightning extends Effect {
|
||||
public EffectStrikeLightning() {
|
||||
super("strike-lightning");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,4 +29,18 @@ public class StrikeLightning extends Effect {
|
||||
LightningUtils.strike(victim, argMap.get("damage"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleProjectileHit(@NotNull final Player player,
|
||||
@NotNull final Projectile projectile,
|
||||
@NotNull final ProjectileHitEvent event,
|
||||
@NotNull final Object args) {
|
||||
Map<String, Integer> argMap = (Map<String, Integer>) args;
|
||||
|
||||
for (int i = 0; i < argMap.get("amount"); i++) {
|
||||
World world = projectile.getLocation().getWorld();
|
||||
assert world != null;
|
||||
world.strikeLightning(projectile.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,20 @@
|
||||
package com.willfp.ecoweapons.effects.util;
|
||||
|
||||
import com.willfp.eco.util.ArrowUtils;
|
||||
import com.willfp.ecoweapons.effects.Effect;
|
||||
import com.willfp.ecoweapons.effects.TriggerType;
|
||||
import com.willfp.ecoweapons.weapons.Weapon;
|
||||
import com.willfp.ecoweapons.weapons.util.WeaponUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EffectListener implements Listener {
|
||||
@@ -34,7 +40,7 @@ public class EffectListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (WeaponUtils.areConditionsMet(player)) {
|
||||
if (!WeaponUtils.areConditionsMet(player, weapon)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -42,4 +48,59 @@ public class EffectListener implements Listener {
|
||||
effect.handleMeleeAttack(player, victim, event, weapon.getEffectStrength(effect, TriggerType.MELEE_ATTACK));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle {@link TriggerType#MELEE_ATTACK}.
|
||||
*
|
||||
* @param event The event.
|
||||
*/
|
||||
@EventHandler(
|
||||
ignoreCancelled = true
|
||||
)
|
||||
public void projectileHitListener(@NotNull final ProjectileHitEvent event) {
|
||||
Bukkit.getLogger().info("Here?");
|
||||
|
||||
if (!(event.getEntity() instanceof Trident || event.getEntity() instanceof Arrow)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item;
|
||||
|
||||
if (event.getEntity() instanceof Trident trident) {
|
||||
item = trident.getItem();
|
||||
} else {
|
||||
item = ArrowUtils.getBow((Arrow) event.getEntity());
|
||||
}
|
||||
|
||||
Bukkit.getLogger().info("2");
|
||||
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getLogger().info("3");
|
||||
|
||||
if (!(event.getEntity().getShooter() instanceof Player player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getLogger().info("hoo");
|
||||
|
||||
Weapon weapon = WeaponUtils.getWeaponFromItem(item);
|
||||
if (weapon == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getLogger().info("nayan");
|
||||
|
||||
if (!WeaponUtils.areConditionsMet(player, weapon)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getLogger().info("here!");
|
||||
|
||||
for (Effect effect : weapon.getEffects(TriggerType.PROJECTILE_HIT)) {
|
||||
effect.handleProjectileHit(player, event.getEntity(), event, weapon.getEffectStrength(effect, TriggerType.PROJECTILE_HIT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,6 @@ public class Weapon {
|
||||
* @param triggerType The trigger type.
|
||||
* @return The strength.
|
||||
*/
|
||||
@Nullable
|
||||
public Object getEffectStrength(@NotNull final Effect effect,
|
||||
@NotNull final TriggerType triggerType) {
|
||||
return effects.get(triggerType).get(effect);
|
||||
|
||||
@@ -61,14 +61,11 @@ public class WeaponUtils {
|
||||
* Get if all conditions are met for a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return If conditions are men.
|
||||
* @param weapon The weapon.
|
||||
* @return If conditions are met.
|
||||
*/
|
||||
public boolean areConditionsMet(@NotNull final Player player) {
|
||||
Weapon weapon = getWeaponFromItem(player.getInventory().getItemInMainHand());
|
||||
if (weapon == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean areConditionsMet(@NotNull final Player player,
|
||||
@NotNull final Weapon weapon) {
|
||||
for (Map.Entry<Condition<?>, Object> entry : weapon.getConditions().entrySet()) {
|
||||
if (!entry.getKey().isMet(player, entry.getValue())) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user