Skip to content

Commit

Permalink
Created alchemy extension
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Nov 26, 2020
1 parent f862783 commit fbe1cd7
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Extensions/Alchemy/build.gradle
Original file line number Diff line number Diff line change
@@ -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 = 'Alchemy'

tasks.withType(Jar) {
destinationDirectory = file("$rootDir/bin/")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.willfp.ecoenchants.alchemy;

import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.potion.PotionEffect;

public class Alchemy extends EcoEnchant {
public Alchemy() {
super("alchemy", EnchantmentType.NORMAL, AlchemyMain.class);
}

@EventHandler
public void onPotionEffect(EntityPotionEffectEvent event) {
if(event.getNewEffect() == null) return;
if(!(event.getEntity() instanceof LivingEntity)) return;

LivingEntity entity = (LivingEntity) event.getEntity();

int level = EnchantChecks.getArmorPoints(entity, this);
if(level == 0) return;

if(!EnchantmentUtils.passedChance(this, level))
return;

PotionEffect effect = event.getNewEffect();

PotionEffect newEffect = new PotionEffect(
effect.getType(),
effect.getDuration(),
((effect.getAmplifier() + 1) * 2) - 1,
effect.isAmbient(),
effect.hasParticles(),
effect.hasIcon()
);

entity.removePotionEffect(effect.getType());
entity.addPotionEffect(newEffect);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.willfp.ecoenchants.alchemy;

import com.willfp.ecoenchants.extensions.Extension;

public class AlchemyMain extends Extension {
@Override
public void onEnable() {

}

@Override
public void onDisable() {

}
}
26 changes: 26 additions & 0 deletions Extensions/Alchemy/src/main/resources/enchants/normal/alchemy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Alchemy EcoEnchant
#

name: "Alchemy"
description: Chance to double the strength of potions
enabled: true

obtaining:
table: true
villager: true
loot: true
rarity: legendary

general-config:
targets:
- helmet
- chestplate
- leggings
- boots
grindstoneable: true
conflicts: []
maximum-level: 6

config:
chance-per-level: 4
3 changes: 3 additions & 0 deletions Extensions/Alchemy/src/main/resources/extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: Alchemy
main: com.willfp.ecoenchants.alchemy.AlchemyMain
version: 1.0.0
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.willfp.ecoenchants.config;

import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.util.Logger;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;

Expand Down Expand Up @@ -43,6 +44,10 @@ public void update() {
config.load(configFile);

InputStream newIn = EcoEnchantsPlugin.getInstance().getResource(name);
if(newIn == null) {
Logger.error(name + " is null?");
return;
}
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
YamlConfiguration newConfig = new YamlConfiguration();
newConfig.load(reader);
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ findProject(':Biomes').projectDir = file('Extensions/Biomes')
include('SprintArtifacts')
findProject(':SprintArtifacts').projectDir = file('Extensions/SprintArtifacts')

include('Alchemy')
findProject(':Alchemy').projectDir = file('Extensions/Alchemy')

0 comments on commit fbe1cd7

Please sign in to comment.