Created Effects extension

This commit is contained in:
Auxilor 2020-11-22 11:58:30 +00:00
parent bbc10a67ef
commit e53d8d946c
16 changed files with 285 additions and 7 deletions

View File

@ -0,0 +1,14 @@
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT'
compileOnly project(':plugin')
}
jar{
archiveFileName = project.name + " Extension" + ".jar"
}
description = 'Effects'
tasks.withType(Jar) {
destinationDirectory = file("$rootDir/bin/")
}

View File

@ -0,0 +1,39 @@
package com.willfp.ecoenchants.effects;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.events.armorequip.ArmorEquipEvent;
import com.willfp.ecoenchants.util.optional.Prerequisite;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public abstract class EffectsEnchantment extends EcoEnchant {
protected EffectsEnchantment(String key, EnchantmentType type, Prerequisite... prerequisites) {
super(key, type, EffectsMain.class, prerequisites);
}
public abstract PotionEffectType getPotionEffect();
@EventHandler
public void onEquip(ArmorEquipEvent event) {
final Player player = event.getPlayer();
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
if (EnchantChecks.getArmorPoints(player, this) > 0) {
if (player.hasPotionEffect(this.getPotionEffect())) {
if (player.getPotionEffect(this.getPotionEffect()).getDuration() >= 1639) {
player.removePotionEffect(this.getPotionEffect());
}
}
}
int level = EnchantChecks.getArmorPoints(player, this);
player.addPotionEffect(new PotionEffect(this.getPotionEffect(), 0x6fffffff, level-1, false, false, true));
}, 1);
}
}

View File

