mirror of
https://github.com/songoda/EpicEnchants.git
synced 2025-01-03 15:08:19 +01:00
Initial commit
This commit is contained in:
commit
621b02fd15
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
out/
|
||||
.idea/
|
||||
*.iml
|
||||
META-INF/
|
||||
target/
|
27
core/pom.xml
Normal file
27
core/pom.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>epicenchants</artifactId>
|
||||
<groupId>com.songoda</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>epicfurnaces</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.13.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,38 @@
|
||||
package com.songoda.epicenchants;
|
||||
|
||||
import com.songoda.epicenchants.objects.ActionClass;
|
||||
import com.songoda.epicenchants.wrappers.PotionEffectWrapper;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ConfigParser {
|
||||
public static PotionEffect parsePotionEffect(String input) {
|
||||
if (input.contains(":")) {
|
||||
return new PotionEffect(PotionEffectType.getByName(input.split(":")[0]), Integer.MAX_VALUE, Integer.valueOf(input.split(":")[1]));
|
||||
}
|
||||
|
||||
return new PotionEffect(PotionEffectType.getByName(input), Integer.MAX_VALUE, 0);
|
||||
}
|
||||
|
||||
public static ActionClass parseActionClass(ConfigurationSection section) {
|
||||
return ActionClass.builder()
|
||||
.modifyDamageGiven(section.getDouble("modify-damage-given"))
|
||||
.modifyDamageTaken(section.getDouble("modify-damage-taken"))
|
||||
.potionEffects(section.getConfigurationSection("potion-effects")
|
||||
.getKeys(false).stream()
|
||||
.map(section::getConfigurationSection)
|
||||
.map(ConfigParser::parsePotionEffect)
|
||||
.collect(Collectors.toSet()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static PotionEffectWrapper parsePotionEffect(ConfigurationSection section) {
|
||||
return new PotionEffectWrapper(new PotionEffect(
|
||||
PotionEffectType.getByName(section.getName()),
|
||||
section.getInt("duration"),
|
||||
section.getInt("amplifier")), section.getDouble("chance"));
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.songoda.epicenchants;
|
||||
|
||||
import com.songoda.epicenchants.managers.EnchantManager;
|
||||
import com.songoda.epicenchants.managers.FileManager;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class EpicEnchants extends JavaPlugin {
|
||||
|
||||
@Getter private FileManager fileManager;
|
||||
@Getter private EnchantManager enchantManager;
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.fileManager = new FileManager(this);
|
||||
this.enchantManager = new EnchantManager();
|
||||
|
||||
saveDefaultConfig();
|
||||
|
||||
try {
|
||||
fileManager.loadEnchants();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.songoda.epicenchants.managers;
|
||||
|
||||
import com.songoda.epicenchants.objects.Enchant;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EnchantManager {
|
||||
private Map<String, Enchant> enchantMap;
|
||||
|
||||
public EnchantManager() {
|
||||
this.enchantMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public Optional<Enchant> getEnchant(String identifier) {
|
||||
return Optional.ofNullable(enchantMap.get(identifier));
|
||||
}
|
||||
|
||||
public void addEnchant(Enchant enchant) {
|
||||
enchantMap.put(enchant.getIdentifier(), enchant);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.songoda.epicenchants.managers;
|
||||
|
||||
import com.songoda.epicenchants.ConfigParser;
|
||||
import com.songoda.epicenchants.EpicEnchants;
|
||||
import com.songoda.epicenchants.objects.Enchant;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.io.File.separator;
|
||||
|
||||
public class FileManager {
|
||||
private final EpicEnchants instance;
|
||||
|
||||
public FileManager(EpicEnchants instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void loadEnchants() {
|
||||
File dir = new File(instance.getDataFolder() + separator + "enchants" + separator);
|
||||
|
||||
if (!dir.exists()) {
|
||||
instance.saveResource("StrengthEnchant.yml", false);
|
||||
}
|
||||
|
||||
Arrays.stream(dir.listFiles((dir1, filename) -> filename.endsWith(".yml"))).forEach(file -> {
|
||||
try {
|
||||
instance.getEnchantManager().addEnchant(loadEnchant(YamlConfiguration.loadConfiguration(file)));
|
||||
} catch (Exception e) {
|
||||
instance.getLogger().severe(ChatColor.RED + "Something went wrong loading the enchant from file " + file.getName());
|
||||
instance.getLogger().severe(ChatColor.RED + "Please check to make sure there are no errors in the file.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Enchant loadEnchant(FileConfiguration config) {
|
||||
return Enchant.builder()
|
||||
.identifier(config.getString("identifier"))
|
||||
.maxTier(config.getInt("max-tier"))
|
||||
.format(config.getString("applied-format"))
|
||||
.itemWhitelist(config.getStringList("item-whitelist").stream().map(Material::valueOf).collect(Collectors.toSet()))
|
||||
.potionEffects(config.getStringList("potion-effects").stream().map(ConfigParser::parsePotionEffect).collect(Collectors.toSet()))
|
||||
.action(ConfigParser.parseActionClass(config.getConfigurationSection("action")))
|
||||
.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.songoda.epicenchants.objects;
|
||||
|
||||
import com.songoda.epicenchants.wrappers.PotionEffectWrapper;
|
||||
import lombok.Builder;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Builder
|
||||
public class ActionClass {
|
||||
private Set<PotionEffectWrapper> potionEffects;
|
||||
private double modifyDamageTaken;
|
||||
private double modifyDamageGiven;
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.songoda.epicenchants.objects;
|
||||
|
||||
import com.songoda.epicenchants.wrappers.MobWrapper;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Builder
|
||||
public class Enchant {
|
||||
@Getter private String identifier;
|
||||
private Set<MobWrapper> mobs;
|
||||
private Set<PotionEffect> potionEffects;
|
||||
private Set<Material> itemWhitelist;
|
||||
private int maxTier;
|
||||
private String format;
|
||||
private ActionClass action;
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.songoda.epicenchants.wrappers;
|
||||
|
||||
import lombok.Builder;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@Builder
|
||||
public class MobWrapper {
|
||||
private EntityType entityType;
|
||||
private double spawnPercentage;
|
||||
private double health;
|
||||
private boolean hostile;
|
||||
private ItemStack helmet, chestPlate, leggings, boots;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.songoda.epicenchants.wrappers;
|
||||
|
||||
import io.netty.util.internal.ThreadLocalRandom;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
public class PotionEffectWrapper {
|
||||
private PotionEffect potionEffect;
|
||||
private double chance;
|
||||
|
||||
public PotionEffectWrapper(PotionEffect potionEffect, double chance) {
|
||||
this.potionEffect = potionEffect;
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
public boolean test() {
|
||||
return ThreadLocalRandom.current().nextDouble(101) < chance;
|
||||
}
|
||||
|
||||
public void perform(Player player) {
|
||||
player.addPotionEffect(potionEffect);
|
||||
}
|
||||
}
|
65
core/src/main/resources/StrengthEnchant.yml
Normal file
65
core/src/main/resources/StrengthEnchant.yml
Normal file
@ -0,0 +1,65 @@
|
||||
enchant-id: Strength
|
||||
|
||||
max-tier: 3
|
||||
|
||||
book-item:
|
||||
material: BOOK
|
||||
display-name: "&cStrength {tier}"
|
||||
lore:
|
||||
- "&7Drag on to enchant"
|
||||
- "&cDestroy Rate {destroy_rate}"
|
||||
- "&aSuccess Rate {success_rate}"
|
||||
|
||||
#Format as seen in the lore of the item
|
||||
applied-format: "&7Strength {tier}"
|
||||
|
||||
#What items this enchant can be applied too
|
||||
item-whitelist:
|
||||
- "DIAMOND_HELMET"
|
||||
- "GOLD_HELMET"
|
||||
- "STONE_HELMET"
|
||||
- "LEATHER_HELMET"
|
||||
|
||||
#Potion effects applied on equip
|
||||
potion-effects:
|
||||
- "STRENGTH:{tier}"
|
||||
|
||||
#Spawned when hit or when you strike an enemy in case of tools
|
||||
mobs:
|
||||
IRON_GOLEM:
|
||||
spawn-percentage: 20
|
||||
health: 80
|
||||
attack-damage: 2
|
||||
hostile: true
|
||||
display-name: "&cAngry guy"
|
||||
armor:
|
||||
helmet:
|
||||
material: DIAMOND_HELMET
|
||||
enchants:
|
||||
- "UNBREAKING:3"
|
||||
- "THORNS:2"
|
||||
chest-plate:
|
||||
material: DIAMOND_CHESTPLATE
|
||||
enchants:
|
||||
- "UNBREAKING:3"
|
||||
- "THORNS:2"
|
||||
leggings:
|
||||
material: DIAMOND_LEGGINGS
|
||||
enchants:
|
||||
- "UNBREAKING:3"
|
||||
- "THORNS:2"
|
||||
boots:
|
||||
material: DIAMOND_BOOTS
|
||||
enchants:
|
||||
- "UNBREAKING:3"
|
||||
- "THORNS:2"
|
||||
|
||||
#On hit or deal damage
|
||||
action:
|
||||
modify-damage-taken: 40
|
||||
modify-damage-given: -10
|
||||
potion-effects:
|
||||
STRENGTH:
|
||||
duration: 3
|
||||
chance: 20
|
||||
amplifier: 2
|
5
core/src/main/resources/plugin.yml
Normal file
5
core/src/main/resources/plugin.yml
Normal file
@ -0,0 +1,5 @@
|
||||
name: EpicEnchants
|
||||
version: ${project.version}
|
||||
main: com.songoda.epicenchants.EpicEnchants
|
||||
authors: [GB6]
|
||||
website: https://songoda.com/
|
36
pom.xml
Normal file
36
pom.xml
Normal file
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>epicenchants</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0</version>
|
||||
<modules>
|
||||
<module>core</module>
|
||||
</modules>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>private</id>
|
||||
<url>http://repo.songoda.com/repository/private/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
Loading…
Reference in New Issue
Block a user