Compare commits

...

16 Commits

Author SHA1 Message Date
ceze88 474c44b45c Release v2.0.0 2024-01-13 16:03:40 +01:00
ceze88 fb406122d8 Migrate to dynamic dependency loading 2024-01-11 16:09:04 +01:00
Christian Koop 13336f72d5
Release v2.0.0-b3-SNAPSHOT 2023-10-23 18:04:01 +02:00
ceze88 5cc234147a Release v2.0.0-SNAPSHOT-b2 2023-07-28 11:53:59 +02:00
ceze88 3658946da0 Fix NPE for some enchants 2023-07-28 11:53:48 +02:00
ceze88 e6f0a8599e Release v2.0.0-SNAPSHOT 2023-07-25 20:19:38 +02:00
ANGEL 8ccfc5c82d Move classes from package com.songoda to com.craftaro; Changed links to Craftaro's wiki 2023-07-25 12:39:40 +03:00
Christian Koop 8cd6e9c6b3
Use `SpigotMC` as maven repository ID 2023-06-29 11:29:23 +02:00
Christian Koop c81a39fb26
Release v1.3.0-SNAPSHOT 2023-06-25 13:59:26 +02:00
Christian Koop 1c9b00b9c0
Merge branch 'master' into development 2023-06-25 13:55:48 +02:00
Christian Koop 5347383f6b
Heavy code style changes and slight refactoring 2023-06-25 13:50:37 +02:00
Christian Koop a6acf326f8
Updates .gitignore 2023-06-25 13:50:37 +02:00
Christian Koop 341fca99ab
Updates PlaceHolderAPI dependency from v2.9.2 to v2.11.3 2023-06-25 12:51:04 +02:00
Christian Koop b3b0ddd105
Modernize and clean up pom.xml 2023-06-25 12:51:04 +02:00
Christian Koop 9e4e198848
Drop support for Songoda UltimateBottles
I think it never got published
2023-06-25 12:51:04 +02:00
Christian Koop 489bff3620
Migrate from SongodaCore to CraftaroCore v3.0.0-SNAPSHOT 2023-06-25 12:51:04 +02:00
147 changed files with 1690 additions and 1715 deletions

10
.gitignore vendored
View File

@ -1,6 +1,10 @@
# JetBrains IDEs
## JetBrains IDEs
/.idea/
/*.iml
*.iml
# Maven
## Maven
/target/
/dependency-reduced-pom.xml
## Misc.
.DS_Store

126
pom.xml
View File

@ -4,71 +4,86 @@
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>
<groupId>com.craftaro</groupId>
<artifactId>EpicEnchants</artifactId>
<version>1.2.7</version>
<version>2.0.0</version>
<name>EpicEnchants</name>
<description>Unlock the potential of your weapons, tools and armor by making your own custom enchants.</description>
<url>https://songoda.com/marketplace/product/67</url>
<url>https://craftaro.com/marketplace/product/67</url>
<properties>
<java.version>1.8</java.version>
<java.release>8</java.release>
<maven.compiler.release>8</maven.compiler.release>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<issueManagement>
<url>https://discord.gg/craftaro</url>
<system>Discord server</system>
</issueManagement>
<scm>
<url>https://github.com/craftaro/EpicEnchants</url>
<connection>scm:git:git://github.com/craftaro/EpicEnchants.git</connection>
</scm>
<build>
<defaultGoal>clean install</defaultGoal>
<finalName>EpicEnchants-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<release>${java.release}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.4.1</version>
<executions>
<execution>
<id>shaded</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<finalName>${project.name}-${project.version}</finalName>
<artifactSet>
<includes>
<include>com.songoda:SongodaCore</include>
</includes>
</artifactSet>
<shadedArtifactAttached>false</shadedArtifactAttached>
<useDependencyReducedPomInJar>true</useDependencyReducedPomInJar>
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
<pattern>com.craftaro.core</pattern>
<shadedPattern>com.craftaro.epicenchants.core</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/**</exclude>
<exclude>LICENSE</exclude>
<exclude>LICENSE.**</exclude>
</excludes>
</filter>
<filter>
<artifact>com.craftaro:CraftaroCore</artifact>
<excludeDefaults>false</excludeDefaults>
<includes>
<include>**/nms/v*/**</include>
</includes>
<excludes>
<exclude>**/third_party/org/apache/**</exclude>
<exclude>**/third_party/net/kyori/**</exclude>
<exclude>**/third_party/com/zaxxer/**</exclude>
<exclude>**/third_party/org/jooq/**</exclude>
<exclude>**/third_party/org/mariadb/**</exclude>
<exclude>**/third_party/com/h2database/**</exclude>
<exclude>**/third_party/org/h2/**</exclude>
<exclude>**/third_party/com/cryptomorin/**</exclude>
<exclude>**/third_party/org/reactivestreams/**</exclude>
</excludes>
</filter>
</filters>
@ -86,51 +101,42 @@
</resources>
</build>
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<url>https://repository.apache.org/snapshots/</url>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>songoda-public</id>
<url>https://repo.songoda.com/repository/public/</url>
<id>craftaro-minecraft-plugins</id>
<url>https://repo.craftaro.com/repository/minecraft-plugins/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io/</url>
<id>SpigotMC</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore</artifactId>
<version>2.6.19</version>
<groupId>com.craftaro</groupId>
<artifactId>CraftaroCore</artifactId>
<version>3.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>UltimateBottles</artifactId>
<version>1_0</version>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.9.2</version>
<version>2.11.3</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -0,0 +1,15 @@
package com.craftaro.epicenchants;
import com.craftaro.core.utils.NumberUtils;
import org.bukkit.command.CommandSender;
public class CommandCommons {
public static boolean isInt(String number, CommandSender sender) {
if (NumberUtils.isInt(number)) {
return true;
}
EpicEnchants.getPlugin(EpicEnchants.class).getLocale().newMessage("Not a number.").sendPrefixedMessage(sender);
return false;
}
}

View File

@ -1,80 +1,76 @@
package com.songoda.epicenchants;
package com.craftaro.epicenchants;
import com.songoda.core.SongodaCore;
import com.songoda.core.SongodaPlugin;
import com.songoda.core.commands.CommandManager;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.configuration.Config;
import com.songoda.core.gui.GuiManager;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.epicenchants.commands.CommandAlchemist;
import com.songoda.epicenchants.commands.CommandApply;
import com.songoda.epicenchants.commands.CommandEnchanter;
import com.songoda.epicenchants.commands.CommandGiveBook;
import com.songoda.epicenchants.commands.CommandGiveItemDust;
import com.songoda.epicenchants.commands.CommandGiveRandomBook;
import com.songoda.epicenchants.commands.CommandGiveScroll;
import com.songoda.epicenchants.commands.CommandList;
import com.songoda.epicenchants.commands.CommandReload;
import com.songoda.epicenchants.commands.CommandSettings;
import com.songoda.epicenchants.commands.CommandTinkerer;
import com.songoda.epicenchants.listeners.ArmorListener;
import com.songoda.epicenchants.listeners.EntityListener;
import com.songoda.epicenchants.listeners.HeldItemListener;
import com.songoda.epicenchants.listeners.PlayerListener;
import com.songoda.epicenchants.listeners.item.BlackScrollListener;
import com.songoda.epicenchants.listeners.item.BookListener;
import com.songoda.epicenchants.listeners.item.DustListener;
import com.songoda.epicenchants.listeners.item.WhiteScrollListener;
import com.songoda.epicenchants.managers.EnchantManager;
import com.songoda.epicenchants.managers.FileManager;
import com.songoda.epicenchants.managers.GroupManager;
import com.songoda.epicenchants.managers.HookManager;
import com.songoda.epicenchants.managers.InfoManager;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.utils.EnchantUtils;
import com.songoda.epicenchants.utils.SpecialItems;
import com.songoda.epicenchants.utils.objects.FastInv;
import com.songoda.epicenchants.utils.settings.Settings;
import com.songoda.epicenchants.utils.single.ItemGroup;
import com.craftaro.core.SongodaCore;
import com.craftaro.core.SongodaPlugin;
import com.craftaro.core.commands.CommandManager;
import com.craftaro.core.configuration.Config;
import com.craftaro.core.dependency.Dependency;
import com.craftaro.core.gui.GuiManager;
import com.craftaro.core.hooks.EconomyManager;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.epicenchants.listeners.ArmorListener;
import com.craftaro.epicenchants.listeners.EntityListener;
import com.craftaro.epicenchants.listeners.HeldItemListener;
import com.craftaro.epicenchants.listeners.PlayerListener;
import com.craftaro.epicenchants.listeners.item.BlackScrollListener;
import com.craftaro.epicenchants.listeners.item.BookListener;
import com.craftaro.epicenchants.listeners.item.DustListener;
import com.craftaro.epicenchants.listeners.item.WhiteScrollListener;
import com.craftaro.epicenchants.managers.EnchantManager;
import com.craftaro.epicenchants.managers.FileManager;
import com.craftaro.epicenchants.managers.GroupManager;
import com.craftaro.epicenchants.managers.InfoManager;
import com.craftaro.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.commands.CommandAlchemist;
import com.craftaro.epicenchants.commands.CommandApply;
import com.craftaro.epicenchants.commands.CommandEnchanter;
import com.craftaro.epicenchants.commands.CommandGiveBook;
import com.craftaro.epicenchants.commands.CommandGiveItemDust;
import com.craftaro.epicenchants.commands.CommandGiveRandomBook;
import com.craftaro.epicenchants.commands.CommandGiveScroll;
import com.craftaro.epicenchants.commands.CommandList;
import com.craftaro.epicenchants.commands.CommandReload;
import com.craftaro.epicenchants.commands.CommandSettings;
import com.craftaro.epicenchants.commands.CommandTinkerer;
import com.craftaro.epicenchants.utils.EnchantUtils;
import com.craftaro.epicenchants.utils.SpecialItems;
import com.craftaro.epicenchants.utils.objects.FastInv;
import com.craftaro.epicenchants.utils.settings.Settings;
import com.craftaro.epicenchants.utils.single.ItemGroup;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class EpicEnchants extends SongodaPlugin {
private static EpicEnchants INSTANCE;
private final GuiManager guiManager = new GuiManager(this);
private EnchantManager enchantManager;
private InfoManager infoManager;
private GroupManager groupManager;
private FileManager fileManager;
private HookManager hookManager;
private CommandManager commandManager;
private SpecialItems specialItems;
private EnchantUtils enchantUtils;
private ItemGroup itemGroup;
public static EpicEnchants getInstance() {
return INSTANCE;
@Override
protected Set<Dependency> getDependencies() {
return new HashSet<>();
}
@Override
public void onPluginLoad() {
INSTANCE = this;
}
@Override
public void onPluginEnable() {
// Run Songoda Updater
SongodaCore.registerPlugin(this, 67, CompatibleMaterial.DIAMOND_SWORD);
SongodaCore.registerPlugin(this, 67, XMaterial.DIAMOND_SWORD);
// setup commands
this.commandManager = new com.songoda.core.commands.CommandManager(this);
this.commandManager = new com.craftaro.core.commands.CommandManager(this);
this.commandManager.addMainCommand("ee")
.addSubCommand(new CommandReload(this))
.addSubCommand(new CommandAlchemist(this))
@ -104,16 +100,14 @@ public class EpicEnchants extends SongodaPlugin {
this.infoManager = new InfoManager(this);
this.specialItems = new SpecialItems(this);
this.commandManager = new CommandManager(this);
this.hookManager = new HookManager();
this.itemGroup = new ItemGroup();
groupManager.loadGroups();
enchantManager.loadEnchants();
infoManager.loadMenus();
hookManager.setup();
this.groupManager.loadGroups();
this.enchantManager.loadEnchants();
this.infoManager.loadMenus();
// Listeners
guiManager.init();
this.guiManager.init();
PluginManager pluginManager = Bukkit.getPluginManager();
pluginManager.registerEvents(new BookListener(this), this);
pluginManager.registerEvents(new ArmorListener(), this);
@ -124,15 +118,15 @@ public class EpicEnchants extends SongodaPlugin {
pluginManager.registerEvents(new BlackScrollListener(this), this);
pluginManager.registerEvents(new DustListener(this), this);
if (!enchantManager.getValues().isEmpty()) {
getLogger().info("Successfully loaded enchants: " + enchantManager.getValues().stream().map(Enchant::getIdentifier).collect(Collectors.joining(", ")));
if (!this.enchantManager.getValues().isEmpty()) {
getLogger().info("Successfully loaded enchants: " + this.enchantManager.getValues().stream().map(Enchant::getIdentifier).collect(Collectors.joining(", ")));
}
}
private void preload() {
FastInv.init(this);
this.fileManager = new FileManager(this);
fileManager.loadFiles();
this.fileManager.loadFiles();
}
@Override
@ -145,17 +139,17 @@ public class EpicEnchants extends SongodaPlugin {
@Override
public void onConfigReload() {
fileManager.clear();
fileManager.loadFiles();
this.fileManager.clear();
this.fileManager.loadFiles();
groupManager.clear();
groupManager.loadGroups();
this.groupManager.clear();
this.groupManager.loadGroups();
enchantManager.clear();
enchantManager.loadEnchants();
this.enchantManager.clear();
this.enchantManager.loadEnchants();
infoManager.clear();
infoManager.loadMenus();
this.infoManager.clear();
this.infoManager.loadMenus();
this.setLocale(getConfig().getString("System.Language Mode"), true);
this.locale.reloadMessages();
@ -182,10 +176,6 @@ public class EpicEnchants extends SongodaPlugin {
return this.fileManager;
}
public HookManager getHookManager() {
return this.hookManager;
}
public SpecialItems getSpecialItems() {
return this.specialItems;
}
@ -199,10 +189,18 @@ public class EpicEnchants extends SongodaPlugin {
}
public CommandManager getCommandManager() {
return commandManager;
return this.commandManager;
}
public GuiManager getGuiManager() {
return guiManager;
return this.guiManager;
}
/**
* @deprecated Use {@link EpicEnchants#getPlugin(Class)} instead
*/
@Deprecated
public static EpicEnchants getInstance() {
return EpicEnchants.getPlugin(EpicEnchants.class);
}
}

View File