@ -0,0 +1,33 @@
package com.willfp.ecoenchants.effects;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.effects.enchants.JumpBoost;
import com.willfp.ecoenchants.effects.enchants.NightVision;
import com.willfp.ecoenchants.effects.enchants.Regeneration;
import com.willfp.ecoenchants.effects.enchants.Speed;
import com.willfp.ecoenchants.effects.enchants.WaterBreathing;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.extensions.Extension;
import org.bukkit.Bukkit;
public class EffectsMain extends Extension {
public static final EcoEnchant JUMP_BOOST = new JumpBoost();
public static final EcoEnchant NIGHT_VISION = new NightVision();
public static final EcoEnchant REGENERATION = new Regeneration();
public static final EcoEnchant SPEED = new Speed();
public static final EcoEnchant WATER_BREATHING = new WaterBreathing();
@Override
public void onEnable() {
Bukkit.getPluginManager().registerEvents(JUMP_BOOST, EcoEnchantsPlugin.getInstance());
Bukkit.getPluginManager().registerEvents(NIGHT_VISION, EcoEnchantsPlugin.getInstance());
Bukkit.getPluginManager().registerEvents(REGENERATION, EcoEnchantsPlugin.getInstance());
Bukkit.getPluginManager().registerEvents(SPEED, EcoEnchantsPlugin.getInstance());
Bukkit.getPluginManager().registerEvents(WATER_BREATHING, EcoEnchantsPlugin.getInstance());
}
@Override
public void onDisable() {
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.effects.enchants;
import com.willfp.ecoenchants.effects.EffectsEnchantment;
import org.bukkit.potion.PotionEffectType;
public class JumpBoost extends EffectsEnchantment {
public JumpBoost() {
super("jump_boost", EnchantmentType.NORMAL);
}
@Override
public PotionEffectType getPotionEffect() {
return PotionEffectType.JUMP;
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.effects.enchants;
import com.willfp.ecoenchants.effects.EffectsEnchantment;
import org.bukkit.potion.PotionEffectType;
public class NightVision extends EffectsEnchantment {
public NightVision() {
super("night_vision", EnchantmentType.NORMAL);
}
@Override
public PotionEffectType getPotionEffect() {
return PotionEffectType.NIGHT_VISION;
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.effects.enchants;
import com.willfp.ecoenchants.effects.EffectsEnchantment;
import org.bukkit.potion.PotionEffectType;
public class Regeneration extends EffectsEnchantment {
public Regeneration() {
super("regeneration", EnchantmentType.NORMAL);
}
@Override
public PotionEffectType getPotionEffect() {
return PotionEffectType.REGENERATION;
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.effects.enchants;
import com.willfp.ecoenchants.effects.EffectsEnchantment;
import org.bukkit.potion.PotionEffectType;
public class Speed extends EffectsEnchantment {
public Speed() {
super("speed", EnchantmentType.NORMAL);
}
@Override
public PotionEffectType getPotionEffect() {
return PotionEffectType.SPEED;
}
}

View File

@ -0,0 +1,15 @@
package com.willfp.ecoenchants.effects.enchants;
import com.willfp.ecoenchants.effects.EffectsEnchantment;
import org.bukkit.potion.PotionEffectType;
public class WaterBreathing extends EffectsEnchantment {
public WaterBreathing() {
super("water_breathing", EnchantmentType.NORMAL);
}
@Override
public PotionEffectType getPotionEffect() {
return PotionEffectType.WATER_BREATHING;
}
}

View File

@ -0,0 +1,24 @@
#
# Jump Boost EcoEnchant
#
name: "Jump Boost"
description: Gives you permanent jump boost.
enabled: true
obtaining:
table: true
villager: true
loot: true
rarity: legendary
general-config:
targets:
- boots
grindstoneable: true
conflicts:
- spring
maximum-level: 3
config:
# No config is available for this enchantment

View File

@ -0,0 +1,23 @@
#
# Night Vision EcoEnchant
#
name: "Night Vision"
description: Gives you permanent night vision.
enabled: true
obtaining:
table: true
villager: true
loot: true
rarity: legendary
general-config:
targets:
- helmet
grindstoneable: true
conflicts: []
maximum-level: 1
config:
# No config is available for this enchantment

View File

@ -0,0 +1,23 @@
#
# Regeneration EcoEnchant
#
name: "Regeneration"
description: Gives you permanent regeneration.
enabled: true
obtaining:
table: true
villager: true
loot: true
rarity: legendary
general-config:
targets:
- helmet
grindstoneable: true
conflicts: []
maximum-level: 2
config:
# No config is available for this enchantment

View File

@ -0,0 +1,24 @@
#
# Speed EcoEnchant
#
name: "Speed"
description: Gives you permanent speed.
enabled: true
obtaining:
table: true
villager: true
loot: true
rarity: legendary
general-config:
targets:
- boots
grindstoneable: true
conflicts:
- streamlining
maximum-level: 3
config:
# No config is available for this enchantment

View File

@ -0,0 +1,23 @@
#
# Water Breathing EcoEnchant
#
name: "Water Breathing"
description: Gives you permanent water breathing.
enabled: true
obtaining:
table: true
villager: true
loot: true
rarity: legendary
general-config:
targets:
- helmet
grindstoneable: true
conflicts: []
maximum-level: 1
config:
# No config is available for this enchantment

View File

@ -0,0 +1,2 @@
name: Effects
main: com.willfp.ecoenchants.effects.EffectsMain

View File

@ -168,13 +168,8 @@ public class ArmorListener implements Listener {
@EventHandler
public void playerRespawnEvent(PlayerRespawnEvent e) {
Player p = e.getPlayer();
for (ItemStack i : p.getInventory().getArmorContents()) {
if (!isAirOrNull(i)) {
Bukkit.getPluginManager().callEvent(new ArmorEquipEvent(p, EquipMethod.DEATH, ArmorType.matchType(i), i, null));
// No way to cancel a death event.
}
}
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(e.getPlayer(), null, null, null, null);
Bukkit.getPluginManager().callEvent(armorEquipEvent);
}
@EventHandler

View File

@ -20,3 +20,6 @@ project(":Firewand").projectDir = file('Extensions/Firewand')
include('Precision')
project(":Precision").projectDir = file('Extensions/Precision')
include('Effects')
findProject(':Effects').projectDir = file('Extensions/Effects')