@ -1,26 +1,25 @@
package com.songoda.epicenchants.commands;
package com.craftaro.epicenchants.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.menus.AlchemistMenu;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.menus.AlchemistMenu;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class CommandAlchemist extends AbstractCommand {
private final EpicEnchants plugin;
public CommandAlchemist(EpicEnchants plugin) {
super(true, "alchemist");
super(CommandType.PLAYER_ONLY, "alchemist");
this.plugin = plugin;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
new AlchemistMenu(plugin, plugin.getFileManager().getConfiguration("menus/alchemist-menu")).open(player);
new AlchemistMenu(this.plugin, this.plugin.getFileManager().getConfiguration("menus/alchemist-menu")).open(player);
return ReturnType.SUCCESS;
}

View File

@ -1,12 +1,12 @@
package com.songoda.epicenchants.commands;
package com.craftaro.epicenchants.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.epicenchants.CommandCommons;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.enums.EnchantResult;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.utils.Tuple;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.CommandCommons;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.enums.EnchantResult;
import com.craftaro.epicenchants.utils.Tuple;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -16,55 +16,58 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static com.songoda.epicenchants.enums.EnchantResult.BROKEN_FAILURE;
import static com.songoda.epicenchants.utils.single.GeneralUtils.getMessageFromResult;
import static com.craftaro.epicenchants.enums.EnchantResult.BROKEN_FAILURE;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.getMessageFromResult;
public class CommandApply extends AbstractCommand {
private final EpicEnchants plugin;
public CommandApply(EpicEnchants plugin) {
super(true, "apply");
super(CommandType.PLAYER_ONLY, "apply");
this.plugin = plugin;
}
//apply [enchant] [level] <success-rate> <destroy-rate>
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 2 || args.length > 4)
if (args.length < 2 || args.length > 4) {
return ReturnType.SYNTAX_ERROR;
}
Optional<Enchant> optionalEnchant = plugin.getEnchantManager().getValue(args[0].replaceAll("_", " "));
Optional<Enchant> optionalEnchant = this.plugin.getEnchantManager().getValue(args[0].replaceAll("_", " "));
if (!optionalEnchant.isPresent()) {
plugin.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
if (!CommandCommons.isInt(args[1], sender))
if (!CommandCommons.isInt(args[1], sender)) {
return ReturnType.FAILURE;
}
int successRate = 100;
int destroyRate = 0;
if (args.length > 2) {
if (!CommandCommons.isInt(args[2], sender))
if (!CommandCommons.isInt(args[2], sender)) {
return ReturnType.FAILURE;
}
successRate = Integer.parseInt(args[2]);
}
if (args.length > 3) {
if (!CommandCommons.isInt(args[3], sender))
if (!CommandCommons.isInt(args[3], sender)) {
return ReturnType.FAILURE;
}
destroyRate = Integer.parseInt(args[3]);
}
Enchant enchant = optionalEnchant.get();
int level = Integer.parseInt(args[1]);
Player player = (Player) sender;
if (!enchant.getItemWhitelist().contains(CompatibleMaterial.getMaterial(player.getItemInHand()))) {
if (!enchant.getItemWhitelist().contains(XMaterial.matchXMaterial(player.getItemInHand().getType()))) {
System.out.println("List = " + enchant.getItemWhitelist());
plugin.getLocale().getMessage("command.apply.invaliditem")
this.plugin.getLocale().getMessage("command.apply.invaliditem")
.processPlaceholder("enchant", enchant.getIdentifier())
.sendPrefixedMessage(player);
return ReturnType.FAILURE;
@ -72,10 +75,9 @@ public class CommandApply extends AbstractCommand {
int slot = player.getInventory().getHeldItemSlot();
ItemStack before = player.getItemInHand();
Tuple<ItemStack, EnchantResult> result = plugin.getEnchantUtils().apply(before, enchant, level,
successRate, destroyRate);
Tuple<ItemStack, EnchantResult> result = this.plugin.getEnchantUtils().apply(before, enchant, level, successRate, destroyRate);
plugin.getLocale().getMessage(getMessageFromResult(result.getRight()))
this.plugin.getLocale().getMessage(getMessageFromResult(result.getRight()))
.processPlaceholder("enchant", enchant.getIdentifier())
.sendPrefixedMessage(player);
@ -91,21 +93,31 @@ public class CommandApply extends AbstractCommand {
@Override
protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) {
return plugin.getEnchantManager().getValues()
.stream().map(Enchant::getIdentifier).collect(Collectors.toList());
return this.plugin
.getEnchantManager()
.getValues()
.stream()
.map(Enchant::getIdentifier)
.collect(Collectors.toList());
} else if (args.length == 2) {
Enchant enchant = plugin.getEnchantManager().getValues()
.stream().findFirst().orElse(null);
Enchant enchant = this.plugin
.getEnchantManager()
.getValues()
.stream()
.findFirst()
.orElse(null);
List<String> levels = new ArrayList<>();
if (enchant != null) {
for (int i = 1; i <= enchant.getMaxLevel(); i++)
for (int i = 1; i <= enchant.getMaxLevel(); i++) {
levels.add(String.valueOf(i));
}
}
return levels;
} else if (args.length == 3 || args.length == 4) {
List<String> rates = new ArrayList<>();
for (int i = 1; i <= 100; i++)
for (int i = 1; i <= 100; i++) {
rates.add(String.valueOf(i));
}
return rates;
}
return null;

View File

@ -1,26 +1,25 @@
package com.songoda.epicenchants.commands;
package com.craftaro.epicenchants.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.menus.EnchanterMenu;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.menus.EnchanterMenu;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class CommandEnchanter extends AbstractCommand {
private final EpicEnchants plugin;
public CommandEnchanter(EpicEnchants plugin) {
super(true, "enchanter");
super(CommandType.PLAYER_ONLY, "enchanter");
this.plugin = plugin;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
new EnchanterMenu(plugin, plugin.getFileManager().getConfiguration("menus/enchanter-menu"), player).open(player);
new EnchanterMenu(this.plugin, this.plugin.getFileManager().getConfiguration("menus/enchanter-menu"), player).open(player);
return ReturnType.SUCCESS;
}

View File

@ -1,9 +1,9 @@
package com.songoda.epicenchants.commands;
package com.craftaro.epicenchants.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicenchants.CommandCommons;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Enchant;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.CommandCommons;
import com.craftaro.epicenchants.EpicEnchants;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@ -15,31 +15,31 @@ import java.util.Optional;
import java.util.stream.Collectors;
public class CommandGiveBook extends AbstractCommand {
private final EpicEnchants plugin;
public CommandGiveBook(EpicEnchants plugin) {
super(false, "givebook");
super(CommandType.CONSOLE_OK, "givebook");
this.plugin = plugin;
}
//givebook <player> <enchant> [level] [success-rate] [destroy-rate]
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 2 || args.length > 5)
if (args.length < 2 || args.length > 5) {
return ReturnType.SYNTAX_ERROR;
}
OfflinePlayer target = Bukkit.getPlayer(args[0]);
if (target == null) {
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
Optional<Enchant> optionalEnchant = plugin.getEnchantManager().getValue(args[1].replaceAll("_", " "));
Optional<Enchant> optionalEnchant = this.plugin.getEnchantManager().getValue(args[1].replaceAll("_", " "));
if (!optionalEnchant.isPresent()) {
plugin.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&cNo enchants exist with that name...").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
@ -49,25 +49,28 @@ public class CommandGiveBook extends AbstractCommand {
int destroyRate = -1;
if (args.length > 2) {
if (!CommandCommons.isInt(args[2], sender))
if (!CommandCommons.isInt(args[2], sender)) {
return ReturnType.FAILURE;
}
level = Integer.parseInt(args[2]);
}
if (args.length > 3) {
if (!CommandCommons.isInt(args[3], sender))
if (!CommandCommons.isInt(args[3], sender)) {
return ReturnType.FAILURE;
}
successRate = Integer.parseInt(args[3]);
}
if (args.length > 4) {
if (!CommandCommons.isInt(args[4], sender))
if (!CommandCommons.isInt(args[4], sender)) {
return ReturnType.FAILURE;
}
destroyRate = Integer.parseInt(args[4]);
}
if (level != -0 && (level > enchant.getMaxLevel() || level < 0)) {
plugin.getLocale().getMessage("command.book." + (level > enchant.getMaxLevel() ? "maxlevel" : "minlevel"))
this.plugin.getLocale().getMessage("command.book." + (level > enchant.getMaxLevel() ? "maxlevel" : "minlevel"))
.processPlaceholder("enchant", enchant.getIdentifier())
.processPlaceholder("max_level", enchant.getMaxLevel())
.sendPrefixedMessage(sender);
@ -75,10 +78,10 @@ public class CommandGiveBook extends AbstractCommand {
}
target.getPlayer().getInventory().addItem(enchant.getBook().get(enchant, level, successRate, destroyRate));
plugin.getLocale().getMessage("command.book.received")
this.plugin.getLocale().getMessage("command.book.received")
.processPlaceholder("enchant", enchant.getIdentifier())
.sendPrefixedMessage(target.getPlayer());
plugin.getLocale().getMessage("command.book.gave")
this.plugin.getLocale().getMessage("command.book.gave")
.processPlaceholder("player", target.getPlayer().getName())
.processPlaceholder("enchant", enchant.getIdentifier())
.sendPrefixedMessage(sender);
@ -90,21 +93,27 @@ public class CommandGiveBook extends AbstractCommand {
if (args.length == 1) {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
} else if (args.length == 2) {
return plugin.getEnchantManager().getValues()
return this.plugin.getEnchantManager().getValues()
.stream().map(Enchant::getIdentifier).collect(Collectors.toList());
} else if (args.length == 3) {
Enchant enchant = plugin.getEnchantManager().getValues()
.stream().findFirst().orElse(null);
Enchant enchant = this.plugin
.getEnchantManager()
.getValues()
.stream()
.findFirst()
.orElse(null);
List<String> levels = new ArrayList<>();
if (enchant != null) {
for (int i = 1; i <= enchant.getMaxLevel(); i++)
for (int i = 1; i <= enchant.getMaxLevel(); i++) {
levels.add(String.valueOf(i));
}
}
return levels;
} else if (args.length == 4 || args.length == 5) {
List<String> rates = new ArrayList<>();
for (int i = 1; i <= 100; i++)
for (int i = 1; i <= 100; i++) {
rates.add(String.valueOf(i));
}
return rates;
}
return null;

View File

@ -1,9 +1,9 @@
package com.songoda.epicenchants.commands;
package com.craftaro.epicenchants.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicenchants.CommandCommons;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Group;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.CommandCommons;
import com.craftaro.epicenchants.EpicEnchants;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@ -15,32 +15,32 @@ import java.util.List;
import java.util.stream.Collectors;
public class CommandGiveItemDust extends AbstractCommand {
private final EpicEnchants plugin;
public CommandGiveItemDust(EpicEnchants plugin) {
super(false, "giveitemdust");
super(CommandType.CONSOLE_OK, "giveitemdust");
this.plugin = plugin;
}
//giveitemdust <player> <group> [type] [percentage]
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 2 || args.length > 5)
if (args.length < 2 || args.length > 5) {
return ReturnType.SYNTAX_ERROR;
}
OfflinePlayer target = Bukkit.getPlayer(args[0]);
if (target == null) {
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
List<Group> groups = plugin.getGroupManager().getValues().stream()
List<Group> groups = this.plugin.getGroupManager().getValues().stream()
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[1])).collect(Collectors.toList());
if (groups.isEmpty()) {
plugin.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
@ -54,16 +54,17 @@ public class CommandGiveItemDust extends AbstractCommand {
}
if (args.length > 3) {
if (!CommandCommons.isInt(args[3], sender))
if (!CommandCommons.isInt(args[3], sender)) {
return ReturnType.FAILURE;
}
percentage = Integer.parseInt(args[3]);
}
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getDust(group, dustType, percentage, true));
plugin.getLocale().getMessage("command.dust.received")
target.getPlayer().getInventory().addItem(this.plugin.getSpecialItems().getDust(group, dustType, percentage, true));
this.plugin.getLocale().getMessage("command.dust.received")
.processPlaceholder("group", group.getIdentifier())
.sendPrefixedMessage(target.getPlayer());
plugin.getLocale().getMessage("command.dust.gave")
this.plugin.getLocale().getMessage("command.dust.gave")
.processPlaceholder("player", target.getPlayer().getName())
.processPlaceholder("group", group.getIdentifier())
.sendPrefixedMessage(sender);
@ -75,18 +76,22 @@ public class CommandGiveItemDust extends AbstractCommand {
if (args.length == 1) {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
} else if (args.length == 2) {
return plugin.getGroupManager().getValues().stream()
.map(Group::getIdentifier).collect(Collectors.toList());
return this.plugin.getGroupManager()
.getValues()
.stream()
.map(Group::getIdentifier)
.collect(Collectors.toList());
} else if (args.length == 3) {
List<String> dusts = new ArrayList<>();
FileConfiguration dustConfig = plugin.getFileManager().getConfiguration("items/dusts");
FileConfiguration dustConfig = this.plugin.getFileManager().getConfiguration("items/dusts");
dusts.addAll(dustConfig.getConfigurationSection("dusts").getKeys(false));
return dusts;
} else if (args.length == 4) {
List<String> rates = new ArrayList<>();
for (int i = 1; i <= 100; i++)
for (int i = 1; i <= 100; i++) {
rates.add(String.valueOf(i));
}
return rates;
}
return null;

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.commands;
package com.craftaro.epicenchants.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Group;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.EpicEnchants;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@ -16,37 +16,38 @@ public class CommandGiveRandomBook extends AbstractCommand {
private final EpicEnchants plugin;
public CommandGiveRandomBook(EpicEnchants plugin) {
super(false, "giverandombook");
super(CommandType.CONSOLE_OK, "giverandombook");
this.plugin = plugin;
}
//giverandombook <player> <group>
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 2 || args.length > 6)
if (args.length < 2 || args.length > 6) {
return ReturnType.SYNTAX_ERROR;
}
OfflinePlayer target = Bukkit.getPlayer(args[0]);
if (target == null) {
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
List<Group> groups = plugin.getGroupManager().getValues().stream()
List<Group> groups = this.plugin.getGroupManager().getValues().stream()
.filter(group -> group.getIdentifier().equalsIgnoreCase(args[1])).collect(Collectors.toList());
if (groups.isEmpty()) {
plugin.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&cThe group you entered was no found...").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
Group group = groups.get(0);
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getMysteryBook(group));
plugin.getLocale().getMessage("command.randombook.received")
target.getPlayer().getInventory().addItem(this.plugin.getSpecialItems().getMysteryBook(group));
this.plugin.getLocale().getMessage("command.randombook.received")
.sendPrefixedMessage(target.getPlayer());
plugin.getLocale().getMessage("command.randombook.gave")
this.plugin.getLocale().getMessage("command.randombook.gave")
.processPlaceholder("player", target.getPlayer().getName())
.sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
@ -55,10 +56,16 @@ public class CommandGiveRandomBook extends AbstractCommand {
@Override
protected List<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
return Bukkit.getOnlinePlayers()
.stream()
.map(Player::getName)
.collect(Collectors.toList());
} else if (args.length == 2) {
return plugin.getGroupManager().getValues().stream()
.map(Group::getIdentifier).collect(Collectors.toList());
return this.plugin.getGroupManager()
.getValues()
.stream()
.map(Group::getIdentifier)
.collect(Collectors.toList());
}
return null;
}

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.commands;
package com.craftaro.epicenchants.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicenchants.CommandCommons;
import com.songoda.epicenchants.EpicEnchants;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.epicenchants.CommandCommons;
import com.craftaro.epicenchants.EpicEnchants;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@ -14,25 +14,25 @@ import java.util.List;
import java.util.stream.Collectors;
public class CommandGiveScroll extends AbstractCommand {
private final EpicEnchants plugin;
public CommandGiveScroll(EpicEnchants plugin) {
super(false, "givescroll");
super(CommandType.CONSOLE_OK, "givescroll");
this.plugin = plugin;
}
//givescroll <giveType> <player> [amount] [success-rate]
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length < 2 || args.length > 5)
if (args.length < 2 || args.length > 5) {
return ReturnType.SYNTAX_ERROR;
}
String giveType = args[0];
OfflinePlayer target = Bukkit.getPlayer(args[1]);
if (target == null) {
plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
this.plugin.getLocale().newMessage("&cThis player does not exist...").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
@ -40,37 +40,39 @@ public class CommandGiveScroll extends AbstractCommand {
int successRate = -1;
if (args.length > 2) {
if (!CommandCommons.isInt(args[2], sender))
if (!CommandCommons.isInt(args[2], sender)) {
return ReturnType.FAILURE;
}
amount = Integer.parseInt(args[2]);
}
if (args.length > 3) {
if (!CommandCommons.isInt(args[3], sender))
if (!CommandCommons.isInt(args[3], sender)) {
return ReturnType.FAILURE;
}
successRate = Integer.parseInt(args[3]);
}
String messageKey;
switch (giveType.toLowerCase()) {
case "whitescroll":
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getWhiteScroll(amount));
target.getPlayer().getInventory().addItem(this.plugin.getSpecialItems().getWhiteScroll(amount));
messageKey = "whitescroll";
break;
case "blackscroll":
messageKey = "blackscroll";
target.getPlayer().getInventory().addItem(plugin.getSpecialItems().getBlackScroll(amount, successRate));
target.getPlayer().getInventory().addItem(this.plugin.getSpecialItems().getBlackScroll(amount, successRate));
break;
default:
plugin.getLocale().getMessage("command.giveunknown")
this.plugin.getLocale().getMessage("command.giveunknown")
.processPlaceholder("unknown", giveType)
.sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
plugin.getLocale().getMessage("command." + messageKey + ".received")
this.plugin.getLocale().getMessage("command." + messageKey + ".received")
.sendPrefixedMessage(target.getPlayer());
plugin.getLocale().getMessage("command." + messageKey + ".gave")
this.plugin.getLocale().getMessage("command." + messageKey + ".gave")
.processPlaceholder("player", target.getName())
.sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
@ -81,11 +83,15 @@ public class CommandGiveScroll extends AbstractCommand {
if (args.length == 1) {
return Arrays.asList("whitescroll", "blackscroll");
} else if (args.length == 2) {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
return Bukkit.getOnlinePlayers()
.stream()
.map(Player::getName)
.collect(Collectors.toList());
} else if (args.length == 3 || args.length == 4) {
List<String> rates = new ArrayList<>();
for (int i = 1; i <= (args.length == 3 ? 10 : 100); i++)
for (int i = 1; i <= (args.length == 3 ? 10 : 100); i++) {
rates.add(String.valueOf(i));
}
return rates;
}
return null;

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.commands;
package com.craftaro.epicenchants.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicenchants.EpicEnchants;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.epicenchants.EpicEnchants;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -10,24 +10,23 @@ import java.util.List;
import java.util.stream.Collectors;
public class CommandList extends AbstractCommand {
private final EpicEnchants plugin;
public CommandList(EpicEnchants plugin) {
super(true, "list");
super(CommandType.PLAYER_ONLY, "list");
this.plugin = plugin;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length > 1 && args[1].equalsIgnoreCase("chat")) {
plugin.getLocale().newMessage(plugin.getEnchantManager().getValues().stream()
this.plugin.getLocale().newMessage(this.plugin.getEnchantManager().getValues().stream()
.sorted(Comparator.comparing(enchant -> enchant.getGroup().getOrder()))
.map(enchant -> enchant.getColoredIdentifier(true)).collect(Collectors.joining("&7, ")))
.sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
}
plugin.getInfoManager().getMainInfoMenu().open((Player) sender);
this.plugin.getInfoManager().getMainInfoMenu().open((Player) sender);
return ReturnType.SUCCESS;
}

View File

@ -1,24 +1,23 @@
package com.songoda.epicenchants.commands;
package com.craftaro.epicenchants.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicenchants.EpicEnchants;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.epicenchants.EpicEnchants;
import org.bukkit.command.CommandSender;
import java.util.List;
public class CommandReload extends AbstractCommand {
private final EpicEnchants plugin;
public CommandReload(EpicEnchants plugin) {
super(false, "reload");
super(CommandType.CONSOLE_OK, "reload");
this.plugin = plugin;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
plugin.reloadConfig();
plugin.getLocale().getMessage("command.reload").sendPrefixedMessage(sender);
this.plugin.reloadConfig();
this.plugin.getLocale().getMessage("command.reload").sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
}

View File

@ -1,25 +1,24 @@
package com.songoda.epicenchants.commands;
package com.craftaro.epicenchants.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.configuration.editor.PluginConfigGui;
import com.songoda.epicenchants.EpicEnchants;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.core.configuration.editor.PluginConfigGui;
import com.craftaro.epicenchants.EpicEnchants;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class CommandSettings extends AbstractCommand {
private final EpicEnchants plugin;
public CommandSettings(EpicEnchants plugin) {
super(true, "Settings");
super(CommandType.PLAYER_ONLY, "Settings");
this.plugin = plugin;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
plugin.getGuiManager().showGUI((Player) sender, new PluginConfigGui(plugin));
this.plugin.getGuiManager().showGUI((Player) sender, new PluginConfigGui(this.plugin));
return ReturnType.SUCCESS;
}

View File

@ -1,26 +1,25 @@
package com.songoda.epicenchants.commands;
package com.craftaro.epicenchants.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.menus.TinkererMenu;
import com.craftaro.core.commands.AbstractCommand;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.menus.TinkererMenu;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class CommandTinkerer extends AbstractCommand {
private final EpicEnchants plugin;
public CommandTinkerer(EpicEnchants plugin) {
super(true, "tinkerer");
super(CommandType.PLAYER_ONLY, "tinkerer");
this.plugin = plugin;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender;
new TinkererMenu(plugin, plugin.getFileManager().getConfiguration("menus/tinkerer-menu")).open(player);
new TinkererMenu(this.plugin, this.plugin.getFileManager().getConfiguration("menus/tinkerer-menu")).open(player);
return ReturnType.SUCCESS;
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicenchants.effect;
package com.craftaro.epicenchants.effect;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View File

@ -1,10 +1,10 @@
package com.songoda.epicenchants.effect;
package com.craftaro.epicenchants.effect;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.enums.TriggerType;
import com.songoda.epicenchants.objects.Condition;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.songoda.epicenchants.utils.single.GeneralUtils;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.enums.TriggerType;
import com.craftaro.epicenchants.objects.Condition;
import com.craftaro.epicenchants.objects.LeveledModifier;
import com.craftaro.epicenchants.utils.single.GeneralUtils;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -18,8 +18,8 @@ import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static com.songoda.epicenchants.effect.EffectExecutor.Who.OPPONENT;
import static com.songoda.epicenchants.effect.EffectExecutor.Who.USER;
import static com.craftaro.epicenchants.effect.EffectExecutor.Who.OPPONENT;
import static com.craftaro.epicenchants.effect.EffectExecutor.Who.USER;
public abstract class EffectExecutor {
private final ConfigurationSection section;
@ -45,15 +45,15 @@ public abstract class EffectExecutor {
}
public void testAndRun(@NotNull Player user, @Nullable LivingEntity opponent, int level, TriggerType type, Event event, EventType eventType, boolean simul) {
if (!simul && !triggerTypes.contains(type)) {
if (!simul && !this.triggerTypes.contains(type)) {
return;
}
if (section.isString("chance") && !GeneralUtils.chance(LeveledModifier.of(section.getString("chance")).get(level, 100, user, opponent))) {
if (this.section.isString("chance") && !GeneralUtils.chance(LeveledModifier.of(this.section.getString("chance")).get(level, 100, user, opponent))) {
return;
}
if (!condition.get(user, opponent, level, event, false)) {
if (!this.condition.get(user, opponent, level, event, false)) {
return;
}
@ -63,25 +63,31 @@ public abstract class EffectExecutor {
execute(user, opponent, level, eventType);
}
simultaneous.forEach(e -> e.testAndRun(user, opponent, level, type, event, eventType, true));
this.simultaneous.forEach(e -> e.testAndRun(user, opponent, level, type, event, eventType, true));
}
public abstract void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType);
protected Who who() {
if (section.isString("who")) {
if (section.getString("who").equalsIgnoreCase("user")) return USER;
else if (section.getString("who").equalsIgnoreCase("opponent")) return OPPONENT;
if (this.section.isString("who")) {
if (this.section.getString("who").equalsIgnoreCase("user")) {
return USER;
}
if (this.section.getString("who").equalsIgnoreCase("opponent")) {
return OPPONENT;
}
}
return USER;
}
public LeveledModifier getAmount() {
return LeveledModifier.of(section.getString("amount"));
return LeveledModifier.of(this.section.getString("amount"));
}
public void consume(Consumer<LivingEntity> playerConsumer, Player user, @Nullable LivingEntity opponent) {
if (triggerTypes.contains(TriggerType.HELD_ITEM) || triggerTypes.contains(TriggerType.STATIC_EFFECT)) {
if (this.triggerTypes.contains(TriggerType.HELD_ITEM) || this.triggerTypes.contains(TriggerType.STATIC_EFFECT)) {
playerConsumer.accept(user);
return;
}
@ -91,8 +97,9 @@ public abstract class EffectExecutor {
playerConsumer.accept(user);
break;
case OPPONENT:
if (opponent != null)
if (opponent != null) {
playerConsumer.accept(opponent);
}
}
}

View File

@ -1,17 +1,15 @@
package com.songoda.epicenchants.effect;
package com.craftaro.epicenchants.effect;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
public class EffectManager {
public static Optional<EffectExecutor> getEffect(ConfigurationSection section) {
if (section == null) {
return Optional.empty();
@ -19,12 +17,12 @@ public class EffectManager {
try {
String formatted = UPPER_UNDERSCORE.to(UPPER_CAMEL, section.getName().toLowerCase()).replaceAll("-.*$", "");
Class<?> clazz = Class.forName("com.songoda.epicenchants.effect.effects." + formatted);
Class<?> clazz = Class.forName("com.craftaro.epicenchants.effect.effects." + formatted);
Constructor<?> constructor = clazz.getConstructor(ConfigurationSection.class);
Object object = constructor.newInstance(section);
return Optional.of((EffectExecutor) object);
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassCastException e) {
e.printStackTrace();
} catch (ReflectiveOperationException | ClassCastException ex) {
ex.printStackTrace();
Bukkit.getLogger().severe("Invalid effect: " + section.getName());
}

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.objects.LeveledModifier;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectEventExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.effect.EffectEventExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -14,7 +14,7 @@ public class CancelEvent extends EffectEventExecutor {
}
@Override
public void execute(Player player, LivingEntity opponent, int level, Event event, EventType eventType) {
public void execute(Player user, LivingEntity opponent, int level, Event event, EventType eventType) {
if (event instanceof Cancellable) {
((Cancellable) event).setCancelled(true);
}

View File

@ -1,9 +1,9 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.utils.single.GeneralUtils;
import com.songoda.epicenchants.utils.single.Placeholders;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.utils.single.GeneralUtils;
import com.craftaro.epicenchants.utils.single.Placeholders;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
@ -17,7 +17,8 @@ public class ConsoleCommand extends EffectExecutor {
@Override
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
GeneralUtils.getString(getSection(), "command").stream()
GeneralUtils.getString(getSection(), "command")
.stream()
.map(s -> Placeholders.setPlaceholders(s, user, opponent, level))
.forEach(s -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s));
}

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
@ -24,7 +24,7 @@ public class DropHead extends EffectExecutor {
}
private Optional<ItemStack> getHead(Entity entity) {
ItemStack out = CompatibleMaterial.PLAYER_HEAD.getItem();
ItemStack out = XMaterial.PLAYER_HEAD.parseItem();
String skin = null;
switch (entity.getType()) {
@ -47,10 +47,10 @@ public class DropHead extends EffectExecutor {
skin = "MHF_Spider";
break;
case ZOMBIE:
out = CompatibleMaterial.ZOMBIE_HEAD.getItem();
out = XMaterial.ZOMBIE_HEAD.parseItem();
break;
case SKELETON:
out = CompatibleMaterial.SKELETON_SKULL.getItem();
out = XMaterial.SKELETON_SKULL.parseItem();
break;
case VILLAGER:
skin = "MHF_Villager";
@ -62,7 +62,7 @@ public class DropHead extends EffectExecutor {
skin = "MHF_Blaze";
break;
case CREEPER:
out = CompatibleMaterial.CREEPER_HEAD.getItem();
out = XMaterial.CREEPER_HEAD.parseItem();
case ENDERMAN:
skin = "MHF_Enderman";
break;
@ -72,8 +72,6 @@ public class DropHead extends EffectExecutor {
case IRON_GOLEM:
skin = "MHF_Golem";
break;
case WITHER_SKELETON:
out = CompatibleMaterial.WITHER_SKELETON_SKULL.getItem();
case PLAYER:
break;
default:
@ -82,9 +80,9 @@ public class DropHead extends EffectExecutor {
SkullMeta skullMeta = (SkullMeta) out.getItemMeta();
if (skin != null && CompatibleMaterial.getMaterial(out) == CompatibleMaterial.PLAYER_HEAD
|| entity instanceof Player)
if ((skin != null && XMaterial.PLAYER_HEAD.isSimilar(out)) || entity instanceof Player) {
skullMeta.setOwner(entity instanceof Player ? entity.getName() : skin);
}
out.setItemMeta(skullMeta);
return Optional.of(out);

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
@ -20,8 +20,7 @@ public class DropHeld extends EffectExecutor {
consume(entity -> {
Player player = ((Player) entity);
if (player.getItemInHand().getType() != Material.AIR) {
entity.getLocation().getWorld().dropItemNaturally(entity.getLocation(), new ItemBuilder(player
.getItemInHand()).build());
entity.getLocation().getWorld().dropItemNaturally(entity.getLocation(), new ItemBuilder(player.getItemInHand()).build());
player.setItemInHand(null);
}
}, user, opponent);

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -16,7 +16,6 @@ public class DropItem extends EffectExecutor {
@Override
public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) {
consume(entity -> entity.getLocation().getWorld().dropItemNaturally(entity.getLocation(),
new ItemBuilder(getSection(), ((Player) entity)).build()), user, opponent);
consume(entity -> entity.getLocation().getWorld().dropItemNaturally(entity.getLocation(), new ItemBuilder(getSection(), ((Player) entity)).build()), user, opponent);
}
}

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.objects.LeveledModifier;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View File

@ -1,13 +1,13 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import static com.songoda.epicenchants.enums.EventType.ON;
import static com.craftaro.epicenchants.enums.EventType.ON;
public class Fly extends EffectExecutor {
public Fly(ConfigurationSection section) {

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View File

@ -1,9 +1,9 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.utils.single.GeneralUtils;
import com.songoda.epicenchants.utils.single.Placeholders;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.utils.single.GeneralUtils;
import com.craftaro.epicenchants.utils.single.Placeholders;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -17,7 +17,8 @@ public class Message extends EffectExecutor {
@Override
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
if (eventType == EventType.ON || eventType == EventType.NONE) {
consume(entity -> GeneralUtils.getString(getSection(), "message").stream()
consume(entity -> GeneralUtils.getString(getSection(), "message")
.stream()
.map(s -> Placeholders.setPlaceholders(s, user, opponent, level))
.forEach(entity::sendMessage), user, opponent);
}

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectEventExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.effect.EffectEventExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
@ -28,7 +28,6 @@ public class ModifyBlock extends EffectEventExecutor {
block.breakNaturally();
return;
}
block.setType(Material.getMaterial(getSection().getString("material")));
}
}

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectEventExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.craftaro.epicenchants.effect.EffectEventExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.objects.LeveledModifier;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View File

@ -1,9 +1,9 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.songoda.epicenchants.utils.single.Experience;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.objects.LeveledModifier;
import com.craftaro.epicenchants.utils.single.Experience;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectEventExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.effect.EffectEventExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectEventExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.craftaro.epicenchants.effect.EffectEventExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.objects.LeveledModifier;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -26,7 +26,8 @@ public class MoreDrops extends EffectEventExecutor {
EntityDeathEvent deathEvent = (EntityDeathEvent) event;
LeveledModifier modifier = getAmount();
List<ItemStack> newDrops = deathEvent.getDrops().stream()
List<ItemStack> newDrops = deathEvent.getDrops()
.stream()
.peek(itemStack -> itemStack.setAmount(((int) (itemStack.getAmount() * modifier.get(level, 1, user, opponent)))))
.collect(Collectors.toList());

View File

@ -1,17 +1,16 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.utils.single.GeneralUtils;
import com.songoda.epicenchants.utils.single.Placeholders;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.utils.single.GeneralUtils;
import com.craftaro.epicenchants.utils.single.Placeholders;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import static com.songoda.epicenchants.effect.EffectExecutor.Who.OPPONENT;
import static com.songoda.epicenchants.enums.EventType.NONE;
import static com.songoda.epicenchants.enums.EventType.ON;
import static com.craftaro.epicenchants.enums.EventType.NONE;
import static com.craftaro.epicenchants.enums.EventType.ON;
public class PlayerCommand extends EffectExecutor {
public PlayerCommand(ConfigurationSection section) {
@ -24,11 +23,12 @@ public class PlayerCommand extends EffectExecutor {
return;
}
if (who() == OPPONENT && !(opponent instanceof Player)) {
if (who() == Who.OPPONENT && !(opponent instanceof Player)) {
return;
}
consume(entity -> GeneralUtils.getString(getSection(), "message").stream()
consume(entity -> GeneralUtils.getString(getSection(), "message")
.stream()
.map(s -> Placeholders.setPlaceholders(s, user, opponent, level))
.forEach(((Player) entity)::performCommand), user, opponent);
}

View File

@ -1,9 +1,9 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.enums.TriggerType;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.enums.TriggerType;
import com.craftaro.epicenchants.objects.LeveledModifier;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -31,17 +31,24 @@ public class Potion extends EffectExecutor {
if (getTriggerTypes().contains(TriggerType.STATIC_EFFECT) || getTriggerTypes().contains(TriggerType.HELD_ITEM)) {
if (eventType == EventType.ON) {
consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, Integer.MAX_VALUE, (int) amplifier.get(level - 1, 0, user, opponent),
false, false)), user, opponent);
consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, Integer.MAX_VALUE, (int) amplifier.get(level - 1, 0, user, opponent), false, false)), user, opponent);
} else if (eventType == EventType.OFF) {
consume(entity -> entity.removePotionEffect(effectType), user, opponent);
}
return;
}
LeveledModifier duration = LeveledModifier.of(getSection().getString("duration"));
consume(entity -> entity.addPotionEffect(new PotionEffect(effectType, (int) duration.get(level, 60, user, opponent) * 20,
(int) amplifier.get(level - 1, 0, user, opponent), false, false)), user, opponent);
consume(
entity -> entity.addPotionEffect(new PotionEffect(effectType,
(int) duration.get(level, 60, user, opponent) * 20,
(int) amplifier.get(level - 1, 0, user, opponent),
false,
false)),
user,
opponent
);
}
}

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -15,8 +15,9 @@ public class Repair extends EffectExecutor {
@Override
public void execute(@NotNull Player user, LivingEntity opponent, int level, EventType eventType) {
consume(livingEntity -> {
if (livingEntity instanceof Player)
if (livingEntity instanceof Player) {
((Player) livingEntity).getItemInHand().setDurability((short) 0);
}
}, user, opponent);
}
}

View File

@ -0,0 +1,112 @@
package com.craftaro.epicenchants.effect.effects;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.objects.LeveledModifier;
import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static com.craftaro.epicenchants.objects.LeveledModifier.of;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.color;
import static java.util.concurrent.ThreadLocalRandom.current;
public class SpawnMob extends EffectExecutor {
private final LeveledModifier attackDamage;
private final String displayName;
private final EntityType entityType;
private final LeveledModifier equipmentDropChance;
private final LeveledModifier health;
private final ItemBuilder helmet;
private final ItemBuilder chestPlate;
private final ItemBuilder leggings;
private final ItemBuilder boots;
private final ItemBuilder handItem;
private final boolean hostile;
private final LeveledModifier amount;
public SpawnMob(ConfigurationSection section) {
super(section);
this.entityType = EntityType.valueOf(section.getString("mob-type"));
this.amount = of(section.getString("amount"));
this.health = of(section.getString("health"));
this.attackDamage = of(section.getString("attack-damage"));
this.equipmentDropChance = LeveledModifier.of(section.getString("equipment-drop-chance"));
this.hostile = section.getBoolean("hostile", false);
this.displayName = section.isString("display-name") ? color(section.getString("display-name")) : "";
this.helmet = section.isConfigurationSection("equipment.helmet") ? new ItemBuilder(section.getConfigurationSection("equipment.helmet")) : null;
this.chestPlate = section.isConfigurationSection("equipment.chestplate") ? new ItemBuilder(section.getConfigurationSection("equipment.chestplate")) : null;
this.leggings = section.isConfigurationSection("equipment.leggings") ? new ItemBuilder(section.getConfigurationSection("equipment.leggings")) : null;
this.boots = section.isConfigurationSection("equipment.boots") ? new ItemBuilder(section.getConfigurationSection("equipment.boots")) : null;
this.handItem = section.isConfigurationSection("equipment.hand-item") ? new ItemBuilder(section.getConfigurationSection("equipment.hand-item")) : null;
}
@Override
public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) {
Location location = user.getLocation();
for (int i = 0; i < this.amount.get(level, 1, user, opponent); i++) {
Location spawnLocation = location.clone().add(current().nextInt(-3, 3), 0, current().nextInt(-3, 3));
int y = location.getWorld().getHighestBlockAt(spawnLocation).getY();
if (y < location.getY() - 10 || y > location.getY() + 10) {
continue;
}
Entity entity = location.getWorld().spawnEntity(spawnLocation, this.entityType);
entity.setCustomName(this.displayName.replace("{level}", "" + level));
entity.setCustomNameVisible(true);
if (entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) entity;
livingEntity.setRemoveWhenFarAway(true);
int dropChance = (int) this.equipmentDropChance.get(level, 0, user, opponent);
if (this.helmet != null) {
livingEntity.getEquipment().setHelmet(this.helmet.buildWithWrappers(level, user, opponent));
}
if (this.chestPlate != null) {
livingEntity.getEquipment().setChestplate(this.chestPlate.buildWithWrappers(level, user, opponent));
}
if (this.leggings != null) {
livingEntity.getEquipment().setLeggings(this.leggings.buildWithWrappers(level, user, opponent));
}
if (this.boots != null) {
livingEntity.getEquipment().setBoots(this.boots.buildWithWrappers(level, user, opponent));
}
livingEntity.getEquipment().setHelmetDropChance(dropChance);
livingEntity.getEquipment().setLeggingsDropChance(dropChance);
livingEntity.getEquipment().setHelmetDropChance(dropChance);
livingEntity.getEquipment().setChestplateDropChance(dropChance);
if (this.handItem != null) {
livingEntity.getEquipment().setItemInHand(this.handItem.buildWithWrappers(level, user, opponent));
}
livingEntity.getEquipment().setItemInHandDropChance(dropChance);
}
if (this.hostile && entity instanceof Monster && opponent != null) {
((Monster) entity).setTarget(opponent);
}
if (entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) entity;
// AttributeInstance attack = ((LivingEntity) entity).getAttribute(Attribute.GENERIC_ATTACK_DAMAGE);
// attack.setBaseValue(attackDamage.get(level, (int) Math.round(attack.getBaseValue()), user, opponent));
double maxHealth = livingEntity.getMaxHealth();
livingEntity.setMaxHealth(this.health.get(level, (int) Math.round(maxHealth), user, opponent));
}
}
}
}

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.objects.LeveledModifier;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType;

View File

@ -1,15 +1,15 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static com.songoda.epicenchants.utils.single.Experience.changeExp;
import static com.songoda.epicenchants.utils.single.Experience.getExp;
import static com.craftaro.epicenchants.utils.single.Experience.changeExp;
import static com.craftaro.epicenchants.utils.single.Experience.getExp;
public class StealExp extends EffectExecutor {
public StealExp(ConfigurationSection section) {

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -27,10 +27,14 @@ public class StealFood extends EffectExecutor {
if (opponentFood <= 0) {
opponentPlayer.setFoodLevel(0);
} else opponentPlayer.setFoodLevel(Math.min(opponentFood, 20));
} else {
opponentPlayer.setFoodLevel(Math.min(opponentFood, 20));
}
if (userFood <= 0) {
user.setFoodLevel(0);
} else user.setFoodLevel(Math.min(userFood, 20));
} else {
user.setFoodLevel(Math.min(userFood, 20));
}
}
}

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

View File

@ -1,16 +1,14 @@
package com.songoda.epicenchants.effect.effects;
package com.craftaro.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.objects.LeveledModifier;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import static com.songoda.epicenchants.effect.EffectExecutor.Who.USER;
public class Throw extends EffectExecutor {
public Throw(ConfigurationSection section) {
super(section);
@ -28,7 +26,7 @@ public class Throw extends EffectExecutor {
Vector vector;
double magnitude = LeveledModifier.of(getSection().getString("magnitude")).get(level, 0.1, user, opponent);
LivingEntity livingEntity = who() == USER ? user : opponent;
LivingEntity livingEntity = who() == Who.USER ? user : opponent;
String relativeToStr = getSection().getString("relative-to");
LivingEntity relative = relativeToStr == null || relativeToStr.equalsIgnoreCase("user") ? user : opponent;

View File

@ -1,4 +1,4 @@
package com.songoda.epicenchants.enums;
package com.craftaro.epicenchants.enums;
public enum EnchantResult {
SUCCESS, FAILURE, BROKEN_FAILURE, CONFLICT, MAXED_OUT, ALREADY_APPLIED, PROTECTED

View File

@ -1,4 +1,4 @@
package com.songoda.epicenchants.enums;
package com.craftaro.epicenchants.enums;
public enum EventType {
ON, OFF, NONE

View File

@ -1,4 +1,4 @@
package com.songoda.epicenchants.enums;
package com.craftaro.epicenchants.enums;
public enum GiveType {
WHITE_SCROLL, BLACK_SCROLL

View File

@ -0,0 +1,11 @@
package com.craftaro.epicenchants.enums;
public enum ItemType {
BOOK,
/**
* @deprecated Was once used for UltimateBottles integration, but I don't think it ever got published
*/
@Deprecated
ENCHANTED,
NONE
}

View File

@ -1,4 +1,4 @@
package com.songoda.epicenchants.enums;
package com.craftaro.epicenchants.enums;
public enum TriggerType {
ATTACK_PLAYER_MELEE,

View File

@ -1,4 +1,4 @@
package com.songoda.epicenchants.events;
package com.craftaro.epicenchants.events;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -8,8 +8,8 @@ import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.ItemStack;
public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList();
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private final EquipMethod equipType;
private final ArmorType type;
@ -18,36 +18,27 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
/**
* Constructor for the ArmorEquipEvent.
*
* @param player The player who put on / removed the armor.
* @param who The player who put on / removed the armor.
* @param type The ArmorType of the armor added
* @param oldArmorPiece The ItemStack of the armor removed.
* @param newArmorPiece The ItemStack of the armor added.
*/
public ArmorEquipEvent(final Player player, final EquipMethod equipType, final ArmorType type, final ItemStack oldArmorPiece, final ItemStack newArmorPiece) {
super(player);
public ArmorEquipEvent(final Player who, final EquipMethod equipType, final ArmorType type, final ItemStack oldArmorPiece, final ItemStack newArmorPiece) {
super(who);
this.equipType = equipType;
this.type = type;
this.oldArmorPiece = oldArmorPiece;
this.newArmorPiece = newArmorPiece;
}
/**
* Gets a list of handlers handling this event.
*
* @return A list of handlers handling this event.
*/
public static HandlerList getHandlerList() {
return handlers;
}
/**
* Gets a list of handlers handling this event.
*
* @return A list of handlers handling this event.
*/
@Override
public final HandlerList getHandlers() {
return handlers;
public HandlerList getHandlers() {
return HANDLERS;
}
/**
@ -55,7 +46,7 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
*
* @param cancel If this event should be cancelled.
*/
public final void setCancelled(final boolean cancel) {
public void setCancelled(final boolean cancel) {
this.cancel = cancel;
}
@ -64,33 +55,33 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
*
* @return If this event is cancelled
*/
public final boolean isCancelled() {
return cancel;
public boolean isCancelled() {
return this.cancel;
}
public final ArmorType getType() {
return type;
public ArmorType getType() {
return this.type;
}
/**
* Returns the last equipped armor piece, could be a piece of armor, {@link Material#AIR}, or null.
*/
public final ItemStack getOldArmorPiece() {
return oldArmorPiece;
public ItemStack getOldArmorPiece() {
return this.oldArmorPiece;
}
public final void setOldArmorPiece(final ItemStack oldArmorPiece) {
public void setOldArmorPiece(final ItemStack oldArmorPiece) {
this.oldArmorPiece = oldArmorPiece;
}
/**
* Returns the newly equipped armor, could be a piece of armor, {@link Material#AIR}, or null.
*/
public final ItemStack getNewArmorPiece() {
return newArmorPiece;
public ItemStack getNewArmorPiece() {
return this.newArmorPiece;
}
public final void setNewArmorPiece(final ItemStack newArmorPiece) {
public void setNewArmorPiece(final ItemStack newArmorPiece) {
this.newArmorPiece = newArmorPiece;
}
@ -98,12 +89,21 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
* Gets the method used to either equip or unequip an armor piece.
*/
public EquipMethod getMethod() {
return equipType;
return this.equipType;
}
/**
* Gets a list of handlers handling this event.
*
* @return A list of handlers handling this event.
*/
public static HandlerList getHandlerList() {
return HANDLERS;
}
public enum EquipMethod {// These have got to be the worst documentations ever.
/**
* When you shift click an armor piece to equip or unequip
* When you shift-click an armor piece to equip or unequip
*/
SHIFT_CLICK,
/**
@ -115,7 +115,7 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
*/
PICK_DROP,
/**
* When you right click an armor piece in the hotbar without the inventory open to equip.
* When you right-click an armor piece in the hotbar without the inventory open to equip.
*/
HOTBAR,
/**
@ -123,18 +123,17 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
*/
HOTBAR_SWAP,
/**
* When in range of a dispenser that shoots an armor piece to equip.
* When in range of a dispenser that shoots an armor piece to equip
*/
DISPENSER,
/**
* When an armor piece is removed due to it losing all durability.
* When an armor piece is removed due to it losing all durability
*/
BROKE,
/**
* When you die causing all armor to unequip
*/
DEATH,
;
}
public enum ArmorType {
@ -154,17 +153,26 @@ public final class ArmorEquipEvent extends PlayerEvent implements Cancellable {
* @return The parsed ArmorType. (null if none were found.)
*/
public static ArmorType matchType(final ItemStack itemStack) {
if (itemStack == null || itemStack.getType().equals(Material.AIR)) return null;
if (itemStack == null || itemStack.getType() == Material.AIR) {
return null;
}
String type = itemStack.getType().name();
if (type.endsWith("_HELMET") || type.endsWith("_SKULL")) return HELMET;
else if (type.endsWith("_CHESTPLATE") || type.equals("ELYTRA")) return CHESTPLATE;
else if (type.endsWith("_LEGGINGS")) return LEGGINGS;
else if (type.endsWith("_BOOTS")) return BOOTS;
else return null;
if (type.endsWith("_HELMET") || type.endsWith("_SKULL")) {
return HELMET;
} else if (type.endsWith("_CHESTPLATE") || type.equals("ELYTRA")) {
return CHESTPLATE;
} else if (type.endsWith("_LEGGINGS")) {
return LEGGINGS;
} else if (type.endsWith("_BOOTS")) {
return BOOTS;
} else {
return null;
}
}
public int getSlot() {
return slot;
return this.slot;
}
}
}

View File

@ -1,13 +1,14 @@
package com.songoda.epicenchants.events;
package com.craftaro.epicenchants.events;
import com.songoda.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.objects.Enchant;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
public class EnchantApplyEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private static final HandlerList HANDLERS = new HandlerList();
private final ItemStack toEnchant;
private final Enchant enchant;
private final int level;
@ -23,23 +24,19 @@ public class EnchantApplyEvent extends Event implements Cancellable {
this.destroyRate = destroyRate;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
return this.cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@Override
public HandlerList getHandlers() {
return handlers;
return HANDLERS;
}
public ItemStack getToEnchant() {
@ -61,4 +58,8 @@ public class EnchantApplyEvent extends Event implements Cancellable {
public int getDestroyRate() {
return this.destroyRate;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
}

View File

@ -1,4 +1,4 @@
package com.songoda.epicenchants.events;
package com.craftaro.epicenchants.events;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -8,8 +8,8 @@ import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.ItemStack;
public final class HeldItemChangedEvent extends PlayerEvent implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList();
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private final EquipMethod equipType;
private final ItemStack oldItem, newItem;
@ -17,47 +17,38 @@ public final class HeldItemChangedEvent extends PlayerEvent implements Cancellab
/**
* Constructor for the HeldItemChangedEvent.
*
* @param player The player who put (un)equipped an item.
* @param who The player who put (un)equipped an item.
* @param oldItem The ItemStack removed.
* @param newItem The ItemStack added.
*/
public HeldItemChangedEvent(final Player player, final EquipMethod equipType, final ItemStack oldItem, final ItemStack newItem) {
super(player);
public HeldItemChangedEvent(final Player who, final EquipMethod equipType, final ItemStack oldItem, final ItemStack newItem) {
super(who);
this.equipType = equipType;
this.oldItem = oldItem;
this.newItem = newItem;
}
/**
* Gets a list of handlers handling this event.
* Gets a list of handlers handling this event
*
* @return A list of handlers handling this event.
*/
public static HandlerList getHandlerList() {
return handlers;
}
/**
* Gets a list of handlers handling this event.
*
* @return A list of handlers handling this event.
* @return A list of handlers handling this event
*/
@Override
public final HandlerList getHandlers() {
return handlers;
return HANDLERS;
}
/**
* Sets if this event should be cancelled.
* Sets if this event should be cancelled
*
* @param cancel If this event should be cancelled.
* @param cancel If this event should be cancelled
*/
public final void setCancelled(final boolean cancel) {
this.cancel = cancel;
}
/**
* Gets if this event is cancelled.
* Gets if this event is cancelled
*
* @return If this event is cancelled
*/
@ -86,9 +77,18 @@ public final class HeldItemChangedEvent extends PlayerEvent implements Cancellab
return equipType;
}
/**
* Gets a list of handlers handling this event.
*
* @return A list of handlers handling this event.
*/
public static HandlerList getHandlerList() {
return HANDLERS;
}
public enum EquipMethod {// These have got to be the worst documentations ever.
/**
* When you shift click an armor piece to equip or unequip
* When you shift-click an armor piece to equip or unequip
*/
SHIFT_CLICK,
/**
@ -108,7 +108,7 @@ public final class HeldItemChangedEvent extends PlayerEvent implements Cancellab
*/
OFFHAND_SWAP,
/**
* When an item, e.g. tool, is removed due to it losing all durability.
* When an item, e.g., tool, is removed due to it losing all durability
*/
BROKE,
/**

View File

@ -1,8 +1,6 @@
package com.songoda.epicenchants.listeners;
package com.craftaro.epicenchants.listeners;
import com.songoda.epicenchants.events.ArmorEquipEvent;
import com.songoda.epicenchants.events.ArmorEquipEvent.ArmorType;
import com.songoda.epicenchants.events.ArmorEquipEvent.EquipMethod;
import com.craftaro.epicenchants.events.ArmorEquipEvent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -24,7 +22,6 @@ import org.bukkit.inventory.ItemStack;
import static org.bukkit.event.EventPriority.HIGHEST;
public class ArmorListener implements Listener {
@EventHandler(ignoreCancelled = true)
public final void onInventoryClick(final InventoryClickEvent e) {
boolean shift = false, numberKey = false;
@ -57,7 +54,7 @@ public class ArmorListener implements Listener {
numberKey = true;
}
ArmorType newArmorType = ArmorType.matchType(shift ? e.getCurrentItem() : e.getCursor());
ArmorEquipEvent.ArmorType newArmorType = ArmorEquipEvent.ArmorType.matchType(shift ? e.getCurrentItem() : e.getCursor());
if (!shift && newArmorType != null && e.getRawSlot() != newArmorType.getSlot()) {
// Used for drag and drop checking to make sure you aren't trying to place a helmet in the boots slot.
@ -65,14 +62,14 @@ public class ArmorListener implements Listener {
}
if (shift) {
newArmorType = ArmorType.matchType(e.getCurrentItem());
newArmorType = ArmorEquipEvent.ArmorType.matchType(e.getCurrentItem());
if (newArmorType != null) {
boolean equipping = true;
if (e.getRawSlot() == newArmorType.getSlot()) {
equipping = false;
}
if (newArmorType.equals(ArmorType.HELMET) && (equipping == isAirOrNull(e.getWhoClicked().getInventory().getHelmet())) || newArmorType.equals(ArmorType.CHESTPLATE) && (equipping == isAirOrNull(e.getWhoClicked().getInventory().getChestplate())) || newArmorType.equals(ArmorType.LEGGINGS) && (equipping == isAirOrNull(e.getWhoClicked().getInventory().getLeggings())) || newArmorType.equals(ArmorType.BOOTS) && (equipping == isAirOrNull(e.getWhoClicked().getInventory().getBoots()))) {
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent((Player) e.getWhoClicked(), EquipMethod.SHIFT_CLICK, newArmorType, equipping ? null : e.getCurrentItem(), equipping ? e.getCurrentItem() : null);
if (newArmorType.equals(ArmorEquipEvent.ArmorType.HELMET) && (equipping == isAirOrNull(e.getWhoClicked().getInventory().getHelmet())) || newArmorType.equals(ArmorEquipEvent.ArmorType.CHESTPLATE) && (equipping == isAirOrNull(e.getWhoClicked().getInventory().getChestplate())) || newArmorType.equals(ArmorEquipEvent.ArmorType.LEGGINGS) && (equipping == isAirOrNull(e.getWhoClicked().getInventory().getLeggings())) || newArmorType.equals(ArmorEquipEvent.ArmorType.BOOTS) && (equipping == isAirOrNull(e.getWhoClicked().getInventory().getBoots()))) {
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent((Player) e.getWhoClicked(), ArmorEquipEvent.EquipMethod.SHIFT_CLICK, newArmorType, equipping ? null : e.getCurrentItem(), equipping ? e.getCurrentItem() : null);
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
if (armorEquipEvent.isCancelled()) {
e.setCancelled(true);
@ -90,24 +87,24 @@ public class ArmorListener implements Listener {
// e.getSlot() == Armor slot, can't use e.getRawSlot() as that gives a hotbar slot ;-;
ItemStack hotbarItem = e.getClickedInventory().getItem(e.getHotbarButton());
if (!isAirOrNull(hotbarItem)) {// Equipping
newArmorType = ArmorType.matchType(hotbarItem);
newArmorType = ArmorEquipEvent.ArmorType.matchType(hotbarItem);
newArmorPiece = hotbarItem;
oldArmorPiece = e.getClickedInventory().getItem(e.getSlot());
} else {// Unequipping
newArmorType = ArmorType.matchType(!isAirOrNull(e.getCurrentItem()) ? e.getCurrentItem() : e.getCursor());
newArmorType = ArmorEquipEvent.ArmorType.matchType(!isAirOrNull(e.getCurrentItem()) ? e.getCurrentItem() : e.getCursor());
}
}
} else {
if (isAirOrNull(e.getCursor()) && !isAirOrNull(e.getCurrentItem())) {// unequip with no new item going into the slot.
newArmorType = ArmorType.matchType(e.getCurrentItem());
newArmorType = ArmorEquipEvent.ArmorType.matchType(e.getCurrentItem());
}
// e.getCurrentItem() == Unequip
// e.getCursor() == Equip
// newArmorType = ArmorType.matchType(!isAirOrNull(e.getCurrentItem()) ? e.getCurrentItem() : e.getCursor());
}
if (newArmorType != null && e.getRawSlot() == newArmorType.getSlot()) {
EquipMethod method = EquipMethod.PICK_DROP;
if (e.getAction().equals(InventoryAction.HOTBAR_SWAP) || numberKey) method = EquipMethod.HOTBAR_SWAP;
ArmorEquipEvent.EquipMethod method = ArmorEquipEvent.EquipMethod.PICK_DROP;
if (e.getAction().equals(InventoryAction.HOTBAR_SWAP) || numberKey) method = ArmorEquipEvent.EquipMethod.HOTBAR_SWAP;
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent((Player) e.getWhoClicked(), method, newArmorType, oldArmorPiece, newArmorPiece);
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
if (armorEquipEvent.isCancelled()) {
@ -131,10 +128,10 @@ public class ArmorListener implements Listener {
}*/
}
ArmorType newArmorType = ArmorType.matchType(e.getItem());
ArmorEquipEvent.ArmorType newArmorType = ArmorEquipEvent.ArmorType.matchType(e.getItem());
if (newArmorType != null) {
if (newArmorType.equals(ArmorType.HELMET) && isAirOrNull(e.getPlayer().getInventory().getHelmet()) || newArmorType.equals(ArmorType.CHESTPLATE) && isAirOrNull(e.getPlayer().getInventory().getChestplate()) || newArmorType.equals(ArmorType.LEGGINGS) && isAirOrNull(e.getPlayer().getInventory().getLeggings()) || newArmorType.equals(ArmorType.BOOTS) && isAirOrNull(e.getPlayer().getInventory().getBoots())) {
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(e.getPlayer(), EquipMethod.HOTBAR, ArmorType.matchType(e.getItem()), null, e.getItem());
if (newArmorType.equals(ArmorEquipEvent.ArmorType.HELMET) && isAirOrNull(e.getPlayer().getInventory().getHelmet()) || newArmorType.equals(ArmorEquipEvent.ArmorType.CHESTPLATE) && isAirOrNull(e.getPlayer().getInventory().getChestplate()) || newArmorType.equals(ArmorEquipEvent.ArmorType.LEGGINGS) && isAirOrNull(e.getPlayer().getInventory().getLeggings()) || newArmorType.equals(ArmorEquipEvent.ArmorType.BOOTS) && isAirOrNull(e.getPlayer().getInventory().getBoots())) {
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(e.getPlayer(), ArmorEquipEvent.EquipMethod.HOTBAR, ArmorEquipEvent.ArmorType.matchType(e.getItem()), null, e.getItem());
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
if (armorEquipEvent.isCancelled()) {
e.setCancelled(true);
@ -151,10 +148,10 @@ public class ArmorListener implements Listener {
return;
}
ArmorType type = ArmorType.matchType(event.getOldCursor());
ArmorEquipEvent.ArmorType type = ArmorEquipEvent.ArmorType.matchType(event.getOldCursor());
if (type != null && type.getSlot() == event.getRawSlots().stream().findFirst().orElse(0)) {
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent((Player) event.getWhoClicked(), EquipMethod.DRAG, type, null, event.getOldCursor());
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent((Player) event.getWhoClicked(), ArmorEquipEvent.EquipMethod.DRAG, type, null, event.getOldCursor());
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
if (armorEquipEvent.isCancelled()) {
event.setResult(Result.DENY);
@ -165,10 +162,10 @@ public class ArmorListener implements Listener {
@EventHandler
public void itemBreakEvent(PlayerItemBreakEvent e) {
ArmorType type = ArmorType.matchType(e.getBrokenItem());
ArmorEquipEvent.ArmorType type = ArmorEquipEvent.ArmorType.matchType(e.getBrokenItem());
if (type != null) {
Player p = e.getPlayer();
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(p, EquipMethod.BROKE, type, e.getBrokenItem(), null);
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(p, ArmorEquipEvent.EquipMethod.BROKE, type, e.getBrokenItem(), null);
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
if (armorEquipEvent.isCancelled()) {
ItemStack i = e.getBrokenItem().clone();
@ -194,9 +191,9 @@ public class ArmorListener implements Listener {
@EventHandler
public void playerDeathEvent(PlayerDeathEvent event) {
for (ItemStack i : event.getEntity().getInventory().getArmorContents()) {
if (!isAirOrNull(i)) {
Bukkit.getServer().getPluginManager().callEvent(new ArmorEquipEvent(event.getEntity(), EquipMethod.DEATH, ArmorType.matchType(i), i, null));
for (ItemStack item : event.getEntity().getInventory().getArmorContents()) {
if (!isAirOrNull(item)) {
Bukkit.getServer().getPluginManager().callEvent(new ArmorEquipEvent(event.getEntity(), ArmorEquipEvent.EquipMethod.DEATH, ArmorEquipEvent.ArmorType.matchType(item), item, null));
// No way to cancel a death event.
}
}

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.listeners;
package com.craftaro.epicenchants.listeners;
import com.songoda.core.nms.NmsManager;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.enums.TriggerType;
import com.craftaro.core.nms.Nms;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.enums.TriggerType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
@ -17,20 +17,7 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.projectiles.ProjectileSource;
import static com.songoda.epicenchants.enums.TriggerType.ATTACK_MOB_MELEE;
import static com.songoda.epicenchants.enums.TriggerType.ATTACK_MOB_RANGE;
import static com.songoda.epicenchants.enums.TriggerType.ATTACK_PLAYER_MELEE;
import static com.songoda.epicenchants.enums.TriggerType.ATTACK_PLAYER_RANGE;
import static com.songoda.epicenchants.enums.TriggerType.DEFENSE_MOB_MELEE;
import static com.songoda.epicenchants.enums.TriggerType.DEFENSE_MOB_RANGE;
import static com.songoda.epicenchants.enums.TriggerType.DEFENSE_PLAYER_MELEE;
import static com.songoda.epicenchants.enums.TriggerType.DEFENSE_PLAYER_RANGE;
import static com.songoda.epicenchants.enums.TriggerType.EXPLOSION_DAMAGE;
import static com.songoda.epicenchants.enums.TriggerType.FALL_DAMAGE;
import static com.songoda.epicenchants.enums.TriggerType.FIRE_DAMAGE;
import static com.songoda.epicenchants.enums.TriggerType.KILLED_MOB;
import static com.songoda.epicenchants.enums.TriggerType.LAVA_DAMAGE;
import static com.songoda.epicenchants.enums.TriggerType.POISON_DAMAGE;
import static com.craftaro.epicenchants.enums.TriggerType.*;
public class EntityListener implements Listener {
private final EpicEnchants instance;
@ -42,7 +29,7 @@ public class EntityListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof Monster && event.getEntity().getKiller() != null) {
instance.getEnchantUtils().handlePlayer(event.getEntity().getKiller(), event.getEntity(), event, KILLED_MOB);
this.instance.getEnchantUtils().handlePlayer(event.getEntity().getKiller(), event.getEntity(), event, KILLED_MOB);
}
}
@ -61,12 +48,12 @@ public class EntityListener implements Listener {
if (hitEntity instanceof Player) {
LivingEntity opponent = source instanceof LivingEntity ? ((LivingEntity) source) : null;
TriggerType type = source instanceof Player ? DEFENSE_PLAYER_RANGE : DEFENSE_MOB_RANGE;
instance.getEnchantUtils().handlePlayer(((Player) hitEntity), opponent, event, type);
this.instance.getEnchantUtils().handlePlayer(((Player) hitEntity), opponent, event, type);
}
if (source instanceof Player) {
TriggerType type = event.getEntity() instanceof Player ? ATTACK_PLAYER_RANGE : ATTACK_MOB_RANGE;
instance.getEnchantUtils().handlePlayer(((Player) source), hitEntity, event, type);
this.instance.getEnchantUtils().handlePlayer(((Player) source), hitEntity, event, type);
}
}
@ -85,7 +72,7 @@ public class EntityListener implements Listener {
}
if (triggerType != null) {
instance.getEnchantUtils().handlePlayer(defender, opponent, event, triggerType);
this.instance.getEnchantUtils().handlePlayer(defender, opponent, event, triggerType);
}
}
@ -101,7 +88,7 @@ public class EntityListener implements Listener {
}
if (triggerType != null) {
instance.getEnchantUtils().handlePlayer(attacker, ((LivingEntity) event.getEntity()), event, triggerType);
this.instance.getEnchantUtils().handlePlayer(attacker, ((LivingEntity) event.getEntity()), event, triggerType);
}
}
}
@ -113,31 +100,32 @@ public class EntityListener implements Listener {
}
switch (event.getCause()) {
case FALL:
instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, FALL_DAMAGE);
this.instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, FALL_DAMAGE);
break;
case FIRE:
case FIRE_TICK:
instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, FIRE_DAMAGE);
this.instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, FIRE_DAMAGE);
break;
case LAVA:
instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, LAVA_DAMAGE);
this.instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, LAVA_DAMAGE);
break;
case BLOCK_EXPLOSION:
case ENTITY_EXPLOSION:
instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, EXPLOSION_DAMAGE);
this.instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, EXPLOSION_DAMAGE);
break;
case POISON:
instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, POISON_DAMAGE);
this.instance.getEnchantUtils().handlePlayer(((Player) event.getEntity()), null, event, POISON_DAMAGE);
break;
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityTargetLivingEntity(EntityTargetLivingEntityEvent event) {
if (event.getTarget() == null)
if (event.getTarget() == null) {
return;
}
if (NmsManager.getNbt().of(event.getEntity()).has(event.getTarget().getUniqueId().toString())) {
if (Nms.getImplementations().getNbt().of(event.getEntity()).has(event.getTarget().getUniqueId().toString())) {
//TODO: Add team support.
event.setCancelled(true);
}

View File

@ -1,8 +1,7 @@
package com.songoda.epicenchants.listeners;
package com.craftaro.epicenchants.listeners;
import com.songoda.epicenchants.events.ArmorEquipEvent;
import com.songoda.epicenchants.events.HeldItemChangedEvent;
import com.songoda.epicenchants.events.HeldItemChangedEvent.EquipMethod;
import com.craftaro.epicenchants.events.ArmorEquipEvent;
import com.craftaro.epicenchants.events.HeldItemChangedEvent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -28,7 +27,6 @@ import java.util.OptionalInt;
import java.util.stream.IntStream;
public class HeldItemListener implements Listener {
private static final boolean SWAP_OFFHAND_SUPPORTED = Arrays.stream(ClickType.values()).anyMatch(e -> e.name().equals("SWAP_OFFHAND"));
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
@ -116,26 +114,26 @@ public class HeldItemListener implements Listener {
} else {
ItemStack newItem = e.getCursor();
ItemStack oldItem = e.getCurrentItem();
EquipMethod method;
HeldItemChangedEvent.EquipMethod method;
if (numberKey) {
if (!(e.getClickedInventory() instanceof PlayerInventory)
|| e.getHotbarButton() != heldslot) //we only care about heldslot
return;
method = EquipMethod.HOTBAR_SWAP;
method = HeldItemChangedEvent.EquipMethod.HOTBAR_SWAP;
newItem = e.getCurrentItem();
oldItem = e.getClickedInventory().getItem(e.getHotbarButton());
} else if (swapoffhand) {
if (!(e.getClickedInventory() instanceof PlayerInventory)
|| e.getSlot() != heldslot) //we only care about heldslot
return;
method = EquipMethod.OFFHAND_SWAP;
method = HeldItemChangedEvent.EquipMethod.OFFHAND_SWAP;
newItem = e.getClickedInventory().getItem(40);
oldItem = e.getCurrentItem();
} else {
if (!(e.getClickedInventory() instanceof PlayerInventory)
|| e.getSlot() != heldslot) //we only care about heldslot
return;
method = EquipMethod.PICK_DROP;
method = HeldItemChangedEvent.EquipMethod.PICK_DROP;
}
HeldItemChangedEvent heldItemChangedEvent = new HeldItemChangedEvent((Player) e.getWhoClicked(), method, oldItem, newItem);
Bukkit.getServer().getPluginManager().callEvent(heldItemChangedEvent);
@ -155,7 +153,7 @@ public class HeldItemListener implements Listener {
boolean bottominventory = rawslot != invslot;
if (bottominventory && event.getWhoClicked().getInventory().getHeldItemSlot() == invslot) {
HeldItemChangedEvent heldItemChangedEvent = new HeldItemChangedEvent((Player) event.getWhoClicked(), EquipMethod.DRAG, null, event.getOldCursor());
HeldItemChangedEvent heldItemChangedEvent = new HeldItemChangedEvent((Player) event.getWhoClicked(), HeldItemChangedEvent.EquipMethod.DRAG, null, event.getOldCursor());
Bukkit.getServer().getPluginManager().callEvent(heldItemChangedEvent);
if (heldItemChangedEvent.isCancelled()) {
event.setResult(Result.DENY);
@ -176,7 +174,7 @@ public class HeldItemListener implements Listener {
hotbarslot = inv.getHeldItemSlot();
if (hotbarslot != -1) {
HeldItemChangedEvent heldItemChangedEvent = new HeldItemChangedEvent(p, EquipMethod.BROKE, e.getBrokenItem(), null);
HeldItemChangedEvent heldItemChangedEvent = new HeldItemChangedEvent(p, HeldItemChangedEvent.EquipMethod.BROKE, e.getBrokenItem(), null);
Bukkit.getServer().getPluginManager().callEvent(heldItemChangedEvent);
if (heldItemChangedEvent.isCancelled()) {
ItemStack i = e.getBrokenItem().clone();
@ -190,8 +188,9 @@ public class HeldItemListener implements Listener {
@EventHandler
public void playerDeathEvent(PlayerDeathEvent event) {
ItemStack i = event.getEntity().getInventory().getItem(event.getEntity().getInventory().getHeldItemSlot());
if (!isAirOrNull(i))
Bukkit.getServer().getPluginManager().callEvent(new HeldItemChangedEvent(event.getEntity(), EquipMethod.DEATH, i, null));
if (!isAirOrNull(i)) {
Bukkit.getServer().getPluginManager().callEvent(new HeldItemChangedEvent(event.getEntity(), HeldItemChangedEvent.EquipMethod.DEATH, i, null));
}
// No way to cancel a death event.
}
@ -202,7 +201,7 @@ public class HeldItemListener implements Listener {
//we try to make a best efford solution
//when the item in the held slot is null we assume it was dropped by pressing Q
if (isAirOrNull(event.getPlayer().getInventory().getItem(event.getPlayer().getInventory().getHeldItemSlot())))
Bukkit.getServer().getPluginManager().callEvent(new HeldItemChangedEvent(event.getPlayer(), EquipMethod.DROP_ITEM, event.getItemDrop().getItemStack(), null));
Bukkit.getServer().getPluginManager().callEvent(new HeldItemChangedEvent(event.getPlayer(), HeldItemChangedEvent.EquipMethod.DROP_ITEM, event.getItemDrop().getItemStack(), null));
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
@ -211,7 +210,7 @@ public class HeldItemListener implements Listener {
int firstEmpty = event.getPlayer().getInventory().firstEmpty();
if (0 <= firstEmpty && firstEmpty <= 8
&& event.getPlayer().getInventory().getHeldItemSlot() == firstEmpty)
Bukkit.getServer().getPluginManager().callEvent(new HeldItemChangedEvent(event.getPlayer(), EquipMethod.PICKUP_ITEM, null, event.getItem().getItemStack()));
Bukkit.getServer().getPluginManager().callEvent(new HeldItemChangedEvent(event.getPlayer(), HeldItemChangedEvent.EquipMethod.PICKUP_ITEM, null, event.getItem().getItemStack()));
}
}

View File

@ -1,9 +1,9 @@
package com.songoda.epicenchants.listeners;
package com.craftaro.epicenchants.listeners;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.events.ArmorEquipEvent;
import com.songoda.epicenchants.events.HeldItemChangedEvent;
import com.songoda.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.events.ArmorEquipEvent;
import com.craftaro.epicenchants.events.HeldItemChangedEvent;
import com.craftaro.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.EpicEnchants;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -19,9 +19,9 @@ import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.Map;
import static com.songoda.epicenchants.enums.EventType.OFF;
import static com.songoda.epicenchants.enums.EventType.ON;
import static com.songoda.epicenchants.enums.TriggerType.*;
import static com.craftaro.epicenchants.enums.EventType.OFF;
import static com.craftaro.epicenchants.enums.EventType.ON;
import static com.craftaro.epicenchants.enums.TriggerType.*;
public class PlayerListener implements Listener {
private final EpicEnchants instance;
@ -32,8 +32,8 @@ public class PlayerListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onArmorEquip(ArmorEquipEvent event) {
Map<Enchant, Integer> oldArmorMap = instance.getEnchantUtils().getEnchants(event.getOldArmorPiece());
Map<Enchant, Integer> newArmorMap = instance.getEnchantUtils().getEnchants(event.getNewArmorPiece());
Map<Enchant, Integer> oldArmorMap = this.instance.getEnchantUtils().getEnchants(event.getOldArmorPiece());
Map<Enchant, Integer> newArmorMap = this.instance.getEnchantUtils().getEnchants(event.getNewArmorPiece());
oldArmorMap.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, STATIC_EFFECT, OFF));
newArmorMap.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, STATIC_EFFECT, ON));
@ -41,8 +41,8 @@ public class PlayerListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onHeldItemChanged(HeldItemChangedEvent event) {
Map<Enchant, Integer> oldItemMap = instance.getEnchantUtils().getEnchants(event.getOldItem());
Map<Enchant, Integer> newItemMap = instance.getEnchantUtils().getEnchants(event.getNewItem());
Map<Enchant, Integer> oldItemMap = this.instance.getEnchantUtils().getEnchants(event.getOldItem());
Map<Enchant, Integer> newItemMap = this.instance.getEnchantUtils().getEnchants(event.getNewItem());
oldItemMap.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, OFF));
newItemMap.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, ON));
@ -50,56 +50,64 @@ public class PlayerListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
instance.getEnchantUtils().getEnchants(event.getPlayer().getInventory().getItem(event.getPreviousSlot()))
this.instance.getEnchantUtils().getEnchants(event.getPlayer().getInventory().getItem(event.getPreviousSlot()))
.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, OFF));
instance.getEnchantUtils().getEnchants(event.getPlayer().getInventory().getItem(event.getNewSlot()))
this.instance.getEnchantUtils().getEnchants(event.getPlayer().getInventory().getItem(event.getNewSlot()))
.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, ON));
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerDeath(PlayerDeathEvent event) {
instance.getEnchantUtils().handlePlayer(event.getEntity(), event.getEntity().getKiller(), event, DEATH);
this.instance.getEnchantUtils().handlePlayer(event.getEntity(), event.getEntity().getKiller(), event, DEATH);
if (event.getEntity().getKiller() != null) {
instance.getEnchantUtils().handlePlayer(event.getEntity().getKiller(), event.getEntity(), event, KILLED_PLAYER);
this.instance.getEnchantUtils().handlePlayer(event.getEntity().getKiller(), event.getEntity(), event, KILLED_PLAYER);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_AIR) {
instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, RIGHT_CLICK);
this.instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, RIGHT_CLICK);
} else if (event.getAction() == Action.LEFT_CLICK_AIR) {
instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, LEFT_CLICK);
this.instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, LEFT_CLICK);
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, RIGHT_CLICK_BLOCK);
this.instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, RIGHT_CLICK_BLOCK);
} else if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, LEFT_CLICK_BLOCK);
this.instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, LEFT_CLICK_BLOCK);
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event) {
instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, BLOCK_BREAK);
if (event.getExpToDrop() != 0)
instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, EXPERIENCE_BLOCK_BREAK);
this.instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, BLOCK_BREAK);
if (event.getExpToDrop() != 0) {
this.instance.getEnchantUtils().handlePlayer(event.getPlayer(), null, event, EXPERIENCE_BLOCK_BREAK);
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerJoin(PlayerJoinEvent event) {
event.getPlayer().getActivePotionEffects().stream().filter(potion -> potion.getDuration() >= 32760)
event.getPlayer()
.getActivePotionEffects()
.stream()
.filter(potion -> potion.getDuration() >= 32760)
.forEach(potionEffect -> event.getPlayer().removePotionEffect(potionEffect.getType()));
Arrays.stream(event.getPlayer().getInventory().getArmorContents()).forEach(itemStack -> {
instance.getEnchantUtils().getEnchants(itemStack).forEach((enchant, level)
-> enchant.onAction(event.getPlayer(), null, event, level, STATIC_EFFECT, ON));
});
ItemStack mainhand = event.getPlayer().getInventory().getItem(event.getPlayer().getInventory().getHeldItemSlot());
if (isItem(mainhand))
instance.getEnchantUtils().getEnchants(mainhand).forEach((enchant, level)
-> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, ON));
Arrays.stream(event.getPlayer().getInventory().getArmorContents())
.forEach(itemStack -> this.instance
.getEnchantUtils()
.getEnchants(itemStack)
.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, STATIC_EFFECT, ON)));
ItemStack mainHand = event.getPlayer().getInventory().getItem(event.getPlayer().getInventory().getHeldItemSlot());
if (isItem(mainHand)) {
this.instance
.getEnchantUtils()
.getEnchants(mainHand)
.forEach((enchant, level) -> enchant.onAction(event.getPlayer(), null, event, level, HELD_ITEM, ON));
}
}
private boolean isItem(ItemStack is) {

View File

@ -1,14 +1,14 @@
package com.songoda.epicenchants.listeners.item;
package com.craftaro.epicenchants.listeners.item;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTCompound;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.utils.single.RomanNumber;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTCompound;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.utils.single.RomanNumber;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import static com.songoda.epicenchants.utils.single.GeneralUtils.getRandomElement;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.getRandomElement;
public class BlackScrollListener extends ItemListener {
public BlackScrollListener(EpicEnchants instance) {
@ -17,7 +17,7 @@ public class BlackScrollListener extends ItemListener {
@Override
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
if (!cursor.hasKey("black-scroll") || !cursor.getBoolean("black-scroll")) {
if (!cursor.hasTag("black-scroll") || !cursor.getBoolean("black-scroll")) {
return;
}
@ -25,20 +25,20 @@ public class BlackScrollListener extends ItemListener {
NBTCompound compound = current.getCompound("enchants");
if (compound == null || compound.getKeys().isEmpty()) {
instance.getLocale().getMessage("blackscroll.noenchants")
this.instance.getLocale().getMessage("blackscroll.noenchants")
.sendPrefixedMessage(event.getWhoClicked());
return;
}
String id = getRandomElement(compound.getKeys());
int level = compound.getInteger(id);
Enchant enchant = instance.getEnchantManager().getValueUnsafe(id);
ItemStack toSet = instance.getEnchantUtils().removeEnchant(event.getCurrentItem(), enchant);
Enchant enchant = this.instance.getEnchantManager().getValueUnsafe(id);
ItemStack toSet = this.instance.getEnchantUtils().removeEnchant(event.getCurrentItem(), enchant);
event.getWhoClicked().getInventory().addItem(enchant.getBook().get(enchant, level, cursor.getInteger("success-rate"), 100));
event.setCurrentItem(toSet);
instance.getLocale().getMessage("blackscroll.success")
this.instance.getLocale().getMessage("blackscroll.success")
.processPlaceholder("enchant", enchant.getIdentifier())
.processPlaceholder("group_color", enchant.getGroup().getColor())
.processPlaceholder("group_name", enchant.getGroup().getName())

View File

@ -1,14 +1,14 @@
package com.songoda.epicenchants.listeners.item;
package com.craftaro.epicenchants.listeners.item;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.enums.EnchantResult;
import com.songoda.epicenchants.events.EnchantApplyEvent;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.objects.Group;
import com.songoda.epicenchants.utils.Tuple;
import com.songoda.epicenchants.utils.single.GeneralUtils;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.epicenchants.events.EnchantApplyEvent;
import com.craftaro.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.enums.EnchantResult;
import com.craftaro.epicenchants.utils.Tuple;
import com.craftaro.epicenchants.utils.single.GeneralUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
@ -17,10 +17,10 @@ import org.bukkit.inventory.ItemStack;
import java.util.Optional;
import static com.songoda.epicenchants.enums.EnchantResult.ALREADY_APPLIED;
import static com.songoda.epicenchants.enums.EnchantResult.BROKEN_FAILURE;
import static com.songoda.epicenchants.enums.EnchantResult.CONFLICT;
import static com.songoda.epicenchants.enums.EnchantResult.MAXED_OUT;
import static com.craftaro.epicenchants.enums.EnchantResult.ALREADY_APPLIED;
import static com.craftaro.epicenchants.enums.EnchantResult.BROKEN_FAILURE;
import static com.craftaro.epicenchants.enums.EnchantResult.CONFLICT;
import static com.craftaro.epicenchants.enums.EnchantResult.MAXED_OUT;
import static java.util.concurrent.ThreadLocalRandom.current;
public class BookListener extends ItemListener {
@ -30,26 +30,26 @@ public class BookListener extends ItemListener {
@Override
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
if (!cursor.hasKey("book-item") || !cursor.getBoolean("book-item")) {
if (!cursor.hasTag("book-item") || !cursor.getBoolean("book-item")) {
return;
}
event.setCancelled(true);
ItemStack toApply = event.getCurrentItem();
Enchant enchant = instance.getEnchantManager().getValue(cursor.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
Enchant enchant = this.instance.getEnchantManager().getValue(cursor.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
if (!enchant.getItemWhitelist().contains(CompatibleMaterial.getMaterial(current.getItem()))) {
if (!enchant.getItemWhitelist().contains(XMaterial.matchXMaterial(current.getItem().getType()))) {
return;
}
// get total amount of enchantments on item
int currentEnchantmentTotal = instance.getEnchantUtils().getEnchants(toApply).size();
int maxAllowedOverride = instance.getEnchantUtils().getMaximumEnchantsCanApply((Player) event.getWhoClicked());
int maxAllowedApply = instance.getEnchantUtils().getMaximumEnchantsCanApplyItem(toApply, (Player) event.getWhoClicked());
int currentEnchantmentTotal = this.instance.getEnchantUtils().getEnchants(toApply).size();
int maxAllowedOverride = this.instance.getEnchantUtils().getMaximumEnchantsCanApply((Player) event.getWhoClicked());
int maxAllowedApply = this.instance.getEnchantUtils().getMaximumEnchantsCanApplyItem(toApply, (Player) event.getWhoClicked());
maxAllowedApply = Math.min(maxAllowedApply, maxAllowedOverride);
// item is at max enchantments
if (currentEnchantmentTotal >= maxAllowedApply) {
instance.getLocale().getMessage("enchants.maxallowed").processPlaceholder("max_enchants", maxAllowedApply).sendPrefixedMessage(event.getWhoClicked());
this.instance.getLocale().getMessage("enchants.maxallowed").processPlaceholder("max_enchants", maxAllowedApply).sendPrefixedMessage(event.getWhoClicked());
return;
}
@ -64,9 +64,9 @@ public class BookListener extends ItemListener {
return;
}
Tuple<ItemStack, EnchantResult> result = instance.getEnchantUtils().apply(toApply, enchant, enchantEvent.getLevel(), enchantEvent.getSuccessRate(), enchantEvent.getDestroyRate());
Tuple<ItemStack, EnchantResult> result = this.instance.getEnchantUtils().apply(toApply, enchant, enchantEvent.getLevel(), enchantEvent.getSuccessRate(), enchantEvent.getDestroyRate());
instance.getLocale().getMessage(GeneralUtils.getMessageFromResult(result.getRight()))
this.instance.getLocale().getMessage(GeneralUtils.getMessageFromResult(result.getRight()))
.processPlaceholder("enchant", enchant.getIdentifier())
.sendPrefixedMessage(event.getWhoClicked());
@ -83,7 +83,7 @@ public class BookListener extends ItemListener {
@Override
void onClick(PlayerInteractEvent event, NBTItem clicked) {
if (!clicked.hasKey("mystery-book") || !clicked.getBoolean("mystery-book")) {
if (!clicked.hasTag("mystery-book") || !clicked.getBoolean("mystery-book")) {
return;
}
@ -93,9 +93,9 @@ public class BookListener extends ItemListener {
return;
}
Group group = instance.getGroupManager().getValue(clicked.getString("group")).orElseThrow(() -> new IllegalStateException("Book without group!"));
Group group = this.instance.getGroupManager().getValue(clicked.getString("group")).orElseThrow(() -> new IllegalStateException("Book without group!"));
Optional<Enchant> enchant = instance.getEnchantManager().getRandomEnchant(group);
Optional<Enchant> enchant = this.instance.getEnchantManager().getRandomEnchant(group);
if (!enchant.isPresent()) {
throw new IllegalStateException("The " + group.getName() + " group does not have any enchants.");
@ -106,7 +106,7 @@ public class BookListener extends ItemListener {
useItem(event);
event.getPlayer().getInventory().addItem(enchant.get().getBook().get(enchant.get(), level));
event.getPlayer().sendMessage(instance.getLocale().getMessage("book.discover")
event.getPlayer().sendMessage(this.instance.getLocale().getMessage("book.discover")
.processPlaceholder("group_name", group.getName())
.processPlaceholder("group_color", group.getColor())
.processPlaceholder("enchant_format", enchant.get().getFormat())

View File

@ -1,9 +1,9 @@
package com.songoda.epicenchants.listeners.item;
package com.craftaro.epicenchants.listeners.item;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.objects.Group;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.EpicEnchants;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
@ -16,17 +16,17 @@ public class DustListener extends ItemListener {
@Override
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
if (!cursor.hasKey("dust") || !cursor.getBoolean("dust")) {
if (!cursor.hasTag("dust") || !cursor.getBoolean("dust")) {
return;
}
if (!current.hasKey("book-item") || !current.getBoolean("book-item")) {
if (!current.hasTag("book-item") || !current.getBoolean("book-item")) {
return;
}
Enchant enchant = instance.getEnchantManager().getValue(current.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
Enchant enchant = this.instance.getEnchantManager().getValue(current.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
if (!enchant.getGroup().equals(instance.getGroupManager().getValue(cursor.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!")))) {
if (!enchant.getGroup().equals(this.instance.getGroupManager().getValue(cursor.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!")))) {
return;
}
@ -45,7 +45,7 @@ public class DustListener extends ItemListener {
@Override
void onClick(PlayerInteractEvent event, NBTItem clicked) {
if (!clicked.hasKey("secret-dust") || !clicked.getBoolean("secret-dust")) {
if (!clicked.hasTag("secret-dust") || !clicked.getBoolean("secret-dust")) {
return;
}
@ -55,10 +55,10 @@ public class DustListener extends ItemListener {
return;
}
Group group = instance.getGroupManager().getValueUnsafe(clicked.getString("group"));
Group group = this.instance.getGroupManager().getValueUnsafe(clicked.getString("group"));
int rate = ThreadLocalRandom.current().nextInt(clicked.getInteger("min-rate"), clicked.getInteger("max-rate"));
useItem(event);
event.getPlayer().getInventory().addItem(instance.getSpecialItems().getDust(group, null, rate, false));
event.getPlayer().getInventory().addItem(this.instance.getSpecialItems().getDust(group, null, rate, false));
}
}

View File

@ -1,7 +1,8 @@
package com.songoda.epicenchants.listeners.item;
package com.craftaro.epicenchants.listeners.item;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.craftaro.core.compatibility.CompatibleHand;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.epicenchants.EpicEnchants;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -10,7 +11,6 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
public abstract class ItemListener implements Listener {
@ -61,9 +61,8 @@ public abstract class ItemListener implements Listener {
void useItem(PlayerInteractEvent event) {
int slot = event.getPlayer().getInventory().getHeldItemSlot();
try {
if (event.getHand() == EquipmentSlot.OFF_HAND) slot = 40;
} catch (Exception | Error ignore) {
if (CompatibleHand.getHand(event) == CompatibleHand.OFF_HAND) {
slot = 40;
}
if (event.getItem().getAmount() > 1) {

View File

@ -0,0 +1,41 @@
package com.craftaro.epicenchants.listeners.item;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
public class WhiteScrollListener extends ItemListener {
public WhiteScrollListener(EpicEnchants instance) {
super(instance);
}
@Override
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
if (!cursor.hasTag("white-scroll") || !cursor.getBoolean("white-scroll")) {
return;
}
event.setCancelled(true);
if (current.hasTag("protected")) {
this.instance.getLocale().getMessage("whitescroll.alreadyapplied")
.sendPrefixedMessage(event.getWhoClicked());
return;
}
if (!this.instance.getItemGroup().isValid(XMaterial.matchXMaterial(event.getCurrentItem().getType()))) {
return;
}
current.setBoolean("protected", true);
this.instance.getLocale().getMessage("whitescrollapplied").sendPrefixedMessage(event.getWhoClicked());
ItemStack toSet = new ItemBuilder(current.getItem()).addLore(this.instance.getSpecialItems().getWhiteScrollLore()).build();
event.getClickedInventory().setItem(event.getSlot(), toSet);
useItem(event);
}
}

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.managers;
package com.craftaro.epicenchants.managers;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.objects.Group;
import com.craftaro.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.EpicEnchants;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
@ -12,10 +12,9 @@ import java.util.Collections;
import java.util.Optional;
import java.util.stream.Collectors;
import static com.songoda.epicenchants.utils.single.ConfigParser.parseEnchant;
import static com.craftaro.epicenchants.utils.single.ConfigParser.parseEnchant;
public class EnchantManager extends Manager<String, Enchant> {
public EnchantManager(EpicEnchants instance) {
super(instance);
}
@ -30,7 +29,7 @@ public class EnchantManager extends Manager<String, Enchant> {
}
public void loadEnchants() {
instance.getFileManager().getYmlFiles("enchants").forEach(file -> {
this.instance.getFileManager().getYmlFiles("enchants").forEach(file -> {
try {
loadEnchant(file);
} catch (Exception e) {
@ -41,10 +40,8 @@ public class EnchantManager extends Manager<String, Enchant> {
});
}
public void loadEnchant(File file) throws Exception {
Enchant enchant = parseEnchant(instance, YamlConfiguration.loadConfiguration(file));
public void loadEnchant(File file) {
Enchant enchant = parseEnchant(this.instance, YamlConfiguration.loadConfiguration(file));
add(enchant.getIdentifier(), enchant);
}
}

View File

@ -1,9 +1,9 @@
package com.songoda.epicenchants.managers;
package com.craftaro.epicenchants.managers;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.utils.objects.FileLocation;
import com.songoda.epicenchants.utils.settings.Settings;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.utils.objects.FileLocation;
import com.craftaro.epicenchants.utils.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
@ -20,12 +20,11 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import static com.songoda.epicenchants.utils.objects.FileLocation.of;
import static com.craftaro.epicenchants.utils.objects.FileLocation.of;
import static java.io.File.separator;
import static java.util.Arrays.asList;
public class FileManager extends Manager<String, FileConfiguration> {
private final String directory;
private final LinkedHashSet<FileLocation> files = new LinkedHashSet<>(asList(
of("menus/main-info-menu.yml", true, true),
@ -89,13 +88,13 @@ public class FileManager extends Manager<String, FileConfiguration> {
public FileManager(EpicEnchants instance) {
super(instance);
directory = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? "master" : "legacy";
Bukkit.getConsoleSender().sendMessage("Using the " + directory + " configurations because version is " + ServerVersion.getServerVersion().name());
this.directory = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? "master" : "legacy";
Bukkit.getConsoleSender().sendMessage("Using the " + this.directory + " configurations because version is " + ServerVersion.getServerVersion().name());
}
public void loadFiles() {
files.forEach(fileLocation -> {
File file = new File(instance.getDataFolder() + separator + fileLocation.getPath());
this.files.forEach(fileLocation -> {
File file = new File(this.instance.getDataFolder() + separator + fileLocation.getPath());
if (!file.exists() && (fileLocation.isRequired() || Settings.FIRST_LOAD.getBoolean())) {
Bukkit.getConsoleSender().sendMessage("Creating file: " + fileLocation.getPath());
@ -103,7 +102,7 @@ public class FileManager extends Manager<String, FileConfiguration> {
try {
// System.out.println(fileLocation.getResourcePath(directory) + " : " + file.toPath());
copy(instance.getResource(fileLocation.getResourcePath(directory)), Files.newOutputStream(file.toPath()));
copy(this.instance.getResource(fileLocation.getResourcePath(this.directory)), Files.newOutputStream(file.toPath()));
} catch (IOException e) {
e.printStackTrace();
}
@ -120,8 +119,8 @@ public class FileManager extends Manager<String, FileConfiguration> {
}
});
instance.getConfig().set("System.First Load", false);
instance.saveConfig();
this.instance.getConfig().set("System.First Load", false);
this.instance.saveConfig();
}
public FileConfiguration getConfiguration(String key) {
@ -129,7 +128,7 @@ public class FileManager extends Manager<String, FileConfiguration> {
}
public List<File> getYmlFiles(String directory) {
File dir = new File(instance.getDataFolder() + separator + directory + separator);
File dir = new File(this.instance.getDataFolder() + separator + directory + separator);
File[] allFiles = dir.listFiles();
List<File> output = new ArrayList<>();
@ -143,8 +142,8 @@ public class FileManager extends Manager<String, FileConfiguration> {
Arrays.stream(allFiles)
.filter(File::isDirectory)
.filter(s -> !s.getName().equalsIgnoreCase("old"))
.forEach(f -> output.addAll(getYmlFiles(directory + separator + f.getName())));
.filter(file -> !file.getName().equalsIgnoreCase("old"))
.forEach(file -> output.addAll(getYmlFiles(directory + separator + file.getName())));
return output;
}

View File

@ -0,0 +1,20 @@
package com.craftaro.epicenchants.managers;
import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.utils.single.ConfigParser;
import org.bukkit.configuration.ConfigurationSection;
public class GroupManager extends Manager<String, Group> {
public GroupManager(EpicEnchants instance) {
super(instance);
}
public void loadGroups() {
ConfigurationSection config = this.instance.getFileManager().getConfiguration("groups").getConfigurationSection("groups");
config.getKeys(false).forEach(key -> {
Group group = ConfigParser.parseGroup(this.instance, config.getConfigurationSection(key));
add(group.getIdentifier().toUpperCase(), group);
});
}
}

View File

@ -1,9 +1,9 @@
package com.songoda.epicenchants.managers;
package com.craftaro.epicenchants.managers;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.menus.InfoMenu;
import com.songoda.epicenchants.menus.MainInfoMenu;
import com.songoda.epicenchants.objects.Group;
import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.menus.InfoMenu;
import com.craftaro.epicenchants.menus.MainInfoMenu;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
@ -23,12 +23,15 @@ public class InfoManager extends Manager<Group, InfoMenu> {
}
public void loadMenus() {
mainInfoMenu = new MainInfoMenu(instance, instance.getFileManager().getConfiguration("menus/main-info-menu"));
instance.getFileManager().getYmlFiles("menus/groups").forEach(file -> {
this.mainInfoMenu = new MainInfoMenu(this.instance, this.instance.getFileManager().getConfiguration("menus/main-info-menu"));
this.instance.getFileManager().getYmlFiles("menus/groups").forEach(file -> {
try {
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
add(instance.getGroupManager().getValue(config.getString("group"))
.orElseThrow(() -> new IllegalArgumentException("Invalid group: " + config.getString("group"))), new InfoMenu(instance, config));
add(this.instance
.getGroupManager()
.getValue(config.getString("group"))
.orElseThrow(() -> new IllegalArgumentException("Invalid group: " + config.getString("group"))),
new InfoMenu(this.instance, config));
} catch (Exception e) {
Bukkit.getConsoleSender().sendMessage("Something went wrong loading the menu from file " + file.getName());
Bukkit.getConsoleSender().sendMessage("Please check to make sure there are no errors in the file.");

View File

@ -1,6 +1,6 @@
package com.songoda.epicenchants.managers;
package com.craftaro.epicenchants.managers;
import com.songoda.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.EpicEnchants;
import java.util.Collection;
import java.util.Collections;
@ -9,7 +9,6 @@ import java.util.Map;
import java.util.Optional;
public abstract class Manager<K, V> {
final EpicEnchants instance;
private final Map<K, V> map;
@ -19,15 +18,16 @@ public abstract class Manager<K, V> {
}
public Optional<V> getValue(K key) {
for (Object k : map.keySet()) {
if (k.toString().equalsIgnoreCase(key.toString()))
return Optional.ofNullable(map.get(k));
for (Object k : this.map.keySet()) {
if (k.toString().equalsIgnoreCase(key.toString())) {
return Optional.ofNullable(this.map.get(k));
}
}
return Optional.empty();
}
public void add(K key, V value) {
map.put(key, value);
this.map.put(key, value);
}
public V getValueUnsafe(K key) {
@ -35,14 +35,14 @@ public abstract class Manager<K, V> {
}
public Collection<V> getValues() {
return Collections.unmodifiableCollection(map.values());
return Collections.unmodifiableCollection(this.map.values());
}
public Collection<K> getKeys() {
return Collections.unmodifiableCollection(map.keySet());
return Collections.unmodifiableCollection(this.map.keySet());
}
public void clear() {
map.clear();
this.map.clear();
}
}

View File

@ -1,14 +1,14 @@
package com.songoda.epicenchants.menus;
package com.craftaro.epicenchants.menus;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.objects.Group;
import com.songoda.epicenchants.objects.Placeholder;
import com.songoda.epicenchants.utils.objects.FastInv;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import com.songoda.epicenchants.utils.single.GeneralUtils;
import com.craftaro.core.hooks.EconomyManager;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.objects.Placeholder;
import com.craftaro.epicenchants.utils.objects.FastInv;
import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import com.craftaro.epicenchants.utils.single.GeneralUtils;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@ -18,11 +18,10 @@ import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.Set;
import static com.songoda.epicenchants.objects.Placeholder.of;
import static com.songoda.epicenchants.utils.single.Experience.changeExp;
import static com.songoda.epicenchants.utils.single.Experience.getExp;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
import static com.songoda.epicenchants.utils.single.GeneralUtils.getSlots;
import static com.craftaro.epicenchants.utils.single.Experience.changeExp;
import static com.craftaro.epicenchants.utils.single.Experience.getExp;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.color;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.getSlots;
public class AlchemistMenu extends FastInv {
private final EpicEnchants instance;
@ -36,13 +35,13 @@ public class AlchemistMenu extends FastInv {
this.instance = instance;
this.config = config;
LEFT_SLOT = config.getInt("left-slot");
RIGHT_SLOT = config.getInt("right-slot");
PREVIEW_SLOT = config.getInt("preview-slot");
ACCEPT_SLOT = config.getInt("accept-slot");
this.LEFT_SLOT = config.getInt("left-slot");
this.RIGHT_SLOT = config.getInt("right-slot");
this.PREVIEW_SLOT = config.getInt("preview-slot");
this.ACCEPT_SLOT = config.getInt("accept-slot");
PREVIEW_ITEM = new ItemBuilder(config.getConfigurationSection("contents.preview")).build();
ACCEPT_ITEM = new ItemBuilder(config.getConfigurationSection("contents.accept-before")).build();
this.PREVIEW_ITEM = new ItemBuilder(config.getConfigurationSection("contents.preview")).build();
this.ACCEPT_ITEM = new ItemBuilder(config.getConfigurationSection("contents.accept-before")).build();
if (config.isConfigurationSection("fill")) {
fill(new ItemBuilder(config.getConfigurationSection("fill")).build());
@ -61,8 +60,8 @@ public class AlchemistMenu extends FastInv {
.map(config::getConfigurationSection)
.forEach(section -> addItem(getSlots(section.getString("slot")), new ItemBuilder(section).build()));
clear(RIGHT_SLOT);
clear(LEFT_SLOT);
clear(this.RIGHT_SLOT);
clear(this.LEFT_SLOT);
updateSlots();
@ -74,7 +73,7 @@ public class AlchemistMenu extends FastInv {
int slot = event.getSlot();
if (slot != RIGHT_SLOT && slot != LEFT_SLOT) {
if (slot != this.RIGHT_SLOT && slot != this.LEFT_SLOT) {
return;
}
@ -107,10 +106,10 @@ public class AlchemistMenu extends FastInv {
// Player closed inventory
onClose(event -> {
if (getInventory().getItem(RIGHT_SLOT) != null)
event.getPlayer().getInventory().addItem(getInventory().getItem(RIGHT_SLOT));
if (getInventory().getItem(LEFT_SLOT) != null)
event.getPlayer().getInventory().addItem(getInventory().getItem(LEFT_SLOT));
if (getInventory().getItem(this.RIGHT_SLOT) != null)
event.getPlayer().getInventory().addItem(getInventory().getItem(this.RIGHT_SLOT));
if (getInventory().getItem(this.LEFT_SLOT) != null)
event.getPlayer().getInventory().addItem(getInventory().getItem(this.LEFT_SLOT));
});
}
@ -124,65 +123,65 @@ public class AlchemistMenu extends FastInv {
NBTItem nbtItem = new NBTItem(toHandle);
if (!nbtItem.hasKey("book-item") && !nbtItem.hasKey("dust")) {
instance.getLocale().getMessage("alchemist.notinterested").sendPrefixedMessage(player);
if (!nbtItem.hasTag("book-item") && !nbtItem.hasTag("dust")) {
this.instance.getLocale().getMessage("alchemist.notinterested").sendPrefixedMessage(player);
return false;
}
// Both slots occupied
if (getInventory().getItem(LEFT_SLOT) != null && getInventory().getItem(RIGHT_SLOT) != null) {
instance.getLocale().getMessage("alchemist.maxtwoitems").sendPrefixedMessage(player);
if (getInventory().getItem(this.LEFT_SLOT) != null && getInventory().getItem(this.RIGHT_SLOT) != null) {
this.instance.getLocale().getMessage("alchemist.maxtwoitems").sendPrefixedMessage(player);
return false;
}
int successRate = nbtItem.getInteger("success-rate");
// Both slots empty
if (getInventory().getItem(LEFT_SLOT) == null && getInventory().getItem(RIGHT_SLOT) == null) {
if (nbtItem.hasKey("book-item")) {
Enchant enchant = instance.getEnchantManager().getValue(nbtItem.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
if (getInventory().getItem(this.LEFT_SLOT) == null && getInventory().getItem(this.RIGHT_SLOT) == null) {
if (nbtItem.hasTag("book-item")) {
Enchant enchant = this.instance.getEnchantManager().getValue(nbtItem.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
int level = nbtItem.getInteger("level");
if (enchant.getMaxLevel() == level) {
instance.getLocale().getMessage("alchemist.maxlevelbook")
this.instance.getLocale().getMessage("alchemist.maxlevelbook")
.sendPrefixedMessage(player);
return false;
}
} else {
Group group = instance.getGroupManager().getValue(nbtItem.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!"));
Group group = this.instance.getGroupManager().getValue(nbtItem.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!"));
if (group.getOrder() == instance.getGroupManager().getValues().stream().mapToInt(Group::getOrder).max().orElse(0) || successRate == 100) {
instance.getLocale().getMessage("alchemist." + (successRate == 100 ? "maxpercentagedust" : "highestgroupdust"))
if (group.getOrder() == this.instance.getGroupManager().getValues().stream().mapToInt(Group::getOrder).max().orElse(0) || successRate == 100) {
this.instance.getLocale().getMessage("alchemist." + (successRate == 100 ? "maxpercentagedust" : "highestgroupdust"))
.sendPrefixedMessage(player);
return false;
}
}
getInventory().setItem(LEFT_SLOT, toHandle);
getInventory().setItem(this.LEFT_SLOT, toHandle);
return true;
}
NBTItem other = new NBTItem(getInventory().getItem(getInventory().getItem(LEFT_SLOT) == null ? RIGHT_SLOT : LEFT_SLOT));
int emptySlot = getInventory().getItem(LEFT_SLOT) == null ? LEFT_SLOT : RIGHT_SLOT;
NBTItem other = new NBTItem(getInventory().getItem(getInventory().getItem(this.LEFT_SLOT) == null ? this.RIGHT_SLOT : this.LEFT_SLOT));
int emptySlot = getInventory().getItem(this.LEFT_SLOT) == null ? this.LEFT_SLOT : this.RIGHT_SLOT;
if (other.hasKey("book-item")) {
if (other.hasTag("book-item")) {
if (!nbtItem.getString("enchant").equals(other.getString("enchant"))) {
instance.getLocale().getMessage("alchemist.differentenchantment").sendPrefixedMessage(player);
this.instance.getLocale().getMessage("alchemist.differentenchantment").sendPrefixedMessage(player);
return false;
}
if (nbtItem.getInteger("level") != other.getInteger("level")) {
instance.getLocale().getMessage("alchemist.differentlevels").sendPrefixedMessage(player);
this.instance.getLocale().getMessage("alchemist.differentlevels").sendPrefixedMessage(player);
return false;
}
} else {
if (!nbtItem.getString("group").equals(other.getString("group"))) {
instance.getLocale().getMessage("alchemist.differentgroups").sendPrefixedMessage(player);
this.instance.getLocale().getMessage("alchemist.differentgroups").sendPrefixedMessage(player);
return false;
}
if (successRate >= 100) {
instance.getLocale().getMessage("alchemist.maxpercentagedust").sendPrefixedMessage(player);
this.instance.getLocale().getMessage("alchemist.maxpercentagedust").sendPrefixedMessage(player);
return false;
}
}
@ -193,100 +192,103 @@ public class AlchemistMenu extends FastInv {
}
private void updateSlots() {
if (getInventory().getItem(LEFT_SLOT) == null || getInventory().getItem(RIGHT_SLOT) == null) {
addItem(ACCEPT_SLOT, ACCEPT_ITEM);
addItem(PREVIEW_SLOT, PREVIEW_ITEM);
if (getInventory().getItem(this.LEFT_SLOT) == null || getInventory().getItem(this.RIGHT_SLOT) == null) {
addItem(this.ACCEPT_SLOT, this.ACCEPT_ITEM);
addItem(this.PREVIEW_SLOT, this.PREVIEW_ITEM);
return;
}
NBTItem leftItem = new NBTItem(getInventory().getItem(LEFT_SLOT));
NBTItem rightItem = new NBTItem(getInventory().getItem(RIGHT_SLOT));
NBTItem leftItem = new NBTItem(getInventory().getItem(this.LEFT_SLOT));
NBTItem rightItem = new NBTItem(getInventory().getItem(this.RIGHT_SLOT));
int ecoCost;
int expCost;
if (leftItem.hasKey("book-item")) {
if (leftItem.hasTag("book-item")) {
int level = leftItem.getInteger("level");
Enchant enchant = instance.getEnchantManager().getValue(leftItem.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
Enchant enchant = this.instance.getEnchantManager().getValue(leftItem.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
int leftSuccess = leftItem.getInteger("success-rate");
int rightSuccess = rightItem.getInteger("success-rate");
int leftDestroy = leftItem.getInteger("destroy-rate");
int rightDestroy = rightItem.getInteger("destroy-rate");
Placeholder[] placeholders = new Placeholder[] {
of("left_success_rate", leftSuccess),
of("right_success_rate", rightSuccess),
of("left_destroy_rate", leftDestroy),
of("right_destroy_rate", rightDestroy),
of("max_destroy_rate", Math.max(leftDestroy, rightDestroy)),
of("min_destroy_rate", Math.min(leftDestroy, rightDestroy)),
of("max_success_rate", Math.max(leftSuccess, rightSuccess)),
of("min_success_rate", Math.min(leftSuccess, rightSuccess))
Placeholder.of("left_success_rate", leftSuccess),
Placeholder.of("right_success_rate", rightSuccess),
Placeholder.of("left_destroy_rate", leftDestroy),
Placeholder.of("right_destroy_rate", rightDestroy),
Placeholder.of("max_destroy_rate", Math.max(leftDestroy, rightDestroy)),
Placeholder.of("min_destroy_rate", Math.min(leftDestroy, rightDestroy)),
Placeholder.of("max_success_rate", Math.max(leftSuccess, rightSuccess)),
Placeholder.of("min_success_rate", Math.min(leftSuccess, rightSuccess))
};
int successRate = getFromFormula("book.success-rate-formula", placeholders);
int destroyRate = getFromFormula("book.destroy-rate-formula", placeholders);
Placeholder[] costPlaceholders = new Placeholder[] {
of("group_order_index", enchant.getGroup().getOrder()),
of("final_success_rate", successRate),
of("final_destroy_rate", destroyRate),
Placeholder.of("group_order_index", enchant.getGroup().getOrder()),
Placeholder.of("final_success_rate", successRate),
Placeholder.of("final_destroy_rate", destroyRate),
};
ecoCost = getFromFormula("book.eco-cost-formula", costPlaceholders);
expCost = getFromFormula("book.exp-cost-formula", costPlaceholders);
getInventory().setItem(PREVIEW_SLOT, enchant.getBook().get(enchant, level + 1, successRate, destroyRate));
getInventory().setItem(this.PREVIEW_SLOT, enchant.getBook().get(enchant, level + 1, successRate, destroyRate));
} else {
Group group = instance.getGroupManager().getValue(leftItem.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!"));
Group group = this.instance.getGroupManager().getValue(leftItem.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!"));
Placeholder[] placeholders = new Placeholder[] {
of("left_percentage", leftItem.getInteger("percentage")),
of("right_percentage", rightItem.getInteger("percentage"))
Placeholder.of("left_percentage", leftItem.getInteger("percentage")),
Placeholder.of("right_percentage", rightItem.getInteger("percentage"))
};
int successRate = getFromFormula("dust.percentage-formula", placeholders);
Placeholder[] costPlaceholders = new Placeholder[] {
of("group_order_index", group.getOrder()),
of("final_success_rate", successRate),
Placeholder.of("group_order_index", group.getOrder()),
Placeholder.of("final_success_rate", successRate),
};
ecoCost = getFromFormula("dust.eco-cost-formula", costPlaceholders);
expCost = getFromFormula("dust.exp-cost-formula", costPlaceholders);
Group newGroup = instance.getGroupManager().getValues().stream()
Group newGroup = this.instance
.getGroupManager()
.getValues()
.stream()
.filter(s -> s.getOrder() == group.getOrder() + 1)
.findFirst()
.orElseThrow(() -> new IllegalStateException("No group higher than: " + group.getIdentifier()));
getInventory().setItem(PREVIEW_SLOT, instance.getSpecialItems().getDust(newGroup, "magic", successRate, true));
getInventory().setItem(this.PREVIEW_SLOT, this.instance.getSpecialItems().getDust(newGroup, "magic", successRate, true));
}
addItem(ACCEPT_SLOT, new ItemBuilder(config.getConfigurationSection("contents.accept-after"),
of("eco_cost", ecoCost),
of("exp_cost", expCost)
addItem(this.ACCEPT_SLOT, new ItemBuilder(this.config.getConfigurationSection("contents.accept-after"),
Placeholder.of("eco_cost", ecoCost),
Placeholder.of("exp_cost", expCost)
).build(), event -> {
if (!EconomyManager.hasBalance(event.getPlayer(), ecoCost) || getExp(event.getPlayer()) < expCost) {
instance.getLocale().getMessage("alchemist.cannotafford").sendPrefixedMessage(event.getPlayer());
this.instance.getLocale().getMessage("alchemist.cannotafford").sendPrefixedMessage(event.getPlayer());
return;
}
EconomyManager.withdrawBalance(event.getPlayer(), ecoCost);
changeExp(event.getPlayer(), -expCost);
instance.getLocale().getMessage("alchemist.success")
this.instance.getLocale().getMessage("alchemist.success")
.processPlaceholder("eco_cost", ecoCost)
.processPlaceholder("exp_cost", expCost)
.sendPrefixedMessage(event.getPlayer());
event.getPlayer().getInventory().addItem(getInventory().getItem(PREVIEW_SLOT));
clear(RIGHT_SLOT);
clear(LEFT_SLOT);
event.getPlayer().getInventory().addItem(getInventory().getItem(this.PREVIEW_SLOT));
clear(this.RIGHT_SLOT);
clear(this.LEFT_SLOT);
event.getPlayer().closeInventory();
});
}
private int getFromFormula(String path, Placeholder... placeholders) {
String toTest = config.getString(path);
String toTest = this.config.getString(path);
for (Placeholder placeholder : placeholders)
toTest = toTest.replace(placeholder.getPlaceholder(), placeholder.getToReplace().toString());

View File

@ -1,10 +1,11 @@
package com.songoda.epicenchants.menus;
package com.craftaro.epicenchants.menus;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Group;
import com.songoda.epicenchants.utils.objects.FastInv;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import com.craftaro.core.hooks.EconomyManager;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.objects.Placeholder;
import com.craftaro.epicenchants.utils.objects.FastInv;
import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -13,14 +14,13 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static com.songoda.epicenchants.objects.Placeholder.of;
import static com.songoda.epicenchants.utils.single.Experience.changeExp;
import static com.songoda.epicenchants.utils.single.Experience.getExp;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
import static com.songoda.epicenchants.utils.single.GeneralUtils.getSlots;
import static com.craftaro.epicenchants.utils.single.Experience.changeExp;
import static com.craftaro.epicenchants.utils.single.Experience.getExp;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.color;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.getSlots;
public class EnchanterMenu extends FastInv {
private final Map<UUID, Long> DELAY = new HashMap<>();
private final Map<UUID, Long> delay = new HashMap<>();
public EnchanterMenu(EpicEnchants instance, FileConfiguration config, Player player) {
super(config.getInt("rows") * 9, color(config.getString("title")));
@ -33,7 +33,7 @@ public class EnchanterMenu extends FastInv {
.stream()
.map(s -> "contents." + s)
.map(config::getConfigurationSection)
.filter(s -> s.get("group") != null)
.filter(section -> section.get("group") != null)
.forEach(section -> {
int expCost = section.getInt("exp-cost");
int ecoCost = section.getInt("eco-cost");
@ -44,14 +44,14 @@ public class EnchanterMenu extends FastInv {
Group group = instance.getGroupManager().getValue(section.getString("group").toUpperCase())
.orElseThrow(() -> new IllegalArgumentException("Invalid group set in enchanter: " + section.getString("group")));
ItemStack itemStack = new ItemBuilder(section,
of("exp_cost", expCost),
of("eco_cost", ecoCost),
of("exp_left", xpLeft),
of("eco_left", ecoLeft)).build();
Placeholder.of("exp_cost", expCost),
Placeholder.of("eco_cost", ecoCost),
Placeholder.of("exp_left", xpLeft),
Placeholder.of("eco_left", ecoLeft)).build();
addItem(getSlots(section.getString("slot")), itemStack, event -> {
// Todo: wanna change this
if (DELAY.getOrDefault(player.getUniqueId(), 0L) > System.currentTimeMillis()) {
if (this.delay.getOrDefault(player.getUniqueId(), 0L) > System.currentTimeMillis()) {
return;
}
@ -72,7 +72,7 @@ public class EnchanterMenu extends FastInv {
changeExp(player, -expCost);
player.getInventory().addItem(instance.getSpecialItems().getMysteryBook(group));
DELAY.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + 120);
this.delay.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + 120);
});
});
@ -80,8 +80,7 @@ public class EnchanterMenu extends FastInv {
.stream()
.map(s -> "contents." + s)
.map(config::getConfigurationSection)
.filter(s -> s.get("group") == null)
.filter(section -> section.get("group") == null)
.forEach(section -> addItem(getSlots(section.getString("slot")), new ItemBuilder(section).build()));
}
}

View File

@ -1,10 +1,11 @@
package com.songoda.epicenchants.menus;
package com.craftaro.epicenchants.menus;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.objects.Group;
import com.songoda.epicenchants.utils.objects.FastInv;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.objects.Placeholder;
import com.craftaro.epicenchants.utils.objects.FastInv;
import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import org.apache.commons.lang.StringUtils;
import org.bukkit.configuration.file.FileConfiguration;
@ -13,9 +14,8 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static com.songoda.epicenchants.objects.Placeholder.of;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
import static com.songoda.epicenchants.utils.single.GeneralUtils.getSlots;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.color;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.getSlots;
import static java.util.Arrays.stream;
public class InfoMenu extends FastInv {
@ -54,12 +54,17 @@ public class InfoMenu extends FastInv {
.collect(Collectors.joining(", "));
addItem(slot, new ItemBuilder(config.getConfigurationSection("enchant-item"),
of("group_color", enchant.getGroup().getColor()),
of("enchant", enchant.getIdentifier()),
of("max_level", enchant.getMaxLevel()),
of("applicable_to", whitelist),
of("enchant", enchant.getIdentifier()),
of("description", enchant.getDescription().stream().map(s -> config.getString("enchant-item.description-color") + s).collect(Collectors.toList()))).build());
Placeholder.of("group_color", enchant.getGroup().getColor()),
Placeholder.of("enchant", enchant.getIdentifier()),
Placeholder.of("max_level", enchant.getMaxLevel()),
Placeholder.of("applicable_to", whitelist),
Placeholder.of("enchant", enchant.getIdentifier()),
Placeholder.of("description", enchant
.getDescription()
.stream()
.map(s -> config.getString("enchant-item.description-color") + s)
.collect(Collectors.toList())))
.build());
});
}
}

View File

@ -0,0 +1,35 @@
package com.craftaro.epicenchants.menus;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.utils.objects.FastInv;
import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.Listener;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.color;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.getSlots;
public class MainInfoMenu extends FastInv implements Listener {
public MainInfoMenu(EpicEnchants instance, FileConfiguration config) {
super(config.getInt("rows") * 9, color(config.getString("title")));
config.getConfigurationSection("contents").getKeys(false)
.stream()
.map(s -> "contents." + s)
.map(config::getConfigurationSection)
.forEach(section -> addItem(getSlots(section.getString("slot")), new ItemBuilder(section).build(), event -> {
if (section.getString("group") == null) {
return;
}
Group group = instance
.getGroupManager()
.getValue(section.getString("group"))
.orElseThrow(() -> new IllegalArgumentException("Invalid group: " + section.getString("group")));
instance.getInfoManager()
.getMenu(group)
.ifPresent(menu -> menu.open(event.getPlayer()));
}));
}
}

View File

@ -1,12 +1,12 @@
package com.songoda.epicenchants.menus;
package com.craftaro.epicenchants.menus;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTCompound;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.enums.ItemType;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.utils.objects.FastInv;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTCompound;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.enums.ItemType;
import com.craftaro.epicenchants.utils.objects.FastInv;
import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
@ -22,11 +22,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import static com.songoda.epicenchants.enums.ItemType.BOOK;
import static com.songoda.epicenchants.enums.ItemType.ENCHANTED;
import static com.songoda.epicenchants.enums.ItemType.NONE;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
import static com.songoda.epicenchants.utils.single.GeneralUtils.getSlots;
import static com.craftaro.epicenchants.enums.ItemType.BOOK;
import static com.craftaro.epicenchants.enums.ItemType.ENCHANTED;
import static com.craftaro.epicenchants.enums.ItemType.NONE;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.color;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.getSlots;
import static java.util.Arrays.stream;
public class TinkererMenu extends FastInv {
@ -54,8 +54,8 @@ public class TinkererMenu extends FastInv {
.forEach(section -> {
addItem(getSlots(section.getString("slot")), new ItemBuilder(section).build(), event -> {
if (section.getName().equalsIgnoreCase("accept-left") || section.getName().equalsIgnoreCase("accept-right")) {
slotMap.values().stream().map(slot -> getInventory().getItem(slot)).filter(Objects::nonNull).forEach(event.getPlayer().getInventory()::addItem);
slotMap.keySet().forEach(slot -> getInventory().clear(slot));
this.slotMap.values().stream().map(slot -> getInventory().getItem(slot)).filter(Objects::nonNull).forEach(event.getPlayer().getInventory()::addItem);
this.slotMap.keySet().forEach(slot -> getInventory().clear(slot));
accepted.set(true);
event.getPlayer().closeInventory();
instance.getLocale().getMessage("tinkerer.accepted").sendPrefixedMessage(event.getPlayer());
@ -118,14 +118,14 @@ public class TinkererMenu extends FastInv {
int slot = event.getSlot();
if (!slotMap.keySet().contains(slot)) {
if (!this.slotMap.keySet().contains(slot)) {
return;
}
if (getInventory().getItem(slot) != null && getInventory().getItem(slot).getType() != Material.AIR) {
event.getPlayer().getInventory().addItem(getInventory().getItem(slot));
getInventory().clear(slot);
getInventory().clear(slotMap.get(slot));
getInventory().clear(this.slotMap.get(slot));
}
});
@ -154,7 +154,7 @@ public class TinkererMenu extends FastInv {
// Player closed inventory
onClose(event -> {
slotMap.keySet().stream().filter(s -> getInventory().getItem(s) != null).forEach(s -> {
this.slotMap.keySet().stream().filter(s -> getInventory().getItem(s) != null).forEach(s -> {
event.getPlayer().getInventory().addItem(getInventory().getItem(s));
});
@ -174,10 +174,6 @@ public class TinkererMenu extends FastInv {
return BOOK;
}
if (!instance.getHookManager().getUltimateBottles().isPresent()) {
return NONE;
}
if (!itemStack.getEnchantments().isEmpty() || (nbtItem.getCompound("enchants") != null && !nbtItem.getCompound("enchants").getKeys().isEmpty())) {
if (getExpAmount(itemStack) == 0) {
return NONE;
@ -190,7 +186,7 @@ public class TinkererMenu extends FastInv {
}
private boolean handleItem(ItemStack itemStack, ItemType itemType) {
Optional<Map.Entry<Integer, Integer>> emptySlot = slotMap.entrySet().stream()
Optional<Map.Entry<Integer, Integer>> emptySlot = this.slotMap.entrySet().stream()
.filter(slot -> getInventory().getItem(slot.getKey()) == null || getInventory().getItem(slot.getKey()).getType() == Material.AIR)
.findFirst();
@ -203,13 +199,8 @@ public class TinkererMenu extends FastInv {
addItem(emptySlot.get().getKey(), finalItemStack);
switch (itemType) {
case BOOK:
getInventory().setItem(emptySlot.get().getValue(), instance.getSpecialItems().getSecretDust(new NBTItem(finalItemStack)));
break;
case ENCHANTED:
getInventory().setItem(emptySlot.get().getValue(), instance.getHookManager().getUltimateBottles().get().createBottle("Tinkerer", getExpAmount(finalItemStack)));
break;
if (itemType == BOOK) {
getInventory().setItem(emptySlot.get().getValue(), this.instance.getSpecialItems().getSecretDust(new NBTItem(finalItemStack)));
}
return true;
@ -229,7 +220,7 @@ public class TinkererMenu extends FastInv {
private int getExpAmount(ItemStack itemStack) {
AtomicInteger total = new AtomicInteger();
ConfigurationSection section = config.getConfigurationSection("exp-table-per-level");
ConfigurationSection section = this.config.getConfigurationSection("exp-table-per-level");
itemStack.getEnchantments().forEach((enchantment, level) -> {
total.addAndGet(section.getInt(enchantment.getName(), section.getInt("DEFAULT")) * level);
@ -248,7 +239,7 @@ public class TinkererMenu extends FastInv {
}
enchantments.getKeys().forEach(key -> {
Enchant enchant = instance.getEnchantManager().getValueUnsafe(key);
Enchant enchant = this.instance.getEnchantManager().getValueUnsafe(key);
total.addAndGet(section.getInt(enchant.getIdentifier(), enchant.getGroup().getTinkererExp()) * enchantments.getInteger(key));
});

View File

@ -1,12 +1,12 @@
package com.songoda.epicenchants.objects;
package com.craftaro.epicenchants.objects;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import com.songoda.epicenchants.utils.settings.Settings;
import com.songoda.epicenchants.utils.single.GeneralUtils;
import com.songoda.epicenchants.utils.single.ItemGroup;
import com.songoda.epicenchants.utils.single.RomanNumber;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import com.craftaro.epicenchants.utils.settings.Settings;
import com.craftaro.epicenchants.utils.single.GeneralUtils;
import com.craftaro.epicenchants.utils.single.ItemGroup;
import com.craftaro.epicenchants.utils.single.RomanNumber;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@ -14,14 +14,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.color;
import static java.util.concurrent.ThreadLocalRandom.current;
public class BookItem {
private EpicEnchants instance;
private Material material;
private String displayName;
private List<String> lore;
private final EpicEnchants instance;
private final Material material;
private final String displayName;
private final List<String> lore;
BookItem(EpicEnchants instance, Material material, String displayName, List<String> lore) {
this.instance = instance;
@ -52,7 +52,7 @@ public class BookItem {
int finalSuccessRate = successRate;
int finalDestroyRate = destroyRate;
List<String> toSet = new ArrayList<>(lore);
List<String> toSet = new ArrayList<>(this.lore);
for (int i = toSet.size() - 1; i >= 0; i--) {
String string = toSet.get(i);
@ -64,17 +64,17 @@ public class BookItem {
}
string = string
.replace("{item_group}", "" + instance.getItemGroup().getGroup(enchant.getItemWhitelist()).map(ItemGroup.Group::getName).orElse("N/A"))
.replace("{success_rate}", "" + finalSuccessRate)
.replace("{destroy_rate}", "" + finalDestroyRate);
.replace("{item_group}", this.instance.getItemGroup().getGroup(enchant.getItemWhitelist()).map(ItemGroup.Group::getName).orElse("N/A"))
.replace("{success_rate}", String.valueOf(finalSuccessRate))
.replace("{destroy_rate}", String.valueOf(finalDestroyRate));
toSet.set(i, string);
}
ItemBuilder itemBuilder = new ItemBuilder(material)
.name(color(displayName
.replace("{level}", "" + (Settings.ROMAN.getBoolean() ? RomanNumber.toRoman(level) : level))
.replace("{enchant}", "" + enchant.getIdentifier())
ItemBuilder itemBuilder = new ItemBuilder(this.material)
.name(color(this.displayName
.replace("{level}", String.valueOf(Settings.ROMAN.getBoolean() ? RomanNumber.toRoman(level) : level))
.replace("{enchant}", enchant.getIdentifier())
.replace("{group_color}", enchant.getGroup().getColor())
.replace("{group_name}", enchant.getGroup().getName())
))
@ -120,7 +120,7 @@ public class BookItem {
}
public BookItem build() {
return new BookItem(instance, material, displayName, lore);
return new BookItem(this.instance, this.material, this.displayName, this.lore);
}
public String toString() {

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.objects;
package com.craftaro.epicenchants.objects;
import com.songoda.epicenchants.utils.single.GeneralUtils;
import com.songoda.epicenchants.utils.single.Placeholders;
import com.craftaro.epicenchants.utils.single.GeneralUtils;
import com.craftaro.epicenchants.utils.single.Placeholders;
import org.bukkit.ChatColor;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -20,11 +20,11 @@ public class Condition {
}
public boolean get(Player user, @Nullable LivingEntity attacker, int level, @Nullable Event event, boolean def) {
if (string == null || string.isEmpty()) {
if (this.string == null || this.string.isEmpty()) {
return true;
}
String toValidate = ChatColor.stripColor(Placeholders.setPlaceholders(string, user, attacker, level, event));
String toValidate = ChatColor.stripColor(Placeholders.setPlaceholders(this.string, user, attacker, level, event));
return (boolean) GeneralUtils.parseJS(toValidate, "condition", def);
}

View File

@ -1,10 +1,10 @@
package com.songoda.epicenchants.objects;
package com.craftaro.epicenchants.objects;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.enums.TriggerType;
import com.songoda.epicenchants.utils.single.RomanNumber;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.epicenchants.effect.EffectExecutor;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.enums.TriggerType;
import com.craftaro.epicenchants.utils.single.RomanNumber;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@ -15,22 +15,21 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.color;
public class Enchant {
private String author;
private String identifier;
private Group group;
private int maxLevel;
private Set<String> conflict;
private Set<CompatibleMaterial> itemWhitelist;
private Set<EffectExecutor> effectExecutors;
private List<String> description;
private String format;
@Nullable
private BookItem bookItem;
private final String author;
private final String identifier;
private final Group group;
private final int maxLevel;
private final Set<String> conflict;
private final Set<XMaterial> itemWhitelist;
private final Set<EffectExecutor> effectExecutors;
private final List<String> description;
private final String format;
private final @Nullable BookItem bookItem;
Enchant(String author, String identifier, Group group, int maxLevel, Set<String> conflict, Set<CompatibleMaterial> itemWhitelist, Set<EffectExecutor> effectExecutors, List<String> description, String format, BookItem bookItem) {
Enchant(String author, String identifier, Group group, int maxLevel, Set<String> conflict, Set<XMaterial> itemWhitelist, Set<EffectExecutor> effectExecutors, List<String> description, String format, @Nullable BookItem bookItem) {
this.author = author;
this.identifier = identifier;
this.group = group;
@ -48,26 +47,26 @@ public class Enchant {
}
public void onAction(@NotNull Player user, @Nullable LivingEntity opponent, Event event, int level, TriggerType triggerType, EventType eventType) {
effectExecutors.forEach(effect -> effect.testAndRun(user, opponent, level, triggerType, event, eventType));
this.effectExecutors.forEach(effect -> effect.testAndRun(user, opponent, level, triggerType, event, eventType));
}
public BookItem getBook() {
return bookItem != null ? bookItem : group.getBookItem();
return this.bookItem != null ? this.bookItem : this.group.getBookItem();
}
public String getFormat(int level, boolean roman) {
String output = format.isEmpty() ? group.getFormat() : format;
String output = this.format.isEmpty() ? this.group.getFormat() : this.format;
output = output
.replace("{level}", "" + (roman ? RomanNumber.toRoman(level) : level))
.replace("{enchant}", "" + identifier)
.replace("{group_color}", "" + group.getColor());
.replace("{level}", String.valueOf(roman ? RomanNumber.toRoman(level) : level))
.replace("{enchant}", this.identifier)
.replace("{group_color}", this.group.getColor());
return color(output);
}
public String getAuthor() {
return author;
return this.author;
}
public String getIdentifier() {
@ -96,7 +95,7 @@ public class Enchant {
return this.conflict;
}
public Set<CompatibleMaterial> getItemWhitelist() {
public Set<XMaterial> getItemWhitelist() {
return new HashSet<>(this.itemWhitelist);
}
@ -123,7 +122,7 @@ public class Enchant {
private Group group;
private int maxLevel;
private Set<String> conflict;
private Set<CompatibleMaterial> itemWhitelist;
private Set<XMaterial> itemWhitelist;
private Set<EffectExecutor> effectExecutors;
private List<String> description;
private String format;
@ -157,7 +156,7 @@ public class Enchant {
return this;
}
public Enchant.EnchantBuilder itemWhitelist(Set<CompatibleMaterial> itemWhitelist) {
public Enchant.EnchantBuilder itemWhitelist(Set<XMaterial> itemWhitelist) {
this.itemWhitelist = itemWhitelist;
return this;
}
@ -183,7 +182,7 @@ public class Enchant {
}
public Enchant build() {
return new Enchant(author, identifier, group, maxLevel, conflict, itemWhitelist, effectExecutors, description, format, bookItem);
return new Enchant(this.author, this.identifier, this.group, this.maxLevel, this.conflict, this.itemWhitelist, this.effectExecutors, this.description, this.format, this.bookItem);
}
public String toString() {

View File

@ -1,16 +1,19 @@
package com.songoda.epicenchants.objects;
package com.craftaro.epicenchants.objects;
public class Group {
private String identifier;
private String name;
private String format;
private String color;
private String descriptionColor;
private int slotsUsed;
private BookItem bookItem;
private int destroyRateMin, destroyRateMax, successRateMin, successRateMax;
private int tinkererExp;
private int order;
private final String identifier;
private final String name;
private final String format;
private final String color;
private final String descriptionColor;
private final int slotsUsed;
private final BookItem bookItem;
private final int destroyRateMin;
private final int destroyRateMax;
private final int successRateMin;
private final int successRateMax;
private final int tinkererExp;
private final int order;
Group(String identifier, String name, String format, String color, String descriptionColor, int slotsUsed, BookItem bookItem, int destroyRateMin, int destroyRateMax, int successRateMin, int successRateMax, int tinkererExp, int order) {
this.identifier = identifier;
@ -168,7 +171,7 @@ public class Group {
}
public Group build() {
return new Group(identifier, name, format, color, descriptionColor, slotsUsed, bookItem, destroyRateMin, destroyRateMax, successRateMin, successRateMax, tinkererExp, order);
return new Group(this.identifier, this.name, this.format, this.color, this.descriptionColor, this.slotsUsed, this.bookItem, this.destroyRateMin, this.destroyRateMax, this.successRateMin, this.successRateMax, this.tinkererExp, this.order);
}
public String toString() {

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.objects;
package com.craftaro.epicenchants.objects;
import com.songoda.epicenchants.utils.single.GeneralUtils;
import com.songoda.epicenchants.utils.single.Placeholders;
import com.craftaro.epicenchants.utils.single.GeneralUtils;
import com.craftaro.epicenchants.utils.single.Placeholders;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -17,15 +17,15 @@ public class LeveledModifier {
}
public double get(int level, double def, Player user, LivingEntity opponent) {
if (string == null || string.isEmpty()) {
if (this.string == null || this.string.isEmpty()) {
return def;
}
if (string.equalsIgnoreCase("MAX")) {
if (this.string.equalsIgnoreCase("MAX")) {
return Integer.MAX_VALUE;
}
String toTest = Placeholders.setPlaceholders(string, user, opponent, level);
String toTest = Placeholders.setPlaceholders(this.string, user, opponent, level);
Object value = GeneralUtils.parseJS(toTest, "LeveledModifier", def);
return value instanceof Double ? (double) value : (int) value;

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.objects;
package com.craftaro.epicenchants.objects;
public class Placeholder {
private String placeholder;
private Object toReplace;
private final String placeholder;
private final Object toReplace;
private Placeholder(String placeholder, Object toReplace) {
this.placeholder = "{" + placeholder + "}";
@ -14,10 +14,10 @@ public class Placeholder {
}
public String getPlaceholder() {
return placeholder;
return this.placeholder;
}
public Object getToReplace() {
return toReplace;
return this.toReplace;
}
}

View File

@ -1,16 +1,17 @@
package com.songoda.epicenchants.utils;
package com.craftaro.epicenchants.utils;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTCompound;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.core.utils.TextUtils;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.enums.EnchantResult;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.enums.TriggerType;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import com.songoda.epicenchants.utils.settings.Settings;
import com.songoda.epicenchants.utils.single.GeneralUtils;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTCompound;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.core.utils.NumberUtils;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.enums.EnchantResult;
import com.craftaro.epicenchants.enums.EventType;
import com.craftaro.epicenchants.enums.TriggerType;
import com.craftaro.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import com.craftaro.epicenchants.utils.settings.Settings;
import com.craftaro.epicenchants.utils.single.GeneralUtils;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -18,8 +19,8 @@ import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -30,15 +31,6 @@ import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import static com.songoda.epicenchants.enums.EnchantResult.ALREADY_APPLIED;
import static com.songoda.epicenchants.enums.EnchantResult.BROKEN_FAILURE;
import static com.songoda.epicenchants.enums.EnchantResult.CONFLICT;
import static com.songoda.epicenchants.enums.EnchantResult.FAILURE;
import static com.songoda.epicenchants.enums.EnchantResult.MAXED_OUT;
import static com.songoda.epicenchants.enums.EnchantResult.PROTECTED;
import static com.songoda.epicenchants.enums.EnchantResult.SUCCESS;
import static com.songoda.epicenchants.enums.TriggerType.HELD_ITEM;
public class EnchantUtils {
private final EpicEnchants instance;
@ -48,47 +40,47 @@ public class EnchantUtils {
}
public Tuple<ItemStack, EnchantResult> apply(ItemStack itemStack, Enchant enchant, int level, int successRate, int destroyRate) {
boolean hasProtection = new NBTItem(itemStack).hasKey("protected");
boolean hasProtection = new NBTItem(itemStack).hasTag("protected");
Map<Enchant, Integer> currentEnchantMap = getEnchants(itemStack);
Set<String> currentIds = currentEnchantMap.keySet().stream().map(Enchant::getIdentifier).collect(Collectors.toSet());
Set<String> currentConflicts = currentEnchantMap.keySet().stream().map(Enchant::getConflict).flatMap(Collection::stream).collect(Collectors.toSet());
if (enchant.getConflict().stream().anyMatch(currentIds::contains) || currentConflicts.contains(enchant.getIdentifier())) {
return Tuple.of(itemStack, CONFLICT);
return Tuple.of(itemStack, EnchantResult.CONFLICT);
}
if (currentEnchantMap.entrySet().stream().anyMatch(entry -> entry.getKey().equals(enchant) && entry.getValue() == enchant.getMaxLevel())) {
return Tuple.of(itemStack, MAXED_OUT);
return Tuple.of(itemStack, EnchantResult.MAXED_OUT);
}
if (currentEnchantMap.entrySet().stream().anyMatch(entry -> entry.getKey().equals(enchant) && entry.getValue() >= level)) {
return Tuple.of(itemStack, ALREADY_APPLIED);
return Tuple.of(itemStack, EnchantResult.ALREADY_APPLIED);
}
if (!GeneralUtils.chance(successRate)) {
if (GeneralUtils.chance(destroyRate)) {
if (hasProtection) {
NBTItem nbtItem = new ItemBuilder(itemStack).removeLore(instance.getSpecialItems().getWhiteScrollLore()).nbt();
NBTItem nbtItem = new ItemBuilder(itemStack).removeLore(this.instance.getSpecialItems().getWhiteScrollLore()).nbt();
nbtItem.removeKey("protected");
return Tuple.of(nbtItem.getItem(), PROTECTED);
return Tuple.of(nbtItem.getItem(), EnchantResult.PROTECTED);
}
return Tuple.of(new ItemStack(Material.AIR), BROKEN_FAILURE);
return Tuple.of(new ItemStack(Material.AIR), EnchantResult.BROKEN_FAILURE);
}
return Tuple.of(itemStack, FAILURE);
return Tuple.of(itemStack, EnchantResult.FAILURE);
}
ItemBuilder itemBuilder = new ItemBuilder(itemStack);
if (hasProtection) {
itemBuilder.removeLore(instance.getSpecialItems().getWhiteScrollLore());
itemBuilder.removeLore(this.instance.getSpecialItems().getWhiteScrollLore());
}
itemBuilder.removeLore(enchant.getFormat(-1, Settings.ROMAN.getBoolean()).replace("-1", "").trim());
itemBuilder.addLore(enchant.getFormat(level, Settings.ROMAN.getBoolean()));
if (hasProtection) {
itemBuilder.addLore(instance.getSpecialItems().getWhiteScrollLore());
itemBuilder.addLore(this.instance.getSpecialItems().getWhiteScrollLore());
}
NBTItem nbtItem = itemBuilder.nbt();
@ -96,7 +88,7 @@ public class EnchantUtils {
NBTCompound compound = nbtItem.getOrCreateCompound("enchants");
compound.setInteger(enchant.getIdentifier(), level);
return Tuple.of(nbtItem.getItem(), SUCCESS);
return Tuple.of(nbtItem.getItem(), EnchantResult.SUCCESS);
}
public Map<Enchant, Integer> getEnchants(ItemStack itemStack) {
@ -105,7 +97,7 @@ public class EnchantUtils {
}
NBTItem nbtItem = new NBTItem(itemStack);
if (!nbtItem.hasKey("enchants")) {
if (!nbtItem.hasTag("enchants")) {
return Collections.emptyMap();
}
@ -115,8 +107,8 @@ public class EnchantUtils {
return Collections.emptyMap();
}
return compound.getKeys().stream().filter(key -> instance.getEnchantManager().getValueUnsafe(key) != null)
.collect(Collectors.toMap(key -> instance.getEnchantManager().getValueUnsafe(key), compound::getInteger));
return compound.getKeys().stream().filter(key -> this.instance.getEnchantManager().getValueUnsafe(key) != null)
.collect(Collectors.toMap(key -> this.instance.getEnchantManager().getValueUnsafe(key), compound::getInteger));
}
public void handlePlayer(@NotNull Player player, @Nullable LivingEntity opponent, Event event, TriggerType triggerType) {
@ -124,7 +116,7 @@ public class EnchantUtils {
stacks.add(GeneralUtils.getHeldItem(player, event));
stacks.removeIf(Objects::isNull);
if (triggerType == HELD_ITEM) {
if (triggerType == TriggerType.HELD_ITEM) {
stacks = Collections.singletonList(player.getItemInHand());
}
@ -155,26 +147,34 @@ public class EnchantUtils {
public int getMaximumEnchantsCanApplyItem(ItemStack itemStack, Player p) {
int max;
if (p.isOp()) return 100; // in theory no single item will have 100 enchantments at a time.
if (instance.getFileManager().getConfiguration("items/item-limits").contains("limits." + itemStack.getType().toString())) {
max = instance.getFileManager().getConfiguration("items/item-limits").getInt("limits." + itemStack.getType().toString());
if (p.isOp()) {
return 100; // in theory, no single item will have 100 enchantments at a time.
}
if (this.instance.getFileManager().getConfiguration("items/item-limits").contains("limits." + itemStack.getType().toString())) {
max = this.instance.getFileManager().getConfiguration("items/item-limits").getInt("limits." + itemStack.getType().toString());
} else {
max = instance.getFileManager().getConfiguration("items/item-limits").getInt("default");
max = this.instance.getFileManager().getConfiguration("items/item-limits").getInt("default");
}
return max;
}
public int getMaximumEnchantsCanApply(Player p) {
int max = 0;
if (p.isOp()) return 100; // in theory no single item will have 100 enchantments at a time.
if (p.isOp()) {
return 100; // in theory, no single item will have 100 enchantments at a time.
}
for (PermissionAttachmentInfo effectivePermission : p.getEffectivePermissions()) {
if (!effectivePermission.getPermission().startsWith("epicenchants.maxapply.")) continue;
if (!effectivePermission.getPermission().startsWith("epicenchants.maxapply.")) {
continue;
}
String node[] = effectivePermission.getPermission().split("\\.");
String[] node = effectivePermission.getPermission().split("\\.");
if (Methods.isInt(node[node.length - 1])) {
if (NumberUtils.isInt(node[node.length - 1])) {
int num = Integer.parseInt(node[node.length - 1]);
if (num > max) max = num;
if (num > max) {
max = num;
}
}
}
return max;

View File

@ -1,10 +1,11 @@
package com.songoda.epicenchants.utils;
package com.craftaro.epicenchants.utils;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Group;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import com.songoda.epicenchants.utils.settings.Settings;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.objects.Placeholder;
import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import com.craftaro.epicenchants.utils.settings.Settings;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
@ -12,8 +13,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.concurrent.ThreadLocalRandom;
import static com.songoda.epicenchants.objects.Placeholder.of;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.color;
public class SpecialItems {
private final EpicEnchants instance;
@ -23,7 +23,7 @@ public class SpecialItems {
}
public ItemStack getWhiteScroll(int amount) {
NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("white-scroll")).nbt();
NBTItem nbtItem = new ItemBuilder(this.instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("white-scroll")).nbt();
nbtItem.setBoolean("white-scroll", true);
ItemStack itemStack = nbtItem.getItem();
@ -34,7 +34,7 @@ public class SpecialItems {
public ItemStack getBlackScroll(int amount, int chance) {
int successRate = chance == -1 ? ThreadLocalRandom.current().nextInt(Settings.BLACK_MIN.getInt(), Settings.BLACK_MAX.getInt() + 1) : chance;
NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("black-scroll"), of("success-rate", successRate)).nbt();
NBTItem nbtItem = new ItemBuilder(this.instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("black-scroll"), Placeholder.of("success-rate", successRate)).nbt();
nbtItem.setBoolean("black-scroll", true);
nbtItem.setInteger("success-rate", successRate);
@ -47,9 +47,9 @@ public class SpecialItems {
}
public ItemStack getMysteryBook(Group group) {
NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("mystery-book"),
of("group-color", group.getColor()),
of("group-name", group.getName())).nbt();
NBTItem nbtItem = new ItemBuilder(this.instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("mystery-book"),
Placeholder.of("group-color", group.getColor()),
Placeholder.of("group-name", group.getName())).nbt();
nbtItem.setBoolean("mystery-book", true);
nbtItem.setString("group", group.getIdentifier());
@ -57,16 +57,16 @@ public class SpecialItems {
}
public ItemStack getSecretDust(NBTItem book) {
Group group = instance.getEnchantManager().getValueUnsafe(book.getString("enchant")).getGroup();
Group group = this.instance.getEnchantManager().getValueUnsafe(book.getString("enchant")).getGroup();
return getSecretDust(group, (int) Math.floor(book.getInteger("success-rate") / 10.0));
}
public ItemStack getSecretDust(Group group, int max) {
NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/dusts").getConfigurationSection("secret-dust"),
of("group-color", group.getColor()),
of("group-name", group.getName()),
of("max-rate", max),
of("min-rate", 0)).nbt();
NBTItem nbtItem = new ItemBuilder(this.instance.getFileManager().getConfiguration("items/dusts").getConfigurationSection("secret-dust"),
Placeholder.of("group-color", group.getColor()),
Placeholder.of("group-name", group.getName()),
Placeholder.of("max-rate", max),
Placeholder.of("min-rate", 0)).nbt();
nbtItem.setBoolean("secret-dust", true);
nbtItem.setString("group", group.getIdentifier());
@ -76,7 +76,7 @@ public class SpecialItems {
}
public ItemStack getDust(Group group, @Nullable String type, int percentage, boolean command) {
FileConfiguration dustConfig = instance.getFileManager().getConfiguration("items/dusts");
FileConfiguration dustConfig = this.instance.getFileManager().getConfiguration("items/dusts");
int random = ThreadLocalRandom.current().nextInt(101);
int counter = 0;
@ -103,9 +103,9 @@ public class SpecialItems {
}
NBTItem nbtItem = new ItemBuilder(config,
of("group-color", group.getColor()),
of("group-name", group.getName()),
of("percentage", percentage)).nbt();
Placeholder.of("group-color", group.getColor()),
Placeholder.of("group-name", group.getName()),
Placeholder.of("percentage", percentage)).nbt();
if (type.equalsIgnoreCase("mystery")) {
return nbtItem.getItem();
@ -119,6 +119,6 @@ public class SpecialItems {
}
public String getWhiteScrollLore() {
return color(instance.getFileManager().getConfiguration("items/special-items").getString("white-scroll.format"));
return color(this.instance.getFileManager().getConfiguration("items/special-items").getString("white-scroll.format"));
}
}

View File

@ -1,8 +1,8 @@
package com.songoda.epicenchants.utils;
package com.craftaro.epicenchants.utils;
public class Tuple<key, value> {
private key x;
private value y;
private final key x;
private final value y;
public Tuple(key x, value y) {
this.x = x;
@ -18,6 +18,6 @@ public class Tuple<key, value> {
}
public static <key, value> Tuple of(key x, value y) {
return new Tuple(x, y);
return new Tuple<>(x, y);
}
}

View File

@ -1,4 +1,4 @@
package com.songoda.epicenchants.utils.objects;
package com.craftaro.epicenchants.utils.objects;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -55,9 +55,9 @@ public class FastInv implements InventoryHolder {
runSync(() -> {
if (type == InventoryType.CHEST && size > 0) {
inventory = Bukkit.createInventory(this, size, title);
this.inventory = Bukkit.createInventory(this, size, title);
} else {
inventory = Bukkit.createInventory(this, type, title);
this.inventory = Bukkit.createInventory(this, type, title);
}
});
}
@ -124,7 +124,7 @@ public class FastInv implements InventoryHolder {
}
public InventoryClickEvent getEvent() {
return event;
return this.event;
}
}
@ -149,7 +149,7 @@ public class FastInv implements InventoryHolder {
*/
public FastInv addItem(ItemStack item, FastInvClickListener listener) {
runSync(() -> {
int slot = inventory.firstEmpty();
int slot = this.inventory.firstEmpty();
if (slot >= 0) {
addItem(slot, item, listener);
}
@ -180,12 +180,12 @@ public class FastInv implements InventoryHolder {
*/
public FastInv addItem(int slot, ItemStack item, FastInvClickListener listener) {
runSync(() -> {
inventory.setItem(slot, item);
this.inventory.setItem(slot, item);
if (listener != null) {
itemListeners.put(slot, listener);
this.itemListeners.put(slot, listener);
} else {
itemListeners.remove(slot);
this.itemListeners.remove(slot);
}
});
@ -253,10 +253,10 @@ public class FastInv implements InventoryHolder {
* @return This FastInv instance, for chaining.
*/
public FastInv edge(ItemStack item) {
int height = inventory.getSize() / 9;
int height = this.inventory.getSize() / 9;
addItem(0, 9, item);
addItem(inventory.getSize() - 9, inventory.getSize() - 1, item);
addItem(this.inventory.getSize() - 9, this.inventory.getSize() - 1, item);
for (int i = 0; i < height; i++) {
addItem(i * 9, item);
@ -284,8 +284,8 @@ public class FastInv implements InventoryHolder {
public FastInv fill(ItemStack itemStack) {
runSync(() -> {
for (int i = 0; i < inventory.getSize(); i++) {
if (inventory.getItem(i) == null) {
for (int i = 0; i < this.inventory.getSize(); i++) {
if (this.inventory.getItem(i) == null) {
addItem(i, itemStack);
}
}
@ -301,7 +301,7 @@ public class FastInv implements InventoryHolder {
* @return This FastInv instance, for chaining.
*/
public FastInv onClose(FastInvCloseListener listener) {
closeListeners.add(listener);
this.closeListeners.add(listener);
return this;
}
@ -313,7 +313,7 @@ public class FastInv implements InventoryHolder {
* @return This FastInv instance, for chaining.
*/
public FastInv onClick(FastInvClickListener listener) {
clickListeners.add(listener);
this.clickListeners.add(listener);
return this;
}
@ -339,7 +339,7 @@ public class FastInv implements InventoryHolder {
* @return This FastInv instance, for chaining
*/
public FastInv onUpdate(long delay, long period, Runnable runnable) {
tasks.add(Bukkit.getScheduler().runTaskTimer(plugin, runnable, delay, period));
this.tasks.add(Bukkit.getScheduler().runTaskTimer(plugin, runnable, delay, period));
return this;
}
@ -349,15 +349,15 @@ public class FastInv implements InventoryHolder {
* @param player The player to open the menu.
*/
public void open(Player player) {
Bukkit.getScheduler().runTask(plugin, () -> player.openInventory(inventory));
Bukkit.getScheduler().runTask(plugin, () -> player.openInventory(this.inventory));
}
/**
* Cancel all tasks.
*/
public void cancelTasks() {
tasks.forEach(BukkitTask::cancel);
tasks.clear();
this.tasks.forEach(BukkitTask::cancel);
this.tasks.clear();
}
/**
@ -380,13 +380,13 @@ public class FastInv implements InventoryHolder {
*/
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
/**
* Set if the tasks will be cancel on menus close.
* Set if the tasks will be canceled on menus close.
*
* @param cancelTasksOnClose Set if the tasks will be cancel
* @param cancelTasksOnClose Set if the tasks will be canceled
*
* @return This FastInv instance, for chaining.
*/
@ -420,7 +420,7 @@ public class FastInv implements InventoryHolder {
* @return This associated FastInv instance.
*/
public FastInv getInventory() {
return inventory;
return this.inventory;
}
/**
@ -429,7 +429,7 @@ public class FastInv implements InventoryHolder {
* @return the player who clicked.
*/
public Player getPlayer() {
return player;
return this.player;
}
/**
@ -438,11 +438,11 @@ public class FastInv implements InventoryHolder {
* @return Whether the event was cancelled.
*/
public boolean isCancelled() {
return cancelled;
return this.cancelled;
}
/**
* Set if the event will be cancel or not.
* Set if the event will be canceled or not.
*
* @param cancel Whether the event should be cancelled.
*/

View File

@ -1,4 +1,4 @@
package com.songoda.epicenchants.utils.objects;
package com.craftaro.epicenchants.utils.objects;
public class FileLocation {
private final boolean required, versionDependent;
@ -19,22 +19,22 @@ public class FileLocation {
}
public String getResourcePath(String dir) {
return (versionDependent ? "version-dependent/" + dir + "/" : "") + path;
return (this.versionDependent ? "version-dependent/" + dir + "/" : "") + this.path;
}
public boolean isDirectory() {
return path.endsWith("/");
return this.path.endsWith("/");
}
public boolean isRequired() {
return required;
return this.required;
}
public boolean isVersionDependent() {
return versionDependent;
return this.versionDependent;
}
public String getPath() {
return path;
return this.path;
}
}

View File

@ -1,10 +1,11 @@
package com.songoda.epicenchants.utils.objects;
package com.craftaro.epicenchants.utils.objects;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.objects.Placeholder;
import com.songoda.epicenchants.utils.single.ConfigParser;
import com.songoda.epicenchants.utils.single.GeneralUtils;
import com.songoda.epicenchants.wrappers.EnchantmentWrapper;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.craftaro.epicenchants.objects.Placeholder;
import com.craftaro.epicenchants.wrappers.EnchantmentWrapper;
import com.craftaro.epicenchants.utils.single.ConfigParser;
import com.craftaro.epicenchants.utils.single.GeneralUtils;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
@ -23,10 +24,9 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.color;
public class ItemBuilder {
private final ItemStack item;
private ItemMeta meta;
private final Set<EnchantmentWrapper> enchantmentWrappers;
@ -53,8 +53,8 @@ public class ItemBuilder {
public ItemBuilder(ConfigurationSection section, Player player, Placeholder... placeholders) {
this(section, placeholders);
if (item.getType() == Material.LEGACY_SKULL_ITEM) {
((SkullMeta) item.getItemMeta()).setOwningPlayer(player);
if (XMaterial.PLAYER_HEAD.isSimilar(this.item)) {
((SkullMeta) this.item.getItemMeta()).setOwner(player.getName());
}
}
@ -119,11 +119,11 @@ public class ItemBuilder {
* Name:
*/
public boolean hasName() {
return meta.hasDisplayName();
return this.meta.hasDisplayName();
}
public ItemBuilder name(String name) {
meta.setDisplayName(name);
this.meta.setDisplayName(name);
return this;
}
@ -131,7 +131,7 @@ public class ItemBuilder {
* Lore:
*/
public boolean hasLore() {
return meta.hasLore();
return this.meta.hasLore();
}
public ItemBuilder lore(String... lore) {
@ -139,37 +139,37 @@ public class ItemBuilder {
}
public ItemBuilder lore(List<String> lore) {
meta.setLore(lore);
this.meta.setLore(lore);
return this;
}
public ItemBuilder addLore(List<String> lore) {
if (!meta.hasLore()) {
meta.setLore(lore);
if (!this.meta.hasLore()) {
this.meta.setLore(lore);
return this;
}
List<String> toAdd = meta.getLore();
List<String> toAdd = this.meta.getLore();
toAdd.addAll(lore);
meta.setLore(toAdd);
this.meta.setLore(toAdd);
return this;
}
public ItemBuilder removeLore(String string) {
if (meta == null || !meta.hasLore()) {
if (this.meta == null || !this.meta.hasLore()) {
return this;
}
meta.setLore(meta.getLore().stream().filter(s -> !s.startsWith(string)).collect(Collectors.toList()));
this.meta.setLore(this.meta.getLore().stream().filter(s -> !s.startsWith(string)).collect(Collectors.toList()));
return this;
}
public ItemBuilder removeLore(int index) {
if (!meta.hasLore()) {
if (!this.meta.hasLore()) {
return this;
}
List<String> lore = meta.getLore();
List<String> lore = this.meta.getLore();
if (index >= lore.size()) {
return this;
@ -177,7 +177,7 @@ public class ItemBuilder {
lore.remove(index);
meta.setLore(lore);
this.meta.setLore(lore);
return this;
}
@ -189,29 +189,29 @@ public class ItemBuilder {
* Enchantments:
*/
public boolean hasEnchants() {
return meta.hasEnchants();
return this.meta.hasEnchants();
}
public boolean hasEnchant(Enchantment enchantment) {
return meta.hasEnchant(enchantment);
return this.meta.hasEnchant(enchantment);
}
public boolean hasConflictingEnchant(Enchantment enchantment) {
return meta.hasConflictingEnchant(enchantment);
return this.meta.hasConflictingEnchant(enchantment);
}
public ItemBuilder addEnchant(Enchantment enchantment, int level) {
meta.addEnchant(enchantment, level, true);
this.meta.addEnchant(enchantment, level, true);
return this;
}
public ItemBuilder removeEnchant(Enchantment enchantment) {
meta.removeEnchant(enchantment);
this.meta.removeEnchant(enchantment);
return this;
}
public ItemBuilder addEnchantWrapper(EnchantmentWrapper enchantmentWrapper) {
enchantmentWrappers.add(enchantmentWrapper);
this.enchantmentWrappers.add(enchantmentWrapper);
return this;
}
@ -219,21 +219,21 @@ public class ItemBuilder {
* Skulls:
*/
public boolean hasSkullOwner() {
return ((SkullMeta) meta).hasOwner();
return ((SkullMeta) this.meta).hasOwner();
}
public String getSkullOwner() {
return ((SkullMeta) meta).getOwner();
return ((SkullMeta) this.meta).getOwner();
}
public ItemBuilder skullOwner(String owner) {
item.setDurability((short) 3);
((SkullMeta) meta).setOwner(owner);
this.item.setDurability((short) 3);
((SkullMeta) this.meta).setOwner(owner);
return this;
}
public ItemBuilder durability(int durability) {
item.setDurability((short) durability);
this.item.setDurability((short) durability);
return this;
}
@ -241,25 +241,16 @@ public class ItemBuilder {
* Flags:
*/
public boolean hasFlag(ItemFlag flag) {
return meta.hasItemFlag(flag);
return this.meta.hasItemFlag(flag);
}
public ItemBuilder addFlags(ItemFlag... flags) {
meta.addItemFlags(flags);
this.meta.addItemFlags(flags);
return this;
}
public ItemBuilder removeFlags(ItemFlag... flags) {
meta.removeItemFlags(flags);
return this;
}
public ItemBuilder unbreakable() {
return unbreakable(true);
}
public ItemBuilder unbreakable(boolean unbreakable) {
meta.setUnbreakable(unbreakable);
this.meta.removeItemFlags(flags);
return this;
}
@ -271,30 +262,30 @@ public class ItemBuilder {
* Build the ItemStack.
*/
public ItemStack build() {
item.setItemMeta(meta);
return item;
this.item.setItemMeta(this.meta);
return this.item;
}
public ItemStack buildWithWrappers(int level, Player user, LivingEntity opponent) {
item.setItemMeta(meta);
enchantmentWrappers.forEach(enchant -> item.addUnsafeEnchantment(enchant.getEnchantment(), enchant.getAmplifier(level, user, opponent)));
return item;
this.item.setItemMeta(this.meta);
this.enchantmentWrappers.forEach(enchant -> this.item.addUnsafeEnchantment(enchant.getEnchantment(), enchant.getAmplifier(level, user, opponent)));
return this.item;
}
public Map<Enchantment, Integer> getEnchants() {
return meta.getEnchants();
return this.meta.getEnchants();
}
public Set<ItemFlag> getFlags() {
return meta.getItemFlags();
return this.meta.getItemFlags();
}
public List<String> getLore() {
return meta.getLore();
return this.meta.getLore();
}
public ItemMeta getMeta() {
return meta;
return this.meta;
}
/*
@ -302,13 +293,6 @@ public class ItemBuilder {
*/
public String getName() {
return meta.getDisplayName();
}
/*
* Unbreakability:
*/
public boolean isUnbreakable() {
return meta.isUnbreakable();
return this.meta.getDisplayName();
}
}

View File

@ -1,32 +1,31 @@
package com.songoda.epicenchants.utils.settings;
package com.craftaro.epicenchants.utils.settings;
import com.songoda.core.configuration.Config;
import com.songoda.core.configuration.ConfigSetting;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.epicenchants.EpicEnchants;
import com.craftaro.core.configuration.Config;
import com.craftaro.core.configuration.ConfigSetting;
import com.craftaro.core.hooks.EconomyManager;
import com.craftaro.epicenchants.EpicEnchants;
import java.util.stream.Collectors;
public class Settings {
static final Config CONFIG = EpicEnchants.getPlugin(EpicEnchants.class).getCoreConfig();
static final Config config = EpicEnchants.getInstance().getCoreConfig();
public static final ConfigSetting ROMAN = new ConfigSetting(CONFIG, "Main.Roman Numerals", true);
public static final ConfigSetting ROMAN = new ConfigSetting(config, "Main.Roman Numerals", true);
public static final ConfigSetting BLACK_MIN = new ConfigSetting(CONFIG, "Main.Black Scroll Min", 20);
public static final ConfigSetting BLACK_MAX = new ConfigSetting(CONFIG, "Main.Black Scroll Max", 100);
public static final ConfigSetting BLACK_MIN = new ConfigSetting(config, "Main.Black Scroll Min", 20);
public static final ConfigSetting BLACK_MAX = new ConfigSetting(config, "Main.Black Scroll Max", 100);
public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(config, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(),
public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(CONFIG, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(),
"Which economy plugin should be used?",
"Supported plugins you have installed: \"" + EconomyManager.getManager().getRegisteredPlugins().stream().collect(Collectors.joining("\", \"")) + "\".");
public static final ConfigSetting GLASS_TYPE_1 = new ConfigSetting(config, "Interfaces.Glass Type 1", 7);
public static final ConfigSetting GLASS_TYPE_2 = new ConfigSetting(config, "Interfaces.Glass Type 2", 11);
public static final ConfigSetting GLASS_TYPE_3 = new ConfigSetting(config, "Interfaces.Glass Type 3", 3);
public static final ConfigSetting GLASS_TYPE_1 = new ConfigSetting(CONFIG, "Interfaces.Glass Type 1", 7);
public static final ConfigSetting GLASS_TYPE_2 = new ConfigSetting(CONFIG, "Interfaces.Glass Type 2", 11);
public static final ConfigSetting GLASS_TYPE_3 = new ConfigSetting(CONFIG, "Interfaces.Glass Type 3", 3);
public static final ConfigSetting FIRST_LOAD = new ConfigSetting(config, "System.First Load", true);
public static final ConfigSetting FIRST_LOAD = new ConfigSetting(CONFIG, "System.First Load", true);
public static final ConfigSetting LANGUGE_MODE = new ConfigSetting(config, "System.Language Mode", "en_US",
public static final ConfigSetting LANGUGE_MODE = new ConfigSetting(CONFIG, "System.Language Mode", "en_US",
"The enabled language file.",
"More language files (if available) can be found in the plugins data folder.");
@ -35,18 +34,18 @@ public class Settings {
* called after EconomyManager load
*/
public static void setupConfig() {
config.load();
config.setAutoremove(true).setAutosave(true);
CONFIG.load();
CONFIG.setAutoremove(true).setAutosave(true);
// convert economy settings
if (config.getBoolean("Economy.Use Vault Economy") && EconomyManager.getManager().isEnabled("Vault")) {
config.set("Main.Economy", "Vault");
} else if (config.getBoolean("Economy.Use Reserve Economy") && EconomyManager.getManager().isEnabled("Reserve")) {
config.set("Main.Economy", "Reserve");
} else if (config.getBoolean("Economy.Use Player Points Economy") && EconomyManager.getManager().isEnabled("PlayerPoints")) {
config.set("Main.Economy", "PlayerPoints");
if (CONFIG.getBoolean("Economy.Use Vault Economy") && EconomyManager.getManager().isEnabled("Vault")) {
CONFIG.set("Main.Economy", "Vault");
} else if (CONFIG.getBoolean("Economy.Use Reserve Economy") && EconomyManager.getManager().isEnabled("Reserve")) {
CONFIG.set("Main.Economy", "Reserve");
} else if (CONFIG.getBoolean("Economy.Use Player Points Economy") && EconomyManager.getManager().isEnabled("PlayerPoints")) {
CONFIG.set("Main.Economy", "PlayerPoints");
}
config.saveChanges();
CONFIG.saveChanges();
}
}

View File

@ -1,12 +1,12 @@
package com.songoda.epicenchants.utils.single;
package com.craftaro.epicenchants.utils.single;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.effect.EffectManager;
import com.songoda.epicenchants.objects.BookItem;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.objects.Group;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.songoda.epicenchants.wrappers.EnchantmentWrapper;
import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.effect.EffectManager;
import com.craftaro.epicenchants.objects.BookItem;
import com.craftaro.epicenchants.objects.Enchant;
import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.objects.LeveledModifier;
import com.craftaro.epicenchants.wrappers.EnchantmentWrapper;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
@ -18,16 +18,14 @@ import java.util.HashSet;
import java.util.Optional;
import java.util.stream.Collectors;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
public class ConfigParser {
public static Enchant parseEnchant(EpicEnchants instance, FileConfiguration config) throws Exception {
public static Enchant parseEnchant(EpicEnchants instance, FileConfiguration config) {
return Enchant.builder()
.author("author")
.identifier(config.getString("identifier"))
.group(instance.getGroupManager().getValue(config.getString("group").toUpperCase()).orElseThrow(() -> new IllegalArgumentException("Invalid group: " + config.getString("group"))))
.maxLevel(config.getInt("max-level"))
.format(config.isSet("applied-format") ? color(config.getString("applied-format")) : "")
.format(config.isSet("applied-format") ? GeneralUtils.color(config.getString("applied-format")) : "")
.bookItem(parseBookItem(instance, config.getConfigurationSection("book-item")))
.itemWhitelist((config.isList("item-whitelist") ? config.getStringList("item-whitelist").stream().map(instance.getItemGroup()::get).flatMap(Collection::stream).collect(Collectors.toSet()) : Collections.emptySet()))
.conflict(config.isList("conflicting-enchants") ? new HashSet<>(config.getStringList("conflicting-enchants")) : Collections.emptySet())
@ -53,7 +51,7 @@ public class ConfigParser {
return section != null ? BookItem.builder()
.instance(instance)
.material(Material.valueOf(section.getString("material")))
.displayName(color(section.getString("display-name")))
.displayName(GeneralUtils.color(section.getString("display-name")))
.lore(section.getStringList("lore").stream().map(GeneralUtils::color).collect(Collectors.toList()))
.build() : null;
}
@ -62,7 +60,7 @@ public class ConfigParser {
return section != null ? Group.builder()
.order(section.getInt("order"))
.identifier(section.getName())
.name(color(section.getString("group-name")))
.name(GeneralUtils.color(section.getString("group-name")))
.format(section.getString("group-lore-format"))
.color(section.getString("group-color"))
.descriptionColor(section.getString("description-color"))

View File

@ -1,4 +1,4 @@
package com.songoda.epicenchants.utils.single;
package com.craftaro.epicenchants.utils.single;
import org.bukkit.entity.Player;

View File

@ -1,8 +1,9 @@
package com.songoda.epicenchants.utils.single;
package com.craftaro.epicenchants.utils.single;
import com.songoda.core.math.MathUtils;
import com.songoda.epicenchants.enums.EnchantResult;
import com.songoda.epicenchants.enums.TriggerType;
import com.craftaro.core.compatibility.CompatibleHand;
import com.craftaro.core.math.MathUtils;
import com.craftaro.epicenchants.enums.EnchantResult;
import com.craftaro.epicenchants.enums.TriggerType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -10,7 +11,6 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
@ -74,11 +74,8 @@ public class GeneralUtils {
} else if (entity.getEquipment() != null) {
ItemStack item = entity.getEquipment().getItemInHand();
try {
if (item.getType() == Material.AIR) {
return entity.getEquipment().getItemInOffHand();
}
} catch (NoSuchMethodError ignore) {
if (item == null || item.getType() == Material.AIR) {
return CompatibleHand.OFF_HAND.getItem(entity);
}
return item;
}
@ -86,16 +83,13 @@ public class GeneralUtils {
}
public static int getHeldItemSlot(Player player, Event event) {
int slot = player.getInventory().getHeldItemSlot();
try {
if (event instanceof PlayerInteractEvent && ((PlayerInteractEvent) event).getHand() == EquipmentSlot.OFF_HAND) {
slot = 40;
}
} catch (NoSuchMethodError ignore) {
if (event == null) {
return player.getInventory().getHeldItemSlot();
}
return slot;
if (CompatibleHand.getHand(event) == CompatibleHand.OFF_HAND) {
return 40;
}
return player.getInventory().getHeldItemSlot();
}
public static Object parseJS(String toParse, String type, Object def) {

View File

@ -0,0 +1,155 @@
package com.craftaro.epicenchants.utils.single;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import org.apache.commons.lang.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import static com.craftaro.third_party.com.cryptomorin.xseries.XMaterial.*;
public class ItemGroup {
private final Multimap<Group, XMaterial> groupMap;
public ItemGroup() {
this.groupMap = HashMultimap.create();
this.groupMap.putAll(ItemGroup.Group.AXES, Arrays.asList(NETHERITE_AXE, DIAMOND_AXE, GOLDEN_AXE, IRON_AXE, STONE_AXE, WOODEN_AXE));
this.groupMap.putAll(ItemGroup.Group.PICKAXES, Arrays.asList(NETHERITE_PICKAXE, DIAMOND_PICKAXE, GOLDEN_PICKAXE, IRON_PICKAXE, STONE_PICKAXE, WOODEN_PICKAXE));
this.groupMap.putAll(ItemGroup.Group.HOES, Arrays.asList(NETHERITE_HOE, DIAMOND_HOE, GOLDEN_HOE, IRON_HOE, STONE_HOE, WOODEN_HOE));
this.groupMap.putAll(ItemGroup.Group.SHOVELS, Arrays.asList(NETHERITE_SHOVEL, DIAMOND_SHOVEL, GOLDEN_SHOVEL, IRON_SHOVEL, STONE_SHOVEL, WOODEN_SHOVEL));
this.groupMap.putAll(ItemGroup.Group.SWORDS, Arrays.asList(NETHERITE_SWORD, DIAMOND_SWORD, GOLDEN_SWORD, IRON_SWORD, STONE_SWORD, WOODEN_SWORD));
this.groupMap.put(ItemGroup.Group.BOWS, BOW);
this.groupMap.putAll(ItemGroup.Group.BOOTS, Arrays.asList(NETHERITE_BOOTS, DIAMOND_BOOTS, GOLDEN_BOOTS, IRON_BOOTS, LEATHER_BOOTS));
this.groupMap.putAll(ItemGroup.Group.LEGGINGS, Arrays.asList(NETHERITE_LEGGINGS, DIAMOND_LEGGINGS, GOLDEN_LEGGINGS, IRON_LEGGINGS, LEATHER_LEGGINGS));
this.groupMap.putAll(ItemGroup.Group.CHESTPLATES, Arrays.asList(NETHERITE_CHESTPLATE, DIAMOND_CHESTPLATE, GOLDEN_CHESTPLATE, IRON_CHESTPLATE, LEATHER_CHESTPLATE));
this.groupMap.putAll(ItemGroup.Group.HELMETS, Arrays.asList(NETHERITE_HELMET, DIAMOND_HELMET, GOLDEN_HELMET, IRON_HELMET, LEATHER_HELMET));
this.groupMap.put(ItemGroup.Group.TRIDENTS, TRIDENT);
}
public Set<XMaterial> get(String key) {
Optional<Group> optionalGroup = Group.from(key);
Set<XMaterial> output = new HashSet<>();
optionalGroup.ifPresent(group -> output.addAll(getMaterials(group)));
Optional<XMaterial> material = XMaterial.matchXMaterial(key);
material.ifPresent(output::add);
return output;
}
public boolean isValid(XMaterial material) {
for (Group group : this.groupMap.keys()) {
if (getMaterials(group).contains(material)) {
return true;
}
}
return false;
}
public Set<String> getGroups(Set<XMaterial> materials) {
Set<String> groups = new HashSet<>();
for (int i = 0; i < 5; i++) {
getGroup(materials).ifPresent(group -> {
groups.add(group.getName());
new ArrayList<>(getMaterials(group)).forEach(materials::remove);
});
}
groups.addAll(materials.stream().map(XMaterial::toString).collect(Collectors.toSet()));
return groups;
}
public Optional<Group> getGroup(Set<XMaterial> materials) {
for (Group group : Group.values()) {
if (!group.getChildren().isEmpty() && group.getChildren().stream().allMatch(child -> materials.containsAll(this.groupMap.get(child)))) {
return Optional.of(group);
}
}
for (Map.Entry<Group, Collection<XMaterial>> entry : this.groupMap.asMap().entrySet()) {
if (materials.containsAll(entry.getValue())) {
return Optional.of(entry.getKey());
}
}
return Optional.empty();
}
public Set<XMaterial> getMaterials(Group group) {
Set<XMaterial> out = new HashSet<>();
for (int i = 0; i < 5; i++) {
if (group.getChildren().isEmpty()) {
out.addAll(this.groupMap.get(group));
} else {
out.addAll(group.getChildren().stream().map(this::getMaterials).flatMap(Collection::stream).collect(Collectors.toSet()));
}
}
return out;
}
public enum Group {
AXES,
HOES,
PICKAXES,
SHOVELS,
TOOLS(AXES, PICKAXES, HOES, SHOVELS),
SWORDS,
BOWS,
TRIDENTS,
WEAPONS(SWORDS, BOWS, AXES, TRIDENTS),
BOOTS,
LEGGINGS,
CHESTPLATES,
HELMETS,
ARMOR(BOOTS, LEGGINGS, CHESTPLATES, HELMETS);
private final Set<Group> children;
Group(Group... child) {
this.children = child == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(child));
}
public static Optional<Group> from(String key) {
for (Group group : values()) {
if (group.toString().equalsIgnoreCase(key)) {
return Optional.of(group);
}
}
return Optional.empty();
}
public String getName() {
return StringUtils.capitalize(toString().toLowerCase());
}
public Set<Group> getChildren() {
return this.children;
}
}
}

View File

@ -1,4 +1,4 @@
package com.songoda.epicenchants.utils.single;
package com.craftaro.epicenchants.utils.single;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
@ -27,10 +27,9 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static com.songoda.epicenchants.utils.single.GeneralUtils.getHeldItem;
import static com.craftaro.epicenchants.utils.single.GeneralUtils.getHeldItem;
public class Placeholders {
private static final Map<String, Function<Event, String>> EVENT_FUNCTIONS = new HashMap<String, Function<Event, String>>() {{
put("{block_type}", event -> {
if (event instanceof BlockBreakEvent) {

View File

@ -1,9 +1,9 @@
package com.songoda.epicenchants.utils.single;
package com.craftaro.epicenchants.utils.single;
import java.util.TreeMap;
public class RomanNumber {
private final static TreeMap<Integer, String> TREE_MAP = new TreeMap<Integer, String>() {{
private static final TreeMap<Integer, String> TREE_MAP = new TreeMap<Integer, String>() {{
put(1000, "M");
put(900, "CM");
put(500, "D");

View File

@ -1,6 +1,6 @@
package com.songoda.epicenchants.wrappers;
package com.craftaro.epicenchants.wrappers;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.craftaro.epicenchants.objects.LeveledModifier;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -8,8 +8,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class EnchantmentWrapper {
private LeveledModifier amplifier;
private Enchantment enchantment;
private final LeveledModifier amplifier;
private final Enchantment enchantment;
EnchantmentWrapper(LeveledModifier amplifier, Enchantment enchantment) {
this.amplifier = amplifier;
@ -21,11 +21,11 @@ public class EnchantmentWrapper {
}
public int getAmplifier(int level, @NotNull Player user, @Nullable LivingEntity opponent) {
return (int) amplifier.get(level, 0, user, opponent);
return (int) this.amplifier.get(level, 0, user, opponent);
}
public Enchantment getEnchantment() {
return enchantment;
return this.enchantment;
}
public static class EnchantmentWrapperBuilder {
@ -46,7 +46,7 @@ public class EnchantmentWrapper {
}
public EnchantmentWrapper build() {
return new EnchantmentWrapper(amplifier, enchantment);
return new EnchantmentWrapper(this.amplifier, this.enchantment);
}
public String toString() {

Binary file not shown.

View File

@ -1,15 +0,0 @@
package com.songoda.epicenchants;
import com.songoda.epicenchants.utils.Methods;
import org.bukkit.command.CommandSender;
public class CommandCommons {
public static boolean isInt(String number, CommandSender sender) {
if (!Methods.isInt(number)) {
EpicEnchants.getInstance().getLocale().newMessage("Not a number.").sendPrefixedMessage(sender);
return false;
}
return true;
}
}

View File

@ -1,102 +0,0 @@
package com.songoda.epicenchants.effect.effects;
import com.songoda.epicenchants.effect.EffectExecutor;
import com.songoda.epicenchants.enums.EventType;
import com.songoda.epicenchants.objects.LeveledModifier;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static com.songoda.epicenchants.objects.LeveledModifier.of;
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
import static java.util.concurrent.ThreadLocalRandom.current;
public class SpawnMob extends EffectExecutor {
private LeveledModifier attackDamage;
private String displayName;
private EntityType entityType;
private LeveledModifier equipmentDropChance;
private LeveledModifier health;
private ItemBuilder helmet, chestPlate, leggings, boots, handItem;
private boolean hostile;
private LeveledModifier amount;
public SpawnMob(ConfigurationSection section) {
super(section);
entityType = EntityType.valueOf(section.getString("mob-type"));
amount = of(section.getString("amount"));
health = of(section.getString("health"));
attackDamage = of(section.getString("attack-damage"));
equipmentDropChance = LeveledModifier.of(section.getString("equipment-drop-chance"));
hostile = section.getBoolean("hostile", false);
displayName = section.isString("display-name") ? color(section.getString("display-name")) : "";
helmet = section.isConfigurationSection("equipment.helmet") ? new ItemBuilder(section.getConfigurationSection("equipment.helmet")) : null;
chestPlate = section.isConfigurationSection("equipment.chestplate") ? new ItemBuilder(section.getConfigurationSection("equipment.chestplate")) : null;
leggings = section.isConfigurationSection("equipment.leggings") ? new ItemBuilder(section.getConfigurationSection("equipment.leggings")) : null;
boots = section.isConfigurationSection("equipment.boots") ? new ItemBuilder(section.getConfigurationSection("equipment.boots")) : null;
handItem = section.isConfigurationSection("equipment.hand-item") ? new ItemBuilder(section.getConfigurationSection("equipment.hand-item")) : null;
}
@Override
public void execute(@NotNull Player user, @Nullable LivingEntity opponent, int level, EventType eventType) {
Location location = user.getLocation();
for (int i = 0; i < amount.get(level, 1, user, opponent); i++) {
Location spawnLocation = location.clone().add(current().nextInt(-3, 3), 0, current().nextInt(-3, 3));
int y = location.getWorld().getHighestBlockAt(spawnLocation).getY();
if (y < location.getY() - 10 || y > location.getY() + 10) {
continue;
}
Entity entity = location.getWorld().spawnEntity(spawnLocation, entityType);
entity.setCustomName(displayName.replace("{level}", "" + level));
entity.setCustomNameVisible(true);
if (entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) entity;
livingEntity.setRemoveWhenFarAway(true);
int dropChance = (int) equipmentDropChance.get(level, 0, user, opponent);
if (helmet != null)
livingEntity.getEquipment().setHelmet(helmet.buildWithWrappers(level, user, opponent));
if (chestPlate != null)
livingEntity.getEquipment().setChestplate(chestPlate.buildWithWrappers(level, user, opponent));
if (leggings != null)
livingEntity.getEquipment().setLeggings(leggings.buildWithWrappers(level, user, opponent));
if (boots != null) livingEntity.getEquipment().setBoots(boots.buildWithWrappers(level, user, opponent));
livingEntity.getEquipment().setHelmetDropChance(dropChance);
livingEntity.getEquipment().setLeggingsDropChance(dropChance);
livingEntity.getEquipment().setHelmetDropChance(dropChance);
livingEntity.getEquipment().setChestplateDropChance(dropChance);
if (handItem != null)
livingEntity.getEquipment().setItemInHand(handItem.buildWithWrappers(level, user, opponent));
livingEntity.getEquipment().setItemInHandDropChance(dropChance);
}
if (hostile && entity instanceof Monster && opponent != null) {
((Monster) entity).setTarget(opponent);
}
if (entity instanceof LivingEntity) {
AttributeInstance attack = ((LivingEntity) entity).getAttribute(Attribute.GENERIC_ATTACK_DAMAGE);
attack.setBaseValue(attackDamage.get(level, (int) Math.round(attack.getBaseValue()), user, opponent));
AttributeInstance heal = ((LivingEntity) entity).getAttribute(Attribute.GENERIC_MAX_HEALTH);
heal.setBaseValue(health.get(level, (int) Math.round(heal.getBaseValue()), user, opponent));
}
}
}
}

View File

@ -1,5 +0,0 @@
package com.songoda.epicenchants.enums;
public enum ItemType {
BOOK, ENCHANTED, NONE
}

View File

@ -1,41 +0,0 @@
package com.songoda.epicenchants.listeners.item;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
public class WhiteScrollListener extends ItemListener {
public WhiteScrollListener(EpicEnchants instance) {
super(instance);
}
@Override
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
if (!cursor.hasKey("white-scroll") || !cursor.getBoolean("white-scroll")) {
return;
}
event.setCancelled(true);
if (current.hasKey("protected")) {
instance.getLocale().getMessage("whitescroll.alreadyapplied")
.sendPrefixedMessage(event.getWhoClicked());
return;
}
if (!instance.getItemGroup().isValid(CompatibleMaterial.getMaterial(event.getCurrentItem())))
return;
current.setBoolean("protected", true);
instance.getLocale().getMessage("whitescrollapplied").sendPrefixedMessage(event.getWhoClicked());
ItemStack toSet = new ItemBuilder(current.getItem()).addLore(instance.getSpecialItems().getWhiteScrollLore()).build();
event.getClickedInventory().setItem(event.getSlot(), toSet);
useItem(event);
}
}

View File

@ -1,20 +0,0 @@
package com.songoda.epicenchants.managers;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Group;
import com.songoda.epicenchants.utils.single.ConfigParser;
import org.bukkit.configuration.ConfigurationSection;
public class GroupManager extends Manager<String, Group> {
public GroupManager(EpicEnchants instance) {
super(instance);
}
public void loadGroups() {
ConfigurationSection config = instance.getFileManager().getConfiguration("groups").getConfigurationSection("groups");
config.getKeys(false).forEach(key -> {
Group group = ConfigParser.parseGroup(instance, config.getConfigurationSection(key));
add(group.getIdentifier().toUpperCase(), group);
});
}
}

View File

@ -1,18 +0,0 @@
package com.songoda.epicenchants.managers;
import com.songoda.ultimatebottles.UltimateBottles;
import org.bukkit.Bukkit;
import java.util.Optional;
public class HookManager {
private UltimateBottles ultimateBottles;
public void setup() {
ultimateBottles = Bukkit.getPluginManager().isPluginEnabled("UltimateBottles") ? (UltimateBottles) Bukkit.getPluginManager().getPlugin("UltimateBottles") : null;
}
public Optional<UltimateBottles> getUltimateBottles() {
return Optional.ofNullable(ultimateBottles);
}
}

Some files were not shown because too many files have changed in this diff Show More